I’m trying to get ERB templates ‘working’ in Emacs 22 and 23 (two different servers).
I’ve found several examples online that use almost exactly this snippet. Note that I don’t want any background colors, as I’m working in a terminal over SSH.
This is correctly detecting where the first region begins, as the mode line changes when the point moves. But something is not right, since it doesn’t highlight my ruby code unless I clear it with at least two blank lines, and it also seems to consider everything below the first segment of ruby code to be ruby code, even after the closing tags.
I can only assume that the patterns are not correct, and I’d like to understand the syntax so I can debug it better myself. Can anyone tell me what all the @ symbols mean here?
Moreover, has anybody actually gotten ERB templates working in mmm-mode?
(require 'mmm-mode)
(require 'mmm-auto)
(setq mmm-global-mode 'maybe)
(setq mmm-submode-decoration-level 0)
(mmm-add-group
'fancy-html
'((html-erb
:submode ruby-mode
:match-face (("<%#" . mmm-comment-submode-face)
("<%=" . mmm-output-submode-face)
("<%" . mmm-code-submode-face))
:front "<%[#=]?"
:back "%>"
:insert ((?% erb-code nil @ "<%" @ " " _ " " @ "%>" @)
(?# erb-comment nil @ "<%#" @ " " _ " " @ "%>" @)
(?= erb-expression nil @ "<%=" @ " " _ " " @ "%>" @)))))
(add-to-list 'mmm-mode-ext-classes-alist '(html-mode nil fancy-html))


I have a similar setup, which might even have been the basis for what you’re trying. Executing
font-lock-fontify-buffereven with the newlines missing causes the correct highlighting to be displayed, so the problem presumably lies in mmm-mode.The main benefit of the
mmm-modesetup has been that I can easily see the ERB regions; the setup has never syntax-highlighted embedded code perfectly for me, and although I’ve been updatingmmm-modefor compatibility with recent emacsen, it might be worth you exploring alternatives if you really want that detailed sub-region highlighting.Like you, I’ve been unwilling to resort to
nxhtmlbecause it’s very heavy-weight, and I believe it also has display quirks.I’ll also point out that
haml-modedoes quite a nice job of syntax-highlighting embedded code blocks natively (just ruby code originally, until I contributed javascript and css support), and that’s one of several reasons why I prefer haml to html+erb these days.