From e1e520d365900194fd3f4dd2643f34486d4c5775 Mon Sep 17 00:00:00 2001 From: Hektor Misplon Date: Mon, 15 May 2023 13:41:06 +0200 Subject: [PATCH] Detect snippet math contexts --- .vim/ftplugin/pandoc/wiki.vim | 16 ++++++++++++++++ .vim/snips/pandoc.snippets | 11 +++++++++++ 2 files changed, 27 insertions(+) diff --git a/.vim/ftplugin/pandoc/wiki.vim b/.vim/ftplugin/pandoc/wiki.vim index d076429..6a0b2d3 100644 --- a/.vim/ftplugin/pandoc/wiki.vim +++ b/.vim/ftplugin/pandoc/wiki.vim @@ -1,2 +1,18 @@ set cc=81 set cocu="" +func! GetContext() + " https://stackoverflow.com/questions/9464844/how-to-get-group-name-of-highlighting-under-cursor-in-vim + if !exists("*synstack") + return + endif + let matches = map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")') + if index(matches, 'pandocLaTeXInlineMath') >= 0 + echo 'math_inline' + elseif index(matches, 'pandocLaTeXMathBlock') >= 0 + echo 'math_block' + else + echo '' + endif +endfunc +com! -nargs=0 GetContext :call GetContext() + diff --git a/.vim/snips/pandoc.snippets b/.vim/snips/pandoc.snippets index 2a1bd36..525dd1a 100644 --- a/.vim/snips/pandoc.snippets +++ b/.vim/snips/pandoc.snippets @@ -24,6 +24,17 @@ # # Online reference: https://github.com/SirVer/ultisnips/blob/master/doc/UltiSnips.txt +global !p +def math(): + return vim.command_output('GetContext') == 'math_inline' or vim.command_output('GetContext') == 'math_block' + +def math_inline(): + return vim.command_output('GetContext') == 'math_inline' + +def math_block(): + return vim.command_output('GetContext') == 'math_block' +endglobal + extends html # Zettelkasten templating