From 5a5962d6ebc10db3e20d9a1b7cf9e453c28427a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Tue, 6 Apr 2021 22:19:31 +0200 Subject: [PATCH 1/6] feat: add conceals for (sub)*sections refer: #1978 --- autoload/vimtex/options.vim | 1 + autoload/vimtex/syntax/core.vim | 18 ++++++++++++++++++ doc/vimtex.txt | 3 +++ test/test-syntax/test-conceal.tex | 8 ++++++++ 4 files changed, 30 insertions(+) diff --git a/autoload/vimtex/options.vim b/autoload/vimtex/options.vim index f670cde374..2269651b24 100644 --- a/autoload/vimtex/options.vim +++ b/autoload/vimtex/options.vim @@ -284,6 +284,7 @@ function! vimtex#options#init() abort " {{{1 \ 'math_fracs': g:vimtex_syntax_conceal_default, \ 'math_super_sub': g:vimtex_syntax_conceal_default, \ 'math_symbols': g:vimtex_syntax_conceal_default, + \ 'sections': g:vimtex_syntax_conceal_default, \ 'styles': g:vimtex_syntax_conceal_default, \}) call s:init_option('vimtex_syntax_conceal_cites', { diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 681abf21a4..f8b3d78f65 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -614,6 +614,11 @@ function! vimtex#syntax#core#init() abort " {{{1 if g:vimtex_syntax_conceal.cites call s:match_conceal_cites_{g:vimtex_syntax_conceal_cites.type}() endif + + " Conceal section commands + if g:vimtex_syntax_conceal.sections + call s:match_conceal_sections() + endif endif " }}}2 @@ -785,6 +790,7 @@ function! vimtex#syntax#core#init_highlights() abort " {{{1 highlight def link texParboxOptHeight texError highlight def link texParboxOptIPos texError highlight def link texParboxOptPos texError + highlight def link texPartConcealed texCmdPart highlight def link texRefOpt texOpt highlight def link texRefConcealedOpt1 texRefOpt highlight def link texRefConcealedOpt2 texRefOpt @@ -1939,3 +1945,15 @@ function! s:gather_newtheorems() abort " {{{1 endfunction " }}}1 +function! s:match_conceal_sections() abort " {{{1 + syntax match texCmdPart "\v\\%(sub)*section>\*?" contains=texPartConcealed nextgroup=texPartArgTitle + syntax match texPartConcealed "\\" contained conceal cchar=# + syntax match texPartConcealed "sub" contained conceal cchar=# + syntax match texPartConcealed "section" contained conceal cchar= + + call vimtex#syntax#core#new_arg('texPartArgTitle', { + \ 'opts': 'contained keepend concealends' + \}) +endfunction + +" }}}1 diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 095e7aa4b8..13cbf8f726 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -2183,6 +2183,9 @@ OPTIONS *vimtex-options* Replace various math symbol commands to an equivalent unicode character. This includes quite a lot of replacements, so be warned! + sections~ + Conceal `\(sub)*section` commands. + styles~ Conceal the LaTeX command "boundaries" for italicized and bolded style commands, i.e. `\emph`, `\textit`, and `\textbf`. This means that one diff --git a/test/test-syntax/test-conceal.tex b/test/test-syntax/test-conceal.tex index ef9628042a..758226720e 100644 --- a/test/test-syntax/test-conceal.tex +++ b/test/test-syntax/test-conceal.tex @@ -63,4 +63,12 @@ $$\lVert \mathrm{w} \rVert_2^2$$ +\chapter{test} + +\section{test} + +\subsection{testing} + +\subsubsection{testing} + \end{document} From eebb320f9501a0ca60f431aa97118c4b34e13dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 7 Apr 2021 22:59:35 +0200 Subject: [PATCH 2/6] doc: minor improvement --- doc/vimtex.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 13cbf8f726..8893d4e2a9 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -2184,7 +2184,11 @@ OPTIONS *vimtex-options* This includes quite a lot of replacements, so be warned! sections~ - Conceal `\(sub)*section` commands. + Conceal `\(sub)*section` commands. The titles are replaced with Markdown + style ATX headers, e.g.: + + `\section{Test}` --> `# Test` + `\subsection{Test}` --> `## Test` styles~ Conceal the LaTeX command "boundaries" for italicized and bolded style @@ -4079,6 +4083,7 @@ are several major differences that users may want to be aware of: Associated settings: * |g:vimtex_syntax_enabled| * |g:vimtex_syntax_conceal| +* |g:vimtex_syntax_conceal_cites| * |g:vimtex_syntax_conceal_default| * |g:vimtex_syntax_nested| * |g:vimtex_syntax_nospell_commands| From 27214974402e566adfa6a9d5b695b2bfa8c164bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 7 Apr 2021 23:01:06 +0200 Subject: [PATCH 3/6] feat: change option name and default of section conceal g:vimtex_syntax_conceal_default is removed in favour of g:vimtex_syntax_conceal_disable --- autoload/vimtex/options.vim | 36 +++++++++++++++++------------ doc/vimtex.txt | 45 +++++++++++++++++++++++++------------ 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/autoload/vimtex/options.vim b/autoload/vimtex/options.vim index 2269651b24..5c01c1683f 100644 --- a/autoload/vimtex/options.vim +++ b/autoload/vimtex/options.vim @@ -273,25 +273,25 @@ function! vimtex#options#init() abort " {{{1 call s:init_option('vimtex_subfile_start_local', 0) call s:init_option('vimtex_syntax_enabled', 1) - call s:init_option('vimtex_syntax_conceal_default', 1) call s:init_option('vimtex_syntax_conceal', { - \ 'accents': g:vimtex_syntax_conceal_default, - \ 'cites': g:vimtex_syntax_conceal_default, - \ 'fancy': g:vimtex_syntax_conceal_default, - \ 'greek': g:vimtex_syntax_conceal_default, - \ 'math_bounds': g:vimtex_syntax_conceal_default, - \ 'math_delimiters': g:vimtex_syntax_conceal_default, - \ 'math_fracs': g:vimtex_syntax_conceal_default, - \ 'math_super_sub': g:vimtex_syntax_conceal_default, - \ 'math_symbols': g:vimtex_syntax_conceal_default, - \ 'sections': g:vimtex_syntax_conceal_default, - \ 'styles': g:vimtex_syntax_conceal_default, + \ 'accents': 1, + \ 'cites': 1, + \ 'fancy': 1, + \ 'greek': 1, + \ 'math_bounds': 1, + \ 'math_delimiters': 1, + \ 'math_fracs': 1, + \ 'math_super_sub': 1, + \ 'math_symbols': 1, + \ 'sections': 0, + \ 'styles': 1, \}) call s:init_option('vimtex_syntax_conceal_cites', { \ 'type': 'brackets', \ 'icon': '📖', \ 'verbose': v:true, \}) + call s:init_option('vimtex_syntax_conceal_disable', 0) call s:init_option('vimtex_syntax_custom_cmds', []) call s:init_option('vimtex_syntax_nested', { \ 'aliases' : { @@ -324,10 +324,17 @@ function! vimtex#options#init() abort " {{{1 call s:init_option('vimtex_syntax_nospell_comments', 0) call s:init_option('vimtex_syntax_packages', { \ 'amsmath': {'load': 2}, - \ 'babel': {'conceal': g:vimtex_syntax_conceal_default}, - \ 'hyperref': {'conceal': g:vimtex_syntax_conceal_default}, + \ 'babel': {'conceal': 1}, + \ 'hyperref': {'conceal': 1}, \}) + " Disable conceals if chosen + if g:vimtex_syntax_conceal_disable + call map(g:vimtex_syntax_conceal, {k, v -> 0}) + let g:vimtex_syntax_packages.babel.conceal = 0 + let g:vimtex_syntax_packages.hyperref.conceal = 0 + endif + call s:init_option('vimtex_texcount_custom_arg', '') call s:init_option('vimtex_text_obj_enabled', 1) @@ -465,6 +472,7 @@ function! s:check_for_deprecated_options() abort " {{{1 \ 'g:vimtex_quickfix_latexlog', \ 'g:vimtex_quickfix_warnings', \ 'g:vimtex_syntax_autoload_packages', + \ 'g:vimtex_syntax_conceal_default', \ 'g:vimtex_textidote_jar', \ 'g:vimtex_toc_fold', \ 'g:vimtex_toc_fold_level_start', diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 8893d4e2a9..493307d0b4 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -2133,13 +2133,6 @@ OPTIONS *vimtex-options* Default value: 1. -*g:vimtex_syntax_conceal_default* - Specify the default flag for the conceal feature. This is used e.g. in - |vimtex_syntax_conceal| and for package specific options in - |vimtex_syntax_packages|. For more info, see |vimtex-syntax-conceal|. - - Default value: 1 - *g:vimtex_syntax_conceal* A dictionary for specifying which core conceal features to activate. This mostly implies concealing particular elements with a replacement unicode @@ -2197,7 +2190,28 @@ OPTIONS *vimtex-options* `\emph{text here}` --> `text here` - Default value: All keys set to |g:vimtex_syntax_conceal_default|. + Default value: > + + let g:vimtex_syntax_conceal = { + \ 'accents': 1, + \ 'cites': 1, + \ 'fancy': 1, + \ 'greek': 1, + \ 'math_bounds': 1, + \ 'math_delimiters': 1, + \ 'math_fracs': 1, + \ 'math_super_sub': 1, + \ 'math_symbols': 1, + \ 'sections': 0, + \ 'styles': 1, + \} + +*g:vimtex_syntax_conceal_disable* + The option |g:vimtex_syntax_conceal| allows to selectively disable conceal + features. For convenience, this option allows to disable all conceal + features in one go. For more info, see |vimtex-syntax-conceal|. + + Default value: 0 *g:vimtex_syntax_conceal_cites* A simple dictionary to control how citation conceal should work. It has @@ -2358,8 +2372,7 @@ OPTIONS *vimtex-options* array~ asymptote~ babel~ - `conceal` whether to enable conceal - Default: |g:vimtex_syntax_conceal_default| + `conceal` whether to enable conceal; enabled by default beamer~ biblatex~ booktabs~ @@ -4084,7 +4097,7 @@ Associated settings: * |g:vimtex_syntax_enabled| * |g:vimtex_syntax_conceal| * |g:vimtex_syntax_conceal_cites| -* |g:vimtex_syntax_conceal_default| +* |g:vimtex_syntax_conceal_disable| * |g:vimtex_syntax_nested| * |g:vimtex_syntax_nospell_commands| * |g:vimtex_syntax_packages| @@ -4096,9 +4109,9 @@ VimTeX utilizes the |syn-conceal| feature of Vim to allow displaying commands like `\alpha` as `α`. That is, various elements/commands can be concealed or substituted with a unicode symbol. -This feature is enabled by default. It can be fully disabled with -|g:vimtex_syntax_conceal_default| or specific types of concealments can be -disabled with |g:vimtex_syntax_conceal|. +This feature is mostly enabled by default. Various types of concealments can +be enabled/disabled with |g:vimtex_syntax_conceal|. The entire feature can be +fully disabled with |g:vimtex_syntax_conceal_disable|. For conceals to work properly, one must set the option 'conceallevel' to 2. It is also good to be aware of the 'concealcursor' option. @@ -5789,6 +5802,10 @@ The following changelog only logs particularly important changes, such as changes that break backwards compatibility. See the git log for the detailed changelog. +2021-04-07: Better options for syntax conceal~ +Deprecated *g:vimtex_syntax_conceal_default* in favour of the more simple +|g:vimtex_syntax_conceal_disable|. + 2020-11-16: More flexible package syntax options~ Deprecate *g:vimtex_syntax_autoload_packages* in favor of |g:vimtex_syntax_packages|, which allows more fine grained control over each From bbae745a986801bac4fa5f06968af24a74abb3ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 7 Apr 2021 23:05:58 +0200 Subject: [PATCH 4/6] fix: minor issue --- autoload/vimtex/compiler.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/vimtex/compiler.vim b/autoload/vimtex/compiler.vim index fc576c5380..789184338c 100644 --- a/autoload/vimtex/compiler.vim +++ b/autoload/vimtex/compiler.vim @@ -426,7 +426,7 @@ endfunction " {{{1 Initialize module -if !g:vimtex_compiler_enabled | finish | endif +if !get(g:, 'vimtex_compiler_enabled') | finish | endif augroup vimtex_compiler autocmd! From 406303ebdf5ffbcf02ef4b8bf3d990154145f38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Thu, 15 Apr 2021 21:53:37 +0200 Subject: [PATCH 5/6] fix: minor issues refer: #2022 --- autoload/vimtex/syntax/core.vim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index f8b3d78f65..3e297ea09a 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -791,6 +791,7 @@ function! vimtex#syntax#core#init_highlights() abort " {{{1 highlight def link texParboxOptIPos texError highlight def link texParboxOptPos texError highlight def link texPartConcealed texCmdPart + highlight def link texPartConcArgTitle texPartArgTitle highlight def link texRefOpt texOpt highlight def link texRefConcealedOpt1 texRefOpt highlight def link texRefConcealedOpt2 texRefOpt @@ -1946,12 +1947,12 @@ endfunction " }}}1 function! s:match_conceal_sections() abort " {{{1 - syntax match texCmdPart "\v\\%(sub)*section>\*?" contains=texPartConcealed nextgroup=texPartArgTitle + syntax match texCmdPart "\v\\%(sub)*section>\*?" contains=texPartConcealed nextgroup=texPartConcArgTitle syntax match texPartConcealed "\\" contained conceal cchar=# syntax match texPartConcealed "sub" contained conceal cchar=# - syntax match texPartConcealed "section" contained conceal cchar= + syntax match texPartConcealed "section\*\?" contained conceal cchar= - call vimtex#syntax#core#new_arg('texPartArgTitle', { + call vimtex#syntax#core#new_arg('texPartConcArgTitle', { \ 'opts': 'contained keepend concealends' \}) endfunction From d8a1e54879f02fe49a91b291ff970bd0a90111bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sat, 9 Oct 2021 16:39:13 +0200 Subject: [PATCH 6/6] chore: adjustments --- autoload/vimtex/syntax/core.vim | 22 +++++++++++----------- doc/vimtex.txt | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 3e297ea09a..3e35260908 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -1934,17 +1934,6 @@ function! s:match_conceal_cites_icon() abort " {{{1 \ 'conceal cchar=' . g:vimtex_syntax_conceal_cites.icon endfunction -" }}}1 - -function! s:gather_newtheorems() abort " {{{1 - let l:lines = vimtex#parser#preamble(b:vimtex.tex) - - call filter(l:lines, {_, x -> x =~# '^\s*\\newtheorem\>'}) - call map(l:lines, {_, x -> matchstr(x, '^\s*\\newtheorem\>\*\?{\zs[^}]*')}) - - return l:lines -endfunction - " }}}1 function! s:match_conceal_sections() abort " {{{1 syntax match texCmdPart "\v\\%(sub)*section>\*?" contains=texPartConcealed nextgroup=texPartConcArgTitle @@ -1958,3 +1947,14 @@ function! s:match_conceal_sections() abort " {{{1 endfunction " }}}1 + +function! s:gather_newtheorems() abort " {{{1 + let l:lines = vimtex#parser#preamble(b:vimtex.tex) + + call filter(l:lines, {_, x -> x =~# '^\s*\\newtheorem\>'}) + call map(l:lines, {_, x -> matchstr(x, '^\s*\\newtheorem\>\*\?{\zs[^}]*')}) + + return l:lines +endfunction + +" }}}1 diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 493307d0b4..18ed652f9c 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -5802,8 +5802,8 @@ The following changelog only logs particularly important changes, such as changes that break backwards compatibility. See the git log for the detailed changelog. -2021-04-07: Better options for syntax conceal~ -Deprecated *g:vimtex_syntax_conceal_default* in favour of the more simple +2021-10-09: Better options for syntax conceal~ +Deprecated *g:vimtex_syntax_conceal_default* in favour of |g:vimtex_syntax_conceal_disable|. 2020-11-16: More flexible package syntax options~