make comment-dwim in source code blocks more DWIM-ish
commit2d444c1647e3bb3923fbc2a3c197bc67b221df41
authorAaron Ecay <aaronecay@gmail.com>
Mon, 28 Oct 2013 21:40:37 +0000 (28 17:40 -0400)
committerBastien Guerry <bzg@altern.org>
Mon, 4 Nov 2013 11:28:35 +0000 (4 12:28 +0100)
treeb4fee28e15a7b285a29fbc973be3b5c36c98d80e
parent2ac57db0a3bece3f00d9a3ad698b6cf94c134c76
make comment-dwim in source code blocks more DWIM-ish

* lisp/org.el (org-insert-comment, org-comment-or-uncomment-region):
use the relevant language’s major mode comment function if called from
within a source block.

This patch makes it easier to (un)comment lines of babel source.  Now
M-; in a soucre code block should Just Work.

The modification to ‘org-insert-comment’ also fixes a bug, whereby the
function would eat blank lines after it.  The first block, where ! is
the point, would lead to the second instead of the third:

 #+name: orig
 #+begin_src org
 xxxxxxx
 !

 yyyyyy
 #+end_src

 #+name: bad
 #+begin_src org
 xxxxxxx
 #
 yyyyyy
 #+end_src

 #+name: desired
 #+begin_src org
 xxxxxxx
 #

 yyyyyy
 #+end_src

Also, the ‘org-comment-or-uncomment-region’ change results in an
undesirably move of the point after the comment is created.  This is
because ‘comment-region’ wraps the call to ‘comment-region-function’
in a ‘save-excursion’.  The org mode code deletes and reinserts the
whole babel block, which confuses save-excursion.  Org carefully puts
the point back in the proper place, but comment-region’s
save-excursion then substitutes its own erroneous placement.
lisp/org.el