Getting emacs to use ruby-mode in mmm-mode
Finally wanted to get ruby-mode functioning in mmm-mode.
This link was the most helpful (and so are the links on the page): http://blog.invisible.ch/archives/000417.html
Finally, I settled for this:
;;; mmm-mode
(require 'mmm-auto)
(setq mmm-global-mode 'maybe)
(setq mmm-submode-decoration-level 0)
;;; ruby-electric (omg this is going to spoil me)
(require 'ruby-electric)
(defun ruby-indent ()
(local-set-key \"\C-m\" 'ruby-reindent-then-newline-and-indent))
(add-hook 'ruby-mode-hook
'(lambda ()
(ruby-indent)
(ruby-electric-mode)
))
;;; eRuby (ruby/html mmm)
(mmm-add-classes
'((erb-code
:submode ruby-mode
:front \"< %[#=]?\"
:back \"%>”
)))
(add-hook ‘html-mode-hook
(lambda ()
(setq mmm-classes ‘(erb-code))
(mmm-mode-on)))
(add-to-list ‘auto-mode-alist ‘(”\\.rhtml$” . html-mode))
Now, I spent 2 hours trying to figure out how the HECK to get indentation working within the HTML. When I first saw it wasn’t working, I thought it was just me, but someone has noted this before. My last attempt almost ran me out of ideas. Since ruby-mode looks for indentational keywords, I would add “< %" to the list, as it is always precedes in embedded ruby anyway. Unfortunately, that doesn't work, but I think the reason why is because mmm-mode suppresses the initial start string from the encapsulated mode, so ruby-mode never sees it.
Instead, I went straight to the functions that used ruby-indent-beg-re. ruby-beginning-of-indent finds where ruby-mode should start indenting, so I decided to include the "(" in ruby-indent-beg-re. Of course, with all the other stuff that ruby-beginning-of-indent puts in, this fix might not work at all, so I modified the function to use this instead:
- concat "^\\(" ruby-indent-beg-re "\\)\\b"
+ concat "^\\(" ruby-indent-beg-re "\\)\\b\\|\("
Before, then I thought I had it working, I needed a starting paren to get ruby to see where I wanted it to start indenting, so it wouldn't hurt if I added a open paren to when I wanted multi-line indented embedded ruby.
And that, with making the byte-compiled file using byte-compile-file in emacs, fixed it. It's too early to say whether or not I've broken something, but I don't think I have.
