aboutsummaryrefslogtreecommitdiff
path: root/runtime/indent
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-08-02 15:10:04 +0200
committerGitHub <noreply@github.com>2019-08-02 15:10:04 +0200
commit7cf0119c6857846fd1f254feb237f6137f140856 (patch)
tree1fb4d7c43a6cd86d7758bc0dc2d2aa23240b5947 /runtime/indent
parentb92a5bc3c4bdfddfc21638556ace6ef3fd90155c (diff)
parent532ee54a42a294073e8b441f3ce5a050d16963a2 (diff)
downloadrneovim-7cf0119c6857846fd1f254feb237f6137f140856.tar.gz
rneovim-7cf0119c6857846fd1f254feb237f6137f140856.tar.bz2
rneovim-7cf0119c6857846fd1f254feb237f6137f140856.zip
Merge #10666 from justinmk/vim-runtime
vim-patch: runtime updates
Diffstat (limited to 'runtime/indent')
-rw-r--r--runtime/indent/awk.vim2
-rw-r--r--runtime/indent/cobol.vim11
-rw-r--r--runtime/indent/html.vim11
-rw-r--r--runtime/indent/mma.vim2
-rw-r--r--runtime/indent/python.vim104
-rw-r--r--runtime/indent/rmd.vim2
-rw-r--r--runtime/indent/sh.vim28
-rw-r--r--runtime/indent/testdir/html.ok6
-rw-r--r--runtime/indent/testdir/xml.ok4
-rw-r--r--runtime/indent/xml.vim63
10 files changed, 153 insertions, 80 deletions
diff --git a/runtime/indent/awk.vim b/runtime/indent/awk.vim
index aad73ee71f..e65331977c 100644
--- a/runtime/indent/awk.vim
+++ b/runtime/indent/awk.vim
@@ -47,7 +47,7 @@ endif
function! GetAwkIndent()
- " Find previous line and get it's indentation
+ " Find previous line and get its indentation
let prev_lineno = s:Get_prev_line( v:lnum )
if prev_lineno == 0
return 0
diff --git a/runtime/indent/cobol.vim b/runtime/indent/cobol.vim
index c08444ac40..590a729df4 100644
--- a/runtime/indent/cobol.vim
+++ b/runtime/indent/cobol.vim
@@ -1,7 +1,12 @@
" Vim indent file
" Language: cobol
-" Author: Tim Pope <vimNOSPAM@tpope.info>
+" Maintainer: Ankit Jain <ajatkj@yahoo.co.in>
+" (formerly Tim Pope <vimNOSPAM@tpope.info>)
" $Id: cobol.vim,v 1.1 2007/05/05 18:08:19 vimboss Exp $
+" Last Update: By Ankit Jain on 22.03.2019
+" Ankit Jain 22.03.2019 Changes & fixes:
+" Allow chars in 1st 6 columns
+" #C22032019
if exists("b:did_indent")
finish
@@ -66,7 +71,9 @@ function! GetCobolIndent(lnum) abort
let ashft = minshft + 1
let bshft = ashft + 4
" (Obsolete) numbered lines
- if getline(a:lnum) =~? '^\s*\d\{6\}\%($\|[ */$CD-]\)'
+ " #C22032019: Columns 1-6 could have alphabets as well as numbers
+ "if getline(a:lnum) =~? '^\s*\d\{6\}\%($\|[ */$CD-]\)'
+ if getline(a:lnum) =~? '^\s*[a-zA-Z0-9]\{6\}\%($\|[ */$CD-]\)'
return 0
endif
let cline = s:stripped(a:lnum)
diff --git a/runtime/indent/html.vim b/runtime/indent/html.vim
index 1a8177050a..1d2043ae9e 100644
--- a/runtime/indent/html.vim
+++ b/runtime/indent/html.vim
@@ -2,7 +2,7 @@
" Header: "{{{
" Maintainer: Bram Moolenaar
" Original Author: Andy Wokula <anwoku@yahoo.de>
-" Last Change: 2018 Mar 28
+" Last Change: 2019 Mar 20
" Version: 1.0
" Description: HTML indent script with cached state for faster indenting on a
" range of lines.
@@ -902,12 +902,19 @@ func! s:InsideTag(foundHtmlString)
"{{{
if a:foundHtmlString
" Inside an attribute string.
- " Align with the previous line or use an external function.
+ " Align with the opening quote or use an external function.
let lnum = v:lnum - 1
if lnum > 1
if exists('b:html_indent_tag_string_func')
return b:html_indent_tag_string_func(lnum)
endif
+ " If there is a double quote in the previous line, indent with the
+ " character after it.
+ if getline(lnum) =~ '"'
+ call cursor(lnum, 0)
+ normal f"
+ return virtcol('.')
+ endif
return indent(lnum)
endif
endif
diff --git a/runtime/indent/mma.vim b/runtime/indent/mma.vim
index 8298ad98cd..a76fa8ede0 100644
--- a/runtime/indent/mma.vim
+++ b/runtime/indent/mma.vim
@@ -57,7 +57,7 @@ function GetMmaIndent()
if getline(v:lnum) =~ '[^[]*]\s*$'
" move to the closing bracket
call search(']','bW')
- " and find it's partner's indent
+ " and find its partner's indent
let ind = indent(searchpair('\[','',']','bWn'))
" same for ( blocks
elseif getline(v:lnum) =~ '[^(]*)$'
diff --git a/runtime/indent/python.vim b/runtime/indent/python.vim
index 7ab3cb9f50..e53987a0de 100644
--- 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)
-
- " 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))
- endif
- if plnumstart == p
- return indent(plnum)
+ if plnumstart == p
+ return indent(plnum)
+ endif
+ return plindent
endif
- return plindent
+
endif
diff --git a/runtime/indent/rmd.vim b/runtime/indent/rmd.vim
index 182b07cbaa..83fe4e4fed 100644
--- a/runtime/indent/rmd.vim
+++ b/runtime/indent/rmd.vim
@@ -39,7 +39,7 @@ endfunction
function s:GetYamlIndent()
let pline = getline(v:lnum - 1)
if pline =~ ':\s*$'
- return indent(v:lnum) + &sw
+ return indent(v:lnum) + shiftwidth()
elseif pline =~ '^\s*- '
return indent(v:lnum) + 2
endif
diff --git a/runtime/indent/sh.vim b/runtime/indent/sh.vim
index c93be31958..148a86ed67 100644
--- a/runtime/indent/sh.vim
+++ b/runtime/indent/sh.vim
@@ -3,10 +3,18 @@
" Maintainer: Christian Brabandt <cb@256bit.org>
" Original Author: Nikolai Weibull <now@bitwi.se>
" Previous Maintainer: Peter Aronoff <telemachus@arpinum.org>
-" Latest Revision: 2019-02-02
+" Latest Revision: 2019-04-27
" License: Vim (see :h license)
" Repository: https://github.com/chrisbra/vim-sh-indent
" Changelog:
+" 20190428 - De-indent fi correctly when typing with
+" https://github.com/chrisbra/vim-sh-indent/issues/15
+" 20190325 - Indent fi; correctly
+" https://github.com/chrisbra/vim-sh-indent/issues/14
+" 20190319 - Indent arrays (only zsh and bash)
+" https://github.com/chrisbra/vim-sh-indent/issues/13
+" 20190316 - Make use of searchpairpos for nested if sections
+" fixes https://github.com/chrisbra/vim-sh-indent/issues/11
" 20190201 - Better check for closing if sections
" 20180724 - make check for zsh syntax more rigid (needs word-boundaries)
" 20180326 - better support for line continuation
@@ -86,6 +94,12 @@ function! GetShIndent()
if line !~ '}\s*\%(#.*\)\=$'
let ind += s:indent_value('default')
endif
+ " array (only works for zsh or bash)
+ elseif s:is_array(line) && line !~ ')\s*$' && (&ft is# 'zsh' || s:is_bash())
+ let ind += s:indent_value('continuation-line')
+ " end of array
+ elseif curline =~ '^\s*)$'
+ let ind -= s:indent_value('continuation-line')
elseif s:is_continuation_line(line)
if pnum == 0 || !s:is_continuation_line(pline)
let ind += s:indent_value('continuation-line')
@@ -114,8 +128,8 @@ function! GetShIndent()
let line = curline
" Current line is a endif line, so get indent from start of "if condition" line
" TODO: should we do the same for other "end" lines?
- if curline =~ '^\s*\%(fi\)\s*\%(#.*\)\=$'
- let previous_line = search('if.\{-\};\s*then\s*\%(#.*\)\=$', 'bnW')
+ if curline =~ '^\s*\%(fi\);\?\s*\%(#.*\)\=$'
+ let previous_line = searchpair('\<if\>', '', '\<fi\>\zs', 'bnW')
if previous_line > 0
let ind = indent(previous_line)
endif
@@ -179,6 +193,10 @@ function! s:is_function_definition(line)
\ a:line =~ '^\s*function\s*\w\S\+\s*\%(()\)\?\s*{'
endfunction
+function! s:is_array(line)
+ return a:line =~ '^\s*\<\k\+\>=('
+endfunction
+
function! s:is_case_label(line, pnum)
if a:line !~ '^\s*(\=.*)'
return 0
@@ -272,5 +290,9 @@ function! s:is_end_expression(line)
return a:line =~ '\<\%(fi\|esac\|done\|end\)\>\s*\%(#.*\)\=$'
endfunction
+function! s:is_bash()
+ return get(g:, 'is_bash', 0) || get(b:, 'is_bash', 0)
+endfunction
+
let &cpo = s:cpo_save
unlet s:cpo_save
diff --git a/runtime/indent/testdir/html.ok b/runtime/indent/testdir/html.ok
index 524d57bb6c..ad819333cc 100644
--- a/runtime/indent/testdir/html.ok
+++ b/runtime/indent/testdir/html.ok
@@ -9,17 +9,17 @@
</div>
<div
- class="foo bar">
+ class="foo bar">
text
</div>
<div class="foo bar"
- data="something">
+ data="something">
text
</div>
<div class="foo
- bar">
+ bar">
text
</div>
diff --git a/runtime/indent/testdir/xml.ok b/runtime/indent/testdir/xml.ok
index 529198572a..cfdf701c11 100644
--- a/runtime/indent/testdir/xml.ok
+++ b/runtime/indent/testdir/xml.ok
@@ -10,11 +10,11 @@
<!-- text comment -->
<!--
- text comment
+ text comment
-->
</tag1>
<!--
- text comment
+ text comment
end coment -->
</tag0>
<!-- END_INDENT -->
diff --git a/runtime/indent/xml.vim b/runtime/indent/xml.vim
index 29069bab84..ad22de1d50 100644
--- a/runtime/indent/xml.vim
+++ b/runtime/indent/xml.vim
@@ -1,9 +1,11 @@
" Language: xml
" Repository: https://github.com/chrisbra/vim-xml-ftplugin
-" Last Changed: Jan 28, 2019
+" Last Changed: Feb 04, 2019
" Maintainer: Christian Brabandt <cb@256bit.org>
" Previous Maintainer: Johannes Zellner <johannes@zellner.org>
" Last Change:
+" 20190204 - correctly handle wrap tags
+" https://github.com/chrisbra/vim-xml-ftplugin/issues/5
" 20190128 - Make sure to find previous tag
" https://github.com/chrisbra/vim-xml-ftplugin/issues/4
" 20181116 - Fix indentation when tags start with a colon or an underscore
@@ -74,13 +76,20 @@ fun! <SID>XmlIndentSynCheck(lnum)
endfun
" [-- return the sum of indents of a:lnum --]
-fun! <SID>XmlIndentSum(lnum, style, add)
- let line = getline(a:lnum)
- if a:style == match(line, '^\s*</')
+fun! <SID>XmlIndentSum(line, style, add)
+ if <SID>IsXMLContinuation(a:line) && a:style == 0
+ " no complete tag, add one additional indent level
+ " but only for the current line
+ return a:add + shiftwidth()
+ elseif <SID>HasNoTagEnd(a:line)
+ " no complete tag, return initial indent
+ return a:add
+ endif
+ if a:style == match(a:line, '^\s*</')
return (shiftwidth() *
- \ (<SID>XmlIndentWithPattern(line, b:xml_indent_open)
- \ - <SID>XmlIndentWithPattern(line, b:xml_indent_close)
- \ - <SID>XmlIndentWithPattern(line, '.\{-}/>'))) + a:add
+ \ (<SID>XmlIndentWithPattern(a:line, b:xml_indent_open)
+ \ - <SID>XmlIndentWithPattern(a:line, b:xml_indent_close)
+ \ - <SID>XmlIndentWithPattern(a:line, '.\{-}/>'))) + a:add
else
return a:add
endif
@@ -89,19 +98,24 @@ endfun
" Main indent function
fun! XmlIndentGet(lnum, use_syntax_check)
" Find a non-empty line above the current line.
- let plnum = prevnonblank(a:lnum - 1)
- " Hit the start of the file, use zero indent.
- if plnum == 0
+ if prevnonblank(a:lnum - 1) == 0
+ " Hit the start of the file, use zero indent.
return 0
endif
" Find previous line with a tag (regardless whether open or closed,
" but always start restrict the match to a line before the current one
+ " Note: xml declaration: <?xml version="1.0"?>
+ " won't be found, as it is not a legal tag name
let ptag_pattern = '\%(.\{-}<[/:A-Z_a-z]\)'. '\%(\&\%<'. line('.').'l\)'
- let ptag = search(ptag_pattern, 'bnw')
+ let ptag = search(ptag_pattern, 'bnW')
+ " no previous tag
+ if ptag == 0
+ return 0
+ endif
let syn_name = ''
if a:use_syntax_check
- let check_lnum = <SID>XmlIndentSynCheck(plnum)
+ let check_lnum = <SID>XmlIndentSynCheck(ptag)
let check_alnum = <SID>XmlIndentSynCheck(a:lnum)
if check_lnum == 0 || check_alnum == 0
return indent(a:lnum)
@@ -113,18 +127,31 @@ fun! XmlIndentGet(lnum, use_syntax_check)
return <SID>XmlIndentComment(a:lnum)
endif
+ let pline = getline(ptag)
+ let pind = indent(ptag)
" Get indent from previous tag line
- let ind = <SID>XmlIndentSum(ptag, -1, indent(ptag))
+ let ind = <SID>XmlIndentSum(pline, -1, pind)
+ let t_ind = ind
" Determine indent from current line
- let ind = <SID>XmlIndentSum(a:lnum, 0, ind)
+ let ind = <SID>XmlIndentSum(getline(a:lnum), 0, ind)
return ind
endfun
+func! <SID>IsXMLContinuation(line)
+ " Checks, whether or not the line matches a start-of-tag
+ return a:line !~ '^\s*<'
+endfunc
+
+func! <SID>HasNoTagEnd(line)
+ " Checks whether or not the line matches '>' (so finishes a tag)
+ return a:line !~ '>\s*$'
+endfunc
+
" return indent for a commented line,
" the middle part might be indented on additional level
func! <SID>XmlIndentComment(lnum)
- let ptagopen = search(b:xml_indent_open, 'bnw')
- let ptagclose = search(b:xml_indent_close, 'bnw')
+ let ptagopen = search(b:xml_indent_open, 'bnW')
+ let ptagclose = search(b:xml_indent_close, 'bnW')
if getline(a:lnum) =~ '<!--'
" if previous tag was a closing tag, do not add
" one additional level of indent
@@ -136,10 +163,10 @@ func! <SID>XmlIndentComment(lnum)
endif
elseif getline(a:lnum) =~ '-->'
" end of comment, same as start of comment
- return indent(search('<!--', 'bnw'))
+ return indent(search('<!--', 'bnW'))
else
" middle part of comment, add one additional level
- return indent(search('<!--', 'bnw')) + shiftwidth()
+ return indent(search('<!--', 'bnW')) + shiftwidth()
endif
endfunc