Lifepillar
unread,Mar 10, 2021, 11:15:38 AM3/10/21Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to vim...@googlegroups.com
I would like to indent code structured as follows:
if X then
(
if Y then
(
...
)
)
else
...
To make Python look like a language that is easy to indent, this
language has `if... then... [else]` blocks without `endif`.
I get can get it almost right, except that the last `else` above gets
aligned with `if Y then`. The relevant snippet from my indent script
currently looks as follows:
fun! s:find_pair(pstart, pmid, pend)
call cursor(v:lnum, 1)
call search(a:pend, 'Wc')
return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn'))
endf
" And in my indentation function:
if getline(v:lnum) =~# '\<else\>'
return s:find_pair('\<then\>', '', '\<else\>')
endif
if getline(v:lnum) =~# '^\s*)'
return s:find_pair('(', '', ')')
endif
Any idea how I could take into account the blocks in parentheses when
matching `else` with its corresponding `if... then`?
Thanks,
Life.