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

    lisp/org.el: Fix bug when removing priority due to wrapping
    
    * lisp/org.el (org-priority): Avoid computation (and validation) of a new
    priority value when `remove' is true to avoid an incorrect validation
    failure inside of `org-priority-to-string'.
    
    * testing/lisp/test-org.el: Add unit tests to exercise removal of priority
    for both numeric and alphabetic priorities when using `org-priority-up' and
    `org-priority-down'.
---
 lisp/org.el              |  5 ++++-
 testing/lisp/test-org.el | 25 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index d8601ad59a..156b615674 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11471,7 +11471,10 @@ interactive prompt, it will automatically be converted 
to uppercase."
            ;; normal cycling: `new-value' is beyond highest/lowest priority
            ;; and is wrapped around to the empty priority
            (setq remove t)))
-       (setq new-value-string (org-priority-to-string new-value))
+        (setq new-value-string
+              (if remove
+                  "removed"
+                (org-priority-to-string new-value)))
        (if has-existing-cookie
            (if remove
                (replace-match "" t t nil 1)
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index c80cdc8b19..8bc36a0e80 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -10207,6 +10207,31 @@ two
          (nth 3 (org-heading-components)))))
   )
 
+(ert-deftest test-org/org-priority-cycling ()
+  "Test proper cycling of priority values."
+  ;; Numerics with custom priority wrapping should remove the priority when it 
exceeds bounds
+  (should
+   (string-equal "Priority removed"
+       (org-test-with-temp-text "#+PRIORITIES: 0 10 5\n* [#0] Test\n"
+                                (goto-char (point-max))
+                                (org-priority-up))))
+  (should
+   (string-equal "Priority removed"
+       (org-test-with-temp-text "#+PRIORITIES: 0 10 5\n* [#10] Test\n"
+                                (goto-char (point-max))
+                                (org-priority-down))))
+  ;; Alpha with custom priority wrapping should remove the priority when it 
exceeds bounds
+  (should
+   (string-equal "Priority removed"
+       (org-test-with-temp-text "#+PRIORITIES: A Z M\n* [#A] Test\n"
+                                (goto-char (point-max))
+                                (org-priority-up))))
+  (should
+   (string-equal "Priority removed"
+       (org-test-with-temp-text "#+PRIORITIES: A Z M\n* [#Z] Test\n"
+                                (goto-char (point-max))
+                                (org-priority-down)))))
+
 (provide 'test-org)
 
 ;;; test-org.el ends here

Reply via email to