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