[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[emacs-wiki-discuss] More proof-of-concept code: Task scoring
From: |
Sacha Chua |
Subject: |
[emacs-wiki-discuss] More proof-of-concept code: Task scoring |
Date: |
Fri, 18 Feb 2005 16:12:36 +0900 |
User-agent: |
Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux) |
johnsu01 pasted a simple function for sorting tasks in #emacs and I
couldn't resist tweaking it. Here's the relevant snippet from my
http://sacha.free.net.ph/notebook/emacs/planner-config.el .
Hope it makes someone else happy! =)
;;;_+ Fancy task sorting: idea and base code from johnsu01 on 2005.02.18.
;; This code allows you to sort your tasks based on regular expressions.
;; Try it out with
;;
;; C-u M-x sacha/planner-score-sort-tasks RET
some-regexp-matching-tasks-to-be-raised RET
;;
;; If you like the effects and want to keep a whole bunch of sorting
;; rules so that you can call M-x sacha/planner-score-sort-tasks
;; without any arguments, modify the sacha/planner-score-rules
;; variable.
;;
;; If you want this to become your default sorting algorithm,
;; (setq planner-sort-tasks-key-function 'sacha/planner-score-tasks-key)
;;
;; If you want it to trigger only on some pages but not on others, see
;; the `planner-sort-tasks-basic' function for inspiration.
;;
;; I hope this code shows how easy it is to tweak task sorting. =)
;; It's also handy for quickly pulling up certain tasks, as the regular
;; M-x planner-sort-tasks will leave some semblance of the old order in.
(defvar sacha/planner-score-rules '(("patch" . 100)
("bug" . 100))
"*Alist of planner scoring rules of the form (regexp . score-value).
Tasks with higher scores are listed first.")
(defun sacha/planner-score-tasks-key ()
"Sort tasks by the rules in `sacha/planner-score-rules'."
(let ((score 0)
(case-fold-search t)
(line (buffer-substring-no-properties (line-beginning-position)
(line-end-position))))
(mapc
(lambda (item)
(when (string-match (car item) line)
(setq score (- score (cdr item)))))
sacha/planner-score-rules)
score))
(defun sacha/planner-score-sort-tasks (&optional new-rule)
"Sort tasks by `sacha/planner-score-rules' or NEW-RULE.
If called interactively, prompt for NEW-RULE. If NEW-RULE is
non-nil, tasks matching that regexp are raised. If not, tasks are
sorted according to `sacha/planner-score-rules'."
(interactive (list (if current-prefix-arg (read-string "Task regexp: "))))
(let ((planner-sort-tasks-key-function 'sacha/planner-score-tasks-key)
(sacha/planner-score-rules
(if new-rule
(list (cons new-rule 1))
sacha/planner-score-rules)))
(planner-sort-tasks)))
--
Sacha Chua <address@hidden> - open source geekette
http://sacha.free.net.ph/ - PGP Key ID: 0xE7FDF77C
interests: emacs, gnu/linux, personal information management, CS ed
sachac on irc.freenode.net#emacs . YM: sachachua83
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [emacs-wiki-discuss] More proof-of-concept code: Task scoring,
Sacha Chua <=