Support for vim and emacs file variables


#1

Both vim and emacs support file variables, mainly used to specify file’s syntax:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html#Specifying-File-Variables

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?

Thanks.


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

@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.


#3

it is grammar-mode


#4

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


#5

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.


#6

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.


#7

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.


#8

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.


#9

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


#12

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.

https://developer.gnome.org/anjuta-manual/stable/language-support-cpp-modelines-emacs.html.en
http://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html#Specifying-File-Variables

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.


#13

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


#14

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


#15

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.