开发者

Emacs mmm-mode not highlighting a ruby submode (ERB) without a newline? Elisp advice?

开发者 https://www.devze.com 2023-04-07 01:32 出处:网络
I\'m trying to get ERB templates \'working\' in Emacs 22 and 23 (two different servers开发者_运维百科).

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))

Emacs mmm-mode not highlighting a ruby submode (ERB) without a newline? Elisp advice?

Emacs mmm-mode not highlighting a ruby submode (ERB) without a newline? Elisp advice?


I have a similar setup, which might even have been the basis for what you're trying. Executing font-lock-fontify-buffer even 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-mode setup 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 updating mmm-mode for 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 nxhtml because it's very heavy-weight, and I believe it also has display quirks.

I'll also point out that haml-mode does 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.


Firstly, if you have SSH access to the box, use tramp.

I have no deep MMM-mode magic for ERB. However, I use Rinari with nxhtml and it all just works. Ask questions about rinari and nxhtml if you need help getting that going.


It's fixed now. Update to the latest mmm-mode from git repo or MELPA.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号