Skip to content

Commit 44c3435

Browse files
committed
Improve indent for coroutine function definition
1 parent f0fedf6 commit 44c3435

2 files changed

Lines changed: 54 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-17
4+
" Last Change: 2023-07-19
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*<%(def|class)>') || a:str =~# '\v^\s*<%(if|elif|while|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|for|except|with|match|case)>'
183183
endfunction
184184

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

189189
function! s:cont() abort

test/indent.vimspec

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,15 @@ Describe filetype indent
350350
Assert Equals(Insert(in), Buffer(out))
351351
End
352352
End
353+
354+
It indents the await expression
355+
let in = "await spam \\\<CR>.eggs()"
356+
let out = [
357+
\ 'await spam \',
358+
\ ' .eggs()',
359+
\]
360+
Assert Equals(Insert(in), Buffer(out))
361+
End
353362
End
354363

355364
Describe simple statement
@@ -1089,5 +1098,47 @@ Describe filetype indent
10891098
Assert Equals(Insert(in), Buffer(out))
10901099
End
10911100
End
1101+
1102+
Describe coroutine
1103+
Describe coroutine function definition
1104+
It aligns with left brackets
1105+
let in = "async def spam(*args,\<CR>**kwargs):"
1106+
let out = [
1107+
\ 'async def spam(*args,',
1108+
\ ' **kwargs):',
1109+
\]
1110+
Assert Equals(Insert(in), Buffer(out))
1111+
End
1112+
1113+
It increases the indent level (hanging indent)
1114+
let in = "async def spam(\<CR>*args,\<CR>**kwargs\<CR>):"
1115+
let out = [
1116+
\ 'async def spam(',
1117+
\ ' *args,',
1118+
\ ' **kwargs',
1119+
\ '):',
1120+
\]
1121+
Assert Equals(Insert(in), Buffer(out))
1122+
End
1123+
1124+
It increases the indent level (line continueation)
1125+
let in = "async def \\\<CR>spam():\<CR>...\<CR>"
1126+
let in .= "async \\\<CR>def eggs():\<CR>...\<CR>"
1127+
let in .= "async \\\<CR>def \\\<CR>ham():"
1128+
let out = [
1129+
\ 'async def \',
1130+
\ ' spam():',
1131+
\ ' ...',
1132+
\ 'async \',
1133+
\ ' def eggs():',
1134+
\ ' ...',
1135+
\ 'async \',
1136+
\ ' def \',
1137+
\ ' ham():',
1138+
\]
1139+
Assert Equals(Insert(in), Buffer(out))
1140+
End
1141+
End
1142+
End
10921143
End
10931144
End

0 commit comments

Comments
 (0)