aboutsummaryrefslogtreecommitdiff
path: root/runtime/indent/python.vim
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-04-28 01:33:17 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-04-28 21:29:57 -0400
commit0185625c04ee736dac36789d0cb590ecde8926e8 (patch)
tree8464e1314905bbc50cacc6939585b70a9fd744b0 /runtime/indent/python.vim
parent3d86857f28f0c9b93c5f56c8ce846ddd26ddbf38 (diff)
downloadrneovim-0185625c04ee736dac36789d0cb590ecde8926e8.tar.gz
rneovim-0185625c04ee736dac36789d0cb590ecde8926e8.tar.bz2
rneovim-0185625c04ee736dac36789d0cb590ecde8926e8.zip
vim-patch:47e13953ffdb
Update runtime files https://github.com/vim/vim/commit/47e13953ffdbb9f163b901196dec8c2100b72edd Ignore *.rej files, generated by vim-patch.sh. Source of mistakes for 1st-time contributors.
Diffstat (limited to 'runtime/indent/python.vim')
-rw-r--r--runtime/indent/python.vim24
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