runtime(xml): update XML runtime files
Commit:
https://github.com/vim/vim/commit/5eb10c5359e05338050819b8229bd4c8af36d365
Author: Christian Brabandt <[email protected]>
Date: Wed Jan 7 21:54:51 2026 +0000
runtime(xml): update XML runtime files
closes: https://github.com/vim/vim/issues/19112
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/runtime/autoload/xmlformat.vim b/runtime/autoload/xmlformat.vim
index c89c8784b..c541e6575 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 <[email protected]>
" 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>', '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
index 83c528eff..6256d171e 100644
--- a/runtime/ftplugin/xml.vim
+++ b/runtime/ftplugin/xml.vim
@@ -1,12 +1,11 @@
" Vim filetype plugin file
" Language: xml
" Maintainer: Christian Brabandt <[email protected]>
-" Last Changed: Dec 07th, 2018
-" 2024 Jan 14 by Vim Project (browsefilter)
-" 2024 May 23 by Riley Bruins <[email protected]>
('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) *.xml
" .
\ "DTD Files (*.dtd) *.dtd
" .
- \ "XSD Files (*.xsd) *.xsd
"
- if has("win32")
- let b:browsefilter .= "All Files (*.*) *
"
- else
- let b:browsefilter .= "All Files (*) *
"
- endif
+ \ "XSD Files (*.xsd) *.xsd
" .
+ \ "All Files (*.*) *.*
"
endif
" Undo the stuff we changed.
diff --git a/runtime/indent/xml.vim b/runtime/indent/xml.vim
index 5bf53ad1f..db71fc03c 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! <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)
+ 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)
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1vdbZW-001bK7-8e%40256bit.org.