comparison runtime/indent/html.vim @ 13437:02b3f719eacb

Update runtime files. commit https://github.com/vim/vim/commit/b5b7562475ad032a174b893286172de0d2c157cd Author: Bram Moolenaar <Bram@vim.org> Date: Fri Mar 9 22:22:21 2018 +0100 Update runtime files.
author Christian Brabandt <cb@256bit.org>
date Fri, 09 Mar 2018 22:30:06 +0100
parents 63b0b7b79b25
children 9eebe457eb3c
comparison
equal deleted inserted replaced
13436:698a757ec8ec 13437:02b3f719eacb
1 " Vim indent script for HTML 1 " Vim indent script for HTML
2 " Header: "{{{ 2 " Header: "{{{
3 " Maintainer: Bram Moolenaar 3 " Maintainer: Bram Moolenaar
4 " Original Author: Andy Wokula <anwoku@yahoo.de> 4 " Original Author: Andy Wokula <anwoku@yahoo.de>
5 " Last Change: 2017 Jun 13 5 " Last Change: 2018 Mar 09
6 " Version: 1.0 6 " Version: 1.0
7 " Description: HTML indent script with cached state for faster indenting on a 7 " Description: HTML indent script with cached state for faster indenting on a
8 " range of lines. 8 " range of lines.
9 " Supports template systems through hooks. 9 " Supports template systems through hooks.
10 " Supports Closure stylesheets. 10 " Supports Closure stylesheets.
53 53
54 " Allow for line continuation below. 54 " Allow for line continuation below.
55 let s:cpo_save = &cpo 55 let s:cpo_save = &cpo
56 set cpo-=C 56 set cpo-=C
57 "}}} 57 "}}}
58
59 " Pattern to match the name of a tag, including custom elements.
60 let s:tagname = '\w\+\(-\w\+\)*'
58 61
59 " Check and process settings from b:html_indent and g:html_indent... variables. 62 " Check and process settings from b:html_indent and g:html_indent... variables.
60 " Prefer using buffer-local settings over global settings, so that there can 63 " Prefer using buffer-local settings over global settings, so that there can
61 " be defaults for all HTML files and exceptions for specific types of HTML 64 " be defaults for all HTML files and exceptions for specific types of HTML
62 " files. 65 " files.
278 " Store the result in s:curind and s:nextrel. 281 " Store the result in s:curind and s:nextrel.
279 let s:curind = 0 " relative indent steps for current line [unit &sw]: 282 let s:curind = 0 " relative indent steps for current line [unit &sw]:
280 let s:nextrel = 0 " relative indent steps for next line [unit &sw]: 283 let s:nextrel = 0 " relative indent steps for next line [unit &sw]:
281 let s:block = 0 " assume starting outside of a block 284 let s:block = 0 " assume starting outside of a block
282 let s:countonly = 1 " don't change state 285 let s:countonly = 1 " don't change state
283 call substitute(a:text, '<\zs/\=\w\+\(-\w\+\)*\>\|<!--\[\|\[endif\]-->\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') 286 call substitute(a:text, '<\zs/\=' . s:tagname . '\>\|<!--\[\|\[endif\]-->\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g')
284 let s:countonly = 0 287 let s:countonly = 0
285 endfunc "}}} 288 endfunc "}}}
286 289
287 " Count the number of start and end tags in text. 290 " Count the number of start and end tags in text.
288 func! s:CountTagsAndState(text) 291 func! s:CountTagsAndState(text)
290 " Store the result in s:curind and s:nextrel. Update b:hi_newstate.block. 293 " Store the result in s:curind and s:nextrel. Update b:hi_newstate.block.
291 let s:curind = 0 " relative indent steps for current line [unit &sw]: 294 let s:curind = 0 " relative indent steps for current line [unit &sw]:
292 let s:nextrel = 0 " relative indent steps for next line [unit &sw]: 295 let s:nextrel = 0 " relative indent steps for next line [unit &sw]:
293 296
294 let s:block = b:hi_newstate.block 297 let s:block = b:hi_newstate.block
295 let tmp = substitute(a:text, '<\zs/\=\w\+\(-\w\+\)*\>\|<!--\[\|\[endif\]-->\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') 298 let tmp = substitute(a:text, '<\zs/\=' . s:tagname . '\>\|<!--\[\|\[endif\]-->\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g')
296 if s:block == 3 299 if s:block == 3
297 let b:hi_newstate.scripttype = s:GetScriptType(matchstr(tmp, '\C.*<SCRIPT\>\zs[^>]*')) 300 let b:hi_newstate.scripttype = s:GetScriptType(matchstr(tmp, '\C.*<SCRIPT\>\zs[^>]*'))
298 endif 301 endif
299 let b:hi_newstate.block = s:block 302 let b:hi_newstate.block = s:block
300 endfunc "}}} 303 endfunc "}}}
528 531
529 " Check if the previous line starts with end tag. 532 " Check if the previous line starts with end tag.
530 let swendtag = match(text, '^\s*</') >= 0 533 let swendtag = match(text, '^\s*</') >= 0
531 534
532 " If previous line ended in a closing tag, line up with the opening tag. 535 " If previous line ended in a closing tag, line up with the opening tag.
533 if !swendtag && text =~ '</\w\+\s*>\s*$' 536 if !swendtag && text =~ '</' . s:tagname . '\s*>\s*$'
534 call cursor(state.lnum, 99999) 537 call cursor(state.lnum, 99999)
535 normal! F< 538 normal! F<
536 let start_lnum = HtmlIndent_FindStartTag() 539 let start_lnum = HtmlIndent_FindStartTag()
537 if start_lnum > 0 540 if start_lnum > 0
538 let state.baseindent = indent(start_lnum) 541 let state.baseindent = indent(start_lnum)
858 func! HtmlIndent_FindStartTag() 861 func! HtmlIndent_FindStartTag()
859 "{{{ 862 "{{{
860 " The cursor must be on or before a closing tag. 863 " The cursor must be on or before a closing tag.
861 " If found, positions the cursor at the match and returns the line number. 864 " If found, positions the cursor at the match and returns the line number.
862 " Otherwise returns 0. 865 " Otherwise returns 0.
863 let tagname = matchstr(getline('.')[col('.') - 1:], '</\zs\w\+\ze') 866 let tagname = matchstr(getline('.')[col('.') - 1:], '</\zs' . s:tagname . '\ze')
864 let start_lnum = searchpair('<' . tagname . '\>', '', '</' . tagname . '\>', 'bW') 867 let start_lnum = searchpair('<' . tagname . '\>', '', '</' . tagname . '\>', 'bW')
865 if start_lnum > 0 868 if start_lnum > 0
866 return start_lnum 869 return start_lnum
867 endif 870 endif
868 return 0 871 return 0
874 " Call this with the cursor on the "<" of a start tag. 877 " Call this with the cursor on the "<" of a start tag.
875 " This will move the cursor to the ">" of the matching end tag or, when it's 878 " This will move the cursor to the ">" of the matching end tag or, when it's
876 " a self-closing tag, to the matching ">". 879 " a self-closing tag, to the matching ">".
877 " Limited to look up to b:html_indent_line_limit lines away. 880 " Limited to look up to b:html_indent_line_limit lines away.
878 let text = getline('.') 881 let text = getline('.')
879 let tagname = matchstr(text, '\w\+\|!--', col('.')) 882 let tagname = matchstr(text, s:tagname . '\|!--', col('.'))
880 if tagname == '!--' 883 if tagname == '!--'
881 call search('--\zs>') 884 call search('--\zs>')
882 elseif s:get_tag('/' . tagname) != 0 885 elseif s:get_tag('/' . tagname) != 0
883 " tag with a closing tag, find matching "</tag>" 886 " tag with a closing tag, find matching "</tag>"
884 call searchpair('<' . tagname, '', '</' . tagname . '\zs>', 'W', '', line('.') + b:html_indent_line_limit) 887 call searchpair('<' . tagname, '', '</' . tagname . '\zs>', 'W', '', line('.') + b:html_indent_line_limit)
919 if len(text) < 300 922 if len(text) < 300
920 let idx = match(text, '.*\s\zs[_a-zA-Z0-9-]\+="') 923 let idx = match(text, '.*\s\zs[_a-zA-Z0-9-]\+="')
921 else 924 else
922 let idx = match(text, '\s\zs[_a-zA-Z0-9-]\+="') 925 let idx = match(text, '\s\zs[_a-zA-Z0-9-]\+="')
923 endif 926 endif
927 if idx == -1
928 " try <tag attr
929 let idx = match(text, '<' . s:tagname . '\s\+\zs\w')
930 endif
931 if idx == -1
932 " after just <tag indent one level more
933 let idx = match(text, '<' . s:tagname . '$')
934 if idx >= 0
935 call cursor(lnum, idx)
936 return virtcol('.') + shiftwidth()
937 endif
938 endif
924 if idx > 0 939 if idx > 0
925 " Found the attribute. TODO: assumes spaces, no Tabs. 940 " Found the attribute to align with.
926 return idx 941 call cursor(lnum, idx)
942 return virtcol('.')
927 endif 943 endif
928 endwhile 944 endwhile
929 return -1 945 return -1
930 endfunc "}}} 946 endfunc "}}}
931 947