1

I'm playing with mmm-mode to combine markdown-mode and ESS for editing Rmarkdown files. I'm using gnu emacs 24.3 on Windows 7 and up-to-date version of the aforementioned modes. This is what I've got in my .emacs file:

(require 'mmm-mode)   ;;; possibly init with (require 'mmm-auto) instead
(mmm-add-classes
 '((rmarkdown
    :submode r-mode
    :face mmm-declaration-submode-face
    :front "^```[{]r.*[}] *$"   
    :back "^``` *$")))
(setq mmm-global-mode 'maybe)
(mmm-add-mode-ext-class 'markdown-mode "\\.rmd\\'" 'rmarkdown)

That works so far as within a buffer showing an rmarkdown file, R code blocks are recognized and I get proper syntactically aware font-locking within both R code blocks and markdown blocks. More, when I have the point in an R code block I get ESS and Imenu-R menus and when it's in a markdown region I get a markdown menu. So far so good.

Here are my issues. Within R code blocks electric left assignment doesn't work. I can't simply hit the underscore key to get '<-' and to toggle between that and '_'.

Also, I don't get syntactically aware auto indentation for R code.

Both of these things work when I'm using ESS to edit files containing pure R code.

Any thoughts on how to tune this up? I'm aware of this previous post from nearly a year ago: How can I use Emacs ESS mode with R markdown? and the pointer to polymode, but polymode seems to be advancing slowly. I've also seen other pointers to org-mode for similar functionality and while that's a plunge I may take at some point, today my questions are about getting the most out of the combination of mmm-mode, markdown-mode and ESS. Thanks for your help.

Community
  • 1
  • 1
Dave Braze
  • 441
  • 3
  • 14

1 Answers1

4

Polymode is the way to go. Unfortunately still in development, but works for most of the things.

VitoshKa
  • 8,387
  • 3
  • 35
  • 59
  • Why? mmm-mode works. And indirect buffers have been repeatedly condemned on emacs-devel by the Emacs maintainer. – Dmitry Mar 12 '14 at 07:29
  • Although, if you've really managed to make Dave Love's approach work in current Emacs, and support the essential features (font-lock and indentation, at least), I'd love to see that. – Dmitry Mar 12 '14 at 07:32
  • @Dmitry font-lock and indentation work reasonably well. Given that all the code is generic and there are no mode-specific tweaking I think indirect buffers are the way to go for now. – VitoshKa Mar 12 '14 at 17:28
  • How did you manage to make indentation work without mode-specific tweaks? Do you support anything like ERB/JSP/PHP? – Dmitry Mar 12 '14 at 21:05
  • @Dmitry, by wrapping indent-line-function and indent-region-function. I don't use ERB/JSP/PHP but I would be happy to add if you have real life examples. – VitoshKa Mar 14 '14 at 02:17
  • @Dmitry, polymode is designed to be extensible. It is not my task to add the modes, I just have to document the api. New modes are usually 2 lines of elisp to add. – VitoshKa Mar 14 '14 at 02:18
  • I'll check it out when I have the time, but see this issue for ERB examples: https://github.com/fxbois/web-mode/issues/67 – Dmitry Mar 16 '14 at 05:39
  • Okay. Thank you. I've accepted this answer. I do find polymode frustrating, but less so than what I was doing before. – Dave Braze Jul 07 '14 at 12:25