neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 8eba81182afcd6cea025c8eafc04533c3292e97c
parent 6e3883adb82b64acd04da7936abb4addba886284
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Thu,  8 Jan 2026 08:46:25 +0800

vim-patch:5eb10c5: runtime(xml): update XML runtime files

closes: vim/vim#19112

https://github.com/vim/vim/commit/5eb10c5359e05338050819b8229bd4c8af36d365

Co-authored-by: Christian Brabandt <cb@256bit.org>

Diffstat:
Mruntime/autoload/xmlformat.vim | 24++++++++++++++++--------
Mruntime/ftplugin/xml.vim | 19+++++++------------
Mruntime/indent/xml.vim | 30+++++++++++++++++++++++++++++-
3 files changed, 52 insertions(+), 21 deletions(-)

diff --git 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 <cb@256bit.org> " 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) + let nextmatch = match(list, '^\s*$\|<[/]\?[^>]*>', current) if nextmatch > -1 - let line .= ' '. join(list[(current + 1):(nextmatch-1)], " ") - call remove(list, current+1, 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>', 'tag content</tag>'] @@ -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 @@ -1,12 +1,11 @@ " Vim filetype plugin file " Language: xml " Maintainer: Christian Brabandt <cb@256bit.org> -" Last Changed: Dec 07th, 2018 -" 2024 Jan 14 by Vim Project (browsefilter) -" 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('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 <dwsharp at users dot sourceforge dot net> +" 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(<f-args>) 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 @@ -88,7 +88,9 @@ endfun " [-- return the sum of indents of a:lnum --] fun! <SID>XmlIndentSum(line, style, add) - if <SID>IsXMLContinuation(a:line) && a:style == 0 && !<SID>IsXMLEmptyClosingTag(a:line) + if <SID>IsXMLContinuation(a:line) && + \ a:style == 0 && + \ !<SID>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 <i>inline tags</i>' + if (match(curline, '<\([:a-zA-Z_]\+\)[^>]*>.*</\1>') > -1) + return pind + endif + endif + + if curline =~ '^\s*</[a-zA-Z_]>' + return <SID>ReturnIndentForMatchingTag(curline) endif " Get indent from previous tag line @@ -181,6 +194,21 @@ func! <SID>IsXMLEmptyClosingTag(line) return a:line =~? '<[^>]*/>\s*$' endfunc +func! <SID>ReturnIndentForMatchingTag(line) + " For a line with just a simple closing tag + " get the indent from a matching opening tag + if a:line =~? '^\s*</[a-z_]*>' + let _c = getcursorpos() + let pat = matchstr(a:line, '^\s*</\zs[a-z_]\+\ze>') + " position cursor before the opening tag + norm! 0 + " get the indent from the matching opening tag + let match_line = searchpair('<' .. pat .. '>', '', '</' .. 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! <SID>XmlIndentComment(lnum)