* [PATCH] make org-comment-dwim comment headings if on a heading
@ 2017-11-20 21:14 Alex Branham
2017-11-22 23:17 ` Nicolas Goaziou
0 siblings, 1 reply; 6+ messages in thread
From: Alex Branham @ 2017-11-20 21:14 UTC (permalink / raw)
To: Org-mode
[-- Attachment #1: Type: text/plain, Size: 1422 bytes --]
This patch changes the behavior of `org-comment-dwim' so that if point is on a heading, it will toggle the heading.
Alex
From 655cd7afdfdf28797052952eae0c4e87cd86f445 Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Mon, 20 Nov 2017 15:12:34 -0600
Subject: [PATCH] Make org-comment-dwim comment headings if point is at heading
* listp/org.el (org-comment-dwim): If point is on heading, call
org-toggle-comment.
---
lisp/org.el | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index f873f1021..25fa3a533 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -22817,11 +22817,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."
+ "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")
- (if (org-in-src-block-p)
- (org-babel-do-in-edit-buffer (call-interactively 'comment-dwim))
- (call-interactively 'comment-dwim)))
+ (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
--
2.15.0
[-- 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: 1264 bytes --]
From 43fd460accf071e1c69df5fcbbcce0e4943563f2 Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Mon, 20 Nov 2017 15:08:09 -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
---
lisp/org.el | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index f873f1021..81bc9278f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -22817,11 +22817,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."
+ "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")
- (if (org-in-src-block-p)
- (org-babel-do-in-edit-buffer (call-interactively 'comment-dwim))
- (call-interactively 'comment-dwim)))
+ (cond ((org-on-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
--
2.15.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] make org-comment-dwim comment headings if on a heading
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
0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2017-11-22 23:17 UTC (permalink / raw)
To: Alex Branham; +Cc: Org-mode
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,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] make org-comment-dwim comment headings if on a heading
2017-11-22 23:17 ` Nicolas Goaziou
@ 2017-11-27 3:07 ` Alex Branham
2017-11-29 13:46 ` Nicolas Goaziou
0 siblings, 1 reply; 6+ messages in thread
From: Alex Branham @ 2017-11-27 3:07 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Org-mode
[-- 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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] make org-comment-dwim comment headings if on a heading
2017-11-27 3:07 ` Alex Branham
@ 2017-11-29 13:46 ` Nicolas Goaziou
2017-11-29 15:24 ` Alex Branham
0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2017-11-29 13:46 UTC (permalink / raw)
To: Alex Branham; +Cc: Org-mode
Hello,
Alex Branham <alex.branham@gmail.com> writes:
> 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...
Mapping means `org-comment-dwim' binding replaces `comment-dwim'
binding, which doesn't mean both functions are mapped to each other.
The tests in "test-org.el" were broken: they tested `comment-dwim'
instead of `org-comment-dwim'. I fixed the tests, then applied your
patch.
I also added TINYCHANGE at the end of the commit message. Please
consider signing FSF papers if you haven't done so. If you did, let me
know it so I can update our registry.
Would you mind writing an entry in ORG-NEWS? It could go in
"Miscellaneous" section.
Thank you!
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] make org-comment-dwim comment headings if on a heading
2017-11-29 13:46 ` Nicolas Goaziou
@ 2017-11-29 15:24 ` Alex Branham
2017-11-29 20:17 ` Nicolas Goaziou
0 siblings, 1 reply; 6+ messages in thread
From: Alex Branham @ 2017-11-29 15:24 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Org-mode
[-- Attachment #1: Type: text/plain, Size: 431 bytes --]
On Wed 29 Nov 2017 at 13:46, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> I also added TINYCHANGE at the end of the commit message. Please
> consider signing FSF papers if you haven't done so. If you did, let me
> know it so I can update our registry.
I've signed the papers.
>
> Would you mind writing an entry in ORG-NEWS? It could go in
> "Miscellaneous" section.
Patch attached, thanks!
>
> Thank you!
>
> Regards,
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ORG-NEWS-Document-new-behavior-of-org-comment-dwim-o.patch --]
[-- Type: text/x-diff, Size: 755 bytes --]
From 1d62a9c612c97dd35929a40c49d86a5812a853e9 Mon Sep 17 00:00:00 2001
From: Alex Branham <branham@utexas.edu>
Date: Wed, 29 Nov 2017 09:21:58 -0600
Subject: [PATCH] ORG-NEWS: Document new behavior of org-comment-dwim on
headings
---
etc/ORG-NEWS | 1 +
1 file changed, 1 insertion(+)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index b41804edb..402fc8e52 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -188,6 +188,7 @@ file links, which lead to them being broken in web browsers. Now both
of these exporters will properly export to =irc:= links, which will
open properly in irc clients from web browsers.
+*** ~org-comment-dwim~ (bound to =M-;=) now comments headings, if point is on a heading
* Version 9.1
** Incompatible changes
--
2.15.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] make org-comment-dwim comment headings if on a heading
2017-11-29 15:24 ` Alex Branham
@ 2017-11-29 20:17 ` Nicolas Goaziou
0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2017-11-29 20:17 UTC (permalink / raw)
To: Alex Branham; +Cc: Org-mode
Alex Branham <alex.branham@gmail.com> writes:
> Patch attached, thanks!
Applied. Thank you.
Regards,
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-11-29 20:17 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2017-11-29 13:46 ` Nicolas Goaziou
2017-11-29 15:24 ` Alex Branham
2017-11-29 20:17 ` Nicolas Goaziou
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).