emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Alex Branham <alex.branham@gmail.com>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: Org-mode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] make org-comment-dwim comment headings if on a heading
Date: Sun, 26 Nov 2017 21:07:32 -0600	[thread overview]
Message-ID: <87po84to5n.fsf@gmail.com> (raw)
In-Reply-To: <878texlx7g.fsf@nicolasgoaziou.fr>

[-- Attachment #1: Type: text/plain, Size: 940 bytes --]

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 <mail@nicolasgoaziou.fr> wrote:

> Hello,
>
> Alex Branham <alex.branham@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,


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-org-comment-dwim-check-if-on-a-heading.patch --]
[-- Type: text/x-diff, Size: 1970 bytes --]

From 477d7172f1c93a7162e29999daef3578d26731c8 Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@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	other threads:[~2017-11-27  3:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-20 21:14 [PATCH] make org-comment-dwim comment headings if on a heading Alex Branham
2017-11-22 23:17 ` Nicolas Goaziou
2017-11-27  3:07   ` Alex Branham [this message]
2017-11-29 13:46     ` Nicolas Goaziou
2017-11-29 15:24       ` Alex Branham
2017-11-29 20:17         ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87po84to5n.fsf@gmail.com \
    --to=alex.branham@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@nicolasgoaziou.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).