helix icon indicating copy to clipboard operation
helix copied to clipboard

add basic modeline support

Open doy opened this issue 2 years ago • 5 comments

fixes #729

currently only supports setting language, indent style, and line endings, but maybe this is enough?

doy avatar Jul 30 '23 09:07 doy

Also one more thing: I think the modeline.rs file can/should be moved to helix-core

pascalkuthe avatar Jul 30 '23 12:07 pascalkuthe

vim modelines are pretty standard even in editors other than vim. Kakoune also parses these by default (https://github.com/mawww/kakoune/blob/master/rc/detection/modeline.kak). I think it would be reasonable to mirror kakoune here. It supports the following options currently:

  • scrolloff
  • sidescrolloff (do we even have a sepreat setting for this?
  • tabstop
  • shiftwidth
  • textwidth
  • fileformat
  • filetype
  • spelllang
  • bom
  • nobom

pascalkuthe avatar Jul 30 '23 18:07 pascalkuthe

yeah, i don't think this belongs in a plugin. i'm not tied to vim syntax specifically (we could also totally just do our own thing) but it feels pretty important to be able to have some way to override settings like file type that heuristics aren't always going to correctly identify (i have quite a few files that aren't identifiable by filename or shebang).

doy avatar Aug 02 '23 02:08 doy

this should resolve the issues mentioned so far (other than the extended list of options that kakoune supports - should i implement those now or can it wait?). let me know if there are any other issues!

doy avatar Aug 02 '23 03:08 doy

i added a second commit which adds support for parsing a helix-specific modeline, since that is probably going to be more useful going forward. i think parsing some amount of vim modelines is useful because they are so widespread, but for configuration that doesn't exist in vim (or is different in vim, such as language names), we are going to want a different method for configuring that.

this currently uses the same toml configuration syntax we use for the configuration file, but not sure if that's what we actually want (given that my understanding is that the toml configuration file is eventually intended to go away in favor of some kind of scripted configuration - telling people to rewrite their local configuration file is different from telling them to fix modelines in every file they want to use). let me know if you think this is fine or if we can come up with something better here.

doy avatar Sep 17 '23 17:09 doy

There is some exoteric examples that I tested if Vim can properly detect the file type. Vim got it right in all but the FSharp example, that is expected because Vim doesn't have by default the file type definition for FSharp. In my tests the only thing that seems to break detection here is that requirement of a : at the end of the directive.

https://github.com/lucasew/nix-flake-shell/tree/c896400199f12a293ec6ee7d54b5f2e19f0f0a99/tests

lucasew avatar Jul 26 '24 15:07 lucasew

vim modelines are pretty standard even in editors other than vim.

I don't know common it is parse vim's modelines. Gedit can parse expandtab, tabstop, shiftwidth, wrap and textwidth: https://help.gnome.org/users/gedit/stable/gedit-plugins-modelines.html.en

The Kate editor supports their own Kate-specific modelines: https://kate-editor.org/2006/02/09/kate-modelines/#:~:text=Kate%20Part's%20modelines%20%E2%80%93%20also%20called,to%20Emacs%20and%20vim%20modelines.

But I imagine a lot of Helix's users will come from vim/neovim, which parse them.

I agree parsing vim's modelines would be a good fit for a plugin. Emacs can parse Vim's modelines using a plugin: https://www.emacswiki.org/emacs/vim-modeline

Regarding the trailing colon. I'm one of the vim users who waw aware that's not required, so I don't put in in my own files. I'm not sure how common that is.

markstos avatar Jul 26 '24 17:07 markstos