Skip to content

Commit

Permalink
feat(toc): support for comment package
Browse files Browse the repository at this point in the history
refer: #2882
  • Loading branch information
lervag committed Feb 7, 2024
1 parent 386007c commit 281b1bd
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions autoload/vimtex/parser/toc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ function! vimtex#parser#toc#get_matchers() abort " {{{1
let l:re .= '|' . l:matcher.prefilter_re
endif
endfor
let l:cmds = vimtex#util#uniq_unsorted(l:cmds)
let l:matchers.prefilter = '\v\\%(' . join(l:cmds, '|') . ')' . l:re

return l:matchers
Expand Down
31 changes: 31 additions & 0 deletions autoload/vimtex/parser/toc/comment.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
" VimTeX - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve Lervåg
" Email: [email protected]
"

function! vimtex#parser#toc#comment#new() abort " {{{1
return s:matcher
endfunction

" }}}1

let s:matcher = {
\ 'in_preamble' : 1,
\ 'prefilter_cmds': ['begin'],
\ 're': '^\s*\\begin{comment}',
\ 're_end': '^\s*\\end{comment}',
\}
function! s:matcher.get_entry(context) abort dict " {{{1
let a:context.continue = 'comment'
return {}
endfunction

" }}}1
function! s:matcher.continue(context) abort dict " {{{1
if a:context.line =~# self.re_end
unlet! a:context.continue
endif
endfunction

" }}}1
21 changes: 21 additions & 0 deletions test/test-toc/test-comment.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
\documentclass{article}
\usepackage{comment}

\begin{document}

\section{Real section}

\begin{comment}
\section{Commented section}
\subsection{Commented subsection}
\subsubsection{Commented subsubsection}
\end{comment}

\begin{comment}
\begin{figure} \label{fig:commented}
\end{figure}
\end{comment}

\section{Next real section}

\end{document}
22 changes: 22 additions & 0 deletions test/test-toc/test-comment.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set nocompatible
let &rtp = '../..,' . &rtp
filetype plugin on

set nomore

nnoremap q :qall!<cr>
silent edit test-comment.tex

if empty($INMAKE) | finish | endif

let s:toc = vimtex#toc#get_entries()
call assert_equal(len(s:toc), 3)

" let s:i = 0
" for s:x in s:toc
" echo s:i '--' s:x.title "\n"
" let s:i += 1
" endfor

call vimtex#test#finished()

0 comments on commit 281b1bd

Please sign in to comment.