|
| 1 | +" Vim indent file |
| 2 | +" Language: Nushell |
| 3 | +" Maintainer: El Kasztano |
| 4 | +" URL: https://github.com/elkasztano/nushell-syntax-vim |
| 5 | +" License: MIT <https://opensource.org/license/mit> |
| 6 | +" Last Change: 2025 Sep 05 |
| 7 | + |
| 8 | +" Only load if no other indent file is loaded |
| 9 | +if exists("b:did_indent") |
| 10 | + finish |
| 11 | +endif |
| 12 | +let b:did_indent = 1 |
| 13 | + |
| 14 | +setlocal cindent |
| 15 | +setlocal cinoptions=L0,(s,Ws,J1,j1,+0,f5,m1,i0 |
| 16 | +setlocal cinkeys=0{,0},!^F,o,O,0[,0],0),0# |
| 17 | + |
| 18 | +setlocal autoindent |
| 19 | +setlocal indentkeys=0{,0},!^F,o,O,0[,0],0),0# |
| 20 | + |
| 21 | +setlocal shiftwidth=2 |
| 22 | +setlocal softtabstop=2 |
| 23 | +setlocal expandtab |
| 24 | + |
| 25 | +setlocal indentexpr=GetNuIndent(v:lnum) |
| 26 | + |
| 27 | +let b:undo_indent = "setl ai< cin< cink< cino< et< inde< indk< sts< sw<" |
| 28 | + |
| 29 | +" only define once |
| 30 | +if exists("*GetNuIndent") |
| 31 | + finish |
| 32 | +endif |
| 33 | + |
| 34 | +let s:save_cpo = &cpo |
| 35 | +set cpo&vim |
| 36 | + |
| 37 | +function GetNuIndent(lnum) |
| 38 | + let prevlnum = prevnonblank(v:lnum - 1) "get number of last non blank line |
| 39 | + let line = getline(a:lnum) |
| 40 | + let synname = synIDattr(synID(a:lnum, 1, 1), "name") |
| 41 | + if (synname == "nuString") || (synname == "nuComment") |
| 42 | + return -1 |
| 43 | + endif |
| 44 | + if getline(prevlnum) =~ '\%(^.*[$\|^.*[\s*#.*$\)' |
| 45 | + return (prevlnum > 0) * indent(prevlnum) + shiftwidth() |
| 46 | + endif |
| 47 | + if getline(v:lnum) =~ "^\s*]\>" |
| 48 | + return (prevlnum > 0) * indent(prevlnum) - shiftwidth() |
| 49 | + endif |
| 50 | + return cindent(a:lnum) |
| 51 | +endfunction |
| 52 | + |
| 53 | +let &cpo = s:save_cpo |
| 54 | +unlet s:save_cpo |
0 commit comments