From 2cdbbe50a4a695004adce50d7502869bb2410928 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 1 Aug 2019 22:45:59 +0200 Subject: vim-patch:63b74a8362b1 Update runtime files. https://github.com/vim/vim/commit/63b74a8362b14576b21d342dc424d0396ca8ea27 --- runtime/indent/xml.vim | 63 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 18 deletions(-) (limited to 'runtime/indent/xml.vim') 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 " Previous Maintainer: Johannes Zellner " 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! XmlIndentSynCheck(lnum) endfun " [-- return the sum of indents of a:lnum --] -fun! XmlIndentSum(lnum, style, add) - let line = getline(a:lnum) - if a:style == match(line, '^\s*XmlIndentSum(line, style, add) + if 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 HasNoTagEnd(a:line) + " no complete tag, return initial indent + return a:add + endif + if a:style == match(a:line, '^\s*XmlIndentWithPattern(line, b:xml_indent_open) - \ - XmlIndentWithPattern(line, b:xml_indent_close) - \ - XmlIndentWithPattern(line, '.\{-}/>'))) + a:add + \ (XmlIndentWithPattern(a:line, b:xml_indent_open) + \ - XmlIndentWithPattern(a:line, b:xml_indent_close) + \ - 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: + " 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 = XmlIndentSynCheck(plnum) + let check_lnum = XmlIndentSynCheck(ptag) let check_alnum = 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 XmlIndentComment(a:lnum) endif + let pline = getline(ptag) + let pind = indent(ptag) " Get indent from previous tag line - let ind = XmlIndentSum(ptag, -1, indent(ptag)) + let ind = XmlIndentSum(pline, -1, pind) + let t_ind = ind " Determine indent from current line - let ind = XmlIndentSum(a:lnum, 0, ind) + let ind = XmlIndentSum(getline(a:lnum), 0, ind) return ind endfun +func! IsXMLContinuation(line) + " Checks, whether or not the line matches a start-of-tag + return a:line !~ '^\s*<' +endfunc + +func! 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! 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) =~ '' " end of comment, same as start of comment - return indent(search('