I have language specific syntax highlighting and (kind of) indentation working in Org-mode source code blocks.

However, because of the syntax highlighting if I am editing the code block in the Org-mode buffer, I often find myself thinking that I am in an e.g., emacs lisp buffer. When I try to comment out code in one of these blocks though, I get # at the begining of the comment, instead of the delimiter for the language of the source code block. This mean that commenting is often a 4 step process of:

  1. Comment the code with M-; leading to code that has the wrong style comment.
  2. Uncomment that code.
  3. Call org-edit-special with C-c ' to get to a buffer specific to the language.
  4. Comment out the code again (and usually go back to the org-mode buffer).

I would like to do this with only the first step if possible. Is there a way to use language specifc comments in org-src block?

1 Answer 1



;; allow comment region in the code edit buffer (according to language)
(defun my-org-comment-dwim (&optional arg)
  (interactive "P")
  (or (org-babel-do-key-sequence-in-edit-buffer (kbd "M-;"))
      (comment-dwim arg)))

;; make `C-c C-v C-x M-;' more convenient
(define-key org-mode-map
  (kbd "M-;") 'my-org-comment-dwim)

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.