From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Branham Subject: Re: [PATCH] make org-comment-dwim comment headings if on a heading Date: Sun, 26 Nov 2017 21:07:32 -0600 Message-ID: <87po84to5n.fsf@gmail.com> References: <87zi7godo1.fsf@gmail.com> <878texlx7g.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJ9ll-0007Py-Bl for emacs-orgmode@gnu.org; Sun, 26 Nov 2017 22:07:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eJ9lg-00052a-Ps for emacs-orgmode@gnu.org; Sun, 26 Nov 2017 22:07:41 -0500 Received: from mail-ot0-x22e.google.com ([2607:f8b0:4003:c0f::22e]:39324) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eJ9lg-00052T-J7 for emacs-orgmode@gnu.org; Sun, 26 Nov 2017 22:07:36 -0500 Received: by mail-ot0-x22e.google.com with SMTP id v15so23028683ote.6 for ; Sun, 26 Nov 2017 19:07:36 -0800 (PST) In-reply-to: <878texlx7g.fsf@nicolasgoaziou.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Nicolas Goaziou Cc: Org-mode --=-=-= Content-Type: text/plain 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 wrote: > Hello, > > Alex Branham 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, --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Make-org-comment-dwim-check-if-on-a-heading.patch >From 477d7172f1c93a7162e29999daef3578d26731c8 Mon Sep 17 00:00:00 2001 From: Alex Branham 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 --=-=-=--