From dda6bf799aff238bfcde5538d96f9b4c6d333ed4 Mon Sep 17 00:00:00 2001 From: Stephen Berman Date: Wed, 23 Jan 2013 16:23:32 +0100 Subject: [PATCH] * calendar/todos.el: Improve handling of saved top priorities items. (todos-find-item): Find done items and items whose priority has changed or whose text was truncated or augmented; add doc string. (todos-check-top-priorities): Highlight each item that is not up to date. (todos-jump-to-item): Jump to items whose priority has changed or whose text was truncated or augmented. --- lisp/ChangeLog | 10 +++++ lisp/calendar/todos.el | 93 ++++++++++++++++++++++++++++++++---------- 2 files changed, 82 insertions(+), 21 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e435ad188e7..ed336ad5bf2 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,13 @@ +2013-01-23 Stephen Berman + + * calendar/todos.el: Improve handling of saved top priorities items. + (todos-find-item): Find done items and items whose priority has + changed or whose text was truncated or augmented; add doc string. + (todos-check-top-priorities): Highlight each item that is not up + to date. + (todos-jump-to-item): Jump to items whose priority has changed or + whose text was truncated or augmented. + 2013-01-22 Stephen Berman * calendar/todos.el: Revise handling of initial display and extend diff --git a/lisp/calendar/todos.el b/lisp/calendar/todos.el index 836537a8d37..14cfdc59127 100644 --- a/lisp/calendar/todos.el +++ b/lisp/calendar/todos.el @@ -2138,7 +2138,13 @@ in Todos Filter Items mode." " \"%s\"") buffer-type fnames)))) (defun todos-find-item (str) - "" + "Search for saved top priority item STR in its Todos file. +Return the list (FOUND FILE CAT), where CAT and FILE are the +item's category and file, and FOUND is a cons cell if the search +succeeds, whose car is the start of the item in FILE and whose +cdr is `done' if the item is now a done item, `changed' if its +priority has changed or its text was truncated or augmented, and +`same' otherwise." (string-match (concat (if todos-filter-done-items (concat "\\(?:" todos-done-string-start "\\|" todos-date-string-start "\\)") @@ -2149,12 +2155,16 @@ in Todos Filter Items mode." (regexp-quote todos-nondiary-end)) "?" "\\(?4: \\[\\(?3:(archive) \\)?\\(?2:.*:\\)?" "\\(?1:.*\\)\\]\\).*$") str) - ;; FIXME: use cat and file to find priorities (let ((cat (match-string 1 str)) (file (match-string 2 str)) (archive (string= (match-string 3 str) "(archive) ")) + (filcat (match-string 4 str)) + (tpriority 1) found) (setq str (replace-match "" nil nil str 4)) + (save-excursion + (while (search-backward filcat nil t) + (setq tpriority (1+ tpriority)))) (setq file (if file (concat todos-files-directory (substring file 0 -1) (if archive ".toda" ".todo")) @@ -2166,20 +2176,61 @@ in Todos Filter Items mode." (with-current-buffer (find-buffer-visiting file) (widen) (goto-char (point-min)) - (re-search-forward - (concat "^" (regexp-quote (concat todos-category-beg cat)) "$") nil t) - ;; FIXME: use todos-forward-item to find priority, and return it as well - (setq found (search-forward str nil t))) - (list found file cat))) + (let ((beg (re-search-forward + (concat "^" (regexp-quote (concat todos-category-beg cat)) "$") + nil t)) + (done (save-excursion + (re-search-forward + (concat "^" (regexp-quote todos-category-done)) nil t))) + (end (save-excursion + (or (re-search-forward + (concat "^" (regexp-quote todos-category-beg)) + nil t) + (point-max))))) + (setq found (when (search-forward str end t) + (goto-char (match-beginning 0)))) + (when found + (setq found + (cons found (if (> (point) done) + 'done + (let ((cpriority 1)) + (save-excursion + ;; Not top item in category. + (while (> (point) (1+ beg)) + (let ((opoint (point))) + (todos-backward-item) + ;; Can't move backward beyond + ;; first item in file. + (unless (= (point) opoint) + (setq cpriority (1+ cpriority)))))) + (if (and (= tpriority cpriority) + ;; Proper substring is not the same. + (string= (todos-item-string) + str)) + 'same + 'changed)))))))) + (list found file cat))) (defun todos-check-top-priorities () - "Return a message saying whether top priorities file is up-to-date." - (while (not (eobp)) - (let ((item (todos-item-string))) - (unless (car (todos-find-item item)) - (error "Top priorities file is not up to date"))) - (todos-forward-item)) - (message "Top priorities file is up to date.")) + "Return a message saying whether top priorities file is up to date." + ;; (catch 'old + (let ((count 0)) + (while (not (eobp)) + (let* ((item (todos-item-string)) + (found (car (todos-find-item item)))) + (unless (eq (cdr found) 'same) + (save-excursion + (overlay-put (make-overlay (todos-item-start) (todos-item-end)) + 'face 'todos-search)) + (setq count (1+ count)))) + ;; (throw 'old (message "The marked item is not up to date."))) + (todos-forward-item)) + (if (zerop count) + (message "Top priorities file is up to date.") + (message (concat "The highlighted item" (if (= count 1) " is " "s are ") + "not up to date." + ;; "\nType on item for details." + ))))) (defun todos-top-priorities-filename () ;FIXME: make part of t-s-t-p-b ? "" @@ -3479,22 +3530,22 @@ CAT; this is used in Todos Categories mode." (let* ((str (todos-item-string)) (buf (current-buffer)) (res (todos-find-item str)) + (found (nth 0 res)) (file (nth 1 res)) - (cat (nth 2 res)) - beg) - (if (not (car res)) - (message "Item not found") - (setq beg (match-beginning 0)) + (cat (nth 2 res))) + (if (not found) + (message "Category %s does not contain this item." cat) (kill-buffer buf) (set-window-buffer (selected-window) (set-buffer (find-buffer-visiting file))) (setq todos-current-todos-file file) (setq todos-category-number (todos-category-number cat)) - (let ((todos-show-with-done (if todos-filter-done-items + (let ((todos-show-with-done (if (or todos-filter-done-items + (eq (cdr found) 'done)) t todos-show-with-done))) (todos-category-select)) - (goto-char beg)))) + (goto-char (car found))))) (defun todos-forward-item (&optional count) "Move point down to start of item with next lower priority. -- 2.39.5