branch: externals/org
commit f08922964829895a512984419cd0f22eddb56cea
Author: Derek Chen-Becker <[email protected]>
Commit: Ihor Radchenko <[email protected]>

    lisp/org-element.el: Properly handle numeric priorities
    
    Update org-element to properly parse numeric priorities by using a newly
    defined helper function that parses priority values.  Also update the
    headline and inline task interpreters to properly format numeric
    properties.  Add unit tests for the new functionality.
    
    * lisp/org-element.el (org-element--headline-parse-title,
    org-element-headline-interpreter, org-element-inlinetask-interpreter):
    Update `org-element--headline-parse-title' to use `org-priority-to-value'
    for parsing of priorities so that numeric properies are handled properly.
    Change `org-element-headline-interpreter' and
    `org-element-inlinetask-interpreter' to use the `org-priority-to-string'
    function for display conversion of priority values.
    * testing/lisp/test-org-colview.el: Add unit tests to validate proper
    handling of priority formatting in column view.
    * testing/lisp/test-org.el: Add a unit test for the `org-priority-to-value'
    function for single digit, double digit, and character values.
    * testing/lisp/test-ox.el: Add a unit test for the org export interpreters
    for headlines and inline tasks to ensure proper conversion of numeric
    priorities.
---
 lisp/org-element.el              | 10 +++++-----
 testing/lisp/test-org-colview.el | 27 +++++++++++++++++++++++++++
 testing/lisp/test-org.el         |  9 +++++++++
 testing/lisp/test-ox.el          | 23 +++++++++++++++++++++++
 4 files changed, 64 insertions(+), 5 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index e1425d9eb7..651790c19a 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -1359,9 +1359,9 @@ Throw `:org-element-deferred-retry' signal at the end."
                                (org-element--get-cached-string 
(match-string-no-properties 1)))))
             (todo-type
              (and todo (if (member todo org-done-keywords) 'done 'todo)))
-            (priority (and (looking-at "\\[#.\\][ \t]*")
-                           (progn (goto-char (match-end 0))
-                                  (aref (match-string 0) 2))))
+            (priority (and (looking-at org-priority-regexp)
+                            (progn (goto-char (match-end 0))
+                                   (org-priority-to-value (match-string 2)))))
             (commentedp
              (and (let ((case-fold-search nil))
                      (looking-at org-element--headline-comment-re))
@@ -1520,7 +1520,7 @@ CONTENTS is the contents of the element."
                               ?*)
                  (and todo (concat " " todo))
                  (and commentedp (concat " " org-element-comment-string))
-                 (and priority (format " [#%c]" priority))
+                 (and priority (format " [#%s]" (org-priority-to-string 
priority)))
                  " "
                  (if (and org-footnote-section
                           (org-element-property :footnote-section-p headline))
@@ -1739,7 +1739,7 @@ CONTENTS is the contents of inlinetask."
                      (format ":%s:" (mapconcat 'identity tag-list ":")))))
         (task (concat (make-string level ?*)
                       (and todo (concat " " todo))
-                      (and priority (format " [#%c]" priority))
+                      (and priority (format " [#%s]" (org-priority-to-string 
priority)))
                       (and title (concat " " title)))))
     (concat task
            ;; Align tags.
diff --git a/testing/lisp/test-org-colview.el b/testing/lisp/test-org-colview.el
index 681f4fe481..bb283f61f6 100644
--- a/testing/lisp/test-org-colview.el
+++ b/testing/lisp/test-org-colview.el
@@ -1783,5 +1783,32 @@ there are 4 parameters
      (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
      (buffer-substring-no-properties (point) (point-max))))))
 
+(ert-deftest test-org-colview/priorities ()
+  "Test that column view properly handles priorities."
+  ;; test alphabetic priorities
+  (should
+   (equal "B"
+          (org-test-with-temp-text
+           "* [#B] Test"
+           (let ((org-columns-default-format "%PRIORITY"))
+             (org-columns)
+             (get-char-property (point) 'org-columns-value)))))
+  ;; test numeric single-digit priorities
+  (should
+   (equal "6"
+          (org-test-with-temp-text
+           "* [#6] Test"
+           (let ((org-columns-default-format "%PRIORITY"))
+             (org-columns)
+             (get-char-property (point) 'org-columns-value)))))
+  ;; test numeric double-digit priorities
+  (should
+   (equal "15"
+          (org-test-with-temp-text
+           "* [#15] Test"
+           (let ((org-columns-default-format "%PRIORITY"))
+             (org-columns)
+             (get-char-property (point) 'org-columns-value)))))  )
+
 (provide 'test-org-colview)
 ;;; test-org-colview.el ends here
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 1a28d01ed8..76b2a58fb7 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -10152,6 +10152,15 @@ two
      (seq-every-p (lambda (pv) (org-priority-valid-value-p pv t))
                   '(?A ?L ?N ?Z)))))
 
+(ert-deftest test-org/priority-parsing ()
+  "Test parsing of priority values."
+  ;; single digit
+  (should (eq 7 (org-priority-to-value "7")))
+  ;; double digit
+  (should (eq 42 (org-priority-to-value "42")))
+  ;; alphabetic
+  (should (eq ?G (org-priority-to-value "G"))))
+
 (provide 'test-org)
 
 ;;; test-org.el ends here
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index e9d9a06f7e..858b8ee225 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -3149,6 +3149,29 @@ Para2"
                (org-export-as (org-test-default-backend)
                               nil nil nil '(:with-tasks nil))))))))
 
+(ert-deftest test-org-export/handle-numeric-priorities ()
+  "Test handling of numeric priorities in headers and inlinetasks."
+  ;; Properly handle numeric priorities in normal headers
+  (should
+   (equal "* [#3] H2\nContents\n"
+          (let ()
+            (org-test-with-temp-text "* [#3] H2\nContents"
+                                     (org-export-as 
(org-test-default-backend))))))
+  ;; Properly handle numeric priorities in inline tasks
+    (should
+     (equal "* H2\n*** [#8] Inline\nContents\n"
+            (let ((org-inlinetask-min-level 3))
+              (org-test-with-temp-text "* H2\n*** [#8] Inline\nContents"
+                                       (org-export-as 
(org-test-default-backend)
+                                                      nil nil nil 
'(:with-tasks t))))))
+    (should
+     (equal "* H2\n*** [#37] Inline\nContents\n"
+            (let ((org-inlinetask-min-level 3))
+              (org-test-with-temp-text "* H2\n*** [#37] Inline\nContents"
+                                       (org-export-as 
(org-test-default-backend)
+                                                      nil nil nil 
'(:with-tasks t))))))
+  )
+
 
 
 ;;; Keywords

Reply via email to