diff runtime/indent/python.vim @ 15932:c3c1abe7aff2

Update runtime files commit https://github.com/vim/vim/commit/f6b401090e816b4216f783a9b85d21d9ad134ff8 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Feb 22 15:24:03 2019 +0100 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Fri, 22 Feb 2019 15:30:07 +0100
parents 4ee65b4150fd
children 7f88f6a3ed4c
line wrap: on
line diff
--- 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)
+  call cursor(plnum, 1)
 
-  " 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))
+      if plnumstart == p
+        return indent(plnum)
+      endif
+      return plindent
     endif
-    if plnumstart == p
-      return indent(plnum)
-    endif
-    return plindent
+
   endif