annotate runtime/indent/xml.vim @ 10611:6bff81438f27 v8.0.0195

patch 8.0.0195: fail to jump to static tag in current file commit https://github.com/vim/vim/commit/a9d23c20879d0dcb289a4db54b3c7df060f87c3c Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jan 16 20:53:34 2017 +0100 patch 8.0.0195: fail to jump to static tag in current file Problem: Jumping to a tag that is a static item in the current file fails. (Kazunobu Kuriyama) Solution: Make sure the first byte of the tag key is not NUL. (Suggested by James McCoy, closes #1387)
author Christian Brabandt <cb@256bit.org>
date Mon, 16 Jan 2017 21:00:04 +0100
parents 9910cbff5f16
children 63b0b7b79b25
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Language: xml
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Maintainer: Johannes Zellner <johannes@zellner.org>
3713
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
3 " Last Change: 2012 Jul 25
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 " Notes: 1) does not indent pure non-xml code (e.g. embedded scripts)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 " 2) will be confused by unbalanced tags in comments
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 " or CDATA sections.
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
7 " 2009-05-26 patch by Nikolai Weibull
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
8 " TODO: implement pre-like tags, see xml_indent_open / xml_indent_close
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 let b:did_indent = 1
3526
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
15 let s:keepcpo= &cpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
16 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 " [-- local settings (must come before aborting the script) --]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 setlocal indentexpr=XmlIndentGet(v:lnum,1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 setlocal indentkeys=o,O,*<Return>,<>>,<<>,/,{,}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 if !exists('b:xml_indent_open')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 let b:xml_indent_open = '.\{-}<\a'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 " pre tag, e.g. <address>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 " let b:xml_indent_open = '.\{-}<[/]\@!\(address\)\@!'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 if !exists('b:xml_indent_close')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 let b:xml_indent_close = '.\{-}</'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 " end pre tag, e.g. </address>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 " let b:xml_indent_close = '.\{-}</\(address\)\@!'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33
3713
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
34 let &cpo = s:keepcpo
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
35 unlet s:keepcpo
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
36
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 " [-- finish, if the function already exists --]
3713
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
38 if exists('*XmlIndentGet')
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
39 finish
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
40 endif
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
41
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
42 let s:keepcpo= &cpo
9910cbff5f16 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
43 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 fun! <SID>XmlIndentWithPattern(line, pat)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 let s = substitute('x'.a:line, a:pat, "\1", 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 return strlen(substitute(s, "[^\1].*$", '', ''))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 " [-- check if it's xml --]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 fun! <SID>XmlIndentSynCheck(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 if '' != &syntax
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 let syn1 = synIDattr(synID(a:lnum, 1, 1), 'name')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 let syn2 = synIDattr(synID(a:lnum, strlen(getline(a:lnum)) - 1, 1), 'name')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 if '' != syn1 && syn1 !~ 'xml' && '' != syn2 && syn2 !~ 'xml'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 " don't indent pure non-xml code
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 return 0
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
58 elseif syn1 =~ '^xmlComment' && syn2 =~ '^xmlComment'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
59 " indent comments specially
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
60 return -1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 return 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 " [-- return the sum of indents of a:lnum --]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 fun! <SID>XmlIndentSum(lnum, style, add)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 let line = getline(a:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 if a:style == match(line, '^\s*</')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 return (&sw *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 \ (<SID>XmlIndentWithPattern(line, b:xml_indent_open)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 \ - <SID>XmlIndentWithPattern(line, b:xml_indent_close)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 \ - <SID>XmlIndentWithPattern(line, '.\{-}/>'))) + a:add
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 return a:add
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 fun! XmlIndentGet(lnum, use_syntax_check)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 " Find a non-empty line above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 let lnum = prevnonblank(a:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 " Hit the start of the file, use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 if a:use_syntax_check
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
89 let check_lnum = <SID>XmlIndentSynCheck(lnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
90 let check_alnum = <SID>XmlIndentSynCheck(a:lnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
91 if 0 == check_lnum || 0 == check_alnum
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 return indent(a:lnum)
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
93 elseif -1 == check_lnum || -1 == check_alnum
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
94 return -1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 let ind = <SID>XmlIndentSum(lnum, -1, indent(lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 let ind = <SID>XmlIndentSum(a:lnum, 0, ind)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103
3526
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
104 let &cpo = s:keepcpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
105 unlet s:keepcpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
106
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 " vim:ts=8