annotate runtime/indent/xml.vim @ 23086:d020ba29f111 v8.2.2089

patch 8.2.2089: libvterm test fails to build on Mac Commit: https://github.com/vim/vim/commit/6cd42db9dc1251b052b97d47bafc063eacac1b3e Author: Bram Moolenaar <Bram@vim.org> Date: Fri Dec 4 18:09:54 2020 +0100 patch 8.2.2089: libvterm test fails to build on Mac Problem: Libvterm test fails to build on Mac. Solution: Adjust configure to remove a space between -L and the path that follows.
author Bram Moolenaar <Bram@vim.org>
date Fri, 04 Dec 2020 18:15:04 +0100
parents 29c5f168c6fd
children f0d7cb510ce3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 17571
diff changeset
1 " Language: XML
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 17571
diff changeset
2 " Maintainer: Christian Brabandt <cb@256bit.org>
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 17571
diff changeset
3 " Repository: https://github.com/chrisbra/vim-xml-ftplugin
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 17571
diff changeset
4 " Previous Maintainer: Johannes Zellner <johannes@zellner.org>
23047
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
5 " Last Changed: 2020 Nov 4th
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
6 " Last Change:
23047
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
7 " 20200529 - Handle empty closing tags correctly
18790
8dde7ced3344 Update a few runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
8 " 20191202 - Handle docbk filetype
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
9 " 20190726 - Correctly handle non-tagged data
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
10 " 20190204 - correctly handle wrap tags
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
11 " https://github.com/chrisbra/vim-xml-ftplugin/issues/5
15729
fe57e4f0eac1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15194
diff changeset
12 " 20190128 - Make sure to find previous tag
fe57e4f0eac1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15194
diff changeset
13 " https://github.com/chrisbra/vim-xml-ftplugin/issues/4
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
14 " 20181116 - Fix indentation when tags start with a colon or an underscore
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
15 " https://github.com/vim/vim/pull/926
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
16 " 20181022 - Do not overwrite indentkeys setting
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
17 " https://github.com/chrisbra/vim-xml-ftplugin/issues/1
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
18 " 20180724 - Correctly indent xml comments https://github.com/vim/vim/issues/3200
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
19 "
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
20 " Notes:
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
21 " 1) does not indent pure non-xml code (e.g. embedded scripts)
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
22 " 2) will be confused by unbalanced tags in comments
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
23 " or CDATA sections.
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
24 " 2009-05-26 patch by Nikolai Weibull
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
25 " TODO: implement pre-like tags, see xml_indent_open / xml_indent_close
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 let b:did_indent = 1
3526
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
32 let s:keepcpo= &cpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
33 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 " [-- local settings (must come before aborting the script) --]
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
36 " Attention: Parameter use_syntax_check is used by the docbk.vim indent script
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 setlocal indentexpr=XmlIndentGet(v:lnum,1)
14999
2b30a2b4bde2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
38 setlocal indentkeys=o,O,*<Return>,<>>,<<>,/,{,},!^F
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
39 " autoindent: used when the indentexpr returns -1
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
40 setlocal autoindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 if !exists('b:xml_indent_open')
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
43 let b:xml_indent_open = '.\{-}<[:A-Z_a-z]'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 " pre tag, e.g. <address>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 " let b:xml_indent_open = '.\{-}<[/]\@!\(address\)\@!'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 if !exists('b:xml_indent_close')
23047
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
49 let b:xml_indent_close = '.\{-}</\|/>.\{-}'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 " end pre tag, e.g. </address>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 " let b:xml_indent_close = '.\{-}</\(address\)\@!'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53
3713
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
54 let &cpo = s:keepcpo
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
55 unlet s:keepcpo
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
56
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 " [-- finish, if the function already exists --]
3713
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
58 if exists('*XmlIndentGet')
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
59 finish
3713
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
60 endif
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
61
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
62 let s:keepcpo= &cpo
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
63 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 fun! <SID>XmlIndentWithPattern(line, pat)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 let s = substitute('x'.a:line, a:pat, "\1", 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 return strlen(substitute(s, "[^\1].*$", '', ''))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 " [-- check if it's xml --]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 fun! <SID>XmlIndentSynCheck(lnum)
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
72 if &syntax != ''
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
73 let syn1 = synIDattr(synID(a:lnum, 1, 1), 'name')
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
74 let syn2 = synIDattr(synID(a:lnum, strlen(getline(a:lnum)) - 1, 1), 'name')
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
75 if syn1 != '' && syn1 !~ 'xml' && syn2 != '' && syn2 !~ 'xml'
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
76 " don't indent pure non-xml code
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
77 return 0
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
78 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 return 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 " [-- return the sum of indents of a:lnum --]
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
84 fun! <SID>XmlIndentSum(line, style, add)
23047
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
85 if <SID>IsXMLContinuation(a:line) && a:style == 0 && !<SID>IsXMLEmptyClosingTag(a:line)
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
86 " no complete tag, add one additional indent level
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
87 " but only for the current line
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
88 return a:add + shiftwidth()
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
89 elseif <SID>HasNoTagEnd(a:line)
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
90 " no complete tag, return initial indent
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
91 return a:add
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
92 endif
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
93 if a:style == match(a:line, '^\s*</')
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
94 return (shiftwidth() *
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
95 \ (<SID>XmlIndentWithPattern(a:line, b:xml_indent_open)
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
96 \ - <SID>XmlIndentWithPattern(a:line, b:xml_indent_close)
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
97 \ - <SID>XmlIndentWithPattern(a:line, '.\{-}/>'))) + a:add
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 else
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
99 return a:add
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
103 " Main indent function
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 fun! XmlIndentGet(lnum, use_syntax_check)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 " Find a non-empty line above the current line.
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
106 if prevnonblank(a:lnum - 1) == 0
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
107 " Hit the start of the file, use zero indent.
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
108 return 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 endif
15729
fe57e4f0eac1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15194
diff changeset
110 " Find previous line with a tag (regardless whether open or closed,
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
111 " but always restrict the match to a line before the current one
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
112 " Note: xml declaration: <?xml version="1.0"?>
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
113 " won't be found, as it is not a legal tag name
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
114 let ptag_pattern = '\%(.\{-}<[/:A-Z_a-z]\)'. '\%(\&\%<'. a:lnum .'l\)'
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
115 let ptag = search(ptag_pattern, 'bnW')
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
116 " no previous tag
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
117 if ptag == 0
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
118 return 0
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
119 endif
15729
fe57e4f0eac1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15194
diff changeset
120
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
121 let pline = getline(ptag)
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
122 let pind = indent(ptag)
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
123
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
124 let syn_name_start = '' " Syntax element at start of line (excluding whitespace)
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
125 let syn_name_end = '' " Syntax element at end of line
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
126 let curline = getline(a:lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 if a:use_syntax_check
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
128 let check_lnum = <SID>XmlIndentSynCheck(ptag)
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
129 let check_alnum = <SID>XmlIndentSynCheck(a:lnum)
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
130 if check_lnum == 0 || check_alnum == 0
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
131 return indent(a:lnum)
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
132 endif
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
133 let syn_name_end = synIDattr(synID(a:lnum, strlen(curline) - 1, 1), 'name')
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
134 let syn_name_start = synIDattr(synID(a:lnum, match(curline, '\S') + 1, 1), 'name')
23047
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
135 let prev_syn_name_end = synIDattr(synID(ptag, strlen(pline) - 1, 1), 'name')
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
136 " not needed (yet?)
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
137 " let prev_syn_name_start = synIDattr(synID(ptag, match(pline, '\S') + 1, 1), 'name')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
140 if syn_name_end =~ 'Comment' && syn_name_start =~ 'Comment'
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
141 return <SID>XmlIndentComment(a:lnum)
18790
8dde7ced3344 Update a few runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
142 elseif empty(syn_name_start) && empty(syn_name_end) && a:use_syntax_check
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
143 " non-xml tag content: use indent from 'autoindent'
23047
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
144 if pline =~ b:xml_indent_close
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
145 return pind
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
146 elseif !empty(prev_syn_name_end)
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
147 " only indent by an extra shiftwidth, if the previous line ends
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
148 " with an XML like tag
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
149 return pind + shiftwidth()
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
150 else
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
151 " no extra indent, looks like a text continuation line
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
152 return pind
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
153 endif
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
154 endif
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
155
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
156 " Get indent from previous tag line
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
157 let ind = <SID>XmlIndentSum(pline, -1, pind)
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
158 " Determine indent from current line
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
159 let ind = <SID>XmlIndentSum(curline, 0, ind)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
163 func! <SID>IsXMLContinuation(line)
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
164 " Checks, whether or not the line matches a start-of-tag
18790
8dde7ced3344 Update a few runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
165 return a:line !~ '^\s*<' && &ft is# 'xml'
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
166 endfunc
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
167
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
168 func! <SID>HasNoTagEnd(line)
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
169 " Checks whether or not the line matches '>' (so finishes a tag)
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
170 return a:line !~ '>\s*$'
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
171 endfunc
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
172
23047
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
173 func! <SID>IsXMLEmptyClosingTag(line)
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
174 " Checks whether the line ends with an empty closing tag such as <lb/>
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
175 return a:line =~? '<[^>]*/>\s*$'
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
176 endfunc
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
177
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
178 " return indent for a commented line,
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
179 " the middle part might be indented one additional level
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
180 func! <SID>XmlIndentComment(lnum)
23047
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
181 let ptagopen = search('.\{-}<[:A-Z_a-z]\_[^/]\{-}>.\{-}', 'bnW')
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
182 let ptagclose = search(b:xml_indent_close, 'bnW')
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
183 if getline(a:lnum) =~ '<!--'
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
184 " if previous tag was a closing tag, do not add
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
185 " one additional level of indent
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
186 if ptagclose > ptagopen && a:lnum > ptagclose
23047
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
187 " If the previous tag was closed on the same line as it was
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
188 " declared, we should indent with its indent level.
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
189 if !<SID>IsXMLContinuation(getline(ptagclose))
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
190 return indent(ptagclose)
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
191 else
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
192 return indent(ptagclose) - shiftwidth()
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
193 endif
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
194 elseif ptagclose == ptagopen
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
195 return indent(ptagclose)
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
196 else
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
197 " start of comment, add one indentation level
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
198 return indent(ptagopen) + shiftwidth()
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
199 endif
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
200 elseif getline(a:lnum) =~ '-->'
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
201 " end of comment, same as start of comment
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
202 return indent(search('<!--', 'bnW'))
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
203 else
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
204 " middle part of comment, add one additional level
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
205 return indent(search('<!--', 'bnW')) + shiftwidth()
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
206 endif
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
207 endfunc
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
208
3526
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
209 let &cpo = s:keepcpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
210 unlet s:keepcpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
211
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
212 " vim:ts=4 et sts=-1 sw=0