emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-get-heading and COMMENT
@ 2017-01-11 17:10 Matt Price
  2017-01-14 11:04 ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Matt Price @ 2017-01-11 17:10 UTC (permalink / raw)
  To: Org Mode

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

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? Or should I
maybe be using the org-element API instead? I'm just trying to generate
custom id's from headline text + a shortened hash (acquired via
org-new-id).

[-- Attachment #2: Type: text/html, Size: 468 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: org-get-heading and COMMENT
  2017-01-11 17:10 org-get-heading and COMMENT Matt Price
@ 2017-01-14 11:04 ` Nicolas Goaziou
  2017-01-17 23:05   ` Matt Price
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2017-01-14 11:04 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

Hello,

Matt Price <moptop99@gmail.com> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: org-get-heading and COMMENT
  2017-01-14 11:04 ` Nicolas Goaziou
@ 2017-01-17 23:05   ` Matt Price
  2017-01-18 23:31     ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Matt Price @ 2017-01-17 23:05 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode


[-- Attachment #1.1: Type: text/plain, Size: 584 bytes --]

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

On Sat, Jan 14, 2017 at 6:04 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> Matt Price <moptop99@gmail.com> 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
>

[-- Attachment #1.2: Type: text/html, Size: 1127 bytes --]

[-- Attachment #2: 0004-Add-support-for-new-switches-to-org-get-heading.patch --]
[-- Type: text/x-patch, Size: 2763 bytes --]

From 7c78da444b74a7f75645d2af854859a6a7bf476a Mon Sep 17 00:00:00 2001
From: Matt Price <matt.price@utoronto.ca>
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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: org-get-heading and COMMENT
  2017-01-17 23:05   ` Matt Price
@ 2017-01-18 23:31     ` Nicolas Goaziou
  2017-01-19  0:31       ` Matt Price
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2017-01-18 23:31 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

Hello,

Matt Price <moptop99@gmail.com> writes:

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

No problem. I refactored your patch and pushed it.

Thank you.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: org-get-heading and COMMENT
  2017-01-18 23:31     ` Nicolas Goaziou
@ 2017-01-19  0:31       ` Matt Price
  0 siblings, 0 replies; 5+ messages in thread
From: Matt Price @ 2017-01-19  0:31 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode

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

:-) I look forward to seeing the improved version -- mine felt very
cumbersome!

On Wed, Jan 18, 2017 at 6:31 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> Matt Price <moptop99@gmail.com> writes:
>
> > Sorry for the delay. I am very slow with regexps!
>
> No problem. I refactored your patch and pushed it.
>
> Thank you.
>
> Regards,
>
> --
> Nicolas Goaziou
>

[-- Attachment #2: Type: text/html, Size: 879 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-01-19  0:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-11 17:10 org-get-heading and COMMENT Matt Price
2017-01-14 11:04 ` Nicolas Goaziou
2017-01-17 23:05   ` Matt Price
2017-01-18 23:31     ` Nicolas Goaziou
2017-01-19  0:31       ` Matt Price

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).