Skip to content

Commit

Permalink
Improve indent for ...
Browse files Browse the repository at this point in the history
  • Loading branch information
hattya committed May 21, 2023
1 parent decdfda commit 338de5d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion indent/python.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
" Vim indent file
" Language: Python
" Author: Akinori Hattori <hattya@gmail.com>
" Last Change: 2022-09-27
" Last Change: 2023-05-21
" License: MIT License

if exists('b:did_indent')
Expand Down Expand Up @@ -33,6 +33,7 @@ let s:compound_stmts = {
\ '^\s*\<finally\>': '\v^\s*<%(try|except|else)>',
\}
let s:dedent = '\v^\s*<%(pass|return|raise|break|continue)>'
let s:ellipsis = '\v^\s*\.{3}\.@!'
let s:lcont = '\\$'
let s:syn_skip = '\v\c%(Comment|Quotes|String)$'
let s:syn_str = '\v\c%(Quotes|String)$'
Expand Down Expand Up @@ -134,6 +135,9 @@ function! GetPEP8PythonIndent() abort
elseif ll =~# s:dedent
" simple statement
let ind -= shiftwidth()
elseif ll =~# s:ellipsis
" ellipsis
let ind -= shiftwidth()
elseif getline(v:lnum - 1) =~# s:lcont
" line continuation
if s:is_compound_stmt(ll)
Expand Down
14 changes: 14 additions & 0 deletions test/indent.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,20 @@ Describe filetype indent
\]
Assert Equals(Insert(in), Buffer(out))
End

It decreases the indent level after ellipsis
let in = "def spam():\<CR>...\<CR>"
let in .= "def eggs():\<CR>....\<CR>"
let in .= "def ham():"
let out = [
\ 'def spam():',
\ ' ...',
\ 'def eggs():',
\ ' ....',
\ ' def ham():',
\]
Assert Equals(Insert(in), Buffer(out))
End
End

Describe if statement
Expand Down

0 comments on commit 338de5d

Please sign in to comment.