all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* org-priority: allow customization of priority indicator
@ 2022-10-17 20:46 drlkf
  2022-10-18  6:57 ` Bastien
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: drlkf @ 2022-10-17 20:46 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 535 bytes --]

Hello,

I would like to submit a patch to allow users to change the priority
tag's form entirely. While it has been working for my use-case i.e
basic operations inside org buffers and org-agenda, it is not perfect
and there are some bugs that remain when using more advanced features
with different tag forms (mine is `_p' where `p' is `[1-9]'), that I am
not competent enough to solve. However I believe there are no breaking
changes if the user does not modify said tag form. If there's any
precision I can add, please let me know.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-priority.patch --]
[-- Type: text/x-diff, Size: 6579 bytes --]

From 94117daef8fec4e214d9973a17c2ae4baba1d761 Mon Sep 17 00:00:00 2001
From: drlkf <drlkf@drlkf.net>
Date: Thu, 9 Jun 2022 03:19:00 +0200
Subject: [PATCH] org-priority: allow customization of priority indicator

* org.el (org-priority): Allow the user to set the prefix and suffix
of the priority indicator so that it have a completely different form
for them (e.g _A instead of [#A]).
---
 org-agenda.el  |  4 ++--
 org-element.el |  8 ++++++--
 org.el         | 40 ++++++++++++++++++++++++++++++++--------
 3 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/org-agenda.el b/org-agenda.el
index 71aac271f..cbbe5e4c6 100644
--- a/org-agenda.el
+++ b/org-agenda.el
@@ -3431,8 +3431,8 @@ This ensures the export commands can easily use it."
       (setq props (plist-put props 'day tmp))
       (setq props (plist-put props 'agenda-day tmp)))
     (when (setq tmp (plist-get props 'txt))
-      (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
-	(plist-put props 'priority-letter (match-string 1 tmp))
+      (when (string-match org-priority-regexp tmp)
+	(plist-put props 'priority-letter (match-string 3 tmp))
 	(setq tmp (replace-match "" t t tmp)))
       (when (and (setq re (plist-get props 'org-todo-regexp))
 		 (setq re (concat "\\`\\.*" re " ?"))
diff --git a/org-element.el b/org-element.el
index 9db1406b3..2047e202b 100644
--- a/org-element.el
+++ b/org-element.el
@@ -1009,7 +1009,9 @@ Assume point is at beginning of the headline."
 			     (match-string 1))))
 	   (todo-type
 	    (and todo (if (member todo org-done-keywords) 'done 'todo)))
-	   (priority (and (looking-at "\\[#.\\][ \t]*")
+	   (priority (and (looking-at (format "%s.%s[ \t]*"
+                                              (regexp-quote org-priority-prefix)
+                                              (regexp-quote org-priority-prefix)))
 			  (progn (goto-char (match-end 0))
 				 (aref (match-string 0) 2))))
 	   (commentedp
@@ -1158,7 +1160,9 @@ Assume point is at beginning of the inline task."
 			     (match-string 0))))
 	   (todo-type (and todo
 			   (if (member todo org-done-keywords) 'done 'todo)))
-	   (priority (and (looking-at "\\[#.\\][ \t]*")
+	   (priority (and (looking-at (format "%s.%s[ \t]*"
+                                              (regexp-quote org-priority-prefix)
+                                              (regexp-quote org-priority-prefix)))
 			  (progn (goto-char (match-end 0))
 				 (aref (match-string 0) 2))))
 	   (title-start (point))
diff --git a/org.el b/org.el
index 06af12339..648eb840a 100644
--- a/org.el
+++ b/org.el
@@ -4468,14 +4468,18 @@ related expressions."
 	      org-complex-heading-regexp
 	      (concat "^\\(\\*+\\)"
 		      "\\(?: +" org-todo-regexp "\\)?"
-		      "\\(?: +\\(\\[#.\\]\\)\\)?"
+		      (format "\\(?: +\\(%s.%s\\)\\)?"
+                              (regexp-quote org-priority-prefix)
+                              (regexp-quote org-priority-suffix))
 		      "\\(?: +\\(.*?\\)\\)??"
 		      "\\(?:[ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)?"
 		      "[ \t]*$")
 	      org-complex-heading-regexp-format
 	      (concat "^\\(\\*+\\)"
 		      "\\(?: +" org-todo-regexp "\\)?"
-		      "\\(?: +\\(\\[#.\\]\\)\\)?"
+		      (format "\\(?: +\\(%s.%s\\)\\)?"
+                              (regexp-quote org-priority-prefix)
+                              (regexp-quote org-priority-suffix))
 		      "\\(?: +"
 		      ;; Stats cookies can be stuck to body.
 		      "\\(?:\\[[0-9%%/]+\\] *\\)*"
@@ -5764,8 +5768,10 @@ needs to be inserted at a specific position in the font-lock sequence.")
 	  '(org-activate-code (1 'org-code t))
 	  ;; COMMENT
 	  (list (format
-		 "^\\*+\\(?: +%s\\)?\\(?: +\\[#[A-Z0-9]\\]\\)? +\\(?9:%s\\)\\(?: \\|$\\)"
+		 "^\\*+\\(?: +%s\\)?\\(?: +%s[A-Z0-9]%s\\)? +\\(?9:%s\\)\\(?: \\|$\\)"
 		 org-todo-regexp
+		 (regexp-quote org-priority-prefix)
+		 (regexp-quote org-priority-suffix)
 		 org-comment-string)
 		'(9 'org-special-keyword t))
 	  ;; Blocks and meta lines
@@ -7144,7 +7150,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) (aref (match-string 3) (length org-priority-prefix)))
 	    (match-string-no-properties 4)
 	    (match-string-no-properties 5)))))
 
@@ -11269,13 +11275,29 @@ from the `before-change-functions' in the current buffer."
 
 ;;;; Priorities
 
+(defvar org-priority-prefix "[#"
+  "Prefix to insert before a priority value to form the priority indicator.
+It should be matched in accordance by `org-priority-regexp' in order
+for priorities to work both-ways (inserting and extracting).")
+
+(defvar org-priority-suffix "]"
+  "Suffix to insert after a priority value to end the priority indicator.
+It should be matched in accordance by `org-priority-regexp' in order
+for priorities to work both-ways (inserting and extracting).")
+
 (defvar org-priority-regexp ".*?\\(\\[#\\([A-Z0-9]+\\)\\] ?\\)"
   "Regular expression matching the priority indicator.
 A priority indicator can be e.g. [#A] or [#1].
 This regular expression matches these groups:
 0 : the whole match, e.g. \"TODO [#A] Hack\"
 1 : the priority cookie, e.g. \"[#A]\"
-2 : the value of the priority cookie, e.g. \"A\".")
+2 : the value of the priority cookie, e.g. \"A\".
+
+This regexp should match `org-priority-prefix' and
+`org-priority-suffix' values in order for priorities to work both-ways
+(inserting and extracting).
+
+See also `org-mouse-priority-regexp'.")
 
 (defun org-priority-up ()
   "Increase the priority of the current item."
@@ -11389,9 +11411,9 @@ or a character."
 	    (if (match-end 2)
 		(progn
 		  (goto-char (match-end 2))
-		  (insert " [#" news "]"))
+		  (insert " " org-priority-prefix news org-priority-suffix))
 	      (goto-char (match-beginning 3))
-	      (insert "[#" news "] "))))
+	      (insert org-priority-prefix news org-priority-suffix " "))))
 	(org-align-tags))
       (if remove
 	  (message "Priority removed")
@@ -18800,7 +18822,9 @@ 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 (format "%s[A-Z0-9]%s"
+                                (regexp-quote org-priority-prefix)
+                                (regexp-quote org-priority-suffix)))
 	(push (org-point-in-group p 0 :priority) clist)))
 
      ((org-at-item-p)
-- 
2.30.2


[-- Attachment #3.1: Type: text/plain, Size: 0 bytes --]



[-- Attachment #3.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-04-04 12:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-17 20:46 org-priority: allow customization of priority indicator drlkf
2022-10-18  6:57 ` Bastien
2022-10-18  6:59 ` Stefan Kangas
2022-10-18  8:28 ` Fwd: " drlkf
2022-10-18 12:35   ` Ihor Radchenko
2022-11-21  3:24     ` Ihor Radchenko
2022-11-24 22:11       ` drlkf
2022-11-25  2:12         ` Ihor Radchenko
2023-04-04 12:59           ` Ihor Radchenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.