branch: externals/org
commit 5a1cc9224323e56054b6ae2893cf57bc0e087e51
Author: Derek Chen-Becker <[email protected]>
Commit: Ihor Radchenko <[email protected]>
lisp/org.el: Handle numeric priorities in `org-heading-components'
* lisp/org.el (org-heading-components): Change the extraction logic for
priorities to utilize `substring' instead of `aref' so that we can
accommodate double digit numerics. Also utilize `org-priority-to-value' to
convert the matched string into a proper priority value.
* testing/lisp/test-org.el: Add a set of unit tests for priority extraction
with `org-heading-components' to validate handling of numeric priorities.
---
lisp/org.el | 4 ++--
testing/lisp/test-org.el | 19 +++++++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index 7b455a18a3..d8601ad59a 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6773,7 +6773,7 @@ This is a list with the following elements:
- the level as an integer
- the reduced level, different if `org-odd-levels-only' is set.
- the TODO keyword, or nil
-- the priority character, like ?A, or nil if no priority is given
+- the priority value, like ?A or 42, or nil if no priority is given
- the headline text itself, or the tags string if no headline text
- the tags string, or nil."
(save-excursion
@@ -6784,7 +6784,7 @@ This is a list with the following elements:
(list (length (match-string 1))
(org-reduced-level (length (match-string 1)))
(match-string-no-properties 2)
- (and (match-end 3) (aref (match-string 3) 2))
+ (and (match-end 3) (org-priority-to-value (substring
(match-string 3) 2 -1)))
(match-string-no-properties 4)
(match-string-no-properties 5))
(org-fold-core-update-optimization (match-beginning 0) (match-end
0))))))
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 530584e8d3..c80cdc8b19 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -10188,6 +10188,25 @@ two
;; alphabetic
(should (eq ?G (org-priority-to-value "G"))))
+(ert-deftest test-org/org-heading-components ()
+ "Test parsing of headers using org-heading-components."
+ ;; character priority
+ (should
+ (eq ?A
+ (org-test-with-temp-text "* [#A] H1\n Body"
+ (nth 3 (org-heading-components)))))
+ ;; single digit numeric priority
+ (should
+ (eq 2
+ (org-test-with-temp-text "* [#2] H1\n Body"
+ (nth 3 (org-heading-components)))))
+ ;; double digit numeric priority
+ (should
+ (eq 10
+ (org-test-with-temp-text "* [#10] H1\n Body"
+ (nth 3 (org-heading-components)))))
+ )
+
(provide 'test-org)
;;; test-org.el ends here