diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-05-12 22:49:12 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-05-12 22:49:12 +0200 |
commit | 47e13953ffdbb9f163b901196dec8c2100b72edd (patch) | |
tree | cc2251dbffe417d931b2c234f686e58d5c61f9d8 /runtime/indent/python.vim | |
parent | 9e6ba8cbef2b2363f1d0a0e2c2a8d21c3b987416 (diff) |
Update runtime files
Diffstat (limited to 'runtime/indent/python.vim')
-rw-r--r-- | runtime/indent/python.vim | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/runtime/indent/python.vim b/runtime/indent/python.vim index e53987a0de..f9236e63c7 100644 --- a/runtime/indent/python.vim +++ b/runtime/indent/python.vim @@ -28,6 +28,11 @@ set cpo&vim let s:maxoff = 50 " maximum number of lines to look backwards for () +" See if the specified line is already user-dedented from the expected value. +function s:Dedented(lnum, expected) + return indent(a:lnum) <= a:expected - shiftwidth() +endfunction + function GetPythonIndent(lnum) " If this line is explicitly joined: If the previous line was also joined, @@ -158,12 +163,12 @@ function GetPythonIndent(lnum) " If the previous line was a stop-execution statement... if getline(plnum) =~ '^\s*\(break\|continue\|raise\|return\|pass\)\>' " See if the user has already dedented - if indent(a:lnum) > indent(plnum) - shiftwidth() - " If not, recommend one dedent - return indent(plnum) - shiftwidth() + if s:Dedented(a:lnum, indent(plnum)) + " If so, trust the user + return -1 endif - " Otherwise, trust the user - return -1 + " If not, recommend one dedent + return indent(plnum) - shiftwidth() endif " If the current line begins with a keyword that lines up with "try" @@ -191,7 +196,7 @@ function GetPythonIndent(lnum) endif " Or the user has already dedented - if indent(a:lnum) <= plindent - shiftwidth() + if s:Dedented(a:lnum, plindent) return -1 endif @@ -203,7 +208,12 @@ function GetPythonIndent(lnum) " + c) " here if parlnum > 0 - return plindent + " ...unless the user has already dedented + if s:Dedented(a:lnum, plindent) + return -1 + else + return plindent + endif endif return -1 |