`org-get-heading' is more consistent on empty headlines

* lisp/org.el (org-get-heading): Ensure that return value is always
  a string.
* testing/lisp/test-org.el (test-org/get-heading): Add tests.

Reported-by: Joe Schafer <joesmoe10@gmail.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/108559>
This commit is contained in:
Nicolas Goaziou 2016-07-30 22:30:19 +02:00
parent d2de890d3e
commit 406ad6eb52
2 changed files with 9 additions and 2 deletions

View File

@ -8092,7 +8092,9 @@ When NO-TODO is non-nil, don't include TODO keywords."
(cond (cond
((and no-tags no-todo) ((and no-tags no-todo)
(looking-at org-complex-heading-regexp) (looking-at org-complex-heading-regexp)
(match-string 4)) ;; Return value has to be a string, but match group 4 is
;; optional.
(or (match-string 4) ""))
(no-tags (no-tags
(looking-at (concat org-outline-regexp (looking-at (concat org-outline-regexp
"\\(.*?\\)" "\\(.*?\\)"

View File

@ -1438,7 +1438,12 @@
(should (should
(equal "Todo H" (equal "Todo H"
(org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>" (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
(org-get-heading nil t))))) (org-get-heading nil t))))
;; On an empty headline, return value is consistent.
(should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
(should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
(should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
(should (equal "" (org-test-with-temp-text "* " (org-get-heading t t)))))
(ert-deftest test-org/in-commented-heading-p () (ert-deftest test-org/in-commented-heading-p ()
"Test `org-in-commented-heading-p' specifications." "Test `org-in-commented-heading-p' specifications."