annotate runtime/indent/xml.vim @ 3386:cb2ae92ce106 v7.3.459

updated for version 7.3.459 Problem: Win32: Warnings for type conversion. Solution: Add type casts. (Mike Williams)
author Bram Moolenaar <bram@vim.org>
date Wed, 29 Feb 2012 13:58:47 +0100
parents 7bc41231fbc7
children dd6c2497c997
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>
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
3 " Last Change: 2009-05-26 00:17: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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 " [-- local settings (must come before aborting the script) --]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 setlocal indentexpr=XmlIndentGet(v:lnum,1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 setlocal indentkeys=o,O,*<Return>,<>>,<<>,/,{,}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 set cpo-=C
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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 " [-- finish, if the function already exists --]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 if exists('*XmlIndentGet') | finish | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 fun! <SID>XmlIndentWithPattern(line, pat)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 let s = substitute('x'.a:line, a:pat, "\1", 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 return strlen(substitute(s, "[^\1].*$", '', ''))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 " [-- check if it's xml --]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 fun! <SID>XmlIndentSynCheck(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 if '' != &syntax
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 let syn1 = synIDattr(synID(a:lnum, 1, 1), 'name')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 let syn2 = synIDattr(synID(a:lnum, strlen(getline(a:lnum)) - 1, 1), 'name')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 if '' != syn1 && syn1 !~ 'xml' && '' != syn2 && syn2 !~ 'xml'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 " don't indent pure non-xml code
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 return 0
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
50 elseif syn1 =~ '^xmlComment' && syn2 =~ '^xmlComment'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
51 " indent comments specially
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
52 return -1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 return 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 " [-- return the sum of indents of a:lnum --]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 fun! <SID>XmlIndentSum(lnum, style, add)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 let line = getline(a:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 if a:style == match(line, '^\s*</')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 return (&sw *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 \ (<SID>XmlIndentWithPattern(line, b:xml_indent_open)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 \ - <SID>XmlIndentWithPattern(line, b:xml_indent_close)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 \ - <SID>XmlIndentWithPattern(line, '.\{-}/>'))) + a:add
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 return a:add
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 fun! XmlIndentGet(lnum, use_syntax_check)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 " Find a non-empty line above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 let lnum = prevnonblank(a:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 " Hit the start of the file, use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 if a:use_syntax_check
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
81 let check_lnum = <SID>XmlIndentSynCheck(lnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
82 let check_alnum = <SID>XmlIndentSynCheck(a:lnum)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
83 if 0 == check_lnum || 0 == check_alnum
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 return indent(a:lnum)
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
85 elseif -1 == check_lnum || -1 == check_alnum
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 7
diff changeset
86 return -1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 let ind = <SID>XmlIndentSum(lnum, -1, indent(lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 let ind = <SID>XmlIndentSum(a:lnum, 0, ind)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 " vim:ts=8