robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
567053bb3c
master
1" Language: Typst 2" Maintainer: Maxim Kim <habamax@gmail.com> 3" Previous Maintainer: Luca Saccarola <github.e41mv@aleeas.com> 4" Last Change: 2026 Jun 29 5" Based on the plugin at https://github.com/kaarmu/typst.vim 6 7function ! typst#indentexpr () abort 8let l: lnum = v: lnum 9let s: sw = shiftwidth () 10 11let [ l: plnum , l: pline ] = s: get_prev_nonblank ( l: lnum - 1 ) 12if l: plnum == 0 |return 0 |endif 13 14let l: line = getline ( l: lnum ) 15let l: ind = indent ( l: plnum ) 16 17let l: synname = synIDattr ( synID ( l: lnum , 1 , 1 ), 'name' ) 18 19" Use last indent for block comments 20if l: synname == 'typstCommentBlock' 21return l: ind 22" do not change the indents of bullet lists 23elseif l: synname == 'typstMarkupBulletList' 24return indent ( a: lnum ) 25endif 26 27if l: pline =~ '\v[{[(]\s*$' 28let l: ind += s: sw 29endif 30 31if l: line =~ '\v^\s*[}\])]' 32let l: ind -= s: sw 33endif 34 35return l: ind 36endfunction 37 38function ! typst#foldexpr () 39let line = getline ( v: lnum ) 40 41" Whenever the user wants to fold nested headers under the parent 42let nested = get ( g:, "typst_foldnested" , 1 ) 43 44" Regular headers 45let depth = match ( line , '\(^=\+\)\@<=\( .*$\)\@=' ) 46 47" Do not fold nested regular headers 48if depth > 1 && ! nested 49let depth = 1 50endif 51 52if depth > 0 53" check syntax, it should be typstMarkupHeading 54let syncode = synstack ( v: lnum , 1 ) 55if len ( syncode ) > 0 && synIDattr ( syncode [ 0 ], 'name' ) ==# 'typstMarkupHeading' 56return ">" .. depth 57endif 58endif 59 60return "=" 61endfunction 62 63" Gets the previous non-blank line that is not a comment. 64function ! s: get_prev_nonblank ( lnum ) abort 65let l: lnum = prevnonblank ( a: lnum ) 66let l: line = getline ( l: lnum ) 67 68while l: lnum > 0 && l: line =~ '^\s*//' 69let l: lnum = prevnonblank ( l: lnum - 1 ) 70let l: line = getline ( l: lnum ) 71endwhile 72 73return [ l: lnum , s: remove_comments ( l: line )] 74endfunction 75 76" Removes comments from the given line. 77function ! s: remove_comments ( line ) abort 78return substitute ( a: line , '\s*//.*' , '' , '' ) 79endfunction