aboutsummaryrefslogtreecommitdiff
path: root/runtime/autoload/typst.vim
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2024-10-22 00:18:16 +0200
committerChristian Clason <ch.clason+github@icloud.com>2024-10-22 09:10:46 +0200
commita25ec00f8886c9b87e9423aedd498cec9419508b (patch)
tree4e192cdc2a727777df245e3cc0f294b9e75c1dcf /runtime/autoload/typst.vim
parenta6d1165771781732cb8ff6105df6f0429c46cde1 (diff)
downloadrneovim-a25ec00f8886c9b87e9423aedd498cec9419508b.tar.gz
rneovim-a25ec00f8886c9b87e9423aedd498cec9419508b.tar.bz2
rneovim-a25ec00f8886c9b87e9423aedd498cec9419508b.zip
vim-patch:421ed14: runtime(typst): add folding to typst ftplugin
closes: vim/vim#15897 https://github.com/vim/vim/commit/421ed14b8a0f50e0d2d9247dda49feb69352bd0d Co-authored-by: Luca Saccarola <github.e41mv@aleeas.com>
Diffstat (limited to 'runtime/autoload/typst.vim')
-rw-r--r--runtime/autoload/typst.vim27
1 files changed, 26 insertions, 1 deletions
diff --git a/runtime/autoload/typst.vim b/runtime/autoload/typst.vim
index 55edd23928..baf765a30b 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 Oct 21
" Based on: https://github.com/kaarmu/typst.vim
function! typst#indentexpr() abort
@@ -31,6 +31,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)