comparison runtime/autoload/python.vim @ 29840:b15334beeaa4

Update runtime files Commit: https://github.com/vim/vim/commit/fd999452adaf529a30d78844b5fbee355943da29 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 24 18:30:14 2022 +0100 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Wed, 24 Aug 2022 19:45:05 +0200
parents 90a966f5c77a
children b2412874362f
comparison
equal deleted inserted replaced
29839:30481eb9c6ea 29840:b15334beeaa4
1 " Support for Python indenting, see runtime/indent/python.vim 1 " Support for Python indenting, see runtime/indent/python.vim
2 2
3 let s:keepcpo= &cpo 3 let s:keepcpo= &cpo
4 set cpo&vim 4 set cpo&vim
5 5
6 " searchpair() can be slow, limit the time to 150 msec or what is put in 6 " need to inspect some old g:pyindent_* variables to be backward compatible
7 " g:pyindent_searchpair_timeout 7 let g:python_indent = extend(get(g:, 'python_indent', {}), #{
8 let s:searchpair_timeout = get(g:, 'pyindent_searchpair_timeout', 150) 8 \ closed_paren_align_last_line: v:true,
9 9 \ open_paren: get(g:, 'pyindent_open_paren', 'shiftwidth() * 2'),
10 " Identing inside parentheses can be very slow, regardless of the searchpair() 10 \ nested_paren: get(g:, 'pyindent_nested_paren', 'shiftwidth()'),
11 " timeout, so let the user disable this feature if he doesn't need it 11 \ continue: get(g:, 'pyindent_continue', 'shiftwidth() * 2'),
12 let s:disable_parentheses_indenting = get(g:, 'pyindent_disable_parentheses_indenting', v:false) 12 "\ searchpair() can be slow, limit the time to 150 msec or what is put in
13 "\ g:python_indent.searchpair_timeout
14 \ searchpair_timeout: get(g:, 'pyindent_searchpair_timeout', 150),
15 "\ Identing inside parentheses can be very slow, regardless of the searchpair()
16 "\ timeout, so let the user disable this feature if he doesn't need it
17 \ disable_parentheses_indenting: get(g:, 'pyindent_disable_parentheses_indenting', v:false),
18 \ }, 'keep')
13 19
14 let s:maxoff = 50 " maximum number of lines to look backwards for () 20 let s:maxoff = 50 " maximum number of lines to look backwards for ()
15 21
16 function s:SearchBracket(fromlnum, flags) 22 function s:SearchBracket(fromlnum, flags)
17 return searchpairpos('[[({]', '', '[])}]', a:flags, 23 return searchpairpos('[[({]', '', '[])}]', a:flags,
18 \ {-> synstack('.', col('.')) 24 \ {-> synstack('.', col('.'))
19 \ ->map({_, id -> id->synIDattr('name')}) 25 \ ->map({_, id -> id->synIDattr('name')})
20 \ ->match('\%(Comment\|Todo\|String\)$') >= 0}, 26 \ ->match('\%(Comment\|Todo\|String\)$') >= 0},
21 \ [0, a:fromlnum - s:maxoff]->max(), s:searchpair_timeout) 27 \ [0, a:fromlnum - s:maxoff]->max(), g:python_indent.searchpair_timeout)
22 endfunction 28 endfunction
23 29
24 " See if the specified line is already user-dedented from the expected value. 30 " See if the specified line is already user-dedented from the expected value.
25 function s:Dedented(lnum, expected) 31 function s:Dedented(lnum, expected)
26 return indent(a:lnum) <= a:expected - shiftwidth() 32 return indent(a:lnum) <= a:expected - shiftwidth()
36 " line it up with that one, otherwise add two 'shiftwidth' 42 " line it up with that one, otherwise add two 'shiftwidth'
37 if getline(a:lnum - 1) =~ '\\$' 43 if getline(a:lnum - 1) =~ '\\$'
38 if a:lnum > 1 && getline(a:lnum - 2) =~ '\\$' 44 if a:lnum > 1 && getline(a:lnum - 2) =~ '\\$'
39 return indent(a:lnum - 1) 45 return indent(a:lnum - 1)
40 endif 46 endif
41 return indent(a:lnum - 1) + (exists("g:pyindent_continue") ? eval(g:pyindent_continue) : (shiftwidth() * 2)) 47 return indent(a:lnum - 1) + get(g:, 'pyindent_continue', g:python_indent.continue)->eval()
42 endif 48 endif
43 49
44 " If the start of the line is in a string don't change the indent. 50 " If the start of the line is in a string don't change the indent.
45 if has('syntax_items') 51 if has('syntax_items')
46 \ && synIDattr(synID(a:lnum, 1, 1), "name") =~ "String$" 52 \ && synIDattr(synID(a:lnum, 1, 1), "name") =~ "String$"
53 if plnum == 0 59 if plnum == 0
54 " This is the first non-empty line, use zero indent. 60 " This is the first non-empty line, use zero indent.
55 return 0 61 return 0
56 endif 62 endif
57 63
58 if s:disable_parentheses_indenting == 1 64 if g:python_indent.disable_parentheses_indenting == 1
59 let plindent = indent(plnum) 65 let plindent = indent(plnum)
60 let plnumstart = plnum 66 let plnumstart = plnum
61 else 67 else
62 " Indent inside parens. 68 " Indent inside parens.
63 " Align with the open paren unless it is at the end of the line. 69 " Align with the open paren unless it is at the end of the line.
68 " 400) 74 " 400)
69 " open_paren_at_EOL( 75 " open_paren_at_EOL(
70 " 100, 200, 300, 400) 76 " 100, 200, 300, 400)
71 call cursor(a:lnum, 1) 77 call cursor(a:lnum, 1)
72 let [parlnum, parcol] = s:SearchBracket(a:lnum, 'nbW') 78 let [parlnum, parcol] = s:SearchBracket(a:lnum, 'nbW')
73 if parlnum > 0 && parcol != col([parlnum, '$']) - 1 79 if parlnum > 0
74 return parcol 80 if parcol != col([parlnum, '$']) - 1
81 return parcol
82 elseif getline(a:lnum) =~ '^\s*[])}]' && !g:python_indent.closed_paren_align_last_line
83 return indent(parlnum)
84 endif
75 endif 85 endif
76 86
77 call cursor(plnum, 1) 87 call cursor(plnum, 1)
78 88
79 " If the previous line is inside parenthesis, use the indent of the starting 89 " If the previous line is inside parenthesis, use the indent of the starting
121 else 131 else
122 if p == plnum 132 if p == plnum
123 " When the start is inside parenthesis, only indent one 'shiftwidth'. 133 " When the start is inside parenthesis, only indent one 'shiftwidth'.
124 let [pp, _] = s:SearchBracket(a:lnum, 'bW') 134 let [pp, _] = s:SearchBracket(a:lnum, 'bW')
125 if pp > 0 135 if pp > 0
126 return indent(plnum) + (exists("g:pyindent_nested_paren") ? eval(g:pyindent_nested_paren) : shiftwidth()) 136 return indent(plnum)
137 \ + get(g:, 'pyindent_nested_paren', g:python_indent.nested_paren)->eval()
127 endif 138 endif
128 return indent(plnum) + (exists("g:pyindent_open_paren") ? eval(g:pyindent_open_paren) : (shiftwidth() * 2)) 139 return indent(plnum)
140 \ + get(g:, 'pyindent_open_paren', g:python_indent.open_paren)->eval()
129 endif 141 endif
130 if plnumstart == p 142 if plnumstart == p
131 return indent(plnum) 143 return indent(plnum)
132 endif 144 endif
133 return plindent 145 return plindent