Skip to content

Commit

Permalink
add generic conceal option
Browse files Browse the repository at this point in the history
  • Loading branch information
kaarmu committed Dec 5, 2023
1 parent fff946c commit 5b11b42
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
(Neo)vim plugin for [Typst](https://typst.app).

I am applying the 80/20 rule in this project since I prefer to have
something now rather than waiting for everthing later.
something now rather than waiting for everything later.

## Features

Expand All @@ -15,8 +15,8 @@ something now rather than waiting for everthing later.
**Existing**
- Vim syntax highlighting.
- Compile the active document with `:make`.
- Concealing for italic, bold. You must `set conceallevel=2` for this to work.
- Concealing symbols in math mode. You must `set conceallevel=2` and the `g:typst_conceal_math` option.
- Concealing for italic, bold. Can be enabled with `g:typst_conceal`.
- Concealing symbols in math mode. Can be enabled with `g:typst_conceal_math`.

**Possible features**
- Formatting using [this](https://github.com/astrale-sharp/typst-fmt/)?
Expand Down Expand Up @@ -64,18 +64,26 @@ call plug#end()

### Options

- `g:typst_cmd`:
Specifies the location of the Typst executable. Defaults to `"typst"`.
- `g:typst_pdf_viewer`:
- `g:typst_cmd`:
Specifies the location of the Typst executable.
*Default:* `'typst'`
- `g:typst_pdf_viewer`:
Specifies pdf viewer that `typst watch --open` will use.
*Default:* `''`
- `gtypst_conceal`:
Enable concealment.
*Default:* `0`
- `g:typst_conceal_math`:
Enable concealment for math symbols in math mode (i.e. replaces symbols
with their actual unicode character). **OBS**: this can affect performance,
see issue [#64](https://github.com/kaarmu/typst.vim/issues/64).
- `g:typst_auto_close_toc`:
*Default:* `g:typst_conceal`
- `g:typst_auto_close_toc`:
Specifies whether TOC will be automatically closed after using it.
*Default:* `0`
- `g:typst_auto_open_quickfix`:
Specifies whether the quickfix list should automatically open when there are errors from typst. Defaults to `v:true`.
Specifies whether the quickfix list should automatically open when there are errors from typst.
*Default:* `1`

### Commands

Expand Down
7 changes: 6 additions & 1 deletion ftplugin/typst.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ endfunction

call s:declare_option('typst_cmd', 'typst')
call s:declare_option('typst_pdf_viewer', '')
call s:declare_option('typst_conceal_math', 0)
call s:declare_option('typst_conceal', 0)
call s:declare_option('typst_conceal_math', g:typst_conceal)
call s:declare_option('typst_auto_close_toc', 0)
call s:declare_option('typst_auto_open_quickfix', 1)

Expand All @@ -34,6 +35,10 @@ setlocal tabstop=8
setlocal softtabstop=2
setlocal shiftwidth=2

if g:typst_conceal
setlocal conceallevel=2
endif

setlocal commentstring=//%s
setlocal comments=s1:/*,mb:*,ex:*/,://

Expand Down
36 changes: 26 additions & 10 deletions syntax/typst.vim
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,37 @@ syntax match typstMarkupEnumList
syntax match typstMarkupItalic
\ /\v(\w|\\)@1<!_\S@=.{-}(\n.{-1,})*\S@1<=\\@1<!_/
\ contains=typstMarkupItalicRegion
syntax region typstMarkupItalicRegion
\ contained
\ matchgroup=typstMarkupItalicDelimiter
\ start=/\(^\|[^0-9a-zA-Z]\)\@<=_/ end=/_\($\|[^0-9a-zA-Z]\)\@=/
\ concealends contains=typstMarkupLabel,typstMarkupBold,@Spell
if g:typst_conceal
syntax region typstMarkupItalicRegion
\ contained
\ matchgroup=typstMarkupItalicDelimiter
\ start=/\(^\|[^0-9a-zA-Z]\)\@<=_/ end=/_\($\|[^0-9a-zA-Z]\)\@=/
\ concealends contains=typstMarkupLabel,typstMarkupBold,@Spell
else
syntax region typstMarkupItalicRegion
\ contained
\ matchgroup=typstMarkupItalicDelimiter
\ start=/\(^\|[^0-9a-zA-Z]\)\@<=_/ end=/_\($\|[^0-9a-zA-Z]\)\@=/
\ contains=typstMarkupLabel,typstMarkupBold,@Spell
endif
" syntax match typstMarkupBoldError
" \ /\v(\w|\\)@<!\*\S@=.*|.*\S@<=\\@<!\*/
syntax match typstMarkupBold
\ /\v(\w|\\)@1<!\*\S@=.{-}(\n.{-1,})*\S@1<=\\@1<!\*/
\ contains=typstMarkupBoldRegion
syntax region typstMarkupBoldRegion
\ contained
\ matchgroup=typstMarkupBoldDelimiter
\ start=/\(^\|[^0-9a-zA-Z]\)\@<=\*/ end=/\*\($\|[^0-9a-zA-Z]\)\@=/
\ concealends contains=typstMarkupLabel,typstMarkupBold,@Spell
if g:typst_conceal
syntax region typstMarkupBoldRegion
\ contained
\ matchgroup=typstMarkupBoldDelimiter
\ start=/\(^\|[^0-9a-zA-Z]\)\@<=\*/ end=/\*\($\|[^0-9a-zA-Z]\)\@=/
\ concealends contains=typstMarkupLabel,typstMarkupBold,@Spell
else
syntax region typstMarkupBoldRegion
\ contained
\ matchgroup=typstMarkupBoldDelimiter
\ start=/\(^\|[^0-9a-zA-Z]\)\@<=\*/ end=/\*\($\|[^0-9a-zA-Z]\)\@=/
\ contains=typstMarkupLabel,typstMarkupBold,@Spell
endif
syntax match typstMarkupLinebreak
\ /\\\\/
syntax match typstMarkupNonbreakingSpace
Expand Down

0 comments on commit 5b11b42

Please sign in to comment.