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