Skip to content

Commit 6c8647f

Browse files
committed
Improve indent for async with statement
1 parent 479ecb5 commit 6c8647f

2 files changed

Lines changed: 55 additions & 3 deletions

File tree

indent/python.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" Vim indent file
22
" Language: Python
33
" Author: Akinori Hattori <hattya@gmail.com>
4-
" Last Change: 2023-07-20
4+
" Last Change: 2023-07-21
55
" License: MIT License
66

77
if exists('b:did_indent')
@@ -179,11 +179,11 @@ function! s:synmatch(lnum, col, pat) abort
179179
endfunction
180180

181181
function! s:is_compound_stmt(str, ...) abort
182-
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)>'
182+
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)>'
183183
endfunction
184184

185185
function! s:matchkw(str) abort
186-
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*\*)=)')
186+
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*\*)=)')
187187
endfunction
188188

189189
function! s:cont() abort

test/indent.vimspec

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,58 @@ Describe filetype indent
12081208
Assert Equals(Insert(in), Buffer(out))
12091209
End
12101210
End
1211+
1212+
Describe async with statement
1213+
It aligns with left brackets
1214+
let in = "async with (spam,\<CR>eggs):"
1215+
let out = [
1216+
\ 'async with (spam,',
1217+
\ ' eggs):',
1218+
\] "" Assert Equals(Insert(in), Buffer(out))
1219+
End
1220+
1221+
It increases the indent level by 2
1222+
let b:python_indent_multiline_statement = 1
1223+
let in = "async with (spam,\<CR>eggs):"
1224+
let out = [
1225+
\ 'async with (spam,',
1226+
\ ' eggs):',
1227+
\]
1228+
Assert Equals(Insert(in), Buffer(out))
1229+
End
1230+
1231+
It increases the indent level (hanging indent)
1232+
let in = "async with (\<CR>spam,\<CR>eggs,\<CR>):"
1233+
let out = [
1234+
\ 'async with (',
1235+
\ ' spam,',
1236+
\ ' eggs,',
1237+
\ '):',
1238+
\]
1239+
Assert Equals(Insert(in), Buffer(out))
1240+
End
1241+
1242+
It increases the indent level by 2 (hanging indent)
1243+
let b:python_indent_multiline_statement = 1
1244+
let in = "async with (\<CR>spam,\<CR>eggs,\<CR>):"
1245+
let out = [
1246+
\ 'async with (',
1247+
\ ' spam,',
1248+
\ ' eggs,',
1249+
\ '):',
1250+
\]
1251+
Assert Equals(Insert(in), Buffer(out))
1252+
End
1253+
1254+
It increases the indent level (line continueation)
1255+
let in = "async with spam, \\\<CR>eggs:"
1256+
let out = [
1257+
\ 'async with spam, \',
1258+
\ ' eggs:',
1259+
\]
1260+
Assert Equals(Insert(in), Buffer(out))
1261+
End
1262+
End
12111263
End
12121264
End
12131265
End

0 commit comments

Comments
 (0)