Mercurial > vim
annotate runtime/indent/xml.vim @ 14999:2b30a2b4bde2
Update runtime files
commit https://github.com/vim/vim/commit/ba3ff539303c7bb6e46a6802dce3c7b2e55284e0
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Nov 4 14:45:49 2018 +0100
Update runtime files
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 04 Nov 2018 15:00:08 +0100 |
parents | 2f7e67dd088c |
children | 8b334e4cb97f |
rev | line source |
---|---|
7 | 1 " Language: xml |
14421 | 2 " Repository: https://github.com/chrisbra/vim-xml-ftplugin |
3 " Maintainer: Christian Brabandt <cb@256bit.org> | |
4 " Previous Maintainer: Johannes Zellner <johannes@zellner.org> | |
14999 | 5 " Last Change: 20181022 - Do not overwrite indentkeys setting |
6 " https://github.com/chrisbra/vim-xml-ftplugin/issues/1 | |
7 " 20180724 - Correctly indent xml comments https://github.com/vim/vim/issues/3200 | |
7 | 8 " Notes: 1) does not indent pure non-xml code (e.g. embedded scripts) |
9 " 2) will be confused by unbalanced tags in comments | |
10 " or CDATA sections. | |
2034 | 11 " 2009-05-26 patch by Nikolai Weibull |
12 " TODO: implement pre-like tags, see xml_indent_open / xml_indent_close | |
7 | 13 |
14 " Only load this indent file when no other was loaded. | |
15 if exists("b:did_indent") | |
16 finish | |
17 endif | |
18 let b:did_indent = 1 | |
3526
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2034
diff
changeset
|
19 let s:keepcpo= &cpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2034
diff
changeset
|
20 set cpo&vim |
7 | 21 |
22 " [-- local settings (must come before aborting the script) --] | |
23 setlocal indentexpr=XmlIndentGet(v:lnum,1) | |
14999 | 24 setlocal indentkeys=o,O,*<Return>,<>>,<<>,/,{,},!^F |
7 | 25 |
26 if !exists('b:xml_indent_open') | |
27 let b:xml_indent_open = '.\{-}<\a' | |
28 " pre tag, e.g. <address> | |
29 " let b:xml_indent_open = '.\{-}<[/]\@!\(address\)\@!' | |
30 endif | |
31 | |
32 if !exists('b:xml_indent_close') | |
33 let b:xml_indent_close = '.\{-}</' | |
34 " end pre tag, e.g. </address> | |
35 " let b:xml_indent_close = '.\{-}</\(address\)\@!' | |
36 endif | |
37 | |
3713 | 38 let &cpo = s:keepcpo |
39 unlet s:keepcpo | |
40 | |
7 | 41 " [-- finish, if the function already exists --] |
3713 | 42 if exists('*XmlIndentGet') |
43 finish | |
44 endif | |
45 | |
46 let s:keepcpo= &cpo | |
47 set cpo&vim | |
7 | 48 |
49 fun! <SID>XmlIndentWithPattern(line, pat) | |
50 let s = substitute('x'.a:line, a:pat, "\1", 'g') | |
51 return strlen(substitute(s, "[^\1].*$", '', '')) | |
52 endfun | |
53 | |
54 " [-- check if it's xml --] | |
55 fun! <SID>XmlIndentSynCheck(lnum) | |
56 if '' != &syntax | |
57 let syn1 = synIDattr(synID(a:lnum, 1, 1), 'name') | |
58 let syn2 = synIDattr(synID(a:lnum, strlen(getline(a:lnum)) - 1, 1), 'name') | |
59 if '' != syn1 && syn1 !~ 'xml' && '' != syn2 && syn2 !~ 'xml' | |
60 " don't indent pure non-xml code | |
61 return 0 | |
62 endif | |
63 endif | |
64 return 1 | |
65 endfun | |
66 | |
67 " [-- return the sum of indents of a:lnum --] | |
68 fun! <SID>XmlIndentSum(lnum, style, add) | |
69 let line = getline(a:lnum) | |
70 if a:style == match(line, '^\s*</') | |
11518 | 71 return (shiftwidth() * |
7 | 72 \ (<SID>XmlIndentWithPattern(line, b:xml_indent_open) |
73 \ - <SID>XmlIndentWithPattern(line, b:xml_indent_close) | |
74 \ - <SID>XmlIndentWithPattern(line, '.\{-}/>'))) + a:add | |
75 else | |
76 return a:add | |
77 endif | |
78 endfun | |
79 | |
80 fun! XmlIndentGet(lnum, use_syntax_check) | |
81 " Find a non-empty line above the current line. | |
82 let lnum = prevnonblank(a:lnum - 1) | |
83 | |
84 " Hit the start of the file, use zero indent. | |
85 if lnum == 0 | |
86 return 0 | |
87 endif | |
88 | |
89 if a:use_syntax_check | |
2034 | 90 let check_lnum = <SID>XmlIndentSynCheck(lnum) |
91 let check_alnum = <SID>XmlIndentSynCheck(a:lnum) | |
92 if 0 == check_lnum || 0 == check_alnum | |
7 | 93 return indent(a:lnum) |
2034 | 94 elseif -1 == check_lnum || -1 == check_alnum |
95 return -1 | |
7 | 96 endif |
97 endif | |
98 | |
99 let ind = <SID>XmlIndentSum(lnum, -1, indent(lnum)) | |
100 let ind = <SID>XmlIndentSum(a:lnum, 0, ind) | |
101 | |
102 return ind | |
103 endfun | |
104 | |
3526
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2034
diff
changeset
|
105 let &cpo = s:keepcpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2034
diff
changeset
|
106 unlet s:keepcpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2034
diff
changeset
|
107 |
7 | 108 " vim:ts=8 |