From: Daniel Hahler Date: Sat, 11 May 2019 13:10:47 +0000 (+0200) Subject: Fix indent with pythonTodo at end of line (#124) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/68c34f9b2944a9ebf1f970d2d54b915806a121ad?ds=sidebyside;hp=--cc 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). --- 68c34f9b2944a9ebf1f970d2d54b915806a121ad diff --git a/indent/python.vim b/indent/python.vim index 5da97e9..36ff12a 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -69,13 +69,15 @@ let s:stop_statement = '^\s*\(break\|continue\|raise\|return\|pass\)\>' let s:skip_after_opening_paren = 'synIDattr(synID(line("."), col("."), 0), "name") ' . \ '=~? "\\vcomment|jedi\\S"' +let s:special_chars_syn_pattern = "\\vstring|comment|^pythonbytes%(contents)=$|pythonTodo|jedi\\S" + if !get(g:, 'python_pep8_indent_skip_concealed', 0) || !has('conceal') " Skip strings and comments. Return 1 for chars to skip. " jedi* refers to syntax definitions from jedi-vim for call signatures, which " are inserted temporarily into the buffer. function! s:_skip_special_chars(line, col) return synIDattr(synID(a:line, a:col, 0), 'name') - \ =~? "\\vstring|comment|^pythonbytes%(contents)=$|jedi\\S" + \ =~? s:special_chars_syn_pattern endfunction else " Also ignore anything concealed. @@ -90,8 +92,8 @@ else function! s:_skip_special_chars(line, col) return synIDattr(synID(a:line, a:col, 0), 'name') - \ =~? "\\vstring|comment|^pythonbytes%(contents)=$|jedi\\S" - \ || s:is_concealed(a:line, a:col) + \ =~? s:special_chars_syn_pattern + \ || s:is_concealed(a:line, a:col) endfunction endif diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb index 4227b3f..db66b8f 100644 --- a/spec/indent/indent_spec.rb +++ b/spec/indent/indent_spec.rb @@ -702,7 +702,10 @@ describe "Compact multiline dict" do end describe "Using O" do - before { vim.feedkeys 'iif foo:\' } + before { + vim.feedkeys '\ggdG' + vim.feedkeys 'iif foo:\' + } it "respects autoindent" do vim.feedkeys '1\\' @@ -727,3 +730,17 @@ describe "searchpairpos" do indent.should == shiftwidth end end + +describe "o within TODO" do + before { + vim.feedkeys '\ggdG' + vim.feedkeys 'iif 1: # TODO\' + # Assertion that we have a pythonTodo here. + vim.echo('synIDattr(synID(line("."), col("."), 0), "name")').should match 'pythonTodo' + } + + it "respects autoindent" do + vim.feedkeys 'o' + indent.should == shiftwidth + end +end