diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 18:31:31 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 18:31:31 +0000 |
commit | 9243becbedbb6a1592208051f8fa2b090dcc5e7d (patch) | |
tree | 607c2a862ec3f4399b8766383f6f8e04c4aa43b4 /runtime/autoload/python.vim | |
parent | 9e40b6e9e1bc67f2d856adb837ee64dd0e25b717 (diff) | |
parent | 3c48d3c83fc21dbc0841f9210f04bdb073d73cd1 (diff) | |
download | rneovim-usermarks.tar.gz rneovim-usermarks.tar.bz2 rneovim-usermarks.zip |
Merge remote-tracking branch 'upstream/master' into usermarksusermarks
Diffstat (limited to 'runtime/autoload/python.vim')
-rw-r--r-- | runtime/autoload/python.vim | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/runtime/autoload/python.vim b/runtime/autoload/python.vim index e45dbd9db8..1eaad09ef5 100644 --- a/runtime/autoload/python.vim +++ b/runtime/autoload/python.vim @@ -3,13 +3,19 @@ let s:keepcpo= &cpo set cpo&vim -" searchpair() can be slow, limit the time to 150 msec or what is put in -" g:pyindent_searchpair_timeout -let s:searchpair_timeout = get(g:, 'pyindent_searchpair_timeout', 150) - -" Identing inside parentheses can be very slow, regardless of the searchpair() -" timeout, so let the user disable this feature if he doesn't need it -let s:disable_parentheses_indenting = get(g:, 'pyindent_disable_parentheses_indenting', v:false) +" need to inspect some old g:pyindent_* variables to be backward compatible +let g:python_indent = extend(get(g:, 'python_indent', {}), #{ + \ closed_paren_align_last_line: v:true, + \ open_paren: get(g:, 'pyindent_open_paren', 'shiftwidth() * 2'), + \ nested_paren: get(g:, 'pyindent_nested_paren', 'shiftwidth()'), + \ continue: get(g:, 'pyindent_continue', 'shiftwidth() * 2'), + "\ searchpair() can be slow, limit the time to 150 msec or what is put in + "\ g:python_indent.searchpair_timeout + \ searchpair_timeout: get(g:, 'pyindent_searchpair_timeout', 150), + "\ Identing inside parentheses can be very slow, regardless of the searchpair() + "\ timeout, so let the user disable this feature if he doesn't need it + \ disable_parentheses_indenting: get(g:, 'pyindent_disable_parentheses_indenting', v:false), + \ }, 'keep') let s:maxoff = 50 " maximum number of lines to look backwards for () @@ -18,7 +24,7 @@ function s:SearchBracket(fromlnum, flags) \ {-> synstack('.', col('.')) \ ->map({_, id -> id->synIDattr('name')}) \ ->match('\%(Comment\|Todo\|String\)$') >= 0}, - \ [0, a:fromlnum - s:maxoff]->max(), s:searchpair_timeout) + \ [0, a:fromlnum - s:maxoff]->max(), g:python_indent.searchpair_timeout) endfunction " See if the specified line is already user-dedented from the expected value. @@ -38,7 +44,7 @@ function python#GetIndent(lnum, ...) if a:lnum > 1 && getline(a:lnum - 2) =~ '\\$' return indent(a:lnum - 1) endif - return indent(a:lnum - 1) + (exists("g:pyindent_continue") ? eval(g:pyindent_continue) : (shiftwidth() * 2)) + return indent(a:lnum - 1) + get(g:, 'pyindent_continue', g:python_indent.continue)->eval() endif " If the start of the line is in a string don't change the indent. @@ -55,7 +61,7 @@ function python#GetIndent(lnum, ...) return 0 endif - if s:disable_parentheses_indenting == 1 + if g:python_indent.disable_parentheses_indenting == 1 let plindent = indent(plnum) let plnumstart = plnum else @@ -70,8 +76,12 @@ function python#GetIndent(lnum, ...) " 100, 200, 300, 400) call cursor(a:lnum, 1) let [parlnum, parcol] = s:SearchBracket(a:lnum, 'nbW') - if parlnum > 0 && parcol != col([parlnum, '$']) - 1 - return parcol + if parlnum > 0 + if parcol != col([parlnum, '$']) - 1 + return parcol + elseif getline(a:lnum) =~ '^\s*[])}]' && !g:python_indent.closed_paren_align_last_line + return indent(parlnum) + endif endif call cursor(plnum, 1) @@ -123,9 +133,11 @@ function python#GetIndent(lnum, ...) " When the start is inside parenthesis, only indent one 'shiftwidth'. let [pp, _] = s:SearchBracket(a:lnum, 'bW') if pp > 0 - return indent(plnum) + (exists("g:pyindent_nested_paren") ? eval(g:pyindent_nested_paren) : shiftwidth()) + return indent(plnum) + \ + get(g:, 'pyindent_nested_paren', g:python_indent.nested_paren)->eval() endif - return indent(plnum) + (exists("g:pyindent_open_paren") ? eval(g:pyindent_open_paren) : (shiftwidth() * 2)) + return indent(plnum) + \ + get(g:, 'pyindent_open_paren', g:python_indent.open_paren)->eval() endif if plnumstart == p return indent(plnum) |