Sorry for the delay. I am very slow with regexps!

On Sat, Jan 14, 2017 at 6:04 AM, Nicolas Goaziou <[email protected]>
wrote:

> Hello,
>
> Matt Price <[email protected]> writes:
>
> > I see that
> >
> > (org-get-heading t t)
> >
> > executed on a heading like:
> >
> > * COMMENT Heading Title
> >
> > returns:
> >
> > COMMENT Heading Title
> >
> > Should there be a third switch, something like NO-COMMENT?
>
> I have no objection, but it would also need to have NO-PRIORITY for
> completeness. Do you want to provide a patch for that?
>
> Regards,
>
> --
> Nicolas Goaziou
>
From 7c78da444b74a7f75645d2af854859a6a7bf476a Mon Sep 17 00:00:00 2001
From: Matt Price <[email protected]>
Date: Tue, 17 Jan 2017 18:03:12 -0500
Subject: [PATCH 4/4] Add support for new switches to org-get-heading

NO-COMMENT tag, if true, will not return the COMMENT string with
heading.

NO-PRIORITY, if true, will not return the priority string (e.g.,
[#A]).
---
 lisp/org.el | 49 +++++++++++++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index cf1581204..349255bf9 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8015,29 +8015,38 @@ So this will delete or add empty lines."
     (insert empty-lines)
     (move-to-column column)))
 
-(defun org-get-heading (&optional no-tags no-todo)
+(defun org-get-heading (&optional no-tags no-todo no-comment no-priority)
   "Return the heading of the current entry, without the stars.
-When NO-TAGS is non-nil, don't include tags.
-When NO-TODO is non-nil, don't include TODO keywords."
+    When NO-TAGS is non-nil, don't include tags.
+    When NO-TODO is non-nil, don't include TODO keywords.
+    When NO-COMMENTS is non-nil, don't include comment string.
+    When NO-PRIORITY is non-nil, don't include priority string."
   (save-excursion
     (org-back-to-heading t)
-    (let ((case-fold-search nil))
-      (cond
-       ((and no-tags no-todo)
-	(looking-at org-complex-heading-regexp)
-	;; Return value has to be a string, but match group 4 is
-	;; optional.
-	(or (match-string 4) ""))
-       (no-tags
-	(looking-at (concat org-outline-regexp
-			    "\\(.*?\\)"
-			    "\\(?:[ \t]+:[[:alnum:]:_@#%]+:\\)?[ \t]*$"))
-	(match-string 1))
-       (no-todo
-	(looking-at org-todo-line-regexp)
-	(match-string 3))
-       (t (looking-at org-heading-regexp)
-	  (match-string 2))))))
+    (looking-at org-complex-heading-regexp)
+    (let* ((case-fold-search nil)
+	   (todo (or (match-string 2) nil))
+	   (priority (or (match-string 3) nil))
+	   (headlineplus (or (match-string 4) nil))
+	   (tags (or (match-string 5) nil))
+	   (returnval "")
+	   )
+      (if (and (not no-todo) todo)
+	  (setq returnval (concat todo returnval)))
+      (if (and (not no-priority) priority)
+	  (setq returnval (concat returnval (if (> (length returnval) 0) " ") priority 
+				  )))
+      (if (and no-comment (string= "COMMENT" (substring headlineplus 0 7)))
+	  (setq returnval (concat returnval
+				  (if (>  (length returnval) 0 ) 
+				      " "
+				    "")
+				  (substring headlineplus 8 nil)))
+	(setq returnval (concat returnval " " headlineplus)))
+      (if (and (not no-tags) tags)
+	  (setq returnval (concat returnval " " tags)))
+      returnval
+      )))
 
 (defvar orgstruct-mode)   ; defined below
 
-- 
2.11.0

Reply via email to