Skip to content

Commit

Permalink
Closes #83.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaarmu committed Feb 4, 2024
1 parent 816ba15 commit e28d440
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
26 changes: 26 additions & 0 deletions autoload/typst/options.vim
Original file line number Diff line number Diff line change
@@ -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
23 changes: 4 additions & 19 deletions ftplugin/typst.vim
Original file line number Diff line number Diff line change
@@ -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 <v0.8, workaround for https://github.com/typst/typst/issues/1937
Expand Down Expand Up @@ -59,4 +43,5 @@ command! -buffer Toct call typst#Toc('tab')

let &cpo = s:cpo_orig
unlet s:cpo_orig

" vim: tabstop=8 shiftwidth=4 softtabstop=4 expandtab
6 changes: 3 additions & 3 deletions syntax/typst.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
" Language: Typst
" Maintainer: Kaj Munhoz Arfvidsson

if exists("b:current_syntax")
finish
endif
if exists("b:current_syntax") | finish | endif

call typst#options#init()

syntax sync fromstart
syntax spell toplevel
Expand Down

0 comments on commit e28d440

Please sign in to comment.