diff options
Diffstat (limited to 'runtime/indent')
-rw-r--r-- | runtime/indent/dosbatch.vim | 59 | ||||
-rw-r--r-- | runtime/indent/dtd.vim | 6 | ||||
-rw-r--r-- | runtime/indent/html.vim | 49 | ||||
-rw-r--r-- | runtime/indent/javascript.vim | 183 | ||||
-rw-r--r-- | runtime/indent/logtalk.vim | 5 | ||||
-rw-r--r-- | runtime/indent/nsis.vim | 91 | ||||
-rw-r--r-- | runtime/indent/php.vim | 104 | ||||
-rw-r--r-- | runtime/indent/prolog.vim | 13 | ||||
-rw-r--r-- | runtime/indent/python.vim | 14 | ||||
-rw-r--r-- | runtime/indent/r.vim | 37 | ||||
-rw-r--r-- | runtime/indent/rmd.vim | 25 | ||||
-rw-r--r-- | runtime/indent/rnoweb.vim | 2 | ||||
-rw-r--r-- | runtime/indent/sas.vim | 38 | ||||
-rw-r--r-- | runtime/indent/scheme.vim | 9 | ||||
-rw-r--r-- | runtime/indent/sh.vim | 85 | ||||
-rw-r--r-- | runtime/indent/teraterm.vim | 4 | ||||
-rw-r--r-- | runtime/indent/tex.vim | 30 | ||||
-rw-r--r-- | runtime/indent/wast.vim | 17 | ||||
-rw-r--r-- | runtime/indent/xml.vim | 9 |
19 files changed, 580 insertions, 200 deletions
diff --git a/runtime/indent/dosbatch.vim b/runtime/indent/dosbatch.vim new file mode 100644 index 0000000000..aea2a184d4 --- /dev/null +++ b/runtime/indent/dosbatch.vim @@ -0,0 +1,59 @@ +" Vim indent file +" Language: MSDOS batch file (with NT command extensions) +" Maintainer: Ken Takata +" URL: https://github.com/k-takata/vim-dosbatch-indent +" Last Change: 2017 May 10 +" Filenames: *.bat +" License: VIM License + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal nosmartindent +setlocal noautoindent +setlocal indentexpr=GetDosBatchIndent(v:lnum) +setlocal indentkeys=!^F,o,O +setlocal indentkeys+=0=) + +if exists("*GetDosBatchIndent") + finish +endif + +let s:cpo_save = &cpo +set cpo&vim + +function! GetDosBatchIndent(lnum) + let l:prevlnum = prevnonblank(a:lnum-1) + if l:prevlnum == 0 + " top of file + return 0 + endif + + " grab the previous and current line, stripping comments. + let l:prevl = substitute(getline(l:prevlnum), '\c^\s*\%(@\s*\)\?rem\>.*$', '', '') + let l:thisl = getline(a:lnum) + let l:previ = indent(l:prevlnum) + + let l:ind = l:previ + + if l:prevl =~? '^\s*@\=if\>.*(\s*$' || + \ l:prevl =~? '\<do\>\s*(\s*$' || + \ l:prevl =~? '\<else\>\s*\%(if\>.*\)\?(\s*$' || + \ l:prevl =~? '^.*\(&&\|||\)\s*(\s*$' + " previous line opened a block + let l:ind += shiftwidth() + endif + if l:thisl =~ '^\s*)' + " this line closed a block + let l:ind -= shiftwidth() + endif + + return l:ind +endfunction + +let &cpo = s:cpo_save +unlet s:cpo_save + +" vim: ts=8 sw=2 sts=2 diff --git a/runtime/indent/dtd.vim b/runtime/indent/dtd.vim index 5633362367..963ac408ef 100644 --- a/runtime/indent/dtd.vim +++ b/runtime/indent/dtd.vim @@ -3,9 +3,6 @@ " Previous Maintainer: Nikolai Weibull <now@bitwi.se> " Latest Revision: 2011-07-08 -let s:cpo_save = &cpo -set cpo&vim - setlocal indentexpr=GetDTDIndent() setlocal indentkeys=!^F,o,O,> setlocal nosmartindent @@ -14,6 +11,9 @@ if exists("*GetDTDIndent") finish endif +let s:cpo_save = &cpo +set cpo&vim + " TODO: Needs to be adjusted to stop at [, <, and ]. let s:token_pattern = '^[^[:space:]]\+' diff --git a/runtime/indent/html.vim b/runtime/indent/html.vim index 37697841fd..6c866594c5 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: 2017 Jun 13 +" Last Change: 2018 Mar 28 " Version: 1.0 " Description: HTML indent script with cached state for faster indenting on a " range of lines. @@ -56,6 +56,9 @@ let s:cpo_save = &cpo set cpo-=C "}}} +" Pattern to match the name of a tag, including custom elements. +let s:tagname = '\w\+\(-\w\+\)*' + " Check and process settings from b:html_indent and g:html_indent... variables. " Prefer using buffer-local settings over global settings, so that there can " be defaults for all HTML files and exceptions for specific types of HTML @@ -213,7 +216,8 @@ endfunc "}}} " Add known tag pairs. " Self-closing tags and tags that are sometimes {{{ " self-closing (e.g., <p>) are not here (when encountering </p> we can find -" the matching <p>, but not the other way around). +" the matching <p>, but not the other way around). Known self-closing tags: +" 'p', 'img', 'source'. " Old HTML tags: call s:AddITags(s:indent_tags, [ \ 'a', 'abbr', 'acronym', 'address', 'b', 'bdo', 'big', @@ -230,9 +234,9 @@ call s:AddITags(s:indent_tags, [ call s:AddITags(s:indent_tags, [ \ 'area', 'article', 'aside', 'audio', 'bdi', 'canvas', \ 'command', 'data', 'datalist', 'details', 'embed', 'figcaption', - \ 'figure', 'footer', 'header', 'keygen', 'mark', 'meter', 'nav', 'output', - \ 'progress', 'rp', 'rt', 'ruby', 'section', 'source', 'summary', 'svg', - \ 'time', 'track', 'video', 'wbr']) + \ 'figure', 'footer', 'header', 'keygen', 'main', 'mark', 'meter', + \ 'nav', 'output', 'picture', 'progress', 'rp', 'rt', 'ruby', 'section', + \ 'summary', 'svg', 'time', 'track', 'video', 'wbr']) " Tags added for web components: call s:AddITags(s:indent_tags, [ @@ -280,7 +284,7 @@ func! s:CountITags(text) let s:nextrel = 0 " relative indent steps for next line [unit &sw]: let s:block = 0 " assume starting outside of a block let s:countonly = 1 " don't change state - call substitute(a:text, '<\zs/\=\w\+\(-\w\+\)*\>\|<!--\[\|\[endif\]-->\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') + call substitute(a:text, '<\zs/\=' . s:tagname . '\>\|<!--\[\|\[endif\]-->\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') let s:countonly = 0 endfunc "}}} @@ -292,7 +296,7 @@ func! s:CountTagsAndState(text) let s:nextrel = 0 " relative indent steps for next line [unit &sw]: let s:block = b:hi_newstate.block - let tmp = substitute(a:text, '<\zs/\=\w\+\(-\w\+\)*\>\|<!--\[\|\[endif\]-->\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') + let tmp = substitute(a:text, '<\zs/\=' . s:tagname . '\>\|<!--\[\|\[endif\]-->\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g') if s:block == 3 let b:hi_newstate.scripttype = s:GetScriptType(matchstr(tmp, '\C.*<SCRIPT\>\zs[^>]*')) endif @@ -530,7 +534,7 @@ func! s:FreshState(lnum) let swendtag = match(text, '^\s*</') >= 0 " If previous line ended in a closing tag, line up with the opening tag. - if !swendtag && text =~ '</\w\+\s*>\s*$' + if !swendtag && text =~ '</' . s:tagname . '\s*>\s*$' call cursor(state.lnum, 99999) normal! F< let start_lnum = HtmlIndent_FindStartTag() @@ -659,7 +663,7 @@ func! s:CSSIndent() else let cur_hasfield = curtext =~ '^\s*[a-zA-Z0-9-]\+:' let prev_unfinished = s:CssUnfinished(prev_text) - if !cur_hasfield && (prev_hasfield || prev_unfinished) + if prev_unfinished " Continuation line has extra indent if the previous line was not a " continuation line. let extra = shiftwidth() @@ -712,9 +716,13 @@ func! s:CSSIndent() endfunc "}}} " Inside <style>: Whether a line is unfinished. +" tag: +" tag: blah +" tag: blah && +" tag: blah || func! s:CssUnfinished(text) "{{{ - return a:text =~ '\s\(||\|&&\|:\)\s*$' + return a:text =~ '\(||\|&&\|:\|\k\)\s*$' endfunc "}}} " Search back for the first unfinished line above "lnum". @@ -860,7 +868,7 @@ func! HtmlIndent_FindStartTag() " The cursor must be on or before a closing tag. " If found, positions the cursor at the match and returns the line number. " Otherwise returns 0. - let tagname = matchstr(getline('.')[col('.') - 1:], '</\zs\w\+\ze') + let tagname = matchstr(getline('.')[col('.') - 1:], '</\zs' . s:tagname . '\ze') let start_lnum = searchpair('<' . tagname . '\>', '', '</' . tagname . '\>', 'bW') if start_lnum > 0 return start_lnum @@ -876,7 +884,7 @@ func! HtmlIndent_FindTagEnd() " a self-closing tag, to the matching ">". " Limited to look up to b:html_indent_line_limit lines away. let text = getline('.') - let tagname = matchstr(text, '\w\+\|!--', col('.')) + let tagname = matchstr(text, s:tagname . '\|!--', col('.')) if tagname == '!--' call search('--\zs>') elseif s:get_tag('/' . tagname) != 0 @@ -921,9 +929,22 @@ func! s:InsideTag(foundHtmlString) else let idx = match(text, '\s\zs[_a-zA-Z0-9-]\+="') endif + if idx == -1 + " try <tag attr + let idx = match(text, '<' . s:tagname . '\s\+\zs\w') + endif + if idx == -1 + " after just <tag indent one level more + let idx = match(text, '<' . s:tagname . '$') + if idx >= 0 + call cursor(lnum, idx) + return virtcol('.') + shiftwidth() + endif + endif if idx > 0 - " Found the attribute. TODO: assumes spaces, no Tabs. - return idx + " Found the attribute to align with. + call cursor(lnum, idx) + return virtcol('.') endif endwhile return -1 diff --git a/runtime/indent/javascript.vim b/runtime/indent/javascript.vim index 2861716287..f3bf96aa97 100644 --- a/runtime/indent/javascript.vim +++ b/runtime/indent/javascript.vim @@ -2,7 +2,7 @@ " Language: Javascript " Maintainer: Chris Paul ( https://github.com/bounceme ) " URL: https://github.com/pangloss/vim-javascript -" Last Change: September 18, 2017 +" Last Change: December 4, 2017 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -10,10 +10,6 @@ if exists('b:did_indent') endif let b:did_indent = 1 -" indent correctly if inside <script> -" vim/vim@690afe1 for the switch from cindent -let b:html_indent_script1 = 'inc' - " Now, set up our indentation expression and keys that trigger it. setlocal indentexpr=GetJavascriptIndent() setlocal autoindent nolisp nosmartindent @@ -25,13 +21,6 @@ setlocal indentkeys+=0],0) let b:undo_indent = 'setlocal indentexpr< smartindent< autoindent< indentkeys<' -" Regex of syntax group names that are or delimit string or are comments. -let b:syng_strcom = get(b:,'syng_strcom','string\|comment\|regex\|special\|doc\|template\%(braces\)\@!') -let b:syng_str = get(b:,'syng_str','string\|template\|special') -" template strings may want to be excluded when editing graphql: -" au! Filetype javascript let b:syng_str = '^\%(.*template\)\@!.*string\|special' -" au! Filetype javascript let b:syng_strcom = '^\%(.*template\)\@!.*string\|comment\|regex\|special\|doc' - " Only define the function once. if exists('*GetJavascriptIndent') finish @@ -40,6 +29,23 @@ endif let s:cpo_save = &cpo set cpo&vim +" indent correctly if inside <script> +" vim/vim@690afe1 for the switch from cindent +" overridden with b:html_indent_script1 +call extend(g:,{'html_indent_script1': 'inc'},'keep') + +" Regex of syntax group names that are or delimit string or are comments. +let s:bvars = { + \ 'syng_strcom': 'string\|comment\|regex\|special\|doc\|template\%(braces\)\@!', + \ 'syng_str': 'string\|template\|special' } +" template strings may want to be excluded when editing graphql: +" au! Filetype javascript let b:syng_str = '^\%(.*template\)\@!.*string\|special' +" au! Filetype javascript let b:syng_strcom = '^\%(.*template\)\@!.*string\|comment\|regex\|special\|doc' + +function s:GetVars() + call extend(b:,extend(s:bvars,{'js_cache': [0,0,0]}),'keep') +endfunction + " Get shiftwidth value if exists('*shiftwidth') function s:sw() @@ -104,21 +110,22 @@ endfunction function s:SkipFunc() if s:top_col == 1 throw 'out of bounds' - endif - let s:top_col = 0 - if s:check_in + elseif s:check_in if eval(s:skip_expr) return 1 endif let s:check_in = 0 elseif getline('.') =~ '\%<'.col('.').'c\/.\{-}\/\|\%>'.col('.').'c[''"]\|\\$' if eval(s:skip_expr) - let s:looksyn = a:firstline return 1 endif - elseif search('\m`\|\${\|\*\/','nW'.s:z,s:looksyn) && eval(s:skip_expr) - let s:check_in = 1 - return 1 + elseif search('\m`\|\${\|\*\/','nW'.s:z,s:looksyn) + if eval(s:skip_expr) + let s:check_in = 1 + return 1 + endif + else + let s:synid_cache[:] += [[line2byte('.') + col('.') - 1], ['']] endif let [s:looksyn, s:top_col] = getpos('.')[1:2] endfunction @@ -159,19 +166,29 @@ function s:Token() return s:LookingAt() =~ '\k' ? expand('<cword>') : s:LookingAt() endfunction -function s:PreviousToken() - let l:col = col('.') +function s:PreviousToken(...) + let [l:pos, tok] = [getpos('.'), ''] if search('\m\k\{1,}\|\S','ebW') - if search('\m\*\%#\/\|\/\/\%<'.a:firstline.'l','nbW',line('.')) && eval(s:in_comm) - if s:SearchLoop('\S\ze\_s*\/[/*]','bW',s:in_comm) - return s:Token() + if getline('.')[col('.')-2:col('.')-1] == '*/' + if eval(s:in_comm) && !s:SearchLoop('\S\ze\_s*\/[/*]','bW',s:in_comm) + call setpos('.',l:pos) + else + let tok = s:Token() endif - call cursor(a:firstline, l:col) else - return s:Token() + let two = a:0 || line('.') != l:pos[1] ? strridx(getline('.')[:col('.')],'//') + 1 : 0 + if two && eval(s:in_comm) + call cursor(0,two) + let tok = s:PreviousToken(1) + if tok is '' + call setpos('.',l:pos) + endif + else + let tok = s:Token() + endif endif endif - return '' + return tok endfunction function s:Pure(f,...) @@ -183,23 +200,30 @@ function s:SearchLoop(pat,flags,expr) endfunction function s:ExprCol() + if getline('.')[col('.')-2] == ':' + return 1 + endif let bal = 0 - while s:SearchLoop('[{}?]\|\_[^:]\zs::\@!','bW',s:skip_expr) + while s:SearchLoop('[{}?:]','bW',s:skip_expr) if s:LookingAt() == ':' + if getline('.')[col('.')-2] == ':' + call cursor(0,col('.')-1) + continue + endif let bal -= 1 elseif s:LookingAt() == '?' - let bal += 1 - if bal == 1 - break + if getline('.')[col('.'):col('.')+1] =~ '^\.\d\@!' + continue + elseif !bal + return 1 endif + let bal += 1 elseif s:LookingAt() == '{' - let bal = !s:IsBlock() - break + return !s:IsBlock() elseif !s:GetPair('{','}','bW',s:skip_expr) break endif endwhile - return s:Nat(bal) endfunction " configurable regexes that define continuation lines, not including (, {, or [. @@ -208,30 +232,29 @@ let s:opfirst = '^' . get(g:,'javascript_opfirst', let s:continuation = get(g:,'javascript_continuation', \ '\C\%([<=,.~!?/*^%|&:]\|+\@<!+\|-\@<!-\|=\@<!>\|\<\%(typeof\|new\|delete\|void\|in\|instanceof\|await\)\)') . '$' -function s:Continues(ln,con) - let tok = matchstr(a:con[-15:],s:continuation) +function s:Continues() + let tok = matchstr(strpart(getline('.'),col('.')-15,15),s:continuation) if tok =~ '[a-z:]' - call cursor(a:ln, len(a:con)) return tok == ':' ? s:ExprCol() : s:PreviousToken() != '.' elseif tok !~ '[/>]' return tok isnot '' endif - return s:SynAt(a:ln, len(a:con)) !~? (tok == '>' ? 'jsflow\|^html' : 'regex') + return s:SynAt(line('.'),col('.')) !~? (tok == '>' ? 'jsflow\|^html' : 'regex') endfunction " Check if line 'lnum' has a balanced amount of parentheses. -function s:Balanced(lnum) - let [l:open, l:line] = [0, getline(a:lnum)] - let pos = match(l:line, '[][(){}]') +function s:Balanced(lnum,line) + let l:open = 0 + let pos = match(a:line, '[][(){}]') while pos != -1 if s:SynAt(a:lnum,pos + 1) !~? b:syng_strcom - let l:open += match(' ' . l:line[pos],'[[({]') + let l:open += match(' ' . a:line[pos],'[[({]') if l:open < 0 return endif endif - let pos = match(l:line, !l:open ? '[][(){}]' : '()' =~ l:line[pos] ? - \ '[()]' : '{}' =~ l:line[pos] ? '[{}]' : '[][]', pos + 1) + let pos = match(a:line, !l:open ? '[][(){}]' : '()' =~ a:line[pos] ? + \ '[()]' : '{}' =~ a:line[pos] ? '[{}]' : '[][]', pos + 1) endwhile return !l:open endfunction @@ -244,27 +267,38 @@ function s:OneScope() \ s:Pure('s:PreviousToken') != '.' && !(tok == 'while' && s:DoWhile()) elseif s:Token() =~# '^else$\|^do$' return s:Pure('s:PreviousToken') != '.' + elseif strpart(getline('.'),col('.')-2,2) == '=>' + call cursor(0,col('.')-1) + if s:PreviousToken() == ')' + return s:GetPair('(', ')', 'bW', s:skip_expr) + endif + return 1 endif - return strpart(getline('.'),col('.')-2,2) == '=>' endfunction function s:DoWhile() let cpos = searchpos('\m\<','cbW') - if s:SearchLoop('\C[{}]\|\<\%(do\|while\)\>','bW',s:skip_expr) - if s:{s:LookingAt() == '}' && s:GetPair('{','}','bW',s:skip_expr) ? - \ 'Previous' : ''}Token() ==# 'do' && s:IsBlock() - return 1 + while s:SearchLoop('\C[{}]\|\<\%(do\|while\)\>','bW',s:skip_expr) + if s:LookingAt() =~ '\a' + if s:Pure('s:IsBlock') + if s:LookingAt() ==# 'd' + return 1 + endif + break + endif + elseif s:LookingAt() != '}' || !s:GetPair('{','}','bW',s:skip_expr) + break endif - call call('cursor',cpos) - endif + endwhile + call call('cursor',cpos) endfunction " returns total offset from braceless contexts. 'num' is the lineNr which " encloses the entire context, 'cont' if whether a:firstline is a continued " expression, which could have started in a braceless context -function s:IsContOne(num,cont) - let [l:num, b_l] = [a:num + !a:num, 0] - let pind = a:num ? indent(a:num) + s:sw() : 0 +function s:IsContOne(cont) + let [l:num, b_l] = [b:js_cache[1] + !b:js_cache[1], 0] + let pind = b:js_cache[1] ? indent(b:js_cache[1]) + s:sw() : 0 let ind = indent('.') + !a:cont while line('.') > l:num && ind > pind || line('.') == l:num if indent('.') < ind && s:OneScope() @@ -282,20 +316,16 @@ function s:IsContOne(num,cont) return b_l endfunction -function s:Class() - return (s:Token() ==# 'class' || s:PreviousToken() =~# '^class$\|^extends$') && - \ s:PreviousToken() != '.' -endfunction - function s:IsSwitch() - return s:PreviousToken() !~ '[.*]' && - \ (!s:GetPair('{','}','cbW',s:skip_expr) || s:IsBlock() && !s:Class()) + call call('cursor',b:js_cache[1:]) + return search('\m\C\%#.\_s*\%(\%(\/\/.*\_$\|\/\*\_.\{-}\*\/\)\@>\_s*\)*\%(case\|default\)\>','nWc'.s:z) endfunction " https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader function s:IsBlock() let tok = s:PreviousToken() if join(s:stack) =~? 'xml\|jsx' && s:SynAt(line('.'),col('.')-1) =~? 'xml\|jsx' + let s:in_jsx = 1 return tok != '{' elseif tok =~ '\k' if tok ==# 'type' @@ -320,7 +350,7 @@ function s:IsBlock() endfunction function GetJavascriptIndent() - let b:js_cache = get(b:,'js_cache',[0,0,0]) + call s:GetVars() let s:synid_cache = [[],[]] let l:line = getline(v:lnum) " use synstack as it validates syn state and works in an empty line @@ -334,7 +364,7 @@ function GetJavascriptIndent() return -1 endif elseif s:stack[-1] =~? b:syng_str - if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1) + if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1,getline(v:lnum-1)) let b:js_cache[0] = v:lnum endif return -1 @@ -361,7 +391,7 @@ function GetJavascriptIndent() call cursor(v:lnum,1) let idx = index([']',')','}'],l:line[0]) if b:js_cache[0] > l:lnum && b:js_cache[0] < v:lnum || - \ b:js_cache[0] == l:lnum && s:Balanced(l:lnum) + \ b:js_cache[0] == l:lnum && s:Balanced(l:lnum,pline) call call('cursor',b:js_cache[1:]) else let [s:looksyn, s:top_col, s:check_in, s:l1] = [v:lnum - 1,0,0, @@ -382,10 +412,10 @@ function GetJavascriptIndent() let [b:js_cache[0], num] = [v:lnum, b:js_cache[1]] - let [num_ind, is_op, b_l, l:switch_offset] = [s:Nat(indent(num)),0,0,0] + let [num_ind, is_op, b_l, l:switch_offset, s:in_jsx] = [s:Nat(indent(num)),0,0,0,0] if !num || s:LookingAt() == '{' && s:IsBlock() let ilnum = line('.') - if num && s:LookingAt() == ')' && s:GetPair('(',')','bW',s:skip_expr) + if num && !s:in_jsx && s:LookingAt() == ')' && s:GetPair('(',')','bW',s:skip_expr) if ilnum == num let [num, num_ind] = [line('.'), indent('.')] endif @@ -399,23 +429,24 @@ function GetJavascriptIndent() endif endif if idx == -1 && pline[-1:] !~ '[{;]' + call cursor(l:lnum, len(pline)) let sol = matchstr(l:line,s:opfirst) if sol is '' || sol == '/' && s:SynAt(v:lnum, \ 1 + len(getline(v:lnum)) - len(l:line)) =~? 'regex' - if s:Continues(l:lnum,pline) + if s:Continues() let is_op = s:sw() endif - elseif num && sol =~# '^\%(in\%(stanceof\)\=\|\*\)$' - call call('cursor',b:js_cache[1:]) - if s:PreviousToken() =~ '\k' && s:Class() - return num_ind + s:sw() - endif - let is_op = s:sw() + elseif num && sol =~# '^\%(in\%(stanceof\)\=\|\*\)$' && + \ s:LookingAt() == '}' && s:GetPair('{','}','bW',s:skip_expr) && + \ s:PreviousToken() == ')' && s:GetPair('(',')','bW',s:skip_expr) && + \ (s:PreviousToken() == ']' || s:LookingAt() =~ '\k' && + \ s:{s:PreviousToken() == '*' ? 'Previous' : ''}Token() !=# 'function') + return num_ind + s:sw() else let is_op = s:sw() endif call cursor(l:lnum, len(pline)) - let b_l = s:Nat(s:IsContOne(b:js_cache[1],is_op) - (!is_op && l:line =~ '^{')) * s:sw() + let b_l = s:Nat(s:IsContOne(is_op) - (!is_op && l:line =~ '^{')) * s:sw() endif elseif idx.s:LookingAt().&cino =~ '^-1(.*(' && (search('\m\S','nbW',num) || s:ParseCino('U')) let pval = s:ParseCino('(') @@ -431,10 +462,10 @@ function GetJavascriptIndent() " main return if l:line =~ '^[])}]\|^|}' - if l:line_raw[0] == ')' && getline(num)[b:js_cache[2]-1] == '(' + if l:line_raw[0] == ')' if s:ParseCino('M') return indent(l:lnum) - elseif &cino =~# 'm' && !s:ParseCino('m') + elseif num && &cino =~# 'm' && !s:ParseCino('m') return virtcol('.') - 1 endif endif diff --git a/runtime/indent/logtalk.vim b/runtime/indent/logtalk.vim index 5b69663e1d..8e36f86115 100644 --- a/runtime/indent/logtalk.vim +++ b/runtime/indent/logtalk.vim @@ -1,5 +1,5 @@ " Maintainer: Paulo Moura <pmoura@logtalk.org> -" Revised on: 2008.06.02 +" Revised on: 2018.08.04 " Language: Logtalk " This Logtalk indent file is a modified version of the Prolog @@ -42,6 +42,9 @@ function! GetLogtalkIndent() " Check for clause head on previous line elseif pline =~ ':-\s*\(%.*\)\?$' let ind = ind + shiftwidth() + " Check for grammar rule head on previous line + elseif pline =~ '-->\s*\(%.*\)\?$' + let ind = ind + shiftwidth() " Check for entity closing directive on previous line elseif pline =~ '^\s*:-\send_\(object\|protocol\|category\)\.\(%.*\)\?$' let ind = ind - shiftwidth() diff --git a/runtime/indent/nsis.vim b/runtime/indent/nsis.vim new file mode 100644 index 0000000000..223f4fa28e --- /dev/null +++ b/runtime/indent/nsis.vim @@ -0,0 +1,91 @@ +" Vim indent file +" Language: NSIS script +" Maintainer: Ken Takata +" URL: https://github.com/k-takata/vim-nsis +" Last Change: 2018-01-21 +" Filenames: *.nsi +" License: VIM License + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal nosmartindent +setlocal noautoindent +setlocal indentexpr=GetNsisIndent(v:lnum) +setlocal indentkeys=!^F,o,O +setlocal indentkeys+==~${Else,=~${EndIf,=~${EndUnless,=~${AndIf,=~${AndUnless,=~${OrIf,=~${OrUnless,=~${Case,=~${Default,=~${EndSelect,=~${EndSwith,=~${Loop,=~${Next,=~${MementoSectionEnd,=~FunctionEnd,=~SectionEnd,=~SectionGroupEnd,=~PageExEnd,0=~!macroend,0=~!if,0=~!else,0=~!endif + +if exists("*GetNsisIndent") + finish +endif + +function! GetNsisIndent(lnum) + " If this line is explicitly joined: If the previous line was also joined, + " line it up with that one, otherwise add two 'shiftwidth' + if getline(a:lnum - 1) =~ '\\$' + if a:lnum > 1 && getline(a:lnum - 2) =~ '\\$' + return indent(a:lnum - 1) + endif + return indent(a:lnum - 1) + shiftwidth() * 2 + endif + + " Grab the current line, stripping comments. + let l:thisl = substitute(getline(a:lnum), '[;#].*$', '', '') + " Check if this line is a conditional preprocessor line. + let l:preproc = l:thisl =~? '^\s*!\%(if\|else\|endif\)' + + " Grab the previous line, stripping comments. + " Skip preprocessor lines and continued lines. + let l:prevlnum = a:lnum + while 1 + let l:prevlnum = prevnonblank(l:prevlnum - 1) + if l:prevlnum == 0 + " top of file + return 0 + endif + let l:prevl = substitute(getline(l:prevlnum), '[;#].*$', '', '') + let l:prevpreproc = l:prevl =~? '^\s*!\%(if\|else\|endif\)' + if l:preproc == l:prevpreproc && getline(l:prevlnum - 1) !~? '\\$' + break + endif + endwhile + let l:previ = indent(l:prevlnum) + let l:ind = l:previ + + if l:preproc + " conditional preprocessor + if l:prevl =~? '^\s*!\%(if\%(\%(macro\)\?n\?def\)\?\|else\)\>' + let l:ind += shiftwidth() + endif + if l:thisl =~? '^\s*!\%(else\|endif\)\?\>' + let l:ind -= shiftwidth() + endif + return l:ind + endif + + if l:prevl =~? '^\s*\%(\${\%(If\|IfNot\|Unless\|ElseIf\|ElseIfNot\|ElseUnless\|Else\|AndIf\|AndIfNot\|AndUnless\|OrIf\|OrIfNot\|OrUnless\|Select\|Case\|Case[2-5]\|CaseElse\|Default\|Switch\|Do\|DoWhile\|DoUntil\|For\|ForEach\|MementoSection\)}\|Function\>\|Section\>\|SectionGroup\|PageEx\>\|!macro\>\)' + " previous line opened a block + let l:ind += shiftwidth() + endif + if l:thisl =~? '^\s*\%(\${\%(ElseIf\|ElseIfNot\|ElseUnless\|Else\|EndIf\|EndUnless\|AndIf\|AndIfNot\|AndUnless\|OrIf\|OrIfNot\|OrUnless\|Loop\|LoopWhile\|LoopUntil\|Next\|MementoSectionEnd\)\>}\?\|FunctionEnd\>\|SectionEnd\>\|SectionGroupEnd\|PageExEnd\>\|!macroend\>\)' + " this line closed a block + let l:ind -= shiftwidth() + elseif l:thisl =~? '^\s*\${\%(Case\|Case[2-5]\|CaseElse\|Default\)\>}\?' + if l:prevl !~? '^\s*\${\%(Select\|Switch\)}' + let l:ind -= shiftwidth() + endif + elseif l:thisl =~? '^\s*\${\%(EndSelect\|EndSwitch\)\>}\?' + " this line closed a block + if l:prevl =~? '^\s*\${\%(Select\|Switch\)}' + let l:ind -= shiftwidth() + else + let l:ind -= shiftwidth() * 2 + endif + endif + + return l:ind +endfunction + +" vim: ts=8 sw=2 sts=2 diff --git a/runtime/indent/php.vim b/runtime/indent/php.vim index 35dddaa270..b0430dea8d 100644 --- a/runtime/indent/php.vim +++ b/runtime/indent/php.vim @@ -3,8 +3,8 @@ " Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr> " URL: http://www.2072productions.com/vim/indent/php.vim " Home: https://github.com/2072/PHP-Indenting-for-VIm -" Last Change: 2017 Jun 13 -" Version: 1.62 +" Last Change: 2018 May 18th +" Version: 1.66 " " " Type :help php-indent for available options @@ -82,6 +82,12 @@ else let b:PHP_outdentphpescape = 1 endif +if exists("PHP_noArrowMatching") + let b:PHP_noArrowMatching = PHP_noArrowMatching +else + let b:PHP_noArrowMatching = 0 +endif + if exists("PHP_vintage_case_default_indent") && PHP_vintage_case_default_indent let b:PHP_vintage_case_default_indent = 1 @@ -130,7 +136,7 @@ endif let s:PHP_validVariable = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' let s:notPhpHereDoc = '\%(break\|return\|continue\|exit\|die\|else\)' let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|\%(}\s*\)\?else\>\|do\>\|while\>\|switch\>\|case\>\|default\>\|for\%(each\)\=\>\|declare\>\|class\>\|trait\>\|use\>\|interface\>\|abstract\>\|final\>\|try\>\|\%(}\s*\)\=catch\>\|\%(}\s*\)\=finally\>\)' -let s:functionDecl = '\<function\>\%(\s\+'.s:PHP_validVariable.'\)\=\s*(.*' +let s:functionDecl = '\<function\>\%(\s\+&\='.s:PHP_validVariable.'\)\=\s*(.*' let s:endline = '\s*\%(//.*\|#.*\|/\*.*\*/\s*\)\=$' let s:unstated = '\%(^\s*'.s:blockstart.'.*)\|\%(//.*\)\@<!\<e'.'lse\>\)'.s:endline @@ -140,7 +146,6 @@ let s:PHP_startindenttag = '<?\%(.*?>\)\@!\|<script[^>]*>\%(.*<\/script>\)\@!' let s:structureHead = '^\s*\%(' . s:blockstart . '\)\|'. s:functionDecl . s:endline . '\|\<new\s\+class\>' - let s:escapeDebugStops = 0 function! DebugPrintReturn(scriptLine) @@ -257,7 +262,7 @@ endfun function! Skippmatch() " {{{ let synname = synIDattr(synID(line("."), col("."), 0), "name") - if synname == "Delimiter" || synname == "phpRegionDelimiter" || synname =~# "^phpParent" || synname == "phpArrayParens" || synname =~# '^php\%(Block\|Brace\)' || synname == "javaScriptBraces" || synname =~# '^php\%(Doc\)\?Comment' && b:UserIsTypingComment + if synname ==? "Delimiter" || synname ==? "phpRegionDelimiter" || synname =~? "^phpParent" || synname ==? "phpArrayParens" || synname =~? '^php\%(Block\|Brace\)' || synname ==? "javaScriptBraces" || synname =~? '^php\%(Doc\)\?Comment' && b:UserIsTypingComment return 0 else return 1 @@ -297,6 +302,48 @@ function! BalanceDirection (str) return balance endfun +function! StripEndlineComments (line) + return substitute(a:line,"\\(//\\|#\\)\\(\\(\\([^\"']*\\([\"']\\)[^\"']*\\5\\)\\+[^\"']*$\\)\\|\\([^\"']*$\\)\\)",'','') +endfun + +function! FindArrowIndent (lnum) " {{{ + + let parrentArrowPos = 0 + let lnum = a:lnum + while lnum > 1 + let last_line = getline(lnum) + if last_line =~ '^\s*->' + let parrentArrowPos = indent(a:lnum) + break + else + call cursor(lnum, 1) + let cleanedLnum = StripEndlineComments(last_line) + if cleanedLnum =~ '->' + if ! b:PHP_noArrowMatching + let parrentArrowPos = searchpos('->', 'W', lnum)[1] - 1 + else + let parrentArrowPos = indent(lnum) + shiftwidth() + endif + break + elseif cleanedLnum =~ ')'.s:endline && BalanceDirection(last_line) < 0 + call searchpos(')'.s:endline, 'cW', lnum) + let openedparent = searchpair('(', '', ')', 'bW', 'Skippmatch()') + if openedparent != lnum + let lnum = openedparent + else + let openedparent = -1 + endif + + else + let parrentArrowPos = indent(lnum) + shiftwidth() + break + endif + endif + endwhile + + return parrentArrowPos +endfun "}}} + function! FindTheIfOfAnElse (lnum, StopAfterFirstPrevElse) " {{{ if getline(a:lnum) =~# '^\s*}\s*else\%(if\)\=\>' @@ -368,7 +415,7 @@ function! FindTheSwitchIndent (lnum) " {{{ endfunction "}}} -let s:SynPHPMatchGroups = {'phpParent':1, 'Delimiter':1, 'Define':1, 'Storageclass':1, 'StorageClass':1, 'Structure':1, 'Exception':1} +let s:SynPHPMatchGroups = {'phpparent':1, 'delimiter':1, 'define':1, 'storageclass':1, 'structure':1, 'exception':1} function! IslinePHP (lnum, tofind) " {{{ let cline = getline(a:lnum) @@ -384,7 +431,7 @@ function! IslinePHP (lnum, tofind) " {{{ let synname = synIDattr(synID(a:lnum, coltotest, 0), "name") - if synname == 'phpStringSingle' || synname == 'phpStringDouble' || synname == 'phpBacktick' + if synname ==? 'phpStringSingle' || synname ==? 'phpStringDouble' || synname ==? 'phpBacktick' if cline !~ '^\s*[''"`]' return "SpecStringEntrails" else @@ -392,7 +439,7 @@ function! IslinePHP (lnum, tofind) " {{{ end end - if get(s:SynPHPMatchGroups, synname) || synname =~ '^php' || synname =~? '^javaScript' + if get(s:SynPHPMatchGroups, tolower(synname)) || synname =~ '^php' || synname =~? '^javaScript' return synname else return "" @@ -423,6 +470,10 @@ endfunc call ResetPhpOptions() +function! GetPhpIndentVersion() + return "1.66-bundle" +endfun + function! GetPhpIndent() let b:GetLastRealCodeLNum_ADD = 0 @@ -480,14 +531,14 @@ function! GetPhpIndent() endif if synname!="" - if synname == "SpecStringEntrails" + if synname ==? "SpecStringEntrails" let b:InPHPcode = -1 " thumb down let b:InPHPcode_tofind = "" - elseif synname != "phpHereDoc" && synname != "phpHereDocDelimiter" + elseif synname !=? "phpHereDoc" && synname !=? "phpHereDocDelimiter" let b:InPHPcode = 1 let b:InPHPcode_tofind = "" - if synname =~# '^php\%(Doc\)\?Comment' + if synname =~? '^php\%(Doc\)\?Comment' let b:UserIsTypingComment = 1 let b:InPHPcode_checked = 0 endif @@ -556,7 +607,7 @@ function! GetPhpIndent() if 1 == b:InPHPcode - if !b:InPHPcode_and_script && last_line =~ '\%(<?.*\)\@<!?>\%(.*<?\)\@!' && IslinePHP(lnum, '?>')=~"Delimiter" + if !b:InPHPcode_and_script && last_line =~ '\%(<?.*\)\@<!?>\%(.*<?\)\@!' && IslinePHP(lnum, '?>')=~?"Delimiter" if cline !~? s:PHP_startindenttag let b:InPHPcode = 0 let b:InPHPcode_tofind = s:PHP_startindenttag @@ -712,7 +763,8 @@ function! GetPhpIndent() let last_line_num = GetLastRealCodeLNum(last_line_num - 1) let previous_line = getline(last_line_num) endwhile - + elseif cline =~ '^\s*->' + return FindArrowIndent(lnum) elseif last_line =~# unstated && cline !~ '^\s*);\='.endline let ind = ind + shiftwidth() " we indent one level further when the preceding line is not stated return ind + addSpecial @@ -724,7 +776,7 @@ function! GetPhpIndent() let isSingleLineBlock = 0 while 1 - if ! isSingleLineBlock && previous_line =~ '^\s*}\|;\s*}'.endline " XXX + if ! isSingleLineBlock && previous_line =~ '^\s*}\|;\s*}'.endline call cursor(last_line_num, 1) if previous_line !~ '^}' @@ -793,8 +845,7 @@ function! GetPhpIndent() let AntepenultimateLine = getline(plinnum) - let last_line = substitute(last_line,"\\(//\\|#\\)\\(\\(\\([^\"']*\\([\"']\\)[^\"']*\\5\\)\\+[^\"']*$\\)\\|\\([^\"']*$\\)\\)",'','') - + let last_line = StripEndlineComments(last_line) if ind == b:PHP_default_indenting if last_line =~ terminated && last_line !~# s:defaultORcase @@ -804,11 +855,13 @@ function! GetPhpIndent() if !LastLineClosed + let openedparent = -1 + if last_line =~# '[{(\[]'.endline || last_line =~? '\h\w*\s*(.*,$' && AntepenultimateLine !~ '[,(\[]'.endline && BalanceDirection(last_line) > 0 let dontIndent = 0 - if last_line =~ '\S\+\s*{'.endline && last_line !~ '^\s*[)\]]\+\s*{'.endline && last_line !~ s:structureHead + if last_line =~ '\S\+\s*{'.endline && last_line !~ '^\s*[)\]]\+\(\s*:\s*'.s:PHP_validVariable.'\)\=\s*{'.endline && last_line !~ s:structureHead let dontIndent = 1 endif @@ -819,18 +872,17 @@ function! GetPhpIndent() if b:PHP_BracesAtCodeLevel || b:PHP_vintage_case_default_indent == 1 let b:PHP_CurrentIndentLevel = ind - return ind + addSpecial endif - elseif last_line =~ '\S\+\s*),'.endline && BalanceDirection(last_line) < 0 + elseif last_line =~ '),'.endline && BalanceDirection(last_line) < 0 call cursor(lnum, 1) - call search('),'.endline, 'W') " line never begins with ) so no need for 'c' flag + call searchpos('),'.endline, 'cW') let openedparent = searchpair('(', '', ')', 'bW', 'Skippmatch()') if openedparent != lnum let ind = indent(openedparent) endif - elseif last_line =~ '^\s*'.s:blockstart + elseif last_line =~ s:structureHead let ind = ind + shiftwidth() @@ -838,9 +890,17 @@ function! GetPhpIndent() let ind = ind + shiftwidth() endif + + if openedparent >= 0 + let last_line = StripEndlineComments(getline(openedparent)) + endif + endif + + if cline =~ '^\s*[)\]];\=' + let ind = ind - shiftwidth() endif - if cline =~ '^\s*[)\]];\=' + if last_line =~ '^\s*->' && last_line !~? s:structureHead && BalanceDirection(last_line) <= 0 let ind = ind - shiftwidth() endif diff --git a/runtime/indent/prolog.vim b/runtime/indent/prolog.vim index 26a3bc3cd9..ecd0894166 100644 --- a/runtime/indent/prolog.vim +++ b/runtime/indent/prolog.vim @@ -2,6 +2,7 @@ " Maintainer : Gergely Kontra <kgergely@mcl.hu> " Revised on : 2002.02.18. 23:34:05 " Language : Prolog +" Last change by: Takuya Fujiwara, 2018 Sep 23 " TODO: " checking with respect to syntax highlighting @@ -37,10 +38,18 @@ function! GetPrologIndent() let ind = indent(pnum) " Previous line was comment -> use previous line's indent if pline =~ '^\s*%' - retu ind + return ind + endif + " Previous line was the start of block comment -> +1 after '/*' comment + if pline =~ '^\s*/\*' + return ind + 1 + endif + " Previous line was the end of block comment -> -1 after '*/' comment + if pline =~ '^\s*\*/' + return ind - 1 endif " Check for clause head on previous line - if pline =~ ':-\s*\(%.*\)\?$' + if pline =~ '\%(:-\|-->\)\s*\(%.*\)\?$' let ind = ind + shiftwidth() " Check for end of clause on previous line elseif pline =~ '\.\s*\(%.*\)\?$' diff --git a/runtime/indent/python.vim b/runtime/indent/python.vim index 4ce3c234a5..7ab3cb9f50 100644 --- a/runtime/indent/python.vim +++ b/runtime/indent/python.vim @@ -53,6 +53,11 @@ function GetPythonIndent(lnum) return 0 endif + " searchpair() can be slow sometimes, limit the time to 100 msec or what is + " put in g:pyindent_searchpair_timeout + let searchpair_stopline = 0 + let searchpair_timeout = get(g:, 'pyindent_searchpair_timeout', 150) + " If the previous line is inside parenthesis, use the indent of the starting " line. " Trick: use the non-existing "dummy" variable to break out of the loop when @@ -61,7 +66,8 @@ function GetPythonIndent(lnum) let parlnum = searchpair('(\|{\|\[', '', ')\|}\|\]', 'nbW', \ "line('.') < " . (plnum - s:maxoff) . " ? dummy :" \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')" - \ . " =~ '\\(Comment\\|Todo\\|String\\)$'") + \ . " =~ '\\(Comment\\|Todo\\|String\\)$'", + \ searchpair_stopline, searchpair_timeout) if parlnum > 0 let plindent = indent(parlnum) let plnumstart = parlnum @@ -80,14 +86,16 @@ function GetPythonIndent(lnum) let p = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW', \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :" \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')" - \ . " =~ '\\(Comment\\|Todo\\|String\\)$'") + \ . " =~ '\\(Comment\\|Todo\\|String\\)$'", + \ searchpair_stopline, searchpair_timeout) if p > 0 if p == plnum " When the start is inside parenthesis, only indent one 'shiftwidth'. let pp = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW', \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :" \ . " synIDattr(synID(line('.'), col('.'), 1), 'name')" - \ . " =~ '\\(Comment\\|Todo\\|String\\)$'") + \ . " =~ '\\(Comment\\|Todo\\|String\\)$'", + \ searchpair_stopline, searchpair_timeout) if pp > 0 return indent(plnum) + (exists("g:pyindent_nested_paren") ? eval(g:pyindent_nested_paren) : shiftwidth()) endif diff --git a/runtime/indent/r.vim b/runtime/indent/r.vim index 373b0e65df..ca85a2e62d 100644 --- a/runtime/indent/r.vim +++ b/runtime/indent/r.vim @@ -2,7 +2,7 @@ " Language: R " Author: Jakson Alves de Aquino <jalvesaq@gmail.com> " Homepage: https://github.com/jalvesaq/R-Vim-runtime -" Last Change: Thu Feb 18, 2016 06:32AM +" Last Change: Sun Aug 19, 2018 09:13PM " Only load this indent file when no other was loaded. @@ -19,22 +19,16 @@ if exists("*GetRIndent") finish endif +let s:cpo_save = &cpo +set cpo&vim + " Options to make the indentation more similar to Emacs/ESS: -if !exists("g:r_indent_align_args") - let g:r_indent_align_args = 1 -endif -if !exists("g:r_indent_ess_comments") - let g:r_indent_ess_comments = 0 -endif -if !exists("g:r_indent_comment_column") - let g:r_indent_comment_column = 40 -endif -if ! exists("g:r_indent_ess_compatible") - let g:r_indent_ess_compatible = 0 -endif -if ! exists("g:r_indent_op_pattern") - let g:r_indent_op_pattern = '\(&\||\|+\|-\|\*\|/\|=\|\~\|%\|->\)\s*$' -endif +let g:r_indent_align_args = get(g:, 'r_indent_align_args', 1) +let g:r_indent_ess_comments = get(g:, 'r_indent_ess_comments', 0) +let g:r_indent_comment_column = get(g:, 'r_indent_comment_column', 40) +let g:r_indent_ess_compatible = get(g:, 'r_indent_ess_compatible', 0) +let g:r_indent_op_pattern = get(g:, 'r_indent_op_pattern', + \ '\(&\||\|+\|-\|\*\|/\|=\|\~\|%\|->\)\s*$') function s:RDelete_quotes(line) let i = 0 @@ -231,7 +225,7 @@ function GetRIndent() let cline = SanitizeRLine(cline) - if cline =~ '^\s*}' || cline =~ '^\s*}\s*)$' + if cline =~ '^\s*}' let indline = s:Get_matching_brace(clnum, '{', '}', 1) if indline > 0 && indline != clnum let iline = SanitizeRLine(getline(indline)) @@ -244,6 +238,11 @@ function GetRIndent() endif endif + if cline =~ '^\s*)$' + let indline = s:Get_matching_brace(clnum, '(', ')', 1) + return indent(indline) + endif + " Find the first non blank line above the current line let lnum = s:Get_prev_line(clnum) " Hit the start of the file, use zero indent. @@ -515,7 +514,9 @@ function GetRIndent() endwhile return ind - endfunction +let &cpo = s:cpo_save +unlet s:cpo_save + " vim: sw=2 diff --git a/runtime/indent/rmd.vim b/runtime/indent/rmd.vim index 88904405e8..182b07cbaa 100644 --- a/runtime/indent/rmd.vim +++ b/runtime/indent/rmd.vim @@ -2,7 +2,7 @@ " Language: Rmd " Author: Jakson Alves de Aquino <jalvesaq@gmail.com> " Homepage: https://github.com/jalvesaq/R-Vim-runtime -" Last Change: Tue Apr 07, 2015 04:38PM +" Last Change: Sun Aug 19, 2018 09:14PM " Only load this indent file when no other was loaded. @@ -20,7 +20,10 @@ if exists("*GetRmdIndent") finish endif -function GetMdIndent() +let s:cpo_save = &cpo +set cpo&vim + +function s:GetMdIndent() let pline = getline(v:lnum - 1) let cline = getline(v:lnum) if prevnonblank(v:lnum - 1) < v:lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+' @@ -33,15 +36,31 @@ function GetMdIndent() return indent(prevnonblank(v:lnum - 1)) endfunction +function s:GetYamlIndent() + let pline = getline(v:lnum - 1) + if pline =~ ':\s*$' + return indent(v:lnum) + &sw + elseif pline =~ '^\s*- ' + return indent(v:lnum) + 2 + endif + return indent(prevnonblank(v:lnum - 1)) +endfunction + function GetRmdIndent() if getline(".") =~ '^[ \t]*```{r .*}$' || getline(".") =~ '^[ \t]*```$' return 0 endif if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW") return s:RIndent() + elseif v:lnum > 1 && search('^---$', "bnW") == 1 && + \ (search('^---$', "nW") > v:lnum || search('^...$', "nW") > v:lnum) + return s:GetYamlIndent() else - return GetMdIndent() + return s:GetMdIndent() endif endfunction +let &cpo = s:cpo_save +unlet s:cpo_save + " vim: sw=2 diff --git a/runtime/indent/rnoweb.vim b/runtime/indent/rnoweb.vim index 8c11e85cb3..73966868b8 100644 --- a/runtime/indent/rnoweb.vim +++ b/runtime/indent/rnoweb.vim @@ -21,7 +21,7 @@ else let s:TeXIndent = function(substitute(&indentexpr, "()", "", "")) endif -unlet b:did_indent +unlet! b:did_indent runtime indent/r.vim let s:RIndent = function(substitute(&indentexpr, "()", "", "")) let b:did_indent = 1 diff --git a/runtime/indent/sas.vim b/runtime/indent/sas.vim index d591b2796e..9cc9e025c4 100644 --- a/runtime/indent/sas.vim +++ b/runtime/indent/sas.vim @@ -1,8 +1,8 @@ " Vim indent file " Language: SAS " Maintainer: Zhen-Huan Hu <wildkeny@gmail.com> -" Version: 3.0.1 -" Last Change: Mar 13, 2017 +" Version: 3.0.3 +" Last Change: Jun 26, 2018 if exists("b:did_indent") finish @@ -27,9 +27,9 @@ let s:section_run = '\v%(^|;)\s*run\s*;' let s:section_end = '\v%(^|;)\s*%(quit|enddata)\s*;' " Regex that captures the start of a control block (anything inside a section) -let s:block_str = '\v<%(do>%([^;]+<%(to|over)>[^;]+)=|%(define|layout|method|select)>[^;]+|begingraph)\s*;' +let s:block_str = '\v<%(do>%([^;]+<%(to|over|while)>[^;]+)=|%(compute|define\s+%(column|footer|header|style|table|tagset|crosstabs|statgraph)|edit|layout|method|select)>[^;]+|begingraph)\s*;' " Regex that captures the end of a control block (anything inside a section) -let s:block_end = '\v<%(end|endlayout|endgraph)\s*;' +let s:block_end = '\v<%(end|endcomp|endlayout|endgraph)\s*;' " Regex that captures the start of a macro let s:macro_str = '\v%(^|;)\s*\%macro>' @@ -52,7 +52,7 @@ function! s:PrevMatch(lnum, regex) let prev_lnum = prevnonblank(a:lnum - 1) while prev_lnum > 0 let prev_line = getline(prev_lnum) - if prev_line =~ a:regex + if prev_line =~? a:regex break else let prev_lnum = prevnonblank(prev_lnum - 1) @@ -71,11 +71,11 @@ function! GetSASIndent() let prev_line = getline(prev_lnum) " Previous non-blank line contains the start of a macro/section/block " while not the end of a macro/section/block (at the same line) - if (prev_line =~ s:section_str && prev_line !~ s:section_run && prev_line !~ s:section_end) || - \ (prev_line =~ s:block_str && prev_line !~ s:block_end) || - \ (prev_line =~ s:macro_str && prev_line !~ s:macro_end) - let ind = indent(prev_lnum) + &sts - elseif prev_line =~ s:section_run && prev_line !~ s:section_end + if (prev_line =~? s:section_str && prev_line !~? s:section_run && prev_line !~? s:section_end) || + \ (prev_line =~? s:block_str && prev_line !~? s:block_end) || + \ (prev_line =~? s:macro_str && prev_line !~? s:macro_end) + let ind = indent(prev_lnum) + shiftwidth() + elseif prev_line =~? s:section_run && prev_line !~? s:section_end let prev_section_str_lnum = s:PrevMatch(v:lnum, s:section_str) let prev_section_end_lnum = max([ \ s:PrevMatch(v:lnum, s:section_end), @@ -83,9 +83,9 @@ function! GetSASIndent() \ s:PrevMatch(v:lnum, s:program_end)]) " Check if the section supports run-processing if prev_section_end_lnum < prev_section_str_lnum && - \ getline(prev_section_str_lnum) =~ '\v%(^|;)\s*proc\s+%(' . + \ getline(prev_section_str_lnum) =~? '\v%(^|;)\s*proc\s+%(' . \ join(s:run_processing_procs, '|') . ')>' - let ind = indent(prev_lnum) + &sts + let ind = indent(prev_lnum) + shiftwidth() else let ind = indent(prev_lnum) endif @@ -95,26 +95,26 @@ function! GetSASIndent() endif " Re-adjustments based on the inputs of the current line let curr_line = getline(v:lnum) - if curr_line =~ s:program_end + if curr_line =~? s:program_end " End of the program " Same indentation as the first non-blank line return indent(nextnonblank(1)) - elseif curr_line =~ s:macro_end + elseif curr_line =~? s:macro_end " Current line is the end of a macro " Match the indentation of the start of the macro return indent(s:PrevMatch(v:lnum, s:macro_str)) - elseif curr_line =~ s:block_end && curr_line !~ s:block_str + elseif curr_line =~? s:block_end && curr_line !~? s:block_str " Re-adjust if current line is the end of a block " while not the beginning of a block (at the same line) " Returning the indent of previous block start directly " would not work due to nesting - let ind = ind - &sts - elseif curr_line =~ s:section_str || curr_line =~ s:section_run || curr_line =~ s:section_end + let ind = ind - shiftwidth() + elseif curr_line =~? s:section_str || curr_line =~? s:section_run || curr_line =~? s:section_end " Re-adjust if current line is the start/end of a section " since the end of a section could be inexplicit let prev_section_str_lnum = s:PrevMatch(v:lnum, s:section_str) " Check if the previous section supports run-processing - if getline(prev_section_str_lnum) =~ '\v%(^|;)\s*proc\s+%(' . + if getline(prev_section_str_lnum) =~? '\v%(^|;)\s*proc\s+%(' . \ join(s:run_processing_procs, '|') . ')>' let prev_section_end_lnum = max([ \ s:PrevMatch(v:lnum, s:section_end), @@ -128,7 +128,7 @@ function! GetSASIndent() \ s:PrevMatch(v:lnum, s:program_end)]) endif if prev_section_end_lnum < prev_section_str_lnum - let ind = ind - &sts + let ind = ind - shiftwidth() endif endif return ind diff --git a/runtime/indent/scheme.vim b/runtime/indent/scheme.vim index a16f4f9ea1..496da3267d 100644 --- a/runtime/indent/scheme.vim +++ b/runtime/indent/scheme.vim @@ -1,11 +1,14 @@ " Vim indent file -" Language: Scheme -" Maintainer: Sergey Khorev <sergey.khorev@gmail.com> -" Last Change: 2005 Jun 24 +" Language: Scheme +" Last Change: 2018 Jan 31 +" Maintainer: Evan Hanson <evhan@foldling.org> +" Previous Maintainer: Sergey Khorev <sergey.khorev@gmail.com> +" URL: https://foldling.org/vim/indent/scheme.vim " Only load this indent file when no other was loaded. if exists("b:did_indent") finish endif +" Use the Lisp indenting runtime! indent/lisp.vim diff --git a/runtime/indent/sh.vim b/runtime/indent/sh.vim index fd9a6a9c92..32bc9f35bb 100644 --- a/runtime/indent/sh.vim +++ b/runtime/indent/sh.vim @@ -1,12 +1,16 @@ " Vim indent file " Language: Shell Script " Maintainer: Christian Brabandt <cb@256bit.org> -" Previous Maintainer: Peter Aronoff <telemachus@arpinum.org> " Original Author: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2017-08-08 +" Previous Maintainer: Peter Aronoff <telemachus@arpinum.org> +" Latest Revision: 2018-03-26 " License: Vim (see :h license) " Repository: https://github.com/chrisbra/vim-sh-indent " Changelog: +" 20180724 - make check for zsh syntax more rigid (needs word-boundaries) +" 20180326 - better support for line continuation +" 20180325 - better detection of function definitions +" 20180127 - better support for zsh complex commands " 20170808: - better indent of line continuation " 20170502: - get rid of buffer-shiftwidth function " 20160912: - preserve indentation of here-doc blocks @@ -59,12 +63,15 @@ function! GetShIndent() if lnum == 0 return 0 endif + let line = getline(lnum) let pnum = prevnonblank(lnum - 1) - + let pline = getline(pnum) let ind = indent(lnum) - let line = getline(lnum) - if line =~ '^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>' + + " Check contents of previous lines + if line =~ '^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>' || + \ (&ft is# 'zsh' && line =~ '\<\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>') if line !~ '\<\%(fi\|esac\|done\|end\)\>\s*\%(#.*\)\=$' let ind += s:indent_value('default') endif @@ -72,21 +79,35 @@ function! GetShIndent() if !s:is_case_ended(line) let ind += s:indent_value('case-statements') endif - elseif line =~ '^\s*\<\k\+\>\s*()\s*{' || line =~ '^\s*{' || line =~ '^\s*function\s*\w\S\+\s*\%(()\)\?\s*{' + " function definition + elseif s:is_function_definition(line) if line !~ '}\s*\%(#.*\)\=$' let ind += s:indent_value('default') endif elseif s:is_continuation_line(line) - if pnum == 0 || !s:is_continuation_line(getline(pnum)) + if pnum == 0 || !s:is_continuation_line(pline) let ind += s:indent_value('continuation-line') endif - elseif pnum != 0 && s:is_continuation_line(getline(pnum)) - let ind = indent(s:find_continued_lnum(pnum)) + elseif s:end_block(line) && !s:start_block(line) + let ind -= s:indent_value('default') + elseif pnum != 0 && s:is_continuation_line(pline) && !s:end_block(getline(v:lnum)) + " only add indent, if line and pline is in the same block + let i = v:lnum + let ind2 = indent(s:find_continued_lnum(pnum)) + while !s:is_empty(getline(i)) && i > pnum + let i -= 1 + endw + if i == pnum + let ind += ind2 + else + let ind = ind2 + endif endif let pine = line + " Check content of current line let line = getline(v:lnum) - if line =~ '^\s*\%(then\|do\|else\|elif\|fi\|done\|end\)\>' || line =~ '^\s*}' + if line =~ '^\s*\%(then\|do\|else\|elif\|fi\|done\|end\)\>' || s:end_block(line) let ind -= s:indent_value('default') elseif line =~ '^\s*esac\>' && s:is_case_empty(getline(v:lnum - 1)) let ind -= s:indent_value('default') @@ -112,14 +133,24 @@ function! GetShIndent() " statements, executed within a here document. Keep the current indent elseif match(map(synstack(v:lnum, 1), 'synIDattr(v:val, "name")'), '\c\mheredoc') > -1 return indent(v:lnum) + elseif s:is_comment(line) && s:is_empty(getline(v:lnum-1)) + return indent(v:lnum) endif - return ind + return ind > 0 ? ind : 0 endfunction function! s:is_continuation_line(line) - return a:line =~ '\%(\%(^\|[^\\]\)\\\|&&\|||\||\)' . + " Comment, cannot be a line continuation + if a:line =~ '^\s*#' + return 0 + else + " start-of-line + " \\ or && or || or | + " followed optionally by { or # + return a:line =~ '\%(\%(^\|[^\\]\)\\\|&&\|||\||\)' . \ '\s*\({\s*\)\=\(#.*\)\=$' + endif endfunction function! s:find_continued_lnum(lnum) @@ -130,6 +161,12 @@ function! s:find_continued_lnum(lnum) return i endfunction +function! s:is_function_definition(line) + return a:line =~ '^\s*\<\k\+\>\s*()\s*{' || + \ a:line =~ '^\s*{' || + \ a:line =~ '^\s*function\s*\w\S\+\s*\%(()\)\?\s*{' +endfunction + function! s:is_case_label(line, pnum) if a:line !~ '^\s*(\=.*)' return 0 @@ -195,5 +232,29 @@ function! s:escape(pattern) return '\V'. escape(a:pattern, '\\') endfunction +function! s:is_empty(line) + return a:line =~ '^\s*$' +endfunction + +function! s:end_block(line) + return a:line =~ '^\s*}' +endfunction + +function! s:start_block(line) + return a:line =~ '{\s*\(#.*\)\?$' +endfunction + +function! s:find_start_block(lnum) + let i = a:lnum + while i > 1 && !s:start_block(getline(i)) + let i -= 1 + endwhile + return i +endfunction + +function! s:is_comment(line) + return a:line =~ '^\s*#' +endfunction + let &cpo = s:cpo_save unlet s:cpo_save diff --git a/runtime/indent/teraterm.vim b/runtime/indent/teraterm.vim index 370283c77f..35d7354290 100644 --- a/runtime/indent/teraterm.vim +++ b/runtime/indent/teraterm.vim @@ -1,9 +1,9 @@ " Vim indent file " Language: Tera Term Language (TTL) -" Based on Tera Term Version 4.92 +" Based on Tera Term Version 4.100 " Maintainer: Ken Takata " URL: https://github.com/k-takata/vim-teraterm -" Last Change: 2017 Jun 13 +" Last Change: 2018-08-31 " Filenames: *.ttl " License: VIM License diff --git a/runtime/indent/tex.vim b/runtime/indent/tex.vim index 1a4d8b1cb6..a748cfbb40 100644 --- a/runtime/indent/tex.vim +++ b/runtime/indent/tex.vim @@ -2,7 +2,7 @@ " Language: LaTeX " Maintainer: Yichao Zhou <broken.zhou AT gmail.com> " Created: Sat, 16 Feb 2002 16:50:19 +0100 -" Version: 0.9.4 +" Version: 1.0.0 " Please email me if you found something I can do. Comments, bug report and " feature request are welcome. @@ -62,6 +62,8 @@ " (*) Fix a bug between g:tex_noindent_env and g:tex_indent_items " Now g:tex_noindent_env='document\|verbatim\|itemize' (Emacs " style) is supported. Thanks Miles Wheeler for reporting. +" 2018/02/07 by Yichao Zhou <broken.zhou AT gmail.com> +" (*) Make indentation more smart in the normal mode " " }}} @@ -91,19 +93,14 @@ " If this variable is set, item-environments are indented like Emacs does " it, i.e., continuation lines are indented with a shiftwidth. " -" NOTE: I've already set the variable below; delete the corresponding line -" if you don't like this behaviour. -" -" Per default, it is unset. -" -" set unset -" ---------------------------------------------------------------- -" \begin{itemize} \begin{itemize} -" \item blablabla \item blablabla -" bla bla bla bla bla bla -" \item blablabla \item blablabla -" bla bla bla bla bla bla -" \end{itemize} \end{itemize} +" set unset +" ------------------------------------------------------ +" \begin{itemize} \begin{itemize} +" \item blablabla \item blablabla +" bla bla bla bla bla bla +" \item blablabla \item blablabla +" bla bla bla bla bla bla +" \end{itemize} \end{itemize} " " " * g:tex_items @@ -290,8 +287,9 @@ function! GetTeXIndent() " {{{ endif endif - if stay - " If there is no obvious indentation hint, we trust our user. + if stay && mode() == 'i' + " If there is no obvious indentation hint, and indentation is triggered + " in insert mode, we trust our user. if empty(cline) return ind else diff --git a/runtime/indent/wast.vim b/runtime/indent/wast.vim new file mode 100644 index 0000000000..1be234b6e9 --- /dev/null +++ b/runtime/indent/wast.vim @@ -0,0 +1,17 @@ +" Vim indent file +" Language: WebAssembly +" Maintainer: rhysd <lin90162@yahoo.co.jp> +" Last Change: Jul 29, 2018 +" For bugs, patches and license go to https://github.com/rhysd/vim-wasm + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +" WebAssembly text format is S-expression. We can reuse LISP indentation +" logic. +setlocal indentexpr=lispindent('.') +setlocal noautoindent nosmartindent + +let b:undo_indent = "setl lisp< indentexpr<" diff --git a/runtime/indent/xml.vim b/runtime/indent/xml.vim index 87ffb329b5..dcafb467a6 100644 --- a/runtime/indent/xml.vim +++ b/runtime/indent/xml.vim @@ -1,6 +1,8 @@ " Language: xml -" Maintainer: Johannes Zellner <johannes@zellner.org> -" Last Change: 2017 Jun 13 +" Repository: https://github.com/chrisbra/vim-xml-ftplugin +" Maintainer: Christian Brabandt <cb@256bit.org> +" Previous Maintainer: Johannes Zellner <johannes@zellner.org> +" Last Change: 20180724 - Correctly indent xml comments https://github.com/vim/vim/issues/3200 " Notes: 1) does not indent pure non-xml code (e.g. embedded scripts) " 2) will be confused by unbalanced tags in comments " or CDATA sections. @@ -55,9 +57,6 @@ fun! <SID>XmlIndentSynCheck(lnum) if '' != syn1 && syn1 !~ 'xml' && '' != syn2 && syn2 !~ 'xml' " don't indent pure non-xml code return 0 - elseif syn1 =~ '^xmlComment' && syn2 =~ '^xmlComment' - " indent comments specially - return -1 endif endif return 1 |