Mercurial > vim
annotate runtime/indent/html.vim @ 10315:c1cfdf43560c v8.0.0053
commit https://github.com/vim/vim/commit/60ef3e81f4a54d9f7ee617d57021f0811ec8ada5
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Oct 29 14:37:56 2016 +0200
patch 8.0.0053
Problem: No test for what 8.0.0047 fixes.
Solution: Add a test. (Hirohito Higashi)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 29 Oct 2016 14:45:04 +0200 |
parents | 8a1481e59d64 |
children | 523cd59d6db0 |
rev | line source |
---|---|
4869 | 1 " Vim indent script for HTML |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
2 " Header: "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
3 " Maintainer: Bram Moolenaar |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
4 " Original Author: Andy Wokula <anwoku@yahoo.de> |
8869
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
7147
diff
changeset
|
5 " Last Change: 2016 Mar 30 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
6 " Version: 1.0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
7 " Description: HTML indent script with cached state for faster indenting on a |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
8 " range of lines. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
9 " Supports template systems through hooks. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
10 " Supports Closure stylesheets. |
4869 | 11 " |
12 " Credits: | |
13 " indent/html.vim (2006 Jun 05) from J. Zellner | |
14 " indent/css.vim (2006 Dec 20) from N. Weibull | |
15 " | |
16 " History: | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
17 " 2014 June (v1.0) overhaul (Bram) |
4911 | 18 " 2012 Oct 21 (v0.9) added support for shiftwidth() |
19 " 2011 Sep 09 (v0.8) added HTML5 tags (thx to J. Zuckerman) | |
20 " 2008 Apr 28 (v0.6) revised customization | |
21 " 2008 Mar 09 (v0.5) fixed 'indk' issue (thx to C.J. Robinson) | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
22 "}}} |
7 | 23 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
24 " Init Folklore, check user settings (2nd time ++) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
25 if exists("b:did_indent") "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
26 finish |
7 | 27 endif |
28 let b:did_indent = 1 | |
29 | |
4869 | 30 setlocal indentexpr=HtmlIndent() |
31 setlocal indentkeys=o,O,<Return>,<>>,{,},!^F | |
7 | 32 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
33 " "j1" is included to make cindent() work better with Javascript. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
34 setlocal cino=j1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
35 " "J1" should be included, but it doen't work properly before 7.4.355. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
36 if has("patch-7.4.355") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
37 setlocal cino+=J1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
38 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
39 " Before patch 7.4.355 indenting after "(function() {" does not work well, add |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
40 " )2 to limit paren search. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
41 if !has("patch-7.4.355") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
42 setlocal cino+=)2 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
43 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
44 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
45 " Needed for % to work when finding start/end of a tag. |
6009 | 46 setlocal matchpairs+=<:> |
47 | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
48 let b:undo_indent = "setlocal inde< indk< cino<" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
49 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
50 " b:hi_indent keeps state to speed up indenting consecutive lines. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
51 let b:hi_indent = {"lnum": -1} |
7 | 52 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
53 """""" Code below this is loaded only once. """"" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
54 if exists("*HtmlIndent") && !exists('g:force_reload_html') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
55 call HtmlIndent_CheckUserSettings() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
56 finish |
7 | 57 endif |
58 | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
59 " shiftwidth() exists since patch 7.3.694 |
4911 | 60 if exists('*shiftwidth') |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
61 let s:ShiftWidth = function('shiftwidth') |
4911 | 62 else |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
63 func! s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
64 return &shiftwidth |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
65 endfunc |
4911 | 66 endif |
67 | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
68 " Allow for line continuation below. |
867 | 69 let s:cpo_save = &cpo |
7 | 70 set cpo-=C |
4869 | 71 "}}} |
7 | 72 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
73 " Check and process settings from b:html_indent and g:html_indent... variables. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
74 " Prefer using buffer-local settings over global settings, so that there can |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
75 " be defaults for all HTML files and exceptions for specific types of HTML |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
76 " files. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
77 func! HtmlIndent_CheckUserSettings() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
78 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
79 let inctags = '' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
80 if exists("b:html_indent_inctags") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
81 let inctags = b:html_indent_inctags |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
82 elseif exists("g:html_indent_inctags") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
83 let inctags = g:html_indent_inctags |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
84 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
85 let b:hi_tags = {} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
86 if len(inctags) > 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
87 call s:AddITags(b:hi_tags, split(inctags, ",")) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
88 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
89 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
90 let autotags = '' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
91 if exists("b:html_indent_autotags") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
92 let autotags = b:html_indent_autotags |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
93 elseif exists("g:html_indent_autotags") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
94 let autotags = g:html_indent_autotags |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
95 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
96 let b:hi_removed_tags = {} |
6840 | 97 if len(autotags) > 0 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
98 call s:RemoveITags(b:hi_removed_tags, split(autotags, ",")) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
99 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
100 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
101 " Syntax names indicating being inside a string of an attribute value. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
102 let string_names = [] |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
103 if exists("b:html_indent_string_names") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
104 let string_names = b:html_indent_string_names |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
105 elseif exists("g:html_indent_string_names") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
106 let string_names = g:html_indent_string_names |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
107 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
108 let b:hi_insideStringNames = ['htmlString'] |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
109 if len(string_names) > 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
110 for s in string_names |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
111 call add(b:hi_insideStringNames, s) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
112 endfor |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
113 endif |
7 | 114 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
115 " Syntax names indicating being inside a tag. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
116 let tag_names = [] |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
117 if exists("b:html_indent_tag_names") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
118 let tag_names = b:html_indent_tag_names |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
119 elseif exists("g:html_indent_tag_names") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
120 let tag_names = g:html_indent_tag_names |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
121 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
122 let b:hi_insideTagNames = ['htmlTag', 'htmlScriptTag'] |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
123 if len(tag_names) > 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
124 for s in tag_names |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
125 call add(b:hi_insideTagNames, s) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
126 endfor |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
127 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
128 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
129 let indone = {"zero": 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
130 \,"auto": "indent(prevnonblank(v:lnum-1))" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
131 \,"inc": "b:hi_indent.blocktagind + s:ShiftWidth()"} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
132 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
133 let script1 = '' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
134 if exists("b:html_indent_script1") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
135 let script1 = b:html_indent_script1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
136 elseif exists("g:html_indent_script1") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
137 let script1 = g:html_indent_script1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
138 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
139 if len(script1) > 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
140 let b:hi_js1indent = get(indone, script1, indone.zero) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
141 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
142 let b:hi_js1indent = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
143 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
144 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
145 let style1 = '' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
146 if exists("b:html_indent_style1") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
147 let style1 = b:html_indent_style1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
148 elseif exists("g:html_indent_style1") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
149 let style1 = g:html_indent_style1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
150 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
151 if len(style1) > 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
152 let b:hi_css1indent = get(indone, style1, indone.zero) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
153 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
154 let b:hi_css1indent = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
155 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
156 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
157 if !exists('b:html_indent_line_limit') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
158 if exists('g:html_indent_line_limit') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
159 let b:html_indent_line_limit = g:html_indent_line_limit |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
160 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
161 let b:html_indent_line_limit = 200 |
4869 | 162 endif |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
163 endif |
4869 | 164 endfunc "}}} |
165 | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
166 " Init Script Vars |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
167 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
168 let b:hi_lasttick = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
169 let b:hi_newstate = {} |
4869 | 170 let s:countonly = 0 |
171 "}}} | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
172 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
173 " Fill the s:indent_tags dict with known tags. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
174 " The key is "tagname" or "/tagname". {{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
175 " The value is: |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
176 " 1 opening tag |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
177 " 2 "pre" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
178 " 3 "script" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
179 " 4 "style" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
180 " 5 comment start |
7147
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
181 " 6 conditional comment start |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
182 " -1 closing tag |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
183 " -2 "/pre" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
184 " -3 "/script" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
185 " -4 "/style" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
186 " -5 comment end |
7147
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
187 " -6 conditional comment end |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
188 let s:indent_tags = {} |
7147
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
189 let s:endtags = [0,0,0,0,0,0,0] " long enough for the highest index |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
190 "}}} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
191 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
192 " Add a list of tag names for a pair of <tag> </tag> to "tags". |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
193 func! s:AddITags(tags, taglist) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
194 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
195 for itag in a:taglist |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
196 let a:tags[itag] = 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
197 let a:tags['/' . itag] = -1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
198 endfor |
4869 | 199 endfunc "}}} |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
200 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
201 " Take a list of tag name pairs that are not to be used as tag pairs. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
202 func! s:RemoveITags(tags, taglist) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
203 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
204 for itag in a:taglist |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
205 let a:tags[itag] = 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
206 let a:tags['/' . itag] = 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
207 endfor |
4869 | 208 endfunc "}}} |
209 | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
210 " Add a block tag, that is a tag with a different kind of indenting. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
211 func! s:AddBlockTag(tag, id, ...) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
212 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
213 if !(a:id >= 2 && a:id < len(s:endtags)) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
214 echoerr 'AddBlockTag ' . a:id |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
215 return |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
216 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
217 let s:indent_tags[a:tag] = a:id |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
218 if a:0 == 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
219 let s:indent_tags['/' . a:tag] = -a:id |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
220 let s:endtags[a:id] = "</" . a:tag . ">" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
221 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
222 let s:indent_tags[a:1] = -a:id |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
223 let s:endtags[a:id] = a:1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
224 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
225 endfunc "}}} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
226 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
227 " Add known tag pairs. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
228 " Self-closing tags and tags that are sometimes {{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
229 " self-closing (e.g., <p>) are not here (when encountering </p> we can find |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
230 " the matching <p>, but not the other way around). |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
231 " Old HTML tags: |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
232 call s:AddITags(s:indent_tags, [ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
233 \ 'a', 'abbr', 'acronym', 'address', 'b', 'bdo', 'big', |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
234 \ 'blockquote', 'body', 'button', 'caption', 'center', 'cite', 'code', |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
235 \ 'colgroup', 'del', 'dfn', 'dir', 'div', 'dl', 'em', 'fieldset', 'font', |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
236 \ 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'html', |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
237 \ 'i', 'iframe', 'ins', 'kbd', 'label', 'legend', 'li', |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
238 \ 'map', 'menu', 'noframes', 'noscript', 'object', 'ol', |
4869 | 239 \ 'optgroup', 'q', 's', 'samp', 'select', 'small', 'span', 'strong', 'sub', |
240 \ 'sup', 'table', 'textarea', 'title', 'tt', 'u', 'ul', 'var', 'th', 'td', | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
241 \ 'tr', 'tbody', 'tfoot', 'thead']) |
4869 | 242 |
8869
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
7147
diff
changeset
|
243 " New HTML5 elements: |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
244 call s:AddITags(s:indent_tags, [ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
245 \ 'area', 'article', 'aside', 'audio', 'bdi', 'canvas', |
8869
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
7147
diff
changeset
|
246 \ 'command', 'data', 'datalist', 'details', 'embed', 'figcaption', |
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
7147
diff
changeset
|
247 \ 'figure', 'footer', 'header', 'keygen', 'mark', 'meter', 'nav', 'output', |
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
7147
diff
changeset
|
248 \ 'progress', 'rp', 'rt', 'ruby', 'section', 'source', 'summary', 'svg', |
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
7147
diff
changeset
|
249 \ 'time', 'track', 'video', 'wbr']) |
6663 | 250 |
251 " Tags added for web components: | |
252 call s:AddITags(s:indent_tags, [ | |
253 \ 'content', 'shadow', 'template']) | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
254 "}}} |
4869 | 255 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
256 " Add Block Tags: these contain alien content |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
257 "{{{ |
4869 | 258 call s:AddBlockTag('pre', 2) |
259 call s:AddBlockTag('script', 3) | |
260 call s:AddBlockTag('style', 4) | |
261 call s:AddBlockTag('<!--', 5, '-->') | |
7147
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
262 call s:AddBlockTag('<!--[', 6, '![endif]-->') |
4869 | 263 "}}} |
264 | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
265 " Return non-zero when "tagname" is an opening tag, not being a block tag, for |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
266 " which there should be a closing tag. Can be used by scripts that include |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
267 " HTML indenting. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
268 func! HtmlIndent_IsOpenTag(tagname) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
269 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
270 if get(s:indent_tags, a:tagname) == 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
271 return 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
272 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
273 return get(b:hi_tags, a:tagname) == 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
274 endfunc "}}} |
4869 | 275 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
276 " Get the value for "tagname", taking care of buffer-local tags. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
277 func! s:get_tag(tagname) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
278 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
279 let i = get(s:indent_tags, a:tagname) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
280 if (i == 1 || i == -1) && get(b:hi_removed_tags, a:tagname) != 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
281 return 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
282 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
283 if i == 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
284 let i = get(b:hi_tags, a:tagname) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
285 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
286 return i |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
287 endfunc "}}} |
7 | 288 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
289 " Count the number of start and end tags in "text". |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
290 func! s:CountITags(text) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
291 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
292 " Store the result in s:curind and s:nextrel. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
293 let s:curind = 0 " relative indent steps for current line [unit &sw]: |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
294 let s:nextrel = 0 " relative indent steps for next line [unit &sw]: |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
295 let s:block = 0 " assume starting outside of a block |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
296 let s:countonly = 1 " don't change state |
7147
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
297 call substitute(a:text, '<\zs/\=\w\+\(-\w\+\)*\>\|<!--\[\|\[endif\]-->\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
298 let s:countonly = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
299 endfunc "}}} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
300 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
301 " Count the number of start and end tags in text. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
302 func! s:CountTagsAndState(text) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
303 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
304 " Store the result in s:curind and s:nextrel. Update b:hi_newstate.block. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
305 let s:curind = 0 " relative indent steps for current line [unit &sw]: |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
306 let s:nextrel = 0 " relative indent steps for next line [unit &sw]: |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
307 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
308 let s:block = b:hi_newstate.block |
7147
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
309 let tmp = substitute(a:text, '<\zs/\=\w\+\(-\w\+\)*\>\|<!--\[\|\[endif\]-->\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
310 if s:block == 3 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
311 let b:hi_newstate.scripttype = s:GetScriptType(matchstr(tmp, '\C.*<SCRIPT\>\zs[^>]*')) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
312 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
313 let b:hi_newstate.block = s:block |
4869 | 314 endfunc "}}} |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
315 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
316 " Used by s:CountITags() and s:CountTagsAndState(). |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
317 func! s:CheckTag(itag) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
318 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
319 " Returns an empty string or "SCRIPT". |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
320 " a:itag can be "tag" or "/tag" or "<!--" or "-->" |
6663 | 321 if (s:CheckCustomTag(a:itag)) |
322 return "" | |
323 endif | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
324 let ind = s:get_tag(a:itag) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
325 if ind == -1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
326 " closing tag |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
327 if s:block != 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
328 " ignore itag within a block |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
329 return "" |
4869 | 330 endif |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
331 if s:nextrel == 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
332 let s:curind -= 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
333 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
334 let s:nextrel -= 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
335 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
336 elseif ind == 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
337 " opening tag |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
338 if s:block != 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
339 return "" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
340 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
341 let s:nextrel += 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
342 elseif ind != 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
343 " block-tag (opening or closing) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
344 return s:CheckBlockTag(a:itag, ind) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
345 " else ind==0 (other tag found): keep indent |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
346 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
347 return "" |
4869 | 348 endfunc "}}} |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
349 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
350 " Used by s:CheckTag(). Returns an empty string or "SCRIPT". |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
351 func! s:CheckBlockTag(blocktag, ind) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
352 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
353 if a:ind > 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
354 " a block starts here |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
355 if s:block != 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
356 " already in a block (nesting) - ignore |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
357 " especially ignore comments after other blocktags |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
358 return "" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
359 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
360 let s:block = a:ind " block type |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
361 if s:countonly |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
362 return "" |
4869 | 363 endif |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
364 let b:hi_newstate.blocklnr = v:lnum |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
365 " save allover indent for the endtag |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
366 let b:hi_newstate.blocktagind = b:hi_indent.baseindent + (s:nextrel + s:curind) * s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
367 if a:ind == 3 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
368 return "SCRIPT" " all except this must be lowercase |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
369 " line is to be checked again for the type attribute |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
370 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
371 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
372 let s:block = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
373 " we get here if starting and closing a block-tag on the same line |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
374 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
375 return "" |
4869 | 376 endfunc "}}} |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
377 |
6663 | 378 " Used by s:CheckTag(). |
379 func! s:CheckCustomTag(ctag) | |
380 "{{{ | |
381 " Returns 1 if ctag is the tag for a custom element, 0 otherwise. | |
382 " a:ctag can be "tag" or "/tag" or "<!--" or "-->" | |
383 let pattern = '\%\(\w\+-\)\+\w\+' | |
384 if match(a:ctag, pattern) == -1 | |
385 return 0 | |
386 endif | |
387 if matchstr(a:ctag, '\/\ze.\+') == "/" | |
388 " closing tag | |
389 if s:block != 0 | |
390 " ignore ctag within a block | |
391 return 1 | |
392 endif | |
393 if s:nextrel == 0 | |
394 let s:curind -= 1 | |
395 else | |
396 let s:nextrel -= 1 | |
397 endif | |
398 else | |
399 " opening tag | |
400 if s:block != 0 | |
401 return 1 | |
402 endif | |
403 let s:nextrel += 1 | |
404 endif | |
405 return 1 | |
406 endfunc "}}} | |
407 | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
408 " Return the <script> type: either "javascript" or "" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
409 func! s:GetScriptType(str) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
410 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
411 if a:str == "" || a:str =~ "java" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
412 return "javascript" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
413 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
414 return "" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
415 endif |
4869 | 416 endfunc "}}} |
417 | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
418 " Look back in the file, starting at a:lnum - 1, to compute a state for the |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
419 " start of line a:lnum. Return the new state. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
420 func! s:FreshState(lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
421 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
422 " A state is to know ALL relevant details about the |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
423 " lines 1..a:lnum-1, initial calculating (here!) can be slow, but updating is |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
424 " fast (incremental). |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
425 " TODO: this should be split up in detecting the block type and computing the |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
426 " indent for the block type, so that when we do not know the indent we do |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
427 " not need to clear the whole state and re-detect the block type again. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
428 " State: |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
429 " lnum last indented line == prevnonblank(a:lnum - 1) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
430 " block = 0 a:lnum located within special tag: 0:none, 2:<pre>, |
7147
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
431 " 3:<script>, 4:<style>, 5:<!--, 6:<!--[ |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
432 " baseindent use this indent for line a:lnum as a start - kind of |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
433 " autoindent (if block==0) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
434 " scripttype = '' type attribute of a script tag (if block==3) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
435 " blocktagind indent for current opening (get) and closing (set) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
436 " blocktag (if block!=0) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
437 " blocklnr lnum of starting blocktag (if block!=0) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
438 " inattr line {lnum} starts with attributes of a tag |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
439 let state = {} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
440 let state.lnum = prevnonblank(a:lnum - 1) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
441 let state.scripttype = "" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
442 let state.blocktagind = -1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
443 let state.block = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
444 let state.baseindent = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
445 let state.blocklnr = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
446 let state.inattr = 0 |
4869 | 447 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
448 if state.lnum == 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
449 return state |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
450 endif |
7 | 451 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
452 " Heuristic: |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
453 " remember startline state.lnum |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
454 " look back for <pre, </pre, <script, </script, <style, </style tags |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
455 " remember stopline |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
456 " if opening tag found, |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
457 " assume a:lnum within block |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
458 " else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
459 " look back in result range (stopline, startline) for comment |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
460 " \ delimiters (<!--, -->) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
461 " if comment opener found, |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
462 " assume a:lnum within comment |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
463 " else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
464 " assume usual html for a:lnum |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
465 " if a:lnum-1 has a closing comment |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
466 " look back to get indent of comment opener |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
467 " FI |
1121 | 468 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
469 " look back for a blocktag |
7147
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
470 let stopline2 = v:lnum + 1 |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
471 if has_key(b:hi_indent, 'block') && b:hi_indent.block > 5 |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
472 let [stopline2, stopcol2] = searchpos('<!--', 'bnW') |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
473 endif |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
474 let [stopline, stopcol] = searchpos('\c<\zs\/\=\%(pre\>\|script\>\|style\>\)', "bnW") |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
475 if stopline > 0 && stopline < stopline2 |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
476 " ugly ... why isn't there searchstr() |
4869 | 477 let tagline = tolower(getline(stopline)) |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
478 let blocktag = matchstr(tagline, '\/\=\%(pre\>\|script\>\|style\>\)', stopcol - 1) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
479 if blocktag[0] != "/" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
480 " opening tag found, assume a:lnum within block |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
481 let state.block = s:indent_tags[blocktag] |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
482 if state.block == 3 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
483 let state.scripttype = s:GetScriptType(matchstr(tagline, '\>[^>]*', stopcol)) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
484 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
485 let state.blocklnr = stopline |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
486 " check preceding tags in the line: |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
487 call s:CountITags(tagline[: stopcol-2]) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
488 let state.blocktagind = indent(stopline) + (s:curind + s:nextrel) * s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
489 return state |
4869 | 490 elseif stopline == state.lnum |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
491 " handle special case: previous line (= state.lnum) contains a |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
492 " closing blocktag which is preceded by line-noise; |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
493 " blocktag == "/..." |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
494 let swendtag = match(tagline, '^\s*</') >= 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
495 if !swendtag |
7147
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
496 let [bline, bcol] = searchpos('<'.blocktag[1:].'\>', "bnW") |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
497 call s:CountITags(tolower(getline(bline)[: bcol-2])) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
498 let state.baseindent = indent(bline) + (s:curind + s:nextrel) * s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
499 return state |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
500 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
501 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
502 endif |
7147
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
503 if stopline > stopline2 |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
504 let stopline = stopline2 |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
505 let stopcol = stopcol2 |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
506 endif |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
507 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
508 " else look back for comment |
7147
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
509 let [comlnum, comcol, found] = searchpos('\(<!--\[\)\|\(<!--\)\|-->', 'bpnW', stopline) |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
510 if found == 2 || found == 3 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
511 " comment opener found, assume a:lnum within comment |
7147
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
512 let state.block = (found == 3 ? 5 : 6) |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
513 let state.blocklnr = comlnum |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
514 " check preceding tags in the line: |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
515 call s:CountITags(tolower(getline(comlnum)[: comcol-2])) |
7147
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
516 if found == 2 |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
517 let state.baseindent = b:hi_indent.baseindent |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
518 endif |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
519 let state.blocktagind = indent(comlnum) + (s:curind + s:nextrel) * s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
520 return state |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
521 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
522 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
523 " else within usual HTML |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
524 let text = tolower(getline(state.lnum)) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
525 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
526 " Check a:lnum-1 for closing comment (we need indent from the opening line). |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
527 " Not when other tags follow (might be --> inside a string). |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
528 let comcol = stridx(text, '-->') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
529 if comcol >= 0 && match(text, '[<>]', comcol) <= 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
530 call cursor(state.lnum, comcol + 1) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
531 let [comlnum, comcol] = searchpos('<!--', 'bW') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
532 if comlnum == state.lnum |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
533 let text = text[: comcol-2] |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
534 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
535 let text = tolower(getline(comlnum)[: comcol-2]) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
536 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
537 call s:CountITags(text) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
538 let state.baseindent = indent(comlnum) + (s:curind + s:nextrel) * s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
539 " TODO check tags that follow "-->" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
540 return state |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
541 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
542 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
543 " Check if the previous line starts with end tag. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
544 let swendtag = match(text, '^\s*</') >= 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
545 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
546 " If previous line ended in a closing tag, line up with the opening tag. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
547 if !swendtag && text =~ '</\w\+\s*>\s*$' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
548 call cursor(state.lnum, 99999) |
6159 | 549 normal! F< |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
550 let start_lnum = HtmlIndent_FindStartTag() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
551 if start_lnum > 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
552 let state.baseindent = indent(start_lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
553 if col('.') > 2 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
554 " check for tags before the matching opening tag. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
555 let text = getline(start_lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
556 let swendtag = match(text, '^\s*</') >= 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
557 call s:CountITags(text[: col('.') - 2]) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
558 let state.baseindent += s:nextrel * s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
559 if !swendtag |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
560 let state.baseindent += s:curind * s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
561 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
562 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
563 return state |
7 | 564 endif |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
565 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
566 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
567 " Else: no comments. Skip backwards to find the tag we're inside. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
568 let [state.lnum, found] = HtmlIndent_FindTagStart(state.lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
569 " Check if that line starts with end tag. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
570 let text = getline(state.lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
571 let swendtag = match(text, '^\s*</') >= 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
572 call s:CountITags(tolower(text)) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
573 let state.baseindent = indent(state.lnum) + s:nextrel * s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
574 if !swendtag |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
575 let state.baseindent += s:curind * s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
576 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
577 return state |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
578 endfunc "}}} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
579 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
580 " Indent inside a <pre> block: Keep indent as-is. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
581 func! s:Alien2() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
582 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
583 return -1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
584 endfunc "}}} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
585 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
586 " Return the indent inside a <script> block for javascript. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
587 func! s:Alien3() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
588 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
589 let lnum = prevnonblank(v:lnum - 1) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
590 while lnum > 1 && getline(lnum) =~ '^\s*/[/*]' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
591 " Skip over comments to avoid that cindent() aligns with the <script> tag |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
592 let lnum = prevnonblank(lnum - 1) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
593 endwhile |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
594 if lnum == b:hi_indent.blocklnr |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
595 " indent for the first line after <script> |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
596 return eval(b:hi_js1indent) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
597 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
598 if b:hi_indent.scripttype == "javascript" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
599 return cindent(v:lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
600 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
601 return -1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
602 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
603 endfunc "}}} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
604 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
605 " Return the indent inside a <style> block. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
606 func! s:Alien4() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
607 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
608 if prevnonblank(v:lnum-1) == b:hi_indent.blocklnr |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
609 " indent for first content line |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
610 return eval(b:hi_css1indent) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
611 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
612 return s:CSSIndent() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
613 endfunc "}}} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
614 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
615 " Indending inside a <style> block. Returns the indent. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
616 func! s:CSSIndent() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
617 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
618 " This handles standard CSS and also Closure stylesheets where special lines |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
619 " start with @. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
620 " When the line starts with '*' or the previous line starts with "/*" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
621 " and does not end in "*/", use C indenting to format the comment. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
622 " Adopted $VIMRUNTIME/indent/css.vim |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
623 let curtext = getline(v:lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
624 if curtext =~ '^\s*[*]' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
625 \ || (v:lnum > 1 && getline(v:lnum - 1) =~ '\s*/\*' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
626 \ && getline(v:lnum - 1) !~ '\*/\s*$') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
627 return cindent(v:lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
628 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
629 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
630 let min_lnum = b:hi_indent.blocklnr |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
631 let prev_lnum = s:CssPrevNonComment(v:lnum - 1, min_lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
632 let [prev_lnum, found] = HtmlIndent_FindTagStart(prev_lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
633 if prev_lnum <= min_lnum |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
634 " Just below the <style> tag, indent for first content line after comments. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
635 return eval(b:hi_css1indent) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
636 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
637 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
638 " If the current line starts with "}" align with it's match. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
639 if curtext =~ '^\s*}' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
640 call cursor(v:lnum, 1) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
641 try |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
642 normal! % |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
643 " Found the matching "{", align with it after skipping unfinished lines. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
644 let align_lnum = s:CssFirstUnfinished(line('.'), min_lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
645 return indent(align_lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
646 catch |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
647 " can't find it, try something else, but it's most likely going to be |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
648 " wrong |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
649 endtry |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
650 endif |
7 | 651 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
652 " add indent after { |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
653 let brace_counts = HtmlIndent_CountBraces(prev_lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
654 let extra = brace_counts.c_open * s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
655 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
656 let prev_text = getline(prev_lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
657 let below_end_brace = prev_text =~ '}\s*$' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
658 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
659 " Search back to align with the first line that's unfinished. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
660 let align_lnum = s:CssFirstUnfinished(prev_lnum, min_lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
661 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
662 " Handle continuation lines if aligning with previous line and not after a |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
663 " "}". |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
664 if extra == 0 && align_lnum == prev_lnum && !below_end_brace |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
665 let prev_hasfield = prev_text =~ '^\s*[a-zA-Z0-9-]\+:' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
666 let prev_special = prev_text =~ '^\s*\(/\*\|@\)' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
667 if curtext =~ '^\s*\(/\*\|@\)' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
668 " if the current line is not a comment or starts with @ (used by template |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
669 " systems) reduce indent if previous line is a continuation line |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
670 if !prev_hasfield && !prev_special |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
671 let extra = -s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
672 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
673 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
674 let cur_hasfield = curtext =~ '^\s*[a-zA-Z0-9-]\+:' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
675 let prev_unfinished = s:CssUnfinished(prev_text) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
676 if !cur_hasfield && (prev_hasfield || prev_unfinished) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
677 " Continuation line has extra indent if the previous line was not a |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
678 " continuation line. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
679 let extra = s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
680 " Align with @if |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
681 if prev_text =~ '^\s*@if ' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
682 let extra = 4 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
683 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
684 elseif cur_hasfield && !prev_hasfield && !prev_special |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
685 " less indent below a continuation line |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
686 let extra = -s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
687 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
688 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
689 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
690 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
691 if below_end_brace |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
692 " find matching {, if that line starts with @ it's not the start of a rule |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
693 " but something else from a template system |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
694 call cursor(prev_lnum, 1) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
695 call search('}\s*$') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
696 try |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
697 normal! % |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
698 " Found the matching "{", align with it. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
699 let align_lnum = s:CssFirstUnfinished(line('.'), min_lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
700 let special = getline(align_lnum) =~ '^\s*@' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
701 catch |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
702 let special = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
703 endtry |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
704 if special |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
705 " do not reduce indent below @{ ... } |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
706 if extra < 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
707 let extra += s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
708 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
709 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
710 let extra -= (brace_counts.c_close - (prev_text =~ '^\s*}')) * s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
711 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
712 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
713 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
714 " if no extra indent yet... |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
715 if extra == 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
716 if brace_counts.p_open > brace_counts.p_close |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
717 " previous line has more ( than ): add a shiftwidth |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
718 let extra = s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
719 elseif brace_counts.p_open < brace_counts.p_close |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
720 " previous line has more ) than (: subtract a shiftwidth |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
721 let extra = -s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
722 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
723 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
724 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
725 return indent(align_lnum) + extra |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
726 endfunc "}}} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
727 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
728 " Inside <style>: Whether a line is unfinished. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
729 func! s:CssUnfinished(text) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
730 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
731 return a:text =~ '\s\(||\|&&\|:\)\s*$' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
732 endfunc "}}} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
733 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
734 " Search back for the first unfinished line above "lnum". |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
735 func! s:CssFirstUnfinished(lnum, min_lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
736 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
737 let align_lnum = a:lnum |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
738 while align_lnum > a:min_lnum && s:CssUnfinished(getline(align_lnum - 1)) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
739 let align_lnum -= 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
740 endwhile |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
741 return align_lnum |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
742 endfunc "}}} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
743 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
744 " Find the non-empty line at or before "lnum" that is not a comment. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
745 func! s:CssPrevNonComment(lnum, stopline) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
746 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
747 " caller starts from a line a:lnum + 1 that is not a comment |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
748 let lnum = prevnonblank(a:lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
749 while 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
750 let ccol = match(getline(lnum), '\*/') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
751 if ccol < 0 |
10228
8a1481e59d64
commit https://github.com/vim/vim/commit/3e496b0ea31996b665824f45664dee1fdd73c4d0
Christian Brabandt <cb@256bit.org>
parents:
8869
diff
changeset
|
752 " No comment end thus it's something else. |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
753 return lnum |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
754 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
755 call cursor(lnum, ccol + 1) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
756 " Search back for the /* that starts the comment |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
757 let lnum = search('/\*', 'bW', a:stopline) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
758 if indent(".") == virtcol(".") - 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
759 " The found /* is at the start of the line. Now go back to the line |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
760 " above it and again check if it is a comment. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
761 let lnum = prevnonblank(lnum - 1) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
762 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
763 " /* is after something else, thus it's not a comment line. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
764 return lnum |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
765 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
766 endwhile |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
767 endfunc "}}} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
768 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
769 " Check the number of {} and () in line "lnum". Return a dict with the counts. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
770 func! HtmlIndent_CountBraces(lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
771 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
772 let brs = substitute(getline(a:lnum), '[''"].\{-}[''"]\|/\*.\{-}\*/\|/\*.*$\|[^{}()]', '', 'g') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
773 let c_open = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
774 let c_close = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
775 let p_open = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
776 let p_close = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
777 for brace in split(brs, '\zs') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
778 if brace == "{" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
779 let c_open += 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
780 elseif brace == "}" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
781 if c_open > 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
782 let c_open -= 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
783 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
784 let c_close += 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
785 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
786 elseif brace == '(' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
787 let p_open += 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
788 elseif brace == ')' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
789 if p_open > 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
790 let p_open -= 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
791 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
792 let p_close += 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
793 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
794 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
795 endfor |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
796 return {'c_open': c_open, |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
797 \ 'c_close': c_close, |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
798 \ 'p_open': p_open, |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
799 \ 'p_close': p_close} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
800 endfunc "}}} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
801 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
802 " Return the indent for a comment: <!-- --> |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
803 func! s:Alien5() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
804 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
805 let curtext = getline(v:lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
806 if curtext =~ '^\s*\zs-->' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
807 " current line starts with end of comment, line up with comment start. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
808 call cursor(v:lnum, 0) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
809 let lnum = search('<!--', 'b') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
810 if lnum > 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
811 " TODO: what if <!-- is not at the start of the line? |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
812 return indent(lnum) |
4869 | 813 endif |
814 | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
815 " Strange, can't find it. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
816 return -1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
817 endif |
6009 | 818 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
819 let prevlnum = prevnonblank(v:lnum - 1) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
820 let prevtext = getline(prevlnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
821 let idx = match(prevtext, '^\s*\zs<!--') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
822 if idx >= 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
823 " just below comment start, add a shiftwidth |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
824 return idx + s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
825 endif |
7 | 826 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
827 " Some files add 4 spaces just below a TODO line. It's difficult to detect |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
828 " the end of the TODO, so let's not do that. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
829 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
830 " Align with the previous non-blank line. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
831 return indent(prevlnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
832 endfunc "}}} |
6009 | 833 |
7147
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
834 " Return the indent for conditional comment: <!--[ ![endif]--> |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
835 func! s:Alien6() |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
836 "{{{ |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
837 let curtext = getline(v:lnum) |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
838 if curtext =~ '\s*\zs<!\[endif\]-->' |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
839 " current line starts with end of comment, line up with comment start. |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
840 let lnum = search('<!--', 'bn') |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
841 if lnum > 0 |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
842 return indent(lnum) |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
843 endif |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
844 endif |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
845 return b:hi_indent.baseindent + s:ShiftWidth() |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
846 endfunc "}}} |
c590de398af9
commit https://github.com/vim/vim/commit/ca63501fbcd1cf9c8aa9ff12c093c95b62a89ed7
Christian Brabandt <cb@256bit.org>
parents:
6840
diff
changeset
|
847 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
848 " When the "lnum" line ends in ">" find the line containing the matching "<". |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
849 func! HtmlIndent_FindTagStart(lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
850 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
851 " Avoids using the indent of a continuation line. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
852 " Moves the cursor. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
853 " Return two values: |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
854 " - the matching line number or "lnum". |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
855 " - a flag indicating whether we found the end of a tag. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
856 " This method is global so that HTML-like indenters can use it. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
857 " To avoid matching " > " or " < " inside a string require that the opening |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
858 " "<" is followed by a word character and the closing ">" comes after a |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
859 " non-white character. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
860 let idx = match(getline(a:lnum), '\S>\s*$') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
861 if idx > 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
862 call cursor(a:lnum, idx) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
863 let lnum = searchpair('<\w', '' , '\S>', 'bW', '', max([a:lnum - b:html_indent_line_limit, 0])) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
864 if lnum > 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
865 return [lnum, 1] |
6009 | 866 endif |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
867 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
868 return [a:lnum, 0] |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
869 endfunc "}}} |
6009 | 870 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
871 " Find the unclosed start tag from the current cursor position. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
872 func! HtmlIndent_FindStartTag() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
873 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
874 " The cursor must be on or before a closing tag. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
875 " If found, positions the cursor at the match and returns the line number. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
876 " Otherwise returns 0. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
877 let tagname = matchstr(getline('.')[col('.') - 1:], '</\zs\w\+\ze') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
878 let start_lnum = searchpair('<' . tagname . '\>', '', '</' . tagname . '\>', 'bW') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
879 if start_lnum > 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
880 return start_lnum |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
881 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
882 return 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
883 endfunc "}}} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
884 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
885 " Moves the cursor from a "<" to the matching ">". |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
886 func! HtmlIndent_FindTagEnd() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
887 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
888 " Call this with the cursor on the "<" of a start tag. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
889 " This will move the cursor to the ">" of the matching end tag or, when it's |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
890 " a self-closing tag, to the matching ">". |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
891 " Limited to look up to b:html_indent_line_limit lines away. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
892 let text = getline('.') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
893 let tagname = matchstr(text, '\w\+\|!--', col('.')) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
894 if tagname == '!--' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
895 call search('--\zs>') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
896 elseif s:get_tag('/' . tagname) != 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
897 " tag with a closing tag, find matching "</tag>" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
898 call searchpair('<' . tagname, '', '</' . tagname . '\zs>', 'W', '', line('.') + b:html_indent_line_limit) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
899 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
900 " self-closing tag, find the ">" |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
901 call search('\S\zs>') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
902 endif |
4869 | 903 endfunc "}}} |
904 | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
905 " Indenting inside a start tag. Return the correct indent or -1 if unknown. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
906 func! s:InsideTag(foundHtmlString) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
907 "{{{ |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
908 if a:foundHtmlString |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
909 " Inside an attribute string. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
910 " Align with the previous line or use an external function. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
911 let lnum = v:lnum - 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
912 if lnum > 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
913 if exists('b:html_indent_tag_string_func') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
914 return b:html_indent_tag_string_func(lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
915 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
916 return indent(lnum) |
4869 | 917 endif |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
918 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
919 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
920 " Should be another attribute: " attr="val". Align with the previous |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
921 " attribute start. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
922 let lnum = v:lnum |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
923 while lnum > 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
924 let lnum -= 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
925 let text = getline(lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
926 " Find a match with one of these, align with "attr": |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
927 " attr= |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
928 " <tag attr= |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
929 " text<tag attr= |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
930 " <tag>text</tag>text<tag attr= |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
931 " For long lines search for the first match, finding the last match |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
932 " gets very slow. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
933 if len(text) < 300 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
934 let idx = match(text, '.*\s\zs[_a-zA-Z0-9-]\+="') |
4869 | 935 else |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
936 let idx = match(text, '\s\zs[_a-zA-Z0-9-]\+="') |
4869 | 937 endif |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
938 if idx > 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
939 " Found the attribute. TODO: assumes spaces, no Tabs. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
940 return idx |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
941 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
942 endwhile |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
943 return -1 |
4869 | 944 endfunc "}}} |
945 | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
946 " THE MAIN INDENT FUNCTION. Return the amount of indent for v:lnum. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
947 func! HtmlIndent() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
948 "{{{ |
6484 | 949 if prevnonblank(v:lnum - 1) < 1 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
950 " First non-blank line has no indent. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
951 return 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
952 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
953 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
954 let curtext = tolower(getline(v:lnum)) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
955 let indentunit = s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
956 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
957 let b:hi_newstate = {} |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
958 let b:hi_newstate.lnum = v:lnum |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
959 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
960 " When syntax HL is enabled, detect we are inside a tag. Indenting inside |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
961 " a tag works very differently. Do not do this when the line starts with |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
962 " "<", it gets the "htmlTag" ID but we are not inside a tag then. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
963 if curtext !~ '^\s*<' |
6159 | 964 normal! ^ |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
965 let stack = synstack(v:lnum, col('.')) " assumes there are no tabs |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
966 let foundHtmlString = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
967 for synid in reverse(stack) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
968 let name = synIDattr(synid, "name") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
969 if index(b:hi_insideStringNames, name) >= 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
970 let foundHtmlString = 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
971 elseif index(b:hi_insideTagNames, name) >= 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
972 " Yes, we are inside a tag. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
973 let indent = s:InsideTag(foundHtmlString) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
974 if indent >= 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
975 " Do not keep the state. TODO: could keep the block type. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
976 let b:hi_indent.lnum = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
977 return indent |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
978 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
979 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
980 endfor |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
981 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
982 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
983 " does the line start with a closing tag? |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
984 let swendtag = match(curtext, '^\s*</') >= 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
985 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
986 if prevnonblank(v:lnum - 1) == b:hi_indent.lnum && b:hi_lasttick == b:changedtick - 1 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
987 " use state (continue from previous line) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
988 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
989 " start over (know nothing) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
990 let b:hi_indent = s:FreshState(v:lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
991 endif |
4869 | 992 |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
993 if b:hi_indent.block >= 2 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
994 " within block |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
995 let endtag = s:endtags[b:hi_indent.block] |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
996 let blockend = stridx(curtext, endtag) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
997 if blockend >= 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
998 " block ends here |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
999 let b:hi_newstate.block = 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1000 " calc indent for REST OF LINE (may start more blocks): |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1001 call s:CountTagsAndState(strpart(curtext, blockend + strlen(endtag))) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1002 if swendtag && b:hi_indent.block != 5 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1003 let indent = b:hi_indent.blocktagind + s:curind * indentunit |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1004 let b:hi_newstate.baseindent = indent + s:nextrel * indentunit |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1005 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1006 let indent = s:Alien{b:hi_indent.block}() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1007 let b:hi_newstate.baseindent = b:hi_indent.blocktagind + s:nextrel * indentunit |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1008 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1009 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1010 " block continues |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1011 " indent this line with alien method |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1012 let indent = s:Alien{b:hi_indent.block}() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1013 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1014 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1015 " not within a block - within usual html |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1016 let b:hi_newstate.block = b:hi_indent.block |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1017 if swendtag |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1018 " The current line starts with an end tag, align with its start tag. |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1019 call cursor(v:lnum, 1) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1020 let start_lnum = HtmlIndent_FindStartTag() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1021 if start_lnum > 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1022 " check for the line starting with something inside a tag: |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1023 " <sometag <- align here |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1024 " attr=val><open> not here |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1025 let text = getline(start_lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1026 let angle = matchstr(text, '[<>]') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1027 if angle == '>' |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1028 call cursor(start_lnum, 1) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1029 normal! f>% |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1030 let start_lnum = line('.') |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1031 let text = getline(start_lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1032 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1033 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1034 let indent = indent(start_lnum) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1035 if col('.') > 2 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1036 let swendtag = match(text, '^\s*</') >= 0 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1037 call s:CountITags(text[: col('.') - 2]) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1038 let indent += s:nextrel * s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1039 if !swendtag |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1040 let indent += s:curind * s:ShiftWidth() |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1041 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1042 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1043 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1044 " not sure what to do |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1045 let indent = b:hi_indent.baseindent |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1046 endif |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1047 let b:hi_newstate.baseindent = indent |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1048 else |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1049 call s:CountTagsAndState(curtext) |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1050 let indent = b:hi_indent.baseindent |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1051 let b:hi_newstate.baseindent = indent + (s:curind + s:nextrel) * indentunit |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1052 endif |
6009 | 1053 endif |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1054 |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1055 let b:hi_lasttick = b:changedtick |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1056 call extend(b:hi_indent, b:hi_newstate, "force") |
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1057 return indent |
6009 | 1058 endfunc "}}} |
1059 | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1060 " Check user settings when loading this script the first time. |
4869 | 1061 call HtmlIndent_CheckUserSettings() |
7 | 1062 |
867 | 1063 let &cpo = s:cpo_save |
1064 unlet s:cpo_save | |
1065 | |
6032
b8f703a4e55f
Updated runtime files. Overhauled HTML indent script.
Bram Moolenaar <bram@vim.org>
parents:
6009
diff
changeset
|
1066 " vim: fdm=marker ts=8 sw=2 tw=78 |