Thanks. I've been trying to do that and ran into an issue that you can 
hopefully help me understand.

I've attached the updated patch (with a test), but the test fails because 
calling M-x comment-dwim in an org buffer on a heading results in the old 
behavior of comment-dwim rather than the new behavior. Calling M-x 
org-comment-dwim directly works as I expect (and M-; works like this too). Do 
you have any idea what might be going on? I thought they would behave the same 
since comment-dwim is mapped to org-comment-dwim, but that doesn't seem to be 
the case...

Thanks,
Alex

On Wed 22 Nov 2017 at 23:17, Nicolas Goaziou <m...@nicolasgoaziou.fr> wrote:

> Hello,
>
> Alex Branham <alex.bran...@gmail.com> writes:
>
>> This patch changes the behavior of `org-comment-dwim' so that if point
>> is on a heading, it will toggle the heading.
>
> Thank you. 
>
> Could you add a test to test-org/comment-dwim from "test-org.el"?
>
> Regards,

>From 477d7172f1c93a7162e29999daef3578d26731c8 Mon Sep 17 00:00:00 2001
From: Alex Branham <bran...@utexas.edu>
Date: Sun, 26 Nov 2017 21:02:28 -0600
Subject: [PATCH] Make org-comment-dwim check if on a heading

* lisp/org.el (org-comment-dwim): if on a heading, comment the heading
* testing/lisp/test-org.el: add a test for comment-dwim on org headings
---
 lisp/org.el              | 14 +++++++++-----
 testing/lisp/test-org.el |  6 ++++++
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 2b33a2163..b17c96614 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -23324,12 +23324,16 @@ strictly within a source block, use appropriate comment syntax."
 		(forward-line)))))))))
 
 (defun org-comment-dwim (_arg)
-  "Call `comment-dwim' within a source edit buffer if needed."
-  (interactive "*P")
-  (if (org-in-src-block-p)
-      (org-babel-do-in-edit-buffer (call-interactively 'comment-dwim))
-    (call-interactively 'comment-dwim)))
+  "Call the comment command you mean.
 
+Calls `org-toggle-comment' if on a heading, otherwise call
+`comment-dwim' (within a source edit buffer if needed)."
+  (interactive "*P")
+  (cond ((org-at-heading-p)
+	 (call-interactively #'org-toggle-comment))
+	((org-in-src-block-p)
+	 (org-babel-do-in-edit-buffer (call-interactively #'comment-dwim)))
+	(t (call-interactively #'comment-dwim))))
 
 ;;; Timestamps API
 
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index d067c04ff..a97384a4e 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -153,6 +153,12 @@
 	  (org-test-with-temp-text "#+KEYWORD: value"
 	    (progn (call-interactively 'comment-dwim)
 		   (buffer-string)))))
+  ;; Comment a heading
+  (should
+   (equal "* COMMENT Test"
+	  (org-test-with-temp-text "* Test"
+	    (progn (call-interactively 'comment-dwim)
+		   (buffer-string)))))
   ;; In a source block, use appropriate syntax.
   (should
    (equal "  ;; "
-- 
2.15.0

Reply via email to