fgallina/multi-web-mode

Mixing ruby-mode with html-mode for .erb doesn't seem to be working

Closed this issue · 2 comments

Hi,

Thanks for making this! I've been playing around with other multi-mode alternatives and this one seems the most appealing :) I'm having an issue that's probably down to my own mistake, however. I'm triggering the mode using a hook like this:

(defun multi-web-mode-html-erb ()
    (setq mweb-default-major-mode 'html-mode)
    (setq mweb-tags '((ruby-mode "<%==|<%=|<%#|<%" "%>")))
    (setq mweb-filename-extensions '("html.erb"))
    (multi-web-mode))

(defun multi-web-mode-text-erb ()
    (setq mweb-default-major-mode 'text-mode)
    (setq mweb-tags '((ruby-mode "<%==|<%=|<%#|<%" "%>")))
    (setq mweb-filename-extensions '("text.erb"))
    (multi-web-mode))

(add-to-list 'auto-mode-alist '("\.html\.erb$" . multi-web-mode-html-erb))
(add-to-list 'auto-mode-alist '("\.text\.erb$" . multi-web-mode-text-erb))

I'm doing it this way so that I can get better customization per file extension than with a global mode. It is being triggered correctly, but when I open a .html.erb file it just renders as HTML everywhere, with the blocks of Ruby not being highlighted at all (unless I throw some bogus HTML inside the <% ... %> blocks, which causes the HTML to be highlighted, like multi-web-mode isn't recognising the ERB tags.

.text.erb files just get rendered with no highlighting, due to them being interpreted as all-text, with no ERB.

Is there's a problem with the patterns I'm setting for the <% erb %> tags? They're a lot like tags really :)

Chris

Hi Chris,

Thanks for your kind words about the mode.

With regards to your issue I have to point that your regexp for tags is wrong (you got them almost right), try with this setup instead:

(defun multi-web-mode-html-erb ()
    (setq mweb-default-major-mode 'html-mode)
    (setq mweb-tags '((ruby-mode "<%==\\|<%=\\|<%#\\|<%" "%>")))
    (setq mweb-filename-extensions '("html.erb"))
    (multi-web-mode))

Note that I escaped the pipes, that's because of how Emacs Regexp are built.

Aha! Thank you, that was exactly it. I completely missed the need to escape the pipe character :)