annotate runtime/indent/xml.vim @ 34625:ad1b0609b2f8 v9.1.0201

patch 9.1.0201: gM not working correctly with virt text Commit: https://github.com/vim/vim/commit/366c81a2005370ac738618d889ec0337397a9f96 Author: Dylan Thacker-Smith <dylan.ah.smith@gmail.com> Date: Sun Mar 24 09:46:56 2024 +0100 patch 9.1.0201: gM not working correctly with virt text Problem: `gM` would include outer virtual text and its padding when getting the line length used to calculate the middle of the line, putting the cursor much closer to virtual text lines. Solution: Exclude outer virtual text in getting the line length for `gM`, so that virtual text doesn't influence where the cursor is moved to (Dylan Thacker-Smith). closes: #14262 Signed-off-by: Dylan Thacker-Smith <dylan.ah.smith@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sun, 24 Mar 2024 10:00:07 +0100
parents f0d7cb510ce3
children
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
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 23047
diff changeset
42 let b:undo_indent = "setl ai< inde< indk<"
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 23047
diff changeset
43
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 if !exists('b:xml_indent_open')
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
45 let b:xml_indent_open = '.\{-}<[:A-Z_a-z]'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 " pre tag, e.g. <address>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 " let b:xml_indent_open = '.\{-}<[/]\@!\(address\)\@!'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 if !exists('b:xml_indent_close')
23047
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
51 let b:xml_indent_close = '.\{-}</\|/>.\{-}'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 " end pre tag, e.g. </address>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 " let b:xml_indent_close = '.\{-}</\(address\)\@!'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 23047
diff changeset
56 if !exists('b:xml_indent_continuation_filetype')
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 23047
diff changeset
57 let b:xml_indent_continuation_filetype = 'xml'
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 23047
diff changeset
58 endif
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 23047
diff changeset
59
3713
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
60 let &cpo = s:keepcpo
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
61 unlet s:keepcpo
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
62
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 " [-- finish, if the function already exists --]
3713
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
64 if exists('*XmlIndentGet')
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
65 finish
3713
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
66 endif
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
67
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
68 let s:keepcpo= &cpo
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
69 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 fun! <SID>XmlIndentWithPattern(line, pat)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 let s = substitute('x'.a:line, a:pat, "\1", 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 return strlen(substitute(s, "[^\1].*$", '', ''))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 " [-- check if it's xml --]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 fun! <SID>XmlIndentSynCheck(lnum)
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
78 if &syntax != ''
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
79 let syn1 = synIDattr(synID(a:lnum, 1, 1), 'name')
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
80 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
81 if syn1 != '' && syn1 !~ 'xml' && syn2 != '' && syn2 !~ 'xml'
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
82 " don't indent pure non-xml code
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
83 return 0
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
84 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 return 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 " [-- return the sum of indents of a:lnum --]
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
90 fun! <SID>XmlIndentSum(line, style, add)
23047
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
91 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
92 " no complete tag, add one additional indent level
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
93 " but only for the current line
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
94 return a:add + shiftwidth()
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
95 elseif <SID>HasNoTagEnd(a:line)
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
96 " no complete tag, return initial indent
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
97 return a:add
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
98 endif
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
99 if a:style == match(a:line, '^\s*</')
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
100 return (shiftwidth() *
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
101 \ (<SID>XmlIndentWithPattern(a:line, b:xml_indent_open)
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
102 \ - <SID>XmlIndentWithPattern(a:line, b:xml_indent_close)
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
103 \ - <SID>XmlIndentWithPattern(a:line, '.\{-}/>'))) + a:add
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 else
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
105 return a:add
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
109 " Main indent function
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 fun! XmlIndentGet(lnum, use_syntax_check)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 " Find a non-empty line above the current line.
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
112 if prevnonblank(a:lnum - 1) == 0
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
113 " Hit the start of the file, use zero indent.
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
114 return 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 endif
15729
fe57e4f0eac1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15194
diff changeset
116 " 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
117 " 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
118 " Note: xml declaration: <?xml version="1.0"?>
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
119 " 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
120 let ptag_pattern = '\%(.\{-}<[/:A-Z_a-z]\)'. '\%(\&\%<'. a:lnum .'l\)'
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
121 let ptag = search(ptag_pattern, 'bnW')
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
122 " no previous tag
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
123 if ptag == 0
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
124 return 0
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
125 endif
15729
fe57e4f0eac1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15194
diff changeset
126
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
127 let pline = getline(ptag)
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
128 let pind = indent(ptag)
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
129
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
130 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
131 let syn_name_end = '' " Syntax element at end of line
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
132 let curline = getline(a:lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 if a:use_syntax_check
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
134 let check_lnum = <SID>XmlIndentSynCheck(ptag)
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
135 let check_alnum = <SID>XmlIndentSynCheck(a:lnum)
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
136 if check_lnum == 0 || check_alnum == 0
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
137 return indent(a:lnum)
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
138 endif
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
139 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
140 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
141 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
142 " not needed (yet?)
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
143 " 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
144 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
146 if syn_name_end =~ 'Comment' && syn_name_start =~ 'Comment'
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
147 return <SID>XmlIndentComment(a:lnum)
18790
8dde7ced3344 Update a few runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18456
diff changeset
148 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
149 " non-xml tag content: use indent from 'autoindent'
23047
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
150 if pline =~ b:xml_indent_close
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
151 return pind
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
152 elseif !empty(prev_syn_name_end)
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
153 " only indent by an extra shiftwidth, if the previous line ends
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
154 " with an XML like tag
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
155 return pind + shiftwidth()
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
156 else
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
157 " no extra indent, looks like a text continuation line
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
158 return pind
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
159 endif
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
160 endif
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
161
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
162 " Get indent from previous tag line
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
163 let ind = <SID>XmlIndentSum(pline, -1, pind)
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
164 " Determine indent from current line
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
165 let ind = <SID>XmlIndentSum(curline, 0, ind)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
169 func! <SID>IsXMLContinuation(line)
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
170 " Checks, whether or not the line matches a start-of-tag
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 23047
diff changeset
171 return a:line !~ '^\s*<' && &ft =~# b:xml_indent_continuation_filetype
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
172 endfunc
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
173
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
174 func! <SID>HasNoTagEnd(line)
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
175 " Checks whether or not the line matches '>' (so finishes a tag)
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
176 return a:line !~ '>\s*$'
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
177 endfunc
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
178
23047
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
179 func! <SID>IsXMLEmptyClosingTag(line)
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
180 " 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
181 return a:line =~? '<[^>]*/>\s*$'
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
182 endfunc
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
183
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
184 " return indent for a commented line,
17571
2704c4e3e20a Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 16086
diff changeset
185 " the middle part might be indented one additional level
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
186 func! <SID>XmlIndentComment(lnum)
23047
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
187 let ptagopen = search('.\{-}<[:A-Z_a-z]\_[^/]\{-}>.\{-}', 'bnW')
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
188 let ptagclose = search(b:xml_indent_close, 'bnW')
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
189 if getline(a:lnum) =~ '<!--'
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
190 " if previous tag was a closing tag, do not add
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
191 " one additional level of indent
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
192 if ptagclose > ptagopen && a:lnum > ptagclose
23047
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
193 " 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
194 " declared, we should indent with its indent level.
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
195 if !<SID>IsXMLContinuation(getline(ptagclose))
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
196 return indent(ptagclose)
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
197 else
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
198 return indent(ptagclose) - shiftwidth()
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
199 endif
29c5f168c6fd Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18790
diff changeset
200 elseif ptagclose == ptagopen
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
201 return indent(ptagclose)
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
202 else
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
203 " start of comment, add one indentation level
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
204 return indent(ptagopen) + shiftwidth()
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
205 endif
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
206 elseif getline(a:lnum) =~ '-->'
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
207 " end of comment, same as start of comment
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
208 return indent(search('<!--', 'bnW'))
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
209 else
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
210 " middle part of comment, add one additional level
16086
bd7461db24b3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15729
diff changeset
211 return indent(search('<!--', 'bnW')) + shiftwidth()
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
212 endif
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
213 endfunc
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
214
3526
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
215 let &cpo = s:keepcpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
216 unlet s:keepcpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
217
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 14999
diff changeset
218 " vim:ts=4 et sts=-1 sw=0