emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: drlkf <drlkf@drlkf.net>
To: <emacs-orgmode@gnu.org>
Subject: Fwd: org-priority: allow customization of priority indicator
Date: Tue, 18 Oct 2022 10:28:47 +0200	[thread overview]
Message-ID: <2243d1d4-94f5-4d05-b655-fac44f277a48@internet> (raw)
In-Reply-To: f198bab7-9ec6-4496-89cd-d84d0917506a@internet

[-- 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 --]

       reply	other threads:[~2022-10-18  9:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <f198bab7-9ec6-4496-89cd-d84d0917506a@internet>
2022-10-18  8:28 ` drlkf [this message]
2022-10-18 12:35   ` Fwd: org-priority: allow customization of priority indicator 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2243d1d4-94f5-4d05-b655-fac44f277a48@internet \
    --to=drlkf@drlkf.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).