made the pack completely portable and wrote relevent bat files to go with it

This commit is contained in:
Draqoken
2025-04-09 17:04:56 +03:00
parent 5e77d7e9cf
commit 5e4144c3c0
7417 changed files with 2181044 additions and 19 deletions

View File

@@ -0,0 +1,48 @@
This directory contains files to automatically compute the indent for a
type of file.
If you want to add your own indent file for your personal use, read the docs
at ":help indent-expression". Looking at the existing files should give you
inspiration.
If you make a new indent file which would be useful for others, please send it
to the vim-dev mailing list <vim-dev@vim.org>. Include instructions for
detecting the file type for this language, by file name extension or by
checking a few lines in the file. And please stick to the rules below.
If you have remarks about an existing file, send them to the maintainer of
that file. Only when you get no response send a message to the vim-dev
mailing list: <vim-dev@vim.org>.
If you are the maintainer of an indent file and make improvements, e-mail the
new version to the vim-dev mailing list: <vim-dev@vim.org>.
Rules for making an indent file:
You should use this check for "b:did_indent":
" Only load this indent file when no other was loaded yet.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
Always use ":setlocal" to set 'indentexpr'. This avoids it being carried over
to other buffers.
To trigger the indenting after typing a word like "endif", add the word to the
'indentkeys' option with "+=".
You normally set 'indentexpr' to evaluate a function and then define that
function. That function only needs to be defined once for as long as Vim is
running. Add a test if the function exists and use ":finish", like this:
if exists("*GetMyIndent")
finish
endif
The user may have several options set unlike you, try to write the file such
that it works with any option settings. Also be aware of certain features not
being compiled in.
To test the indent file, see testdir/README.txt.

View File

@@ -0,0 +1,13 @@
" Vim indent file
" Language: Aap recipe
" Maintainer: The Vim Project <https://github.com/vim/vim>
" Last Change: 2023 Aug 10
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
" Works mostly like Python.
runtime! indent/python.vim

View File

@@ -0,0 +1,311 @@
"------------------------------------------------------------------------------
" Description: Vim Ada indent file
" Language: Ada (2005)
" $Id: ada.vim 887 2008-07-08 14:29:01Z krischik $
" Copyright: Copyright (C) 2006 Martin Krischik
" Maintainer: Martin Krischik <krischik@users.sourceforge.net>
" Neil Bird <neil@fnxweb.com>
" Ned Okie <nokie@radford.edu>
" $Author: krischik $
" $Date: 2008-07-08 16:29:01 +0200 (Di, 08 Jul 2008) $
" Version: 4.6
" $Revision: 887 $
" $HeadURL: https://gnuada.svn.sourceforge.net/svnroot/gnuada/trunk/tools/vim/indent/ada.vim $
" History: 24.05.2006 MK Unified Headers
" 16.07.2006 MK Ada-Mode as vim-ball
" 15.10.2006 MK Bram's suggestion for runtime integration
" 05.11.2006 MK Bram suggested to save on spaces
" 19.09.2007 NO g: missing before ada#Comment
" 2022 April: b:undo_indent added by Doug Kearns
" Help Page: ft-vim-indent
"------------------------------------------------------------------------------
" ToDo:
" Verify handling of multi-line exprs. and recovery upon the final ';'.
" Correctly find comments given '"' and "" ==> " syntax.
" Combine the two large block-indent functions into one?
"------------------------------------------------------------------------------
" Only load this indent file when no other was loaded.
if exists("b:did_indent") || version < 700
finish
endif
let b:did_indent = 45
setlocal indentexpr=GetAdaIndent()
setlocal indentkeys-=0{,0}
setlocal indentkeys+=0=~then,0=~end,0=~elsif,0=~when,0=~exception,0=~begin,0=~is,0=~record
let b:undo_indent = "setl inde< indk<"
" Only define the functions once.
if exists("*GetAdaIndent")
finish
endif
let s:keepcpo= &cpo
set cpo&vim
if exists("g:ada_with_gnat_project_files")
let s:AdaBlockStart = '^\s*\(if\>\|while\>\|else\>\|elsif\>\|loop\>\|for\>.*\<\(loop\|use\)\>\|declare\>\|begin\>\|type\>.*\<is\>[^;]*$\|\(type\>.*\)\=\<record\>\|procedure\>\|function\>\|accept\>\|do\>\|task\>\|package\>\|project\>\|then\>\|when\>\|is\>\)'
else
let s:AdaBlockStart = '^\s*\(if\>\|while\>\|else\>\|elsif\>\|loop\>\|for\>.*\<\(loop\|use\)\>\|declare\>\|begin\>\|type\>.*\<is\>[^;]*$\|\(type\>.*\)\=\<record\>\|procedure\>\|function\>\|accept\>\|do\>\|task\>\|package\>\|then\>\|when\>\|is\>\)'
endif
" Section: s:MainBlockIndent {{{1
"
" Try to find indent of the block we're in
" prev_indent = the previous line's indent
" prev_lnum = previous line (to start looking on)
" blockstart = expr. that indicates a possible start of this block
" stop_at = if non-null, if a matching line is found, gives up!
" No recursive previous block analysis: simply look for a valid line
" with a lesser or equal indent than we currently (on prev_lnum) have.
" This shouldn't work as well as it appears to with lines that are currently
" nowhere near the correct indent (e.g., start of line)!
" Seems to work OK as it 'starts' with the indent of the /previous/ line.
function s:MainBlockIndent (prev_indent, prev_lnum, blockstart, stop_at)
let lnum = a:prev_lnum
let line = substitute( getline(lnum), g:ada#Comment, '', '' )
while lnum > 1
if a:stop_at != '' && line =~ '^\s*' . a:stop_at && indent(lnum) < a:prev_indent
return a:prev_indent
elseif line =~ '^\s*' . a:blockstart
let ind = indent(lnum)
if ind < a:prev_indent
return ind
endif
endif
let lnum = prevnonblank(lnum - 1)
" Get previous non-blank/non-comment-only line
while 1
let line = substitute( getline(lnum), g:ada#Comment, '', '' )
if line !~ '^\s*$' && line !~ '^\s*#'
break
endif
let lnum = prevnonblank(lnum - 1)
if lnum <= 0
return a:prev_indent
endif
endwhile
endwhile
" Fallback - just move back one
return a:prev_indent - shiftwidth()
endfunction MainBlockIndent
" Section: s:EndBlockIndent {{{1
"
" Try to find indent of the block we're in (and about to complete),
" including handling of nested blocks. Works on the 'end' of a block.
" prev_indent = the previous line's indent
" prev_lnum = previous line (to start looking on)
" blockstart = expr. that indicates a possible start of this block
" blockend = expr. that indicates a possible end of this block
function s:EndBlockIndent( prev_indent, prev_lnum, blockstart, blockend )
let lnum = a:prev_lnum
let line = getline(lnum)
let ends = 0
while lnum > 1
if getline(lnum) =~ '^\s*' . a:blockstart
let ind = indent(lnum)
if ends <= 0
if ind < a:prev_indent
return ind
endif
else
let ends = ends - 1
endif
elseif getline(lnum) =~ '^\s*' . a:blockend
let ends = ends + 1
endif
let lnum = prevnonblank(lnum - 1)
" Get previous non-blank/non-comment-only line
while 1
let line = getline(lnum)
let line = substitute( line, g:ada#Comment, '', '' )
if line !~ '^\s*$'
break
endif
let lnum = prevnonblank(lnum - 1)
if lnum <= 0
return a:prev_indent
endif
endwhile
endwhile
" Fallback - just move back one
return a:prev_indent - shiftwidth()
endfunction EndBlockIndent
" Section: s:StatementIndent {{{1
"
" Return indent of previous statement-start
" (after we've indented due to multi-line statements).
" This time, we start searching on the line *before* the one given (which is
" the end of a statement - we want the previous beginning).
function s:StatementIndent( current_indent, prev_lnum )
let lnum = a:prev_lnum
while lnum > 0
let prev_lnum = lnum
let lnum = prevnonblank(lnum - 1)
" Get previous non-blank/non-comment-only line
while 1
let line = substitute( getline(lnum), g:ada#Comment, '', '' )
if line !~ '^\s*$' && line !~ '^\s*#'
break
endif
let lnum = prevnonblank(lnum - 1)
if lnum <= 0
return a:current_indent
endif
endwhile
" Leave indent alone if our ';' line is part of a ';'-delineated
" aggregate (e.g., procedure args.) or first line after a block start.
if line =~ s:AdaBlockStart || line =~ '(\s*$'
return a:current_indent
endif
if line !~ '[.=(]\s*$'
let ind = indent(prev_lnum)
if ind < a:current_indent
return ind
endif
endif
endwhile
" Fallback - just use current one
return a:current_indent
endfunction StatementIndent
" Section: GetAdaIndent {{{1
"
" Find correct indent of a new line based upon what went before
"
function GetAdaIndent()
" Find a non-blank line above the current line.
let lnum = prevnonblank(v:lnum - 1)
let ind = indent(lnum)
let package_line = 0
" Get previous non-blank/non-comment-only/non-cpp line
while 1
let line = substitute( getline(lnum), g:ada#Comment, '', '' )
if line !~ '^\s*$' && line !~ '^\s*#'
break
endif
let lnum = prevnonblank(lnum - 1)
if lnum <= 0
return ind
endif
endwhile
" Get default indent (from prev. line)
let ind = indent(lnum)
let initind = ind
" Now check what's on the previous line
if line =~ s:AdaBlockStart || line =~ '(\s*$'
" Check for false matches to AdaBlockStart
let false_match = 0
if line =~ '^\s*\(procedure\|function\|package\)\>.*\<is\s*new\>'
" Generic instantiation
let false_match = 1
elseif line =~ ')\s*;\s*$' || line =~ '^\([^(]*([^)]*)\)*[^(]*;\s*$'
" forward declaration
let false_match = 1
endif
" Move indent in
if ! false_match
let ind = ind + shiftwidth()
endif
elseif line =~ '^\s*\(case\|exception\)\>'
" Move indent in twice (next 'when' will move back)
let ind = ind + 2 * shiftwidth()
elseif line =~ '^\s*end\s*record\>'
" Move indent back to tallying 'type' preceding the 'record'.
" Allow indent to be equal to 'end record's.
let ind = s:MainBlockIndent( ind+shiftwidth(), lnum, 'type\>', '' )
elseif line =~ '\(^\s*new\>.*\)\@<!)\s*[;,]\s*$'
" Revert to indent of line that started this parenthesis pair
exe lnum
exe 'normal! $F)%'
if getline('.') =~ '^\s*('
" Dire layout - use previous indent (could check for g:ada#Comment here)
let ind = indent( prevnonblank( line('.')-1 ) )
else
let ind = indent('.')
endif
exe v:lnum
elseif line =~ '[.=(]\s*$'
" A statement continuation - move in one
let ind = ind + shiftwidth()
elseif line =~ '^\s*new\>'
" Multiple line generic instantiation ('package blah is\nnew thingy')
let ind = s:StatementIndent( ind - shiftwidth(), lnum )
elseif line =~ ';\s*$'
" Statement end (but not 'end' ) - try to find current statement-start indent
let ind = s:StatementIndent( ind, lnum )
endif
" Check for potential argument list on next line
let continuation = (line =~ '[A-Za-z0-9_]\s*$')
" Check current line; search for simplistic matching start-of-block
let line = getline(v:lnum)
if line =~ '^\s*#'
" Start of line for ada-pp
let ind = 0
elseif continuation && line =~ '^\s*('
" Don't do this if we've already indented due to the previous line
if ind == initind
let ind = ind + shiftwidth()
endif
elseif line =~ '^\s*\(begin\|is\)\>'
let ind = s:MainBlockIndent( ind, lnum, '\(procedure\|function\|declare\|package\|task\)\>', 'begin\>' )
elseif line =~ '^\s*record\>'
let ind = s:MainBlockIndent( ind, lnum, 'type\>\|for\>.*\<use\>', '' ) + shiftwidth()
elseif line =~ '^\s*\(else\|elsif\)\>'
let ind = s:MainBlockIndent( ind, lnum, 'if\>', '' )
elseif line =~ '^\s*when\>'
" Align 'when' one /in/ from matching block start
let ind = s:MainBlockIndent( ind, lnum, '\(case\|exception\)\>', '' ) + shiftwidth()
elseif line =~ '^\s*end\>\s*\<if\>'
" End of if statements
let ind = s:EndBlockIndent( ind, lnum, 'if\>', 'end\>\s*\<if\>' )
elseif line =~ '^\s*end\>\s*\<loop\>'
" End of loops
let ind = s:EndBlockIndent( ind, lnum, '\(\(while\|for\)\>.*\)\?\<loop\>', 'end\>\s*\<loop\>' )
elseif line =~ '^\s*end\>\s*\<record\>'
" End of records
let ind = s:EndBlockIndent( ind, lnum, '\(type\>.*\)\=\<record\>', 'end\>\s*\<record\>' )
elseif line =~ '^\s*end\>\s*\<procedure\>'
" End of procedures
let ind = s:EndBlockIndent( ind, lnum, 'procedure\>.*\<is\>', 'end\>\s*\<procedure\>' )
elseif line =~ '^\s*end\>\s*\<case\>'
" End of case statement
let ind = s:EndBlockIndent( ind, lnum, 'case\>.*\<is\>', 'end\>\s*\<case\>' )
elseif line =~ '^\s*end\>'
" General case for end
let ind = s:MainBlockIndent( ind, lnum, '\(if\|while\|for\|loop\|accept\|begin\|record\|case\|exception\|package\)\>', '' )
elseif line =~ '^\s*exception\>'
let ind = s:MainBlockIndent( ind, lnum, 'begin\>', '' )
elseif line =~ '^\s*then\>'
let ind = s:MainBlockIndent( ind, lnum, 'if\>', '' )
endif
return ind
endfunction GetAdaIndent
let &cpo = s:keepcpo
unlet s:keepcpo
finish " 1}}}
"------------------------------------------------------------------------------
" Copyright (C) 2006 Martin Krischik
"
" Vim is Charityware - see ":help license" or uganda.txt for licence details.
"------------------------------------------------------------------------------
" vim: textwidth=78 wrap tabstop=8 shiftwidth=3 softtabstop=3 noexpandtab
" vim: foldmethod=marker

View File

@@ -0,0 +1,12 @@
" Vim indent file
" Language: ANT files
" Maintainer: David Fishburn <fishburn@ianywhere.com>
" Last Change: Thu May 15 2003 10:02:54 PM
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
" Use XML formatting rules
runtime! indent/xml.vim

View File

@@ -0,0 +1,16 @@
" Vim indent file
" Language: Arduino
" Maintainer: The Vim Project <https://github.com/vim/vim>
" Ken Takata <https://github.com/k-takata>
" Last Change: 2024 Apr 03
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" Use C indenting.
setlocal cindent
let b:undo_indent = "setl cin<"

View File

@@ -0,0 +1,88 @@
" Vim indent file (experimental).
" Language: Astro
" Author: Wuelner Martínez <wuelner.martinez@outlook.com>
" Maintainer: Wuelner Martínez <wuelner.martinez@outlook.com>
" URL: https://github.com/wuelnerdotexe/vim-astro
" Last Change: 2022 Aug 07
" Based On: Evan Lecklider's vim-svelte
" Changes: See https://github.com/evanleck/vim-svelte
" Credits: See vim-svelte on github
" Only load this indent file when no other was loaded yet.
if exists('b:did_indent')
finish
endif
let b:html_indent_script1 = 'inc'
let b:html_indent_style1 = 'inc'
" Embedded HTML indent.
runtime! indent/html.vim
let s:html_indent = &l:indentexpr
unlet b:did_indent
let b:did_indent = 1
setlocal indentexpr=GetAstroIndent()
setlocal indentkeys=<>>,/,0{,{,},0},0),0],0\,<<>,,!^F,*<Return>,o,O,e,;
let b:undo_indent = 'setl inde< indk<'
" Only define the function once.
if exists('*GetAstroIndent')
finish
endif
let s:cpoptions_save = &cpoptions
setlocal cpoptions&vim
function! GetAstroIndent()
let l:current_line_number = v:lnum
if l:current_line_number == 0
return 0
endif
let l:current_line = getline(l:current_line_number)
if l:current_line =~ '^\s*</\?\(script\|style\)'
return 0
endif
let l:previous_line_number = prevnonblank(l:current_line_number - 1)
let l:previous_line = getline(l:previous_line_number)
let l:previous_line_indent = indent(l:previous_line_number)
if l:previous_line =~ '^\s*</\?\(script\|style\)'
return l:previous_line_indent + shiftwidth()
endif
execute 'let l:indent = ' . s:html_indent
if searchpair('<style>', '', '</style>', 'bW') &&
\ l:previous_line =~ ';$' && l:current_line !~ '}'
return l:previous_line_indent
endif
if synID(l:previous_line_number, match(
\ l:previous_line, '\S'
\ ) + 1, 0) == hlID('htmlTag') && synID(l:current_line_number, match(
\ l:current_line, '\S'
\ ) + 1, 0) != hlID('htmlEndTag')
let l:indents_match = l:indent == l:previous_line_indent
let l:previous_closes = l:previous_line =~ '/>$'
if l:indents_match &&
\ !l:previous_closes && l:previous_line =~ '<\(\u\|\l\+:\l\+\)'
return l:previous_line_indent + shiftwidth()
elseif !l:indents_match && l:previous_closes
return l:previous_line_indent
endif
endif
return l:indent
endfunction
let &cpoptions = s:cpoptions_save
unlet s:cpoptions_save
" vim: ts=8

View File

@@ -0,0 +1,11 @@
" Vim indent file
" Language: automake
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
" Latest Revision: 2006-04-19
if exists("b:did_indent")
finish
endif
" same as makefile indenting for now.
runtime! indent/make.vim

View File

@@ -0,0 +1,235 @@
" vim: set sw=3 sts=3:
" Awk indent script. It can handle multi-line statements and expressions.
" It works up to the point where the distinction between correct/incorrect
" and personal taste gets fuzzy. Drop me an e-mail for bug reports and
" reasonable style suggestions.
"
" Bugs:
" =====
" - Some syntax errors may cause erratic indentation.
" - Same for very unusual but syntacticly correct use of { }
" - In some cases it's confused by the use of ( and { in strings constants
" - This version likes the closing brace of a multiline pattern-action be on
" character position 1 before the following pattern-action combination is
" formatted
" Author:
" =======
" Erik Janssen, ejanssen@itmatters.nl
"
" History:
" ========
" 26-04-2002 Got initial version working reasonably well
" 29-04-2002 Fixed problems in function headers and max line width
" Added support for two-line if's without curly braces
" Fixed hang: 2011 Aug 31
" 2022 April: b:undo_indent added by Doug Kearns
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetAwkIndent()
" Mmm, copied from the tcl indent program. Is this okay?
setlocal indentkeys-=:,0#
let b:undo_indent = "setl inde< indk<"
" Only define the function once.
if exists("*GetAwkIndent")
finish
endif
" This function contains a lot of exit points. It checks for simple cases
" first to get out of the function as soon as possible, thereby reducing the
" number of possibilities later on in the difficult parts
function! GetAwkIndent()
" Find previous line and get its indentation
let prev_lineno = s:Get_prev_line( v:lnum )
if prev_lineno == 0
return 0
endif
let prev_data = getline( prev_lineno )
let ind = indent( prev_lineno )
" Increase indent if the previous line contains an opening brace. Search
" for this brace the hard way to prevent errors if the previous line is a
" 'pattern { action }' (simple check match on /{/ increases the indent then)
if s:Get_brace_balance( prev_data, '{', '}' ) > 0
return ind + shiftwidth()
endif
let brace_balance = s:Get_brace_balance( prev_data, '(', ')' )
" If prev line has positive brace_balance and starts with a word (keyword
" or function name), align the current line on the first '(' of the prev
" line
if brace_balance > 0 && s:Starts_with_word( prev_data )
return s:Safe_indent( ind, s:First_word_len(prev_data), getline(v:lnum))
endif
" If this line starts with an open brace bail out now before the line
" continuation checks.
if getline( v:lnum ) =~ '^\s*{'
return ind
endif
" If prev line seems to be part of multiline statement:
" 1. Prev line is first line of a multiline statement
" -> attempt to indent on first ' ' or '(' of prev line, just like we
" indented the positive brace balance case above
" 2. Prev line is not first line of a multiline statement
" -> copy indent of prev line
let continue_mode = s:Seems_continuing( prev_data )
if continue_mode > 0
if s:Seems_continuing( getline(s:Get_prev_line( prev_lineno )) )
" Case 2
return ind
else
" Case 1
if continue_mode == 1
" Need continuation due to comma, backslash, etc
return s:Safe_indent( ind, s:First_word_len(prev_data), getline(v:lnum))
else
" if/for/while without '{'
return ind + shiftwidth()
endif
endif
endif
" If the previous line doesn't need continuation on the current line we are
" on the start of a new statement. We have to make sure we align with the
" previous statement instead of just the previous line. This is a bit
" complicated because the previous statement might be multi-line.
"
" The start of a multiline statement can be found by:
"
" 1 If the previous line contains closing braces and has negative brace
" balance, search backwards until cumulative brace balance becomes zero,
" take indent of that line
" 2 If the line before the previous needs continuation search backward
" until that's not the case anymore. Take indent of one line down.
" Case 1
if prev_data =~ ')' && brace_balance < 0
while brace_balance != 0 && prev_lineno > 0
let prev_lineno = s:Get_prev_line( prev_lineno )
let prev_data = getline( prev_lineno )
let brace_balance=brace_balance+s:Get_brace_balance(prev_data,'(',')' )
endwhile
let ind = indent( prev_lineno )
else
" Case 2
if s:Seems_continuing( getline( prev_lineno - 1 ) )
let prev_lineno = prev_lineno - 2
let prev_data = getline( prev_lineno )
while prev_lineno > 0 && (s:Seems_continuing( prev_data ) > 0)
let prev_lineno = s:Get_prev_line( prev_lineno )
let prev_data = getline( prev_lineno )
endwhile
let ind = indent( prev_lineno + 1 )
endif
endif
" Decrease indent if this line contains a '}'.
if getline(v:lnum) =~ '^\s*}'
let ind = ind - shiftwidth()
endif
return ind
endfunction
" Find the open and close braces in this line and return how many more open-
" than close braces there are. It's also used to determine cumulative balance
" across multiple lines.
function! s:Get_brace_balance( line, b_open, b_close )
let line2 = substitute( a:line, a:b_open, "", "g" )
let openb = strlen( a:line ) - strlen( line2 )
let line3 = substitute( line2, a:b_close, "", "g" )
let closeb = strlen( line2 ) - strlen( line3 )
return openb - closeb
endfunction
" Find out whether the line starts with a word (i.e. keyword or function
" call). Might need enhancements here.
function! s:Starts_with_word( line )
if a:line =~ '^\s*[a-zA-Z_0-9]\+\s*('
return 1
endif
return 0
endfunction
" Find the length of the first word in a line. This is used to be able to
" align a line relative to the 'print ' or 'if (' on the previous line in case
" such a statement spans multiple lines.
" Precondition: only to be used on lines where 'Starts_with_word' returns 1.
function! s:First_word_len( line )
let white_end = matchend( a:line, '^\s*' )
if match( a:line, '^\s*func' ) != -1
let word_end = matchend( a:line, '[a-z]\+\s\+[a-zA-Z_0-9]\+[ (]*' )
else
let word_end = matchend( a:line, '[a-zA-Z_0-9]\+[ (]*' )
endif
return word_end - white_end
endfunction
" Determine if 'line' completes a statement or is continued on the next line.
" This one is far from complete and accepts illegal code. Not important for
" indenting, however.
function! s:Seems_continuing( line )
" Unfinished lines
if a:line =~ '\(--\|++\)\s*$'
return 0
endif
if a:line =~ '[\\,\|\&\+\-\*\%\^]\s*$'
return 1
endif
" if/for/while (cond) eol
if a:line =~ '^\s*\(if\|while\|for\)\s*(.*)\s*$' || a:line =~ '^\s*else\s*'
return 2
endif
return 0
endfunction
" Get previous relevant line. Search back until a line is that is no
" comment or blank and return the line number
function! s:Get_prev_line( lineno )
let lnum = a:lineno - 1
let data = getline( lnum )
while lnum > 0 && (data =~ '^\s*#' || data =~ '^\s*$')
let lnum = lnum - 1
let data = getline( lnum )
endwhile
return lnum
endfunction
" This function checks whether an indented line exceeds a maximum linewidth
" (hardcoded 80). If so and it is possible to stay within 80 positions (or
" limit num of characters beyond linewidth) by decreasing the indent (keeping
" it > base_indent), do so.
function! s:Safe_indent( base, wordlen, this_line )
let line_base = matchend( a:this_line, '^\s*' )
let line_len = strlen( a:this_line ) - line_base
let indent = a:base
if (indent + a:wordlen + line_len) > 80
" Simple implementation good enough for the time being
let indent = indent + 3
endif
return indent + a:wordlen
endfunction

View File

@@ -0,0 +1,18 @@
" Vim indent file
" Language: bash
" Maintainer: The Vim Project <https://github.com/vim/vim>
" Last Change: 2023 Aug 13
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
" The actual indenting is in sh.vim and controlled by buffer-local variables.
unlet! b:is_sh
unlet! b:is_kornshell
let b:is_bash = 1
runtime! indent/sh.vim
" vim: ts=8

View File

@@ -0,0 +1,11 @@
" Vim indent file
" Language: BASIC (QuickBASIC 4.5)
" Maintainer: Doug Kearns <dougkearns@gmail.com>
" Last Change: 2022 Jan 24
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
runtime! indent/vb.vim

View File

@@ -0,0 +1,15 @@
" Vim indent file
" Language: BibTeX
" Maintainer: Dorai Sitaram <ds26@gte.com>
" URL: http://www.ccs.neu.edu/~dorai/vimplugins/vimplugins.html
" Last Change: 2005 Mar 28
" Only do this when not done yet for this buffer
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal cindent
let b:undo_indent = "setl cin<"

View File

@@ -0,0 +1,22 @@
" Vim indent file
" Language: BitBake
" Copyright: Copyright (C) 2019 Agilent Technologies, Inc.
" Maintainer: Chris Laplante <chris.laplante@agilent.com>
" License: You may redistribute this under the same terms as Vim itself
if exists("b:did_indent")
finish
endif
runtime! indent/sh.vim
setlocal indentexpr=bitbake#Indent(v:lnum)
setlocal autoindent
setlocal nolisp
setlocal shiftwidth=4
setlocal expandtab
setlocal indentkeys+=<:>,=elif,=except,0=\"
let b:undo_indent .= ' inde< ai< lisp< sw< et< indk<'
let b:did_indent = 1

View File

@@ -0,0 +1,73 @@
" Vim indent file
" Language: bst
" Author: Tim Pope <vimNOSPAM@tpope.info>
" Last Change: 2022 Mar 15
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetBstIndent(v:lnum)
setlocal cinkeys&
setlocal cinkeys-=0#
setlocal indentkeys&
let b:undo_indent = 'setlocal indentexpr< cinkeys< indentkeys<'
" Only define the function once.
if exists("*GetBstIndent")
finish
endif
function! s:prevgood(lnum)
" Find a non-blank line above the current line.
" Skip over comments.
let lnum = a:lnum
while lnum > 0
let lnum = prevnonblank(lnum - 1)
if getline(lnum) !~ '^\s*%.*$'
break
endif
endwhile
return lnum
endfunction
function! s:strip(lnum)
let line = getline(a:lnum)
let line = substitute(line,'"[^"]*"','""','g')
let line = substitute(line,'%.*','','')
let line = substitute(line,'^\s\+','','')
return line
endfunction
function! s:count(string,char)
let str = substitute(a:string,'[^'.a:char.']','','g')
return strlen(str)
endfunction
function! GetBstIndent(lnum) abort
if a:lnum == 1
return 0
endif
let lnum = s:prevgood(a:lnum)
if lnum <= 0
return indent(a:lnum - 1)
endif
let line = s:strip(lnum)
let cline = s:strip(a:lnum)
if cline =~ '^}' && exists("b:current_syntax")
call cursor(a:lnum,indent(a:lnum))
if searchpair('{','','}','bW',"synIDattr(synID(line('.'),col('.'),1),'name') =~? 'comment\\|string'")
if col('.')+1 == col('$')
return indent('.')
else
return virtcol('.')-1
endif
endif
endif
let fakeline = substitute(line,'^}','','').matchstr(cline,'^}')
let ind = indent(lnum)
let ind = ind + shiftwidth() * s:count(line,'{')
let ind = ind - shiftwidth() * s:count(fakeline,'}')
return ind
endfunction

View File

@@ -0,0 +1,105 @@
" Vim indent file
" Language: Bazel (http://bazel.io)
" Maintainer: David Barnett (https://github.com/google/vim-ft-bzl)
" Last Change: 2021 Jul 08
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
let g:pyindent_nested_paren = 'shiftwidth()'
let g:pyindent_open_paren = 'shiftwidth()'
endif
let l:indent = -1
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
" Indent inside parens.
if searchpair('(\|{\|\[', '', ')\|}\|\]', 'W',
\ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :" .
\ " synIDattr(synID(line('.'), col('.'), 1), 'name')" .
\ " =~ '\\(Comment\\|String\\)$'") && line('.') == a:lnum
" If cursor is at close parens, match indent with open parens.
" E.g.
" foo(
" )
let l:indent = indent(l:par_line)
else
" 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(l:par_line, 1)
if l:par_col != col('$') - 1
let l:indent = l:par_col
endif
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

View File

@@ -0,0 +1,16 @@
" Vim indent file
" Language: C
" Maintainer: The Vim Project <https://github.com/vim/vim>
" Last Change: 2023 Aug 10
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" C indenting is built-in, thus this is very simple
setlocal cindent
let b:undo_indent = "setl cin<"

View File

@@ -0,0 +1,136 @@
" Description: Comshare Dimension Definition Language (CDL)
" Maintainer: Raul Segura Acevedo <raulseguraaceved@netscape.net> (Invalid email address)
" Doug Kearns <dougkearns@gmail.com>
" Last Change: 2022 Apr 06
if exists("b:did_indent")
"finish
endif
let b:did_indent = 1
setlocal indentexpr=CdlGetIndent(v:lnum)
setlocal indentkeys&
setlocal indentkeys+==~else,=~endif,=~then,;,),=
let b:undo_indent = "setl inde< indk<"
" Only define the function once.
if exists("*CdlGetIndent")
"finish
endif
" find out if an "...=..." expression is an assignment (or a conditional)
" it scans 'line' first, and then the previous lines
fun! CdlAssignment(lnum, line)
let f = -1
let lnum = a:lnum
let line = a:line
while lnum > 0 && f == -1
" line without members [a] of [b]:[c]...
let inicio = 0
while 1
" keywords that help to decide
let inicio = matchend(line, '\c\<\(expr\|\a*if\|and\|or\|not\|else\|then\|memberis\|\k\+of\)\>\|[<>;]', inicio)
if inicio < 0
break
endif
" it's formula if there's a ';', 'elsE', 'theN', 'enDif' or 'expr'
" conditional if there's a '<', '>', 'elseif', 'if', 'and', 'or', 'not',
" 'memberis', 'childrenof' and other \k\+of functions
let f = line[inicio-1] =~? '[en;]' || strpart(line, inicio-4, 4) =~? 'ndif\|expr'
endw
let lnum = prevnonblank(lnum-1)
let line = substitute(getline(lnum), '\c\(\[[^]]*]\(\s*of\s*\|:\)*\)\+', ' ', 'g')
endw
" if we hit the start of the file then f = -1, return 1 (formula)
return f != 0
endf
fun! CdlGetIndent(lnum)
let thisline = getline(a:lnum)
if match(thisline, '^\s*\(\k\+\|\[[^]]*]\)\s*\(,\|;\s*$\)') >= 0
" it's an attributes line
return shiftwidth()
elseif match(thisline, '^\c\s*\([{}]\|\/[*/]\|dimension\|schedule\|group\|hierarchy\|class\)') >= 0
" it's a header or '{' or '}' or a comment
return 0
end
let lnum = prevnonblank(a:lnum-1)
" Hit the start of the file, use zero indent.
if lnum == 0
return 0
endif
" PREVIOUS LINE
let ind = indent(lnum)
let line = getline(lnum)
" Whether a '=' is a conditional or an assignment. -1 means we don't know
" yet.
" One 'closing' element at the beginning of the line has already reduced the
" indent, but 'else', 'elseif' & 'then' increment it for the next line.
" '=' at the beginning already has the right indent (increased for
" asignments).
let f = -1
let inicio = matchend(line, '^\c\s*\(else\a*\|then\|endif\|/[*/]\|[);={]\)')
if inicio > 0
let c = line[inicio-1]
" ')' and '=' don't change indent and are useless to set 'f'
if c == '{'
return shiftwidth()
elseif c != ')' && c != '='
let f = 1 " all but 'elseif' are followed by a formula
if c ==? 'n' || c ==? 'e' " 'then', 'else'
let ind = ind + shiftwidth()
elseif strpart(line, inicio-6, 6) ==? 'elseif' " elseif, set f to conditional
let ind = ind + shiftwidth()
let f = 0
end
end
end
" remove members [a] of [b]:[c]... (inicio remains valid)
let line = substitute(line, '\c\(\[[^]]*]\(\s*of\s*\|:\)*\)\+', ' ', 'g')
while 1
" search for the next interesting element
let inicio=matchend(line, '\c\<if\|endif\|[()=;]', inicio)
if inicio < 0
break
end
let c = line[inicio-1]
" 'expr(...)' containing the formula
if strpart(line, inicio-5, 5) ==? 'expr('
let ind = 0
let f = 1
elseif c == ')' || c== ';' || strpart(line, inicio-5, 5) ==? 'endif'
let ind = ind - shiftwidth()
elseif c == '(' || c ==? 'f' " '(' or 'if'
let ind = ind + shiftwidth()
else " c == '='
" if it is an assignment increase indent
if f == -1 " we don't know yet, find out
let f = CdlAssignment(lnum, strpart(line, 0, inicio))
end
if f == 1 " formula increase it
let ind = ind + shiftwidth()
end
end
endw
" CURRENT LINE, if it starts with a closing element, decrease indent
" or if it starts with '=' (assignment), increase indent
if match(thisline, '^\c\s*\(else\|then\|endif\|[);]\)') >= 0
let ind = ind - shiftwidth()
elseif match(thisline, '^\s*=') >= 0
if f == -1 " we don't know yet if is an assignment, find out
let f = CdlAssignment(lnum, "")
end
if f == 1 " formula increase it
let ind = ind + shiftwidth()
end
end
return ind
endfun

View File

@@ -0,0 +1,21 @@
" Vim indent file
" Language: Ch
" Maintainer: SoftIntegration, Inc. <info@softintegration.com>
" URL: http://www.softintegration.com/download/vim/indent/ch.vim
" Last change: 2006 Apr 30
" 2023 Aug 28 by Vim Project (undo_indent)
" Created based on cpp.vim
"
" Ch is a C/C++ interpreter with many high level extensions
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" Ch indenting is built-in, thus this is very simple
setlocal cindent
let b:undo_indent = "setlocal cindent<"

View File

@@ -0,0 +1,53 @@
" Vim indent file
" Language: ChaiScript
" Maintainer: Jason Turner <lefticus 'at' gmail com>
" Last Change: 2022 Apr 06
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetChaiScriptIndent()
setlocal autoindent
let b:undo_indent = "setl ai< inde<"
" Only define the function once.
if exists("*GetChaiScriptIndent")
finish
endif
function! GetChaiScriptIndent()
" Find a non-blank line above the current line.
let lnum = prevnonblank(v:lnum - 1)
" Hit the start of the file, use zero indent.
if lnum == 0
return 0
endif
" Add a 'shiftwidth' after lines that start a block:
" lines containing a {
let ind = indent(lnum)
let flag = 0
let prevline = getline(lnum)
if prevline =~ '^.*{.*'
let ind = ind + shiftwidth()
let flag = 1
endif
" Subtract a 'shiftwidth' after lines containing a { followed by a }
" to keep it balanced
if flag == 1 && prevline =~ '.*{.*}.*'
let ind = ind - shiftwidth()
endif
" Subtract a 'shiftwidth' on lines ending with }
if getline(v:lnum) =~ '^\s*\%(}\)'
let ind = ind - shiftwidth()
endif
return ind
endfunction

View File

@@ -0,0 +1,14 @@
" Vim indent file
" Language: generic Changelog file
" Maintainer: noone
" Last Change: 2005 Mar 29
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal ai
let b:undo_indent = "setl ai<"

View File

@@ -0,0 +1,32 @@
" Vim indent file
" Language: Chatito
" Maintainer: ObserverOfTime <chronobserver@disroot.org>
" Last Change: 2022 Sep 20
if exists('b:did_indent')
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetChatitoIndent()
setlocal indentkeys=o,O,*<Return>,0#,!^F
let b:undo_indent = 'setl inde< indk<'
if exists('*GetChatitoIndent')
finish
endif
function GetChatitoIndent()
let l:prev = v:lnum - 1
if getline(prevnonblank(l:prev)) =~# '^[~%@]\['
" shift indent after definitions
return shiftwidth()
elseif getline(l:prev) !~# '^\s*$'
" maintain indent in sentences
return indent(l:prev)
else
" reset indent after a blank line
return 0
end
endfunction

View File

@@ -0,0 +1,427 @@
" Vim indent file
" Language: Clojure
" Maintainer: Alex Vear <alex@vear.uk>
" Former Maintainers: Sung Pae <self@sungpae.com>
" Meikel Brandmeyer <mb@kotka.de>
" URL: https://github.com/clojure-vim/clojure.vim
" License: Vim (see :h license)
" Last Change: 2022-03-24
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
let s:save_cpo = &cpo
set cpo&vim
let b:undo_indent = 'setlocal autoindent< smartindent< expandtab< softtabstop< shiftwidth< indentexpr< indentkeys<'
setlocal noautoindent nosmartindent
setlocal softtabstop=2 shiftwidth=2 expandtab
setlocal indentkeys=!,o,O
if exists("*searchpairpos")
if !exists('g:clojure_maxlines')
let g:clojure_maxlines = 300
endif
if !exists('g:clojure_fuzzy_indent')
let g:clojure_fuzzy_indent = 1
endif
if !exists('g:clojure_fuzzy_indent_patterns')
let g:clojure_fuzzy_indent_patterns = ['^with', '^def', '^let']
endif
if !exists('g:clojure_fuzzy_indent_blacklist')
let g:clojure_fuzzy_indent_blacklist = ['-fn$', '\v^with-%(meta|out-str|loading-context)$']
endif
if !exists('g:clojure_special_indent_words')
let g:clojure_special_indent_words = 'deftype,defrecord,reify,proxy,extend-type,extend-protocol,letfn'
endif
if !exists('g:clojure_align_multiline_strings')
let g:clojure_align_multiline_strings = 0
endif
if !exists('g:clojure_align_subforms')
let g:clojure_align_subforms = 0
endif
function! s:syn_id_name()
return synIDattr(synID(line("."), col("."), 0), "name")
endfunction
function! s:ignored_region()
return s:syn_id_name() =~? '\vstring|regex|comment|character'
endfunction
function! s:current_char()
return getline('.')[col('.')-1]
endfunction
function! s:current_word()
return getline('.')[col('.')-1 : searchpos('\v>', 'n', line('.'))[1]-2]
endfunction
function! s:is_paren()
return s:current_char() =~# '\v[\(\)\[\]\{\}]' && !s:ignored_region()
endfunction
" Returns 1 if string matches a pattern in 'patterns', which should be
" a list of patterns.
function! s:match_one(patterns, string)
for pat in a:patterns
if a:string =~# pat | return 1 | endif
endfor
endfunction
function! s:match_pairs(open, close, stopat)
" Stop only on vector and map [ resp. {. Ignore the ones in strings and
" comments.
if a:stopat == 0 && g:clojure_maxlines > 0
let stopat = max([line(".") - g:clojure_maxlines, 0])
else
let stopat = a:stopat
endif
let pos = searchpairpos(a:open, '', a:close, 'bWn', "!s:is_paren()", stopat)
return [pos[0], col(pos)]
endfunction
function! s:clojure_check_for_string_worker()
" Check whether there is the last character of the previous line is
" highlighted as a string. If so, we check whether it's a ". In this
" case we have to check also the previous character. The " might be the
" closing one. In case the we are still in the string, we search for the
" opening ". If this is not found we take the indent of the line.
let nb = prevnonblank(v:lnum - 1)
if nb == 0
return -1
endif
call cursor(nb, 0)
call cursor(0, col("$") - 1)
if s:syn_id_name() !~? "string"
return -1
endif
" This will not work for a " in the first column...
if s:current_char() == '"'
call cursor(0, col("$") - 2)
if s:syn_id_name() !~? "string"
return -1
endif
if s:current_char() != '\'
return -1
endif
call cursor(0, col("$") - 1)
endif
let p = searchpos('\(^\|[^\\]\)\zs"', 'bW')
if p != [0, 0]
return p[1] - 1
endif
return indent(".")
endfunction
function! s:check_for_string()
let pos = getpos('.')
try
let val = s:clojure_check_for_string_worker()
finally
call setpos('.', pos)
endtry
return val
endfunction
function! s:strip_namespace_and_macro_chars(word)
return substitute(a:word, "\\v%(.*/|[#'`~@^,]*)(.*)", '\1', '')
endfunction
function! s:clojure_is_method_special_case_worker(position)
" Find the next enclosing form.
call search('\S', 'Wb')
" Special case: we are at a '(('.
if s:current_char() == '('
return 0
endif
call cursor(a:position)
let next_paren = s:match_pairs('(', ')', 0)
" Special case: we are now at toplevel.
if next_paren == [0, 0]
return 0
endif
call cursor(next_paren)
call search('\S', 'W')
let w = s:strip_namespace_and_macro_chars(s:current_word())
if g:clojure_special_indent_words =~# '\V\<' . w . '\>'
" `letfn` is a special-special-case.
if w ==# 'letfn'
" Earlier code left the cursor at:
" (letfn [...] ...)
" ^
" Search and get coordinates of first `[`
" (letfn [...] ...)
" ^
call search('\[', 'W')
let pos = getcurpos()
let letfn_bracket = [pos[1], pos[2]]
" Move cursor to start of the form this function was
" initially called on. Grab the coordinates of the
" closest outer `[`.
call cursor(a:position)
let outer_bracket = s:match_pairs('\[', '\]', 0)
" If the located square brackets are not the same,
" don't use special-case formatting.
if outer_bracket != letfn_bracket
return 0
endif
endif
return 1
endif
return 0
endfunction
function! s:is_method_special_case(position)
let pos = getpos('.')
try
let val = s:clojure_is_method_special_case_worker(a:position)
finally
call setpos('.', pos)
endtry
return val
endfunction
" Check if form is a reader conditional, that is, it is prefixed by #?
" or #?@
function! s:is_reader_conditional_special_case(position)
return getline(a:position[0])[a:position[1] - 3 : a:position[1] - 2] == "#?"
\|| getline(a:position[0])[a:position[1] - 4 : a:position[1] - 2] == "#?@"
endfunction
" Returns 1 for opening brackets, -1 for _anything else_.
function! s:bracket_type(char)
return stridx('([{', a:char) > -1 ? 1 : -1
endfunction
" Returns: [opening-bracket-lnum, indent]
function! s:clojure_indent_pos()
" Get rid of special case.
if line(".") == 1
return [0, 0]
endif
" We have to apply some heuristics here to figure out, whether to use
" normal lisp indenting or not.
let i = s:check_for_string()
if i > -1
return [0, i + !!g:clojure_align_multiline_strings]
endif
call cursor(0, 1)
" Find the next enclosing [ or {. We can limit the second search
" to the line, where the [ was found. If no [ was there this is
" zero and we search for an enclosing {.
let paren = s:match_pairs('(', ')', 0)
let bracket = s:match_pairs('\[', '\]', paren[0])
let curly = s:match_pairs('{', '}', bracket[0])
" In case the curly brace is on a line later then the [ or - in
" case they are on the same line - in a higher column, we take the
" curly indent.
if curly[0] > bracket[0] || curly[1] > bracket[1]
if curly[0] > paren[0] || curly[1] > paren[1]
return curly
endif
endif
" If the curly was not chosen, we take the bracket indent - if
" there was one.
if bracket[0] > paren[0] || bracket[1] > paren[1]
return bracket
endif
" There are neither { nor [ nor (, ie. we are at the toplevel.
if paren == [0, 0]
return paren
endif
" Now we have to reimplement lispindent. This is surprisingly easy, as
" soon as one has access to syntax items.
"
" - Check whether we are in a special position after a word in
" g:clojure_special_indent_words. These are special cases.
" - Get the next keyword after the (.
" - If its first character is also a (, we have another sexp and align
" one column to the right of the unmatched (.
" - In case it is in lispwords, we indent the next line to the column of
" the ( + sw.
" - If not, we check whether it is last word in the line. In that case
" we again use ( + sw for indent.
" - In any other case we use the column of the end of the word + 2.
call cursor(paren)
if s:is_method_special_case(paren)
return [paren[0], paren[1] + &shiftwidth - 1]
endif
if s:is_reader_conditional_special_case(paren)
return paren
endif
" In case we are at the last character, we use the paren position.
if col("$") - 1 == paren[1]
return paren
endif
" In case after the paren is a whitespace, we search for the next word.
call cursor(0, col('.') + 1)
if s:current_char() == ' '
call search('\v\S', 'W')
endif
" If we moved to another line, there is no word after the (. We
" use the ( position for indent.
if line(".") > paren[0]
return paren
endif
" We still have to check, whether the keyword starts with a (, [ or {.
" In that case we use the ( position for indent.
let w = s:current_word()
if s:bracket_type(w[0]) == 1
return paren
endif
" If the keyword begins with #, check if it is an anonymous
" function or set, in which case we indent by the shiftwidth
" (minus one if g:clojure_align_subforms = 1), or if it is
" ignored, in which case we use the ( position for indent.
if w[0] == "#"
" TODO: Handle #=() and other rare reader invocations?
if w[1] == '(' || w[1] == '{'
return [paren[0], paren[1] + (g:clojure_align_subforms ? 0 : &shiftwidth - 1)]
elseif w[1] == '_'
return paren
endif
endif
" Test words without namespace qualifiers and leading reader macro
" metacharacters.
"
" e.g. clojure.core/defn and #'defn should both indent like defn.
let ww = s:strip_namespace_and_macro_chars(w)
if &lispwords =~# '\V\<' . ww . '\>'
return [paren[0], paren[1] + &shiftwidth - 1]
endif
if g:clojure_fuzzy_indent
\ && !s:match_one(g:clojure_fuzzy_indent_blacklist, ww)
\ && s:match_one(g:clojure_fuzzy_indent_patterns, ww)
return [paren[0], paren[1] + &shiftwidth - 1]
endif
call search('\v\_s', 'cW')
call search('\v\S', 'W')
if paren[0] < line(".")
return [paren[0], paren[1] + (g:clojure_align_subforms ? 0 : &shiftwidth - 1)]
endif
call search('\v\S', 'bW')
return [line('.'), col('.') + 1]
endfunction
function! GetClojureIndent()
let lnum = line('.')
let orig_lnum = lnum
let orig_col = col('.')
let [opening_lnum, indent] = s:clojure_indent_pos()
" Account for multibyte characters
if opening_lnum > 0
let indent -= indent - virtcol([opening_lnum, indent])
endif
" Return if there are no previous lines to inherit from
if opening_lnum < 1 || opening_lnum >= lnum - 1
call cursor(orig_lnum, orig_col)
return indent
endif
let bracket_count = 0
" Take the indent of the first previous non-white line that is
" at the same sexp level. cf. src/misc1.c:get_lisp_indent()
while 1
let lnum = prevnonblank(lnum - 1)
let col = 1
if lnum <= opening_lnum
break
endif
call cursor(lnum, col)
" Handle bracket counting edge case
if s:is_paren()
let bracket_count += s:bracket_type(s:current_char())
endif
while 1
if search('\v[(\[{}\])]', '', lnum) < 1
break
elseif !s:ignored_region()
let bracket_count += s:bracket_type(s:current_char())
endif
endwhile
if bracket_count == 0
" Check if this is part of a multiline string
call cursor(lnum, 1)
if s:syn_id_name() !~? '\vstring|regex'
call cursor(orig_lnum, orig_col)
return indent(lnum)
endif
endif
endwhile
call cursor(orig_lnum, orig_col)
return indent
endfunction
setlocal indentexpr=GetClojureIndent()
else
" In case we have searchpairpos not available we fall back to
" normal lisp indenting.
setlocal indentexpr=
setlocal lisp
let b:undo_indent .= '| setlocal lisp<'
endif
let &cpo = s:save_cpo
unlet! s:save_cpo
" vim:sts=8:sw=8:ts=8:noet

View File

@@ -0,0 +1,99 @@
" Vim indent file
" Language: CMake (ft=cmake)
" Author: Andy Cedilnik <andy.cedilnik@kitware.com>
" Maintainer: Dimitri Merejkowsky <d.merej@gmail.com>
" Former Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com>
" Last Change: 2023 Dec 12
"
" License: The CMake license applies to this file. See
" https://cmake.org/licensing
" This implies that distribution with Vim is allowed
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=CMakeGetIndent(v:lnum)
setlocal indentkeys+==ENDIF(,ENDFOREACH(,ENDMACRO(,ELSE(,ELSEIF(,ENDWHILE(
let b:undo_indent = "setl inde< indk<"
" Only define the function once.
if exists("*CMakeGetIndent")
finish
endif
let s:keepcpo= &cpo
set cpo&vim
fun! CMakeGetIndent(lnum)
let this_line = getline(a:lnum)
" Find a non-blank line above the current line.
let lnum = a:lnum
let lnum = prevnonblank(lnum - 1)
let previous_line = getline(lnum)
" Hit the start of the file, use zero indent.
if lnum == 0
return 0
endif
let ind = indent(lnum)
let or = '\|'
" Regular expressions used by line indentation function.
let cmake_regex_comment = '#.*'
let cmake_regex_identifier = '[A-Za-z][A-Za-z0-9_]*'
let cmake_regex_quoted = '"\([^"\\]\|\\.\)*"'
let cmake_regex_arguments = '\(' . cmake_regex_quoted .
\ or . '\$(' . cmake_regex_identifier . ')' .
\ or . '[^()\\#"]' . or . '\\.' . '\)*'
let cmake_indent_comment_line = '^\s*' . cmake_regex_comment
let cmake_indent_blank_regex = '^\s*$'
let cmake_indent_open_regex = '^\s*' . cmake_regex_identifier .
\ '\s*(' . cmake_regex_arguments .
\ '\(' . cmake_regex_comment . '\)\?$'
let cmake_indent_close_regex = '^' . cmake_regex_arguments .
\ ')\s*' .
\ '\(' . cmake_regex_comment . '\)\?$'
let cmake_closing_parens_line = '^\s*\()\+\)\s*$'
let cmake_indent_begin_regex = '^\s*\(BLOCK\|IF\|MACRO\|FOREACH\|ELSE\|ELSEIF\|WHILE\|FUNCTION\)\s*('
let cmake_indent_end_regex = '^\s*\(ENDBLOCK\|ENDIF\|ENDFOREACH\|ENDMACRO\|ELSE\|ELSEIF\|ENDWHILE\|ENDFUNCTION\)\s*('
if this_line =~? cmake_closing_parens_line
if previous_line !~? cmake_indent_open_regex
let ind = ind - shiftwidth()
endif
else
" Add
if previous_line =~? cmake_indent_comment_line " Handle comments
let ind = ind
else
if previous_line =~? cmake_indent_begin_regex
let ind = ind + shiftwidth()
endif
if previous_line =~? cmake_indent_open_regex
let ind = ind + shiftwidth()
endif
endif
" Subtract
if this_line =~? cmake_indent_end_regex
let ind = ind - shiftwidth()
endif
if previous_line !~? cmake_closing_parens_line
if previous_line =~? cmake_indent_close_regex
let ind = ind - shiftwidth()
endif
endif
endif
return ind
endfun
let &cpo = s:keepcpo
unlet s:keepcpo

View File

@@ -0,0 +1,226 @@
" Vim indent file
" Language: cobol
" Maintainer: Ankit Jain <ajatkj@yahoo.co.in>
" (formerly Tim Pope <vimNOSPAM@tpope.info>)
" $Id: cobol.vim,v 1.1 2007/05/05 18:08:19 vimboss Exp $
" Last Update: By Ankit Jain on 22.03.2019
" Ankit Jain 22.03.2019 Changes & fixes:
" Allow chars in 1st 6 columns
" #C22032019
" Ankit Jain 24.09.2021 add b:undo_indent (request by tpope)
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal expandtab
setlocal indentexpr=GetCobolIndent(v:lnum)
setlocal indentkeys&
setlocal indentkeys+=0<*>,0/,0$,0=01,=~division,=~section,0=~end,0=~then,0=~else,0=~when,*<Return>,.
let b:undo_indent = "setlocal expandtab< indentexpr< indentkeys<"
" Only define the function once.
if exists("*GetCobolIndent")
finish
endif
let s:skip = 'getline(".") =~ "^.\\{6\\}[*/$-]\\|\"[^\"]*\""'
function! s:prevgood(lnum)
" Find a non-blank line above the current line.
" Skip over comments.
let lnum = a:lnum
while lnum > 0
let lnum = prevnonblank(lnum - 1)
let line = getline(lnum)
if line !~? '^\s*[*/$-]' && line !~? '^.\{6\}[*/$CD-]'
break
endif
endwhile
return lnum
endfunction
function! s:stripped(lnum)
return substitute(strpart(getline(a:lnum),0,72),'^\s*','','')
endfunction
function! s:optionalblock(lnum,ind,blocks,clauses)
let ind = a:ind
let clauses = '\c\<\%(\<NOT\s\+\)\@<!\%(NOT\s\+\)\=\%('.a:clauses.'\)'
let begin = '\c-\@<!\<\%('.a:blocks.'\)\>'
let beginfull = begin.'\ze.*\%(\n\%(\s*\%([*/$-].*\)\=\n\)*\)\=\s*\%('.clauses.'\)'
let end = '\c\<end-\%('.a:blocks.'\)\>\|\%(\.\%( \|$\)\)\@='
let cline = s:stripped(a:lnum)
let line = s:stripped(s:prevgood(a:lnum))
if cline =~? clauses "&& line !~? '^search\>'
call cursor(a:lnum,1)
let lastclause = searchpair(beginfull,clauses,end,'bWr',s:skip)
if getline(lastclause) =~? clauses && s:stripped(lastclause) !~? '^'.begin
let ind = indent(lastclause)
elseif lastclause > 0
let ind = indent(lastclause) + shiftwidth()
"let ind = ind + shiftwidth()
endif
elseif line =~? clauses && cline !~? end
let ind = ind + shiftwidth()
endif
return ind
endfunction
function! GetCobolIndent(lnum) abort
let minshft = 6
let ashft = minshft + 1
let bshft = ashft + 4
" (Obsolete) numbered lines
" #C22032019: Columns 1-6 could have alphabets as well as numbers
"if getline(a:lnum) =~? '^\s*\d\{6\}\%($\|[ */$CD-]\)'
if getline(a:lnum) =~? '^\s*[a-zA-Z0-9]\{6\}\%($\|[ */$CD-]\)'
return 0
endif
let cline = s:stripped(a:lnum)
" Comments, etc. must start in the 7th column
if cline =~? '^[*/$-]'
return minshft
elseif cline =~# '^[CD]' && indent(a:lnum) == minshft
return minshft
endif
" Divisions, sections, and file descriptions start in area A
if cline =~? '\<\(DIVISION\|SECTION\)\%($\|\.\)' || cline =~? '^[FS]D\>'
return ashft
endif
" Fields
if cline =~? '^0*\(1\|77\)\>'
return ashft
endif
if cline =~? '^\d\+\>'
let cnum = matchstr(cline,'^\d\+\>')
let default = 0
let step = -1
while step < 2
let lnum = a:lnum
while lnum > 0 && lnum < line('$') && lnum > a:lnum - 500 && lnum < a:lnum + 500
let lnum = step > 0 ? nextnonblank(lnum + step) : prevnonblank(lnum + step)
let line = getline(lnum)
let lindent = indent(lnum)
if line =~? '^\s*\d\+\>'
let num = matchstr(line,'^\s*\zs\d\+\>')
if 0+cnum == num
return lindent
elseif 0+cnum > num && default < lindent + shiftwidth()
let default = lindent + shiftwidth()
endif
elseif lindent < bshft && lindent >= ashft
break
endif
endwhile
let step = step + 2
endwhile
return default ? default : bshft
endif
let lnum = s:prevgood(a:lnum)
" Hit the start of the file, use "zero" indent.
if lnum == 0
return ashft
endif
" Initial spaces are ignored
let line = s:stripped(lnum)
let ind = indent(lnum)
" Paragraphs. There may be some false positives.
if cline =~? '^\(\a[A-Z0-9-]*[A-Z0-9]\|\d[A-Z0-9-]*\a\)\.' "\s*$'
if cline !~? '^EXIT\s*\.' && line =~? '\.\s*$'
return ashft
endif
endif
" Paragraphs in the identification division.
"if cline =~? '^\(PROGRAM-ID\|AUTHOR\|INSTALLATION\|' .
"\ 'DATE-WRITTEN\|DATE-COMPILED\|SECURITY\)\>'
"return ashft
"endif
if line =~? '\.$'
" XXX
return bshft
endif
if line =~? '^PERFORM\>'
let perfline = substitute(line, '\c^PERFORM\s*', "", "")
if perfline =~? '^\%(\k\+\s\+TIMES\)\=\s*$'
let ind = ind + shiftwidth()
elseif perfline =~? '^\%(WITH\s\+TEST\|VARYING\|UNTIL\)\>.*[^.]$'
let ind = ind + shiftwidth()
endif
endif
if line =~? '^\%(IF\|THEN\|ELSE\|READ\|EVALUATE\|SEARCH\|SELECT\)\>'
let ind = ind + shiftwidth()
endif
let ind = s:optionalblock(a:lnum,ind,'ADD\|COMPUTE\|DIVIDE\|MULTIPLY\|SUBTRACT','ON\s\+SIZE\s\+ERROR')
let ind = s:optionalblock(a:lnum,ind,'STRING\|UNSTRING\|ACCEPT\|DISPLAY\|CALL','ON\s\+OVERFLOW\|ON\s\+EXCEPTION')
if cline !~? '^AT\s\+END\>' || line !~? '^SEARCH\>'
let ind = s:optionalblock(a:lnum,ind,'DELETE\|REWRITE\|START\|WRITE\|READ','INVALID\s\+KEY\|AT\s\+END\|NO\s\+DATA\|AT\s\+END-OF-PAGE')
endif
if cline =~? '^WHEN\>'
call cursor(a:lnum,1)
" We also search for READ so that contained AT ENDs are skipped
let lastclause = searchpair('\c-\@<!\<\%(SEARCH\|EVALUATE\|READ\)\>','\c\<\%(WHEN\|AT\s\+END\)\>','\c\<END-\%(SEARCH\|EVALUATE\|READ\)\>','bW',s:skip)
let g:foo = s:stripped(lastclause)
if s:stripped(lastclause) =~? '\c\<\%(WHEN\|AT\s\+END\)\>'
"&& s:stripped(lastclause) !~? '^\%(SEARCH\|EVALUATE\|READ\)\>'
let ind = indent(lastclause)
elseif lastclause > 0
let ind = indent(lastclause) + shiftwidth()
endif
elseif line =~? '^WHEN\>'
let ind = ind + shiftwidth()
endif
"I'm not sure why I had this
"if line =~? '^ELSE\>-\@!' && line !~? '\.$'
"let ind = indent(s:prevgood(lnum))
"endif
if cline =~? '^\(END\)\>-\@!'
" On lines with just END, 'guess' a simple shift left
let ind = ind - shiftwidth()
elseif cline =~? '^\(END-IF\|THEN\|ELSE\)\>-\@!'
call cursor(a:lnum,indent(a:lnum))
let match = searchpair('\c-\@<!\<IF\>','\c-\@<!\%(THEN\|ELSE\)\>','\c-\@<!\<END-IF\>\zs','bnW',s:skip)
if match > 0
let ind = indent(match)
endif
elseif cline =~? '^END-[A-Z]'
let beginword = matchstr(cline,'\c\<END-\zs[A-Z0-9-]\+')
let endword = 'END-'.beginword
let first = 0
let suffix = '.*\%(\n\%(\%(\s*\|.\{6\}\)[*/].*\n\)*\)\=\s*'
if beginword =~? '^\%(ADD\|COMPUTE\|DIVIDE\|MULTIPLY\|SUBTRACT\)$'
let beginword = beginword . suffix . '\<\%(NOT\s\+\)\=ON\s\+SIZE\s\+ERROR'
let g:beginword = beginword
let first = 1
elseif beginword =~? '^\%(STRING\|UNSTRING\)$'
let beginword = beginword . suffix . '\<\%(NOT\s\+\)\=ON\s\+OVERFLOW'
let first = 1
elseif beginword =~? '^\%(ACCEPT\|DISPLAY\)$'
let beginword = beginword . suffix . '\<\%(NOT\s\+\)\=ON\s\+EXCEPTION'
let first = 1
elseif beginword ==? 'CALL'
let beginword = beginword . suffix . '\<\%(NOT\s\+\)\=ON\s\+\%(EXCEPTION\|OVERFLOW\)'
let first = 1
elseif beginword =~? '^\%(DELETE\|REWRITE\|START\|READ\|WRITE\)$'
let first = 1
let beginword = beginword . suffix . '\<\%(NOT\s\+\)\=\(INVALID\s\+KEY'
if beginword =~? '^READ'
let first = 0
let beginword = beginword . '\|AT\s\+END\|NO\s\+DATA'
elseif beginword =~? '^WRITE'
let beginword = beginword . '\|AT\s\+END-OF-PAGE'
endif
let beginword = beginword . '\)'
endif
call cursor(a:lnum,indent(a:lnum))
let match = searchpair('\c-\@<!\<'.beginword.'\>','','\c\<'.endword.'\>\zs','bnW'.(first? 'r' : ''),s:skip)
if match > 0
let ind = indent(match)
elseif cline =~? '^\(END-\(READ\|EVALUATE\|SEARCH\|PERFORM\)\)\>'
let ind = ind - shiftwidth()
endif
endif
return ind < bshft ? bshft : ind
endfunction

View File

@@ -0,0 +1,85 @@
" Vim indent file
" Language: Autoconf configure.{ac,in} file
" Maintainer: Doug Kearns <dougkearns@gmail.com>
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
" Last Change: 24 Sep 2021
" TODO: how about nested [()]'s in one line what's wrong with '\\\@!'?
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
runtime! indent/sh.vim " will set b:did_indent
setlocal indentexpr=GetConfigIndent()
setlocal indentkeys=!^F,o,O,=then,=do,=else,=elif,=esac,=fi,=fin,=fil,=done
setlocal nosmartindent
let b:undo_indent = "setl inde< indk< si<"
" Only define the function once.
if exists("*GetConfigIndent")
finish
endif
" get the offset (indent) of the end of the match of 'regexp' in 'line'
function s:GetOffsetOf(line, regexp)
let end = matchend(a:line, a:regexp)
let width = 0
let i = 0
while i < end
if a:line[i] != "\t"
let width = width + 1
else
let width = width + &ts - (width % &ts)
endif
let i = i + 1
endwhile
return width
endfunction
function GetConfigIndent()
" Find a non-blank line above the current line.
let lnum = prevnonblank(v:lnum - 1)
" Hit the start of the file, use zero indent.
if lnum == 0
return 0
endif
" where to put this
let ind = GetShIndent()
let line = getline(lnum)
" if previous line has unmatched, unescaped opening parentheses,
" indent to its position. TODO: not failsafe if multiple ('s
if line =~ '\\\@<!([^)]*$'
let ind = s:GetOffsetOf(line, '\\\@!(')
endif
" if previous line has unmatched opening bracket,
" indent to its position. TODO: same as above
if line =~ '\[[^]]*$'
let ind = s:GetOffsetOf(line, '\[')
endif
" if previous line had an unmatched closing parentheses,
" indent to the matching opening parentheses
if line =~ '[^(]\+\\\@<!)$'
call search(')', 'bW')
let lnum = searchpair('\\\@<!(', '', ')', 'bWn')
let ind = indent(lnum)
endif
" if previous line had an unmatched closing bracket,
" indent to the matching opening bracket
if line =~ '[^[]\+]$'
call search(']', 'bW')
let lnum = searchpair('\[', '', ']', 'bWn')
let ind = indent(lnum)
endif
return ind
endfunction

View File

@@ -0,0 +1,65 @@
vim9script
# Language: ConTeXt typesetting engine
# Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
# Former Maintainers: Nikolai Weibull <now@bitwi.se>
# Latest Revision: 2023 Dec 26
if exists("b:did_indent")
finish
endif
# Load MetaPost indentation script (this will also set b:did_indent)
runtime! indent/mp.vim
setlocal indentexpr=ConTeXtIndent()
b:undo_indent = "setl indentexpr<"
def PrevNotComment(l: number): number
var prevlnum = prevnonblank(l)
while prevlnum > 0 && getline(prevlnum) =~# '^\s*%'
prevlnum = prevnonblank(prevlnum - 1)
endwhile
return prevlnum
enddef
def FindPair(pstart: string, pmid: string, pend: string): number
cursor(v:lnum, 1)
return indent(searchpair(pstart, pmid, pend, 'bWn',
'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"'))
enddef
def ConTeXtIndent(): number
# Use MetaPost rules inside MetaPost graphic environments
if len(synstack(v:lnum, 1)) > 0 &&
synIDattr(synstack(v:lnum, 1)[0], "name") ==# 'contextMPGraphic'
return g:MetaPostIndent()
endif
const prevlnum = PrevNotComment(v:lnum - 1)
const prevind = indent(prevlnum)
const prevline = getline(prevlnum)
const currline = getline(v:lnum)
# If the current line starts with ], match indentation.
if currline =~# '^\s*\]'
return FindPair('\[', '', '\]')
endif
# If the current line starts with }, match indentation.
if currline =~# '^\s*}'
return FindPair('{', '', '}')
endif
# If the previous line ends with [ or { (possibly followed by a comment) then indent.
if prevline =~# '[{[]\s*\%(%.*\)\=$'
return prevind + shiftwidth()
endif
return -1
enddef
# vim: sw=2 fdm=marker

View File

@@ -0,0 +1,16 @@
" Vim indent file
" Language: C++
" Maintainer: The Vim Project <https://github.com/vim/vim>
" Last Change: 2023 Aug 10
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" C++ indenting is built-in, thus this is very simple
setlocal cindent
let b:undo_indent = "setl cin<"

View File

@@ -0,0 +1,75 @@
" Vim indent file
" Language: C#
" Maintainer: Nick Jensen <nickspoon@gmail.com>
" Former Maintainers: Aquila Deus
" Johannes Zellner <johannes@zellner.org>
" Last Change: 2020-03-26
" License: Vim (see :h license)
" Repository: https://github.com/nickspoons/vim-cs
if exists('b:did_indent')
finish
endif
let b:did_indent = 1
let s:save_cpo = &cpoptions
set cpoptions&vim
setlocal indentexpr=GetCSIndent(v:lnum)
function! s:IsCompilerDirective(line)
" Exclude #region and #endregion - these should be indented normally
return a:line =~# '^\s*#' && !s:IsRegionDirective(a:line)
endf
function! s:IsRegionDirective(line)
return a:line =~# '^\s*#\s*region' || a:line =~# '^\s*#\s*endregion'
endf
function! s:IsAttributeLine(line)
return a:line =~# '^\s*\[[A-Za-z]' && a:line =~# '\]$'
endf
function! s:FindPreviousNonCompilerDirectiveLine(start_lnum)
for delta in range(0, a:start_lnum)
let lnum = a:start_lnum - delta
let line = getline(lnum)
if !s:IsCompilerDirective(line) && !s:IsRegionDirective(line)
return lnum
endif
endfor
return 0
endf
function! GetCSIndent(lnum) abort
" Hit the start of the file, use zero indent.
if a:lnum == 0
return 0
endif
let this_line = getline(a:lnum)
" Compiler directives use zero indent if so configured.
let is_first_col_macro = s:IsCompilerDirective(this_line) && stridx(&l:cinkeys, '0#') >= 0
if is_first_col_macro
return cindent(a:lnum)
endif
let lnum = s:FindPreviousNonCompilerDirectiveLine(a:lnum - 1)
let previous_code_line = getline(lnum)
if s:IsAttributeLine(previous_code_line)
return indent(lnum)
elseif s:IsRegionDirective(this_line)
return cindent(lnum)
else
return cindent(a:lnum)
endif
endfunction
let b:undo_indent = 'setlocal indentexpr<'
let &cpoptions = s:save_cpo
unlet s:save_cpo
" vim:et:sw=2:sts=2

View File

@@ -0,0 +1,86 @@
" Vim indent file
" Language: CSS
" Maintainer: Doug Kearns <dougkearns@gmail.com>
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
" Last Change: 24 Sep 2021
" Use of shiftwidth() added by Oleg Zubchenko.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetCSSIndent()
setlocal indentkeys=0{,0},!^F,o,O
setlocal nosmartindent
let b:undo_indent = "setl inde< indk< si<"
if exists("*GetCSSIndent")
finish
endif
let s:keepcpo= &cpo
set cpo&vim
function s:prevnonblanknoncomment(lnum)
let lnum = a:lnum
while lnum > 1
let lnum = prevnonblank(lnum)
let line = getline(lnum)
if line =~ '\*/'
while lnum > 1 && line !~ '/\*'
let lnum -= 1
endwhile
if line =~ '^\s*/\*'
let lnum -= 1
else
break
endif
else
break
endif
endwhile
return lnum
endfunction
function s:count_braces(lnum, count_open)
let n_open = 0
let n_close = 0
let line = getline(a:lnum)
let pattern = '[{}]'
let i = match(line, pattern)
while i != -1
if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'css\%(Comment\|StringQ\{1,2}\)'
if line[i] == '{'
let n_open += 1
elseif line[i] == '}'
if n_open > 0
let n_open -= 1
else
let n_close += 1
endif
endif
endif
let i = match(line, pattern, i + 1)
endwhile
return a:count_open ? n_open : n_close
endfunction
function GetCSSIndent()
let line = getline(v:lnum)
if line =~ '^\s*\*'
return cindent(v:lnum)
endif
let pnum = s:prevnonblanknoncomment(v:lnum - 1)
if pnum == 0
return 0
endif
return indent(pnum) + s:count_braces(pnum, 1) * shiftwidth()
\ - s:count_braces(v:lnum, 0) * shiftwidth()
endfunction
let &cpo = s:keepcpo
unlet s:keepcpo

View File

@@ -0,0 +1,98 @@
" Vim indent file
" Language: Cucumber
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Last Change: 2023 Dec 28
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal autoindent
setlocal indentexpr=GetCucumberIndent()
setlocal indentkeys=o,O,*<Return>,<:>,0<Bar>,0#,=,!^F
let b:undo_indent = 'setl ai< inde< indk<'
" Only define the function once.
if exists("*GetCucumberIndent")
finish
endif
let s:headings = {
\ 'Feature': 'feature',
\ 'Rule': 'rule',
\ 'Background': 'bg_or_scenario',
\ 'Scenario': 'bg_or_scenario',
\ 'ScenarioOutline': 'bg_or_scenario',
\ 'Examples': 'examples',
\ 'Scenarios': 'examples'}
function! s:Line(lnum) abort
if getline(a:lnum) =~# ':'
let group = matchstr(synIDattr(synID(a:lnum,1+indent(a:lnum), 1), 'name'), '^cucumber\zs.*')
if !has_key(s:headings, group)
let group = substitute(matchstr(getline(a:lnum), '^\s*\zs\%([^:]\+\)\ze:\S\@!'), '\s\+', '', 'g')
endif
else
let group = ''
endif
let char = matchstr(getline(a:lnum), '^\s*\zs[[:punct:]]')
return {
\ 'lnum': a:lnum,
\ 'indent': indent(a:lnum),
\ 'heading': get(s:headings, group, ''),
\ 'tag': char ==# '@',
\ 'table': char ==# '|',
\ 'comment': char ==# '#',
\ }
endfunction
function! GetCucumberIndent(...) abort
let lnum = a:0 ? a:1 : v:lnum
let sw = shiftwidth()
let prev = s:Line(prevnonblank(lnum-1))
let curr = s:Line(lnum)
let next = s:Line(nextnonblank(lnum+1))
if curr.heading ==# 'feature'
" feature heading
return 0
elseif curr.heading ==# 'examples'
" examples heading
return 2 * sw
elseif curr.heading ==# 'bg_or_scenario'
" background, scenario or outline heading
return sw
elseif prev.heading ==# 'feature'
" line after feature heading
return sw
elseif prev.heading ==# 'examples'
" line after examples heading
return 3 * sw
elseif prev.heading ==# 'bg_or_scenario'
" line after background, scenario or outline heading
return 2 * sw
elseif (curr.tag || curr.comment) && (next.heading ==# 'feature' || prev.indent <= 0)
" tag or comment before a feature heading
return 0
elseif curr.tag
" other tags
return sw
elseif (curr.table || curr.comment) && prev.table
" mid-table
" preserve indent
return prev.indent
elseif curr.table && !prev.table
" first line of a table, relative indent
return prev.indent + sw
elseif !curr.table && prev.table
" line after a table, relative unindent
return prev.indent - sw
elseif curr.comment && getline(v:lnum-1) =~# '^\s*$' && next.heading ==# 'bg_or_scenario'
" comments on scenarios
return sw
endif
return prev.indent < 0 ? 0 : prev.indent
endfunction
" vim:set sts=2 sw=2:

View File

@@ -0,0 +1,16 @@
" Vim indent file
" Language: CUDA
" Maintainer: The Vim Project <https://github.com/vim/vim>
" Last Change: 2023 Aug 10
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" It's just like C indenting
setlocal cindent
let b:undo_indent = "setl cin<"

View File

@@ -0,0 +1,24 @@
" Vim indent file for the D programming language (version 0.137).
" Language: D
" Maintainer: Jason Mills <jmills@cs.mun.ca> (Invalid email address)
" Doug Kearns <dougkearns@gmail.com>
" Last Change: 2022 Apr 06
" Version: 0.1
"
" Please email me with bugs, comments, and suggestion. Put vim in the subject
" to ensure the email will not be marked has spam.
"
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" D indenting is a lot like the built-in C indenting.
setlocal cindent
let b:undo_indent = "setl cin<"
" vim: ts=8 noet

View File

@@ -0,0 +1,15 @@
" Vim indent file
" Language: dict(1) configuration file
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
" Last Change: 2022 Apr 06
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentkeys=0{,0},!^F,o,O cinwords= autoindent smartindent
setlocal nosmartindent
inoremap <buffer> # X#
let b:undo_indent = "setl ai< cinw< indk< si< | silent! iunmap <buffer> #"

View File

@@ -0,0 +1,15 @@
" Vim indent file
" Language: dictd(8) configuration file
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
" Latest Revision: 2006-12-20
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentkeys=0{,0},!^F,o,O cinwords= autoindent smartindent
setlocal nosmartindent
inoremap <buffer> # X#
let b:undo_indent = "setl ai< cinw< indk< si< | silent! iunmap <buffer> #"

View File

@@ -0,0 +1,15 @@
" Vim indent file
" Language: DocBook Documentation Format
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
" Latest Revision: 2006-04-19
if exists("b:did_indent")
finish
endif
" Same as XML indenting for now.
runtime! indent/xml.vim
if exists('*XmlIndentGet')
setlocal indentexpr=XmlIndentGet(v:lnum,0)
endif

View File

@@ -0,0 +1,61 @@
" 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: 2021-10-18
" 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=)
let b:undo_indent = "setl ai< inde< indk< si<"
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

View File

@@ -0,0 +1,334 @@
" Vim indent file
" Language: DTD (Document Type Definition for XML)
" Maintainer: Doug Kearns <dougkearns@gmail.com>
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
" Last Change: 24 Sep 2021
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetDTDIndent()
setlocal indentkeys=!^F,o,O,>
setlocal nosmartindent
let b:undo_indent = "setl inde< indk< si<"
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:]]\+'
function s:lex1(input, start, ...)
let pattern = a:0 > 0 ? a:1 : s:token_pattern
let start = matchend(a:input, '^\_s*', a:start)
if start == -1
return ["", a:start]
endif
let end = matchend(a:input, pattern, start)
if end == -1
return ["", a:start]
endif
let token = strpart(a:input, start, end - start)
return [token, end]
endfunction
function s:lex(input, start, ...)
let pattern = a:0 > 0 ? a:1 : s:token_pattern
let info = s:lex1(a:input, a:start, pattern)
while info[0] == '--'
let info = s:lex1(a:input, info[1], pattern)
while info[0] != "" && info[0] != '--'
let info = s:lex1(a:input, info[1], pattern)
endwhile
if info[0] == ""
return info
endif
let info = s:lex1(a:input, info[1], pattern)
endwhile
return info
endfunction
function s:indent_to_innermost_parentheses(line, end)
let token = '('
let end = a:end
let parentheses = [end - 1]
while token != ""
let [token, end] = s:lex(a:line, end, '^\%([(),|]\|[A-Za-z0-9_-]\+\|#P\=CDATA\|%[A-Za-z0-9_-]\+;\)[?*+]\=')
if token[0] == '('
call add(parentheses, end - 1)
elseif token[0] == ')'
if len(parentheses) == 1
return [-1, end]
endif
call remove(parentheses, -1)
endif
endwhile
return [parentheses[-1] - strridx(a:line, "\n", parentheses[-1]), end]
endfunction
" TODO: Line and end could be script global (think OO members).
function GetDTDIndent()
if v:lnum == 1
return 0
endif
" Begin by searching back for a <! that isnt inside a comment.
" From here, depending on what follows immediately after, parse to
" where were at to determine what to do.
if search('<!', 'bceW') == 0
return indent(v:lnum - 1)
endif
let lnum = line('.')
let col = col('.')
let indent = indent('.')
let line = lnum == v:lnum ? getline(lnum) : join(getline(lnum, v:lnum - 1), "\n")
let [declaration, end] = s:lex1(line, col)
if declaration == ""
return indent + shiftwidth()
elseif declaration == '--'
" Were looking at a comment. Now, simply determine if the comment is
" terminated or not. If it isnt, let Vim take care of that using
" 'comments' and 'autoindent'. Otherwise, indent to the first lines level.
while declaration != ""
let [declaration, end] = s:lex(line, end)
if declaration == "-->"
return indent
endif
endwhile
return -1
elseif declaration == 'ELEMENT'
" Check for element name. If none exists, indent one level.
let [name, end] = s:lex(line, end)
if name == ""
return indent + shiftwidth()
endif
" Check for token following element name. This can be a specification of
" whether the start or end tag may be omitted. If nothing is found, indent
" one level.
let [token, end] = s:lex(line, end, '^\%([-O(]\|ANY\|EMPTY\)')
let n = 0
while token =~ '[-O]' && n < 2
let [token, end] = s:lex(line, end, '^\%([-O(]\|ANY\|EMPTY\)')
let n += 1
endwhile
if token == ""
return indent + shiftwidth()
endif
" Next comes the content model. If the token weve found isnt a
" parenthesis it must be either ANY, EMPTY or some random junk. Either
" way, were done indenting this element, so set it to that of the first
" line so that the terminating “>” winds up having the same indentation.
if token != '('
return indent
endif
" Now go through the content model. We need to keep track of the nesting
" of parentheses. As soon as we hit 0 were done. If that happens we must
" have a complete content model. Thus set indentation to be the same as that
" of the first line so that the terminating “>” winds up having the same
" indentation. Otherwise, well indent to the innermost parentheses not yet
" matched.
let [indent_of_innermost, end] = s:indent_to_innermost_parentheses(line, end)
if indent_of_innermost != -1
return indent_of_innermost
endif
" Finally, look for any additions and/or exceptions to the content model.
" This is defined by a “+” or “-” followed by another content model
" declaration.
" TODO: Can the “-” be separated by whitespace from the “(”?
let seen = { '+(': 0, '-(': 0 }
while 1
let [additions_exceptions, end] = s:lex(line, end, '^[+-](')
if additions_exceptions != '+(' && additions_exceptions != '-('
let [token, end] = s:lex(line, end)
if token == '>'
return indent
endif
" TODO: Should use s:lex here on getline(v:lnum) and check for >.
return getline(v:lnum) =~ '^\s*>' || count(values(seen), 0) == 0 ? indent : (indent + shiftwidth())
endif
" If weve seen an addition or exception already and this is of the same
" kind, the user is writing a broken DTD. Time to bail.
if seen[additions_exceptions]
return indent
endif
let seen[additions_exceptions] = 1
let [indent_of_innermost, end] = s:indent_to_innermost_parentheses(line, end)
if indent_of_innermost != -1
return indent_of_innermost
endif
endwhile
elseif declaration == 'ATTLIST'
" Check for element name. If none exists, indent one level.
let [name, end] = s:lex(line, end)
if name == ""
return indent + shiftwidth()
endif
" Check for any number of attributes.
while 1
" Check for attribute name. If none exists, indent one level, unless the
" current line is a lone “>”, in which case we indent to the same level
" as the first line. Otherwise, if the attribute name is “>”, we have
" actually hit the end of the attribute list, in which case we indent to
" the same level as the first line.
let [name, end] = s:lex(line, end)
if name == ""
" TODO: Should use s:lex here on getline(v:lnum) and check for >.
return getline(v:lnum) =~ '^\s*>' ? indent : (indent + shiftwidth())
elseif name == ">"
return indent
endif
" Check for attribute value declaration. If none exists, indent two
" levels. Otherwise, if its an enumerated value, check for nested
" parentheses and indent to the innermost one if we dont reach the end
" of the listc. Otherwise, just continue with looking for the default
" attribute value.
" TODO: Do validation of keywords
" (CDATA|NMTOKEN|NMTOKENS|ID|IDREF|IDREFS|ENTITY|ENTITIES)?
let [value, end] = s:lex(line, end, '^\%((\|[^[:space:]]\+\)')
if value == ""
return indent + shiftwidth() * 2
elseif value == 'NOTATION'
" If this is a enumerated value based on notations, read another token
" for the actual value. If it doesnt exist, indent three levels.
" TODO: If validating according to above, value must be equal to '('.
let [value, end] = s:lex(line, end, '^\%((\|[^[:space:]]\+\)')
if value == ""
return indent + shiftwidth() * 3
endif
endif
if value == '('
let [indent_of_innermost, end] = s:indent_to_innermost_parentheses(line, end)
if indent_of_innermost != -1
return indent_of_innermost
endif
endif
" Finally look for the attributes default value. If non exists, indent
" two levels.
let [default, end] = s:lex(line, end, '^\%("\_[^"]*"\|#\(REQUIRED\|IMPLIED\|FIXED\)\)')
if default == ""
return indent + shiftwidth() * 2
elseif default == '#FIXED'
" We need to look for the fixed value. If non exists, indent three
" levels.
let [default, end] = s:lex(line, end, '^"\_[^"]*"')
if default == ""
return indent + shiftwidth() * 3
endif
endif
endwhile
elseif declaration == 'ENTITY'
" Check for entity name. If none exists, indent one level. Otherwise, if
" the name actually turns out to be a percent sign, “%”, this is a
" parameter entity. Read another token to determine the entity name and,
" again, if none exists, indent one level.
let [name, end] = s:lex(line, end)
if name == ""
return indent + shiftwidth()
elseif name == '%'
let [name, end] = s:lex(line, end)
if name == ""
return indent + shiftwidth()
endif
endif
" Now check for the entity value. If none exists, indent one level. If it
" does exist, indent to same level as first line, as were now done with
" this entity.
"
" The entity value can be a string in single or double quotes (no escapes
" to worry about, as entities are used instead). However, it can also be
" that this is an external unparsed entity. In that case we have to look
" further for (possibly) a public ID and an URI followed by the NDATA
" keyword and the actual notation name. For the public ID and URI, indent
" two levels, if they dont exist. If the NDATA keyword doesnt exist,
" indent one level. Otherwise, if the actual notation name doesnt exist,
" indent two level. If it does, indent to same level as first line, as
" were now done with this entity.
let [value, end] = s:lex(line, end)
if value == ""
return indent + shiftwidth()
elseif value == 'SYSTEM' || value == 'PUBLIC'
let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\)')
if quoted_string == ""
return indent + shiftwidth() * 2
endif
if value == 'PUBLIC'
let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\)')
if quoted_string == ""
return indent + shiftwidth() * 2
endif
endif
let [ndata, end] = s:lex(line, end)
if ndata == ""
return indent + shiftwidth()
endif
let [name, end] = s:lex(line, end)
return name == "" ? (indent + shiftwidth() * 2) : indent
else
return indent
endif
elseif declaration == 'NOTATION'
" Check for notation name. If none exists, indent one level.
let [name, end] = s:lex(line, end)
if name == ""
return indent + shiftwidth()
endif
" Now check for the external ID. If none exists, indent one level.
let [id, end] = s:lex(line, end)
if id == ""
return indent + shiftwidth()
elseif id == 'SYSTEM' || id == 'PUBLIC'
let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\)')
if quoted_string == ""
return indent + shiftwidth() * 2
endif
if id == 'PUBLIC'
let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\|>\)')
if quoted_string == ""
" TODO: Should use s:lex here on getline(v:lnum) and check for >.
return getline(v:lnum) =~ '^\s*>' ? indent : (indent + shiftwidth() * 2)
elseif quoted_string == '>'
return indent
endif
endif
endif
return indent
endif
" TODO: Processing directives could be indented I suppose. But perhaps its
" just as well to let the user decide how to indent them (perhaps extending
" this function to include proper support for whatever processing directive
" language they want to use).
" Conditional sections are simply passed along to let Vim decide what to do
" (and hence the user).
return -1
endfunction
let &cpo = s:cpo_save
unlet s:cpo_save

View File

@@ -0,0 +1,17 @@
" Vim indent file
" Language: D script as described in "Solaris Dynamic Tracing Guide",
" http://docs.sun.com/app/docs/doc/817-6223
" Last Change: 2008/03/20
" Version: 1.2
" Maintainer: Nicolas Weber <nicolasweber@gmx.de>
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" Built-in C indenting works nicely for dtrace.
setlocal cindent
let b:undo_indent = "setl cin<"

View File

@@ -0,0 +1,63 @@
" Vim indent file
" Language: Device Tree
" Maintainer: Roland Hieber, Pengutronix <rhi@pengutronix.de>
"
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal autoindent
setlocal nosmartindent
setlocal indentkeys=o,O,0},0<>>,!<Ctrl-F>
setlocal indentexpr=GetDTSIndent()
setlocal nolisp
let b:undo_indent = 'setl autoindent< smartindent< indentkeys< indentexpr< lisp<'
function GetDTSIndent()
let sw = shiftwidth()
let lnum = v:lnum
let line = getline(lnum)
let prevline = getline(prevnonblank(lnum-1))
let prevind = indent(prevnonblank(lnum-1))
if prevnonblank(lnum-1) < 1
return 0
endif
" Don't indent header and preprocessor directives
if line =~ '^\s*\(/dts-\|#\(include\|define\|undef\|warn\(ing\)\?\|error\|if\(n\?def\)\?\|else\|elif\|endif\)\)'
return 0
" Don't indent /node and &label blocks
elseif line =~ '^\s*[/&].\+{\s*$'
return 0
" Indent to matching bracket or remove one shiftwidth if line begins with } or >
elseif line =~ '^\s*[}>]'
" set cursor to closing bracket on current line
let col = matchend(line, '^\s*[>}]')
call cursor(lnum, col)
" determine bracket type, {} or <>
let pair = strpart('{}<>', stridx('}>', line[col-1]) * 2, 2)
" find matching bracket pair
let pairline = searchpair(pair[0], '', pair[1], 'bW')
if pairline > 0
return indent(pairline)
else
return prevind - sw
endif
" else, add one level of indent if line ends in { or < or = or ,
elseif prevline =~ '[{<=,]$'
return prevind + sw
else
return prevind
endif
endfunction

View File

@@ -0,0 +1,16 @@
" Vim indent file
" Language: dune
" Maintainers: Markus Mottl <markus.mottl@gmail.com>
" URL: https://github.com/ocaml/vim-ocaml
" Last Change: 2021 Jan 01
" 2023 Aug 28 by Vim Project (undo_indent)
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" dune format-dune-file uses 1 space to indent
setlocal softtabstop=1 shiftwidth=1 expandtab
let b:undo_indent = "setl et< sts< sw<"

View File

@@ -0,0 +1,94 @@
" Vim indent file
" Language: Dylan
" Maintainer: Brent A. Fulgham <bfulgham@debian.org> (Invalid email address)
" Doug Kearns <dougkearns@gmail.com>
" Version: 0.01
" Last Change: 2022 Apr 06
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentkeys+==~begin,=~block,=~case,=~cleanup,=~define,=~end,=~else,=~elseif,=~exception,=~for,=~finally,=~if,=~otherwise,=~select,=~unless,=~while
" Define the appropriate indent function but only once
setlocal indentexpr=DylanGetIndent()
let b:undo_indent = "setl inde< indk<"
if exists("*DylanGetIndent")
finish
endif
function DylanGetIndent()
" Get the line to be indented
let cline = getline(v:lnum)
" Don't reindent comments on first column
if cline =~ '^/\[/\*]'
return 0
endif
"Find the previous non-blank line
let lnum = prevnonblank(v:lnum - 1)
"Use zero indent at the top of the file
if lnum == 0
return 0
endif
let prevline=getline(lnum)
let ind = indent(lnum)
let chg = 0
" If previous line was a comment, use its indent
if prevline =~ '^\s*//'
return ind
endif
" If previous line was a 'define', indent
if prevline =~? '\(^\s*\(begin\|block\|case\|define\|else\|elseif\|for\|finally\|if\|select\|unless\|while\)\|\s*\S*\s*=>$\)'
let chg = shiftwidth()
" local methods indent the shift-width, plus 6 for the 'local'
elseif prevline =~? '^\s*local'
let chg = shiftwidth() + 6
" If previous line was a let with no closing semicolon, indent
elseif prevline =~? '^\s*let.*[^;]\s*$'
let chg = shiftwidth()
" If previous line opened a parenthesis, and did not close it, indent
elseif prevline =~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
return = match( prevline, '(.*\((.*)\|[^)]\)*.*$') + 1
"elseif prevline =~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
elseif prevline =~ '^[^(]*)\s*$'
" This line closes a parenthesis. Find opening
let curr_line = prevnonblank(lnum - 1)
while curr_line >= 0
let str = getline(curr_line)
if str !~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
let curr_line = prevnonblank(curr_line - 1)
else
break
endif
endwhile
if curr_line < 0
return -1
endif
let ind = indent(curr_line)
" Although we found the closing parenthesis, make sure this
" line doesn't start with an indentable command:
let curr_str = getline(curr_line)
if curr_str =~? '^\s*\(begin\|block\|case\|define\|else\|elseif\|for\|finally\|if\|select\|unless\|while\)'
let chg = shiftwidth()
endif
endif
" If a line starts with end, un-indent (even if we just indented!)
if cline =~? '^\s*\(cleanup\|end\|else\|elseif\|exception\|finally\|otherwise\)'
let chg = chg - shiftwidth()
endif
return ind + chg
endfunction
" vim:sw=2 tw=130

View File

@@ -0,0 +1,115 @@
" Vim indent file
" Language: Eiffel
" Maintainer: Jocelyn Fiat <jfiat@eiffel.com>
" Previous-Maintainer: David Clarke <gadicath@dishevelled.net>
" Contributions from: Takuya Fujiwara
" Contributions from: Thilo Six
" $Date: 2017/03/08 06:00:00 $
" $Revision: 1.4 $
" URL: https://github.com/eiffelhub/vim-eiffel
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetEiffelIndent()
setlocal nolisp
setlocal nosmartindent
setlocal nocindent
setlocal autoindent
setlocal comments=:--
setlocal indentkeys+==end,=else,=ensure,=require,=check,=loop,=until
setlocal indentkeys+==creation,=feature,=inherit,=class,=is,=redefine,=rename,=variant
setlocal indentkeys+==invariant,=do,=local,=export
let b:undo_indent = "setl smartindent< indentkeys< indentexpr< autoindent< comments< "
" Define some stuff
" keywords grouped by indenting
let s:trust_user_indent = '\(+\)\(\s*\(--\).*\)\=$'
let s:relative_indent = '^\s*\(deferred\|class\|feature\|creation\|inherit\|loop\|from\|across\|until\|if\|else\|elseif\|ensure\|require\|check\|do\|local\|invariant\|variant\|rename\|redefine\|do\|export\)\>'
let s:outdent = '^\s*\(else\|invariant\|variant\|do\|require\|until\|loop\|local\)\>'
let s:no_indent = '^\s*\(class\|feature\|creation\|inherit\)\>'
let s:single_dent = '^[^-]\+[[:alnum:]]\+ is\(\s*\(--\).*\)\=$'
let s:inheritance_dent = '\s*\(redefine\|rename\|export\)\>'
" Only define the function once.
if exists("*GetEiffelIndent")
finish
endif
let s:keepcpo= &cpo
set cpo&vim
function GetEiffelIndent()
" Eiffel Class indenting
"
" Find a non-blank line above the current line.
let lnum = prevnonblank(v:lnum - 1)
" At the start of the file use zero indent.
if lnum == 0
return 0
endif
" trust the user's indenting
if getline(lnum) =~ s:trust_user_indent
return -1
endif
" Add a 'shiftwidth' after lines that start with an indent word
let ind = indent(lnum)
if getline(lnum) =~ s:relative_indent
let ind = ind + shiftwidth()
endif
" Indent to single indent
if getline(v:lnum) =~ s:single_dent && getline(v:lnum) !~ s:relative_indent
\ && getline(v:lnum) !~ '\s*\<\(and\|or\|implies\)\>'
let ind = shiftwidth()
endif
" Indent to double indent
if getline(v:lnum) =~ s:inheritance_dent
let ind = 2 * shiftwidth()
endif
" Indent line after the first line of the function definition
if getline(lnum) =~ s:single_dent
let ind = ind + shiftwidth()
endif
" The following should always be at the start of a line, no indenting
if getline(v:lnum) =~ s:no_indent
let ind = 0
endif
" Subtract a 'shiftwidth', if this isn't the first thing after the 'is'
" or first thing after the 'do'
if getline(v:lnum) =~ s:outdent && getline(v:lnum - 1) !~ s:single_dent
\ && getline(v:lnum - 1) !~ '^\s*do\>'
let ind = ind - shiftwidth()
endif
" Subtract a shiftwidth for end statements
if getline(v:lnum) =~ '^\s*end\>'
let ind = ind - shiftwidth()
endif
" set indent of zero end statements that are at an indent of 3, this should
" only ever be the class's end.
if getline(v:lnum) =~ '^\s*end\>' && ind == shiftwidth()
let ind = 0
endif
return ind
endfunction
let &cpo = s:keepcpo
unlet s:keepcpo
" vim:sw=2

View File

@@ -0,0 +1,116 @@
" Elm indent plugin file
" Language: Elm
" Maintainer: Andreas Scharf <as@99n.de>
" Original Author: Joseph Hager <ajhager@gmail.com>
" Copyright: Joseph Hager <ajhager@gmail.com>
" License: BSD3
" Latest Revision: 2021-09-29
" Only load this indent file when no other was loaded.
if exists('b:did_indent')
finish
endif
let b:did_indent = 1
" Local defaults
setlocal expandtab
setlocal indentexpr=GetElmIndent()
setlocal indentkeys+=0=else,0=if,0=of,0=import,0=then,0=type,0\|,0},0\],0),=-},0=in
setlocal nolisp
setlocal nosmartindent
let b:undo_indent = "setl et< inde< indk< lisp< si<"
" Only define the function once.
if exists('*GetElmIndent')
finish
endif
" Indent pairs
function! s:FindPair(pstart, pmid, pend)
"call search(a:pend, 'bW')
return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"'))
endfunction
function! GetElmIndent()
let l:lnum = v:lnum - 1
" Ident 0 if the first line of the file:
if l:lnum == 0
return 0
endif
let l:ind = indent(l:lnum)
let l:lline = getline(l:lnum)
let l:line = getline(v:lnum)
" Indent if current line begins with '}':
if l:line =~? '^\s*}'
return s:FindPair('{', '', '}')
" Indent if current line begins with 'else':
elseif l:line =~# '^\s*else\>'
if l:lline !~# '^\s*\(if\|then\)\>'
return s:FindPair('\<if\>', '', '\<else\>')
endif
" Indent if current line begins with 'then':
elseif l:line =~# '^\s*then\>'
if l:lline !~# '^\s*\(if\|else\)\>'
return s:FindPair('\<if\>', '', '\<then\>')
endif
" HACK: Indent lines in case with nearest case clause:
elseif l:line =~# '->' && l:line !~# ':' && l:line !~# '\\'
return indent(search('^\s*case', 'bWn')) + &shiftwidth
" HACK: Don't change the indentation if the last line is a comment.
elseif l:lline =~# '^\s*--'
return l:ind
" Align the end of block comments with the start
elseif l:line =~# '^\s*-}'
return indent(search('{-', 'bWn'))
" Indent double shift after let with an empty rhs
elseif l:lline =~# '\<let\>.*\s=$'
return l:ind + 4 + &shiftwidth
" Align 'in' with the parent let.
elseif l:line =~# '^\s*in\>'
return indent(search('^\s*let', 'bWn'))
" Align bindings with the parent let.
elseif l:lline =~# '\<let\>'
return l:ind + 4
" Align bindings with the parent in.
elseif l:lline =~# '^\s*in\>'
return l:ind
endif
" Add a 'shiftwidth' after lines ending with:
if l:lline =~# '\(|\|=\|->\|<-\|(\|\[\|{\|\<\(of\|else\|if\|then\)\)\s*$'
let l:ind = l:ind + &shiftwidth
" Add a 'shiftwidth' after lines starting with type ending with '=':
elseif l:lline =~# '^\s*type' && l:line =~# '^\s*='
let l:ind = l:ind + &shiftwidth
" Back to normal indent after comments:
elseif l:lline =~# '-}\s*$'
call search('-}', 'bW')
let l:ind = indent(searchpair('{-', '', '-}', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"'))
" Ident some operators if there aren't any starting the last line.
elseif l:line =~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l:lline !~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l:lline !~# '^\s*$'
let l:ind = l:ind + &shiftwidth
elseif l:lline ==# '' && getline(l:lnum - 1) !=# ''
let l:ind = indent(search('^\s*\S+', 'bWn'))
endif
return l:ind
endfunc

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,111 @@
" Vim indent file
" Language: eRuby
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" URL: https://github.com/vim-ruby/vim-ruby
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
" Last Change: 2019 Jan 06
if exists("b:did_indent")
finish
endif
runtime! indent/ruby.vim
unlet! b:did_indent
setlocal indentexpr=
if exists("b:eruby_subtype") && b:eruby_subtype != '' && b:eruby_subtype !=# 'eruby'
exe "runtime! indent/".b:eruby_subtype.".vim"
else
runtime! indent/html.vim
endif
unlet! b:did_indent
" Force HTML indent to not keep state.
let b:html_indent_usestate = 0
if &l:indentexpr == ''
if &l:cindent
let &l:indentexpr = 'cindent(v:lnum)'
else
let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))'
endif
endif
let b:eruby_subtype_indentexpr = &l:indentexpr
let b:did_indent = 1
setlocal indentexpr=GetErubyIndent()
setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when
" Only define the function once.
if exists("*GetErubyIndent")
finish
endif
" this file uses line continuations
let s:cpo_sav = &cpo
set cpo&vim
function! GetErubyIndent(...)
" The value of a single shift-width
if exists('*shiftwidth')
let sw = shiftwidth()
else
let sw = &sw
endif
if a:0 && a:1 == '.'
let v:lnum = line('.')
elseif a:0 && a:1 =~ '^\d'
let v:lnum = a:1
endif
let vcol = col('.')
call cursor(v:lnum,1)
let inruby = searchpair('<%','','%>','W')
call cursor(v:lnum,vcol)
if inruby && getline(v:lnum) !~ '^<%\|^\s*[-=]\=%>'
let ind = GetRubyIndent(v:lnum)
else
exe "let ind = ".b:eruby_subtype_indentexpr
" Workaround for Andy Wokula's HTML indent. This should be removed after
" some time, since the newest version is fixed in a different way.
if b:eruby_subtype_indentexpr =~# '^HtmlIndent('
\ && exists('b:indent')
\ && type(b:indent) == type({})
\ && has_key(b:indent, 'lnum')
" Force HTML indent to not keep state
let b:indent.lnum = -1
endif
endif
let lnum = prevnonblank(v:lnum-1)
let line = getline(lnum)
let cline = getline(v:lnum)
if cline =~# '^\s*<%[-=]\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%([-=]\=%>\|$\)'
let ind = ind - sw
endif
if line =~# '\S\s*<%[-=]\=\s*\%(}\|end\).\{-\}\s*\%([-=]\=%>\|$\)'
let ind = ind - sw
endif
if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*[-=]\=%>'
let ind = ind + sw
elseif line =~# '<%[-=]\=\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>'
let ind = ind + sw
endif
if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
let ind = ind + sw
endif
if line !~# '^\s*<%' && line =~# '%>\s*$' && line !~# '^\s*end\>'
\ && synID(v:lnum, match(cline, '\S') + 1, 1) != hlID('htmlEndTag')
let ind = ind - sw
endif
if cline =~# '^\s*[-=]\=%>\s*$'
let ind = ind - sw
endif
return ind
endfunction
let &cpo = s:cpo_sav
unlet! s:cpo_sav
" vim:set sw=2 sts=2 ts=8 noet:

View File

@@ -0,0 +1,39 @@
" Vim indent file
" Language: Eterm configuration file
" Maintainer: Doug Kearns <dougkearns@gmail.com>
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
" Last Change: 24 Sep 2021
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetEtermIndent()
setlocal indentkeys=!^F,o,O,=end
setlocal nosmartindent
let b:undo_indent = "setl inde< indk< si<"
if exists("*GetEtermIndent")
finish
endif
function GetEtermIndent()
let lnum = prevnonblank(v:lnum - 1)
if lnum == 0
return 0
endif
let ind = indent(lnum)
if getline(lnum) =~ '^\s*begin\>'
let ind = ind + shiftwidth()
endif
if getline(v:lnum) =~ '^\s*end\>'
let ind = ind - shiftwidth()
endif
return ind
endfunction

View File

@@ -0,0 +1,11 @@
" Vim indent file
" Language: Expect
" Maintainer: Doug Kearns <dougkearns@gmail.com>
" Last Change: 2022 Jul 16
if exists("b:did_indent")
finish
endif
" Syntax is similar to Tcl
runtime! indent/tcl.vim

View File

@@ -0,0 +1,454 @@
" Vim indent file
" Language: Falcon
" Maintainer: Steven Oliver <oliver.steven@gmail.com>
" Website: https://steveno@github.com/steveno/falconpl-vim.git
" Credits: This is, to a great extent, a copy n' paste of ruby.vim.
" 2022 April: b:undo_indent added by Doug Kearns
" 1. Setup {{{1
" ============
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal nosmartindent
" Setup indent function and when to use it
setlocal indentexpr=FalconGetIndent(v:lnum)
setlocal indentkeys=0{,0},0),0],!^F,o,O,e
setlocal indentkeys+==~case,=~catch,=~default,=~elif,=~else,=~end,=~\"
let b:undo_indent = "setl inde< indk< si<"
" Define the appropriate indent function but only once
if exists("*FalconGetIndent")
finish
endif
let s:cpo_save = &cpo
set cpo&vim
" 2. Variables {{{1
" ============
" Regex of syntax group names that are strings AND comments
let s:syng_strcom = '\<falcon\%(String\|StringEscape\|Comment\)\>'
" Regex of syntax group names that are strings
let s:syng_string = '\<falcon\%(String\|StringEscape\)\>'
" Regex that defines blocks.
"
" Note that there's a slight problem with this regex and s:continuation_regex.
" Code like this will be matched by both:
"
" method_call do |(a, b)|
"
" The reason is that the pipe matches a hanging "|" operator.
"
let s:block_regex =
\ '\%(\<do:\@!\>\|%\@<!{\)\s*\%(|\s*(*\s*\%([*@&]\=\h\w*,\=\s*\)\%(,\s*(*\s*[*@&]\=\h\w*\s*)*\s*\)*|\)\=\s*\%(#.*\)\=$'
let s:block_continuation_regex = '^\s*[^])}\t ].*'.s:block_regex
" Regex that defines continuation lines.
" TODO: this needs to deal with if ...: and so on
let s:continuation_regex =
\ '\%(%\@<![({[\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)\s*\%(#.*\)\=$'
" Regex that defines bracket continuations
let s:bracket_continuation_regex = '%\@<!\%([({[]\)\s*\%(#.*\)\=$'
" Regex that defines continuation lines, not including (, {, or [.
let s:non_bracket_continuation_regex = '\%([\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)\s*\%(#.*\)\=$'
" Keywords to indent on
let s:falcon_indent_keywords = '^\s*\(case\|catch\|class\|enum\|default\|elif\|else' .
\ '\|for\|function\|if.*"[^"]*:.*"\|if \(\(:\)\@!.\)*$\|loop\|object\|select' .
\ '\|switch\|try\|while\|\w*\s*=\s*\w*([$\)'
" Keywords to deindent on
let s:falcon_deindent_keywords = '^\s*\(case\|catch\|default\|elif\|else\|end\)'
" 3. Functions {{{1
" ============
" Check if the character at lnum:col is inside a string, comment, or is ascii.
function s:IsInStringOrComment(lnum, col)
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom
endfunction
" Check if the character at lnum:col is inside a string.
function s:IsInString(lnum, col)
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string
endfunction
" Check if the character at lnum:col is inside a string delimiter
function s:IsInStringDelimiter(lnum, col)
return synIDattr(synID(a:lnum, a:col, 1), 'name') == 'falconStringDelimiter'
endfunction
" Find line above 'lnum' that isn't empty, in a comment, or in a string.
function s:PrevNonBlankNonString(lnum)
let in_block = 0
let lnum = prevnonblank(a:lnum)
while lnum > 0
" Go in and out of blocks comments as necessary.
" If the line isn't empty (with opt. comment) or in a string, end search.
let line = getline(lnum)
if line =~ '^=begin'
if in_block
let in_block = 0
else
break
endif
elseif !in_block && line =~ '^=end'
let in_block = 1
elseif !in_block && line !~ '^\s*#.*$' && !(s:IsInStringOrComment(lnum, 1)
\ && s:IsInStringOrComment(lnum, strlen(line)))
break
endif
let lnum = prevnonblank(lnum - 1)
endwhile
return lnum
endfunction
" Find line above 'lnum' that started the continuation 'lnum' may be part of.
function s:GetMSL(lnum)
" Start on the line we're at and use its indent.
let msl = a:lnum
let msl_body = getline(msl)
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
while lnum > 0
" If we have a continuation line, or we're in a string, use line as MSL.
" Otherwise, terminate search as we have found our MSL already.
let line = getline(lnum)
if s:Match(line, s:non_bracket_continuation_regex) &&
\ s:Match(msl, s:non_bracket_continuation_regex)
" If the current line is a non-bracket continuation and so is the
" previous one, keep its indent and continue looking for an MSL.
"
" Example:
" method_call one,
" two,
" three
"
let msl = lnum
elseif s:Match(lnum, s:non_bracket_continuation_regex) &&
\ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex))
" If the current line is a bracket continuation or a block-starter, but
" the previous is a non-bracket one, respect the previous' indentation,
" and stop here.
"
" Example:
" method_call one,
" two {
" three
"
return lnum
elseif s:Match(lnum, s:bracket_continuation_regex) &&
\ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex))
" If both lines are bracket continuations (the current may also be a
" block-starter), use the current one's and stop here
"
" Example:
" method_call(
" other_method_call(
" foo
return msl
elseif s:Match(lnum, s:block_regex) &&
\ !s:Match(msl, s:continuation_regex) &&
\ !s:Match(msl, s:block_continuation_regex)
" If the previous line is a block-starter and the current one is
" mostly ordinary, use the current one as the MSL.
"
" Example:
" method_call do
" something
" something_else
return msl
else
let col = match(line, s:continuation_regex) + 1
if (col > 0 && !s:IsInStringOrComment(lnum, col))
\ || s:IsInString(lnum, strlen(line))
let msl = lnum
else
break
endif
endif
let msl_body = getline(msl)
let lnum = s:PrevNonBlankNonString(lnum - 1)
endwhile
return msl
endfunction
" Check if line 'lnum' has more opening brackets than closing ones.
function s:ExtraBrackets(lnum)
let opening = {'parentheses': [], 'braces': [], 'brackets': []}
let closing = {'parentheses': [], 'braces': [], 'brackets': []}
let line = getline(a:lnum)
let pos = match(line, '[][(){}]', 0)
" Save any encountered opening brackets, and remove them once a matching
" closing one has been found. If a closing bracket shows up that doesn't
" close anything, save it for later.
while pos != -1
if !s:IsInStringOrComment(a:lnum, pos + 1)
if line[pos] == '('
call add(opening.parentheses, {'type': '(', 'pos': pos})
elseif line[pos] == ')'
if empty(opening.parentheses)
call add(closing.parentheses, {'type': ')', 'pos': pos})
else
let opening.parentheses = opening.parentheses[0:-2]
endif
elseif line[pos] == '{'
call add(opening.braces, {'type': '{', 'pos': pos})
elseif line[pos] == '}'
if empty(opening.braces)
call add(closing.braces, {'type': '}', 'pos': pos})
else
let opening.braces = opening.braces[0:-2]
endif
elseif line[pos] == '['
call add(opening.brackets, {'type': '[', 'pos': pos})
elseif line[pos] == ']'
if empty(opening.brackets)
call add(closing.brackets, {'type': ']', 'pos': pos})
else
let opening.brackets = opening.brackets[0:-2]
endif
endif
endif
let pos = match(line, '[][(){}]', pos + 1)
endwhile
" Find the rightmost brackets, since they're the ones that are important in
" both opening and closing cases
let rightmost_opening = {'type': '(', 'pos': -1}
let rightmost_closing = {'type': ')', 'pos': -1}
for opening in opening.parentheses + opening.braces + opening.brackets
if opening.pos > rightmost_opening.pos
let rightmost_opening = opening
endif
endfor
for closing in closing.parentheses + closing.braces + closing.brackets
if closing.pos > rightmost_closing.pos
let rightmost_closing = closing
endif
endfor
return [rightmost_opening, rightmost_closing]
endfunction
function s:Match(lnum, regex)
let col = match(getline(a:lnum), '\C'.a:regex) + 1
return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0
endfunction
function s:MatchLast(lnum, regex)
let line = getline(a:lnum)
let col = match(line, '.*\zs' . a:regex)
while col != -1 && s:IsInStringOrComment(a:lnum, col)
let line = strpart(line, 0, col)
let col = match(line, '.*' . a:regex)
endwhile
return col + 1
endfunction
" 4. FalconGetIndent Routine {{{1
" ============
function FalconGetIndent(...)
" For the current line, use the first argument if given, else v:lnum
let clnum = a:0 ? a:1 : v:lnum
" Use zero indent at the top of the file
if clnum == 0
return 0
endif
let line = getline(clnum)
let ind = -1
" If we got a closing bracket on an empty line, find its match and indent
" according to it. For parentheses we indent to its column - 1, for the
" others we indent to the containing line's MSL's level. Return -1 if fail.
let col = matchend(line, '^\s*[]})]')
if col > 0 && !s:IsInStringOrComment(clnum, col)
call cursor(clnum, col)
let bs = strpart('(){}[]', stridx(')}]', line[col - 1]) * 2, 2)
if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0
if line[col-1]==')' && col('.') != col('$') - 1
let ind = virtcol('.') - 1
else
let ind = indent(s:GetMSL(line('.')))
endif
endif
return ind
endif
" If we have a deindenting keyword, find its match and indent to its level.
" TODO: this is messy
if s:Match(clnum, s:falcon_deindent_keywords)
call cursor(clnum, 1)
if searchpair(s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'bW',
\ s:end_skip_expr) > 0
let msl = s:GetMSL(line('.'))
let line = getline(line('.'))
if strpart(line, 0, col('.') - 1) =~ '=\s*$' &&
\ strpart(line, col('.') - 1, 2) !~ 'do'
let ind = virtcol('.') - 1
elseif getline(msl) =~ '=\s*\(#.*\)\=$'
let ind = indent(line('.'))
else
let ind = indent(msl)
endif
endif
return ind
endif
" If we are in a multi-line string or line-comment, don't do anything to it.
if s:IsInString(clnum, matchend(line, '^\s*') + 1)
return indent('.')
endif
" Find a non-blank, non-multi-line string line above the current line.
let lnum = s:PrevNonBlankNonString(clnum - 1)
" If the line is empty and inside a string, use the previous line.
if line =~ '^\s*$' && lnum != prevnonblank(clnum - 1)
return indent(prevnonblank(clnum))
endif
" At the start of the file use zero indent.
if lnum == 0
return 0
endif
" Set up variables for the previous line.
let line = getline(lnum)
let ind = indent(lnum)
" If the previous line ended with a block opening, add a level of indent.
if s:Match(lnum, s:block_regex)
return indent(s:GetMSL(lnum)) + shiftwidth()
endif
" If it contained hanging closing brackets, find the rightmost one, find its
" match and indent according to that.
if line =~ '[[({]' || line =~ '[])}]\s*\%(#.*\)\=$'
let [opening, closing] = s:ExtraBrackets(lnum)
if opening.pos != -1
if opening.type == '(' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
if col('.') + 1 == col('$')
return ind + shiftwidth()
else
return virtcol('.')
endif
else
let nonspace = matchend(line, '\S', opening.pos + 1) - 1
return nonspace > 0 ? nonspace : ind + shiftwidth()
endif
elseif closing.pos != -1
call cursor(lnum, closing.pos + 1)
normal! %
if s:Match(line('.'), s:falcon_indent_keywords)
return indent('.') + shiftwidth()
else
return indent('.')
endif
else
call cursor(clnum, 0) " FIXME: column was vcol
end
endif
" If the previous line ended with an "end", match that "end"s beginning's
" indent.
let col = s:Match(lnum, '\%(^\|[^.:@$]\)\<end\>\s*\%(#.*\)\=$')
if col > 0
call cursor(lnum, col)
if searchpair(s:end_start_regex, '', s:end_end_regex, 'bW',
\ s:end_skip_expr) > 0
let n = line('.')
let ind = indent('.')
let msl = s:GetMSL(n)
if msl != n
let ind = indent(msl)
end
return ind
endif
end
let col = s:Match(lnum, s:falcon_indent_keywords)
if col > 0
call cursor(lnum, col)
let ind = virtcol('.') - 1 + shiftwidth()
" TODO: make this better (we need to count them) (or, if a searchpair
" fails, we know that something is lacking an end and thus we indent a
" level
if s:Match(lnum, s:end_end_regex)
let ind = indent('.')
endif
return ind
endif
" Set up variables to use and search for MSL to the previous line.
let p_lnum = lnum
let lnum = s:GetMSL(lnum)
" If the previous line wasn't a MSL and is continuation return its indent.
" TODO: the || s:IsInString() thing worries me a bit.
if p_lnum != lnum
if s:Match(p_lnum, s:non_bracket_continuation_regex) || s:IsInString(p_lnum,strlen(line))
return ind
endif
endif
" Set up more variables, now that we know we wasn't continuation bound.
let line = getline(lnum)
let msl_ind = indent(lnum)
" If the MSL line had an indenting keyword in it, add a level of indent.
" TODO: this does not take into account contrived things such as
" module Foo; class Bar; end
if s:Match(lnum, s:falcon_indent_keywords)
let ind = msl_ind + shiftwidth()
if s:Match(lnum, s:end_end_regex)
let ind = ind - shiftwidth()
endif
return ind
endif
" If the previous line ended with [*+/.,-=], but wasn't a block ending or a
" closing bracket, indent one extra level.
if s:Match(lnum, s:non_bracket_continuation_regex) && !s:Match(lnum, '^\s*\([\])}]\|end\)')
if lnum == p_lnum
let ind = msl_ind + shiftwidth()
else
let ind = msl_ind
endif
return ind
endif
return ind
endfunction
" }}}1
let &cpo = s:cpo_save
unlet s:cpo_save
" vim: set sw=4 sts=4 et tw=80 :

View File

@@ -0,0 +1,12 @@
" Vim indent file
" Language: Fennel
" Maintainer: Gregory Anders <greg[NOSPAM]@gpanders.com>
" Last Change: 2022 Apr 20
" 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

View File

@@ -0,0 +1,85 @@
" Vim indent file
" Language: fish
" Maintainer: Nicholas Boyle (github.com/nickeb96)
" Repository: https://github.com/nickeb96/fish.vim
" Last Change: February 4, 2023
" 2023 Aug 28 by Vim Project (undo_indent)
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetFishIndent(v:lnum)
setlocal indentkeys+==end,=else,=case
let b:undo_indent = "setlocal indentexpr< indentkeys<"
function s:PrevCmdStart(linenum)
let l:linenum = a:linenum
" look for the first line that isn't a line continuation
while l:linenum > 1 && getline(l:linenum - 1) =~# '\\$'
let l:linenum = l:linenum - 1
endwhile
return l:linenum
endfunction
function GetFishIndent(lnum)
let l:shiftwidth = shiftwidth()
let l:prevlnum = prevnonblank(a:lnum - 1)
if l:prevlnum ==# 0
return 0
endif
" if the previous line ended with a line continuation
if getline(a:lnum - 1) =~# '\\$'
if a:lnum ==# 0 || getline(a:lnum - 2) !~# '\\$'
" this is the first line continuation in a chain, so indent it
return indent(a:lnum - 1) + l:shiftwidth
else
" use the same indentation as the previous continued line
return indent(a:lnum - 1)
endif
endif
let l:prevlnum = s:PrevCmdStart(l:prevlnum)
let l:prevline = getline(l:prevlnum)
if l:prevline =~# '^\s*\(begin\|if\|else\|while\|for\|function\|case\|switch\)\>'
let l:indent = l:shiftwidth
else
let l:indent = 0
endif
let l:line = getline(a:lnum)
if l:line =~# '^\s*end\>'
" find end's matching start
let l:depth = 1
let l:currentlnum = a:lnum
while l:depth > 0 && l:currentlnum > 0
let l:currentlnum = s:PrevCmdStart(prevnonblank(l:currentlnum - 1))
let l:currentline = getline(l:currentlnum)
if l:currentline =~# '^\s*end\>'
let l:depth = l:depth + 1
elseif l:currentline =~# '^\s*\(begin\|if\|while\|for\|function\|switch\)\>'
let l:depth = l:depth - 1
endif
endwhile
if l:currentline =~# '^\s*switch\>'
return indent(l:currentlnum)
else
return indent(l:prevlnum) + l:indent - l:shiftwidth
endif
elseif l:line =~# '^\s*else\>'
return indent(l:prevlnum) + l:indent - l:shiftwidth
elseif l:line =~# '^\s*case\>'
if getline(l:prevlnum) =~# '^\s*switch\>'
return indent(l:prevlnum) + l:indent
else
return indent(l:prevlnum) + l:indent - l:shiftwidth
endif
else
return indent(l:prevlnum) + l:indent
endif
endfunction

View File

@@ -0,0 +1,226 @@
" Vim indent file
" Language: Fortran 2023 (and Fortran 2018, 2008, 2003, 95, 90, 77, 66)
" Version: (v50) 2023 December 22
" Maintainers: Ajit J. Thakkar <ajit@unb.ca>; <https://ajit.ext.unb.ca/>
" Joshua Hollett <j.hollett@uwinnipeg.ca>
" Usage: For instructions, do :help fortran-indent from Vim
" Credits:
" Version 0.1 was created in September 2000 by Ajit Thakkar.
" Since then, useful suggestions and contributions have been made, in order, by:
" Albert Oliver Serra, Takuya Fujiwara, Philipp Edelmann, Eisuke Kawashima,
" Louis Cochen, and Doug Kearns.
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
let s:cposet=&cpoptions
set cpoptions&vim
let b:undo_indent = "setl inde< indk<"
setlocal indentkeys+==~end,=~case,=~if,=~else,=~do,=~where,=~elsewhere,=~select
setlocal indentkeys+==~endif,=~enddo,=~endwhere,=~endselect,=~elseif
setlocal indentkeys+==~interface,=~forall,=~associate,=~block,=~enum,=~critical
setlocal indentkeys+==~endforall,=~endassociate,=~endblock,=~endenum,=~endcritical
if exists("b:fortran_indent_more") || exists("g:fortran_indent_more")
setlocal indentkeys+==~function,=~subroutine,=~module,=~contains,=~program
setlocal indentkeys+==~endfunction,=~endsubroutine,=~endmodule
setlocal indentkeys+==~endprogram
endif
" Determine whether this is a fixed or free format source file
" 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
let b:fortran_fixed_source = 0
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
" Modern fortran compilers still allow 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 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.
let s:lmax = 500
if ( s:lmax > line("$") )
let s:lmax = line("$")
endif
let b:fortran_fixed_source = 1
let s:ln=1
while s:ln <= s:lmax
let s:test = strpart(getline(s:ln),0,5)
if s:test !~ '^[Cc*]' && s:test !~ '^ *[!#]' && s:test =~ '[^ 0-9\t]' && s:test !~ '^[ 0-9]*\t'
let b:fortran_fixed_source = 0
break
endif
let s:ln = s:ln + 1
endwhile
endif
endif
" Define the appropriate indent function but only once
if (b:fortran_fixed_source == 1)
setlocal indentexpr=FortranGetFixedIndent()
if exists("*FortranGetFixedIndent")
let &cpoptions = s:cposet
unlet s:cposet
finish
endif
else
setlocal indentexpr=FortranGetFreeIndent()
if exists("*FortranGetFreeIndent")
let &cpoptions = s:cposet
unlet s:cposet
finish
endif
endif
function FortranGetIndent(lnum)
let ind = indent(a:lnum)
let prevline=getline(a:lnum)
" Strip tail comment
let prevstat=substitute(prevline, '!.*$', '', '')
let prev2line=getline(a:lnum-1)
let prev2stat=substitute(prev2line, '!.*$', '', '')
"Indent do loops only if they are all guaranteed to be of do/end do type
if exists("b:fortran_do_enddo") || exists("g:fortran_do_enddo")
if prevstat =~? '^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*do\>'
let ind = ind + shiftwidth()
endif
if getline(v:lnum) =~? '^\s*\(\d\+\s\)\=\s*end\s*do\>'
let ind = ind - shiftwidth()
endif
endif
"Add a shiftwidth to statements following if, else, else if, case, class,
"where, else where, forall, type, interface and associate statements
if prevstat =~? '^\s*\(case\|class\s\+is\|else\|else\s*if\|else\s*where\)\>'
\ ||prevstat=~? '^\s*\(type\|rank\|interface\|associate\|enum\|critical\)\>'
\ ||prevstat=~? '^\s*change\s\+team\>'
\ ||prevstat=~?'^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*\(forall\|where\|block\)\>'
\ ||prevstat=~? '^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*if\>'
let ind = ind + shiftwidth()
" Remove unwanted indent after logical and arithmetic ifs
if prevstat =~? '\<if\>' && prevstat !~? '\<then\>'
let ind = ind - shiftwidth()
endif
" Remove unwanted indent after type( statements
if prevstat =~? '^\s*type\s*('
let ind = ind - shiftwidth()
endif
endif
"Indent program units unless instructed otherwise
if !exists("b:fortran_indent_less") && !exists("g:fortran_indent_less")
let prefix='\(\(pure\|impure\|elemental\|recursive\)\s\+\)\{,2}'
let type='\(\(integer\|real\|double\s\+precision\|complex\|logical'
\.'\|character\|type\|class\)\s*\S*\s\+\)\='
if prevstat =~? '^\s*\(contains\|submodule\|program\)\>'
\ ||prevstat =~? '^\s*'.'module\>\(\s*\procedure\)\@!'
\ ||prevstat =~? '^\s*'.prefix.'subroutine\>'
\ ||prevstat =~? '^\s*'.prefix.type.'function\>'
\ ||prevstat =~? '^\s*'.type.prefix.'function\>'
let ind = ind + shiftwidth()
endif
if getline(v:lnum) =~? '^\s*contains\>'
\ ||getline(v:lnum)=~? '^\s*end\s*'
\ .'\(function\|subroutine\|module\|submodule\|program\)\>'
let ind = ind - shiftwidth()
endif
endif
"Subtract a shiftwidth from else, else if, elsewhere, case, class, end if,
" end where, end select, end forall, end interface, end associate,
" end enum, end type, end block, end team and end type statements
if getline(v:lnum) =~? '^\s*\(\d\+\s\)\=\s*'
\. '\(else\|else\s*if\|else\s*where\|case\|class\|rank\|type\s\+is\|'
\. 'end\s*\(if\|where\|select\|interface\|critical\|team\|'
\. 'type\|forall\|associate\|enum\|block\)\)\>'
let ind = ind - shiftwidth()
" Fix indent for case statement immediately after select
if prevstat =~? '\<select\s*\(case\|type\)\>'
let ind = ind + shiftwidth()
endif
endif
"First continuation line
if prevstat =~ '&\s*$' && prev2stat !~ '&\s*$'
let ind = ind + shiftwidth()
endif
"Line after last continuation line
if prevstat !~ '&\s*$' && prev2stat =~ '&\s*$' && prevstat !~? '\<then\>'
let ind = ind - shiftwidth()
endif
return ind
endfunction
function FortranGetFreeIndent()
"Find the previous non-blank line
let lnum = prevnonblank(v:lnum - 1)
"Use zero indent at the top of the file
if lnum == 0
return 0
endif
let ind=FortranGetIndent(lnum)
return ind
endfunction
function FortranGetFixedIndent()
let currline=getline(v:lnum)
"Don't indent comments, continuation lines and labelled lines
if strpart(currline,0,6) =~ '[^ \t]'
let ind = indent(v:lnum)
return ind
endif
"Find the previous line which is not blank, not a comment,
"not a continuation line, and does not have a label
let lnum = v:lnum - 1
while lnum > 0
let prevline=getline(lnum)
if (prevline =~ "^[C*!]") || (prevline =~ "^\s*$")
\ || (strpart(prevline,5,1) !~ "[ 0]")
" Skip comments, blank lines and continuation lines
let lnum = lnum - 1
else
let test=strpart(prevline,0,5)
if test =~ "[0-9]"
" Skip lines with statement numbers
let lnum = lnum - 1
else
break
endif
endif
endwhile
"First line must begin at column 7
if lnum == 0
return 6
endif
let ind=FortranGetIndent(lnum)
return ind
endfunction
let &cpoptions = s:cposet
unlet s:cposet
" vim:sw=2 tw=130

View File

@@ -0,0 +1,44 @@
" Vim indent file
" Language: FrameScript
" Maintainer: Doug Kearns <dougkearns@gmail.com>
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
" Last Change: 24 Sep 2021
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetFrameScriptIndent()
setlocal indentkeys=!^F,o,O,0=~Else,0=~EndIf,0=~EndLoop,0=~EndSub
setlocal nosmartindent
let b:undo_indent = "setl inde< indk< si<"
if exists("*GetFrameScriptIndent")
finish
endif
function GetFrameScriptIndent()
let lnum = prevnonblank(v:lnum - 1)
if lnum == 0
return 0
endif
if getline(v:lnum) =~ '^\s*\*'
return cindent(v:lnum)
endif
let ind = indent(lnum)
if getline(lnum) =~? '^\s*\%(If\|Loop\|Sub\)'
let ind = ind + shiftwidth()
endif
if getline(v:lnum) =~? '^\s*\%(Else\|End\%(If\|Loop\|Sub\)\)'
let ind = ind - shiftwidth()
endif
return ind
endfunction

View File

@@ -0,0 +1,11 @@
" Vim indent file
" Language: FreeBASIC
" Maintainer: Doug Kearns <dougkearns@gmail.com>
" Last Change: 2022 Jan 24
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
runtime! indent/vb.vim

View File

@@ -0,0 +1,148 @@
vim9script
# Vim indent file
# Language: gdscript (Godot game engine)
# Maintainer: Maxim Kim <habamax@gmail.com>
# Based on python indent file.
if exists("b:did_indent")
finish
endif
b:did_indent = 1
var undo_opts = "setl indentexpr< indentkeys< lisp< autoindent<"
if exists('b:undo_indent')
b:undo_indent ..= "|" .. undo_opts
else
b:undo_indent = undo_opts
endif
setlocal nolisp
setlocal autoindent
setlocal indentexpr=GDScriptIndent()
setlocal indentkeys+=<:>,=elif,=except
def GDScriptIndent(): number
# 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(v:lnum - 1) =~ '\\$'
if v:lnum > 1 && getline(v:lnum - 2) =~ '\\$'
return indent(v:lnum - 1)
endif
return indent(v:lnum - 1) + (shiftwidth() * 2)
endif
# If the start of the line is in a string don't change the indent.
if has('syntax_items') && synIDattr(synID(v:lnum, 1, 1), "name") =~ "String$"
return -1
endif
# Search backwards for the previous non-empty line.
var plnum = prevnonblank(v:lnum - 1)
if plnum == 0
# This is the first non-empty line, use zero indent.
return 0
endif
var plindent = indent(plnum)
var plnumstart = plnum
# Get the line and remove a trailing comment.
# Use syntax highlighting attributes when possible.
var pline = getline(plnum)
var pline_len = strlen(pline)
if has('syntax_items')
# If the last character in the line is a comment, do a binary search for
# the start of the comment. synID() is slow, a linear search would take
# too long on a long line.
if synIDattr(synID(plnum, pline_len, 1), "name") =~ "\\(Comment\\|Todo\\)$"
var min = 1
var max = pline_len
while min < max
var col = (min + max) / 2
if synIDattr(synID(plnum, col, 1), "name") =~ "\\(Comment\\|Todo\\)$"
max = col
else
min = col + 1
endif
endwhile
pline = strpart(pline, 0, min - 1)
endif
else
var col = 0
while col < pline_len
if pline[col] == '#'
pline = strpart(pline, 0, col)
break
endif
col = col + 1
endwhile
endif
# When "inside" parenthesis: If at the first line below the parenthesis add
# one 'shiftwidth' ("inside" is simplified and not really checked)
# my_var = (
# a
# + b
# + c
# )
if pline =~ '[({\[]\s*$'
return indent(plnum) + shiftwidth()
endif
# If the previous line ended with a colon, indent this line
if pline =~ ':\s*$'
return plindent + shiftwidth()
endif
# If the previous line was a stop-execution statement...
if getline(plnum) =~ '^\s*\(break\|continue\|raise\|return\|pass\)\>'
# See if the user has already dedented
if indent(v:lnum) > indent(plnum) - shiftwidth()
# If not, recommend one dedent
return indent(plnum) - shiftwidth()
endif
# Otherwise, trust the user
return -1
endif
# If the current line begins with a keyword that lines up with "try"
if getline(v:lnum) =~ '^\s*\(except\|finally\)\>'
var lnum = v:lnum - 1
while lnum >= 1
if getline(lnum) =~ '^\s*\(try\|except\)\>'
var ind = indent(lnum)
if ind >= indent(v:lnum)
return -1 # indent is already less than this
endif
return ind # line up with previous try or except
endif
lnum = lnum - 1
endwhile
return -1 # no matching "try"!
endif
# If the current line begins with a header keyword, dedent
if getline(v:lnum) =~ '^\s*\(elif\|else\)\>'
# Unless the previous line was a one-liner
if getline(plnumstart) =~ '^\s*\(for\|if\|try\)\>'
return plindent
endif
# Or the user has already dedented
if indent(v:lnum) <= plindent - shiftwidth()
return -1
endif
return plindent - shiftwidth()
endif
return -1
enddef

View File

@@ -0,0 +1,38 @@
" Vim indent file
" Language: git config file
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Last Change: 2017 Jun 13
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal autoindent
setlocal indentexpr=GetGitconfigIndent()
setlocal indentkeys=o,O,*<Return>,0[,],0;,0#,=,!^F
let b:undo_indent = 'setl ai< inde< indk<'
" Only define the function once.
if exists("*GetGitconfigIndent")
finish
endif
function! GetGitconfigIndent()
let sw = shiftwidth()
let line = getline(prevnonblank(v:lnum-1))
let cline = getline(v:lnum)
if line =~ '\\\@<!\%(\\\\\)*\\$'
" odd number of slashes, in a line continuation
return 2 * sw
elseif cline =~ '^\s*\['
return 0
elseif cline =~ '^\s*\a'
return sw
elseif cline == '' && line =~ '^\['
return sw
else
return -1
endif
endfunction

View File

@@ -0,0 +1,51 @@
" Vim indent file
" Language: gitolite configuration
" URL: https://github.com/sitaramc/gitolite/blob/master/contrib/vim/indent/gitolite.vim
" (https://raw.githubusercontent.com/sitaramc/gitolite/master/contrib/vim/indent/gitolite.vim)
" Maintainer: Sitaram Chamarty <sitaramc@gmail.com>
" (former Maintainer: Teemu Matilainen <teemu.matilainen@iki.fi>)
" Last Change: 2022 Apr 06
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal autoindent
setlocal indentexpr=GetGitoliteIndent()
setlocal indentkeys=o,O,*<Return>,!^F,=repo,\",=
let b:undo_indent = "setl ai< inde< indk<"
" Only define the function once.
if exists("*GetGitoliteIndent")
finish
endif
let s:cpo_save = &cpo
set cpo&vim
function! GetGitoliteIndent()
let prevln = prevnonblank(v:lnum-1)
let pline = getline(prevln)
let cline = getline(v:lnum)
if cline =~ '^\s*\(C\|R\|RW\|RW+\|RWC\|RW+C\|RWD\|RW+D\|RWCD\|RW+CD\|-\)[ \t=]'
return shiftwidth()
elseif cline =~ '^\s*config\s'
return shiftwidth()
elseif cline =~ '^\s*option\s'
return shiftwidth()
elseif pline =~ '^\s*repo\s' && cline =~ '^\s*\(#.*\)\?$'
return shiftwidth()
elseif cline =~ '^\s*#'
return indent(prevln)
elseif cline =~ '^\s*$'
return -1
else
return 0
endif
endfunction
let &cpo = s:cpo_save
unlet s:cpo_save

View File

@@ -0,0 +1,14 @@
" Language: OpenGL Shading Language
" Maintainer: Gregory Anders <greg@gpanders.com>
" Last Modified: 2024 Jul 21
" Upstream: https://github.com/tikhomirov/vim-glsl
if exists('b:did_indent')
finish
endif
let b:did_indent = 1
setlocal autoindent cindent
setlocal cinoptions&
let b:undo_indent = 'setl ai< ci< cino<'

View File

@@ -0,0 +1,69 @@
" Vim indent file
" Language: Go
" Maintainer: David Barnett (https://github.com/google/vim-ft-go)
" Last Change: 2017 Jun 13
" 2023 Aug 28 by Vim Project (undo_indent)
"
" TODO:
" - function invocations split across lines
" - general line splits (line ends in an operator)
if exists('b:did_indent')
finish
endif
let b:did_indent = 1
" C indentation is too far off useful, mainly due to Go's := operator.
" Let's just define our own.
setlocal nolisp
setlocal autoindent
setlocal indentexpr=GoIndent(v:lnum)
setlocal indentkeys+=<:>,0=},0=)
let b:undo_indent = "setl ai< inde< indk< lisp<"
if exists('*GoIndent')
finish
endif
function! GoIndent(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*$'
" previous line opened a block
let l:ind += shiftwidth()
endif
if l:prevl =~# '^\s*\(case .*\|default\):$'
" previous line is part of a switch statement
let l:ind += shiftwidth()
endif
" TODO: handle if the previous line is a label.
if l:thisl =~ '^\s*[)}]'
" this line closed a block
let l:ind -= shiftwidth()
endif
" Colons are tricky.
" We want to outdent if it's part of a switch ("case foo:" or "default:").
" We ignore trying to deal with jump labels because (a) they're rare, and
" (b) they're hard to disambiguate from a composite literal key.
if l:thisl =~# '^\s*\(case .*\|default\):$'
let l:ind -= shiftwidth()
endif
return l:ind
endfunction
" vim: sw=2 sts=2 et

View File

@@ -0,0 +1,92 @@
" Vim indent file
" Language: graphql
" Maintainer: Jon Parise <jon@indelible.org>
" Filenames: *.graphql *.graphqls *.gql
" URL: https://github.com/jparise/vim-graphql
" License: MIT <https://opensource.org/license/mit>
" Last Change: 2024 Dec 21
" Set our local options if indentation hasn't already been set up.
" This generally means we've been detected as the primary filetype.
if !exists('b:did_indent')
setlocal autoindent
setlocal nocindent
setlocal nolisp
setlocal nosmartindent
setlocal indentexpr=GetGraphQLIndent()
setlocal indentkeys=0{,0},0),0[,0],0#,!^F,o,O
let b:did_indent = 1
endif
" If our indentation function already exists, we have nothing more to do.
if exists('*GetGraphQLIndent')
finish
endif
let s:cpo_save = &cpoptions
set cpoptions&vim
" searchpair() skip expression that matches in comments and strings.
let s:pair_skip_expr =
\ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "comment\\|string"'
" Check if the character at lnum:col is inside a string.
function s:InString(lnum, col)
return synIDattr(synID(a:lnum, a:col, 1), 'name') ==# 'graphqlString'
endfunction
function GetGraphQLIndent()
" If this is the first non-blank line, we have nothing more to do because
" all of our indentation rules are based on matching against earlier lines.
let l:prevlnum = prevnonblank(v:lnum - 1)
if l:prevlnum == 0
return 0
endif
" If the previous line isn't GraphQL, assume we're part of a template
" string and indent this new line within it.
let l:stack = map(synstack(l:prevlnum, 1), "synIDattr(v:val, 'name')")
if get(l:stack, -1) !~# '^graphql'
return indent(l:prevlnum) + shiftwidth()
endif
let l:line = getline(v:lnum)
" If this line contains just a closing bracket, find its matching opening
" bracket and indent the closing bracket to match.
let l:col = matchend(l:line, '^\s*[]})]')
if l:col > 0 && !s:InString(v:lnum, l:col)
call cursor(v:lnum, l:col)
let l:bracket = l:line[l:col - 1]
if l:bracket ==# '}'
let l:matched = searchpair('{', '', '}', 'bW', s:pair_skip_expr)
elseif l:bracket ==# ']'
let l:matched = searchpair('\[', '', '\]', 'bW', s:pair_skip_expr)
elseif l:bracket ==# ')'
let l:matched = searchpair('(', '', ')', 'bW', s:pair_skip_expr)
else
let l:matched = -1
endif
return l:matched > 0 ? indent(l:matched) : virtcol('.') - 1
endif
" If we're inside of a multiline string, continue with the same indentation.
if s:InString(v:lnum, matchend(l:line, '^\s*') + 1)
return indent(v:lnum)
endif
" If the previous line ended with an opening bracket, indent this line.
if getline(l:prevlnum) =~# '\%(#.*\)\@<![[{(]\s*$'
return indent(l:prevlnum) + shiftwidth()
endif
" Default to the existing indentation level.
return indent(l:prevlnum)
endfunction
let &cpoptions = s:cpo_save
unlet s:cpo_save

View File

@@ -0,0 +1,7 @@
" Vim indent file
" Language: GYP
" Maintainer: ObserverOfTime <chronobserver@disroot.org>
" Last Change: 2022 Sep 27
" JSON indent works well
runtime! indent/json.vim

View File

@@ -0,0 +1,76 @@
" Vim indent file
" Language: Haml
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Last Change: 2022 Mar 15
if exists("b:did_indent")
finish
endif
runtime! indent/ruby.vim
unlet! b:did_indent
let b:did_indent = 1
setlocal autoindent
setlocal indentexpr=GetHamlIndent()
setlocal indentkeys=o,O,*<Return>,},],0),!^F,=end,=else,=elsif,=rescue,=ensure,=when
let b:undo_indent = "setl ai< inde< indk<"
" Only define the function once.
if exists("*GetHamlIndent")
finish
endif
let s:attributes = '\%({.\{-\}}\|\[.\{-\}\]\)'
let s:tag = '\%([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*'
if !exists('g:haml_self_closing_tags')
let g:haml_self_closing_tags = 'base|link|meta|br|hr|img|input'
endif
function! GetHamlIndent()
let lnum = prevnonblank(v:lnum-1)
if lnum == 0
return 0
endif
let line = substitute(getline(lnum),'\s\+$','','')
let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','')
let lastcol = strlen(line)
let line = substitute(line,'^\s\+','','')
let indent = indent(lnum)
let cindent = indent(v:lnum)
let sw = shiftwidth()
if cline =~# '\v^-\s*%(elsif|else|when)>'
let indent = cindent < indent ? cindent : indent - sw
endif
let increase = indent + sw
if indent == indent(lnum)
let indent = cindent <= indent ? -1 : increase
endif
let group = synIDattr(synID(lnum,lastcol,1),'name')
if line =~ '^!!!'
return indent
elseif line =~ '^/\%(\[[^]]*\]\)\=$'
return increase
elseif group == 'hamlFilter'
return increase
elseif line =~ '^'.s:tag.'[&!]\=[=~-]\s*\%(\%(if\|else\|elsif\|unless\|case\|when\|while\|until\|for\|begin\|module\|class\|def\)\>\%(.*\<end\>\)\@!\|.*do\%(\s*|[^|]*|\)\=\s*$\)'
return increase
elseif line =~ '^'.s:tag.'[&!]\=[=~-].*,\s*$'
return increase
elseif line == '-#'
return increase
elseif group =~? '\v^(hamlSelfCloser)$' || line =~? '^%\v%('.g:haml_self_closing_tags.')>'
return indent
elseif group =~? '\v^%(hamlTag|hamlAttributesDelimiter|hamlObjectDelimiter|hamlClass|hamlId|htmlTagName|htmlSpecialTagName)$'
return increase
elseif synIDattr(synID(v:lnum,1,1),'name') ==? 'hamlRubyFilter'
return GetRubyIndent()
else
return indent
endif
endfunction
" vim:set sw=2:

View File

@@ -0,0 +1,70 @@
" Vim indent file
" Language: Hamster Script
" Version: 2.0.6.1
" Last Change: 2021 Oct 11
" Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
" Download: https://www.vim.org/scripts/script.php?script_id=1099
"
" 2.0.6.1 (Oct 2021)
" Added b:undo_indent
" Added cpo check
"
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentkeys+==~if,=~else,=~endif,=~endfor,=~endwhile
setlocal indentkeys+==~do,=~until,=~while,=~repeat,=~for,=~loop
setlocal indentkeys+==~sub,=~endsub
let b:undo_indent = "setl indentkeys<"
" Define the appropriate indent function but only once
setlocal indentexpr=HamGetFreeIndent()
if exists("*HamGetFreeIndent")
finish
endif
let s:keepcpo = &cpo
set cpo&vim
function HamGetIndent(lnum)
let ind = indent(a:lnum)
let prevline=getline(a:lnum)
" Add a shiftwidth to statements following if, else, elseif,
" case, select, default, do, until, while, for, start
if prevline =~? '^\s*\<\(if\|else\%(if\)\?\|for\|repeat\|do\|while\|sub\)\>'
let ind = ind + shiftwidth()
endif
" Subtract a shiftwidth from else, elseif, end(if|while|for), until
let line = getline(v:lnum)
if line =~? '^\s*\(else\|elseif\|loop\|until\|end\%(if\|while\|for\|sub\)\)\>'
let ind = ind - shiftwidth()
endif
return ind
endfunction
function HamGetFreeIndent()
" Find the previous non-blank line
let lnum = prevnonblank(v:lnum - 1)
" Use zero indent at the top of the file
if lnum == 0
return 0
endif
let ind=HamGetIndent(lnum)
return ind
endfunction
" Restore:
let &cpo = s:keepcpo
unlet s:keepcpo
" vim:sw=2 tw=80

View File

@@ -0,0 +1,146 @@
" Vim indent file
" Language: Hare
" Maintainer: Amelia Clarke <selene@perilune.dev>
" Last Change: 2024-04-14
" Upstream: https://git.sr.ht/~sircmpwn/hare.vim
if exists('b:did_indent')
finish
endif
let b:did_indent = 1
let s:cpo_save = &cpo
set cpo&vim
" L0 -> don't deindent labels
" (s -> use one indent after a trailing (
" m1 -> if ) starts a line, indent it the same as its matching (
" ks -> add an extra indent to extra lines in an if expression or for expression
" j1 -> indent code inside {} one level when in parentheses
" J1 -> see j1
" *0 -> don't search for unclosed block comments
" #1 -> don't deindent lines that begin with #
setlocal cinoptions=L0,(s,m1,ks,j1,J1,*0,#1
" Controls which keys reindent the current line.
" 0{ -> { at beginning of line
" 0} -> } at beginning of line
" 0) -> ) at beginning of line
" 0] -> ] at beginning of line
" !^F -> <C-f> (not inserted)
" o -> <CR> or `o` command
" O -> `O` command
" e -> else
" 0=case -> case
setlocal indentkeys=0{,0},0),0],!^F,o,O,e,0=case
setlocal cinwords=if,else,for,switch,match
setlocal indentexpr=GetHareIndent()
let b:undo_indent = 'setl cino< cinw< inde< indk<'
if exists('*GetHareIndent()')
finish
endif
function! FloorCindent(lnum)
return cindent(a:lnum) / shiftwidth() * shiftwidth()
endfunction
function! GetHareIndent()
let line = getline(v:lnum)
let prevlnum = prevnonblank(v:lnum - 1)
let prevline = getline(prevlnum)
let prevprevline = getline(prevnonblank(prevlnum - 1))
" This is all very hacky and imperfect, but it's tough to do much better when
" working with regex-based indenting rules.
" If the previous line ended with =, indent by one shiftwidth.
if prevline =~# '\v\=\s*(//.*)?$'
return indent(prevlnum) + shiftwidth()
endif
" If the previous line ended in a semicolon and the line before that ended
" with =, deindent by one shiftwidth.
if prevline =~# '\v;\s*(//.*)?$' && prevprevline =~# '\v\=\s*(//.*)?$'
return indent(prevlnum) - shiftwidth()
endif
" TODO: The following edge-case is still indented incorrectly:
" case =>
" if (foo) {
" bar;
" };
" | // cursor is incorrectly deindented by one shiftwidth.
"
" This only happens if the {} block is the first statement in the case body.
" If `case` is typed, the case will also be incorrectly deindented by one
" shiftwidth. Are you having fun yet?
" Deindent cases.
if line =~# '\v^\s*case'
" If the previous line was also a case, don't do any special indenting.
if prevline =~# '\v^\s*case'
return indent(prevlnum)
end
" If the previous line was a multiline case, deindent by one shiftwidth.
if prevline =~# '\v\=\>\s*(//.*)?$'
return indent(prevlnum) - shiftwidth()
endif
" If the previous line started a block, deindent by one shiftwidth.
" This handles the first case in a switch/match block.
if prevline =~# '\v\{\s*(//.*)?$'
return FloorCindent(v:lnum) - shiftwidth()
end
" If the previous line ended in a semicolon and the line before that wasn't
" a case, deindent by one shiftwidth.
if prevline =~# '\v;\s*(//.*)?$' && prevprevline !~# '\v\=\>\s*(//.*)?$'
return FloorCindent(v:lnum) - shiftwidth()
end
let l:indent = FloorCindent(v:lnum)
" If a normal cindent would indent the same amount as the previous line,
" deindent by one shiftwidth. This fixes some issues with `case let` blocks.
if l:indent == indent(prevlnum)
return l:indent - shiftwidth()
endif
" Otherwise, do a normal cindent.
return l:indent
endif
" Don't indent an extra shiftwidth for cases which span multiple lines.
if prevline =~# '\v\=\>\s*(//.*)?$' && prevline !~# '\v^\s*case\W'
return indent(prevlnum)
endif
" Indent the body of a case.
" If the previous line ended in a semicolon and the line before that was a
" case, don't do any special indenting.
if prevline =~# '\v;\s*(//.*)?$' && prevprevline =~# '\v\=\>\s*(//.*)?$'
\ && line !~# '\v^\s*}'
return indent(prevlnum)
endif
let l:indent = FloorCindent(v:lnum)
" If the previous line was a case and a normal cindent wouldn't indent, indent
" an extra shiftwidth.
if prevline =~# '\v\=\>\s*(//.*)?$' && l:indent == indent(prevlnum)
return l:indent + shiftwidth()
endif
" If everything above is false, do a normal cindent.
return l:indent
endfunction
let &cpo = s:cpo_save
unlet s:cpo_save
" vim: et sw=2 sts=2 ts=8

View File

@@ -0,0 +1,16 @@
" Vim indent file
" Language: HCL
" Maintainer: Gregory Anders
" Upstream: https://github.com/hashivim/vim-terraform
" Last Change: 2024-09-03
if exists('b:did_indent')
finish
endif
let b:did_indent = 1
setlocal autoindent shiftwidth=2 tabstop=2 softtabstop=2 expandtab
setlocal indentexpr=hcl#indentexpr(v:lnum)
setlocal indentkeys+=<:>,0=},0=)
let b:undo_indent = 'setlocal ai< sw< ts< sts< et< inde< indk<'

View File

@@ -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 shiftwidth()
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 shiftwidth()
endif
" Match inside of a block
if s:IsInBlock(v:lnum)
if prevline =~ "^\k\+.*$"
return shiftwidth()
else
return indent(prevlnum)
endif
endif
return 0
endfunction
let &cpo = s:cpo_save
unlet s:cpo_save

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
" Vim indent file
" Language: Django HTML template
" Maintainer: Dave Hodder <dmh@dmh.org.uk>
" Last Change: 2007 Jan 25
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
" Use HTML formatting rules.
runtime! indent/html.vim

View File

@@ -0,0 +1,65 @@
" IDL (Interactive Data Language) indent file.
" Language: IDL (ft=idlang)
" Maintainer: Aleksandar Jelenak <ajelenak AT yahoo.com> (Invalid email address)
" Doug Kearns <dougkearns@gmail.com>
" Last change: 2022 Apr 06
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentkeys=o,O,0=endif,0=ENDIF,0=endelse,0=ENDELSE,0=endwhile,0=ENDWHILE,0=endfor,0=ENDFOR,0=endrep,0=ENDREP
setlocal indentexpr=GetIdlangIndent(v:lnum)
let b:undo_indent = "setl inde< indk<"
" Only define the function once.
if exists("*GetIdlangIndent")
finish
endif
function GetIdlangIndent(lnum)
" First non-empty line above the current line.
let pnum = prevnonblank(v:lnum-1)
" v:lnum is the first non-empty line -- zero indent.
if pnum == 0
return 0
endif
" Second non-empty line above the current line.
let pnum2 = prevnonblank(pnum-1)
" Current indent.
let curind = indent(pnum)
" Indenting of continued lines.
if getline(pnum) =~ '\$\s*\(;.*\)\=$'
if getline(pnum2) !~ '\$\s*\(;.*\)\=$'
let curind = curind+shiftwidth()
endif
else
if getline(pnum2) =~ '\$\s*\(;.*\)\=$'
let curind = curind-shiftwidth()
endif
endif
" Indenting blocks of statements.
if getline(v:lnum) =~? '^\s*\(endif\|endelse\|endwhile\|endfor\|endrep\)\>'
if getline(pnum) =~? 'begin\>'
elseif indent(v:lnum) > curind-shiftwidth()
let curind = curind-shiftwidth()
else
return -1
endif
elseif getline(pnum) =~? 'begin\>'
if indent(v:lnum) < curind+shiftwidth()
let curind = curind+shiftwidth()
else
return -1
endif
endif
return curind
endfunction

View File

@@ -0,0 +1,183 @@
" Vim indent file
" Language: Idris 2
" Maintainer: Idris Hackers (https://github.com/edwinb/idris2-vim), Serhii Khoma <srghma@gmail.com>
" Author: raichoo <raichoo@googlemail.com>
" Last Change: 2024 Nov 05
" License: Vim (see :h license)
" Repository: https://github.com/ShinKage/idris2-nvim
"
" indentation for idris (idris-lang.org)
"
" Based on haskell indentation by motemen <motemen@gmail.com>
"
" Indentation configuration variables:
"
" g:idris2_indent_if (default: 3)
" Controls indentation after 'if' statements
" Example:
" if condition
" >>>then expr
" >>>else expr
"
" g:idris2_indent_case (default: 5)
" Controls indentation of case expressions
" Example:
" case x of
" >>>>>Left y => ...
" >>>>>Right z => ...
"
" g:idris2_indent_let (default: 4)
" Controls indentation after 'let' bindings
" Example:
" let x = expr in
" >>>>body
"
" g:idris2_indent_rewrite (default: 8)
" Controls indentation after 'rewrite' expressions
" Example:
" rewrite proof in
" >>>>>>>>expr
"
" g:idris2_indent_where (default: 6)
" Controls indentation of 'where' blocks
" Example:
" function args
" >>>>>>where helper = expr
"
" g:idris2_indent_do (default: 3)
" Controls indentation in 'do' blocks
" Example:
" do x <- action
" >>>y <- action
"
" Example configuration in .vimrc:
" let g:idris2_indent_if = 2
if exists('b:did_indent')
finish
endif
setlocal indentexpr=GetIdrisIndent()
setlocal indentkeys=!^F,o,O,}
let b:did_indent = 1
let b:undo_indent = "setlocal indentexpr< indentkeys<"
" we want to use line continuations (\) BEGINNING
let s:cpo_save = &cpo
set cpo&vim
" Define defaults for indent configuration
let s:indent_defaults = {
\ 'idris2_indent_if': 3,
\ 'idris2_indent_case': 5,
\ 'idris2_indent_let': 4,
\ 'idris2_indent_rewrite': 8,
\ 'idris2_indent_where': 6,
\ 'idris2_indent_do': 3
\ }
" we want to use line continuations (\) END
let &cpo = s:cpo_save
unlet s:cpo_save
" Set up indent settings with user overrides
for [key, default] in items(s:indent_defaults)
let varname = 'g:' . key
if !exists(varname)
execute 'let' varname '=' default
endif
endfor
if exists("*GetIdrisIndent")
finish
endif
function! GetIdrisIndent()
let prevline = getline(v:lnum - 1)
if prevline =~ '\s\+(\s*.\+\s\+:\s\+.\+\s*)\s\+->\s*$'
return match(prevline, '(')
elseif prevline =~ '\s\+{\s*.\+\s\+:\s\+.\+\s*}\s\+->\s*$'
return match(prevline, '{')
endif
if prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$'
let s = match(prevline, '[:=]')
if s > 0
return s + 2
else
return match(prevline, '\S')
endif
endif
if prevline =~ '[{([][^})\]]\+$'
return match(prevline, '[{([]')
endif
if prevline =~ '\<let\>\s\+.\+\<in\>\s*$'
return match(prevline, '\<let\>') + g:idris2_indent_let
endif
if prevline =~ '\<rewrite\>\s\+.\+\<in\>\s*$'
return match(prevline, '\<rewrite\>') + g:idris2_indent_rewrite
endif
if prevline !~ '\<else\>'
let s = match(prevline, '\<if\>.*\&.*\zs\<then\>')
if s > 0
return s
endif
let s = match(prevline, '\<if\>')
if s > 0
return s + g:idris2_indent_if
endif
endif
if prevline =~ '\(\<where\>\|\<do\>\|=\|[{([]\)\s*$'
return match(prevline, '\S') + &shiftwidth
endif
if prevline =~ '\<where\>\s\+\S\+.*$'
return match(prevline, '\<where\>') + g:idris2_indent_where
endif
if prevline =~ '\<do\>\s\+\S\+.*$'
return match(prevline, '\<do\>') + g:idris2_indent_do
endif
if prevline =~ '^\s*\<\(co\)\?data\>\s\+[^=]\+\s\+=\s\+\S\+.*$'
return match(prevline, '=')
endif
if prevline =~ '\<with\>\s\+([^)]*)\s*$'
return match(prevline, '\S') + &shiftwidth
endif
if prevline =~ '\<case\>\s\+.\+\<of\>\s*$'
return match(prevline, '\<case\>') + g:idris2_indent_case
endif
if prevline =~ '^\s*\(\<namespace\>\|\<\(co\)\?data\>\)\s\+\S\+\s*$'
return match(prevline, '\(\<namespace\>\|\<\(co\)\?data\>\)') + &shiftwidth
endif
if prevline =~ '^\s*\(\<using\>\|\<parameters\>\)\s*([^(]*)\s*$'
return match(prevline, '\(\<using\>\|\<parameters\>\)') + &shiftwidth
endif
if prevline =~ '^\s*\<mutual\>\s*$'
return match(prevline, '\<mutual\>') + &shiftwidth
endif
let line = getline(v:lnum)
if (line =~ '^\s*}\s*' && prevline !~ '^\s*;')
return match(prevline, '\S') - &shiftwidth
endif
return match(prevline, '\S')
endfunction
" vim:et:sw=2:sts=2

View File

@@ -0,0 +1,68 @@
" Description: InstallShield indenter
" Author: Johannes Zellner <johannes@zellner.org>
" Last Change: Tue, 27 Apr 2004 14:54:59 CEST
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal autoindent
setlocal indentexpr=GetIshdIndent(v:lnum)
setlocal indentkeys&
setlocal indentkeys+==else,=elseif,=endif,=end,=begin,<:>
" setlocal indentkeys-=0#
let b:undo_indent = "setl ai< indentexpr< indentkeys<"
" Only define the function once.
if exists("*GetIshdIndent")
finish
endif
fun! GetIshdIndent(lnum)
" labels and preprocessor get zero indent immediately
let this_line = getline(a:lnum)
let LABELS_OR_PREPROC = '^\s*\(\<\k\+\>:\s*$\|#.*\)'
let LABELS_OR_PREPROC_EXCEPT = '^\s*\<default\+\>:'
if this_line =~ LABELS_OR_PREPROC && this_line !~ LABELS_OR_PREPROC_EXCEPT
return 0
endif
" Find a non-blank line above the current line.
" Skip over labels and preprocessor directives.
let lnum = a:lnum
while lnum > 0
let lnum = prevnonblank(lnum - 1)
let previous_line = getline(lnum)
if previous_line !~ LABELS_OR_PREPROC || previous_line =~ LABELS_OR_PREPROC_EXCEPT
break
endif
endwhile
" Hit the start of the file, use zero indent.
if lnum == 0
return 0
endif
let ind = indent(lnum)
" Add
if previous_line =~ '^\s*\<\(function\|begin\|switch\|case\|default\|if.\{-}then\|else\|elseif\|while\|repeat\)\>'
let ind = ind + shiftwidth()
endif
" Subtract
if this_line =~ '^\s*\<endswitch\>'
let ind = ind - 2 * shiftwidth()
elseif this_line =~ '^\s*\<\(begin\|end\|endif\|endwhile\|else\|elseif\|until\)\>'
let ind = ind - shiftwidth()
elseif this_line =~ '^\s*\<\(case\|default\)\>'
if previous_line !~ '^\s*\<switch\>'
let ind = ind - shiftwidth()
endif
endif
return ind
endfun

View File

@@ -0,0 +1,50 @@
" Vim indent file
" Language: J
" Maintainer: David Bürgin <dbuergin@gluet.ch>
" URL: https://gitlab.com/glts/vim-j
" Last Change: 2015-01-11
if exists('b:did_indent')
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetJIndent()
setlocal indentkeys-=0{,0},:,0#
setlocal indentkeys+=0),0<:>,=case.,=catch.,=catchd.,=catcht.,=do.,=else.,=elseif.,=end.,=fcase.
let b:undo_indent = 'setlocal indentkeys< indentexpr<'
if exists('*GetJIndent')
finish
endif
" If g:j_indent_definitions is true, the bodies of explicit definitions of
" adverbs, conjunctions, and verbs will be indented. Default is false (0).
if !exists('g:j_indent_definitions')
let g:j_indent_definitions = 0
endif
function GetJIndent() abort
let l:prevlnum = prevnonblank(v:lnum - 1)
if l:prevlnum == 0
return 0
endif
let l:indent = indent(l:prevlnum)
let l:prevline = getline(l:prevlnum)
if l:prevline =~# '^\s*\%(case\|catch[dt]\=\|do\|else\%(if\)\=\|fcase\|for\%(_\a\k*\)\=\|if\|select\|try\|whil\%(e\|st\)\)\.\%(\%(\<end\.\)\@!.\)*$'
" Increase indentation after an initial control word that starts or
" continues a block and is not terminated by "end."
let l:indent += shiftwidth()
elseif g:j_indent_definitions && (l:prevline =~# '\<\%([1-4]\|13\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(:\s*0\|def\s\+0\|define\)\>' || l:prevline =~# '^\s*:\s*$')
" Increase indentation in explicit definitions of adverbs, conjunctions,
" and verbs
let l:indent += shiftwidth()
endif
" Decrease indentation in lines that start with either control words that
" continue or end a block, or the special items ")" and ":"
if getline(v:lnum) =~# '^\s*\%()\|:\|\%(case\|catch[dt]\=\|do\|else\%(if\)\=\|end\|fcase\)\.\)'
let l:indent -= shiftwidth()
endif
return l:indent
endfunction

View File

@@ -0,0 +1,150 @@
" Vim indent file
" Language: Java
" Previous Maintainer: Toby Allsopp <toby.allsopp@peace.com>
" Current Maintainer: Hong Xu <hong@topbug.net>
" Homepage: http://www.vim.org/scripts/script.php?script_id=3899
" https://github.com/xuhdev/indent-java.vim
" Last Change: 2016 Mar 7
" Version: 1.1
" License: Same as Vim.
" Copyright (c) 2012-2016 Hong Xu
" Before 2012, this file was maintained by Toby Allsopp.
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" Indent Java anonymous classes correctly.
setlocal cindent cinoptions& cinoptions+=j1
" The "extends" and "implements" lines start off with the wrong indent.
setlocal indentkeys& indentkeys+=0=extends indentkeys+=0=implements
" Set the function to do the work.
setlocal indentexpr=GetJavaIndent()
let b:undo_indent = "set cin< cino< indentkeys< indentexpr<"
" Only define the function once.
if exists("*GetJavaIndent")
finish
endif
let s:keepcpo= &cpo
set cpo&vim
function! SkipJavaBlanksAndComments(startline)
let lnum = a:startline
while lnum > 1
let lnum = prevnonblank(lnum)
if getline(lnum) =~ '\*/\s*$'
while getline(lnum) !~ '/\*' && lnum > 1
let lnum = lnum - 1
endwhile
if getline(lnum) =~ '^\s*/\*'
let lnum = lnum - 1
else
break
endif
elseif getline(lnum) =~ '^\s*//'
let lnum = lnum - 1
else
break
endif
endwhile
return lnum
endfunction
function GetJavaIndent()
" Java is just like C; use the built-in C indenting and then correct a few
" specific cases.
let theIndent = cindent(v:lnum)
" If we're in the middle of a comment then just trust cindent
if getline(v:lnum) =~ '^\s*\*'
return theIndent
endif
" find start of previous line, in case it was a continuation line
let lnum = SkipJavaBlanksAndComments(v:lnum - 1)
" If the previous line starts with '@', we should have the same indent as
" the previous one
if getline(lnum) =~ '^\s*@.*$'
return indent(lnum)
endif
let prev = lnum
while prev > 1
let next_prev = SkipJavaBlanksAndComments(prev - 1)
if getline(next_prev) !~ ',\s*$'
break
endif
let prev = next_prev
endwhile
" Try to align "throws" lines for methods and "extends" and "implements" for
" classes.
if getline(v:lnum) =~ '^\s*\(throws\|extends\|implements\)\>'
\ && getline(lnum) !~ '^\s*\(throws\|extends\|implements\)\>'
let theIndent = theIndent + shiftwidth()
endif
" correct for continuation lines of "throws", "implements" and "extends"
let cont_kw = matchstr(getline(prev),
\ '^\s*\zs\(throws\|implements\|extends\)\>\ze.*,\s*$')
if strlen(cont_kw) > 0
let amount = strlen(cont_kw) + 1
if getline(lnum) !~ ',\s*$'
let theIndent = theIndent - (amount + shiftwidth())
if theIndent < 0
let theIndent = 0
endif
elseif prev == lnum
let theIndent = theIndent + amount
if cont_kw ==# 'throws'
let theIndent = theIndent + shiftwidth()
endif
endif
elseif getline(prev) =~ '^\s*\(throws\|implements\|extends\)\>'
\ && (getline(prev) =~ '{\s*$'
\ || getline(v:lnum) =~ '^\s*{\s*$')
let theIndent = theIndent - shiftwidth()
endif
" When the line starts with a }, try aligning it with the matching {,
" skipping over "throws", "extends" and "implements" clauses.
if getline(v:lnum) =~ '^\s*}\s*\(//.*\|/\*.*\)\=$'
call cursor(v:lnum, 1)
silent normal! %
let lnum = line('.')
if lnum < v:lnum
while lnum > 1
let next_lnum = SkipJavaBlanksAndComments(lnum - 1)
if getline(lnum) !~ '^\s*\(throws\|extends\|implements\)\>'
\ && getline(next_lnum) !~ ',\s*$'
break
endif
let lnum = prevnonblank(next_lnum)
endwhile
return indent(lnum)
endif
endif
" Below a line starting with "}" never indent more. Needed for a method
" below a method with an indented "throws" clause.
let lnum = SkipJavaBlanksAndComments(v:lnum - 1)
if getline(lnum) =~ '^\s*}\s*\(//.*\|/\*.*\)\=$' && indent(lnum) < theIndent
let theIndent = indent(lnum)
endif
return theIndent
endfunction
let &cpo = s:keepcpo
unlet s:keepcpo
" vi: sw=2 et

View File

@@ -0,0 +1,486 @@
" Vim indent file
" Language: Javascript
" Maintainer: Chris Paul ( https://github.com/bounceme )
" URL: https://github.com/pangloss/vim-javascript
" Last Change: December 4, 2017
" Only load this indent file when no other was loaded.
if exists('b:did_indent')
finish
endif
let b:did_indent = 1
" Now, set up our indentation expression and keys that trigger it.
setlocal indentexpr=GetJavascriptIndent()
setlocal autoindent nolisp nosmartindent
setlocal indentkeys+=0],0)
" Testable with something like:
" vim -eNs "+filetype plugin indent on" "+syntax on" "+set ft=javascript" \
" "+norm! gg=G" '+%print' '+:q!' testfile.js \
" | diff -uBZ testfile.js -
let b:undo_indent = 'setlocal indentexpr< smartindent< autoindent< indentkeys<'
" Only define the function once.
if exists('*GetJavascriptIndent')
finish
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()
return shiftwidth()
endfunction
else
function s:sw()
return &l:shiftwidth ? &l:shiftwidth : &l:tabstop
endfunction
endif
" Performance for forwards search(): start search at pos rather than masking
" matches before pos.
let s:z = has('patch-7.4.984') ? 'z' : ''
" Expression used to check whether we should skip a match with searchpair().
let s:skip_expr = "s:SynAt(line('.'),col('.')) =~? b:syng_strcom"
let s:in_comm = s:skip_expr[:-14] . "'comment\\|doc'"
let s:rel = has('reltime')
" searchpair() wrapper
if s:rel
function s:GetPair(start,end,flags,skip)
return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,s:l1,a:skip ==# 's:SkipFunc()' ? 2000 : 200)
endfunction
else
function s:GetPair(start,end,flags,skip)
return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,s:l1)
endfunction
endif
function s:SynAt(l,c)
let byte = line2byte(a:l) + a:c - 1
let pos = index(s:synid_cache[0], byte)
if pos == -1
let s:synid_cache[:] += [[byte], [synIDattr(synID(a:l, a:c, 0), 'name')]]
endif
return s:synid_cache[1][pos]
endfunction
function s:ParseCino(f)
let [divider, n, cstr] = [0] + matchlist(&cino,
\ '\%(.*,\)\=\%(\%d'.char2nr(a:f).'\(-\)\=\([.s0-9]*\)\)\=')[1:2]
for c in split(cstr,'\zs')
if c == '.' && !divider
let divider = 1
elseif c ==# 's'
if n !~ '\d'
return n . s:sw() + 0
endif
let n = str2nr(n) * s:sw()
break
else
let [n, divider] .= [c, 0]
endif
endfor
return str2nr(n) / max([str2nr(divider),1])
endfunction
" Optimized {skip} expr, only callable from the search loop which
" GetJavascriptIndent does to find the containing [[{(] (side-effects)
function s:SkipFunc()
if s:top_col == 1
throw 'out of bounds'
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)
return 1
endif
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
function s:AlternatePair()
let [pat, l:for] = ['[][(){};]', 2]
while s:SearchLoop(pat,'bW','s:SkipFunc()')
if s:LookingAt() == ';'
if !l:for
if s:GetPair('{','}','bW','s:SkipFunc()')
return
endif
break
else
let [pat, l:for] = ['[{}();]', l:for - 1]
endif
else
let idx = stridx('])}',s:LookingAt())
if idx == -1
return
elseif !s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:SkipFunc()')
break
endif
endif
endwhile
throw 'out of bounds'
endfunction
function s:Nat(int)
return a:int * (a:int > 0)
endfunction
function s:LookingAt()
return getline('.')[col('.')-1]
endfunction
function s:Token()
return s:LookingAt() =~ '\k' ? expand('<cword>') : s:LookingAt()
endfunction
function s:PreviousToken(...)
let [l:pos, tok] = [getpos('.'), '']
if search('\m\k\{1,}\|\S','ebW')
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
else
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 tok
endfunction
function s:Pure(f,...)
return eval("[call(a:f,a:000),cursor(a:firstline,".col('.').")][0]")
endfunction
function s:SearchLoop(pat,flags,expr)
return s:GetPair(a:pat,'\_$.',a:flags,a:expr)
endfunction
function s:ExprCol()
if getline('.')[col('.')-2] == ':'
return 1
endif
let bal = 0
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() == '?'
if getline('.')[col('.'):col('.')+1] =~ '^\.\d\@!'
continue
elseif !bal
return 1
endif
let bal += 1
elseif s:LookingAt() == '{'
return !s:IsBlock()
elseif !s:GetPair('{','}','bW',s:skip_expr)
break
endif
endwhile
endfunction
" configurable regexes that define continuation lines, not including (, {, or [.
let s:opfirst = '^' . get(g:,'javascript_opfirst',
\ '\C\%([<>=,.?^%|/&]\|\([-:+]\)\1\@!\|\*\+\|!=\|in\%(stanceof\)\=\>\)')
let s:continuation = get(g:,'javascript_continuation',
\ '\C\%([<=,.~!?/*^%|&:]\|+\@<!+\|-\@<!-\|=\@<!>\|\<\%(typeof\|new\|delete\|void\|in\|instanceof\|await\)\)') . '$'
function s:Continues()
let tok = matchstr(strpart(getline('.'),col('.')-15,15),s:continuation)
if tok =~ '[a-z:]'
return tok == ':' ? s:ExprCol() : s:PreviousToken() != '.'
elseif tok !~ '[/>]'
return tok isnot ''
endif
return s:SynAt(line('.'),col('.')) !~? (tok == '>' ? 'jsflow\|^html' : 'regex')
endfunction
" Check if line 'lnum' has a balanced amount of parentheses.
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(' ' . a:line[pos],'[[({]')
if l:open < 0
return
endif
endif
let pos = match(a:line, !l:open ? '[][(){}]' : '()' =~ a:line[pos] ?
\ '[()]' : '{}' =~ a:line[pos] ? '[{}]' : '[][]', pos + 1)
endwhile
return !l:open
endfunction
function s:OneScope()
if s:LookingAt() == ')' && s:GetPair('(', ')', 'bW', s:skip_expr)
let tok = s:PreviousToken()
return (count(split('for if let while with'),tok) ||
\ tok =~# '^await$\|^each$' && s:PreviousToken() ==# 'for') &&
\ 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
endfunction
function s:DoWhile()
let cpos = searchpos('\m\<','cbW')
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
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(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()
let b_l += 1
elseif !a:cont || b_l || ind < indent(a:firstline)
break
else
call cursor(0,1)
endif
let ind = min([ind, indent('.')])
if s:PreviousToken() is ''
break
endif
endwhile
return b_l
endfunction
function s:IsSwitch()
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'
return s:Pure('eval',"s:PreviousToken() !~# '^\\%(im\\|ex\\)port$' || s:PreviousToken() == '.'")
elseif tok ==# 'of'
return s:Pure('eval',"!s:GetPair('[[({]','[])}]','bW',s:skip_expr) || s:LookingAt() != '(' ||"
\ ."s:{s:PreviousToken() ==# 'await' ? 'Previous' : ''}Token() !=# 'for' || s:PreviousToken() == '.'")
endif
return index(split('return const let import export extends yield default delete var await void typeof throw case new in instanceof')
\ ,tok) < (line('.') != a:firstline) || s:Pure('s:PreviousToken') == '.'
elseif tok == '>'
return getline('.')[col('.')-2] == '=' || s:SynAt(line('.'),col('.')) =~? 'jsflow\|^html'
elseif tok == '*'
return s:Pure('s:PreviousToken') == ':'
elseif tok == ':'
return s:Pure('eval',"s:PreviousToken() =~ '^\\K\\k*$' && !s:ExprCol()")
elseif tok == '/'
return s:SynAt(line('.'),col('.')) =~? 'regex'
elseif tok !~ '[=~!<,.?^%|&([]'
return tok !~ '[-+]' || line('.') != a:firstline && getline('.')[col('.')-2] == tok
endif
endfunction
function GetJavascriptIndent()
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
let s:stack = [''] + map(synstack(v:lnum,1),"synIDattr(v:val,'name')")
" start with strings,comments,etc.
if s:stack[-1] =~? 'comment\|doc'
if l:line =~ '^\s*\*'
return cindent(v:lnum)
elseif l:line !~ '^\s*\/[/*]'
return -1
endif
elseif s:stack[-1] =~? b:syng_str
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
endif
let s:l1 = max([0,prevnonblank(v:lnum) - (s:rel ? 2000 : 1000),
\ get(get(b:,'hi_indent',{}),'blocklnr')])
call cursor(v:lnum,1)
if s:PreviousToken() is ''
return
endif
let [l:lnum, pline] = [line('.'), getline('.')[:col('.')-1]]
let l:line = substitute(l:line,'^\s*','','')
let l:line_raw = l:line
if l:line[:1] == '/*'
let l:line = substitute(l:line,'^\%(\/\*.\{-}\*\/\s*\)*','','')
endif
if l:line =~ '^\/[/*]'
let l:line = ''
endif
" the containing paren, bracket, or curly. Many hacks for performance
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,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,
\ max([s:l1, &smc ? search('\m^.\{'.&smc.',}','nbW',s:l1 + 1) + 1 : 0])]
try
if idx != -1
call s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:SkipFunc()')
elseif getline(v:lnum) !~ '^\S' && s:stack[-1] =~? 'block\|^jsobject$'
call s:GetPair('{','}','bW','s:SkipFunc()')
else
call s:AlternatePair()
endif
catch /^\Cout of bounds$/
call cursor(v:lnum,1)
endtry
let b:js_cache[1:] = line('.') == v:lnum ? [0,0] : getpos('.')[1:2]
endif
let [b:js_cache[0], num] = [v:lnum, b:js_cache[1]]
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:in_jsx && s:LookingAt() == ')' && s:GetPair('(',')','bW',s:skip_expr)
if ilnum == num
let [num, num_ind] = [line('.'), indent('.')]
endif
if idx == -1 && s:PreviousToken() ==# 'switch' && s:IsSwitch()
let l:switch_offset = &cino !~ ':' ? s:sw() : s:ParseCino(':')
if pline[-1:] != '.' && l:line =~# '^\%(default\|case\)\>'
return s:Nat(num_ind + l:switch_offset)
elseif &cino =~ '='
let l:case_offset = s:ParseCino('=')
endif
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()
let is_op = s:sw()
endif
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(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('(')
if !pval
let [Wval, vcol] = [s:ParseCino('W'), virtcol('.')]
if search('\m\S','W',num)
return s:ParseCino('w') ? vcol : virtcol('.')-1
endif
return Wval ? s:Nat(num_ind + Wval) : vcol
endif
return s:Nat(num_ind + pval + searchpair('\m(','','\m)','nbrmW',s:skip_expr,num) * s:sw())
endif
" main return
if l:line =~ '^[])}]\|^|}'
if l:line_raw[0] == ')'
if s:ParseCino('M')
return indent(l:lnum)
elseif num && &cino =~# 'm' && !s:ParseCino('m')
return virtcol('.') - 1
endif
endif
return num_ind
elseif num
return s:Nat(num_ind + get(l:,'case_offset',s:sw()) + l:switch_offset + b_l + is_op)
endif
let nest = get(get(b:, 'hi_indent', {}), 'blocklnr')
if nest
return indent(nextnonblank(nest + 1)) + b_l + is_op
endif
return b_l + is_op
endfunction
let &cpo = s:cpo_save
unlet s:cpo_save

View File

@@ -0,0 +1,2 @@
" Placeholder for backwards compatilibity: .jsx used to stand for JavaScript.
runtime! indent/javascript.vim

View File

@@ -0,0 +1,173 @@
" Vim indent file
" Language: JSON
" Maintainer: Eli Parra <eli@elzr.com> https://github.com/elzr/vim-json
" Last Change: 2020 Aug 30
" https://github.com/jakar/vim-json/commit/20b650e22aa750c4ab6a66aa646bdd95d7cd548a#diff-e81fc111b2052e306d126bd9989f7b7c
" 2022 Sep 07: b:undo_indent added by Doug Kearns
" Original Author: Rogerz Zhang <rogerz.zhang at gmail.com> http://github.com/rogerz/vim-json
" Acknowledgement: Based off of vim-javascript maintained by Darrick Wiebe
" http://www.vim.org/scripts/script.php?script_id=2765
" 0. Initialization {{{1
" =================
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal nosmartindent
" Now, set up our indentation expression and keys that trigger it.
setlocal indentexpr=GetJSONIndent(v:lnum)
setlocal indentkeys=0{,0},0),0[,0],!^F,o,O,e
let b:undo_indent = "setl inde< indk< si<"
" Only define the function once.
if exists("*GetJSONIndent")
finish
endif
let s:cpo_save = &cpo
set cpo&vim
" 1. Variables {{{1
" ============
let s:line_term = '\s*\%(\%(\/\/\).*\)\=$'
" Regex that defines blocks.
let s:block_regex = '\%({\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term
" 2. Auxiliary Functions {{{1
" ======================
" Check if the character at lnum:col is inside a string.
function s:IsInString(lnum, col)
return synIDattr(synID(a:lnum, a:col, 1), 'name') == 'jsonString'
endfunction
" Find line above 'lnum' that isn't empty, or in a string.
function s:PrevNonBlankNonString(lnum)
let lnum = prevnonblank(a:lnum)
while lnum > 0
" If the line isn't empty or in a string, end search.
let line = getline(lnum)
if !(s:IsInString(lnum, 1) && s:IsInString(lnum, strlen(line)))
break
endif
let lnum = prevnonblank(lnum - 1)
endwhile
return lnum
endfunction
" Check if line 'lnum' has more opening brackets than closing ones.
function s:LineHasOpeningBrackets(lnum)
let open_0 = 0
let open_2 = 0
let open_4 = 0
let line = getline(a:lnum)
let pos = match(line, '[][(){}]', 0)
while pos != -1
let idx = stridx('(){}[]', line[pos])
if idx % 2 == 0
let open_{idx} = open_{idx} + 1
else
let open_{idx - 1} = open_{idx - 1} - 1
endif
let pos = match(line, '[][(){}]', pos + 1)
endwhile
return (open_0 > 0) . (open_2 > 0) . (open_4 > 0)
endfunction
function s:Match(lnum, regex)
let col = match(getline(a:lnum), a:regex) + 1
return col > 0 && !s:IsInString(a:lnum, col) ? col : 0
endfunction
" 3. GetJSONIndent Function {{{1
" =========================
function GetJSONIndent(...)
" 3.1. Setup {{{2
" ----------
" For the current line, use the first argument if given, else v:lnum
let clnum = a:0 ? a:1 : v:lnum
" Set up variables for restoring position in file. Could use clnum here.
let vcol = col('.')
" 3.2. Work on the current line {{{2
" -----------------------------
" Get the current line.
let line = getline(clnum)
let ind = -1
" If we got a closing bracket on an empty line, find its match and indent
" according to it.
let col = matchend(line, '^\s*[]}]')
if col > 0 && !s:IsInString(clnum, col)
call cursor(clnum, col)
let bs = strpart('{}[]', stridx('}]', line[col - 1]) * 2, 2)
let pairstart = escape(bs[0], '[')
let pairend = escape(bs[1], ']')
let pairline = searchpair(pairstart, '', pairend, 'bW')
if pairline > 0
let ind = indent(pairline)
else
let ind = virtcol('.') - 1
endif
return ind
endif
" If we are in a multi-line string, don't do anything to it.
if s:IsInString(clnum, matchend(line, '^\s*') + 1)
return indent('.')
endif
" 3.3. Work on the previous line. {{{2
" -------------------------------
let lnum = prevnonblank(clnum - 1)
if lnum == 0
return 0
endif
" Set up variables for current line.
let line = getline(lnum)
let ind = indent(lnum)
" If the previous line ended with a block opening, add a level of indent.
" if s:Match(lnum, s:block_regex)
" return indent(lnum) + shiftwidth()
" endif
" If the previous line contained an opening bracket, and we are still in it,
" add indent depending on the bracket type.
if line =~ '[[({]'
let counts = s:LineHasOpeningBrackets(lnum)
if counts[0] == '1' || counts[1] == '1' || counts[2] == '1'
return ind + shiftwidth()
else
call cursor(clnum, vcol)
end
endif
" }}}2
return ind
endfunction
" }}}1
let &cpo = s:cpo_save
unlet s:cpo_save
" vim:set sw=2 sts=2 ts=8 noet:

View File

@@ -0,0 +1,11 @@
" Vim indent file
" Language: JSON5
" Maintainer: The Vim Project <https://github.com/vim/vim>
" Last Change: 2024-03-26
if exists("b:did_indent")
finish
endif
" Same as jsonc indenting for now
runtime! indent/jsonc.vim

View File

@@ -0,0 +1,192 @@
" Vim indent file
" Language: JSONC (JSON with Comments)
" Original Author: Izhak Jakov <izhak724@gmail.com>
" Acknowledgement: Based off of vim-json maintained by Eli Parra <eli@elzr.com>
" https://github.com/elzr/vim-json
" Last Change: 2021-07-01
" 2023 Aug 28 by Vim Project (undo_indent)
" 0. Initialization {{{1
" =================
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal nosmartindent
" Now, set up our indentation expression and keys that trigger it.
setlocal indentexpr=GetJSONCIndent()
setlocal indentkeys=0{,0},0),0[,0],!^F,o,O,e
let b:undo_indent = "setlocal indentexpr< indentkeys< smartindent<"
" Only define the function once.
if exists("*GetJSONCIndent")
finish
endif
let s:cpo_save = &cpo
set cpo&vim
" 1. Variables {{{1
" ============
let s:line_term = '\s*\%(\%(\/\/\).*\)\=$'
" Regex that defines blocks.
let s:block_regex = '\%({\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term
" 2. Auxiliary Functions {{{1
" ======================
" Check if the character at lnum:col is inside a string.
function s:IsInString(lnum, col)
return synIDattr(synID(a:lnum, a:col, 1), 'name') == 'jsonString'
endfunction
" Find line above 'lnum' that isn't empty, or in a string.
function s:PrevNonBlankNonString(lnum)
let lnum = prevnonblank(a:lnum)
while lnum > 0
" If the line isn't empty or in a string, end search.
let line = getline(lnum)
if !(s:IsInString(lnum, 1) && s:IsInString(lnum, strlen(line)))
break
endif
let lnum = prevnonblank(lnum - 1)
endwhile
return lnum
endfunction
" Check if line 'lnum' has more opening brackets than closing ones.
function s:LineHasOpeningBrackets(lnum)
let open_0 = 0
let open_2 = 0
let open_4 = 0
let line = getline(a:lnum)
let pos = match(line, '[][(){}]', 0)
while pos != -1
let idx = stridx('(){}[]', line[pos])
if idx % 2 == 0
let open_{idx} = open_{idx} + 1
else
let open_{idx - 1} = open_{idx - 1} - 1
endif
let pos = match(line, '[][(){}]', pos + 1)
endwhile
return (open_0 > 0) . (open_2 > 0) . (open_4 > 0)
endfunction
function s:Match(lnum, regex)
let col = match(getline(a:lnum), a:regex) + 1
return col > 0 && !s:IsInString(a:lnum, col) ? col : 0
endfunction
" 3. GetJSONCIndent Function {{{1
" =========================
function GetJSONCIndent()
if !exists("s:inside_comment")
let s:inside_comment = 0
endif
" 3.1. Setup {{{2
" ----------
" Set up variables for restoring position in file. Could use v:lnum here.
let vcol = col('.')
" 3.2. Work on the current line {{{2
" -----------------------------
" Get the current line.
let line = getline(v:lnum)
let ind = -1
if s:inside_comment == 0
" TODO iterate through all the matches in a line
let col = matchend(line, '\/\*')
if col > 0 && !s:IsInString(v:lnum, col)
let s:inside_comment = 1
endif
endif
" If we're in the middle of a comment
if s:inside_comment == 1
let col = matchend(line, '\*\/')
if col > 0 && !s:IsInString(v:lnum, col)
let s:inside_comment = 0
endif
return ind
endif
if line =~ '^\s*//'
return ind
endif
" If we got a closing bracket on an empty line, find its match and indent
" according to it.
let col = matchend(line, '^\s*[]}]')
if col > 0 && !s:IsInString(v:lnum, col)
call cursor(v:lnum, col)
let bs = strpart('{}[]', stridx('}]', line[col - 1]) * 2, 2)
let pairstart = escape(bs[0], '[')
let pairend = escape(bs[1], ']')
let pairline = searchpair(pairstart, '', pairend, 'bW')
if pairline > 0
let ind = indent(pairline)
else
let ind = virtcol('.') - 1
endif
return ind
endif
" If we are in a multi-line string, don't do anything to it.
if s:IsInString(v:lnum, matchend(line, '^\s*') + 1)
return indent('.')
endif
" 3.3. Work on the previous line. {{{2
" -------------------------------
let lnum = prevnonblank(v:lnum - 1)
if lnum == 0
return 0
endif
" Set up variables for current line.
let line = getline(lnum)
let ind = indent(lnum)
" If the previous line ended with a block opening, add a level of indent.
" if s:Match(lnum, s:block_regex)
" return indent(lnum) + shiftwidth()
" endif
" If the previous line contained an opening bracket, and we are still in it,
" add indent depending on the bracket type.
if line =~ '[[({]'
let counts = s:LineHasOpeningBrackets(lnum)
if counts[0] == '1' || counts[1] == '1' || counts[2] == '1'
return ind + shiftwidth()
else
call cursor(v:lnum, vcol)
end
endif
" }}}2
return ind
endfunction
" }}}1
let &cpo = s:cpo_save
unlet s:cpo_save
" vim:set sw=2 sts=2 ts=8 noet:

View File

@@ -0,0 +1,17 @@
" Vim filetype indent file
" Language: JSP files
" Maintainer: David Fishburn <fishburn@ianywhere.com>
" Version: 1.0
" Last Change: Wed Nov 08 2006 11:08:05 AM
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
" If there has been no specific JSP indent script created,
" use the default html indent script which will handle
" html, javascript and most of the JSP constructs.
runtime! indent/html.vim

View File

@@ -0,0 +1,500 @@
" Vim indent file
" Language: Julia
" Maintainer: Carlo Baldassi <carlobaldassi@gmail.com>
" Homepage: https://github.com/JuliaEditorSupport/julia-vim
" Last Change: 2022 Jun 14
" 2023 Aug 28 by Vim Project (undo_indent)
" Notes: originally based on Bram Moolenaar's indent file for vim
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal autoindent
setlocal indentexpr=GetJuliaIndent()
setlocal indentkeys+==end,=else,=catch,=finally,),],}
setlocal indentkeys-=0#
setlocal indentkeys-=:
setlocal indentkeys-=0{
setlocal indentkeys-=0}
setlocal nosmartindent
let b:undo_indent = "setl ai< inde< indk< si<"
" Only define the function once.
if exists("*GetJuliaIndent")
finish
endif
let s:skipPatternsBasic = '\<julia\%(Comment\%([LM]\|Delim\)\)\>'
let s:skipPatterns = '\<julia\%(Comprehension\%(For\|If\)\|RangeKeyword\|Comment\%([LM]\|Delim\)\|\%([bs]\|Shell\|Printf\|Doc\)\?String\|StringPrefixed\|DocStringM\(Raw\)\?\|RegEx\|SymbolS\?\|Macro\|Dotted\)\>'
function JuliaMatch(lnum, str, regex, st, ...)
let s = a:st
let e = a:0 > 0 ? a:1 : -1
let basic_skip = a:0 > 1 ? a:2 : 'all'
let skip = basic_skip ==# 'basic' ? s:skipPatternsBasic : s:skipPatterns
while 1
let f = match(a:str, '\C' . a:regex, s)
if e >= 0 && f >= e
return -1
endif
if f >= 0
let attr = synIDattr(synID(a:lnum,f+1,1),"name")
let attrT = synIDattr(synID(a:lnum,f+1,0),"name")
if attr =~# skip || attrT =~# skip
let s = f+1
continue
endif
endif
break
endwhile
return f
endfunction
function GetJuliaNestingStruct(lnum, ...)
" Auxiliary function to inspect the block structure of a line
let line = getline(a:lnum)
let s = a:0 > 0 ? a:1 : 0
let e = a:0 > 1 ? a:2 : -1
let blocks_stack = []
let num_closed_blocks = 0
while 1
let fb = JuliaMatch(a:lnum, line, '\<\%(if\|else\%(if\)\?\|while\|for\|try\|catch\|finally\|\%(staged\)\?function\|macro\|begin\|mutable\s\+struct\|\%(mutable\s\+\)\@<!struct\|\%(abstract\|primitive\)\s\+type\|let\|\%(bare\)\?module\|quote\|do\)\>', s, e)
let fe = JuliaMatch(a:lnum, line, '\<end\>', s, e)
if fb < 0 && fe < 0
" No blocks found
break
end
if fb >= 0 && (fb < fe || fe < 0)
" The first occurrence is an opening block keyword
" Note: some keywords (elseif,else,catch,finally) are both
" closing blocks and opening new ones
let i = JuliaMatch(a:lnum, line, '\<if\>', s)
if i >= 0 && i == fb
let s = i+1
call add(blocks_stack, 'if')
continue
endif
let i = JuliaMatch(a:lnum, line, '\<elseif\>', s)
if i >= 0 && i == fb
let s = i+1
if len(blocks_stack) > 0 && blocks_stack[-1] == 'if'
let blocks_stack[-1] = 'elseif'
elseif (len(blocks_stack) > 0 && blocks_stack[-1] != 'elseif') || len(blocks_stack) == 0
call add(blocks_stack, 'elseif')
let num_closed_blocks += 1
endif
continue
endif
let i = JuliaMatch(a:lnum, line, '\<else\>', s)
if i >= 0 && i == fb
let s = i+1
if len(blocks_stack) > 0 && blocks_stack[-1] =~# '\<\%(else\)\=if\>'
let blocks_stack[-1] = 'else'
else
call add(blocks_stack, 'else')
let num_closed_blocks += 1
endif
continue
endif
let i = JuliaMatch(a:lnum, line, '\<try\>', s)
if i >= 0 && i == fb
let s = i+1
call add(blocks_stack, 'try')
continue
endif
let i = JuliaMatch(a:lnum, line, '\<catch\>', s)
if i >= 0 && i == fb
let s = i+1
if len(blocks_stack) > 0 && blocks_stack[-1] == 'try'
let blocks_stack[-1] = 'catch'
else
call add(blocks_stack, 'catch')
let num_closed_blocks += 1
endif
continue
endif
let i = JuliaMatch(a:lnum, line, '\<finally\>', s)
if i >= 0 && i == fb
let s = i+1
if len(blocks_stack) > 0 && (blocks_stack[-1] == 'try' || blocks_stack[-1] == 'catch')
let blocks_stack[-1] = 'finally'
else
call add(blocks_stack, 'finally')
let num_closed_blocks += 1
endif
continue
endif
let i = JuliaMatch(a:lnum, line, '\<\%(bare\)\?module\>', s)
if i >= 0 && i == fb
let s = i+1
if i == 0
call add(blocks_stack, 'col1module')
else
call add(blocks_stack, 'other')
endif
continue
endif
let i = JuliaMatch(a:lnum, line, '\<\%(while\|for\|function\|macro\|begin\|\%(mutable\s\+\)\?struct\|\%(abstract\|primitive\)\s\+type\|let\|quote\|do\)\>', s)
if i >= 0 && i == fb
if match(line, '\C\<\%(mutable\|abstract\|primitive\)', i) != -1
let s = i+11
else
let s = i+1
endif
call add(blocks_stack, 'other')
continue
endif
" Note: it should be impossible to get here
break
else
" The first occurrence is an 'end'
let s = fe+1
if len(blocks_stack) == 0
let num_closed_blocks += 1
else
call remove(blocks_stack, -1)
endif
continue
endif
" Note: it should be impossible to get here
break
endwhile
let num_open_blocks = len(blocks_stack) - count(blocks_stack, 'col1module')
return [num_open_blocks, num_closed_blocks]
endfunction
function GetJuliaNestingBrackets(lnum, c)
" Auxiliary function to inspect the brackets structure of a line
let line = getline(a:lnum)[0 : (a:c - 1)]
let s = 0
let brackets_stack = []
let last_closed_bracket = -1
while 1
let fb = JuliaMatch(a:lnum, line, '[([{]', s)
let fe = JuliaMatch(a:lnum, line, '[])}]', s)
if fb < 0 && fe < 0
" No brackets found
break
end
if fb >= 0 && (fb < fe || fe < 0)
" The first occurrence is an opening bracket
let i = JuliaMatch(a:lnum, line, '(', s)
if i >= 0 && i == fb
let s = i+1
call add(brackets_stack, ['par',i])
continue
endif
let i = JuliaMatch(a:lnum, line, '\[', s)
if i >= 0 && i == fb
let s = i+1
call add(brackets_stack, ['sqbra',i])
continue
endif
let i = JuliaMatch(a:lnum, line, '{', s)
if i >= 0 && i == fb
let s = i+1
call add(brackets_stack, ['curbra',i])
continue
endif
" Note: it should be impossible to get here
break
else
" The first occurrence is a closing bracket
let i = JuliaMatch(a:lnum, line, ')', s)
if i >= 0 && i == fe
let s = i+1
if len(brackets_stack) > 0 && brackets_stack[-1][0] == 'par'
call remove(brackets_stack, -1)
else
let last_closed_bracket = i + 1
endif
continue
endif
let i = JuliaMatch(a:lnum, line, ']', s)
if i >= 0 && i == fe
let s = i+1
if len(brackets_stack) > 0 && brackets_stack[-1][0] == 'sqbra'
call remove(brackets_stack, -1)
else
let last_closed_bracket = i + 1
endif
continue
endif
let i = JuliaMatch(a:lnum, line, '}', s)
if i >= 0 && i == fe
let s = i+1
if len(brackets_stack) > 0 && brackets_stack[-1][0] == 'curbra'
call remove(brackets_stack, -1)
else
let last_closed_bracket = i + 1
endif
continue
endif
" Note: it should be impossible to get here
break
endif
" Note: it should be impossible to get here
break
endwhile
let first_open_bracket = -1
let last_open_bracket = -1
let infuncargs = 0
if len(brackets_stack) > 0
let first_open_bracket = brackets_stack[0][1]
let last_open_bracket = brackets_stack[-1][1]
if brackets_stack[-1][0] == 'par' && IsFunctionArgPar(a:lnum, last_open_bracket+1)
let infuncargs = 1
endif
endif
return [first_open_bracket, last_open_bracket, last_closed_bracket, infuncargs]
endfunction
let s:bracketBlocks = '\<julia\%(\%(\%(Printf\)\?Par\|SqBra\%(Idx\)\?\|CurBra\)Block\|ParBlockInRange\|StringVars\%(Par\|SqBra\|CurBra\)\|Dollar\%(Par\|SqBra\)\|QuotedParBlockS\?\)\>'
function IsInBrackets(lnum, c)
let stack = map(synstack(a:lnum, a:c), 'synIDattr(v:val, "name")')
call filter(stack, 'v:val =~# s:bracketBlocks')
return len(stack) > 0
endfunction
function IsInDocString(lnum)
let stack = map(synstack(a:lnum, 1), 'synIDattr(v:val, "name")')
call filter(stack, 'v:val =~# "\\<juliaDocString\\(Delim\\|M\\\(Raw\\)\\?\\)\\?\\>"')
return len(stack) > 0
endfunction
function IsInContinuationImportLine(lnum)
let stack = map(synstack(a:lnum, 1), 'synIDattr(v:val, "name")')
call filter(stack, 'v:val =~# "\\<juliaImportLine\\>"')
if len(stack) == 0
return 0
endif
return JuliaMatch(a:lnum, getline(a:lnum), '\<\%(import\|using\|export\)\>', indent(a:lnum)) == -1
endfunction
function IsFunctionArgPar(lnum, c)
if a:c == 0
return 0
endif
let stack = map(synstack(a:lnum, a:c-1), 'synIDattr(v:val, "name")')
return len(stack) >= 2 && stack[-2] ==# 'juliaFunctionDef'
endfunction
function JumpToMatch(lnum, last_closed_bracket)
" we use the % command to skip back (tries to use matchit if possible,
" otherwise resorts to vim's default, which is buggy but better than
" nothing)
call cursor(a:lnum, a:last_closed_bracket)
let percmap = maparg("%", "n")
if exists("g:loaded_matchit") && percmap =~# 'Match\%(it\|_wrapper\)'
normal %
else
normal! %
end
endfunction
" Auxiliary function to find a line which does not start in the middle of a
" multiline bracketed expression, to be used as reference for block
" indentation.
function LastBlockIndent(lnum)
let lnum = a:lnum
let ind = 0
while lnum > 0
let ind = indent(lnum)
if ind == 0
return [lnum, 0]
endif
if !IsInBrackets(lnum, 1)
break
endif
let lnum = prevnonblank(lnum - 1)
endwhile
return [max([lnum,1]), ind]
endfunction
function GetJuliaIndent()
" Do not alter doctrings indentation
if IsInDocString(v:lnum)
return -1
endif
" Find a non-blank line above the current line.
let lnum = prevnonblank(v:lnum - 1)
" At the start of the file use zero indent.
if lnum == 0
return 0
endif
let ind = -1
let st = -1
let lim = -1
" Multiline bracketed expressions take precedence
let align_brackets = get(g:, "julia_indent_align_brackets", 1)
let align_funcargs = get(g:, "julia_indent_align_funcargs", 0)
let c = len(getline(lnum)) + 1
while IsInBrackets(lnum, c)
let [first_open_bracket, last_open_bracket, last_closed_bracket, infuncargs] = GetJuliaNestingBrackets(lnum, c)
" First scenario: the previous line has a hanging open bracket:
" set the indentation to match the opening bracket (plus an extra space)
" unless we're in a function arguments list or alignment is disabled, in
" which case we just add an extra indent
if last_open_bracket != -1
if (!infuncargs && align_brackets) || (infuncargs && align_funcargs)
let st = last_open_bracket
let ind = virtcol([lnum, st + 1])
else
let ind = indent(lnum) + shiftwidth()
endif
" Second scenario: some multiline bracketed expression was closed in the
" previous line. But since we know we are still in a bracketed expression,
" we need to find the line where the bracket was opened
elseif last_closed_bracket != -1
call JumpToMatch(lnum, last_closed_bracket)
if line(".") == lnum
" something wrong here, give up
let ind = indent(lnum)
else
let lnum = line(".")
let c = col(".") - 1
if c == 0
" uhm, give up
let ind = 0
else
" we skipped a bracket set, keep searching for an opening bracket
let lim = c
continue
endif
endif
" Third scenario: nothing special: keep the indentation
else
let ind = indent(lnum)
endif
" Does the current line start with a closing bracket? Then depending on
" the situation we align it with the opening one, or we let the rest of
" the code figure it out (the case in which we're closing a function
" argument list is special-cased)
if JuliaMatch(v:lnum, getline(v:lnum), '[])}]', indent(v:lnum)) == indent(v:lnum) && ind > 0
if !align_brackets && !align_funcargs
call JumpToMatch(v:lnum, indent(v:lnum))
return indent(line("."))
elseif (align_brackets && getline(v:lnum)[indent(v:lnum)] != ')') || align_funcargs
return ind - 1
else " must be a ')' and align_brackets==1 and align_funcargs==0
call JumpToMatch(v:lnum, indent(v:lnum))
if IsFunctionArgPar(line("."), col("."))
let ind = -1
else
return ind - 1
endif
endif
endif
break
endwhile
if ind == -1
" We are not in a multiline bracketed expression. Thus we look for a
" previous line to use as a reference
let [lnum,ind] = LastBlockIndent(lnum)
let c = len(getline(lnum)) + 1
if IsInBrackets(lnum, c)
let [first_open_bracket, last_open_bracket, last_closed_bracket, infuncargs] = GetJuliaNestingBrackets(lnum, c)
let lim = first_open_bracket
endif
end
" Analyse the reference line
let [num_open_blocks, num_closed_blocks] = GetJuliaNestingStruct(lnum, st, lim)
" Increase indentation for each newly opened block in the reference line
let ind += shiftwidth() * num_open_blocks
" Analyse the current line
let [num_open_blocks, num_closed_blocks] = GetJuliaNestingStruct(v:lnum)
" Decrease indentation for each closed block in the current line
let ind -= shiftwidth() * num_closed_blocks
" Additional special case: multiline import/using/export statements
let prevline = getline(lnum)
" Are we in a multiline import/using/export statement, right below the
" opening line?
if IsInContinuationImportLine(v:lnum) && !IsInContinuationImportLine(lnum)
if get(g:, 'julia_indent_align_import', 1)
" if the opening line has a colon followed by non-comments, use it as
" reference point
let cind = JuliaMatch(lnum, prevline, ':', indent(lnum), lim)
if cind >= 0
let nonwhiteind = JuliaMatch(lnum, prevline, '\S', cind+1, -1, 'basic')
if nonwhiteind >= 0
" return match(prevline, '\S', cind+1) " a bit overkill...
return cind + 2
endif
else
" if the opening line is not a naked import/using/export statement, use
" it as reference
let iind = JuliaMatch(lnum, prevline, '\<import\|using\|export\>', indent(lnum), lim)
if iind >= 0
" assuming whitespace after using... so no `using(XYZ)` please!
let nonwhiteind = JuliaMatch(lnum, prevline, '\S', iind+6, -1, 'basic')
if nonwhiteind >= 0
return match(prevline, '\S', iind+6)
endif
endif
endif
endif
let ind += shiftwidth()
" Or did we just close a multiline import/using/export statement?
elseif !IsInContinuationImportLine(v:lnum) && IsInContinuationImportLine(lnum)
" find the starting line of the statement
let ilnum = 0
for iln in range(lnum-1, 1, -1)
if !IsInContinuationImportLine(iln)
let ilnum = iln
break
endif
endfor
if ilnum == 0
" something went horribly wrong, give up
let ind = indent(lnum)
endif
let ind = indent(ilnum)
endif
return ind
endfunction

View File

@@ -0,0 +1,30 @@
" Vim indent file
" Language: KDL
" Author: Aram Drevekenin <aram@poor.dev>
" Maintainer: Yinzuo Jiang <jiangyinzuo@foxmail.com>
" Last Change: 2024-06-16
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=KdlIndent()
let b:undo_indent = "setlocal indentexpr<"
function! KdlIndent(...)
let line = substitute(getline(v:lnum), '//.*$', '', '')
let previousNum = prevnonblank(v:lnum - 1)
let previous = substitute(getline(previousNum), '//.*$', '', '')
let l:indent = indent(previousNum)
if previous =~ "{" && previous !~ "}"
let l:indent += shiftwidth()
endif
if line =~ "}" && line !~ "{"
let l:indent -= shiftwidth()
endif
return l:indent
endfunction
" vim: sw=2 sts=2 et

View File

@@ -0,0 +1,60 @@
" Vim indent file
" Language: Kotlin
" Maintainer: Alexander Udalov
" URL: https://github.com/udalov/kotlin-vim
" Last Change: 7 November 2021
" 2023 Sep 17 by Vim Project (undo_indent)
if exists('b:did_indent')
finish
endif
let b:did_indent = 1
setlocal cinoptions& cinoptions+=j1,L0
setlocal indentexpr=GetKotlinIndent()
setlocal indentkeys=0},0),!^F,o,O,e,<CR>
setlocal autoindent " TODO ?
let b:undo_indent = "setlocal autoindent< cinoptions< indentexpr< indentkeys<"
" TODO teach it to count bracket balance, etc.
function! GetKotlinIndent()
if v:lnum == 0
return 0
endif
let prev_num = prevnonblank(v:lnum - 1)
let prev = getline(prev_num)
let prev_indent = indent(prev_num)
let cur = getline(v:lnum)
if cur =~ '^\s*\*'
return cindent(v:lnum)
endif
if prev =~ '^\s*\*/'
let st = prev
while st > 1
if getline(st) =~ '^\s*/\*'
break
endif
let st = st - 1
endwhile
return indent(st)
endif
let prev_open_paren = prev =~ '^.*(\s*$'
let cur_close_paren = cur =~ '^\s*).*$'
let prev_open_brace = prev =~ '^.*\({\|->\)\s*$'
let cur_close_brace = cur =~ '^\s*}.*$'
if prev_open_paren && !cur_close_paren || prev_open_brace && !cur_close_brace
return prev_indent + shiftwidth()
endif
if cur_close_paren && !prev_open_paren || cur_close_brace && !prev_open_brace
return prev_indent - shiftwidth()
endif
return prev_indent
endfunction

View File

@@ -0,0 +1,130 @@
" Vim indent file
" Language: Kuka Robot Language
" Maintainer: Patrick Meiser-Knosowski <knosowski@graeffrobotics.de>
" Version: 3.0.0
" Last Change: 15. Apr 2022
" Credits: Based on indent/vim.vim
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal nolisp
setlocal nocindent
setlocal nosmartindent
setlocal autoindent
setlocal indentexpr=GetKrlIndent()
setlocal indentkeys=!^F,o,O,=~end,0=~else,0=~case,0=~default,0=~until,0=~continue,=~part
let b:undo_indent = "setlocal lisp< cindent< smartindent< autoindent< indentexpr< indentkeys<"
if get(g:,'krlSpaceIndent',1)
" Use spaces, not tabs, for indention, 2 is enough.
" More or even tabs would waste valuable space on the teach pendant.
setlocal softtabstop=2
setlocal shiftwidth=2
setlocal expandtab
setlocal shiftround
let b:undo_indent = b:undo_indent." softtabstop< shiftwidth< expandtab< shiftround<"
endif
" Only define the function once.
if exists("*GetKrlIndent")
finish
endif
let s:keepcpo = &cpo
set cpo&vim
function GetKrlIndent() abort
let currentLine = getline(v:lnum)
if currentLine =~? '\v^;(\s*(end)?fold>)@!' && !get(g:, 'krlCommentIndent', 0)
" If current line has a ; in column 1 and is no fold, keep zero indent.
" This may be useful if code is commented out at the first column.
return 0
endif
" Find a non-blank line above the current line.
let preNoneBlankLineNum = s:KrlPreNoneBlank(v:lnum - 1)
if preNoneBlankLineNum == 0
" At the start of the file use zero indent.
return 0
endif
let preNoneBlankLine = getline(preNoneBlankLineNum)
let ind = indent(preNoneBlankLineNum)
" Define add 'shiftwidth' pattern
let addShiftwidthPattern = '\v^\s*('
if get(g:, 'krlIndentBetweenDef', 1)
let addShiftwidthPattern ..= '(global\s+)?def(fct|dat)?\s+\$?\w'
let addShiftwidthPattern ..= '|'
endif
let addShiftwidthPattern ..= 'if>|while>|for>|loop>'
let addShiftwidthPattern ..= '|else>'
let addShiftwidthPattern ..= '|case>|default>'
let addShiftwidthPattern ..= '|repeat>'
let addShiftwidthPattern ..= '|skip>|(ptp_)?spline>'
let addShiftwidthPattern ..= '|time_block\s+(start|part)>'
let addShiftwidthPattern ..= '|const_vel\s+start>'
let addShiftwidthPattern ..= ')'
" Define Subtract 'shiftwidth' pattern
let subtractShiftwidthPattern = '\v^\s*('
if get(g:, 'krlIndentBetweenDef', 1)
let subtractShiftwidthPattern ..= 'end(fct|dat)?>'
let subtractShiftwidthPattern ..= '|'
endif
let subtractShiftwidthPattern ..= 'end(if|while|for|loop)>'
let subtractShiftwidthPattern ..= '|else>'
let subtractShiftwidthPattern ..= '|case>|default>|endswitch>'
let subtractShiftwidthPattern ..= '|until>'
let subtractShiftwidthPattern ..= '|end(skip|spline)>'
let subtractShiftwidthPattern ..= '|time_block\s+(part|end)>'
let subtractShiftwidthPattern ..= '|const_vel\s+end>'
let subtractShiftwidthPattern ..= ')'
" Add shiftwidth
if preNoneBlankLine =~? addShiftwidthPattern
let ind += &sw
endif
" Subtract shiftwidth
if currentLine =~? subtractShiftwidthPattern
let ind = ind - &sw
endif
" First case after a switch gets the indent of the switch.
if currentLine =~? '\v^\s*case>'
\&& preNoneBlankLine =~? '\v^\s*switch>'
let ind = ind + &sw
endif
" align continue with the following instruction
if currentLine =~? '\v^\s*continue>'
\&& getline(v:lnum + 1) =~? subtractShiftwidthPattern
let ind = ind - &sw
endif
return ind
endfunction
" This function works almost like prevnonblank() but handles &-headers,
" comments and continue instructions like blank lines
function s:KrlPreNoneBlank(lnum) abort
let nPreNoneBlank = prevnonblank(a:lnum)
while nPreNoneBlank > 0 && getline(nPreNoneBlank) =~? '\v^\s*(\&\w\+|;|continue>)'
" Previous none blank line irrelevant. Look further aback.
let nPreNoneBlank = prevnonblank(nPreNoneBlank - 1)
endwhile
return nPreNoneBlank
endfunction
let &cpo = s:keepcpo
unlet s:keepcpo
" vim:sw=2 sts=2 et

View File

@@ -0,0 +1,87 @@
" Vim indent file
" Language: ld(1) script
" Maintainer: Doug Kearns <dougkearns@gmail.com>
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
" Last Change: 24 Sep 2021
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetLDIndent()
setlocal indentkeys=0{,0},!^F,o,O
setlocal nosmartindent
let b:undo_indent = "setl inde< indk< si<"
if exists("*GetLDIndent")
finish
endif
function s:prevnonblanknoncomment(lnum)
let lnum = a:lnum
while lnum > 1
let lnum = prevnonblank(lnum)
let line = getline(lnum)
if line =~ '\*/'
while lnum > 1 && line !~ '/\*'
let lnum -= 1
endwhile
if line =~ '^\s*/\*'
let lnum -= 1
else
break
endif
else
break
endif
endwhile
return lnum
endfunction
function s:count_braces(lnum, count_open)
let n_open = 0
let n_close = 0
let line = getline(a:lnum)
let pattern = '[{}]'
let i = match(line, pattern)
while i != -1
if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'ld\%(Comment\|String\)'
if line[i] == '{'
let n_open += 1
elseif line[i] == '}'
if n_open > 0
let n_open -= 1
else
let n_close += 1
endif
endif
endif
let i = match(line, pattern, i + 1)
endwhile
return a:count_open ? n_open : n_close
endfunction
function GetLDIndent()
let line = getline(v:lnum)
if line =~ '^\s*\*'
return cindent(v:lnum)
elseif line =~ '^\s*}'
return indent(v:lnum) - shiftwidth()
endif
let pnum = s:prevnonblanknoncomment(v:lnum - 1)
if pnum == 0
return 0
endif
let ind = indent(pnum) + s:count_braces(pnum, 1) * shiftwidth()
let pline = getline(pnum)
if pline =~ '}\s*$'
let ind -= (s:count_braces(pnum, 0) - (pline =~ '^\s*}' ? 1 : 0)) * shiftwidth()
endif
return ind
endfunction

View File

@@ -0,0 +1,13 @@
" Vim indent file
" Language: less
" Maintainer: Alessandro Vioni <jenoma@gmail.com>
" URL: https://github.com/genoma/vim-less
" Last Change: 2014 November 24
if exists("b:did_indent")
finish
endif
runtime! indent/css.vim
" vim:set sw=2:

View File

@@ -0,0 +1,24 @@
" Vim indent file
" Language: LifeLines
" Maintainer: Patrick Texier <p.texier@orsennes.com>
" Location: <http://patrick.texier.free.fr/vim/indent/lifelines.vim>
" Last Change: 2010 May 7
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" LifeLines uses cindent without ; line terminator, C functions
" declarations, C keywords, C++ formatting
setlocal cindent
setlocal cinwords=""
setlocal cinoptions+=+0
setlocal cinoptions+=p0
setlocal cinoptions+=i0
setlocal cinoptions+=t0
setlocal cinoptions+=*500
let b:undo_indent = "setl cin< cino< cinw<"
" vim: ts=8 sw=4

View File

@@ -0,0 +1,66 @@
" Vim indent file
" Language: Liquid
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Last Change: 2022 Mar 15
if exists('b:did_indent')
finish
endif
set indentexpr=
if exists('b:liquid_subtype')
exe 'runtime! indent/'.b:liquid_subtype.'.vim'
else
runtime! indent/html.vim
endif
unlet! b:did_indent
if &l:indentexpr == ''
if &l:cindent
let &l:indentexpr = 'cindent(v:lnum)'
else
let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))'
endif
endif
let b:liquid_subtype_indentexpr = &l:indentexpr
let b:did_indent = 1
setlocal indentexpr=GetLiquidIndent()
setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=endif,=endunless,=endifchanged,=endcase,=endfor,=endtablerow,=endcapture,=else,=elsif,=when,=empty
let b:undo_indent = "setl inde< indk<"
" Only define the function once.
if exists('*GetLiquidIndent')
finish
endif
function! s:count(string, pattern) abort
let string = substitute(a:string,'\C'.a:pattern,"\n",'g')
return strlen(substitute(string,"[^\n]",'','g'))
endfunction
function! GetLiquidIndent(...) abort
if a:0 && a:1 == '.'
let v:lnum = line('.')
elseif a:0 && a:1 =~ '^\d'
let v:lnum = a:1
endif
let vcol = col('.')
call cursor(v:lnum,1)
exe "let ind = ".b:liquid_subtype_indentexpr
let lnum = prevnonblank(v:lnum-1)
let line = getline(lnum)
let cline = getline(v:lnum)
let line = substitute(line,'\C^\%(\s*{%-\=\s*end\w*\s*-\=%}\)\+','','')
let line = substitute(line,'\C\%(\s*{%-\=\s*if.\+-\=%}.\+{%-\=\s*endif\s*-\=%}\)\+','','g')
let line .= matchstr(cline,'\C^\%(\s*{%-\=\s*end\w*\s*-\=%}\)\+')
let cline = substitute(cline,'\C^\%(\s*{%-\=\s*end\w*\s*-\=%}\)\+','','')
let sw = shiftwidth()
let ind += sw * s:count(line,'{%-\=\s*\%(if\|elsif\|else\|unless\|ifchanged\|case\|when\|for\|empty\|tablerow\|capture\)\>')
let ind -= sw * s:count(line,'{%-\=\s*end\%(if\|unless\|ifchanged\|case\|for\|tablerow\|capture\)\>')
let ind -= sw * s:count(cline,'{%-\=\s*\%(elsif\|else\|when\|empty\)\>')
let ind -= sw * s:count(cline,'{%-\=\s*end\w*$')
return ind
endfunction

View File

@@ -0,0 +1,15 @@
" Vim indent file
" Language: Lisp
" Maintainer: Sergey Khorev <sergey.khorev@gmail.com>
" URL: http://sites.google.com/site/khorser/opensource/vim
" Last Change: 2012 Jan 10
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal ai nosi
let b:undo_indent = "setl ai< si<"

View File

@@ -0,0 +1,9 @@
" Placeholder livebook indent file.
" This simply uses the markdown indenting.
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
runtime! indent/markdown.vim

View File

@@ -0,0 +1,67 @@
" Maintainer: Paulo Moura <pmoura@logtalk.org>
" Revised on: 2018.08.04
" 2023 Aug 28 by Vim Project (undo_indent)
" Language: Logtalk
" This Logtalk indent file is a modified version of the Prolog
" indent file written by Gergely Kontra
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetLogtalkIndent()
setlocal indentkeys-=:,0#
setlocal indentkeys+=0%,-,0;,>,0)
let b:undo_indent = "setlocal indentexpr< indentkeys<"
" Only define the function once.
if exists("*GetLogtalkIndent")
finish
endif
function! GetLogtalkIndent()
" Find a non-blank line above the current line.
let pnum = prevnonblank(v:lnum - 1)
" Hit the start of the file, use zero indent.
if pnum == 0
return 0
endif
let line = getline(v:lnum)
let pline = getline(pnum)
let ind = indent(pnum)
" Previous line was comment -> use previous line's indent
if pline =~ '^\s*%'
retu ind
endif
" Check for entity opening directive on previous line
if pline =~ '^\s*:-\s\(object\|protocol\|category\)\ze(.*,$'
let ind = ind + shiftwidth()
" 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()
" Check for end of clause on previous line
elseif pline =~ '\.\s*\(%.*\)\?$'
let ind = ind - shiftwidth()
endif
" Check for opening conditional on previous line
if pline =~ '^\s*\([(;]\|->\)' && pline !~ '\.\s*\(%.*\)\?$' && pline !~ '^.*\([)][,]\s*\(%.*\)\?$\)'
let ind = ind + shiftwidth()
endif
" Check for closing an unclosed paren, or middle ; or ->
if line =~ '^\s*\([);]\|->\)'
let ind = ind - shiftwidth()
endif
return ind
endfunction

View File

@@ -0,0 +1,77 @@
" Vim indent file
" Language: Lua script
" Maintainer: Marcus Aurelius Farias <marcus.cf 'at' bol.com.br>
" First Author: Max Ischenko <mfi 'at' ukr.net>
" Last Change: 2017 Jun 13
" 2022 Sep 07: b:undo_indent added by Doug Kearns
" 2024 Jul 27: by Vim project: match '(', ')' in function GetLuaIndentIntern()
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetLuaIndent()
" To make Vim call GetLuaIndent() when it finds '\s*end' or '\s*until'
" on the current line ('else' is default and includes 'elseif').
setlocal indentkeys+=0=end,0=until
setlocal autoindent
let b:undo_indent = "setlocal autoindent< indentexpr< indentkeys<"
" Only define the function once.
if exists("*GetLuaIndent")
finish
endif
function! GetLuaIndent()
let ignorecase_save = &ignorecase
try
let &ignorecase = 0
return GetLuaIndentIntern()
finally
let &ignorecase = ignorecase_save
endtry
endfunction
function! GetLuaIndentIntern()
" Find a non-blank line above the current line.
let prevlnum = prevnonblank(v:lnum - 1)
" Hit the start of the file, use zero indent.
if prevlnum == 0
return 0
endif
" Add a 'shiftwidth' after lines that start a block:
" 'function', 'if', 'for', 'while', 'repeat', 'else', 'elseif', '{', '('
let ind = indent(prevlnum)
let prevline = getline(prevlnum)
let midx = match(prevline, '^\s*\%(if\>\|for\>\|while\>\|repeat\>\|else\>\|elseif\>\|do\>\|then\>\)')
if midx == -1
let midx = match(prevline, '\%({\|(\)\s*\%(--\%([^[].*\)\?\)\?$')
if midx == -1
let midx = match(prevline, '\<function\>\s*\%(\k\|[.:]\)\{-}\s*(')
endif
endif
if midx != -1
" Add 'shiftwidth' if what we found previously is not in a comment and
" an "end" or "until" is not present on the same line.
if synIDattr(synID(prevlnum, midx + 1, 1), "name") != "luaComment" && prevline !~ '\<end\>\|\<until\>'
let ind = ind + shiftwidth()
endif
endif
" 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\>\|elseif\>\|until\>\|}\|)\)')
if midx != -1 && synIDattr(synID(v:lnum, midx + 1, 1), "name") != "luaComment"
let ind = ind - shiftwidth()
endif
return ind
endfunction

View File

@@ -0,0 +1,14 @@
" Vim filetype indent file
" Language: Luau
" Maintainer: None yet
" Last Change: 2023 Apr 30
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
" Luau is a superset of Lua
runtime! indent/lua.vim

View File

@@ -0,0 +1,15 @@
" Vim indent file
" Language: Mail
" Maintainer: The Vim Project <https://github.com/vim/vim>
" Last Change: 2023 Aug 13
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" What works best is auto-indenting, disable other indenting.
" For formatting see the ftplugin.
setlocal autoindent nosmartindent nocindent indentexpr=
let b:undo_indent = "setl ai< cin< inde< si<"

View File

@@ -0,0 +1,119 @@
" Vim indent file
" Language: Makefile
" Maintainer: Doug Kearns <dougkearns@gmail.com>
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
" Last Change: 2022 Apr 06
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetMakeIndent()
setlocal indentkeys=!^F,o,O,<:>,=else,=endif
setlocal nosmartindent
let b:undo_indent = "setl inde< indk< si<"
if exists("*GetMakeIndent")
finish
endif
let s:comment_rx = '^\s*#'
let s:rule_rx = '^[^ \t#:][^#:]*:\{1,2}\%([^=:]\|$\)'
let s:continued_rule_rx = '^[^#:]*:\{1,2}\%([^=:]\|$\)'
let s:continuation_rx = '\\$'
let s:assignment_rx = '^\s*\h\w*\s*[+:?]\==\s*\zs.*\\$'
let s:folded_assignment_rx = '^\s*\h\w*\s*[+:?]\=='
" TODO: This needs to be a lot more restrictive in what it matches.
let s:just_inserted_rule_rx = '^\s*[^#:]\+:\{1,2}$'
let s:conditional_directive_rx = '^ *\%(ifn\=\%(eq\|def\)\|else\)\>'
let s:end_conditional_directive_rx = '^\s*\%(else\|endif\)\>'
function s:remove_continuation(line)
return substitute(a:line, s:continuation_rx, "", "")
endfunction
function GetMakeIndent()
" TODO: Should this perhaps be v:lnum -1?
" let prev_lnum = prevnonblank(v:lnum - 1)
let prev_lnum = v:lnum - 1
if prev_lnum == 0
return 0
endif
let prev_line = getline(prev_lnum)
let prev_prev_lnum = prev_lnum - 1
let prev_prev_line = prev_prev_lnum != 0 ? getline(prev_prev_lnum) : ""
" TODO: Deal with comments. In comments, continuations aren't interesting.
if prev_line =~ s:continuation_rx
if prev_prev_line =~ s:continuation_rx
return indent(prev_lnum)
elseif prev_line =~ s:rule_rx
return shiftwidth()
elseif prev_line =~ s:assignment_rx
call cursor(prev_lnum, 1)
if search(s:assignment_rx, 'W') != 0
return virtcol('.') - 1
else
" TODO: ?
return shiftwidth()
endif
else
" TODO: OK, this might be a continued shell command, so perhaps indent
" properly here? Leave this out for now, but in the next release this
" should be using indent/sh.vim somehow.
"if prev_line =~ '^\t' " s:rule_command_rx
" if prev_line =~ '^\s\+[@-]\%(if\)\>'
" return indent(prev_lnum) + 2
" endif
"endif
return indent(prev_lnum) + shiftwidth()
endif
elseif prev_prev_line =~ s:continuation_rx
let folded_line = s:remove_continuation(prev_prev_line) . ' ' . s:remove_continuation(prev_line)
let lnum = prev_prev_lnum - 1
let line = getline(lnum)
while line =~ s:continuation_rx
let folded_line = s:remove_continuation(line) . ' ' . folded_line
let lnum -= 1
let line = getline(lnum)
endwhile
let folded_lnum = lnum + 1
if folded_line =~ s:rule_rx
if getline(v:lnum) =~ s:rule_rx
return 0
else
return &ts
endif
else
" elseif folded_line =~ s:folded_assignment_rx
if getline(v:lnum) =~ s:rule_rx
return 0
else
return indent(folded_lnum)
endif
" else
" " TODO: ?
" return indent(prev_lnum)
endif
elseif prev_line =~ s:rule_rx
if getline(v:lnum) =~ s:rule_rx
return 0
else
return &ts
endif
elseif prev_line =~ s:conditional_directive_rx
return shiftwidth()
else
let line = getline(v:lnum)
if line =~ s:just_inserted_rule_rx
return 0
elseif line =~ s:end_conditional_directive_rx
return v:lnum - 1 == 0 ? 0 : indent(v:lnum - 1) - shiftwidth()
else
return v:lnum - 1 == 0 ? 0 : indent(v:lnum - 1)
endif
endif
endfunction

View File

@@ -0,0 +1,123 @@
" Vim indent file
" Language: MATLAB
" Maintainer: Axel Forsman <axelsfor@gmail.com>
" Previous maintainer: Christophe Poucet <christophe.poucet@pandora.be>
" Last Update: 2021-10-01
" Only load if no other indent file is loaded
if exists('b:did_indent') | finish | endif
let b:did_indent = 1
setlocal indentexpr=GetMatlabIndent()
setlocal indentkeys=!,o,O,e,0=end,0=elseif,0=case,0=otherwise,0=catch,0=function,0=elsei
let b:undo_indent = "setlocal indentexpr< indentkeys<"
" The value of the Function indenting format in
" MATLAB Editor/Debugger Language Preferences.
" The possible values are 0 for Classic, 1 for Indent nested functions
" and 2 for Indent all functions (default).
let b:MATLAB_function_indent = get(g:, 'MATLAB_function_indent', 2)
" The previous value of b:changedtick
let b:MATLAB_lasttick = -1
" The previously indented line
let b:MATLAB_lastline = -1
" Whether the line above was a line continuation
let b:MATLAB_waslc = 0
let b:MATLAB_bracketlevel = 0
" Only define the function once
if exists("*GetMatlabIndent") | finish | endif
let s:keepcpo = &cpo
set cpo&vim
let s:end = '\<end\>\%([^({]*[)}]\)\@!' " Array indexing heuristic
let s:open_pat = 'for\|if\|parfor\|spmd\|switch\|try\|while\|classdef\|properties\|methods\|events\|enumeration'
let s:dedent_pat = '\C^\s*\zs\<\%(end\|else\|elseif\|catch\|\(case\|otherwise\|function\)\)\>'
let s:start_pat = '\C\<\%(function\|' . s:open_pat . '\)\>'
let s:bracket_pair_pat = '\(\[\|{\)\|\(\]\|}\)'
let s:zflag = has('patch-7.4.984') ? 'z' : ''
" Returns whether a comment or string envelops the specified column.
function! s:IsCommentOrString(lnum, col)
return synIDattr(synID(a:lnum, a:col, 1), "name") =~# 'matlabComment\|matlabMultilineComment\|matlabCellComment\|matlabString'
endfunction
" Returns whether the specified line continues on the next line.
function! s:IsLineContinuation(lnum)
let l = getline(a:lnum) | let c = -3
while 1
let c = match(l, '\.\{3}', c + 3)
if c == -1 | return 0
elseif !s:IsCommentOrString(a:lnum, c) | return 1 | endif
endwhile
endfunction
function! s:SubmatchCount(lnum, pattern, ...)
let endcol = a:0 >= 1 ? a:1 : 1 / 0 | let x = [0, 0, 0, 0]
call cursor(a:lnum, 1)
while 1
let [lnum, c, submatch] = searchpos(a:pattern, 'cpe' . s:zflag, a:lnum)
if !submatch || c >= endcol | break | endif
if !s:IsCommentOrString(lnum, c) | let x[submatch - 2] += 1 | endif
if cursor(0, c + 1) == -1 || col('.') == c | break | endif
endwhile
return x
endfunction
function! s:GetOpenCloseCount(lnum, pattern, ...)
let counts = call('s:SubmatchCount', [a:lnum, a:pattern] + a:000)
return counts[0] - counts[1]
endfunction
function! GetMatlabIndent()
let prevlnum = prevnonblank(v:lnum - 1)
if b:MATLAB_lasttick != b:changedtick || b:MATLAB_lastline != prevlnum
" Recalculate bracket count (only have to check same block and line above)
let b:MATLAB_bracketlevel = 0
let previndent = indent(prevlnum) | let l = prevlnum
while 1
let l = prevnonblank(l - 1) | let indent = indent(l)
if l <= 0 || previndent < indent | break | endif
let b:MATLAB_bracketlevel += s:GetOpenCloseCount(l, s:bracket_pair_pat)
if previndent != indent | break | endif
endwhile
let b:MATLAB_waslc = s:IsLineContinuation(prevlnum - 1)
endif
" If line above was blank it can impossibly have been a LC
let above_lc = b:MATLAB_lasttick == b:changedtick && prevlnum != v:lnum - 1 && b:MATLAB_lastline == prevlnum ? 0 : s:IsLineContinuation(v:lnum - 1)
let pair_pat = '\C\<\(' . s:open_pat . '\|'
\ . (b:MATLAB_function_indent == 1 ? '^\@<!' : '')
\ . (b:MATLAB_function_indent >= 1 ? 'function\|' : '')
\ . '\|\%(^\s*\)\@<=\%(else\|elseif\|case\|otherwise\|catch\)\)\>'
\ . '\|\S\s*\zs\(' . s:end . '\)'
let [open, close, b_open, b_close] = prevlnum ? s:SubmatchCount(prevlnum,
\ pair_pat . '\|' . s:bracket_pair_pat) : [0, 0, 0, 0]
let curbracketlevel = b:MATLAB_bracketlevel + b_open - b_close
call cursor(v:lnum, 1)
let submatch = search(s:dedent_pat, 'cp' . s:zflag, v:lnum)
if submatch && !s:IsCommentOrString(v:lnum, col('.'))
" Align end, et cetera with start of block
let [lnum, col] = searchpairpos(s:start_pat, '', '\C' . s:end, 'bW', 's:IsCommentOrString(line("."), col("."))')
let result = lnum ? indent(lnum) + shiftwidth() * (s:GetOpenCloseCount(lnum, pair_pat, col) + submatch == 2) : 0
else
" Count how many blocks the previous line opens/closes
" Line continuations/brackets indent once per statement
let result = (prevlnum > 0) * indent(prevlnum) + shiftwidth() * (open - close
\ + (b:MATLAB_bracketlevel ? -!curbracketlevel : !!curbracketlevel)
\ + (curbracketlevel <= 0) * (above_lc - b:MATLAB_waslc))
endif
let b:MATLAB_waslc = above_lc
let b:MATLAB_bracketlevel = curbracketlevel
let b:MATLAB_lasttick = b:changedtick
let b:MATLAB_lastline = v:lnum
return result
endfunction
let &cpo = s:keepcpo
unlet s:keepcpo

View File

@@ -0,0 +1,183 @@
" Vim indent file
" Language: Meson
" License: VIM License
" Maintainer: Nirbheek Chauhan <nirbheek.chauhan@gmail.com>
" Liam Beguin <liambeguin@gmail.com>
" Original Authors: David Bustos <bustos@caltech.edu>
" Bram Moolenaar <Bram@vim.org>
" Last Change: 2019 Oct 18
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" Some preliminary settings
setlocal nolisp " Make sure lisp indenting doesn't supersede us
setlocal autoindent " indentexpr isn't much help otherwise
setlocal indentexpr=GetMesonIndent(v:lnum)
setlocal indentkeys+==elif,=else,=endforeach,=endif,0)
let b:undo_indent = "setl ai< inde< indk< lisp<"
" Only define the function once.
if exists("*GetMesonIndent")
finish
endif
let s:keepcpo= &cpo
set cpo&vim
" Come here when loading the script the first time.
let s:maxoff = 50 " maximum number of lines to look backwards for ()
function GetMesonIndent(lnum)
echom getline(line("."))
" 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) + (exists("g:mesonindent_continue") ? eval(g:mesonindent_continue) : (shiftwidth() * 2))
endif
" If the start of the line is in a string don't change the indent.
if has('syntax_items')
\ && synIDattr(synID(a:lnum, 1, 1), "name") =~ "String$"
return -1
endif
" Search backwards for the previous non-empty line.
let plnum = prevnonblank(v:lnum - 1)
if plnum == 0
" This is the first non-empty line, use zero indent.
return 0
endif
" 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
" going too far back.
call cursor(plnum, 1)
let parlnum = searchpair('(\|{\|\[', '', ')\|}\|\]', 'nbW',
\ "line('.') < " . (plnum - s:maxoff) . " ? dummy :"
\ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
\ . " =~ '\\(Comment\\|Todo\\|String\\)$'")
if parlnum > 0
let plindent = indent(parlnum)
let plnumstart = parlnum
else
let plindent = indent(plnum)
let plnumstart = plnum
endif
" When inside parenthesis: If at the first line below the parenthesis add
" a 'shiftwidth', otherwise same as previous line.
" i = (a
" + b
" + c)
call cursor(a:lnum, 1)
let p = searchpair('(\|{\|\[', '', ')\|}\|\]', 'bW',
\ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
\ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
\ . " =~ '\\(Comment\\|Todo\\|String\\)$'")
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\\)$'")
if pp > 0
return indent(plnum) + (exists("g:pyindent_nested_paren") ? eval(g:pyindent_nested_paren) : shiftwidth())
endif
return indent(plnum) + (exists("g:pyindent_open_paren") ? eval(g:pyindent_open_paren) : shiftwidth())
endif
if plnumstart == p
return indent(plnum)
endif
return plindent
endif
" Get the line and remove a trailing comment.
" Use syntax highlighting attributes when possible.
let pline = getline(plnum)
let pline_len = strlen(pline)
if has('syntax_items')
" If the last character in the line is a comment, do a binary search for
" the start of the comment. synID() is slow, a linear search would take
" too long on a long line.
if synIDattr(synID(plnum, pline_len, 1), "name") =~ "\\(Comment\\|Todo\\)$"
let min = 1
let max = pline_len
while min < max
let col = (min + max) / 2
if synIDattr(synID(plnum, col, 1), "name") =~ "\\(Comment\\|Todo\\)$"
let max = col
else
let min = col + 1
endif
endwhile
let pline = strpart(pline, 0, min - 1)
endif
else
let col = 0
while col < pline_len
if pline[col] == '#'
let pline = strpart(pline, 0, col)
break
endif
let col = col + 1
endwhile
endif
" If the previous line ended the conditional/loop
if getline(plnum) =~ '^\s*\(endif\|endforeach\)\>\s*'
" Maintain indent
return -1
endif
" If the previous line ended with a builtin, indent this line
if pline =~ '^\s*\(foreach\|if\|else\|elif\)\>\s*'
return plindent + shiftwidth()
endif
" If the current line begins with a header keyword, deindent
if getline(a:lnum) =~ '^\s*\(else\|elif\|endif\|endforeach\)'
" Unless the previous line was a one-liner
if getline(plnumstart) =~ '^\s*\(foreach\|if\)\>\s*'
return plindent
endif
" Or the user has already dedented
if indent(a:lnum) <= plindent - shiftwidth()
return -1
endif
return plindent - shiftwidth()
endif
" When after a () construct we probably want to go back to the start line.
" a = (b
" + c)
" here
if parlnum > 0
return plindent
endif
return -1
endfunction
let &cpo = s:keepcpo
unlet s:keepcpo
" vim:sw=2

View File

@@ -0,0 +1,6 @@
" METAFONT indent file
" Language: METAFONT
" Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
" Latest Revision: 2022 Aug 12
runtime! indent/mp.vim

View File

@@ -0,0 +1,79 @@
" Vim indent file
" Language: Mathematica
" Maintainer: Steve Layland <layland@wolfram.com> (Invalid email address)
" Doug Kearns <dougkearns@gmail.com>
" Last Change: Sat May 10 18:56:22 CDT 2005
" 2022 April: b:undo_indent added by Doug Kearns
" Source: http://vim.sourceforge.net/scripts/script.php?script_id=1274
" http://members.wolfram.com/layland/vim/indent/mma.vim
"
" NOTE:
" Empty .m files will automatically be presumed to be Matlab files
" unless you have the following in your .vimrc:
"
" let filetype_m="mma"
"
" Credits:
" o steve hacked this out of a random indent file in the Vim 6.1
" distribution that he no longer remembers...sh.vim? Thanks!
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetMmaIndent()
setlocal indentkeys+=0[,0],0(,0)
setlocal nosi "turn off smart indent so we don't over analyze } blocks
let b:undo_indent = "setl inde< indk< si<"
if exists("*GetMmaIndent")
finish
endif
function GetMmaIndent()
" Hit the start of the file, use zero indent.
if v:lnum == 0
return 0
endif
" Find a non-blank line above the current line.
let lnum = prevnonblank(v:lnum - 1)
" use indenting as a base
let ind = indent(v:lnum)
let lnum = v:lnum
" if previous line has an unmatched bracket, or ( indent.
" doesn't do multiple parens/blocks/etc...
" also, indent only if this line if this line isn't starting a new
" block... TODO - fix this with indentkeys?
if getline(v:lnum-1) =~ '\\\@<!\%(\[[^\]]*\|([^)]*\|{[^}]*\)$' && getline(v:lnum) !~ '\s\+[\[({]'
let ind = ind+shiftwidth()
endif
" if this line had unmatched closing block,
" indent to the matching opening block
if getline(v:lnum) =~ '[^[]*]\s*$'
" move to the closing bracket
call search(']','bW')
" and find its partner's indent
let ind = indent(searchpair('\[','',']','bWn'))
" same for ( blocks
elseif getline(v:lnum) =~ '[^(]*)$'
call search(')','bW')
let ind = indent(searchpair('(','',')','bWn'))
" and finally, close { blocks if si ain't already set
elseif getline(v:lnum) =~ '[^{]*}'
call search('}','bW')
let ind = indent(searchpair('{','','}','bWn'))
endif
return ind
endfunction

View File

@@ -0,0 +1,6 @@
" Vim indent file
" Language: Mojo
" Maintainer: Riley Bruins <ribru17@gmail.com>
" Last Change: 2024 Jul 07
runtime! indent/python.vim

View File

@@ -0,0 +1,320 @@
vim9script
# MetaPost indent file
# Language: MetaPost
# Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
# Former Maintainers: Eugene Minkovskii <emin@mccme.ru>
# Latest Revision: 2022 Aug 12
if exists("b:did_indent")
finish
endif
b:did_indent = 1
setlocal indentexpr=g:MetaPostIndent()
setlocal indentkeys+==end,=else,=fi,=fill,0),0]
setlocal nolisp
setlocal nosmartindent
b:undo_indent = "setl indentexpr< indentkeys< lisp< smartindent<"
# Regexps {{{
# Expressions starting indented blocks
const MP_OPEN_TAG = [
'\<if\>',
'\<else\%[if]\>',
'\<for\%(\|ever\|suffixes\)\>',
'\<begingroup\>',
'\<\%(\|var\|primary\|secondary\|tertiary\)def\>',
'^\s*\<begin\%(fig\|graph\|glyph\|char\|logochar\)\>',
'[([{]',
]->extend(get(g:, "mp_open_tag", []))->join('\|')
# Expressions ending indented blocks
const MP_CLOSE_TAG = [
'\<fi\>',
'\<else\%[if]\>',
'\<end\%(\|for\|group\|def\|fig\|char\|glyph\|graph\)\>',
'[)\]}]'
]->extend(get(g:, "mp_close_tag", []))->join('\|')
# Statements that may span multiple lines and are ended by a semicolon. To
# keep this list short, statements that are unlikely to be very long or are
# not very common (e.g., keywords like `interim` or `showtoken`) are not
# included.
#
# The regex for assignments and equations (the last branch) is tricky, because
# it must not match things like `for i :=`, `if a=b`, `def...=`, etc... It is
# not perfect, but it works reasonably well.
const MP_STATEMENT = [
'\<\%(\|un\|cut\)draw\%(dot\)\=\>',
'\<\%(\|un\)fill\%[draw]\>',
'\<draw\%(dbl\)\=arrow\>',
'\<clip\>',
'\<addto\>',
'\<save\>',
'\<setbounds\>',
'\<message\>',
'\<errmessage\>',
'\<errhelp\>',
'\<fontmapline\>',
'\<pickup\>',
'\<show\>',
'\<special\>',
'\<write\>',
'\%(^\|;\)\%([^;=]*\%(' .. MP_OPEN_TAG .. '\)\)\@!.\{-}:\==',
]->join('\|')
# A line ends with zero or more spaces, possibly followed by a comment.
const EOL = '\s*\%($\|%\)'
# }}}
# Auxiliary functions {{{
# Returns true if (0-based) position immediately preceding `pos` in `line` is
# inside a string or a comment; returns false otherwise.
# This is the function that is called more often when indenting, so it is
# critical that it is efficient. The method we use is significantly faster
# than using syntax attributes, and more general (it does not require
# syntax_items). It is also faster than using a single regex matching an even
# number of quotes. It helps that MetaPost strings cannot span more than one
# line and cannot contain escaped quotes.
def IsCommentOrString(line: string, pos: number): bool
var in_string = 0
var q = stridx(line, '"')
var c = stridx(line, '%')
while q >= 0 && q < pos
if c >= 0 && c < q
if in_string # Find next percent symbol
c = stridx(line, '%', q + 1)
else # Inside comment
return true
endif
endif
in_string = 1 - in_string
q = stridx(line, '"', q + 1) # Find next quote
endwhile
return in_string || (c >= 0 && c <= pos)
enddef
# Find the first non-comment non-blank line before the given line.
def PrevNonBlankNonComment(lnum: number): number
var nr = prevnonblank(lnum - 1)
while getline(nr) =~# '^\s*%'
nr = prevnonblank(nr - 1)
endwhile
return nr
enddef
# Returns true if the last tag appearing in the line is an open tag; returns
# false otherwise.
def LastTagIsOpen(line: string): bool
var o = LastValidMatchEnd(line, MP_OPEN_TAG, 0)
if o == - 1
return false
endif
return LastValidMatchEnd(line, MP_CLOSE_TAG, o) < 0
enddef
# A simple, efficient and quite effective heuristics is used to test whether
# a line should cause the next line to be indented: count the "opening tags"
# (if, for, def, ...) in the line, count the "closing tags" (endif, endfor,
# ...) in the line, and compute the difference. We call the result the
# "weight" of the line. If the weight is positive, then the next line should
# most likely be indented. Note that `else` and `elseif` are both opening and
# closing tags, so they "cancel out" in almost all cases, the only exception
# being a leading `else[if]`, which is counted as an opening tag, but not as
# a closing tag (so that, for instance, a line containing a single `else:`
# will have weight equal to one, not zero). We do not treat a trailing
# `else[if]` in any special way, because lines ending with an open tag are
# dealt with separately before this function is called (see MetaPostIndent()).
#
# Example:
#
# forsuffixes $=a,b: if x.$ = y.$ : draw else: fill fi
# % This line will be indented because |{forsuffixes,if,else}| > |{else,fi}| (3 > 2)
# endfor
def Weight(line: string): number
var o = 0
var i = ValidMatchEnd(line, MP_OPEN_TAG, 0)
while i > 0
o += 1
i = ValidMatchEnd(line, MP_OPEN_TAG, i)
endwhile
var c = 0
i = matchend(line, '^\s*\<else\%[if]\>') # Skip a leading else[if]
i = ValidMatchEnd(line, MP_CLOSE_TAG, i)
while i > 0
c += 1
i = ValidMatchEnd(line, MP_CLOSE_TAG, i)
endwhile
return o - c
enddef
# Similar to matchend(), but skips strings and comments.
# line: a String
def ValidMatchEnd(line: string, pat: string, start: number): number
var i = matchend(line, pat, start)
while i > 0 && IsCommentOrString(line, i)
i = matchend(line, pat, i)
endwhile
return i
enddef
# Like s:ValidMatchEnd(), but returns the end position of the last (i.e.,
# rightmost) match.
def LastValidMatchEnd(line: string, pat: string, start: number): number
var last_found = -1
var i = matchend(line, pat, start)
while i > 0
if !IsCommentOrString(line, i)
last_found = i
endif
i = matchend(line, pat, i)
endwhile
return last_found
enddef
def DecreaseIndentOnClosingTag(curr_indent: number): number
var cur_text = getline(v:lnum)
if cur_text =~# '^\s*\%(' .. MP_CLOSE_TAG .. '\)'
return max([curr_indent - shiftwidth(), 0])
endif
return curr_indent
enddef
# }}}
# Main function {{{
def g:MetaPostIndent(): number
# Do not touch indentation inside verbatimtex/btex.. etex blocks.
if synIDattr(synID(v:lnum, 1, 1), "name") =~# '^mpTeXinsert$\|^tex\|^Delimiter'
return -1
endif
# At the start of a MetaPost block inside ConTeXt, do not touch indentation
if synIDattr(synID(prevnonblank(v:lnum - 1), 1, 1), "name") == "contextBlockDelim"
return -1
endif
var lnum = PrevNonBlankNonComment(v:lnum)
# At the start of the file use zero indent.
if lnum == 0
return 0
endif
var prev_text = getline(lnum)
# Every rule of indentation in MetaPost is very subjective. We might get
# creative, but things get murky very soon (there are too many corner
# cases). So, we provide a means for the user to decide what to do when this
# script doesn't get it. We use a simple idea: use '%>', '%<', '%=', and
# '%!', to explicitly control indentation. The '<' and '>' symbols may be
# repeated many times (e.g., '%>>' will cause the next line to be indented
# twice).
#
# User-defined overrides take precedence over anything else.
var j = match(prev_text, '%[<>=!]')
if j > 0
var i = strlen(matchstr(prev_text, '%>\+', j)) - 1
if i > 0
return indent(lnum) + i * shiftwidth()
endif
i = strlen(matchstr(prev_text, '%<\+', j)) - 1
if i > 0
return max([indent(lnum) - i * shiftwidth(), 0])
endif
if match(prev_text, '%=', j) > -1
return indent(lnum)
endif
if match(prev_text, '%!', j) > -1
return -1
endif
endif
# If the reference line ends with an open tag, indent.
#
# Example:
#
# if c:
# 0
# else:
# 1
# fi if c2: % Note that this line has weight equal to zero.
# ... % This line will be indented
if LastTagIsOpen(prev_text)
return DecreaseIndentOnClosingTag(indent(lnum) + shiftwidth())
endif
# Lines with a positive weight are unbalanced and should likely be indented.
#
# Example:
#
# def f = enddef for i = 1 upto 5: if x[i] > 0: 1 else: 2 fi
# ... % This line will be indented (because of the unterminated `for`)
if Weight(prev_text) > 0
return DecreaseIndentOnClosingTag(indent(lnum) + shiftwidth())
endif
# Unterminated statements cause indentation to kick in.
#
# Example:
#
# draw unitsquare
# withcolor black; % This line is indented because of `draw`.
# x := a + b + c
# + d + e; % This line is indented because of `:=`.
#
var i = LastValidMatchEnd(prev_text, MP_STATEMENT, 0)
if i >= 0 # Does the line contain a statement?
if ValidMatchEnd(prev_text, ';', i) < 0 # Is the statement unterminated?
return indent(lnum) + shiftwidth()
else
return DecreaseIndentOnClosingTag(indent(lnum))
endif
endif
# Deal with the special case of a statement spanning multiple lines. If the
# current reference line L ends with a semicolon, search backwards for
# another semicolon or a statement keyword. If the latter is found first,
# its line is used as the reference line for indenting the current line
# instead of L.
#
# Example:
#
# if cond:
# draw if a: z0 else: z1 fi
# shifted S
# scaled T; % L
#
# for i = 1 upto 3: % <-- Current line: this gets the same indent as `draw ...`
#
# NOTE: we get here only if L does not contain a statement (among those
# listed in g:MP_STATEMENT).
if ValidMatchEnd(prev_text, ';' .. EOL, 0) >= 0 # L ends with a semicolon
var stm_lnum = PrevNonBlankNonComment(lnum)
while stm_lnum > 0
prev_text = getline(stm_lnum)
var sc_pos = LastValidMatchEnd(prev_text, ';', 0)
var stm_pos = ValidMatchEnd(prev_text, MP_STATEMENT, sc_pos)
if stm_pos > sc_pos
lnum = stm_lnum
break
elseif sc_pos > stm_pos
break
endif
stm_lnum = PrevNonBlankNonComment(stm_lnum)
endwhile
endif
return DecreaseIndentOnClosingTag(indent(lnum))
enddef
# }}}
# vim: sw=2 fdm=marker

View File

@@ -0,0 +1,78 @@
" Vim indent file
" Language: nginx.conf
" Maintainer: Chris Aumann <me@chr4.org>
" Last Change: 2022 Dec 01
" Only load this indent file when no other was loaded.
if exists('b:did_indent')
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetNginxIndent()
setlocal indentkeys=0{,0},0#,!^F,o,O
let b:undo_indent = 'setl inde< indk<'
" Only define the function once.
if exists('*GetNginxIndent')
finish
endif
function GetNginxIndent() abort
let plnum = s:PrevNotAsBlank(v:lnum - 1)
" Hit the start of the file, use zero indent.
if plnum == 0
return 0
endif
let ind = indent(plnum)
" Add a 'shiftwidth' after '{'
if s:AsEndWith(getline(plnum), '{')
let ind = ind + shiftwidth()
end
" Subtract a 'shiftwidth' on '}'
" This is the part that requires 'indentkeys'.
if getline(v:lnum) =~ '^\s*}'
let ind = ind - shiftwidth()
endif
let pplnum = s:PrevNotAsBlank(plnum - 1)
if s:IsLineContinuation(plnum)
if !s:IsLineContinuation(pplnum)
let ind = ind + shiftwidth()
end
else
if s:IsLineContinuation(pplnum)
let ind = ind - shiftwidth()
end
endif
return ind
endfunction
" Find the first line at or above {lnum} that is non-blank and not a comment.
function s:PrevNotAsBlank(lnum) abort
let lnum = prevnonblank(a:lnum)
while lnum > 0
if getline(lnum) !~ '^\s*#'
break
endif
let lnum = prevnonblank(lnum - 1)
endwhile
return lnum
endfunction
" Check whether {line} ends with {pat}, ignoring trailing comments.
function s:AsEndWith(line, pat) abort
return a:line =~ a:pat . '\m\s*\%(#.*\)\?$'
endfunction
function s:IsLineContinuation(lnum) abort
return a:lnum > 0 && !s:AsEndWith(getline(a:lnum), '[;{}]')
endfunction

View File

@@ -0,0 +1,93 @@
" Vim indent file
" Language: NSIS script
" Maintainer: Ken Takata
" URL: https://github.com/k-takata/vim-nsis
" Last Change: 2021-10-18
" 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,=~${EndSwitch,=~${Loop,=~${Next,=~${MementoSectionEnd,=~FunctionEnd,=~SectionEnd,=~SectionGroupEnd,=~PageExEnd,0=~!macroend,0=~!if,0=~!else,0=~!endif
let b:undo_indent = "setl ai< inde< indk< si<"
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

Some files were not shown because too many files have changed in this diff Show More