Skip to content

Add vim/emacs modeline support #49267

Merged
ConradIrwin merged 21 commits intozed-industries:mainfrom
elmarco:modeline
Mar 25, 2026
Merged

Add vim/emacs modeline support #49267
ConradIrwin merged 21 commits intozed-industries:mainfrom
elmarco:modeline

Conversation

@elmarco
Copy link
Copy Markdown
Contributor

@elmarco elmarco commented Feb 16, 2026

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.

Supersedes #41899, changes:

  • limit reading to the first and last 1kb
  • add documentation
  • more variables handled
  • add Arc around ModelineSettings to avoid extra cloning
  • changed the way mode -> language mapping is done, thanks to modeline_aliases language config
  • drop vim ex: support
  • made "Local Variables:" handling a separate commit, so we can drop it easily
  • various code style improvements

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 16, 2026
@ConradIrwin ConradIrwin self-assigned this Feb 20, 2026
@elmarco
Copy link
Copy Markdown
Contributor Author

elmarco commented Mar 10, 2026

@ConradIrwin do you want me to rebase again? anything I can do to help? thanks

@ConradIrwin
Copy link
Copy Markdown
Member

I'm sorry, I thought I had merged this already! Asking Claude to re-try the merge, if it struggles I'd love for you to take a pass.

elmarco and others added 18 commits March 19, 2026 15:00
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit refactors how language settings are accessed across various
crates. Instead of passing individual parameters like `language` and
`file` explicitly, it now utilizes a more fluent builder pattern that
can optionally take a `Buffer` or `BufferSnapshot` to infer these
details.

In a later patch, modeline settings support can be added seamlessly
thanks to this refactoring.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This will allow to configure vim/emacs modeline support.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Add an optional ModelineSettings to Buffer and BufferSnapshot.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
When the buffer is added on reloaded, parse the modelines and update the
detected language.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Associated buffer's modeline is now merged.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Now we need to take modeline into account they are not viable.
Buffers have their own language, so it's almost always an error to
specify the buffer and the language (unless you're in a situation
where you already did .language_at() or equivalent).
The builder methods were not composible (i.e. you had to be careful to
call .language() after .buffer()), so it seems safer to not do that.
@elmarco
Copy link
Copy Markdown
Contributor Author

elmarco commented Mar 20, 2026

@ConradIrwin rebased, thanks

@ConradIrwin ConradIrwin enabled auto-merge (squash) March 24, 2026 02:46
@github-actions
Copy link
Copy Markdown

📏 PR Size: 2126 lines changed (Size XL)

Please note: this PR exceeds the 400 LOC soft limit.

  • Consider splitting into separate PRs if the changes are separable
  • Ensure the PR description includes a guided tour in the "How to Review" section so reviewers know where to start

@ConradIrwin ConradIrwin merged commit 58fec75 into zed-industries:main Mar 25, 2026
31 checks passed

## Notes

- The first kilobyte of a file is searched for modelines.
Copy link
Copy Markdown

@booch booch Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still true? If so how does it interact with the modeline_lines line count? @elmarco

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it applies the 1kb limit, then the line count.

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 large-pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support modeline comments for per-file settings

3 participants