Skip to content

Commit 68c34f9

Browse files
authored
Fix indent with pythonTodo at end of line (#124)
"pythonTodo" is contained in "pythonComment". Fix it by adding "pythonTodo" to the pattern to match special chars. An alternative might be using `synstack()` to get to "pythonComment" still, but this is not really necessary (and likely slower).
1 parent 84f35c0 commit 68c34f9

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

indent/python.vim

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ let s:stop_statement = '^\s*\(break\|continue\|raise\|return\|pass\)\>'
6969
let s:skip_after_opening_paren = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
7070
\ '=~? "\\vcomment|jedi\\S"'
7171

72+
let s:special_chars_syn_pattern = "\\vstring|comment|^pythonbytes%(contents)=$|pythonTodo|jedi\\S"
73+
7274
if !get(g:, 'python_pep8_indent_skip_concealed', 0) || !has('conceal')
7375
" Skip strings and comments. Return 1 for chars to skip.
7476
" jedi* refers to syntax definitions from jedi-vim for call signatures, which
7577
" are inserted temporarily into the buffer.
7678
function! s:_skip_special_chars(line, col)
7779
return synIDattr(synID(a:line, a:col, 0), 'name')
78-
\ =~? "\\vstring|comment|^pythonbytes%(contents)=$|jedi\\S"
80+
\ =~? s:special_chars_syn_pattern
7981
endfunction
8082
else
8183
" Also ignore anything concealed.
@@ -90,8 +92,8 @@ else
9092

9193
function! s:_skip_special_chars(line, col)
9294
return synIDattr(synID(a:line, a:col, 0), 'name')
93-
\ =~? "\\vstring|comment|^pythonbytes%(contents)=$|jedi\\S"
94-
\ || s:is_concealed(a:line, a:col)
95+
\ =~? s:special_chars_syn_pattern
96+
\ || s:is_concealed(a:line, a:col)
9597
endfunction
9698
endif
9799

spec/indent/indent_spec.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,10 @@
702702
end
703703

704704
describe "Using O" do
705-
before { vim.feedkeys 'iif foo:\<CR>' }
705+
before {
706+
vim.feedkeys '\<ESC>ggdG'
707+
vim.feedkeys 'iif foo:\<CR>'
708+
}
706709

707710
it "respects autoindent" do
708711
vim.feedkeys '1\<CR>\<CR>'
@@ -727,3 +730,17 @@
727730
indent.should == shiftwidth
728731
end
729732
end
733+
734+
describe "o within TODO" do
735+
before {
736+
vim.feedkeys '\<ESC>ggdG'
737+
vim.feedkeys 'iif 1: # TODO\<Esc>'
738+
# Assertion that we have a pythonTodo here.
739+
vim.echo('synIDattr(synID(line("."), col("."), 0), "name")').should match 'pythonTodo'
740+
}
741+
742+
it "respects autoindent" do
743+
vim.feedkeys 'o'
744+
indent.should == shiftwidth
745+
end
746+
end

0 commit comments

Comments
 (0)