annotate runtime/autoload/xmlformat.vim @ 20593:89b0f161e6a6 v8.2.0850

patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe Commit: https://github.com/vim/vim/commit/95da136142628e06425f9d9eb2d1ca56a9e48feb Author: Bram Moolenaar <Bram@vim.org> Date: Sat May 30 18:37:55 2020 +0200 patch 8.2.0850: MS-Windows: exepath() works different from cmd.exe Problem: MS-Windows: exepath() works different from cmd.exe. Solution: Make exepath() work better on MS-Windows. (closes https://github.com/vim/vim/issues/6115)
author Bram Moolenaar <Bram@vim.org>
date Sat, 30 May 2020 18:45:04 +0200
parents d4deb2e50667
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Vim plugin for formatting XML
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
2 " Last Change: 2020 Jan 06
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
3 " Version: 0.3
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
4 " Author: Christian Brabandt <cb@256bit.org>
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
5 " Repository: https://github.com/chrisbra/vim-xml-ftplugin
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
6 " License: VIM License
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 " Documentation: see :h xmlformat.txt (TODO!)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 " ---------------------------------------------------------------------
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 " Load Once: {{{1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 if exists("g:loaded_xmlformat") || &cp
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 finish
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 endif
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 let g:loaded_xmlformat = 1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 let s:keepcpo = &cpo
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 set cpo&vim
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 " Main function: Format the input {{{1
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
18 func! xmlformat#Format() abort
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 " only allow reformatting through the gq command
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 " (e.g. Vim is in normal mode)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 if mode() != 'n'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 " do not fall back to internal formatting
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 return 0
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 endif
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
25 let count_orig = v:count
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 let sw = shiftwidth()
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 let prev = prevnonblank(v:lnum-1)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 let s:indent = indent(prev)/sw
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 let result = []
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 let lastitem = prev ? getline(prev) : ''
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 let is_xml_decl = 0
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
32 " go through every line, but don't join all content together and join it
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
33 " back. We might lose empty lines
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
34 let list = getline(v:lnum, (v:lnum + count_orig - 1))
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
35 let current = 0
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
36 for line in list
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
37 " Keep empty input lines?
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
38 if empty(line)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
39 call add(result, '')
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
40 continue
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
41 elseif line !~# '<[/]\?[^>]*>'
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
42 let nextmatch = match(list, '<[/]\?[^>]*>', current)
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
43 if nextmatch > -1
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
44 let line .= ' '. join(list[(current + 1):(nextmatch-1)], " ")
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
45 call remove(list, current+1, nextmatch-1)
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
46 endif
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
47 endif
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
48 " split on `>`, but don't split on very first opening <
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
49 " this means, items can be like ['<tag>', 'tag content</tag>']
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
50 for item in split(line, '.\@<=[>]\zs')
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
51 if s:EndTag(item)
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
52 call s:DecreaseIndent()
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
53 call add(result, s:Indent(item))
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
54 elseif s:EmptyTag(lastitem)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
55 call add(result, s:Indent(item))
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
56 elseif s:StartTag(lastitem) && s:IsTag(item)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
57 let s:indent += 1
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 call add(result, s:Indent(item))
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
59 else
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
60 if !s:IsTag(item)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
61 " Simply split on '<', if there is one,
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
62 " but reformat according to &textwidth
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
63 let t=split(item, '.<\@=\zs')
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
64
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
65 " if the content fits well within a single line, add it there
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
66 " so that the output looks like this:
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
67 "
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
68 " <foobar>1</foobar>
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
69 if s:TagContent(lastitem) is# s:TagContent(t[1]) && strlen(result[-1]) + strlen(item) <= s:Textwidth()
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
70 let result[-1] .= item
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
71 let lastitem = t[1]
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
72 continue
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
73 endif
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
74 " t should only contain 2 items, but just be safe here
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
75 if s:IsTag(lastitem)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
76 let s:indent+=1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
77 endif
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
78 let result+=s:FormatContent([t[0]])
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
79 if s:EndTag(t[1])
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
80 call s:DecreaseIndent()
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
81 endif
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
82 "for y in t[1:]
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
83 let result+=s:FormatContent(t[1:])
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
84 "endfor
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
85 else
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
86 call add(result, s:Indent(item))
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
87 endif
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 endif
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
89 let lastitem = item
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
90 endfor
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
91 let current += 1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
92 endfor
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
94 if !empty(result)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
95 let lastprevline = getline(v:lnum + count_orig)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
96 let delete_lastline = v:lnum + count_orig - 1 == line('$')
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
97 exe v:lnum. ",". (v:lnum + count_orig - 1). 'd'
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 call append(v:lnum - 1, result)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 " Might need to remove the last line, if it became empty because of the
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 " append() call
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 let last = v:lnum + len(result)
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
102 " do not use empty(), it returns true for `empty(0)`
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
103 if getline(last) is '' && lastprevline is '' && delete_lastline
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 exe last. 'd'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 endif
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 endif
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 " do not run internal formatter!
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 return 0
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 endfunc
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 " Check if given tag is XML Declaration header {{{1
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
112 func! s:IsXMLDecl(tag) abort
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113 return a:tag =~? '^\s*<?xml\s\?\%(version="[^"]*"\)\?\s\?\%(encoding="[^"]*"\)\? ?>\s*$'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
114 endfunc
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
115 " Return tag indented by current level {{{1
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
116 func! s:Indent(item) abort
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
117 return repeat(' ', shiftwidth()*s:indent). s:Trim(a:item)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
118 endfu
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
119 " Return item trimmed from leading whitespace {{{1
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
120 func! s:Trim(item) abort
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
121 if exists('*trim')
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
122 return trim(a:item)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 else
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 return matchstr(a:item, '\S\+.*')
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 endif
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126 endfunc
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
127 " Check if tag is a new opening tag <tag> {{{1
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
128 func! s:StartTag(tag) abort
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
129 let is_comment = s:IsComment(a:tag)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
130 return a:tag =~? '^\s*<[^/?]' && !is_comment
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
131 endfunc
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
132 " Check if tag is a Comment start {{{1
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
133 func! s:IsComment(tag) abort
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
134 return a:tag =~? '<!--'
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135 endfunc
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136 " Remove one level of indentation {{{1
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
137 func! s:DecreaseIndent() abort
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
138 let s:indent = (s:indent > 0 ? s:indent - 1 : 0)
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
139 endfunc
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
140 " Check if tag is a closing tag </tag> {{{1
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
141 func! s:EndTag(tag) abort
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
142 return a:tag =~? '^\s*</'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
143 endfunc
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
144 " Check that the tag is actually a tag and not {{{1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
145 " something like "foobar</foobar>"
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
146 func! s:IsTag(tag) abort
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147 return s:Trim(a:tag)[0] == '<'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 endfunc
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
149 " Check if tag is empty <tag/> {{{1
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
150 func! s:EmptyTag(tag) abort
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
151 return a:tag =~ '/>\s*$'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
152 endfunc
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
153 func! s:TagContent(tag) abort "{{{1
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
154 " Return content of a tag
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
155 return substitute(a:tag, '^\s*<[/]\?\([^>]*\)>\s*$', '\1', '')
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
156 endfunc
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
157 func! s:Textwidth() abort "{{{1
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
158 " return textwidth (or 80 if not set)
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
159 return &textwidth == 0 ? 80 : &textwidth
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
160 endfunc
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
161 " Format input line according to textwidth {{{1
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
162 func! s:FormatContent(list) abort
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
163 let result=[]
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
164 let limit = s:Textwidth()
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
165 let column=0
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
166 let idx = -1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
167 let add_indent = 0
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
168 let cnt = 0
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
169 for item in a:list
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
170 for word in split(item, '\s\+\S\+\zs')
19574
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
171 if match(word, '^\s\+$') > -1
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
172 " skip empty words
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
173 continue
d4deb2e50667 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
174 endif
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
175 let column += strdisplaywidth(word, column)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
176 if match(word, "^\\s*\n\\+\\s*$") > -1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
177 call add(result, '')
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
178 let idx += 1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
179 let column = 0
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
180 let add_indent = 1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
181 elseif column > limit || cnt == 0
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
182 let add = s:Indent(s:Trim(word))
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
183 call add(result, add)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
184 let column = strdisplaywidth(add)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
185 let idx += 1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
186 else
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
187 if add_indent
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
188 let result[idx] = s:Indent(s:Trim(word))
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
189 else
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
190 let result[idx] .= ' '. s:Trim(word)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
191 endif
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
192 let add_indent = 0
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
193 endif
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
194 let cnt += 1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
195 endfor
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
196 endfor
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
197 return result
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
198 endfunc
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
199 " Restoration And Modelines: {{{1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
200 let &cpo= s:keepcpo
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
201 unlet s:keepcpo
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
202 " Modeline {{{1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
203 " vim: fdm=marker fdl=0 ts=2 et sw=0 sts=-1