Skip to content

Conversation

@elmarco
Copy link

@elmarco elmarco commented Nov 4, 2025

Many editors such as vim and emacs support "modelines", a comment at the beginning of the file that allows the file type to be explicitly specified along with per-file specific settings

  • The amount of configurations, style and settings mapping cannot be handled in one go, so this opens up a lot of potential improvements.
  • I left out the possiblity to have "zed" specific modelines for now, but this could be potentially interesting.
  • Mapping the mode or filetype to zed language names isn't obvious either. We may want to make it configurable.

This is my first contribution to zed, be kind. I struggled a bit to find the right place to add those settings. I use a similar approach as done with editorconfig (merge_with_editorconfig). There might be better ways.

Closes #4762

Release Notes:

  • Add basic emacs/vim modeline support.

elmarco and others added 3 commits November 4, 2025 17:30
This will allow to configure vim/emacs modeline support.

Signed-off-by: Marc-André Lureau <[email protected]>
Signed-off-by: Marc-André Lureau <[email protected]>
Co-authored-by: Claude <[email protected]>
Signed-off-by: Marc-André Lureau <[email protected]>
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Nov 4, 2025
elmarco and others added 2 commits November 4, 2025 18:08
vim and emacs support "modelines", a comment at the beginning of the
file that allows the file type to be explicitly specified along with
per-file specific settings.

Release Notes:

- Add basic emacs/vim modeline support.

Signed-off-by: Marc-André Lureau <[email protected]>
Co-authored-by: Claude <[email protected]>
Signed-off-by: Marc-André Lureau <[email protected]>
@ConradIrwin
Copy link
Member

Amazing, thank you for this! I think the overall structure is reasonable, and I like that we're doing this as part of detect language.

Looking through the code I have a few suggestions:

  • Let's hard limit the number of bytes to search for modeline to ~1k, we've had persistent problems with performance of files with extremely long lines (we could maybe do the emacs thing and make it ~3k, but seems a bit excessive). If we do that then I don't think we need the setting for number of lines.
  • We should store the ModelineSettings as an Rc in the Buffer and BufferSnapshot to make it cheaper to create a new snapshot (another area of performance sensitivity for us).
  • We need some docs! Maybe a new page describing what variables can be set that's linked to from the existing settings pages?
  • Let's (probably) not ship the "emacs locals" syntax. I've seen modelines before, but never that, and don't want to maintain a third parser for this stuff.
  • I'd also like to tighten up the syntax for vim. Not sure what's actually used in the wild but in my experience it's always " vim?:. I don't think we need to support ex:`, nor doing this on lines with no comments (and particularly not lines with other non-modeling content before the modeline!).

Thanks again, and let me know if you want help with any of these: https://cal.com/conradirwin/pairing

@ConradIrwin
Copy link
Member

(Also feel free to edit typos.toml to fix the style check)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support modeline comments for per-file settings

2 participants