This commit is contained in:
Adam Stankiewicz
2022-10-14 17:40:10 +02:00
parent 38282d5838
commit bc8a81d359
74 changed files with 1217 additions and 775 deletions

View File

@@ -55,6 +55,10 @@ if exists("*searchpairpos")
let g:clojure_align_subforms = 0
endif
if !exists('g:clojure_cljfmt_compat')
let g:clojure_cljfmt_compat = 0
endif
function! s:syn_id_name()
return synIDattr(synID(line("."), col("."), 0), "name")
endfunction
@@ -326,9 +330,16 @@ if exists("*searchpairpos")
return [paren[0], paren[1] + (g:clojure_align_subforms ? 0 : &shiftwidth - 1)]
elseif w[1] == '_'
return paren
elseif w[1] == "'" && g:clojure_cljfmt_compat
return paren
endif
endif
" Paren indent for keywords, symbols and derefs
if g:clojure_cljfmt_compat && w[0] =~# "[:@']"
return paren
endif
" Test words without namespace qualifiers and leading reader macro
" metacharacters.
"

View File

@@ -8,7 +8,12 @@ endif
let b:did_indent = 1
setlocal cindent
setlocal cinoptions+=j1,J1,(2s,u2s,U1,m1,+2s
setlocal cinoptions+=j1,J1,U1,m1,+2s
if get(g:, 'dart_trailing_comma_indent', v:false)
setlocal cinoptions+=(2s,u2s
else
setlocal cinoptions+=(s,us
endif
setlocal indentexpr=DartIndent()

View File

@@ -8,7 +8,7 @@ endif
" Contributors: Edwin Fine <efine145_nospam01 at usa dot net>
" Pawel 'kTT' Salata <rockplayer.pl@gmail.com>
" Ricardo Catalinas Jiménez <jimenezrick@gmail.com>
" Last Update: 2020-Jun-11
" Last Update: 2022-Sep-06
" License: Vim license
" URL: https://github.com/vim-erlang/vim-erlang-runtime
@@ -34,7 +34,7 @@ else
endif
setlocal indentexpr=ErlangIndent()
setlocal indentkeys+=0=end,0=of,0=catch,0=after,0=when,0=),0=],0=},0=>>
setlocal indentkeys+=0=end,0=of,0=catch,0=after,0=else,0=when,0=),0=],0=},0=>>
let b:undo_indent = "setl inde< indk<"
@@ -241,8 +241,8 @@ function! s:GetTokensFromLine(line, string_continuation, atom_continuation,
" Two-character tokens
elseif i + 1 < linelen &&
\ index(['->', '<<', '>>', '||', '==', '/=', '=<', '>=', '++', '--',
\ '::'],
\ index(['->', '<<', '>>', '||', '==', '/=', '=<', '>=', '?=', '++',
\ '--', '::'],
\ a:line[i : i + 1]) != -1
call add(indtokens, [a:line[i : i + 1], vcol, i])
let next_i = i + 2
@@ -564,8 +564,8 @@ function! s:IsCatchStandalone(lnum, i)
let is_standalone = 0
elseif prev_token =~# '[a-z]'
if index(['after', 'and', 'andalso', 'band', 'begin', 'bnot', 'bor', 'bsl',
\ 'bsr', 'bxor', 'case', 'catch', 'div', 'not', 'or', 'orelse',
\ 'rem', 'try', 'xor'], prev_token) != -1
\ 'bsr', 'bxor', 'case', 'catch', 'div', 'maybe', 'not', 'or',
\ 'orelse', 'rem', 'try', 'xor'], prev_token) != -1
" If catch is after these keywords, it is standalone
let is_standalone = 1
else
@@ -574,7 +574,7 @@ function! s:IsCatchStandalone(lnum, i)
"
" Keywords:
" - may precede 'catch': end
" - may not precede 'catch': fun if of receive when
" - may not precede 'catch': else fun if of receive when
" - unused: cond let query
let is_standalone = 0
endif
@@ -583,7 +583,7 @@ function! s:IsCatchStandalone(lnum, i)
let is_standalone = 0
else
" This 'else' branch includes the following tokens:
" -> == /= =< < >= > =:= =/= + - * / ++ -- :: < > ; ( [ { ? = ! . |
" -> == /= =< < >= > ?= =:= =/= + - * / ++ -- :: < > ; ( [ { ? = ! . |
let is_standalone = 1
endif
@@ -596,6 +596,7 @@ endfunction
" Purpose:
" This function is called when a begin-type element ('begin', 'case',
" '[', '<<', etc.) is found. It asks the caller to return if the stack
" if already empty.
" Parameters:
" stack: [token]
" token: string
@@ -764,7 +765,7 @@ endfunction
function! s:SearchEndPair(lnum, curr_col)
return s:SearchPair(
\ a:lnum, a:curr_col,
\ '\C\<\%(case\|try\|begin\|receive\|if\)\>\|' .
\ '\C\<\%(case\|try\|begin\|receive\|if\|maybe\)\>\|' .
\ '\<fun\>\%(\s\|\n\|%.*$\|[A-Z_@][a-zA-Z_@]*\)*(',
\ '',
\ '\<end\>')
@@ -853,6 +854,7 @@ function! s:ErlangCalcIndent2(lnum, stack)
if ret | return res | endif
" case EXPR of BRANCHES end
" if BRANCHES end
" try EXPR catch BRANCHES end
" try EXPR after BODY end
" try EXPR catch BRANCHES after BODY end
@@ -861,15 +863,17 @@ function! s:ErlangCalcIndent2(lnum, stack)
" try EXPR of BRANCHES catch BRANCHES after BODY end
" receive BRANCHES end
" receive BRANCHES after BRANCHES end
" maybe EXPR end
" maybe EXPR else BRANCHES end
" This branch is not Emacs-compatible
elseif (index(['of', 'receive', 'after', 'if'], token) != -1 ||
elseif (index(['of', 'receive', 'after', 'if', 'else'], token) != -1 ||
\ (token ==# 'catch' && !s:IsCatchStandalone(lnum, i))) &&
\ !last_token_of_line &&
\ (empty(stack) || stack ==# ['when'] || stack ==# ['->'] ||
\ stack ==# ['->', ';'])
" If we are after of/receive, but these are not the last
" If we are after of/receive/etc, but these are not the last
" tokens of the line, we want to indent like this:
"
" % stack == []
@@ -895,21 +899,21 @@ function! s:ErlangCalcIndent2(lnum, stack)
" stack = ['when'] => LTI is a guard
if empty(stack) || stack == ['->', ';']
call s:Log(' LTI is in a condition after ' .
\'"of/receive/after/if/catch" -> return')
\'"of/receive/after/if/else/catch" -> return')
return stored_vcol
elseif stack == ['->']
call s:Log(' LTI is in a branch after ' .
\'"of/receive/after/if/catch" -> return')
\'"of/receive/after/if/else/catch" -> return')
return stored_vcol + shiftwidth()
elseif stack == ['when']
call s:Log(' LTI is in a guard after ' .
\'"of/receive/after/if/catch" -> return')
\'"of/receive/after/if/else/catch" -> return')
return stored_vcol + shiftwidth()
else
return s:UnexpectedToken(token, stack)
endif
elseif index(['case', 'if', 'try', 'receive'], token) != -1
elseif index(['case', 'if', 'try', 'receive', 'maybe'], token) != -1
" stack = [] => LTI is a condition
" stack = ['->'] => LTI is a branch
@@ -919,45 +923,47 @@ function! s:ErlangCalcIndent2(lnum, stack)
" pass
elseif (token ==# 'case' && stack[0] ==# 'of') ||
\ (token ==# 'if') ||
\ (token ==# 'maybe' && stack[0] ==# 'else') ||
\ (token ==# 'try' && (stack[0] ==# 'of' ||
\ stack[0] ==# 'catch' ||
\ stack[0] ==# 'after')) ||
\ (token ==# 'receive')
" From the indentation point of view, the keyword
" (of/catch/after/end) before the LTI is what counts, so
" (of/catch/after/else/end) before the LTI is what counts, so
" when we reached these tokens, and the stack already had
" a catch/after/end, we didn't modify it.
" a catch/after/else/end, we didn't modify it.
"
" This way when we reach case/try/receive (i.e. now),
" there is at most one of/catch/after/end token in the
" This way when we reach case/try/receive/maybe (i.e. now),
" there is at most one of/catch/after/else/end token in the
" stack.
if token ==# 'case' || token ==# 'try' ||
\ (token ==# 'receive' && stack[0] ==# 'after')
\ (token ==# 'receive' && stack[0] ==# 'after') ||
\ (token ==# 'maybe' && stack[0] ==# 'else')
call s:Pop(stack)
endif
if empty(stack)
call s:Log(' LTI is in a condition; matching ' .
\'"case/if/try/receive" found')
\'"case/if/try/receive/maybe" found')
let stored_vcol = curr_vcol + shiftwidth()
elseif stack[0] ==# 'align_to_begin_element'
call s:Pop(stack)
let stored_vcol = curr_vcol
elseif len(stack) > 1 && stack[0] ==# '->' && stack[1] ==# ';'
call s:Log(' LTI is in a condition; matching ' .
\'"case/if/try/receive" found')
\'"case/if/try/receive/maybe" found')
call s:Pop(stack)
call s:Pop(stack)
let stored_vcol = curr_vcol + shiftwidth()
elseif stack[0] ==# '->'
call s:Log(' LTI is in a branch; matching ' .
\'"case/if/try/receive" found')
\'"case/if/try/receive/maybe" found')
call s:Pop(stack)
let stored_vcol = curr_vcol + 2 * shiftwidth()
elseif stack[0] ==# 'when'
call s:Log(' LTI is in a guard; matching ' .
\'"case/if/try/receive" found')
\'"case/if/try/receive/maybe" found')
call s:Pop(stack)
let stored_vcol = curr_vcol + 2 * shiftwidth() + 2
endif
@@ -1219,7 +1225,7 @@ function! s:ErlangCalcIndent2(lnum, stack)
if empty(stack)
call s:Push(stack, ';')
elseif index([';', '->', 'when', 'end', 'after', 'catch'],
elseif index([';', '->', 'when', 'end', 'after', 'catch', 'else'],
\stack[0]) != -1
" Pass:
"
@@ -1229,10 +1235,10 @@ function! s:ErlangCalcIndent2(lnum, stack)
" should keep that, because they signify the type of the
" LTI (branch, condition or guard).
" - From the indentation point of view, the keyword
" (of/catch/after/end) before the LTI is what counts, so
" if the stack already has a catch/after/end, we don't
" modify it. This way when we reach case/try/receive,
" there will be at most one of/catch/after/end token in
" (of/catch/after/else/end) before the LTI is what counts, so
" if the stack already has a catch/after/else/end, we don't
" modify it. This way when we reach case/try/receive/maybe,
" there will be at most one of/catch/after/else/end token in
" the stack.
else
return s:UnexpectedToken(token, stack)
@@ -1248,7 +1254,8 @@ function! s:ErlangCalcIndent2(lnum, stack)
" stack = ['->'] -> LTI is a condition
" stack = ['->', ';'] -> LTI is a branch
call s:Push(stack, '->')
elseif index(['->', 'when', 'end', 'after', 'catch'], stack[0]) != -1
elseif index(['->', 'when', 'end', 'after', 'catch', 'else'],
\stack[0]) != -1
" Pass:
"
" - If the stack top is another '->', then one '->' is
@@ -1256,10 +1263,10 @@ function! s:ErlangCalcIndent2(lnum, stack)
" - If the stack top is a 'when', then we should keep
" that, because this signifies that LTI is a in a guard.
" - From the indentation point of view, the keyword
" (of/catch/after/end) before the LTI is what counts, so
" if the stack already has a catch/after/end, we don't
" modify it. This way when we reach case/try/receive,
" there will be at most one of/catch/after/end token in
" (of/catch/after/else/end) before the LTI is what counts, so
" if the stack already has a catch/after/else/end, we don't
" modify it. This way when we reach case/try/receive/maybe,
" there will be at most one of/catch/after/else/end token in
" the stack.
else
return s:UnexpectedToken(token, stack)
@@ -1289,7 +1296,8 @@ function! s:ErlangCalcIndent2(lnum, stack)
" LTI
call s:Push(stack, token)
endif
elseif index(['->', 'when', 'end', 'after', 'catch'], stack[0]) != -1
elseif index(['->', 'when', 'end', 'after', 'catch', 'else'],
\stack[0]) != -1
" Pass:
" - If the stack top is another 'when', then one 'when' is
" enough.
@@ -1297,21 +1305,63 @@ function! s:ErlangCalcIndent2(lnum, stack)
" should keep that, because they signify the type of the
" LTI (branch, condition or guard).
" - From the indentation point of view, the keyword
" (of/catch/after/end) before the LTI is what counts, so
" if the stack already has a catch/after/end, we don't
" modify it. This way when we reach case/try/receive,
" there will be at most one of/catch/after/end token in
" (of/catch/after/else/end) before the LTI is what counts, so
" if the stack already has a catch/after/else/end, we don't
" modify it. This way when we reach case/try/receive/maybe,
" there will be at most one of/catch/after/else/end token in
" the stack.
else
return s:UnexpectedToken(token, stack)
endif
elseif token ==# 'of' || token ==# 'after' ||
elseif token ==# 'of' || token ==# 'after' || token ==# 'else' ||
\ (token ==# 'catch' && !s:IsCatchStandalone(lnum, i))
if token ==# 'after'
" If LTI is between an 'after' and the corresponding
" 'end', then let's return
if token ==# 'after' || token ==# 'else'
" If LTI is between an after/else and the corresponding 'end', then
" let's return because calculating the indentation based on
" after/else is enough.
"
" Example:
" receive A after
" LTI
" maybe A else
" LTI
"
" Note about Emacs compabitility {{{
"
" It would be fine to indent the examples above the following way:
"
" receive A after
" LTI
" maybe A else
" LTI
"
" We intend it the way above because that is how Emacs does it.
" Also, this is a bit faster.
"
" We are still not 100% Emacs compatible because of placing the
" 'end' after the indented blocks.
"
" Emacs example:
"
" receive A after
" LTI
" end,
" maybe A else
" LTI
" end % Yes, it's here (in OTP 25.0, might change
" % later)
"
" vim-erlang example:
"
" receive A after
" LTI
" end,
" maybe A else
" LTI
" end
" }}}
let [ret, res] = s:BeginElementFoundIfEmpty(stack, token, curr_vcol,
\stored_vcol, shiftwidth())
if ret | return res | endif
@@ -1319,7 +1369,8 @@ function! s:ErlangCalcIndent2(lnum, stack)
if empty(stack) || stack[0] ==# '->' || stack[0] ==# 'when'
call s:Push(stack, token)
elseif stack[0] ==# 'catch' || stack[0] ==# 'after' || stack[0] ==# 'end'
elseif stack[0] ==# 'catch' || stack[0] ==# 'after' ||
\stack[0] ==# 'else' || stack[0] ==# 'end'
" Pass: From the indentation point of view, the keyword
" (of/catch/after/end) before the LTI is what counts, so
" if the stack already has a catch/after/end, we don't
@@ -1409,7 +1460,7 @@ function! ErlangIndent()
endif
let ml = matchlist(currline,
\'^\(\s*\)\(\%(end\|of\|catch\|after\)\>\|[)\]}]\|>>\)')
\'^\(\s*\)\(\%(end\|of\|catch\|after\|else\)\>\|[)\]}]\|>>\)')
" If the line has a special beginning, but not a standalone catch
if !empty(ml) && !(ml[2] ==# 'catch' && s:IsCatchStandalone(v:lnum, 0))

View File

@@ -1,204 +0,0 @@
if polyglot#init#is_disabled(expand('<sfile>:p'), 'gdscript', 'indent/gdscript3.vim')
finish
endif
" Vim indent file
" Language: Python
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Original Author: David Bustos <bustos@caltech.edu>
" Last Change: 2013 Jul 9
" Modified for GDScript
" 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=GetPythonIndent(v:lnum)
setlocal indentkeys+=<:>,=elif
" Only define the function once.
if exists("*GetPythonIndent")
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 GetPythonIndent(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) + (exists("g:pyindent_continue") ? eval(g:pyindent_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
" two '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() * 2))
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 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\|return\|pass\)\>'
" See if the user has already dedented
if indent(a: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(a:lnum) =~ '^\s*\(except\|finally\)\>'
" let lnum = a:lnum - 1
" while lnum >= 1
" if getline(lnum) =~ '^\s*\(try\|except\)\>'
" let ind = indent(lnum)
" if ind >= indent(a:lnum)
" return -1 " indent is already less than this
" endif
" return ind " line up with previous try or except
" endif
" let lnum = lnum - 1
" endwhile
" return -1 " no matching "try"!
" endif
" If the current line begins with a header keyword, dedent
if getline(a:lnum) =~ '^\s*\(elif\|else\)\>'
" Unless the previous line was a one-liner
if getline(plnumstart) =~ '^\s*\(for\|if\)\>'
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

@@ -11,5 +11,6 @@ endif
setlocal autoindent cindent
setlocal formatoptions+=roq
setlocal cinoptions&
" vim:set sts=2 sw=2 :

View File

@@ -5,7 +5,7 @@ endif
" Vim indent file
" Language: Haml
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Last Change: 2017 Jun 13
" Last Change: 2022 Mar 15
if exists("b:did_indent")
finish

View File

@@ -96,7 +96,7 @@ let s:ruby_indent_keywords =
\ '\<\%(if\|for\|while\|until\|case\|unless\|begin\):\@!\>'
" Def without an end clause: def method_call(...) = <expression>
let s:ruby_endless_def = '\<def\s\+\k\+[!?]\=\%((.*)\|\s\)\s*='
let s:ruby_endless_def = '\<def\s\+\%(\k\+\.\)\=\k\+[!?]\=\%((.*)\|\s\)\s*='
" Regex used for words that, at the start of a line, remove a level of indent.
let s:ruby_deindent_keywords =

View File

@@ -37,6 +37,8 @@ setlocal cinkeys=0{,0},0),0],!^F,o,O
setlocal indentexpr=GetZigIndent(v:lnum)
let b:undo_indent = "setlocal cindent< cinkeys< cinoptions< indentexpr<"
function! GetZigIndent(lnum)
let curretLineNum = a:lnum
let currentLine = getline(a:lnum)