emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* in-buffer settings for priorities
@ 2007-05-16  9:43 Dmitri Minaev
  2007-05-16 11:47 ` Dmitri Minaev
  2007-05-20 15:45 ` Carsten Dominik
  0 siblings, 2 replies; 8+ messages in thread
From: Dmitri Minaev @ 2007-05-16  9:43 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I'd like to know the opinion of the community (and Carsten's in
particular, of course) on the following idea -- do you think it would
be useful to have in-buffer settings to customize priorities?

The background story (sorry if it's verbose) is like this. I keep my
reading list in org-mode (quite naturally). Normally, the entries are
stored in the chronological order, but sometimes I would like to see
the best or the worst read books. I started by using tags like
:score2:, :score8:, etc., so I could search for tags using regexps
like {score[7-9]}. Unfortunately, the entries were not sorted.
Basically, the only way to sort them is to use priorities instead of
tags. Three grades were not enough, of course, so I set
org-lowest-priority to J. On the contrary, 10 grades were too much for
other files, like todo lists. So, I decided to add per-file settings
for priorities: parameter #+PRIORITY_LOW.

This worked, but using letters to rate books was not the best idea and
I decided to add digits from 0 to 9 to the list of priorities. Now I
think that it might have been better to add a kind of a
#+PRIORITY_STYLE with values 'abc' and 'num', for example, but at that
moment I added another variable -- org-highest-priority and a
corresponding in-buffer setting #+PRIORITY_HIGH. I also had to replace
the regexps for priorities with [A-Z0-9],  I changed the
org-default-priority value from \B to org-lowest-priority, added
#+PRIORITY_DEF setting and adapted the prompts to use
org-highest-priority instead of \A.

Now, I could add this to the reading list:
#+PRIORITY_HIGH: 0
#+PRIORITY_LOW: 9
#+PRIORITY_DEF: 5

Now, only a small change in the .emacs was needed to add a new agenda
custom command that changes the sorting strategy to priority-up, et
voila! I only have to type C-c a 1 b to see the list of books sorted
by my rating.

What still confuses me is the necessity to press S-down to _increase_
the rating. Or, perhaps, I should just get used to the fact the best
books should have rating 1 instead of 9.

The patch against version 4.74 is below. Don't judge me too harshly :)


--- ../org.el	2007-05-16 12:17:15.000000000 +0500
+++ org.el	2007-05-16 13:20:17.000000000 +0500
@@ -1527,9 +1527,8 @@
   :tag "Org Priorities"
   :group 'org-todo)

-(defcustom org-default-priority ?B
-  "The default priority of TODO items.
-This is the priority an item get if no explicit priority is given."
+(defcustom org-highest-priority ?A
+  "The highest priority of TODO items.  A character like ?A, ?B etc."
   :group 'org-priorities
   :type 'character)

@@ -1538,6 +1537,12 @@
   :group 'org-priorities
   :type 'character)

+(defcustom org-default-priority org-lowest-priority
+  "The default priority of TODO items.
+This is the priority an item get if no explicit priority is given."
+  :group 'org-priorities
+  :type 'character)
+
 (defgroup org-time nil
   "Options concerning time stamps and deadlines in Org-mode."
   :tag "Org Time"
@@ -3346,9 +3351,9 @@
     (org-set-local 'org-todo-sets nil)
     (let ((re (org-make-options-regexp
 	       '("CATEGORY" "SEQ_TODO" "PRI_TODO" "TYP_TODO"
-		 "STARTUP" "ARCHIVE" "TAGS" "LINK")))
+		 "STARTUP" "ARCHIVE" "TAGS" "LINK" "PRIORITY_HIGH" "PRIORITY_LOW"
"PRIORITY_DEFAULT")))
 	  (splitre "[ \t]+")
-	  kwds key value cat arch tags links hw dws tail sep kws1)
+	  kwds key value cat arch tags links hw dws tail sep kws1 prio-high
prio-low prio-def)
       (save-excursion
 	(save-restriction
 	  (widen)
@@ -3371,6 +3376,12 @@
 		(push (cons (match-string 1 value)
 			    (org-trim (match-string 2 value)))
 		      links)))
+	     ((equal key "PRIORITY_HIGH")
+	      (setq prio-high value))
+	     ((equal key "PRIORITY_LOW")
+	      (setq prio-low value))
+	     ((equal key "PRIORITY_DEFAULT")
+	      (setq prio-def value))
 	     ((equal key "STARTUP")
 	      (let ((opts (org-split-string value splitre))
 		    l var val)
@@ -3390,6 +3401,9 @@
 				      '(face t fontified t) arch)))
 	    )))
       (and cat (org-set-local 'org-category cat))
+      (and prio-high (org-set-local 'org-highest-priority (aref prio-high 0)))
+      (and prio-low (org-set-local 'org-lowest-priority (aref prio-low 0)))
+      (and prio-def (org-set-local 'org-default-priority (aref prio-def 0)))
       (and arch (org-set-local 'org-archive-location arch))
       (and links (setq org-link-abbrev-alist-local (nreverse links)))
       ;; Process the TODO keywords
@@ -4150,7 +4164,7 @@
 	   (list (concat "^\\*+[ \t]*" org-not-done-regexp)
 		 '(1 'org-todo t))
 	   ;; Priorities
-	   (list (concat "\\[#[A-Z]\\]") '(0 'org-special-keyword t))
+	   (list (concat "\\[#[A-Z0-9]\\]") '(0 'org-special-keyword t))
 	   ;; Special keywords
 	   (list org-repeat-re  '(0 'org-special-keyword t))
 	   (list (concat "\\<" org-deadline-string) '(0 'org-special-keyword t))
@@ -11983,7 +11997,7 @@

 ;;;; Priorities

-(defvar org-priority-regexp ".*?\\(\\[#\\([A-Z]\\)\\] ?\\)"
+(defvar org-priority-regexp ".*?\\(\\[#\\([A-Z0-9]\\)\\] ?\\)"
   "Regular expression matching the priority indicator.")

 (defvar org-remove-priority-next-time nil)
@@ -12012,18 +12026,18 @@
 	(setq current org-default-priority))
       (cond
        ((eq action 'set)
-	(message "Priority A-%c, SPC to remove: " org-lowest-priority)
+	(message "Priority %c-%c, SPC to remove: " org-highest-priority
org-lowest-priority)
 	(setq new (read-char-exclusive))
 	(cond ((equal new ?\ ) (setq remove t))
-	      ((or (< (upcase new) ?A) (> (upcase new) org-lowest-priority))
+	      ((or (< (upcase new) org-highest-priority) (> (upcase new)
org-lowest-priority))
 	       (error "Priority must be between `%c' and `%c'"
-		      ?A org-lowest-priority))))
+		      org-highest-priority org-lowest-priority))))
        ((eq action 'up)
 	(setq new (1- current)))
        ((eq action 'down)
 	(setq new (1+ current)))
        (t (error "Invalid action")))
-      (setq new (min (max ?A (upcase new)) org-lowest-priority))
+      (setq new (min (max org-highest-priority (upcase new))
org-lowest-priority))
       (setq news (format "%c" new))
       (if have
 	  (if remove
@@ -14219,7 +14233,7 @@
 	(setq tmp (calendar-date-string tmp)))
       (setq props (plist-put props 'date tmp)))
     (when (setq tmp (plist-get props 'txt))
-      (when (string-match "\\[#\\([A-Z]\\)\\] ?" tmp)
+      (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
 	(plist-put props 'priority-letter (match-string 1 tmp))
 	(setq tmp (replace-match "" t t tmp)))
       (when (and (setq re (plist-get props 'org-todo-regexp))
@@ -19499,7 +19513,7 @@
 				 (substring hd (match-end 1))))
 	      (setq pri org-default-priority))
 	    (setq pri (floor (1+ (* 8. (/ (float (- org-lowest-priority pri))
-					  (- org-lowest-priority ?A))))))
+					  (- org-lowest-priority org-highest-priority))))))

 	    (princ (format "BEGIN:VTODO
 %s
@@ -20509,7 +20523,7 @@
 	(push (org-point-in-group p 4 :tags) clist))
       (goto-char p)
       (skip-chars-backward "^[\n\r \t") (or (eobp) (backward-char 1))
-      (if (looking-at "\\[#[A-Z]\\]")
+      (if (looking-at "\\[#[A-Z0-9]\\]")
 	  (push (org-point-in-group p 0 :priority) clist)))

      ((org-at-item-p)



-- 
With best regards,
Dmitri Minaev

Russian history blog: http://minaev.blogspot.com

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

end of thread, other threads:[~2007-05-29 16:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-16  9:43 in-buffer settings for priorities Dmitri Minaev
2007-05-16 11:47 ` Dmitri Minaev
2007-05-20 15:45 ` Carsten Dominik
2007-05-21 13:11   ` Dmitri Minaev
2007-05-21 14:35     ` Carsten Dominik
2007-05-22  8:07       ` Dmitri Minaev
2007-05-29 15:27         ` Carsten Dominik
2007-05-22  4:57     ` Carsten Dominik

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).