summaryrefslogtreecommitdiffstats
path: root/runtime/indent
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-02-22 15:24:03 +0100
committerBram Moolenaar <Bram@vim.org>2019-02-22 15:24:03 +0100
commitf6b401090e816b4216f783a9b85d21d9ad134ff8 (patch)
treeb7831ffc83dee622fd5a800f7b5c90b3666379c3 /runtime/indent
parent55d3bdbbe2bfc7a78b4aa17763788dbddf87cab0 (diff)
Update runtime files
Diffstat (limited to 'runtime/indent')
-rw-r--r--runtime/indent/python.vim104
1 files changed, 57 insertions, 47 deletions
diff --git a/runtime/indent/python.vim b/runtime/indent/python.vim
index 7ab3cb9f50..e53987a0de 100644
--- a/runtime/indent/python.vim
+++ b/runtime/indent/python.vim
@@ -2,7 +2,7 @@
" Language: Python
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Original Author: David Bustos <bustos@caltech.edu>
-" Last Change: 2013 Jul 9
+" Last Change: 2019 Feb 21
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
@@ -53,58 +53,68 @@ function GetPythonIndent(lnum)
return 0
endif
- " searchpair() can be slow sometimes, limit the time to 100 msec or what is
- " put in g:pyindent_searchpair_timeout
- let searchpair_stopline = 0
- let searchpair_timeout = get(g:, 'pyindent_searchpair_timeout', 150)
-
- " If the previous line is inside parenthesis, use the indent of the starting
- " line.
- " Trick: use the non-existing "dummy" variable to break out of the loop when
- " going too far back.
call cursor(plnum, 1)
- let parlnum = searchpair('(\|{\|\[', '', ')\|}\|\]', 'nbW',
- \ "line('.') < " . (plnum - s:maxoff) . " ? dummy :"
- \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
- \ . " =~ '\\(Comment\\|Todo\\|String\\)$'",
- \ searchpair_stopline, searchpair_timeout)
- if parlnum > 0
- let plindent = indent(parlnum)
- let plnumstart = parlnum
- else
+
+ " 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 disable_parentheses_indenting = get(g:, "pyindent_disable_parentheses_indenting", 0)
+
+ if disable_parentheses_indenting == 1
let plindent = indent(plnum)
let plnumstart = plnum
- endif
-
+ else
+ " searchpair() can be slow sometimes, limit the time to 150 msec or what is
+ " put in g:pyindent_searchpair_timeout
+ let searchpair_stopline = 0
+ let searchpair_timeout = get(g:, 'pyindent_searchpair_timeout', 150)
+
+ " If the previous line is inside parenthesis, use the indent of the starting
+ " line.
+ " Trick: use the non-existing "dummy" variable to break out of the loop when
+ " going too far back.
+ let parlnum = searchpair('(\|{\|\[', '', ')\|}\|\]', 'nbW',
+ \ "line('.') < " . (plnum - s:maxoff) . " ? dummy :"
+ \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
+ \ . " =~ '\\(Comment\\|Todo\\|String\\)$'",
+ \ searchpair_stopline, searchpair_timeout)
+ if parlnum > 0
+ let plindent = indent(parlnum)
+ let plnumstart = parlnum
+ else
+ let plindent = indent(plnum)
+ let plnumstart = plnum
+ endif
- " When inside parenthesis: If at the first line below the parenthesis add
- " two 'shiftwidth', otherwise same as previous line.
- " i = (a
- " + b
- " + c)
- call cursor(a:lnum, 1)
- let p = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW',
- \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
- \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
- \ . " =~ '\\(Comment\\|Todo\\|String\\)$'",
- \ searchpair_stopline, searchpair_timeout)
- 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\\)$'",
- \ searchpair_stopline, searchpair_timeout)
- if pp > 0
- return indent(plnum) + (exists("g:pyindent_nested_paren") ? eval(g:pyindent_nested_paren) : shiftwidth())
+ " When inside parenthesis: If at the first line below the parenthesis add
+ " two 'shiftwidth', otherwise same as previous line.
+ " i = (a
+ " + b
+ " + c)
+ call cursor(a:lnum, 1)
+ let p = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW',
+ \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
+ \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
+ \ . " =~ '\\(Comment\\|Todo\\|String\\)$'",
+ \ searchpair_stopline, searchpair_timeout)
+ 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\\)$'",
+ \ searchpair_stopline, searchpair_timeout)
+ if pp > 0
+ return indent(plnum) + (exists("g:pyindent_nested_paren") ? eval(g:pyindent_nested_paren) : shiftwidth())
+ endif
+ return indent(plnum) + (exists("g:pyindent_open_paren") ? eval(g:pyindent_open_paren) : (shiftwidth() * 2))
endif
- return indent(plnum) + (exists("g:pyindent_open_paren") ? eval(g:pyindent_open_paren) : (shiftwidth() * 2))
- endif
- if plnumstart == p
- return indent(plnum)
+ if plnumstart == p
+ return indent(plnum)
+ endif
+ return plindent
endif
- return plindent
+
endif