Earlier today I was looking for a Saltstack mode for emacs. Couldn't find one, so I posted the question on Stack overflow. Somebody had a good suggestion about using yaml-mode because a Sublime Text implementation appeared to be taking this approach.Another person thought that Saltstack's use of jinja templates would make an emacs mode easy enough to configure. These were both helpful ideas so I wanted to implement parts of each.
After looking around, I found that someone had configured an emacs mode for a similar situation. They needed to combine HTML and Python to use Mako templates for a project not involving Saltstack. Since Edx uses Mako templates instead of jinja in their Django site, Mako seemed like a good alternative to Jinja templates.
Since someone previously combined HTML and Python modes it seemed reasonable to combine Mako and Yaml modes in Emacs.
Multiple Major (MMM) Mode allows Emacs major modes to be combined. MMM-Mako Mode provides support for Mako files using MMM. Configuring the setup can be a pain so I wanted to document it:
-
Download & untar MMM mode from http://sourceforge.net/projects/mmm-mode/files
mv ~/Downloads/mmm-mode-0.5.1.tar.gz ~/InstalledPrograms/ tar -xvf mmm-mode-0.5.1.tar.gz && cd mmm-mode-0.5.1/ whereis emacs
-
Make & install MMM mode but first specify where your Emacs is installed. I'm using Emacs 24 installed in
/usr/bin/emacs
.EMACS="/usr/bin/emacs" ./configure make sudo make install
My elisp files were installed to /usr/local/share/emacs/site-lisp. You may need to add this directory to the Emacs load path. You will also need to tell Emacs to load the module. Here's what I added to my .emacs configuration.
````elisp
(add-to-list
;; Adding mmm-mode
'load-path "/usr/local/share/emacs/site-lisp")
(require 'mmm-auto)
(setq mmm-global-mode 'maybe)
````
Make sure it's installed correctly by opening emacs M-x mmm-mode
to enable MMM-mode.
-
Next up, installing MMM-Mako. If I can install something with the package manager then I'll do it. Let's first make sure the package will be available by adding melpa to our .emacs
$ emacs -nw ~/.emacs
Placed the following in my .emacs file
```elisp
(require 'package) ;; You might already have this line
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)
```
Back to emacs M-x package-install
, Install package: mmm-mako
. Once mmm-mako is installed then just finish configuring your .emacs
```elisp
(add-to-list
;; Saltstack config
'auto-mode-alist '("\\.sls\\'" . yaml-mode))
(mmm-add-mode-ext-class 'html-mode "\\.sls\\'" 'mako)
```
My full .emacs file can be viewed here. Also, I want to say thank you to Zach for putting together the post about Mako/HTML.
This approach is a work in progress and I'll update as I find bugs/improvements.
For anyone reading, there is now a dedicated Salt major mode under active development 💥