diff options
author | ZyX <kp-pav@yandex.ru> | 2017-12-03 16:49:30 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-12-03 16:49:30 +0300 |
commit | c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57 (patch) | |
tree | b7e59c416d1435725c65f8952b6e55c70544d97e /runtime/indent/html.vim | |
parent | 62108c3b0be46936c83f6d4c98b44ceb5e6f77fd (diff) | |
parent | 27a577586eace687c47e7398845178208cae524a (diff) | |
download | rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.tar.gz rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.tar.bz2 rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.zip |
Merge branch 'master' into s-dash-stdin
Diffstat (limited to 'runtime/indent/html.vim')
-rw-r--r-- | runtime/indent/html.vim | 82 |
1 files changed, 34 insertions, 48 deletions
diff --git a/runtime/indent/html.vim b/runtime/indent/html.vim index 828bc3120b..37697841fd 100644 --- a/runtime/indent/html.vim +++ b/runtime/indent/html.vim @@ -2,7 +2,7 @@ " Header: "{{{ " Maintainer: Bram Moolenaar " Original Author: Andy Wokula <anwoku@yahoo.de> -" Last Change: 2016 Mar 30 +" Last Change: 2017 Jun 13 " Version: 1.0 " Description: HTML indent script with cached state for faster indenting on a " range of lines. @@ -25,27 +25,22 @@ if exists("b:did_indent") "{{{ finish endif + +" Load the Javascript indent script first, it defines GetJavascriptIndent(). +" Undo the rest. +" Load base python indent. +if !exists('*GetJavascriptIndent') + runtime! indent/javascript.vim +endif let b:did_indent = 1 setlocal indentexpr=HtmlIndent() setlocal indentkeys=o,O,<Return>,<>>,{,},!^F -" "j1" is included to make cindent() work better with Javascript. -setlocal cino=j1 -" "J1" should be included, but it doen't work properly before 7.4.355. -if has("patch-7.4.355") - setlocal cino+=J1 -endif -" Before patch 7.4.355 indenting after "(function() {" does not work well, add -" )2 to limit paren search. -if !has("patch-7.4.355") - setlocal cino+=)2 -endif - " Needed for % to work when finding start/end of a tag. setlocal matchpairs+=<:> -let b:undo_indent = "setlocal inde< indk< cino<" +let b:undo_indent = "setlocal inde< indk<" " b:hi_indent keeps state to speed up indenting consecutive lines. let b:hi_indent = {"lnum": -1} @@ -56,15 +51,6 @@ if exists("*HtmlIndent") && !exists('g:force_reload_html') finish endif -" shiftwidth() exists since patch 7.3.694 -if exists('*shiftwidth') - let s:ShiftWidth = function('shiftwidth') -else - func! s:ShiftWidth() - return &shiftwidth - endfunc -endif - " Allow for line continuation below. let s:cpo_save = &cpo set cpo-=C @@ -128,7 +114,7 @@ func! HtmlIndent_CheckUserSettings() let indone = {"zero": 0 \,"auto": "indent(prevnonblank(v:lnum-1))" - \,"inc": "b:hi_indent.blocktagind + s:ShiftWidth()"} + \,"inc": "b:hi_indent.blocktagind + shiftwidth()"} let script1 = '' if exists("b:html_indent_script1") @@ -363,7 +349,7 @@ func! s:CheckBlockTag(blocktag, ind) endif let b:hi_newstate.blocklnr = v:lnum " save allover indent for the endtag - let b:hi_newstate.blocktagind = b:hi_indent.baseindent + (s:nextrel + s:curind) * s:ShiftWidth() + let b:hi_newstate.blocktagind = b:hi_indent.baseindent + (s:nextrel + s:curind) * shiftwidth() if a:ind == 3 return "SCRIPT" " all except this must be lowercase " line is to be checked again for the type attribute @@ -485,7 +471,7 @@ func! s:FreshState(lnum) let state.blocklnr = stopline " check preceding tags in the line: call s:CountITags(tagline[: stopcol-2]) - let state.blocktagind = indent(stopline) + (s:curind + s:nextrel) * s:ShiftWidth() + let state.blocktagind = indent(stopline) + (s:curind + s:nextrel) * shiftwidth() return state elseif stopline == state.lnum " handle special case: previous line (= state.lnum) contains a @@ -495,7 +481,7 @@ func! s:FreshState(lnum) if !swendtag let [bline, bcol] = searchpos('<'.blocktag[1:].'\>', "bnW") call s:CountITags(tolower(getline(bline)[: bcol-2])) - let state.baseindent = indent(bline) + (s:curind + s:nextrel) * s:ShiftWidth() + let state.baseindent = indent(bline) + (s:curind + s:nextrel) * shiftwidth() return state endif endif @@ -516,7 +502,7 @@ func! s:FreshState(lnum) if found == 2 let state.baseindent = b:hi_indent.baseindent endif - let state.blocktagind = indent(comlnum) + (s:curind + s:nextrel) * s:ShiftWidth() + let state.blocktagind = indent(comlnum) + (s:curind + s:nextrel) * shiftwidth() return state endif @@ -535,7 +521,7 @@ func! s:FreshState(lnum) let text = tolower(getline(comlnum)[: comcol-2]) endif call s:CountITags(text) - let state.baseindent = indent(comlnum) + (s:curind + s:nextrel) * s:ShiftWidth() + let state.baseindent = indent(comlnum) + (s:curind + s:nextrel) * shiftwidth() " TODO check tags that follow "-->" return state endif @@ -555,9 +541,9 @@ func! s:FreshState(lnum) let text = getline(start_lnum) let swendtag = match(text, '^\s*</') >= 0 call s:CountITags(text[: col('.') - 2]) - let state.baseindent += s:nextrel * s:ShiftWidth() + let state.baseindent += s:nextrel * shiftwidth() if !swendtag - let state.baseindent += s:curind * s:ShiftWidth() + let state.baseindent += s:curind * shiftwidth() endif endif return state @@ -570,9 +556,9 @@ func! s:FreshState(lnum) let text = getline(state.lnum) let swendtag = match(text, '^\s*</') >= 0 call s:CountITags(tolower(text)) - let state.baseindent = indent(state.lnum) + s:nextrel * s:ShiftWidth() + let state.baseindent = indent(state.lnum) + s:nextrel * shiftwidth() if !swendtag - let state.baseindent += s:curind * s:ShiftWidth() + let state.baseindent += s:curind * shiftwidth() endif return state endfunc "}}} @@ -596,7 +582,7 @@ func! s:Alien3() return eval(b:hi_js1indent) endif if b:hi_indent.scripttype == "javascript" - return cindent(v:lnum) + return GetJavascriptIndent() else return -1 endif @@ -651,7 +637,7 @@ func! s:CSSIndent() " add indent after { let brace_counts = HtmlIndent_CountBraces(prev_lnum) - let extra = brace_counts.c_open * s:ShiftWidth() + let extra = brace_counts.c_open * shiftwidth() let prev_text = getline(prev_lnum) let below_end_brace = prev_text =~ '}\s*$' @@ -668,7 +654,7 @@ func! s:CSSIndent() " if the current line is not a comment or starts with @ (used by template " systems) reduce indent if previous line is a continuation line if !prev_hasfield && !prev_special - let extra = -s:ShiftWidth() + let extra = -shiftwidth() endif else let cur_hasfield = curtext =~ '^\s*[a-zA-Z0-9-]\+:' @@ -676,14 +662,14 @@ func! s:CSSIndent() if !cur_hasfield && (prev_hasfield || prev_unfinished) " Continuation line has extra indent if the previous line was not a " continuation line. - let extra = s:ShiftWidth() + let extra = shiftwidth() " Align with @if if prev_text =~ '^\s*@if ' let extra = 4 endif elseif cur_hasfield && !prev_hasfield && !prev_special " less indent below a continuation line - let extra = -s:ShiftWidth() + let extra = -shiftwidth() endif endif endif @@ -704,10 +690,10 @@ func! s:CSSIndent() if special " do not reduce indent below @{ ... } if extra < 0 - let extra += s:ShiftWidth() + let extra += shiftwidth() endif else - let extra -= (brace_counts.c_close - (prev_text =~ '^\s*}')) * s:ShiftWidth() + let extra -= (brace_counts.c_close - (prev_text =~ '^\s*}')) * shiftwidth() endif endif @@ -715,10 +701,10 @@ func! s:CSSIndent() if extra == 0 if brace_counts.p_open > brace_counts.p_close " previous line has more ( than ): add a shiftwidth - let extra = s:ShiftWidth() + let extra = shiftwidth() elseif brace_counts.p_open < brace_counts.p_close " previous line has more ) than (: subtract a shiftwidth - let extra = -s:ShiftWidth() + let extra = -shiftwidth() endif endif @@ -749,7 +735,7 @@ func! s:CssPrevNonComment(lnum, stopline) while 1 let ccol = match(getline(lnum), '\*/') if ccol < 0 - " No comment end thus its something else. + " No comment end thus it's something else. return lnum endif call cursor(lnum, ccol + 1) @@ -821,7 +807,7 @@ func! s:Alien5() let idx = match(prevtext, '^\s*\zs<!--') if idx >= 0 " just below comment start, add a shiftwidth - return idx + s:ShiftWidth() + return idx + shiftwidth() endif " Some files add 4 spaces just below a TODO line. It's difficult to detect @@ -842,7 +828,7 @@ func! s:Alien6() return indent(lnum) endif endif - return b:hi_indent.baseindent + s:ShiftWidth() + return b:hi_indent.baseindent + shiftwidth() endfunc "}}} " When the "lnum" line ends in ">" find the line containing the matching "<". @@ -952,7 +938,7 @@ func! HtmlIndent() endif let curtext = tolower(getline(v:lnum)) - let indentunit = s:ShiftWidth() + let indentunit = shiftwidth() let b:hi_newstate = {} let b:hi_newstate.lnum = v:lnum @@ -1035,9 +1021,9 @@ func! HtmlIndent() if col('.') > 2 let swendtag = match(text, '^\s*</') >= 0 call s:CountITags(text[: col('.') - 2]) - let indent += s:nextrel * s:ShiftWidth() + let indent += s:nextrel * shiftwidth() if !swendtag - let indent += s:curind * s:ShiftWidth() + let indent += s:curind * shiftwidth() endif endif else |