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

Conditional auto-indent not working as expected #2754

Closed
rhelder opened this issue Jul 8, 2023 · 7 comments
Closed

Conditional auto-indent not working as expected #2754

rhelder opened this issue Jul 8, 2023 · 7 comments
Labels

Comments

@rhelder
Copy link

rhelder commented Jul 8, 2023

Description

Hello,

Conditional auto-indent isn't working as expected for me anymore.

Thanks for your help!

Steps to reproduce

  1. Here is my minimal example:

    \documentclass{minimal}
    
    \newif\ifmytest
    
    \begin{document}
    
    \ifmytest
    True
    \else
    False
    \fi
    
    \end{document}
  2. Here is my minimal vimrc:

    call plug#begin('~/.config/nvim/vim-plug')
         Plug 'lervag/vimtex'
    call plug#end()

(Since I'm using vim-plug, syntax enable and filetype plugin indent on are automatically executed).

Expected behavior

I would expect 'True' and 'False' to be automatically indented as I am typing. Or, if for some reason they are not already automatically indented correctly, I would expect them to be correctly indented if I navigate to the line and type ==.

Actual behavior

As it is, the text does not automatically indent, either while I'm typing or if I use the = command.

I can confirm that g:vimtex_indent_enabled is set to 1, and that g:vimtex_indent_conditionals is set to the default. I use Neovim, so autoindent is set to 'on' by default, but turning off autoindent makes no difference.

Do you use a latexmkrc file?

Yes

VimtexInfo

System info:
  OS: macOS 13.4.1 (22F82)
  Vim version: NVIM v0.9.1
  Has clientserver: true
  Servername: /var/folders/rb/582tp6vs2z56ry48r0qg06d40000gn/T/nvim.rhelder/hM8Y0e/nvim.50359.0

VimTeX project: minimal
  base: minimal.tex
  root: /Users/rhelder/minimal
  tex: /Users/rhelder/minimal/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
@rhelder rhelder added the bug label Jul 8, 2023
@lervag
Copy link
Owner

lervag commented Jul 8, 2023

I tried to reproduce:

# 1. create test dir
mkdir test
cd test

# 2. create files (contents below)
ls -1
# test.tex
# test.vim 

# 3. start neovim
nvim --clean -u test.vim test.tex

# 4. Do "gg=G" to reindent the file - everything works as expected for me

The contents of the test files: test.tex is the file you provided, whereas test.vim contains this:

set nocompatible
set runtimepath^=~/.local/plugged/vimtex
set runtimepath+=~/.local/plugged/vimtex/after
filetype plugin indent on
syntax enable

Clearly, you would have to change the runtimepaths to the correct path on your system. But when you do, I expect the above steps to work also on your side.

I believe you are not doing a proper minimal test, e.g. perhaps you forget the --clean option with your minimal config. If so, this would mean that files in your config directory, e.g. under ~/.config/nvim/plugin/* or ~/.config/nvim/ftplugin/* would be sourced.

@rhelder
Copy link
Author

rhelder commented Jul 8, 2023

Thanks for your quick response!

Sorry for overlooking the --clean option and changing my runtimepaths; I'm a first-timer here and was trying to follow the directions, but I didn't know about that step. Thanks for your patience!

I modified my minimal.vim to match yours (and of course used the --clean option), and indeed gg=G works. But if I retype the conditional, there is still no indentation while I am typing, and if I navigate to the lines that should be indented (either the line containing 'True' or the line containing 'False') == does not indent the line as expected.

I did some additional testing:

  1. I reloaded my full configuration and saw that gg=G works there as well - sorry that I overlooked that in my initial testing.
  2. In the minimal config, you can get == to indent the lines containing 'True' or 'False' only if you use == on the line containing \ifmytest first. (Presumably this is why gg=G does work as expected - because = is executed on the line containing \ifmytest before it is executed on the subsequent lines).

So, in sum, gg=G works as expected - but even in a proper minimal test (sorry about that) indentation while typing does not work as expected, nor does ==.

Thanks again!

@rhelder
Copy link
Author

rhelder commented Jul 8, 2023

Sorry, should have added that indenting with == as I describe in 2 works not only in the minimal config but also in my full config.

@lervag
Copy link
Owner

lervag commented Jul 12, 2023

Thanks, I see. I think I understand the problem now. So, given your example, == will not indent the True or False lines as expected - unless we first indent the conditional opening line \ifmytest.

The reason is because the implementation is built using state. This is done to prevent a possibly long "backward search" on every call to the indent function. It actually helps a lot to reduce delay, but it does have this specific side effect.

lervag added a commit that referenced this issue Jul 12, 2023
@lervag
Copy link
Owner

lervag commented Jul 12, 2023

Ok, I believe I've fixed this now by avoiding the use of the state. I realize the only "state" we need is the assumption that the previous line is correctly indented.

@lervag lervag closed this as completed Jul 12, 2023
@rhelder
Copy link
Author

rhelder commented Jul 13, 2023

Amazing, thanks so much!

@lervag
Copy link
Owner

lervag commented Jul 13, 2023

My pleasure; thanks for opening the issue. The previous implementation was clearly not so well thought out :)

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