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

Closing environments with ]] - indentation broken #2229

Closed
stefanvdlugt opened this issue Nov 1, 2021 · 4 comments
Closed

Closing environments with ]] - indentation broken #2229

stefanvdlugt opened this issue Nov 1, 2021 · 4 comments
Labels

Comments

@stefanvdlugt
Copy link

stefanvdlugt commented Nov 1, 2021

Description

When closing off an opened environment by typing ]] the indentation breaks.
A bisect shows this is likely caused by commit f9d07de.

Steps to reproduce

minimal.vim:

set nocompatible
let &runtimepath  = '~/.vim/bundle/vimtex,' . &runtimepath
let &runtimepath .= ',~/.vim/bundle/vimtex/after'
filetype plugin indent on
syntax enable
set shiftwidth=2

minimal.tex:

\documentclass{minimal}
\begin{document}
\begin{definition}
  My definition

\end{document}
  1. vi -u minimal.vim minimal.tex
  2. move cursor to "My definition", press o]].

Expected behavior

\documentclass{minimal}
\begin{document}
\begin{definition}
  My definition
\end{definition}

\end{document}

Actual behavior

\documentclass{minimal}
\begin{document}
\begin{definition}
  My definition
  \end{definition}

\end{document}

Do you use a latexmkrc file?

No

VimtexInfo

System info
  OS: Linux 5.14.15-arch1-1
  Vim version: VIM 8.2 (1-3441)
  Has clientserver: false

VimTeX project: minimal
  base: minimal.tex
  root: /tmp/vimtex
  tex: /tmp/vimtex/minimal.tex
  main parser: current file verified
  document class: minimal
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: General
  qf method: LaTeX logfile
@stefanvdlugt
Copy link
Author

stefanvdlugt commented Nov 1, 2021

After running :setlocal indentkeys=!^F,o,O,(,),],},\&,=\\item,=\\else,=\\fi indentation works as expected.

lervag added a commit that referenced this issue Nov 1, 2021
@lervag
Copy link
Owner

lervag commented Nov 1, 2021

Thanks, I agree this is a regression. However, I think the reasoning behind the faulty commit is still good, so I'm pushing an alternative fix to this that I believe should fix the issue and keep the recently updated indent behaviour.

See also #2227 for more info on the related change to the indentkeys option.

@lervag lervag closed this as completed Nov 1, 2021
lervag added a commit that referenced this issue Nov 1, 2021
@user202729
Copy link

user202729 commented Nov 2, 2021

Regarding this issue, for some reason I tend to type out the \end{...} explicitly (it's not slower for me anyway, although it's also okay to change that as I learn about ]], but I don't have VimTeX everywhere). (actually it's not possible, \end{document} somehow can't be typed this way)

Although I don't see any easy way to fix this issue -- perhaps add \end to indentkeys if it's at the start of line, although the current behavior of <c-f> doesn't reindent a \end if it doesn't match the corresponding \begin.


Another (not very related and exists already before this commit) but I only notice this now somehow. I'm not sure if this should be supported too) for some code like this

\documentclass[12pt]{article}

\begin{document}

\begin{enumerate}

\item

\end{enumerate}   % (1)

\end{document}

On the line (1), the indent expression returns -4, and Vim interpret it the same as -1 "keep current indentation", so the ^F is equivalent to no-op.

If the whole documentation is gg=Ged entirely by VimTeX it would indent correctly anyway, so it isn't really a problem.

@lervag
Copy link
Owner

lervag commented Nov 3, 2021

Although I don't see any easy way to fix this issue -- perhaps add \end to indentkeys if it's at the start of line, although the current behavior of <c-f> doesn't reindent a \end if it doesn't match the corresponding \begin.

No, \end by itself does not work. The indentation does not recognize it before it matches the argument, i.e. \end{...}. However, we could possibly relax the 0} element in the indentkeys to simply } so that indents are calculated when you type }.

for some code like this ...
On the line (1), the indent expression returns -4, and Vim interpret it the same as -1 "keep current indentation", so the ^F is equivalent to no-op.

You are right that it could be prudent to avoid returning a negative value. But I can't reproduce the issue from your example.

lervag added a commit that referenced this issue Nov 3, 2021
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

3 participants