mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
vim-patch:421ed14: runtime(typst): add folding to typst ftplugin
closes: vim/vim#15897
421ed14b8a
Co-authored-by: Luca Saccarola <github.e41mv@aleeas.com>
This commit is contained in:
parent
a6d1165771
commit
a25ec00f88
@ -1,6 +1,6 @@
|
|||||||
" Language: Typst
|
" Language: Typst
|
||||||
" Maintainer: Gregory Anders
|
" Maintainer: Gregory Anders
|
||||||
" Last Change: 2024-07-14
|
" Last Change: 2024 Oct 21
|
||||||
" Based on: https://github.com/kaarmu/typst.vim
|
" Based on: https://github.com/kaarmu/typst.vim
|
||||||
|
|
||||||
function! typst#indentexpr() abort
|
function! typst#indentexpr() abort
|
||||||
@ -31,6 +31,31 @@ function! typst#indentexpr() abort
|
|||||||
return l:ind
|
return l:ind
|
||||||
endfunction
|
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.
|
" Gets the previous non-blank line that is not a comment.
|
||||||
function! s:get_prev_nonblank(lnum) abort
|
function! s:get_prev_nonblank(lnum) abort
|
||||||
let l:lnum = prevnonblank(a:lnum)
|
let l:lnum = prevnonblank(a:lnum)
|
||||||
|
@ -1039,6 +1039,19 @@ TYPST *ft-typst-plugin*
|
|||||||
*g:typst_conceal*
|
*g:typst_conceal*
|
||||||
When |TRUE| the Typst filetype plugin will set the 'conceallevel' option to 2.
|
When |TRUE| the Typst filetype plugin will set the 'conceallevel' option to 2.
|
||||||
|
|
||||||
|
*g:typst_folding*
|
||||||
|
When |TRUE| the Typst filetype plugin will fold headings. (default: |FALSE|)
|
||||||
|
|
||||||
|
To enable: >
|
||||||
|
let g:typst_folding = 1
|
||||||
|
<
|
||||||
|
*g:typst_foldnested*
|
||||||
|
When |TRUE| the Typst filetype plugin will fold nested heading under their parents
|
||||||
|
(default: |TRUE|)
|
||||||
|
|
||||||
|
To disable: >
|
||||||
|
let g:typst_foldnested = 0
|
||||||
|
<
|
||||||
VIM *ft-vim-plugin*
|
VIM *ft-vim-plugin*
|
||||||
|
|
||||||
The Vim filetype plugin defines mappings to move to the start and end of
|
The Vim filetype plugin defines mappings to move to the start and end of
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
" Vim filetype plugin file
|
" Vim filetype plugin file
|
||||||
" Language: Typst
|
" Language: Typst
|
||||||
" Maintainer: Gregory Anders
|
" Maintainer: Gregory Anders
|
||||||
" Last Change: 2024 Oct 04
|
" Last Change: 2024 Oct 21
|
||||||
" Based on: https://github.com/kaarmu/typst.vim
|
" Based on: https://github.com/kaarmu/typst.vim
|
||||||
|
|
||||||
if exists('b:did_ftplugin')
|
if exists('b:did_ftplugin')
|
||||||
@ -21,6 +21,12 @@ if get(g:, 'typst_conceal', 0)
|
|||||||
let b:undo_ftplugin .= ' cole<'
|
let b:undo_ftplugin .= ' cole<'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if has("folding") && get(g:, 'typst_folding', 0)
|
||||||
|
setlocal foldexpr=typst#foldexpr()
|
||||||
|
setlocal foldmethod=expr
|
||||||
|
let b:undo_ftplugin .= "|setl foldexpr< foldmethod<"
|
||||||
|
endif
|
||||||
|
|
||||||
if !exists('current_compiler')
|
if !exists('current_compiler')
|
||||||
compiler typst
|
compiler typst
|
||||||
let b:undo_ftplugin ..= "| compiler make"
|
let b:undo_ftplugin ..= "| compiler make"
|
||||||
|
Loading…
Reference in New Issue
Block a user