From: Christian Brabandt Date: Wed, 7 Jan 2026 21:54:51 +0000 (+0000) Subject: runtime(xml): update XML runtime files X-Git-Tag: v9.1.2064~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5eb10c5359e05338050819b8229bd4c8af36d365;p=thirdparty%2Fvim.git runtime(xml): update XML runtime files closes: #19112 Signed-off-by: Christian Brabandt --- diff --git a/runtime/autoload/xmlformat.vim b/runtime/autoload/xmlformat.vim index c89c8784b9..c541e65755 100644 --- a/runtime/autoload/xmlformat.vim +++ b/runtime/autoload/xmlformat.vim @@ -1,5 +1,5 @@ " Vim plugin for formatting XML -" Last Change: 2020 Jan 06 +" Last Change: 2023 March 15th " Version: 0.3 " Author: Christian Brabandt " Repository: https://github.com/chrisbra/vim-xml-ftplugin @@ -37,13 +37,17 @@ func! xmlformat#Format() abort " Keep empty input lines? if empty(line) call add(result, '') + let current += 1 continue elseif line !~# '<[/]\?[^>]*>' - let nextmatch = match(list, '<[/]\?[^>]*>', current) - if nextmatch > -1 - let line .= ' '. join(list[(current + 1):(nextmatch-1)], " ") - call remove(list, current+1, nextmatch-1) + let nextmatch = match(list, '^\s*$\|<[/]\?[^>]*>', current) + if nextmatch > -1 + let lineEnd = nextmatch + else + let lineEnd = len(list) endif + let line .= ' '. join(list[(current + 1):(lineEnd-1)], " ") + call remove(list, current+1, lineEnd-1) endif " split on `>`, but don't split on very first opening < " this means, items can be like ['', 'tag content'] @@ -79,9 +83,13 @@ func! xmlformat#Format() abort if s:EndTag(t[1]) call s:DecreaseIndent() endif - "for y in t[1:] - let result+=s:FormatContent(t[1:]) - "endfor + let result+=s:FormatContent(t[1:]) + if s:IsTag(t[1]) + let lastitem = t[1] + continue + endif + elseif s:IsComment(item) + let result+=s:FormatContent([item]) else call add(result, s:Indent(item)) endif @@ -94,7 +102,7 @@ func! xmlformat#Format() abort if !empty(result) let lastprevline = getline(v:lnum + count_orig) let delete_lastline = v:lnum + count_orig - 1 == line('$') - exe v:lnum. ",". (v:lnum + count_orig - 1). 'd' + exe 'silent ' .. v:lnum. ",". (v:lnum + count_orig - 1). 'd' call append(v:lnum - 1, result) " Might need to remove the last line, if it became empty because of the " append() call diff --git a/runtime/ftplugin/xml.vim b/runtime/ftplugin/xml.vim index 83c528eff2..6256d171ed 100644 --- a/runtime/ftplugin/xml.vim +++ b/runtime/ftplugin/xml.vim @@ -1,12 +1,11 @@ " Vim filetype plugin file " Language: xml " Maintainer: Christian Brabandt -" Last Changed: Dec 07th, 2018 -" 2024 Jan 14 by Vim Project (browsefilter) -" 2024 May 23 by Riley Bruins ('commentstring') -" Repository: https://github.com/chrisbra/vim-xml-ftplugin -" Previous Maintainer: Dan Sharp -" URL: http://dwsharp.users.sourceforge.net/vim/ftplugin +" Last Changed: 2024 May 24 +" Repository: https://github.com/chrisbra/vim-xml-ftplugin +" Previously +" Maintainer: Dan Sharp +" URL: http://dwsharp.users.sourceforge.net/vim/ftplugin if exists("b:did_ftplugin") | finish | endif let b:did_ftplugin = 1 @@ -54,12 +53,8 @@ command! -nargs=? XMLent call xmlcomplete#CreateEntConnection() if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") let b:browsefilter="XML Files (*.xml)\t*.xml\n" . \ "DTD Files (*.dtd)\t*.dtd\n" . - \ "XSD Files (*.xsd)\t*.xsd\n" - if has("win32") - let b:browsefilter .= "All Files (*.*)\t*\n" - else - let b:browsefilter .= "All Files (*)\t*\n" - endif + \ "XSD Files (*.xsd)\t*.xsd\n" . + \ "All Files (*.*)\t*.*\n" endif " Undo the stuff we changed. diff --git a/runtime/indent/xml.vim b/runtime/indent/xml.vim index 5bf53ad1f8..db71fc03ca 100644 --- a/runtime/indent/xml.vim +++ b/runtime/indent/xml.vim @@ -88,7 +88,9 @@ endfun " [-- return the sum of indents of a:lnum --] fun! XmlIndentSum(line, style, add) - if IsXMLContinuation(a:line) && a:style == 0 && !IsXMLEmptyClosingTag(a:line) + if IsXMLContinuation(a:line) && + \ a:style == 0 && + \ !IsXMLEmptyClosingTag(a:line) " no complete tag, add one additional indent level " but only for the current line return a:add + shiftwidth() @@ -157,6 +159,17 @@ fun! XmlIndentGet(lnum, use_syntax_check) " no extra indent, looks like a text continuation line return pind endif + elseif empty(syn_name_start) && syn_name_end =~? 'xmlTag' + " Special case: such a line, shouldn't be indented, just because it + " ends with a tag + " 'foobar inline tags' + if (match(curline, '<\([:a-zA-Z_]\+\)[^>]*>.*') > -1) + return pind + endif + endif + + if curline =~ '^\s*' + return ReturnIndentForMatchingTag(curline) endif " Get indent from previous tag line @@ -181,6 +194,21 @@ func! IsXMLEmptyClosingTag(line) return a:line =~? '<[^>]*/>\s*$' endfunc +func! ReturnIndentForMatchingTag(line) + " For a line with just a simple closing tag + " get the indent from a matching opening tag + if a:line =~? '^\s*' + let _c = getcursorpos() + let pat = matchstr(a:line, '^\s*') + " position cursor before the opening tag + norm! 0 + " get the indent from the matching opening tag + let match_line = searchpair('<' .. pat .. '>', '', '', 'bn') + call setpos('.', _c) + return indent(match_line) + endif +endfunc + " return indent for a commented line, " the middle part might be indented one additional level func! XmlIndentComment(lnum)