Skip to content

Commit

Permalink
Improve indent for async with statement
Browse files Browse the repository at this point in the history
  • Loading branch information
hattya committed Jul 21, 2023
1 parent 479ecb5 commit 6c8647f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
6 changes: 3 additions & 3 deletions indent/python.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
" Vim indent file
" Language: Python
" Author: Akinori Hattori <hattya@gmail.com>
" Last Change: 2023-07-20
" Last Change: 2023-07-21
" License: MIT License

if exists('b:did_indent')
Expand Down Expand Up @@ -179,11 +179,11 @@ function! s:synmatch(lnum, col, pat) abort
endfunction

function! s:is_compound_stmt(str, ...) abort
return (a:0 && a:1 && a:str =~# '\v^\s*<%(%(async\s+)=def|class)>') || a:str =~# '\v^\s*<%(if|elif|while|%(async\s+)=for|except|with|match|case)>'
return (a:0 && a:1 && a:str =~# '\v^\s*<%(%(async\s+)=def|class)>') || a:str =~# '\v^\s*<%(if|elif|while|%(async\s+)=%(for|with)|except|match|case)>'
endfunction

function! s:matchkw(str) abort
return matchstr(a:str, '\v^\s*\zs<%(%(await|assert|del|return|yield%(\s+from)=|raise|import|from|global|nonlocal|if|elif|while|%(async\s+)=%(for|def)|with|match|case|class|async)>|except>%(\s*\*)=)')
return matchstr(a:str, '\v^\s*\zs<%(%(await|assert|del|return|yield%(\s+from)=|raise|import|from|global|nonlocal|if|elif|while|%(async\s+)=%(for|with|def)|match|case|class|async)>|except>%(\s*\*)=)')
endfunction

function! s:cont() abort
Expand Down
52 changes: 52 additions & 0 deletions test/indent.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,58 @@ Describe filetype indent
Assert Equals(Insert(in), Buffer(out))
End
End

Describe async with statement
It aligns with left brackets
let in = "async with (spam,\<CR>eggs):"
let out = [
\ 'async with (spam,',
\ ' eggs):',
\] "" Assert Equals(Insert(in), Buffer(out))
End

It increases the indent level by 2
let b:python_indent_multiline_statement = 1
let in = "async with (spam,\<CR>eggs):"
let out = [
\ 'async with (spam,',
\ ' eggs):',
\]
Assert Equals(Insert(in), Buffer(out))
End

It increases the indent level (hanging indent)
let in = "async with (\<CR>spam,\<CR>eggs,\<CR>):"
let out = [
\ 'async with (',
\ ' spam,',
\ ' eggs,',
\ '):',
\]
Assert Equals(Insert(in), Buffer(out))
End

It increases the indent level by 2 (hanging indent)
let b:python_indent_multiline_statement = 1
let in = "async with (\<CR>spam,\<CR>eggs,\<CR>):"
let out = [
\ 'async with (',
\ ' spam,',
\ ' eggs,',
\ '):',
\]
Assert Equals(Insert(in), Buffer(out))
End

It increases the indent level (line continueation)
let in = "async with spam, \\\<CR>eggs:"
let out = [
\ 'async with spam, \',
\ ' eggs:',
\]
Assert Equals(Insert(in), Buffer(out))
End
End
End
End
End

0 comments on commit 6c8647f

Please sign in to comment.