lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.4k stars 388 forks source link

Disregard contents of "comment" environment #2882

Closed boolanger closed 3 weeks ago

boolanger commented 7 months ago

Issue

Vimtex currently treats \section{...}, \subsection{...}, and \subsubsection{..} commands inside the comment environment as if they were real sections in at least these ways (I may have missed others):

To reproduce, open the following with vim:

\documentclass{article}
\usepackage{comment}
\begin{document}
\section{Real section}
\begin{comment}
\section{Commented section}
\subsection{Commented subsection}
\subsubsection{Commented subsubsection}
\end{comment}
\end{document}

with .vimrc

call plug#begin('~/.vim/plugged')
Plug 'lervag/vimtex'
call plug#end()
let g:vimtex_fold_enabled=1

Proposed Solution

I think that it would be better to disregard commented (sub)section commands, since they are not part of the structure of the document. That would mean:

Personally, I like the ability to comment out entire sections, and this would help me do that without messing up document navigation.

By the way, thanks for all your work on vimtex, it's much appreciated!

Edit: For clarity, and I've also added some more features that are affected by this.

boolanger commented 7 months ago

After looking at this a little more, this issue isn't just about sections; vimtex fails to ignore the contents of the comment environment in other cases, too. My preference would be for the contents of comments to be completely ignored, i.e. treated as just text for all purposes. I hope it wouldn't be too difficult to solve these issues together; otherwise I apologize for bringing up so many things at once!

Here are the issues I've found. I'm sure there are others.

lervag commented 7 months ago

Interesting issue. I believe some of these fixes can be quite straightforward, but not all of them. It would be helpful if you could update your list in your original post with all of the issues you've noticed; perhaps you could also make it a check list with + [ ] ..., then I could check off items as I've looked into and fixed/considered them?

lervag commented 7 months ago

I believe I've solved the folding and toc issues now; please update and test. So, the motions remain; I believe these may be more tricky. But I'll have a look when I get the time.

boolanger commented 7 months ago

Thanks a lot for the quick fixes! There's still a minor issue with folding (noted below) but the TOC seems to be solved.

Below are the issues that I've been able to find. Personally, the fixes that I'd appreciate the most are those for the TOC (done), folds, as well as motions and text objects for (sub)sections. I don't often have multiline comments inside other environments or inside equations, and unbalanced delimiters or environment boundaries inside comments are even rarer, so while I'd appreciate fixes to the other issues, they would have much lower priority for me.

Examples:

lervag commented 6 months ago
  • Don't fold inside the comment environment. The comment_pkg commit almost fixes the problem for me except that I still get strange behaviour when I've just entered text in comments, exit to normal mode, and then toggle fold with za. It doesn't reproduce if you just copy the text into vim, though. Here's an example:

I'm having a hard time fixing this without changing the way to match comments entirely. I'm pushing a PR for this because I want some help testing if it causes significantly slower fold performance. Could you pull the branch and test? See #2884.

lervag commented 6 months ago

Reg. #2884; I believe it should fix your folding issue. However, as I wrote, I'm using a different method now. It would be very nice if you could test it on some large documents and report if you find it has a negative performance impact.

lervag commented 3 weeks ago

I'm considering to close this due to lack of activity. I'll close it, but feel free to reopen if you want to follow things up.

lervag commented 3 weeks ago

Notice, though, that I did create a PR (#2884) that is not merged since I was expecting feedback. If these things are now of no interest to you (or others), then I might close the PR as not so relevant to anyone.