Bastard Files

With the abundance of free time caused by my “stay-cation,” one of the projects I worked on was cleaning up my bash configs that I have in version control. During this, something that has annoyed me fairly often has been opening a file in emacs with a nonstandard extension, or no indicator telling emacs what mode to use. In this case moving my bash aliases into a file just called “aliases” and functions into (can you guess?!) “functions,” with these files, emacs has no way to really know they should be opened with shell-script-mode.

Obviously my next move was to confer with the Oracle and hoped that it could divine the info I needed, but I just couldn’t seem to find the right question to ask. I tried “how to tell emacs what mode to use” and a few variations, but I had to use “have file tell emacs what mode to use” before I even found any results that seemed close to what I wanted. After sifting through a bit I found a link to the emacs manual that had what I was looking for!

The problem with everyone using google is that a lot of morons use google

Awww google, I know you are just trying to help...but please just shut up

To accomplish what I want there were actually technically a couple of ways, both formats wrapped in whatever the commenting convention for the language. Here is an example of the short and long format in PHP:

// -*- mode: php-mode; -*-

or the long way:

// Local Variables:
// mode: php-mode;
// End:

Just for clarities sake, I will show an example for bash as well:

# -*- mode: shell-script-mode; -*-

and again the long way:

# Local Variables:
# mode: php-mode;
# End:

[Just a note, in the long form way the case doesn’t matter when writing out “local variables” or “end,” just make sure they each end with a “:”]

Pretty easy right? Though just like everything else in emacs, the power of this far beyond exceeds my understanding allowing you to set all kinds of nice variables to make your life easier. Since I have no need for those other uses of yet…well I don’t care to take time to learn it…yet.

If you do though, feel free to shoot me an email or just comment on how much of a noob I am.

Since this was fairly light on emacs-fu I figured I would throw readers a bone and point them to some very non-noob emacs awesomeness. Check out @berenguel 30-day emacs challenge

%d bloggers like this: