aboutsummaryrefslogtreecommitdiff
path: root/runtime/autoload
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2024-07-15 20:02:22 +0200
committerChristian Clason <c.clason@uni-graz.at>2024-07-16 09:43:57 +0200
commita0fd51c1e2db17ab21e2a2c907b232d05dfffc88 (patch)
tree63abcde462f2276e3ccab6846eee7498f234e641 /runtime/autoload
parent08abb64680c0fb6d31546be22686db4997564b9c (diff)
downloadrneovim-a0fd51c1e2db17ab21e2a2c907b232d05dfffc88.tar.gz
rneovim-a0fd51c1e2db17ab21e2a2c907b232d05dfffc88.tar.bz2
rneovim-a0fd51c1e2db17ab21e2a2c907b232d05dfffc88.zip
vim-patch:1cc4cae: runtime(typst): Add typst runtime files
closes: vim/vim#15234 https://github.com/vim/vim/commit/1cc4cae961a7b49608ef7bd56837cc723d49db4d Co-authored-by: Gregory Anders <greg@gpanders.com>
Diffstat (limited to 'runtime/autoload')
-rw-r--r--runtime/autoload/typst.vim50
1 files changed, 50 insertions, 0 deletions
diff --git a/runtime/autoload/typst.vim b/runtime/autoload/typst.vim
new file mode 100644
index 0000000000..55edd23928
--- /dev/null
+++ b/runtime/autoload/typst.vim
@@ -0,0 +1,50 @@
+" Language: Typst
+" Maintainer: Gregory Anders
+" Last Change: 2024-07-14
+" Based on: https://github.com/kaarmu/typst.vim
+
+function! typst#indentexpr() abort
+ let l:lnum = v:lnum
+ let s:sw = shiftwidth()
+
+ let [l:plnum, l:pline] = s:get_prev_nonblank(l:lnum - 1)
+ if l:plnum == 0 | return 0 | endif
+
+ let l:line = getline(l:lnum)
+ let l:ind = indent(l:plnum)
+
+ let l:synname = synIDattr(synID(l:lnum, 1, 1), 'name')
+
+ " Use last indent for block comments
+ if l:synname == 'typstCommentBlock'
+ return l:ind
+ endif
+
+ if l:pline =~ '\v[{[(]\s*$'
+ let l:ind += s:sw
+ endif
+
+ if l:line =~ '\v^\s*[}\])]'
+ let l:ind -= s:sw
+ endif
+
+ return l:ind
+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)
+ let l:line = getline(l:lnum)
+
+ while l:lnum > 0 && l:line =~ '^\s*//'
+ let l:lnum = prevnonblank(l:lnum - 1)
+ let l:line = getline(l:lnum)
+ endwhile
+
+ return [l:lnum, s:remove_comments(l:line)]
+endfunction
+
+" Removes comments from the given line.
+function! s:remove_comments(line) abort
+ return substitute(a:line, '\s*//.*', '', '')
+endfunction