annotate runtime/autoload/xmlformat.vim @ 18456:6d11fc4aa683

Update runtime files Commit: https://github.com/vim/vim/commit/96f45c0b6fc9e9d404e6805593ed1e0e6795e470 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 26 19:53:45 2019 +0200 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Sat, 26 Oct 2019 20:00:04 +0200
parents bc1a8d21c811
children d4deb2e50667
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
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
2 " Last Change: 2019 Oct 24
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
3 " Version: 0.2
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
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 func! xmlformat#Format()
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)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
43 let line .= join(list[(current + 1):(nextmatch-1)], "\n")
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
44 call remove(list, current+1, nextmatch-1)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
45 endif
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
46 " split on `>`, but don't split on very first opening <
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
47 " this means, items can be like ['<tag>', 'tag content</tag>']
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
48 for item in split(line, '.\@<=[>]\zs')
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
49 if s:EndTag(item)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
50 let s:indent = s:DecreaseIndent()
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
51 call add(result, s:Indent(item))
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
52 elseif s:EmptyTag(lastitem)
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:StartTag(lastitem) && s:IsTag(item)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
55 let s:indent += 1
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 call add(result, s:Indent(item))
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
57 else
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
58 if !s:IsTag(item)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
59 " Simply split on '<', if there is one,
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
60 " but reformat according to &textwidth
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
61 let t=split(item, '.<\@=\zs')
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
62 " t should only contain 2 items, but just be safe here
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
63 if s:IsTag(lastitem)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
64 let s:indent+=1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
65 endif
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
66 let result+=s:FormatContent([t[0]])
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
67 if s:EndTag(t[1])
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
68 let s:indent = s:DecreaseIndent()
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
69 endif
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
70 "for y in t[1:]
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
71 let result+=s:FormatContent(t[1:])
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
72 "endfor
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
73 else
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
74 call add(result, s:Indent(item))
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
75 endif
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 endif
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
77 let lastitem = item
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
78 endfor
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
79 let current += 1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
80 endfor
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
82 if !empty(result)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
83 let lastprevline = getline(v:lnum + count_orig)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
84 let delete_lastline = v:lnum + count_orig - 1 == line('$')
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
85 exe v:lnum. ",". (v:lnum + count_orig - 1). 'd'
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 call append(v:lnum - 1, result)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 " 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
88 " append() call
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 let last = v:lnum + len(result)
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
90 " do not use empty(), it returns true for `empty(0)`
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
91 if getline(last) is '' && lastprevline is '' && delete_lastline
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 exe last. 'd'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 endif
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 endif
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 " do not run internal formatter!
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 return 0
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 endfunc
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 " Check if given tag is XML Declaration header {{{1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 func! s:IsXMLDecl(tag)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 return a:tag =~? '^\s*<?xml\s\?\%(version="[^"]*"\)\?\s\?\%(encoding="[^"]*"\)\? ?>\s*$'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 endfunc
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 " Return tag indented by current level {{{1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 func! s:Indent(item)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 return repeat(' ', shiftwidth()*s:indent). s:Trim(a:item)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 endfu
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 " Return item trimmed from leading whitespace {{{1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 func! s:Trim(item)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 if exists('*trim')
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 return trim(a:item)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 else
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
112 return matchstr(a:item, '\S\+.*')
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113 endif
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 " Check if tag is a new opening tag <tag> {{{1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
116 func! s:StartTag(tag)
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
117 let is_comment = s:IsComment(a:tag)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
118 return a:tag =~? '^\s*<[^/?]' && !is_comment
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
119 endfunc
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
120 " Check if tag is a Comment start {{{1
15131
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
121 func! s:IsComment(tag)
bc1a8d21c811 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
122 return a:tag =~? '<!--'
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 endfunc
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 " Remove one level of indentation {{{1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 func! s:DecreaseIndent()
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126 return (s:indent > 0 ? s:indent - 1 : 0)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
127 endfunc
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
128 " Check if tag is a closing tag </tag> {{{1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
129 func! s:EndTag(tag)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
130 return a:tag =~? '^\s*</'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
131 endfunc
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
132 " Check that the tag is actually a tag and not {{{1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133 " something like "foobar</foobar>"
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
134 func! s:IsTag(tag)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135 return s:Trim(a:tag)[0] == '<'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136 endfunc
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
137 " Check if tag is empty <tag/> {{{1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
138 func! s:EmptyTag(tag)
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
139 return a:tag =~ '/>\s*$'
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
140 endfunc
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
141 " Format input line according to textwidth {{{1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
142 func! s:FormatContent(list)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
143 let result=[]
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
144 let limit = 80
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
145 if &textwidth > 0
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
146 let limit = &textwidth
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
147 endif
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
148 let column=0
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
149 let idx = -1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
150 let add_indent = 0
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
151 let cnt = 0
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
152 for item in a:list
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
153 for word in split(item, '\s\+\S\+\zs')
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
154 let column += strdisplaywidth(word, column)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
155 if match(word, "^\\s*\n\\+\\s*$") > -1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
156 call add(result, '')
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
157 let idx += 1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
158 let column = 0
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
159 let add_indent = 1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
160 elseif column > limit || cnt == 0
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
161 let add = s:Indent(s:Trim(word))
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
162 call add(result, add)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
163 let column = strdisplaywidth(add)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
164 let idx += 1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
165 else
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
166 if add_indent
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
167 let result[idx] = s:Indent(s:Trim(word))
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
168 else
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
169 let result[idx] .= ' '. s:Trim(word)
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
170 endif
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
171 let add_indent = 0
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
172 endif
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
173 let cnt += 1
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
174 endfor
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
175 endfor
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
176 return result
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15131
diff changeset
177 endfunc
13912
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
178 " Restoration And Modelines: {{{1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
179 let &cpo= s:keepcpo
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
180 unlet s:keepcpo
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
181 " Modeline {{{1
a9fdf01085a8 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
182 " vim: fdm=marker fdl=0 ts=2 et sw=0 sts=-1