On Sat, 29 August 2026 14:44, Ihor Radchenko <[email protected]> wrote:

> drlkf <[email protected]> writes:
>> -  (let ((bad-priority-rx (rx line-start ?\[ ?#
>> -                             (group (zero-or-more (not (in ?\[ ?\]))))
>> -                             (group (zero-or-more ?\])))))
>> +  (let ((bad-priority-rx
>> +         (concat "^" (regexp-quote org-priority-prefix) "\\([^"
>> +                 (regexp-quote (substring org-priority-suffix 0 1))
>> +                 (regexp-quote (substring org-priority-prefix 0 1))
>> +                 "]*\\)\\(" (regexp-quote org-priority-suffix) "*\\)")))
>
> This regexp looks strange.
> Could you please explain what you are trying to achieve in this regexp?

sure, in order to match the previous regexp i need to get the first
character of the new prefix const inside the first group (i applied the
same logic to the suffix for consistency); however because there is no
macro expansion in 'rx' syntax 'in' / 'or', 'eval' does not work inside
those so i just changed it to regular regexp string syntax

>From 99f8d04646834f5f4c330008a1fc82a7278f34e7 Mon Sep 17 00:00:00 2001
From: drlkf <[email protected]>
Date: Sun, 9 Aug 2026 18:37:04 +0200
Subject: [PATCH] lisp/org.el: consolidate priority markers

* lisp/org.el (org-priority-regexp, org-priority): consolidate
priority markers into a single set of consts
* lisp/org-mouse.el (org-mouse-priority-regexp): consolidate priority
markers to align with new priority constants
* lisp/org-lint.el (org-lint-priority): consolidate markers to align
with new priority constants

The hardcoded priority markers ~[#~ and ~]~ have been consolidated
into ~org-priority-prefix~ and ~org-priority-suffix~ constants.

TINYCHANGE
---
 lisp/org-lint.el  |  8 +++++---
 lisp/org-mouse.el |  2 +-
 lisp/org.el       | 42 +++++++++++++++++++++++++++++++++++-------
 3 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/lisp/org-lint.el b/lisp/org-lint.el
index df5c0d578..d4bd90b8b 100644
--- a/lisp/org-lint.el
+++ b/lisp/org-lint.el
@@ -1510,9 +1510,11 @@ Use \"export %s\" instead"
   "Report out-of-bounds, invalid, and malformed priorities.
 Raise warnings on headlines containing out-of-bounds, invalid (e.g.,
 `[#-1]', `[#AA]'), or malformed (e.g., `[#1', `[#A') priorities."
-  (let ((bad-priority-rx (rx line-start ?\[ ?#
-                             (group (zero-or-more (not (in ?\[ ?\]))))
-                             (group (zero-or-more ?\])))))
+  (let ((bad-priority-rx
+         (concat "^" (regexp-quote org-priority-prefix) "\\([^"
+                 (regexp-quote (substring org-priority-suffix 0 1))
+                 (regexp-quote (substring org-priority-prefix 0 1))
+                 "]*\\)\\(" (regexp-quote org-priority-suffix) "*\\)")))
     (org-element-map ast 'headline
       (lambda (headline)
         (if-let* ((priority (org-element-property :priority headline)))
diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el
index f2ebe3640..8ccada6e2 100644
--- a/lisp/org-mouse.el
+++ b/lisp/org-mouse.el
@@ -378,7 +378,7 @@ nor a function, elements of KEYWORDS are used directly."
   (org-priority priority))
 
 (defvar org-mouse-priority-regexp
-  (format "\\[#\\(%s\\)\\]" org-priority-value-regexp)
+  (org-make-priority-regexp t)
   "Regular expression matching the priority indicator.
 Differs from `org-priority-regexp' in that it doesn't contain the
 leading `.*?' and only matches a group for the priority value.")
diff --git a/lisp/org.el b/lisp/org.el
index b9d394eec..324c70cc9 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -123,14 +123,34 @@ sure that we are at the beginning of the line.")
   "Matches a headline, putting stars and text into groups.
 Stars are put in group 1 and the trimmed body in group 2.")
 
+(defconst org-priority-prefix "[#"
+  "Marker preceding value in the priority indicator e.g [# in [#A].")
+
+(defconst org-priority-suffix "]"
+  "Marker following value in the priority indicator e.g ] in [#A].")
+
 (defvar org-priority-value-regexp "[A-Z]\\|[0-9]\\|[1-5][0-9]\\|6[0-4]"
   "Regular expression matching valid priority values.
 The priority value must be a capital Latin
 alphabetic character, A through Z, or can be an integer value in the range 0
 through 64.")
 
+(defun org-make-priority-regexp (&optional inner-only)
+  "Generate a correct `org-priority-regexp' using `org-priority'
+variables. Useful after setting custom priority markers or value
+regexp.
+
+If INNER-ONLY is non-nil, return only the inner regular expression,
+e.g to store in `org-mouse-priority-regexp' instead."
+  (let ((inner (concat (regexp-quote org-priority-prefix)
+                       "\\(" org-priority-value-regexp "\\)"
+                       (regexp-quote org-priority-suffix))))
+    (if inner-only
+      inner
+      (concat ".*?\\(" inner " ?\\)"))))
+
 (defvar org-priority-regexp
-  (format ".*?\\(\\[#\\(%s\\)\\] ?\\)" org-priority-value-regexp)
+  (org-make-priority-regexp)
   "Regular expression matching the priority indicator.
 A priority indicator can be e.g. [#A] or [#1].
 The value of the priority cookie must be a capital Latin
@@ -4662,13 +4682,19 @@ related expressions."
 	      org-complex-heading-regexp
 	      (concat "^\\(\\*+\\)"
 		      "\\(?: +" org-todo-regexp "\\)?"
-		      (format "\\(?: +\\(\\[#\\(?:%s\\)\\]\\)\\)?" org-priority-value-regexp)
+		      (format "\\(?: +\\(%s\\(?:%s\\)%s\\)\\)?"
+                              (regexp-quote org-priority-prefix)
+                              org-priority-value-regexp
+                              (regexp-quote org-priority-suffix))
 		      "\\(?: +\\(.*?\\)\\)??"
                       org-tag--group-optional-re)
 	      org-complex-heading-regexp-format
 	      (concat "^\\(\\*+\\)"
 		      "\\(?: +" org-todo-regexp "\\)?"
-		      (format "\\(?: +\\(\\[#\\(?:%s\\)\\]\\)\\)?" org-priority-value-regexp)
+		      (format "\\(?: +\\(%s\\(?:%s\\)%s\\)\\)?"
+                              (regexp-quote org-priority-prefix)
+                              org-priority-value-regexp
+                              (regexp-quote org-priority-suffix))
 		      "\\(?: +"
                       ;; Headline might be commented
                       "\\(?:" org-comment-string " +\\)?"
@@ -6252,9 +6278,11 @@ needs to be inserted at a specific position in the font-lock sequence.")
           ;; Apply this last, after all the markup is highlighted, so
           ;; that even "bright" markup will become dim.
 	  (list (format
-		 "^\\*+\\(?: +%s\\)?\\(?: +\\[#\\(?:%s\\)\\]\\)? +\\(?9:%s\\)\\(?: \\|$\\)"
+		 "^\\*+\\(?: +%s\\)?\\(?: +%s\\(?:%s\\)%s\\)? +\\(?9:%s\\)\\(?: \\|$\\)"
 		 org-todo-regexp
+                 (regexp-quote org-priority-prefix)
                  org-priority-value-regexp
+                 (regexp-quote org-priority-suffix)
 		 org-comment-string)
 		'(9 'org-special-keyword prepend))
           '(org-activate-folds))))
@@ -11652,9 +11680,9 @@ interactive prompt, it will automatically be converted to uppercase."
 	    (if (match-end 2)
 		(progn
 		  (goto-char (match-end 2))
-		  (insert " [#" new-value-string "]"))
+		  (insert " " org-priority-prefix new-value-string org-priority-suffix))
 	      (goto-char (match-beginning 3))
-	      (insert "[#" new-value-string "] "))))
+	      (insert org-priority-prefix new-value-string org-priority-suffix " "))))
 	(when org-auto-align-tags (org-align-tags)))
       (if remove
 	  (message "Priority removed")
@@ -19430,7 +19458,7 @@ and :keyword."
 	(push (org-point-in-group p 4 :tags) clist))
       (goto-char p)
       (skip-chars-backward "^[\n\r \t") (or (bobp) (backward-char 1))
-      (when (looking-at "\\[#[A-Z0-9]\\]")
+      (when (looking-at (org-make-priority-regexp t))
 	(push (org-point-in-group p 0 :priority) clist)))
 
      ((org-at-item-p)
-- 
2.47.3

-- 
drlkf

Reply via email to