From 53ee147f4537a051bfde366ea1459f059fdc13ef Mon Sep 17 00:00:00 2001 From: Matt Price Date: Tue, 17 Jan 2017 18:03:12 -0500 Subject: [PATCH] Add support for new switches to org-get-heading * lisp/org.el (org-get-heading): NO-COMMENT tag, if non-nil, will not return the COMMENT string with heading. Likewise, NO-PRIORITY, if non-nil, will not return the priority cookie. --- lisp/org.el | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 9e993e387..44320b821 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -8015,29 +8015,30 @@ 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-priority no-comment) "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-TODO is non-nil, don't include TODO keywords. +When NO-PRIORITY is non-nil, don't include priority cookie. +When NO-COMMENT is non-nil, don't include COMMENT 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 ((todo (and (not no-todo) (match-string 2))) + (priority (and (not no-priority) (match-string 3))) + (headline (pcase (match-string 4) + (`nil "") + ((and (guard no-comment) h) + (replace-regexp-in-string + (eval-when-compile + (format "\\`%s[ \t]+" org-comment-string)) + "" h)) + (h h))) + (tags (and (not no-tags) (match-string 5)))) + (mapconcat #'identity + (delq nil (list todo priority headline tags)) + " "))))) (defvar orgstruct-mode) ; defined below