diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2021-05-04 19:18:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-04 19:18:16 -0400 |
commit | 4ad30f775e5564c539324b4818886f067d2ecd99 (patch) | |
tree | 97a554379bda7e5fc77e58c690db3f5a72db8c74 /runtime/indent/python.vim | |
parent | 63d8a8f4e8b02e524d85aed08aa16c5d9815598c (diff) | |
parent | d5b063aec1db95704b37a77fdbd968cb6b48cc3b (diff) | |
download | rneovim-4ad30f775e5564c539324b4818886f067d2ecd99.tar.gz rneovim-4ad30f775e5564c539324b4818886f067d2ecd99.tar.bz2 rneovim-4ad30f775e5564c539324b4818886f067d2ecd99.zip |
Merge pull request #14424 from janlazo/vim-8.1.1726
vim-patch:8.1.1726,8.2.{296,860,1827,2388,2788,2790,2801}
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 |