aboutsummaryrefslogtreecommitdiff
path: root/runtime/autoload/typst.vim
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/autoload/typst.vim')
-rw-r--r--runtime/autoload/typst.vim30
1 files changed, 29 insertions, 1 deletions
diff --git a/runtime/autoload/typst.vim b/runtime/autoload/typst.vim
index 55edd23928..6d097dd922 100644
--- a/runtime/autoload/typst.vim
+++ b/runtime/autoload/typst.vim
@@ -1,6 +1,6 @@
" Language: Typst
" Maintainer: Gregory Anders
-" Last Change: 2024-07-14
+" Last Change: 2024 Nov 02
" Based on: https://github.com/kaarmu/typst.vim
function! typst#indentexpr() abort
@@ -18,6 +18,9 @@ function! typst#indentexpr() abort
" Use last indent for block comments
if l:synname == 'typstCommentBlock'
return l:ind
+ " do not change the indents of bullet lists
+ elseif l:synname == 'typstMarkupBulletList'
+ return indent(a:lnum)
endif
if l:pline =~ '\v[{[(]\s*$'
@@ -31,6 +34,31 @@ function! typst#indentexpr() abort
return l:ind
endfunction
+function typst#foldexpr()
+ let line = getline(v:lnum)
+
+ " Whenever the user wants to fold nested headers under the parent
+ let nested = get(g:, "typst_foldnested", 1)
+
+ " Regular headers
+ let depth = match(line, '\(^=\+\)\@<=\( .*$\)\@=')
+
+ " Do not fold nested regular headers
+ if depth > 1 && !nested
+ let depth = 1
+ endif
+
+ if depth > 0
+ " check syntax, it should be typstMarkupHeading
+ let syncode = synstack(v:lnum, 1)
+ if len(syncode) > 0 && synIDattr(syncode[0], 'name') ==# 'typstMarkupHeading'
+ return ">" . depth
+ endif
+ endif
+
+ return "="
+endfunction
+
" Gets the previous non-blank line that is not a comment.
function! s:get_prev_nonblank(lnum) abort
let l:lnum = prevnonblank(a:lnum)