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

Make vim respect the tab width settings #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gridbugs
Copy link

@gridbugs gridbugs commented Nov 8, 2024

Somehow the dune filetype in neovim ends up with the "lisp" option set despite this not being explicitly configured. Without this setting indentation of dune files does not happen at all, as it's needed for vim to indent lines based on parentheses. Unfortunately when "lisp" is set, it also causes the softtabstop and shiftwidth settings to be ignored, presumably to allow for indentation conventions in lisp where elements of lists are aligned to the first element of the list, regardless of its indentation. The default behaviour with "lisp" enabled also effectively uses a softtabstop of 2, and this can't be overriden by setting the softtabstop variable.

This makes it frustrating to edit dune files in vim, as the indentation inserted by the editor won't match the 1-space indentation commonly found in dune files. The workaround is to to set lispoptions=expr:1 which allows vim to use a custom indentexpr when "lisp" is set, and to supply a custom indentexpr function which changes the indentation based on unmatched parentheses, which is an approximation of the behaviour of dune format-dune-file.

@gridbugs
Copy link
Author

gridbugs commented Nov 8, 2024

I still don't understand what causes lisp to be set for the dune filetype. It's definitely set (it's in the output of :set) and unsetting in (run :set nolisp) causes indentation for dune files to completely stop. That makes sense because otherwise vim doesn't know to indent dune files based on parens. I figure it's safer to explicitly set lisp as I've done in this
change so if whatever else causes it to be set stops happening, indentation will continue to work.

Somehow the dune filetype in neovim ends up with the "lisp" option set
despite this not being explicitly configured. Without this setting
indentation of dune files does not happen at all, as it's needed for vim
to indent lines based on parentheses. Unfortunately when "lisp" is set,
it also causes the softtabstop and shiftwidth settings to be ignored,
presumably to allow for indentation conventions in lisp where elements
of lists are aligned to the first element of the list, regardless of its
indentation. The default behaviour with "lisp" enabled also effectively
uses a softtabstop of 2, and this can't be overriden by setting the
softtabstop variable.

This makes it frustrating to edit dune files in vim, as the indentation
inserted by the editor won't match the 1-space indentation commonly
found in dune files. The workaround is to to set lispoptions=expr:1
which allows vim to use a custom indentexpr when "lisp" is set, and
to supply a custom indentexpr function which changes the indentation
based on unmatched parentheses, which is an approximation of the
behaviour of `dune format-dune-file`.

Signed-off-by: Stephen Sherratt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant