Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting vimtex_indent_lists to empty will make all environments behave like list instead #2846

Closed
user202729 opened this issue Dec 6, 2023 · 4 comments
Labels

Comments

@user202729
Copy link

user202729 commented Dec 6, 2023

As in the title.

The suggestion to set this variable to [] was made in #2599 , but it doesn't seem to behave the expected way.

This is caused by the code:

https://github.com/lervag/vimtex/blob/master/indent/tex.vim#L234-L237

if the list is empty, the regex being constructed end up being \\end{\%(\), which matches the end delimiter of every environment.

Side note, in the current situation it will also match any environment name that starts with one of the items in the list.

Side note 2, actually this explicit setting of g:vimtex_indent_lists is only necessary because vimtex cannot look backward in the document to see whether any occurrence of \item appeared in the current environment, right? Otherwise we can just look behind to see if any string \item appeared in the current environment (and not in any nested environment, which can be annoying to implement anyway)

@lervag
Copy link
Owner

lervag commented Dec 7, 2023

The suggestion to set this variable to [] was made in #2599 , but it doesn't seem to behave the expected way.

Sorry, that's fixed now!

Side note, in the current situation it will also match any environment name that starts with one of the items in the list.

This is partly intentional; the list is a list of regexes and the user has flexibility to make it more or less strict.

Side note 2, actually this explicit setting of g:vimtex_indent_lists

You mean the default value? Or some other explicit setting?

is only necessary because vimtex cannot look backward in the document to see whether any occurrence of \item appeared in the current environment, right?

I mean, we can look backward - I do that a lot. But it is quite expensive, so I try to avoid things like that.

Otherwise we can just look behind to see if any string \item appeared in the current environment (and not in any nested environment, which can be annoying to implement anyway)

Sorry about my confusion, but what are you trying to achieve? The point of the option is to allow users flexibility in when to indent the \items...

@user202729
Copy link
Author

This is partly intentional; the list is a list of regexes and the user has flexibility to make it more or less strict.

I see. Maybe mention in the documentation (and also documentation of related settings such as g:vimtex_indent_ignored_envs)?

Sorry about my confusion, but what are you trying to achieve? The point of the option is to allow users flexibility in when to indent the \items...

Ah I see. (the following code is consider "correctly indented" by vimtex.)

\begin{quote}
	% correctly used:
	\begin{quote}
		stuff
	\end{quote}
	\begin{itemize}
		\item stuff
			stuff
		\item stuff
			stuff
	\end{itemize}
	% "incorrectly used":
	\begin{quote}
	\item stuff
		stuff
	\item stuff
		stuff
	\end{quote}
	\begin{itemize}
		stuff
\end{itemize}
\end{quote}

I originally thought of: if \item is detected in the environment body then automatically indent it as if it's a list environment, otherwise automatically indent it as if it isn't. But looks like the behavior is different when \item is used in a non-list environment as well.

I suppose not much point changing then.

@lervag
Copy link
Owner

lervag commented Dec 7, 2023

This is partly intentional; the list is a list of regexes and the user has flexibility to make it more or less strict.

I see. Maybe mention in the documentation (and also documentation of related settings such as g:vimtex_indent_ignored_envs)?

Yes, good point. I'll fix that as well.

\begin{quote}
	% correctly used:
	\begin{quote}
		stuff
	\end{quote}
	\begin{itemize}
		\item stuff
			stuff
		\item stuff
			stuff
	\end{itemize}
	% "incorrectly used":
	\begin{quote}
	\item stuff
		stuff
	\item stuff
		stuff
	\end{quote}
	\begin{itemize}
		stuff
\end{itemize}
\end{quote}

Yes, this output is as expected (by me). The last itemize becomes incorrectly indented because there is no \item. I think it's safe to assume that the user always wants to add an \item in an itemize.

I originally thought of: if \item is detected in the environment body then automatically indent it as if it's a list environment, otherwise automatically indent it as if it isn't.

Ok, I see. If I did find a good way to implement this feature I think I would like to do it, and instead have an option to toggle it on/off. I believe users who want to indent \item wants that everywhere. But: I don't know exactly how to implement this in a good way.

I could try to do a lookahead and count \items in the current environment. But I don't really like that very much, because I want to make the code as stateless as possible.

lervag added a commit that referenced this issue Dec 7, 2023
@user202729
Copy link
Author

Yes it's difficult to implement, plus a bunch of nesting issue. (current environment is not itemize but there's a nested environment inside that is itemize / \item inside verbatim / etc.) I don't think it's worth it either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants