I set org-mode Babel to open rhtml block with web-mode.

(add-to-list 'org-src-lang-modes '("rhtml" . web))

And I have configure company-robe for completing for Rails code in erb engine.

(defadvice company-robe (before web-mode-set-up-ac-sources activate)
    "Set `robe-mode' based on current language before running `company-robe'."
    (if (equal major-mode 'web-mode)
        (let ((web-mode-cur-language (web-mode-language-at-pos)))
          (if (string= web-mode-cur-language "erb")
              (unless robe-mode (robe-mode))
            (if robe-mode (robe-mode -1))

The upper advice work correctly in normal file index.html.erb file.

But web-mode can't recognize engine correctly in Org-mode babel block. When I run (web-mode-language-at-pos), it shows html.

The author of web-mode suggest me to use web-mode-set-engine.

(web-mode-set-engine "erb")

Here the original question I asked in web-mode issues: https://github.com/fxbois/web-mode/issues/678

My problem is the org edited src buffer's major-mode is web-mode, but I want to set web-mode-engine to erb. The only identity in src block is this:

#+BEGIN_SRC rhtml


I checked out Org-mode source code, found some functions relative with this.

  • org-src-construct-edit-buffer-name (org-buffer-name lang)
  • org-babel-expand-src-block
    • org-babel-get-src-block-info (it should return a list: (language body header-arguments-alist switches name indent block-head) )

I tried to run (nth 0 (org-babel-get-src-block-info)) in opened src buffer which is opened by [C-c ']. But only get nil.

  • 1
    org-babel-get-src-block-info will return information when run in the org buffer with point within the src block. The command org-babel-view-src-block-info also is useful.
    – dfeich
    Commented Feb 18, 2016 at 7:10

1 Answer 1


I found the solution, add an advice to get lang before [C-c '] keybinding.

;; let Org-mode Babel src code block auto set `web-mode-engine' for rhtml.
  (defadvice org-edit-special (before org-edit-src-code activate)
    (let ((lang (nth 0 (org-babel-get-src-block-info))))
      (if (string= lang "rhtml")
          (web-mode-set-engine "erb"))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.