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