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