Help with indenting code

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Help with indenting code

I would like to indent code structured as follows:

    if X then
        if Y then

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'))

    " And in my indentation function:

    if getline(v:lnum) =~# '\<else\>'
      return s:find_pair('\<then\>', '', '\<else\>')

    if getline(v:lnum) =~# '^\s*)'
      return s:find_pair('(', '', ')')

Any idea how I could take into account the blocks in parentheses when
matching `else` with its corresponding `if... then`?


You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit

You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit