From d802117c9c81b5d2fc319ace92626535a9eac33a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 6 Jan 2016 00:00:48 +0100 Subject: [PATCH] Add simple version of glc completion (#263) --- autoload/vimtex/complete.vim | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/autoload/vimtex/complete.vim b/autoload/vimtex/complete.vim index 9b84bd0..f6630d9 100644 --- a/autoload/vimtex/complete.vim +++ b/autoload/vimtex/complete.vim @@ -17,7 +17,7 @@ endfunction function! vimtex#complete#init_script() " {{{1 if !g:vimtex_complete_enabled | return | endif - let s:completers = [s:bib, s:ref, s:img, s:inc] + let s:completers = [s:bib, s:ref, s:img, s:inc, s:glc] endfunction " }}}1 @@ -369,6 +369,35 @@ function! s:inc.complete(regex) dict " {{{2 return self.candidates endfunction +" }}}1 +" {{{1 Glossary + +let s:glc = { + \ 'pattern' : '\v\\glc\s*\{[^{}]*', + \ 'enabled' : 1, + \} + +function! s:glc.complete(regex) dict " {{{2 + return self.parse_glossaries() +endfunction + +function! s:glc.parse_glossaries() dict " {{{2 + let self.candidates = [] + + for l:line in filter(vimtex#parser#tex(b:vimtex.tex, 0), + \ 'v:val =~# ''\\newglossaryentry''') + let l:entries = matchstr(l:line, '\\newglossaryentry\s*{\zs[^{}]*') + call add(self.candidates, { + \ 'word' : l:entries, + \ 'abbr' : l:entries, + \ 'menu' : ' [glc]', + \}) + endfor + + return self.candidates +endfunction + + " }}}1 "