diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-06-13 22:15:17 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-06-13 22:15:17 +0200 |
commit | 3f26c9bd2e824d0034f7db0bb9aeb2aa14f22d7a (patch) | |
tree | 9d5000988a7cf7707950a1a5cf32102c433e9609 | |
parent | c0e89ad4d561506bbeddc9778ea68ef03de3fcb5 (diff) | |
download | org-mode-3f26c9bd2e824d0034f7db0bb9aeb2aa14f22d7a.tar.gz |
`org-get-heading' returns nil instead of erroring out
* lisp/org.el (org-get-heading): Return nil instead of throwing an
error before first headline.
-rw-r--r-- | lisp/org.el | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/lisp/org.el b/lisp/org.el index 0f43cce..cee98e5 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7700,25 +7700,27 @@ So this will delete or add empty lines." When NO-TAGS is non-nil, don't include tags. 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)) - (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)) - " "))))) +When NO-COMMENT is non-nil, don't include COMMENT string. +Return nil before first heading." + (unless (org-before-first-heading-p) + (save-excursion + (org-back-to-heading t) + (let ((case-fold-search nil)) + (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)) + " ")))))) (defun org-heading-components () "Return the components of the current heading. |