emacs-wiki-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[emacs-wiki-discuss] Re: Sort tasks alphabetically


From: Jody Klymak
Subject: [emacs-wiki-discuss] Re: Sort tasks alphabetically
Date: Sat, 04 Dec 2004 11:01:55 -0800
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (darwin)

Hello,

Kai von Fintel <address@hidden> writes:

> Is there an easy or blatantly obvious way to have tasks sorted
> alphabetically (within a given A/B/C block)? That way, a prefix like
> "Grocery:" or "Office:" in front of each task could simulate the GTD
> recipe of sorting next tasks by context.

There is no way to do this now that I know of.  

This is a good idea.  Would doing it by associated plan-page be an
acceptable way to sort?  Even just a random (non alphabetical) sorting
based on this would be cool.  If you really just want contextualized
tasks (i.e. things to do at the grocery), I'd make a "project"
GroceryTasks, OfficeTasks, etc.  But this would also be a useful
sorting for tasks to do with real projects.

Here is a hack that sorts within priorities by plan page link.  Seems
to work (so far).  Note that you could use something like
jmk-get-planner-link to get the string from the task and do the
sorting that way.

Also, anyone who can fix the code below, please do.  

Sacha, maybe it'd be cool if instead of the lambda's there were
functions planner-task-sort-key-daypage and
planner-task-sort-key-planpage that did the key generation.  People
could defcustom these?

Cheers,  Jody

(defun jmk-get-planner-link ()
  (interactive)
  (save-excursion
    (save-window-excursion
      (save-restriction
        (beginning-of-line)     
        (let* ((task-info (planner-current-task-info))
              (task-link (and task-info
                              (if (string-match planner-date-regexp
                                                (emacs-wiki-page-name))
                                  (planner-task-plan task-info)
                                (planner-task-date task-info)))))
          (concat "" task-link))))))

(defun planner-sort-tasks ()
  "Sort the tasks.
On day pages, sort according to category and position.  On plan
pages, sort according to status, category, date, and position."
  (interactive)
  (let ((old-point (point))
        (case-fold-search nil)
        (planner-use-font-lock nil)
        (on-date-page (string-match planner-date-regexp
                                    (planner-page-name))))
    (goto-char (point-min))
    (while (re-search-forward "^#[A-C][0-9]+" nil t)
      (goto-char (match-beginning 0))
      (let ((here (point)))
        (while (and (char-after) (= (char-after) ?#))
          (forward-line 1))
        ;;        (let ((paragraph-start (concat paragraph-start "\\|\\*.+")))
        ;;          (forward-paragraph))
        ;; Sort by category and position on date pages
        (sort-fields-1 1 here (point)
                       (if on-date-page
                           (lambda ()
                             (skip-chars-forward "#ABC")
                             (let ((case-fold-search t)
                                   (ch (char-before))
                                   status)
                               (skip-chars-forward "0123456789 ")
                               (setq status (char-after))
                               (concat ;(read (current-buffer))
                                (cond
                                 ((eq status ?P) "B")
                                 ((eq status ?>) "C")
                                 ((eq status ?X) "D")
                                 ((eq status ?C) "E")
                                 (t "A"))
                                (cond ((eq ch ?A) "A")
                                      ((eq ch ?B) "B")
                                      ((eq ch ?C) "C"))
                                (jmk-get-planner-link))))
                         ;; category, then date, and then position on day pages
                         (lambda ()
                           (skip-chars-forward "#ABC")
                           (let ((ch (char-before))
                                 status)
                             (skip-chars-forward "0123456789 ")
                             (setq status (char-after))
                             (goto-char (line-end-position))
                             (skip-chars-backward "]) ")
                             (format "%1c%1c%10s"
                                     (if (or (= status ?X)
                                             (= status ?C))
                                         status ?\ )
                                     ch
                                     (if (= (skip-chars-backward "0123456789.")
                                            -10)
                                         (buffer-substring (point)
                                                           (+ 10 (point)))
                                       
planner-sort-undated-tasks-equivalent)))))
                         nil))) ; sort-fields
    (goto-char old-point))
  nil)                       ; Must return nil because of write-file-functions



-- 
Jody Klymak      http://opg1.ucsd.edu/~jklymak/
mailto:address@hidden   





reply via email to

[Prev in Thread] Current Thread [Next in Thread]