aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Berman2012-06-03 21:10:46 +0100
committerStephen Berman2012-06-03 21:10:46 +0100
commita820dfe8e0d63e9fda849a4250204f525a3f022b (patch)
tree6a4792b8cfc1e806bdb004433d2eb41ec59078be
parentb28872cedf83d969449b47d412810e1c29b14f00 (diff)
downloademacs-a820dfe8e0d63e9fda849a4250204f525a3f022b.tar.gz
emacs-a820dfe8e0d63e9fda849a4250204f525a3f022b.zip
* calendar/todos.el: Further comment revision.
(todos-sorted-column): Change default value. (todos-item-start): Handle empty category (needed in todos-filter-items). (todos-read-date): Don't use calendar-read; make code cleaner. (todos-multiple-filter-files): Rename this variable from todos-multiple-files and adjust users. (todos-multiple-filter-files-widget): Rename from todos-multiple-files-widget and adjust users. (todos-multiple-filter-files): Rename this function from todos-multiple-files and adjust callers. (todos-filter-items): Remove unused code. (todos-insert-category-line): Add space so highlighting of last column is consistent with the others; adjust display of column highlighting. (todos-menu): Remove obsolete entry. (todos-categories-mode-map): Add new bindings. (todos-display-categories-alphabetically-or-by-priority): New command. (todos-display-categories-sorted-by-todo) (todos-display-categories-sorted-by-diary) (todos-display-categories-sorted-by-done) (todos-display-categories-sorted-by-archived): Restore and fix implementation.
-rw-r--r--lisp/ChangeLog26
-rw-r--r--lisp/calendar/todos.el223
2 files changed, 146 insertions, 103 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index bd81d41108e..bc6cdafee82 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,31 @@
12012-09-23 Stephen Berman <stephen.berman@gmx.net> 12012-09-23 Stephen Berman <stephen.berman@gmx.net>
2 2
3 * calendar/todos.el: Further comment revision.
4 (todos-sorted-column): Change default value.
5 (todos-item-start): Handle empty category (needed in
6 todos-filter-items).
7 (todos-read-date): Don't use calendar-read; make code cleaner.
8 (todos-multiple-filter-files): Rename this variable from
9 todos-multiple-files and adjust users.
10 (todos-multiple-filter-files-widget): Rename from
11 todos-multiple-files-widget and adjust users.
12 (todos-multiple-filter-files): Rename this function from
13 todos-multiple-files and adjust callers.
14 (todos-filter-items): Remove unused code.
15 (todos-insert-category-line): Add space so highlighting of last
16 column is consistent with the others; adjust display of column
17 highlighting.
18 (todos-menu): Remove obsolete entry.
19 (todos-categories-mode-map): Add new bindings.
20 (todos-display-categories-alphabetically-or-by-priority): New command.
21 (todos-display-categories-sorted-by-todo)
22 (todos-display-categories-sorted-by-diary)
23 (todos-display-categories-sorted-by-done)
24 (todos-display-categories-sorted-by-archived): Restore and fix
25 implementation.
26
272012-09-23 Stephen Berman <stephen.berman@gmx.net>
28
3 * calendar/todos.el: Significant code rearrangement; further 29 * calendar/todos.el: Significant code rearrangement; further
4 comment revision. 30 comment revision.
5 (todos-filtered-items-buffer): Rename from todos-filter-buffer and 31 (todos-filtered-items-buffer): Rename from todos-filter-buffer and
diff --git a/lisp/calendar/todos.el b/lisp/calendar/todos.el
index 6b1e7b21067..19ab6deca74 100644
--- a/lisp/calendar/todos.el
+++ b/lisp/calendar/todos.el
@@ -607,15 +607,14 @@ categories display according to priority."
607 :group 'todos-faces) 607 :group 'todos-faces)
608 608
609(defface todos-sorted-column 609(defface todos-sorted-column
610 ;; '((t :inherit fringe))
611 '((((class color) 610 '((((class color)
612 (background light)) 611 (background light))
613 (:foreground "grey95")) 612 (:background "grey85"))
614 (((class color) 613 (((class color)
615 (background dark)) 614 (background dark))
616 (:foreground "grey10")) 615 (:background "grey10"))
617 (t 616 (t
618 (:foreground "gray"))) 617 (:background "gray")))
619 "Face for buttons in todos-display-categories." 618 "Face for buttons in todos-display-categories."
620 :group 'todos-faces) 619 :group 'todos-faces)
621 620
@@ -1141,7 +1140,6 @@ the file."
1141 (when buffer-file-name ; During conversion there is no file yet. 1140 (when buffer-file-name ; During conversion there is no file yet.
1142 ;; If the file is an archive, it doesn't have an archive. 1141 ;; If the file is an archive, it doesn't have an archive.
1143 (unless (member (file-truename buffer-file-name) 1142 (unless (member (file-truename buffer-file-name)
1144 ;; FIXME: can todos-archives be too old here?
1145 (funcall todos-files-function t)) 1143 (funcall todos-files-function t))
1146 (setq archive (concat (file-name-sans-extension 1144 (setq archive (concat (file-name-sans-extension
1147 todos-current-todos-file) ".toda")))) 1145 todos-current-todos-file) ".toda"))))
@@ -1250,6 +1248,10 @@ Helper function for `todos-convert-legacy-files'."
1250(defun todos-item-start () 1248(defun todos-item-start ()
1251 "Move to start of current Todos item and return its position." 1249 "Move to start of current Todos item and return its position."
1252 (unless (or 1250 (unless (or
1251 ;; Buffer is empty (invocation possible e.g. via todos-forward-item
1252 ;; from todos-filter-items when processing category with no todo
1253 ;; items).
1254 (eq (point-min) (point-max))
1253 ;; Point is on the empty line between todo and done items. 1255 ;; Point is on the empty line between todo and done items.
1254 (and (looking-at "^$") 1256 (and (looking-at "^$")
1255 (save-excursion 1257 (save-excursion
@@ -1496,12 +1498,14 @@ TYPE can be either a file or a category"
1496(defun todos-read-date () 1498(defun todos-read-date ()
1497 "Prompt for Gregorian date and return it in the current format. 1499 "Prompt for Gregorian date and return it in the current format.
1498Also accepts `*' as an unspecified month, day, or year." 1500Also accepts `*' as an unspecified month, day, or year."
1499 (let* ((year (calendar-read 1501 (let* ((year (let (x)
1500 ;; FIXME: maybe better like monthname with RET for current month 1502 (while (if (numberp x) (< x 0) (not (eq x '*)))
1501 "Year (>0 or * for any year): " 1503 (setq x (read-from-minibuffer
1502 (lambda (x) (or (eq x '*) (> x 0))) 1504 "Year (>0 or RET for this year or * for any year): "
1503 (number-to-string (calendar-extract-year 1505 nil nil t nil (number-to-string
1504 (calendar-current-date))))) 1506 (calendar-extract-year
1507 (calendar-current-date))))))
1508 x))
1505 (month-array (vconcat calendar-month-name-array (vector "*"))) 1509 (month-array (vconcat calendar-month-name-array (vector "*")))
1506 (abbrevs (vconcat calendar-month-abbrev-array (vector "*"))) 1510 (abbrevs (vconcat calendar-month-abbrev-array (vector "*")))
1507 (completion-ignore-case todos-completion-ignore-case) 1511 (completion-ignore-case todos-completion-ignore-case)
@@ -1520,13 +1524,16 @@ Also accepts `*' as an unspecified month, day, or year."
1520 1999 ; FIXME: no Feb. 29 1524 1999 ; FIXME: no Feb. 29
1521 year))) 1525 year)))
1522 (calendar-last-day-of-month month yr)))) 1526 (calendar-last-day-of-month month yr))))
1523 day dayname) 1527 (day (let (x)
1524 (while (if (numberp day) (or (< day 0) (< last day)) (not (eq day '*))) 1528 (while (if (numberp x) (or (< x 0) (< last x)) (not (eq x '*)))
1525 (setq day (read-from-minibuffer 1529 (setq x (read-from-minibuffer
1526 (format "Day (1-%d or RET for today or * for any day): " last) 1530 (format
1527 nil nil t nil 1531 "Day (1-%d or RET for today or * for any day): "
1528 (number-to-string 1532 last) nil nil t nil (number-to-string
1529 (calendar-extract-day (calendar-current-date)))))) 1533 (calendar-extract-day
1534 (calendar-current-date))))))
1535 x))
1536 dayname) ; Needed by calendar-date-display-form.
1530 (setq year (if (eq year '*) (symbol-name '*) (number-to-string year))) 1537 (setq year (if (eq year '*) (symbol-name '*) (number-to-string year)))
1531 (setq day (if (eq day '*) (symbol-name '*) (number-to-string day))) 1538 (setq day (if (eq day '*) (symbol-name '*) (number-to-string day)))
1532 ;; FIXME: make abbreviation customizable 1539 ;; FIXME: make abbreviation customizable
@@ -1563,13 +1570,13 @@ the empty string (i.e., no time string)."
1563;; --------------------------------------------------------------------------- 1570;; ---------------------------------------------------------------------------
1564;;; Item filtering 1571;;; Item filtering
1565 1572
1566(defvar todos-multiple-files nil 1573(defvar todos-multiple-filter-files nil
1567 "List of files selected from `todos-multiple-files' widget.") 1574 "List of files selected from `todos-multiple-filter-files' widget.")
1568 1575
1569(defvar todos-multiple-files-widget nil 1576(defvar todos-multiple-filter-files-widget nil
1570 "Variable holding widget created by `todos-multiple-files'.") 1577 "Variable holding widget created by `todos-multiple-filter-files'.")
1571 1578
1572(defun todos-multiple-files () 1579(defun todos-multiple-filter-files ()
1573 "Pop to a buffer with a widget for choosing multiple filter files." 1580 "Pop to a buffer with a widget for choosing multiple filter files."
1574 (require 'widget) 1581 (require 'widget)
1575 (eval-when-compile 1582 (eval-when-compile
@@ -1579,7 +1586,7 @@ the empty string (i.e., no time string)."
1579 (erase-buffer) 1586 (erase-buffer)
1580 (kill-all-local-variables) 1587 (kill-all-local-variables)
1581 (widget-insert "Select files for generating the top priorities list.\n\n") 1588 (widget-insert "Select files for generating the top priorities list.\n\n")
1582 (setq todos-multiple-files-widget 1589 (setq todos-multiple-filter-files-widget
1583 (widget-create 1590 (widget-create
1584 `(set ,@(mapcar (lambda (x) (list 'const x)) 1591 `(set ,@(mapcar (lambda (x) (list 'const x))
1585 (mapcar 'todos-short-file-name 1592 (mapcar 'todos-short-file-name
@@ -1587,19 +1594,19 @@ the empty string (i.e., no time string)."
1587 (widget-insert "\n") 1594 (widget-insert "\n")
1588 (widget-create 'push-button 1595 (widget-create 'push-button
1589 :notify (lambda (widget &rest ignore) 1596 :notify (lambda (widget &rest ignore)
1590 (setq todos-multiple-files 'quit) 1597 (setq todos-multiple-filter-files 'quit)
1591 (quit-window t) 1598 (quit-window t)
1592 (exit-recursive-edit)) 1599 (exit-recursive-edit))
1593 "Cancel") 1600 "Cancel")
1594 (widget-insert " ") 1601 (widget-insert " ")
1595 (widget-create 'push-button 1602 (widget-create 'push-button
1596 :notify (lambda (&rest ignore) 1603 :notify (lambda (&rest ignore)
1597 (setq todos-multiple-files 1604 (setq todos-multiple-filter-files
1598 (mapcar (lambda (f) 1605 (mapcar (lambda (f)
1599 (concat todos-files-directory 1606 (concat todos-files-directory
1600 f ".todo")) 1607 f ".todo"))
1601 (widget-value 1608 (widget-value
1602 todos-multiple-files-widget))) 1609 todos-multiple-filter-files-widget)))
1603 (quit-window t) 1610 (quit-window t)
1604 (exit-recursive-edit)) 1611 (exit-recursive-edit))
1605 "Apply") 1612 "Apply")
@@ -1624,12 +1631,13 @@ Todos files, by default those in `todos-filter-files'."
1624 (files (list todos-current-todos-file)) 1631 (files (list todos-current-todos-file))
1625 regexp fname bufstr cat beg end done) 1632 regexp fname bufstr cat beg end done)
1626 (when multifile 1633 (when multifile
1627 (setq files (or todos-multiple-files ; Passed from todos-*-multifile. 1634 (setq files (or todos-multiple-filter-files ; Passed from todos-*-multifile.
1628 (if (or (consp filter) 1635 (if (or (consp filter)
1629 (null todos-filter-files)) 1636 (null todos-filter-files))
1630 (progn (todos-multiple-files) todos-multiple-files) 1637 (progn (todos-multiple-filter-files)
1638 todos-multiple-filter-files)
1631 todos-filter-files)) 1639 todos-filter-files))
1632 todos-multiple-files nil)) 1640 todos-multiple-filter-files nil))
1633 (if (eq files 'quit) (keyboard-quit)) 1641 (if (eq files 'quit) (keyboard-quit))
1634 (if (null files) 1642 (if (null files)
1635 (error "No files have been chosen for filtering") 1643 (error "No files have been chosen for filtering")
@@ -1678,8 +1686,9 @@ Todos files, by default those in `todos-filter-files'."
1678 (delete-region (line-beginning-position) (1+ (line-end-position))) 1686 (delete-region (line-beginning-position) (1+ (line-end-position)))
1679 (let (fnum) 1687 (let (fnum)
1680 ;; Unless the number of items to show was supplied by prefix 1688 ;; Unless the number of items to show was supplied by prefix
1681 ;; argument of caller, override `todos-show-priorities' with the 1689 ;; argument of caller, the file-wide value from
1682 ;; file-wide value from `todos-priorities-rules'. 1690 ;; `todos-priorities-rules', if non-nil, overrides
1691 ;; `todos-show-priorities'.
1683 (unless (consp filter) 1692 (unless (consp filter)
1684 (setq fnum (nth 1 (assoc f todos-priorities-rules)))) 1693 (setq fnum (nth 1 (assoc f todos-priorities-rules))))
1685 (while (re-search-forward 1694 (while (re-search-forward
@@ -1688,16 +1697,13 @@ Todos files, by default those in `todos-filter-files'."
1688 (setq cat (match-string 1)) 1697 (setq cat (match-string 1))
1689 (let (cnum) 1698 (let (cnum)
1690 ;; Unless the number of items to show was supplied by prefix 1699 ;; Unless the number of items to show was supplied by prefix
1691 ;; argument of caller, override the file-wide value from 1700 ;; argument of caller, the category-wide value from
1692 ;; `todos-priorities-rules' if set, else 1701 ;; `todos-priorities-rules', if non-nil, overrides a non-nil
1693 ;; `todos-show-priorities' with non-nil category-wide value 1702 ;; file-wide value from `todos-priorities-rules' as well as
1694 ;; from `todos-priorities-rules'. 1703 ;; `todos-show-priorities'.
1695 (unless (consp filter) 1704 (unless (consp filter)
1696 (let ((cats (nth 2 (assoc f todos-priorities-rules)))) 1705 (let ((cats (nth 2 (assoc f todos-priorities-rules))))
1697 (setq cnum (or (cdr (assoc cat cats)) 1706 (setq cnum (or (cdr (assoc cat cats)) fnum))))
1698 fnum
1699 ;; FIXME: need this?
1700 todos-show-priorities))))
1701 (delete-region (match-beginning 0) (match-end 0)) 1707 (delete-region (match-beginning 0) (match-end 0))
1702 (setq beg (point)) ; First item in the current category. 1708 (setq beg (point)) ; First item in the current category.
1703 (setq end (if (re-search-forward 1709 (setq end (if (re-search-forward
@@ -1873,6 +1879,8 @@ option `todos-categories-align'."
1873 (fn (if (eq key 'alpha) 1879 (fn (if (eq key 'alpha)
1874 (lambda (x) (upcase x)) ; Alphabetize case insensitively. 1880 (lambda (x) (upcase x)) ; Alphabetize case insensitively.
1875 (lambda (x) (todos-get-count key x)))) 1881 (lambda (x) (todos-get-count key x))))
1882 ;; Keep track of whether the last sort by key was descending or
1883 ;; ascending.
1876 (descending (member key todos-descending-counts)) 1884 (descending (member key todos-descending-counts))
1877 (cmp (if (eq key 'alpha) 1885 (cmp (if (eq key 'alpha)
1878 'string< 1886 'string<
@@ -1882,6 +1890,7 @@ option `todos-categories-align'."
1882 (funcall cmp t1 t2))))) 1890 (funcall cmp t1 t2)))))
1883 (when key 1891 (when key
1884 (setq l (sort l pred)) 1892 (setq l (sort l pred))
1893 ;; Switch between descending and ascending sort order.
1885 (if descending 1894 (if descending
1886 (setq todos-descending-counts 1895 (setq todos-descending-counts
1887 (delete key todos-descending-counts)) 1896 (delete key todos-descending-counts))
@@ -1925,7 +1934,7 @@ LABEL determines which type of count is sorted."
1925 (eq key 'alpha)) 1934 (eq key 'alpha))
1926 (progn 1935 (progn
1927 ;; If display is alphabetical, switch back to 1936 ;; If display is alphabetical, switch back to
1928 ;; category order. 1937 ;; category priority order.
1929 (todos-display-sorted nil) 1938 (todos-display-sorted nil)
1930 (setq todos-descending-counts 1939 (setq todos-descending-counts
1931 (delete key todos-descending-counts))) 1940 (delete key todos-descending-counts)))
@@ -1974,7 +1983,8 @@ which is the value of the user option
1974 (cons todos-categories-done-label 'done) 1983 (cons todos-categories-done-label 'done)
1975 (cons todos-categories-archived-label 1984 (cons todos-categories-archived-label
1976 'archived))) 1985 'archived)))
1977 "")) 1986 "")
1987 " ") ; So highlighting of last column is consistent with the others.
1978 'face (if (and todos-skip-archived-categories 1988 'face (if (and todos-skip-archived-categories
1979 (zerop (todos-get-count 'todo cat)) 1989 (zerop (todos-get-count 'todo cat))
1980 (zerop (todos-get-count 'done cat)) 1990 (zerop (todos-get-count 'done cat))
@@ -1985,7 +1995,7 @@ which is the value of the user option
1985 (todos-jump-to-category ,cat) 1995 (todos-jump-to-category ,cat)
1986 (kill-buffer buf)))) 1996 (kill-buffer buf))))
1987 ;; Highlight the sorted count column. 1997 ;; Highlight the sorted count column.
1988 (let* ((beg (+ opoint 6 (length str))) 1998 (let* ((beg (+ opoint 7 (length str)))
1989 end ovl) 1999 end ovl)
1990 (cond ((eq nonum 'todo) 2000 (cond ((eq nonum 'todo)
1991 (setq beg (+ beg 1 (/ (length todos-categories-todo-label) 2)))) 2001 (setq beg (+ beg 1 (/ (length todos-categories-todo-label) 2))))
@@ -2001,7 +2011,7 @@ which is the value of the user option
2001 2 (length todos-categories-diary-label) 2011 2 (length todos-categories-diary-label)
2002 2 (length todos-categories-done-label) 2012 2 (length todos-categories-done-label)
2003 2 (/ (length todos-categories-archived-label) 2))))) 2013 2 (/ (length todos-categories-archived-label) 2)))))
2004 (unless (= beg (+ opoint 6 (length str))) 2014 (unless (= beg (+ opoint 7 (length str))) ; Don't highlight categories.
2005 (setq end (+ beg 4)) 2015 (setq end (+ beg 4))
2006 (setq ovl (make-overlay beg end)) 2016 (setq ovl (make-overlay beg end))
2007 (overlay-put ovl 'face 'todos-sorted-column))) 2017 (overlay-put ovl 'face 'todos-sorted-column)))
@@ -2244,7 +2254,6 @@ which is the value of the user option
2244;; --------------------------------------------------------------------------- 2254;; ---------------------------------------------------------------------------
2245;;; Key maps and menus 2255;;; Key maps and menus
2246 2256
2247;; ??FIXME: use easy-mmode-define-keymap and easy-mmode-defmap
2248(defvar todos-key-bindings 2257(defvar todos-key-bindings
2249 `( 2258 `(
2250 ;; display 2259 ;; display
@@ -2263,7 +2272,6 @@ which is the value of the user option
2263 ("As" . todos-show-archive) 2272 ("As" . todos-show-archive)
2264 ("Ac" . todos-choose-archive) 2273 ("Ac" . todos-choose-archive)
2265 ("Y" . todos-diary-items) 2274 ("Y" . todos-diary-items)
2266 ;;("" . todos-update-filter-files)
2267 ("Fe" . todos-edit-multiline) 2275 ("Fe" . todos-edit-multiline)
2268 ("Fh" . todos-highlight-item) 2276 ("Fh" . todos-highlight-item)
2269 ("Fn" . todos-hide-show-item-numbering) 2277 ("Fn" . todos-hide-show-item-numbering)
@@ -2276,7 +2284,6 @@ which is the value of the user option
2276 ("Fym" . todos-diary-items-multifile) 2284 ("Fym" . todos-diary-items-multifile)
2277 ("Fxx" . todos-regexp-items) 2285 ("Fxx" . todos-regexp-items)
2278 ("Fxm" . todos-regexp-items-multifile) 2286 ("Fxm" . todos-regexp-items-multifile)
2279 ;;("" . todos-save-top-priorities)
2280 ;; navigation 2287 ;; navigation
2281 ("f" . todos-forward-category) 2288 ("f" . todos-forward-category)
2282 ("b" . todos-backward-category) 2289 ("b" . todos-backward-category)
@@ -2311,18 +2318,12 @@ which is the value of the user option
2311 ("k" . todos-delete-item) ;FIXME: not single letter? 2318 ("k" . todos-delete-item) ;FIXME: not single letter?
2312 ("m" . todos-move-item) 2319 ("m" . todos-move-item)
2313 ("M" . todos-move-item-to-file) 2320 ("M" . todos-move-item-to-file)
2314 ;; FIXME: This binding prevents `-' from being used in a numerical prefix
2315 ;; argument without typing C-u
2316 ;; ("-" . todos-raise-item-priority)
2317 ("r" . todos-raise-item-priority) 2321 ("r" . todos-raise-item-priority)
2318 ;; ("+" . todos-lower-item-priority)
2319 ("l" . todos-lower-item-priority) 2322 ("l" . todos-lower-item-priority)
2320 ("#" . todos-set-item-priority) 2323 ("#" . todos-set-item-priority)
2321 ("u" . todos-item-undo) 2324 ("u" . todos-item-undo)
2322 ("Ad" . todos-archive-done-item) ;FIXME: ad 2325 ("Ad" . todos-archive-done-item) ;FIXME: ad
2323 ("AD" . todos-archive-category-done-items) ;FIXME: aD or C-u ad ? 2326 ("AD" . todos-archive-category-done-items) ;FIXME: aD or C-u ad ?
2324 ;; ("Au" . todos-unarchive-items) ;FIXME: not in todos-mode!
2325 ;; ("AU" . todos-unarchive-category) ;FIXME: not in todos-mode!
2326 ("s" . todos-save) 2327 ("s" . todos-save)
2327 ("q" . todos-quit) 2328 ("q" . todos-quit)
2328 ([remap newline] . newline-and-indent) 2329 ([remap newline] . newline-and-indent)
@@ -2393,7 +2394,7 @@ which is the value of the user option
2393 ["Rename Current Category" todos-rename-category t] 2394 ["Rename Current Category" todos-rename-category t]
2394 "---" 2395 "---"
2395 ["Save Todos File" todos-save t] 2396 ["Save Todos File" todos-save t]
2396 ["Save Top Priorities" todos-save-top-priorities t]) 2397 )
2397 "---" 2398 "---"
2398 ["Quit" todos-quit t] 2399 ["Quit" todos-quit t]
2399 )) 2400 ))
@@ -2432,8 +2433,11 @@ which is the value of the user option
2432(defvar todos-categories-mode-map 2433(defvar todos-categories-mode-map
2433 (let ((map (make-sparse-keymap))) 2434 (let ((map (make-sparse-keymap)))
2434 (suppress-keymap map t) 2435 (suppress-keymap map t)
2435 ;; (define-key map "a" 'todos-display-categories-alphabetically) 2436 (define-key map "c" 'todos-display-categories-alphabetically-or-by-priority)
2436 (define-key map "c" 'todos-display-categories) 2437 (define-key map "t" 'todos-display-categories-sorted-by-todo)
2438 (define-key map "y" 'todos-display-categories-sorted-by-diary)
2439 (define-key map "d" 'todos-display-categories-sorted-by-done)
2440 (define-key map "a" 'todos-display-categories-sorted-by-archived)
2437 (define-key map "l" 'todos-lower-category-priority) 2441 (define-key map "l" 'todos-lower-category-priority)
2438 (define-key map "+" 'todos-lower-category-priority) 2442 (define-key map "+" 'todos-lower-category-priority)
2439 (define-key map "r" 'todos-raise-category-priority) 2443 (define-key map "r" 'todos-raise-category-priority)
@@ -2463,7 +2467,6 @@ which is the value of the user option
2463 (define-key map "P" 'todos-print) 2467 (define-key map "P" 'todos-print)
2464 (define-key map "q" 'todos-quit) 2468 (define-key map "q" 'todos-quit)
2465 (define-key map "s" 'todos-save) 2469 (define-key map "s" 'todos-save)
2466 ;; (define-key map "S" 'todos-save-top-priorities)
2467 ;; editing commands 2470 ;; editing commands
2468 (define-key map "l" 'todos-lower-item-priority) 2471 (define-key map "l" 'todos-lower-item-priority)
2469 (define-key map "r" 'todos-raise-item-priority) 2472 (define-key map "r" 'todos-raise-item-priority)
@@ -2496,7 +2499,7 @@ which is the value of the user option
2496 2499
2497(put 'todos-mode 'mode-class 'special) 2500(put 'todos-mode 'mode-class 'special)
2498 2501
2499;; Autoloading isn't needed if files are identified by auto-mode-alist 2502;; FIXME: Autoloading isn't needed if files are identified by auto-mode-alist
2500;; ;; As calendar reads included Todos file before todos-mode is loaded. 2503;; ;; As calendar reads included Todos file before todos-mode is loaded.
2501;; ;;;###autoload 2504;; ;;;###autoload
2502(define-derived-mode todos-mode special-mode "Todos" () 2505(define-derived-mode todos-mode special-mode "Todos" ()
@@ -2558,8 +2561,8 @@ which is the value of the user option
2558 "" 2561 ""
2559 (set (make-local-variable 'todos-current-todos-file) 2562 (set (make-local-variable 'todos-current-todos-file)
2560 todos-global-current-todos-file) 2563 todos-global-current-todos-file)
2561 (let ((cats (with-current-buffer (find-buffer-visiting todos-current-todos-file) 2564 (let ((cats (with-current-buffer
2562 ;; FIXME: or (todos-set-categories)? 2565 (find-buffer-visiting todos-current-todos-file)
2563 todos-categories))) 2566 todos-categories)))
2564 (set (make-local-variable 'todos-categories) cats))) 2567 (set (make-local-variable 'todos-categories) cats)))
2565 2568
@@ -2596,13 +2599,15 @@ which is the value of the user option
2596;;;###autoload 2599;;;###autoload
2597(defun todos-show (&optional solicit-file) 2600(defun todos-show (&optional solicit-file)
2598 "Visit the current Todos file and display one of its categories. 2601 "Visit the current Todos file and display one of its categories.
2602With non-nil prefix argument SOLICIT-FILE prompt for which todo
2603file to visit.
2599 2604
2600With non-nil prefix argument SOLICIT-FILE ask for file to visit. 2605Without a prefix argument, the first invocation of this command
2601Otherwise, the first invocation of this command in a session 2606in a session visits `todos-default-todos-file' (creating it if it
2602visits `todos-default-todos-file' (creating it if it does not yet 2607does not yet exist); subsequent invocations from outside of Todos
2603exist); subsequent invocations from outside of Todos mode revisit 2608mode revisit this file or, if the user option
2604this file or, if user option `todos-show-current-file' is 2609`todos-show-current-file' is non-nil, whichever Todos file
2605non-nil, whichever Todos file was visited last. 2610\(either a todo or an archive file) was visited last.
2606 2611
2607The category displayed on initial invocation is the first member 2612The category displayed on initial invocation is the first member
2608of `todos-categories' for the current Todos file, on subsequent 2613of `todos-categories' for the current Todos file, on subsequent
@@ -2634,10 +2639,6 @@ corresponding Todos file, displaying the corresponding category."
2634 (concat (file-name-sans-extension todos-current-todos-file) 2639 (concat (file-name-sans-extension todos-current-todos-file)
2635 ".todo")) 2640 ".todo"))
2636 (t 2641 (t
2637 ;; FIXME: If todos-current-todos-file is an archive,
2638 ;; todos-show will revisit it rather than the
2639 ;; corresponding todo file -- ok or make it
2640 ;; customizable?
2641 (or todos-current-todos-file 2642 (or todos-current-todos-file
2642 (and todos-show-current-file 2643 (and todos-show-current-file
2643 todos-global-current-todos-file) 2644 todos-global-current-todos-file)
@@ -2688,33 +2689,50 @@ are shown in `todos-archived-only' face."
2688 (let (sortkey) 2689 (let (sortkey)
2689 (todos-update-categories-display sortkey))) 2690 (todos-update-categories-display sortkey)))
2690 2691
2691;; FIXME: provide key bindings for these or delete them 2692(defun todos-display-categories-alphabetically-or-by-priority ()
2692 2693 ""
2693;; ;; FIXME: make this toggle with todos-display-categories 2694 (interactive)
2694;; (defun todos-display-categories-alphabetically () 2695 (save-excursion
2695;; "" 2696 (goto-char (point-min))
2696;; (interactive) 2697 (forward-line 2)
2697;; (todos-display-sorted 'alpha)) 2698 (if (member 'alpha todos-descending-counts)
2699 (progn
2700 (todos-update-categories-display nil)
2701 (setq todos-descending-counts
2702 (delete 'alpha todos-descending-counts)))
2703 (todos-update-categories-display 'alpha))))
2698 2704
2699;; (defun todos-display-categories-sorted-by-todo () 2705(defun todos-display-categories-sorted-by-todo ()
2700;; "" 2706 ""
2701;; (interactive) 2707 (interactive)
2702;; (todos-display-sorted 'todo)) 2708 (save-excursion
2709 (goto-char (point-min))
2710 (forward-line 2)
2711 (todos-update-categories-display 'todo)))
2703 2712
2704;; (defun todos-display-categories-sorted-by-diary () 2713(defun todos-display-categories-sorted-by-diary ()
2705;; "" 2714 ""
2706;; (interactive) 2715 (interactive)
2707;; (todos-display-sorted 'diary)) 2716 (save-excursion
2717 (goto-char (point-min))
2718 (forward-line 2)
2719 (todos-update-categories-display 'diary)))
2708 2720
2709;; (defun todos-display-categories-sorted-by-done () 2721(defun todos-display-categories-sorted-by-done ()
2710;; "" 2722 ""
2711;; (interactive) 2723 (interactive)
2712;; (todos-display-sorted 'done)) 2724 (save-excursion
2725 (goto-char (point-min))
2726 (forward-line 2)
2727 (todos-update-categories-display 'done)))
2713 2728
2714;; (defun todos-display-categories-sorted-by-archived () 2729(defun todos-display-categories-sorted-by-archived ()
2715;; "" 2730 ""
2716;; (interactive) 2731 (interactive)
2717;; (todos-display-sorted 'archived)) 2732 (save-excursion
2733 (goto-char (point-min))
2734 (forward-line 2)
2735 (todos-update-categories-display 'archived)))
2718 2736
2719(defun todos-show-archive (&optional ask) 2737(defun todos-show-archive (&optional ask)
2720 "Visit the archive of the current Todos category, if it exists. 2738 "Visit the archive of the current Todos category, if it exists.
@@ -2761,9 +2779,7 @@ displayed."
2761(defun todos-save () 2779(defun todos-save ()
2762 "Save the current Todos file." 2780 "Save the current Todos file."
2763 (interactive) 2781 (interactive)
2764 (save-buffer) 2782 (save-buffer))
2765 ;; (if todos-save-top-priorities-too (todos-save-top-priorities))
2766 )
2767 2783
2768(defun todos-quit () 2784(defun todos-quit ()
2769 "Exit the current Todos-related buffer. 2785 "Exit the current Todos-related buffer.
@@ -3382,8 +3398,8 @@ list in each category."
3382 (cons 'top arg) 3398 (cons 'top arg)
3383 (setq files (if (or (consp arg) 3399 (setq files (if (or (consp arg)
3384 (null todos-filter-files)) 3400 (null todos-filter-files))
3385 (progn (todos-multiple-files) 3401 (progn (todos-multiple-filter-files)
3386 todos-multiple-files) 3402 todos-multiple-filter-files)
3387 todos-filter-files)) 3403 todos-filter-files))
3388 (if (equal arg '(16)) 3404 (if (equal arg '(16))
3389 (cons 'top (read-number 3405 (cons 'top (read-number
@@ -3407,8 +3423,8 @@ The files are those listed in `todos-filter-files'."
3407 (interactive "P") 3423 (interactive "P")
3408 (let ((buf todos-diary-items-buffer) 3424 (let ((buf todos-diary-items-buffer)
3409 (files (if (or arg (null todos-filter-files)) 3425 (files (if (or arg (null todos-filter-files))
3410 (progn (todos-multiple-files) 3426 (progn (todos-multiple-filter-files)
3411 todos-multiple-files) 3427 todos-multiple-filter-files)
3412 todos-filter-files))) 3428 todos-filter-files)))
3413 (todos-filter-items 'diary t) 3429 (todos-filter-items 'diary t)
3414 (todos-filtered-buffer-name buf files))) 3430 (todos-filtered-buffer-name buf files)))
@@ -3428,8 +3444,8 @@ The items are those in the files listed in `todos-filter-files'."
3428 (interactive "P") 3444 (interactive "P")
3429 (let ((buf todos-regexp-items-buffer) 3445 (let ((buf todos-regexp-items-buffer)
3430 (files (if (or arg (null todos-filter-files)) 3446 (files (if (or arg (null todos-filter-files))
3431 (progn (todos-multiple-files) 3447 (progn (todos-multiple-filter-files)
3432 todos-multiple-files) 3448 todos-multiple-filter-files)
3433 todos-filter-files))) 3449 todos-filter-files)))
3434 (todos-filter-items 'regexp t) 3450 (todos-filter-items 'regexp t)
3435 (todos-filtered-buffer-name buf files))) 3451 (todos-filtered-buffer-name buf files)))
@@ -4665,6 +4681,7 @@ With prefix ARG delete an existing comment."
4665 (todos-item-end) 4681 (todos-item-end)
4666 (insert " [" todos-comment-string ": " comment "]")))))) 4682 (insert " [" todos-comment-string ": " comment "]"))))))
4667 4683
4684;; FIXME: also with marked items
4668;; FIXME: delete comment from restored item or just leave it up to user? 4685;; FIXME: delete comment from restored item or just leave it up to user?
4669(defun todos-item-undo () 4686(defun todos-item-undo ()
4670 "Restore this done item to the todo section of this category. 4687 "Restore this done item to the todo section of this category.
@@ -4676,7 +4693,7 @@ the restored item."
4676 (done-item (todos-item-string)) 4693 (done-item (todos-item-string))
4677 (opoint (point)) 4694 (opoint (point))
4678 (orig-mrk (progn (todos-item-start) (point-marker))) 4695 (orig-mrk (progn (todos-item-start) (point-marker)))
4679 ;; Find the end of the date string added upon marking item as done. 4696 ;; Find the end of the date string added upon tagging item as done.
4680 (start (search-forward "] ")) 4697 (start (search-forward "] "))
4681 item undone) 4698 item undone)
4682 (todos-item-start) 4699 (todos-item-start)