File: runtime/indent/python.vim
When checking for a colon at the end of a statement to decide whether to indent
the next line, it strips trailing comments; however, the syntax group can be
pythonTodo rather than pythonComment, which it was not detecting.
Thus, a line like this:
if True: # TODO
would lead to the next line not being indented an extra level, which is not
correct.
The simple solution (employed here) is to change the check for `Comment$` to
`(Comment|Todo)$`. A more complex but
more-correct-in-case-of-user-extensions-to-the-syntax solution would check the
whole synstack, but I deemed that as probably unnecessary. I'm happy to write
such a thing if desired, though.
This has been an issue for quite some time, probably since the beginning of
that syntax file.
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
*** runtime/indent/python.vim 2013-07-09 23:14:48.209114454 +1000
--- new.python.vim 2013-07-09 23:22:45.719482300 +1000
***************
*** 2,8 ****
" Language: Python
" Maintainer: Bram Moolenaar <[email protected]>
" Original Author: David Bustos <[email protected]>
! " Last Change: 2013 Jun 21
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
--- 2,8 ----
" Language: Python
" Maintainer: Bram Moolenaar <[email protected]>
" Original Author: David Bustos <[email protected]>
! " Last Change: 2013 Jul 9
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
***************
*** 61,67 ****
let parlnum = searchpair('(\|{\|\[', '', ')\|}\|\]', 'nbW',
\ "line('.') < " . (plnum - s:maxoff) . " ? dummy :"
\ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
! \ . " =~ '\\(Comment\\|String\\)$'")
if parlnum > 0
let plindent = indent(parlnum)
let plnumstart = parlnum
--- 61,67 ----
let parlnum = searchpair('(\|{\|\[', '', ')\|}\|\]', 'nbW',
\ "line('.') < " . (plnum - s:maxoff) . " ? dummy :"
\ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
! \ . " =~ '\\(Comment\\|Todo\\|String\\)$'")
if parlnum > 0
let plindent = indent(parlnum)
let plnumstart = parlnum
***************
*** 80,93 ****
let p = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW',
\ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
\ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
! \ . " =~ '\\(Comment\\|String\\)$'")
if p > 0
if p == plnum
" When the start is inside parenthesis, only indent one 'shiftwidth'.
let pp = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW',
\ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
\ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
! \ . " =~ '\\(Comment\\|String\\)$'")
if pp > 0
return indent(plnum) + (exists("g:pyindent_nested_paren") ? eval(g:pyindent_nested_paren) : shiftwidth())
endif
--- 80,93 ----
let p = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW',
\ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
\ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
! \ . " =~ '\\(Comment\\|Todo\\|String\\)$'")
if p > 0
if p == plnum
" When the start is inside parenthesis, only indent one 'shiftwidth'.
let pp = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW',
\ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
\ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
! \ . " =~ '\\(Comment\\|Todo\\|String\\)$'")
if pp > 0
return indent(plnum) + (exists("g:pyindent_nested_paren") ? eval(g:pyindent_nested_paren) : shiftwidth())
endif
***************
*** 108,119 ****
" If the last character in the line is a comment, do a binary search for
" the start of the comment. synID() is slow, a linear search would take
" too long on a long line.
! if synIDattr(synID(plnum, pline_len, 1), "name") =~ "Comment$"
let min = 1
let max = pline_len
while min < max
let col = (min + max) / 2
! if synIDattr(synID(plnum, col, 1), "name") =~ "Comment$"
let max = col
else
let min = col + 1
--- 108,119 ----
" If the last character in the line is a comment, do a binary search for
" the start of the comment. synID() is slow, a linear search would take
" too long on a long line.
! if synIDattr(synID(plnum, pline_len, 1), "name") =~ "\\(Comment\\|Todo\\)$"
let min = 1
let max = pline_len
while min < max
let col = (min + max) / 2
! if synIDattr(synID(plnum, col, 1), "name") =~ "\\(Comment\\|Todo\\)$"
let max = col
else
let min = col + 1