Support for vim and emacs file variables


Both vim and emacs support file variables, mainly used to specify file’s syntax:

For example, I have file ferm.conf, which should be opened with shell script syntax:

# -*- shell-script -*-

table filter {
    chain INPUT {

The first line (comment) is understood by both vim and emacs, but unfortunately not Atom. Is there any package or built-in feature to achieve the same in Atom?


Supports modeline
Add built-in support for "modelines"
Add built-in support for "modelines"

@mark_hahn made a package for this, if I recall correctly. I don’t remember the name of it off the top of my head though.


it is grammar-mode


Thanks. This plugin works fine, unfortunately it requires its own markers. Is there a way to make it understand existing marker?


Is there a standard format for the markers? I seem to remember having a reason to design my own format, although I don’t know what that was.

Also, what would be the standard for the grammar names?

Maybe a config setting to allow any format and some name mappings would work.

I’ve never used this kind of thing before I wrote that. I just had a need for shell files that had no suffix. Let me know what you want.


I would like Atom to follow GitHub in how it deals with a very specific version of the original ask. On GitHub if you specify a value for mode it will use that to represent the type of file. This applies proper color coding and “stats” about the project.

# -*- mode: yaml -*-

This is very handy if you wanted to name a file .conf instead of .yaml. It would be great if Atom could apply the results of running Ctrl + Shift + l to a file if this particular comment was in place.


I don’t think I can use file suffixes. Atom has a set of specific grammar names I have to use. I wonder if they match the github names. In any case can anyone tell me how to map a suffix to the grammar name?

Is this the exact format used by everyone?

P.S. My code is very simple. A PR to my repo would be appreciated.


You can use the atom.grammars.selectGrammar function:

If you give it the extension with a leading period and an empty string for the file contents, it should give you what you want.


Let me know if the other one works for you or not.


Both Vim and Emacs have a feature most commonly referred to as modelines. The basic idea is that it provides you the ability to store information about how to parse a file within a comment. A very common use case is when you are using a custom file extension for a certain file type, like .conf for YAML. Let’s say you are always going to parse that file as YAML, then the extension or file meta is no matter. The only thing that is important is to maintain the proper syntax highlighting and whitespace requirements.

Emacs modelines are loosely defined, but pretty common in use. GitHub supports the use of -*- mode: yaml -*- to apply yaml syntax highlighting. Some open source projects use modelines in more advanced ways, but things start to vary at that point. The mode property is the most common one to find in use. There are some active examples of setting tabs and other whitespace properties as well.

Vim requires the use of vim in the comment, so that could rule it out. There are likely plugins to use the Emacs variations as well. On the other hand vim modelines have a pretty well established format and commonly used shorthand.

I think there is a lot of room to build upon the Emacs variation. I also think there is a lot to learn from the vim method. Supporting both would certainly have advantages in enabling people to use Atom in diverse teams.


I moved this back to the other topic because we already have a topic for this.


Has anyone tried this other plugin? If it works the I don’t need to take the trouble.


Sorry, I should have missed it somehow, but I cannot find anything but your grammar-mode in this thread. Could you please point me to this other plugin? Thanks.