From e28d440c7ba4df2516d7d7f908c4fb664a8cf86c Mon Sep 17 00:00:00 2001 From: Kaj Munhoz Arfvidsson Date: Sun, 4 Feb 2024 18:34:45 +0100 Subject: [PATCH] Closes #83. --- autoload/typst/options.vim | 26 ++++++++++++++++++++++++++ ftplugin/typst.vim | 23 ++++------------------- syntax/typst.vim | 6 +++--- 3 files changed, 33 insertions(+), 22 deletions(-) create mode 100644 autoload/typst/options.vim diff --git a/autoload/typst/options.vim b/autoload/typst/options.vim new file mode 100644 index 0000000..b12fe9f --- /dev/null +++ b/autoload/typst/options.vim @@ -0,0 +1,26 @@ + +let s:initialized = v:false + +function! typst#options#init() abort " {{{1 + if s:initialized | return | endif + + call s:declare_option('typst_cmd', 'typst') + call s:declare_option('typst_pdf_viewer', '') + call s:declare_option('typst_conceal', 0) + call s:declare_option('typst_conceal_math', g:typst_conceal) + call s:declare_option('typst_conceal_emoji', g:typst_conceal) + call s:declare_option('typst_auto_close_toc', 0) + call s:declare_option('typst_auto_open_quickfix', 1) + call s:declare_option('typst_embedded_languages', []) + + let s:initialized = v:true +endfunction " }}}1 + +function! s:declare_option(option, default) " {{{1 + let l:option = 'g:' . a:option + if !exists(l:option) + let {l:option} = a:default + endif +endfunction " }}}1 + +" vim: tabstop=8 shiftwidth=4 softtabstop=4 expandtab diff --git a/ftplugin/typst.vim b/ftplugin/typst.vim index 2ef4a85..cd24eaa 100644 --- a/ftplugin/typst.vim +++ b/ftplugin/typst.vim @@ -1,28 +1,12 @@ " Only do this when not done yet for this buffer -if exists("b:did_ftplugin") - finish -endif - -function! s:declare_option(option, value) - if !exists('g:'..a:option) - exec 'let g:'..a:option..' = '..string(a:value) - endif -endfunction - -call s:declare_option('typst_cmd', 'typst') -call s:declare_option('typst_pdf_viewer', '') -call s:declare_option('typst_conceal', 0) -call s:declare_option('typst_conceal_math', g:typst_conceal) -call s:declare_option('typst_conceal_emoji', g:typst_conceal) -call s:declare_option('typst_auto_close_toc', 0) -call s:declare_option('typst_auto_open_quickfix', 1) -call s:declare_option('typst_embedded_languages', []) - +if exists("b:did_ftplugin") | finish | endif let b:did_ftplugin = 1 let s:cpo_orig = &cpo set cpo&vim +call typst#options#init() + compiler typst " " If you're on typst