From 6dc6eb3b029ec00c10e20dcfaa0b6e328bf36e03 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 19 Jan 2017 00:14:16 +0100 Subject: [PATCH] Fix failing test * lisp/org.el (org-link-search): Remove priority cookie from headlines during a fuzzy search. Tiny optimization. * testing/lisp/test-org.el (test-org/get-heading): Add tests. --- etc/ORG-NEWS | 3 +++ lisp/org.el | 5 +++-- testing/lisp/test-org.el | 41 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 99952a907..bb3020cca 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -202,6 +202,9 @@ that doesn't exist in the target file, save positon before raising an error. As a consequence, it is possible to jump back to the original document with ~org-mark-ring-goto~ (default binding =C-c &=). +*** ~org-get-heading~ accepts two more optional arguments + +See docstring for details. * Version 9.0 ** Incompatible changes diff --git a/lisp/org.el b/lisp/org.el index 44320b821..0413d8368 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -11146,7 +11146,8 @@ of matched result, which is either `dedicated' or `fuzzy'." org-comment-string (mapconcat #'regexp-quote words ".+"))) (cookie-re "\\[[0-9]*\\(?:%\\|/[0-9]*\\)\\]") - (comment-re (format "\\`%s[ \t]+" org-comment-string))) + (comment-re (eval-when-compile + (format "\\`%s[ \t]+" org-comment-string)))) (goto-char (point-min)) (catch :found (while (re-search-forward title-re nil t) @@ -11155,7 +11156,7 @@ of matched result, which is either `dedicated' or `fuzzy'." (replace-regexp-in-string cookie-re "" (replace-regexp-in-string - comment-re "" (org-get-heading t t))))) + comment-re "" (org-get-heading t t t))))) (throw :found t))) nil))) (beginning-of-line) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 49e94778c..9008e6bd4 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1513,11 +1513,20 @@ (equal "H" (org-test-with-temp-text "* H\nText" (org-get-heading)))) - ;; Without any optional argument, return TODO keywords and tags. + ;; Without any optional argument, return TODO keyword, priority + ;; cookie, COMMENT keyword and tags. (should (equal "TODO H" (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H" (org-get-heading)))) + (should + (equal "[#A] H" + (org-test-with-temp-text "* [#A] H" + (org-get-heading)))) + (should + (equal "COMMENT H" + (org-test-with-temp-text "* COMMENT H" + (org-get-heading)))) (should (equal "H :tag:" (org-test-with-temp-text "* H :tag:" @@ -1545,11 +1554,39 @@ (equal "Todo H" (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H" (org-get-heading nil t)))) + ;; With NO-PRIORITY, ignore priority. + (should + (equal "H" + (org-test-with-temp-text "* [#A] H" + (org-get-heading nil nil t)))) + (should + (equal "H" + (org-test-with-temp-text "* H" + (org-get-heading nil nil t)))) + (should + (equal "TODO H" + (org-test-with-temp-text "* TODO [#A] H" + (org-get-heading nil nil t)))) + ;; With NO-COMMENT, ignore COMMENT keyword. + (should + (equal "H" + (org-test-with-temp-text "* COMMENT H" + (org-get-heading nil nil nil t)))) + (should + (equal "H" + (org-test-with-temp-text "* H" + (org-get-heading nil nil nil t)))) + (should + (equal "TODO [#A] H" + (org-test-with-temp-text "* TODO [#A] COMMENT H" + (org-get-heading nil nil 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))))) + (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t)))) + (should + (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t))))) (ert-deftest test-org/in-commented-heading-p () "Test `org-in-commented-heading-p' specifications."