aboutsummaryrefslogtreecommitdiff
path: root/runtime/indent
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/indent')
-rw-r--r--runtime/indent/bzl.vim97
-rw-r--r--runtime/indent/fortran.vim27
-rw-r--r--runtime/indent/hog.vim77
-rw-r--r--runtime/indent/html.vim54
-rw-r--r--runtime/indent/lua.vim6
-rw-r--r--runtime/indent/sh.vim21
-rw-r--r--runtime/indent/systemd.vim10
-rw-r--r--runtime/indent/teraterm.vim67
-rw-r--r--runtime/indent/yaml.vim12
9 files changed, 334 insertions, 37 deletions
diff --git a/runtime/indent/bzl.vim b/runtime/indent/bzl.vim
new file mode 100644
index 0000000000..24e5b870cd
--- /dev/null
+++ b/runtime/indent/bzl.vim
@@ -0,0 +1,97 @@
+" Vim indent file
+" Language: Bazel (http://bazel.io)
+" Maintainer: David Barnett (https://github.com/google/vim-ft-bzl)
+" Last Change: 2015 Aug 11
+
+if exists('b:did_indent')
+ finish
+endif
+
+" Load base python indent.
+if !exists('*GetPythonIndent')
+ runtime! indent/python.vim
+endif
+
+let b:did_indent = 1
+
+" Only enable bzl google indent if python google indent is enabled.
+if !get(g:, 'no_google_python_indent')
+ setlocal indentexpr=GetBzlIndent(v:lnum)
+endif
+
+if exists('*GetBzlIndent')
+ finish
+endif
+
+let s:save_cpo = &cpo
+set cpo-=C
+
+" Maximum number of lines to look backwards.
+let s:maxoff = 50
+
+""
+" Determine the correct indent level given an {lnum} in the current buffer.
+function GetBzlIndent(lnum) abort
+ let l:use_recursive_indent = !get(g:, 'no_google_python_recursive_indent')
+ if l:use_recursive_indent
+ " Backup and override indent setting variables.
+ if exists('g:pyindent_nested_paren')
+ let l:pyindent_nested_paren = g:pyindent_nested_paren
+ endif
+ if exists('g:pyindent_open_paren')
+ let l:pyindent_open_paren = g:pyindent_open_paren
+ endif
+ " Vim 7.3.693 and later defines a shiftwidth() function to get the effective
+ " shiftwidth value. Fall back to &shiftwidth if the function doesn't exist.
+ let l:sw_expr = exists('*shiftwidth') ? 'shiftwidth()' : '&shiftwidth'
+ let g:pyindent_nested_paren = l:sw_expr . ' * 2'
+ let g:pyindent_open_paren = l:sw_expr . ' * 2'
+ endif
+
+ let l:indent = -1
+
+ " Indent inside parens.
+ " Align with the open paren unless it is at the end of the line.
+ " E.g.
+ " open_paren_not_at_EOL(100,
+ " (200,
+ " 300),
+ " 400)
+ " open_paren_at_EOL(
+ " 100, 200, 300, 400)
+ call cursor(a:lnum, 1)
+ let [l:par_line, l:par_col] = searchpairpos('(\|{\|\[', '', ')\|}\|\]', 'bW',
+ \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :" .
+ \ " synIDattr(synID(line('.'), col('.'), 1), 'name')" .
+ \ " =~ '\\(Comment\\|String\\)$'")
+ if l:par_line > 0
+ call cursor(l:par_line, 1)
+ if l:par_col != col('$') - 1
+ let l:indent = l:par_col
+ endif
+ endif
+
+ " Delegate the rest to the original function.
+ if l:indent == -1
+ let l:indent = GetPythonIndent(a:lnum)
+ endif
+
+ if l:use_recursive_indent
+ " Restore global variables.
+ if exists('l:pyindent_nested_paren')
+ let g:pyindent_nested_paren = l:pyindent_nested_paren
+ else
+ unlet g:pyindent_nested_paren
+ endif
+ if exists('l:pyindent_open_paren')
+ let g:pyindent_open_paren = l:pyindent_open_paren
+ else
+ unlet g:pyindent_open_paren
+ endif
+ endif
+
+ return l:indent
+endfunction
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
diff --git a/runtime/indent/fortran.vim b/runtime/indent/fortran.vim
index 2c83f26b58..d492889fc7 100644
--- a/runtime/indent/fortran.vim
+++ b/runtime/indent/fortran.vim
@@ -1,9 +1,9 @@
" Vim indent file
-" Language: Fortran 2008 (and earlier versions: 2003, 95, 90, and 77)
-" Version: 0.41
-" Last Change: 2015 Jan. 15
+" Language: Fortran 2008 (and older: Fortran 2003, 95, 90, and 77)
+" Version: 0.42
+" Last Change: 2015 Nov. 30
" Maintainer: Ajit J. Thakkar <ajit@unb.ca>; <http://www2.unb.ca/~ajit/>
-" Usage: Do :help fortran-indent from Vim
+" Usage: For instructions, do :help fortran-indent from Vim
" Credits:
" Useful suggestions were made by: Albert Oliver Serra.
@@ -27,7 +27,10 @@ if exists("b:fortran_indent_more") || exists("g:fortran_indent_more")
endif
" Determine whether this is a fixed or free format source file
-" if this hasn't been done yet
+" if this hasn't been done yet using the priority:
+" buffer-local value
+" > global value
+" > file extension as in Intel ifort, gcc (gfortran), NAG, Pathscale, and Cray compilers
if !exists("b:fortran_fixed_source")
if exists("fortran_free_source")
" User guarantees free source form
@@ -35,13 +38,19 @@ if !exists("b:fortran_fixed_source")
elseif exists("fortran_fixed_source")
" User guarantees fixed source form
let b:fortran_fixed_source = 1
+ elseif expand("%:e") ==? "f\<90\|95\|03\|08\>"
+ " Free-form file extension defaults as in Intel ifort, gcc(gfortran), NAG, Pathscale, and Cray compilers
+ let b:fortran_fixed_source = 0
+ elseif expand("%:e") ==? "f\|f77\|for"
+ " Fixed-form file extension defaults
+ let b:fortran_fixed_source = 1
else
- " f90 and f95 allow both fixed and free source form
- " assume fixed source form unless signs of free source form
+ " Modern fortran still allows both fixed and free source form
+ " Assume fixed source form unless signs of free source form
" are detected in the first five columns of the first s:lmax lines.
- " Detection becomes more accurate and more time-consuming if more lines
+ " Detection becomes more accurate and time-consuming if more lines
" are checked. Increase the limit below if you keep lots of comments at
- " the very top of each file and you have a fast computer
+ " the very top of each file and you have a fast computer.
let s:lmax = 500
if ( s:lmax > line("$") )
let s:lmax = line("$")
diff --git a/runtime/indent/hog.vim b/runtime/indent/hog.vim
new file mode 100644
index 0000000000..02ac7d4d1b
--- /dev/null
+++ b/runtime/indent/hog.vim
@@ -0,0 +1,77 @@
+" Vim indent file
+" Language: hog (Snort.conf)
+" Maintainer: Victor Roemer, <vroemer@badsec.org>
+" Last Change: Mar 7, 2013
+
+" Only load this indent file when no other was loaded.
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+let b:undo_indent = 'setlocal smartindent< indentexpr< indentkeys<'
+
+setlocal nosmartindent
+setlocal indentexpr=GetHogIndent()
+setlocal indentkeys+=!^F,o,O,0#
+
+" Only define the function once.
+if exists("*GetHogIndent")
+ finish
+endif
+
+let s:cpo_save = &cpo
+set cpo&vim
+
+let s:syn_blocks = '\<SnortRuleTypeBody\>'
+
+function s:IsInBlock(lnum)
+ return synIDattr(synID(a:lnum, 1, 1), 'name') =~ s:syn_blocks
+endfunction
+
+function GetHogIndent()
+ let prevlnum = prevnonblank(v:lnum-1)
+
+ " Comment blocks have identical indent
+ if getline(v:lnum) =~ '^\s*#' && getline(prevlnum) =~ '^\s*#'
+ return indent(prevlnum)
+ endif
+
+ " Ignore comment lines when calculating indent
+ while getline(prevlnum) =~ '^\s*#'
+ let prevlnum = prevnonblank(prevlnum-1)
+ if !prevlnum
+ return previndent
+ endif
+ endwhile
+
+ " Continuation of a line that wasn't indented
+ let prevline = getline(prevlnum)
+ if prevline =~ '^\k\+.*\\\s*$'
+ return &sw
+ endif
+
+ " Continuation of a line that was indented
+ if prevline =~ '\k\+.*\\\s*$'
+ return indent(prevlnum)
+ endif
+
+ " Indent the next line if previous line contained a start of a block
+ " definition ('{' or '(').
+ if prevline =~ '^\k\+[^#]*{}\@!\s*$' " TODO || prevline =~ '^\k\+[^#]*()\@!\s*$'
+ return &sw
+ endif
+
+ " Match inside of a block
+ if s:IsInBlock(v:lnum)
+ if prevline =~ "^\k\+.*$"
+ return &sw
+ else
+ return indent(prevlnum)
+ endif
+ endif
+
+ return 0
+endfunction
+
+let &cpo = s:cpo_save
+unlet s:cpo_save
diff --git a/runtime/indent/html.vim b/runtime/indent/html.vim
index 7eb963b7b2..8aaf82e21f 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: 2015 Jun 12
+" Last Change: 2015 Sep 25
" Version: 1.0
" Description: HTML indent script with cached state for faster indenting on a
" range of lines.
@@ -178,13 +178,15 @@ let s:countonly = 0
" 3 "script"
" 4 "style"
" 5 comment start
+" 6 conditional comment start
" -1 closing tag
" -2 "/pre"
" -3 "/script"
" -4 "/style"
" -5 comment end
+" -6 conditional comment end
let s:indent_tags = {}
-let s:endtags = [0,0,0,0,0,0] " long enough for the highest index
+let s:endtags = [0,0,0,0,0,0,0] " long enough for the highest index
"}}}
" Add a list of tag names for a pair of <tag> </tag> to "tags".
@@ -257,6 +259,7 @@ call s:AddBlockTag('pre', 2)
call s:AddBlockTag('script', 3)
call s:AddBlockTag('style', 4)
call s:AddBlockTag('<!--', 5, '-->')
+call s:AddBlockTag('<!--[', 6, '![endif]-->')
"}}}
" Return non-zero when "tagname" is an opening tag, not being a block tag, for
@@ -291,7 +294,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\+\)*\>\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g')
+ call substitute(a:text, '<\zs/\=\w\+\(-\w\+\)*\>\|<!--\[\|\[endif\]-->\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g')
let s:countonly = 0
endfunc "}}}
@@ -303,7 +306,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\+\)*\>\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g')
+ let tmp = substitute(a:text, '<\zs/\=\w\+\(-\w\+\)*\>\|<!--\[\|\[endif\]-->\|<!--\|-->', '\=s:CheckTag(submatch(0))', 'g')
if s:block == 3
let b:hi_newstate.scripttype = s:GetScriptType(matchstr(tmp, '\C.*<SCRIPT\>\zs[^>]*'))
endif
@@ -425,7 +428,7 @@ func! s:FreshState(lnum)
" State:
" lnum last indented line == prevnonblank(a:lnum - 1)
" block = 0 a:lnum located within special tag: 0:none, 2:<pre>,
- " 3:<script>, 4:<style>, 5:<!--
+ " 3:<script>, 4:<style>, 5:<!--, 6:<!--[
" baseindent use this indent for line a:lnum as a start - kind of
" autoindent (if block==0)
" scripttype = '' type attribute of a script tag (if block==3)
@@ -464,10 +467,13 @@ func! s:FreshState(lnum)
" FI
" look back for a blocktag
- call cursor(a:lnum, 1)
- let [stopline, stopcol] = searchpos('\c<\zs\/\=\%(pre\>\|script\>\|style\>\)', "bW")
- if stopline > 0
- " fugly ... why isn't there searchstr()
+ let stopline2 = v:lnum + 1
+ if has_key(b:hi_indent, 'block') && b:hi_indent.block > 5
+ let [stopline2, stopcol2] = searchpos('<!--', 'bnW')
+ endif
+ let [stopline, stopcol] = searchpos('\c<\zs\/\=\%(pre\>\|script\>\|style\>\)', "bnW")
+ if stopline > 0 && stopline < stopline2
+ " ugly ... why isn't there searchstr()
let tagline = tolower(getline(stopline))
let blocktag = matchstr(tagline, '\/\=\%(pre\>\|script\>\|style\>\)', stopcol - 1)
if blocktag[0] != "/"
@@ -487,23 +493,29 @@ func! s:FreshState(lnum)
" blocktag == "/..."
let swendtag = match(tagline, '^\s*</') >= 0
if !swendtag
- let [bline, bcol] = searchpos('<'.blocktag[1:].'\>', "bW")
+ 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()
return state
endif
endif
endif
+ if stopline > stopline2
+ let stopline = stopline2
+ let stopcol = stopcol2
+ endif
" else look back for comment
- call cursor(a:lnum, 1)
- let [comlnum, comcol, found] = searchpos('\(<!--\)\|-->', 'bpW', stopline)
- if found == 2
+ let [comlnum, comcol, found] = searchpos('\(<!--\[\)\|\(<!--\)\|-->', 'bpnW', stopline)
+ if found == 2 || found == 3
" comment opener found, assume a:lnum within comment
- let state.block = 5
+ let state.block = (found == 3 ? 5 : 6)
let state.blocklnr = comlnum
" check preceding tags in the line:
call s:CountITags(tolower(getline(comlnum)[: comcol-2]))
+ if found == 2
+ let state.baseindent = b:hi_indent.baseindent
+ endif
let state.blocktagind = indent(comlnum) + (s:curind + s:nextrel) * s:ShiftWidth()
return state
endif
@@ -819,6 +831,20 @@ func! s:Alien5()
return indent(prevlnum)
endfunc "}}}
+" Return the indent for conditional comment: <!--[ ![endif]-->
+func! s:Alien6()
+ "{{{
+ let curtext = getline(v:lnum)
+ if curtext =~ '\s*\zs<!\[endif\]-->'
+ " current line starts with end of comment, line up with comment start.
+ let lnum = search('<!--', 'bn')
+ if lnum > 0
+ return indent(lnum)
+ endif
+ endif
+ return b:hi_indent.baseindent + s:ShiftWidth()
+endfunc "}}}
+
" When the "lnum" line ends in ">" find the line containing the matching "<".
func! HtmlIndent_FindTagStart(lnum)
"{{{
diff --git a/runtime/indent/lua.vim b/runtime/indent/lua.vim
index 5f049d4585..d1d2c0d600 100644
--- a/runtime/indent/lua.vim
+++ b/runtime/indent/lua.vim
@@ -2,7 +2,7 @@
" Language: Lua script
" Maintainer: Marcus Aurelius Farias <marcus.cf 'at' bol.com.br>
" First Author: Max Ischenko <mfi 'at' ukr.net>
-" Last Change: 2014 Nov 12
+" Last Change: 2016 Jan 10
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
@@ -52,9 +52,9 @@ function! GetLuaIndent()
endif
endif
- " Subtract a 'shiftwidth' on end, else (and elseif), until and '}'
+ " Subtract a 'shiftwidth' on end, else, elseif, until and '}'
" This is the part that requires 'indentkeys'.
- let midx = match(getline(v:lnum), '^\s*\%(end\>\|else\>\|until\>\|}\)')
+ let midx = match(getline(v:lnum), '^\s*\%(end\>\|else\>\|elseif\>\|until\>\|}\)')
if midx != -1 && synIDattr(synID(v:lnum, midx + 1, 1), "name") != "luaComment"
let ind = ind - &shiftwidth
endif
diff --git a/runtime/indent/sh.vim b/runtime/indent/sh.vim
index 0394ee22e8..5bd8c77fab 100644
--- a/runtime/indent/sh.vim
+++ b/runtime/indent/sh.vim
@@ -1,16 +1,21 @@
" Vim indent file
-" Language: Shell Script
-" Maintainer: Peter Aronoff <telemachus@arpinum.org>
-" Original Author: Nikolai Weibull <now@bitwi.se>
-" Latest Revision: 2014-08-22
+" 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: 2015-12-15
+" License: Vim (see :h license)
+" Repository: https://github.com/chrisbra/vim-sh-indent
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
+let b:undo_indent = 'setlocal indentexpr< indentkeys< smartindent<'
+
setlocal indentexpr=GetShIndent()
-setlocal indentkeys+=0=then,0=do,0=else,0=elif,0=fi,0=esac,0=done,),0=;;,0=;&
+setlocal indentkeys+=0=then,0=do,0=else,0=elif,0=fi,0=esac,0=done,0=end,),0=;;,0=;&
setlocal indentkeys+=0=fin,0=fil,0=fip,0=fir,0=fix
setlocal indentkeys-=:,0#
setlocal nosmartindent
@@ -54,8 +59,8 @@ function! GetShIndent()
let ind = indent(lnum)
let line = getline(lnum)
- if line =~ '^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\)\>'
- if line !~ '\<\%(fi\|esac\|done\)\>\s*\%(#.*\)\=$'
+ if line =~ '^\s*\%(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
elseif s:is_case_label(line, pnum)
@@ -76,7 +81,7 @@ function! GetShIndent()
let pine = line
let line = getline(v:lnum)
- if line =~ '^\s*\%(then\|do\|else\|elif\|fi\|done\)\>' || line =~ '^\s*}'
+ if line =~ '^\s*\%(then\|do\|else\|elif\|fi\|done\|end\)\>' || line =~ '^\s*}'
let ind -= s:indent_value('default')
elseif line =~ '^\s*esac\>' && s:is_case_empty(getline(v:lnum - 1))
let ind -= s:indent_value('default')
diff --git a/runtime/indent/systemd.vim b/runtime/indent/systemd.vim
new file mode 100644
index 0000000000..a05a87bb1c
--- /dev/null
+++ b/runtime/indent/systemd.vim
@@ -0,0 +1,10 @@
+" Vim indent file
+" Language: systemd.unit(5)
+
+" Only load this indent file when no other was loaded.
+if exists("b:did_indent")
+ finish
+endif
+
+" Looks a lot like dosini files.
+runtime! indent/dosini.vim
diff --git a/runtime/indent/teraterm.vim b/runtime/indent/teraterm.vim
new file mode 100644
index 0000000000..ba24257b02
--- /dev/null
+++ b/runtime/indent/teraterm.vim
@@ -0,0 +1,67 @@
+" Vim indent file
+" Language: Tera Term Language (TTL)
+" Based on Tera Term Version 4.86
+" Maintainer: Ken Takata
+" URL: https://github.com/k-takata/vim-teraterm
+" Last Change: 2015 Jun 4
+" Filenames: *.ttl
+" License: VIM License
+
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+setlocal nosmartindent
+setlocal noautoindent
+setlocal indentexpr=GetTeraTermIndent(v:lnum)
+setlocal indentkeys=!^F,o,O,e
+setlocal indentkeys+==elseif,=endif,=loop,=next,=enduntil,=endwhile
+
+if exists("*GetTeraTermIndent")
+ finish
+endif
+
+" The shiftwidth() function is relatively new.
+" Don't require it to exist.
+if exists('*shiftwidth')
+ function s:sw() abort
+ return shiftwidth()
+ endfunction
+else
+ function s:sw() abort
+ return &shiftwidth
+ endfunction
+endif
+
+function! GetTeraTermIndent(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), ';.*$', '', '')
+ let l:thisl = substitute(getline(a:lnum), ';.*$', '', '')
+ let l:previ = indent(l:prevlnum)
+
+ let l:ind = l:previ
+
+ if l:prevl =~ '^\s*if\>.*\<then\s*$'
+ " previous line opened a block
+ let l:ind += s:sw()
+ endif
+ if l:prevl =~ '^\s*\%(elseif\|else\|do\|until\|while\|for\)\>'
+ " previous line opened a block
+ let l:ind += s:sw()
+ endif
+ if l:thisl =~ '^\s*\%(elseif\|else\|endif\|enduntil\|endwhile\|loop\|next\)\>'
+ " this line closed a block
+ let l:ind -= s:sw()
+ endif
+
+ return l:ind
+endfunction
+
+" vim: ts=8 sw=2 sts=2
diff --git a/runtime/indent/yaml.vim b/runtime/indent/yaml.vim
index 1d03715773..aa4906ce0a 100644
--- a/runtime/indent/yaml.vim
+++ b/runtime/indent/yaml.vim
@@ -1,6 +1,7 @@
" Vim indent file
" Language: YAML
" Maintainer: Nikolai Pavlov <zyx.vim@gmail.com>
+" Last Change: 2015 Nov 01
" Only load this indent file when no other was loaded.
if exists('b:did_indent')
@@ -13,7 +14,7 @@ set cpo&vim
let b:did_indent = 1
setlocal indentexpr=GetYAMLIndent(v:lnum)
-setlocal indentkeys=!^F,o,O,0#,0},0],<:>,-
+setlocal indentkeys=!^F,o,O,0#,0},0],<:>,0-
setlocal nosmartindent
let b:undo_indent = 'setlocal indentexpr< indentkeys< smartindent<'
@@ -115,8 +116,13 @@ function GetYAMLIndent(lnum)
\ s:liststartregex))
elseif line =~# s:mapkeyregex
" Same for line containing mapping key
- return indent(s:FindPrevLEIndentedLineMatchingRegex(a:lnum,
- \ s:mapkeyregex))
+ let prevmapline = s:FindPrevLEIndentedLineMatchingRegex(a:lnum,
+ \ s:mapkeyregex)
+ if getline(prevmapline) =~# '^\s*- '
+ return indent(prevmapline) + 2
+ else
+ return indent(prevmapline)
+ endif
elseif prevline =~# '^\s*- '
" - List with
" multiline scalar