robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
ae7ab90159
master
1" Vim indent file 2" Language: fish 3" Maintainer: Nicholas Boyle (github.com/nickeb96) 4" Repository: https://github.com/nickeb96/fish.vim 5" Last Change: February 4, 2023 6" 2023 Aug 28 by Vim Project (undo_indent) 7 8if exists ( "b:did_indent" ) 9finish 10endif 11let b: did_indent = 1 12 13setlocal indentexpr = GetFishIndent (v:lnum) 14setlocal indentkeys += =end,=else,=case 15 16let b: undo_indent = "setlocal indentexpr< indentkeys<" 17 18function s: PrevCmdStart ( linenum ) 19let l: linenum = a: linenum 20" look for the first line that isn't a line continuation 21while l: linenum > 1 && getline ( l: linenum - 1 ) =~# '\\$' 22let l: linenum = l: linenum - 1 23endwhile 24return l: linenum 25endfunction 26 27function GetFishIndent ( lnum ) 28let l: shiftwidth = shiftwidth () 29 30let l: prevlnum = prevnonblank ( a: lnum - 1 ) 31if l: prevlnum ==# 0 32return 0 33endif 34 35" if the previous line ended with a line continuation 36if getline ( a: lnum - 1 ) =~# '\\$' 37if a: lnum ==# 0 || getline ( a: lnum - 2 ) !~# '\\$' 38" this is the first line continuation in a chain, so indent it 39return indent ( a: lnum - 1 ) + l: shiftwidth 40else 41" use the same indentation as the previous continued line 42return indent ( a: lnum - 1 ) 43endif 44endif 45 46let l: prevlnum = s: PrevCmdStart ( l: prevlnum ) 47 48let l: prevline = getline ( l: prevlnum ) 49if l: prevline =~# '^\s*\(begin\|if\|else\|while\|for\|function\|case\|switch\)\>' 50let l: indent = l: shiftwidth 51else 52let l: indent = 0 53endif 54 55let l: line = getline ( a: lnum ) 56if l: line =~# '^\s*end\>' 57" find end's matching start 58let l: depth = 1 59let l: currentlnum = a: lnum 60while l: depth > 0 && l: currentlnum > 0 61let l: currentlnum = s: PrevCmdStart ( prevnonblank ( l: currentlnum - 1 )) 62let l: currentline = getline ( l: currentlnum ) 63if l: currentline =~# '^\s*end\>' 64let l: depth = l: depth + 1 65elseif l: currentline =~# '^\s*\(begin\|if\|while\|for\|function\|switch\)\>' 66let l: depth = l: depth - 1 67endif 68endwhile 69if l: currentline =~# '^\s*switch\>' 70return indent ( l: currentlnum ) 71else 72return indent ( l: prevlnum ) + l: indent - l: shiftwidth 73endif 74elseif l: line =~# '^\s*else\>' 75return indent ( l: prevlnum ) + l: indent - l: shiftwidth 76elseif l: line =~# '^\s*case\>' 77if getline ( l: prevlnum ) =~# '^\s*switch\>' 78return indent ( l: prevlnum ) + l: indent 79else 80return indent ( l: prevlnum ) + l: indent - l: shiftwidth 81endif 82else 83return indent ( l: prevlnum ) + l: indent 84endif 85endfunction