aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Berman2013-05-14 23:52:19 +0200
committerStephen Berman2013-05-14 23:52:19 +0200
commit04c9cdf7e8d959032ab98893cf330a3d8da46e70 (patch)
treea8bca66f660fb46b5577f510e46feab6e780be67
parent199b0d390421502bbf5cf98d850178a6b9f433d8 (diff)
downloademacs-04c9cdf7e8d959032ab98893cf330a3d8da46e70.tar.gz
emacs-04c9cdf7e8d959032ab98893cf330a3d8da46e70.zip
* todos.el: Improve handling of jumping to a category, in
particular that of an archive. (todos-category-completions): Add optional parameter to restrict completions of archive categories to current archive. Exclude archive from completion files. (todos-read-category): When called from an archive, restrict category completions to the archive. Fix mistaken use of all completion files instead of just those in which the chosen category occurs. (todos-archive-mode-map): Add new key binding. (todos-jump-to-category): Rename second optional parameter and extend its use to restricting category completions to the current archive. (todos-jump-to-archive-category): New command.
-rw-r--r--lisp/calendar/ChangeLog17
-rw-r--r--lisp/calendar/todos.el98
2 files changed, 79 insertions, 36 deletions
diff --git a/lisp/calendar/ChangeLog b/lisp/calendar/ChangeLog
index 6767b97a26f..8206f7071b2 100644
--- a/lisp/calendar/ChangeLog
+++ b/lisp/calendar/ChangeLog
@@ -1,3 +1,20 @@
12013-05-14 Stephen Berman <stephen.berman@gmx.net>
2
3 * todos.el: Improve handling of jumping to a category, in
4 particular that of an archive.
5 (todos-category-completions): Add optional parameter to restrict
6 completions of archive categories to current archive. Exclude
7 archive from completion files.
8 (todos-read-category): When called from an archive, restrict
9 category completions to the archive. Fix mistaken use of all
10 completion files instead of just those in which the chosen
11 category occurs.
12 (todos-archive-mode-map): Add new key binding.
13 (todos-jump-to-category): Rename second optional parameter and
14 extend its use to restricting category completions to the current
15 archive.
16 (todos-jump-to-archive-category): New command.
17
12013-05-13 Stephen Berman <stephen.berman@gmx.net> 182013-05-13 Stephen Berman <stephen.berman@gmx.net>
2 19
3 * todos.el (todos-modes-set-2): Restore point after finding start 20 * todos.el (todos-modes-set-2): Restore point after finding start
diff --git a/lisp/calendar/todos.el b/lisp/calendar/todos.el
index 91470a38cf8..822f9ba5586 100644
--- a/lisp/calendar/todos.el
+++ b/lisp/calendar/todos.el
@@ -1185,23 +1185,26 @@ done items are shown. Its value is determined by user option
1185 (overlay-put new-ov 'display todos-done-separator) 1185 (overlay-put new-ov 'display todos-done-separator)
1186 (delete-overlay ov)))))))) 1186 (delete-overlay ov))))))))
1187 1187
1188(defun todos-category-completions () 1188(defun todos-category-completions (&optional archive)
1189 "Return a list of completions for `todos-read-category'. 1189 "Return a list of completions for `todos-read-category'.
1190Each element of the list is a cons of a category name and the 1190Each element of the list is a cons of a category name and the
1191file or list of files (as short file names) it is in. The files 1191file or list of files (as short file names) it is in. The files
1192are the current (or else the default) Todos file plus all other 1192are either the current (or if there is none, the default) todo
1193Todos files named in `todos-category-completions-files'." 1193file plus the files listed in `todos-category-completions-files',
1194or, with non-nil ARCHIVE, the current archive file."
1194 (let* ((curfile (or todos-current-todos-file 1195 (let* ((curfile (or todos-current-todos-file
1195 (and todos-show-current-file 1196 (and todos-show-current-file
1196 todos-global-current-todos-file) 1197 todos-global-current-todos-file)
1197 (todos-absolute-file-name todos-default-todos-file))) 1198 (todos-absolute-file-name todos-default-todos-file)))
1198 (files (or (mapcar 'todos-absolute-file-name 1199 (files (or (unless archive
1199 todos-category-completions-files) 1200 (mapcar 'todos-absolute-file-name
1201 todos-category-completions-files))
1200 (list curfile))) 1202 (list curfile)))
1201 listall listf) 1203 listall listf)
1202 ;; If file was just added, it has no category completions. 1204 ;; If file was just added, it has no category completions.
1203 (unless (zerop (buffer-size (find-buffer-visiting curfile))) 1205 (unless (zerop (buffer-size (find-buffer-visiting curfile)))
1204 (add-to-list 'files curfile) 1206 (unless (member curfile todos-archives)
1207 (add-to-list 'files curfile))
1205 (dolist (f files listall) 1208 (dolist (f files listall)
1206 (with-current-buffer (find-file-noselect f 'nowarn) 1209 (with-current-buffer (find-file-noselect f 'nowarn)
1207 ;; Ensure category is properly displayed in case user 1210 ;; Ensure category is properly displayed in case user
@@ -1663,10 +1666,11 @@ otherwise, a new file name is allowed."
1663Show completions for existing categories with TAB or SPC. 1666Show completions for existing categories with TAB or SPC.
1664 1667
1665The argument MATCH-TYPE specifies the matching requirements on 1668The argument MATCH-TYPE specifies the matching requirements on
1666the category name: with the value `merge' the name must complete 1669the category name: with the value `todo' or `archive' the name
1667to that of an existing category; with the value `add' the name 1670must complete to that of an existing todo or archive category,
1668must not be that of an existing category; with all other values 1671respectively; with the value `add' the name must not be that of
1669both existing and new valid category names are accepted. 1672an existing category; with all other values both existing and new
1673valid category names are accepted.
1670 1674
1671With non-nil argument FILE prompt for a file and complete only 1675With non-nil argument FILE prompt for a file and complete only
1672against categories in that file; otherwise complete against all 1676against categories in that file; otherwise complete against all
@@ -1675,9 +1679,13 @@ categories from `todos-category-completions-files'."
1675 (let ((map minibuffer-local-completion-map)) 1679 (let ((map minibuffer-local-completion-map))
1676 (define-key map " " nil) 1680 (define-key map " " nil)
1677 (let* ((add (eq match-type 'add)) 1681 (let* ((add (eq match-type 'add))
1682 (archive (eq match-type 'archive))
1678 (file0 (when (and file (> (length todos-files) 1)) 1683 (file0 (when (and file (> (length todos-files) 1))
1679 (todos-read-file-name "Choose a Todos file: " nil t))) 1684 (todos-read-file-name (concat "Choose a" (if archive
1680 (completions (unless file0 (todos-category-completions))) 1685 "n archive"
1686 " todo")
1687 " file: ") archive t)))
1688 (completions (unless file0 (todos-category-completions archive)))
1681 (categories (cond (file0 1689 (categories (cond (file0
1682 (with-current-buffer 1690 (with-current-buffer
1683 (find-file-noselect file0 'nowarn) 1691 (find-file-noselect file0 'nowarn)
@@ -1716,8 +1724,8 @@ categories from `todos-category-completions-files'."
1716 (if (atom catfil) 1724 (if (atom catfil)
1717 catfil 1725 catfil
1718 (todos-absolute-file-name 1726 (todos-absolute-file-name
1719 (completing-read (format str cat) 1727 (let ((files (mapcar 'todos-short-file-name catfil)))
1720 todos-category-completions-files)))))) 1728 (completing-read (format str cat) files)))))))
1721 ;; Default to the current file. 1729 ;; Default to the current file.
1722 (unless file0 (setq file0 todos-current-todos-file)) 1730 (unless file0 (setq file0 todos-current-todos-file))
1723 ;; First validate only a name passed interactively from 1731 ;; First validate only a name passed interactively from
@@ -2916,6 +2924,7 @@ which is the value of the user option
2916 (define-key map "PF" 'todos-print-buffer-to-file) 2924 (define-key map "PF" 'todos-print-buffer-to-file)
2917 (define-key map "S" 'todos-search) 2925 (define-key map "S" 'todos-search)
2918 (define-key map "X" 'todos-clear-matches) 2926 (define-key map "X" 'todos-clear-matches)
2927 (define-key map "a" 'todos-jump-to-archive-category)
2919 (define-key map "b" 'todos-backward-category) 2928 (define-key map "b" 'todos-backward-category)
2920 (define-key map "f" 'todos-forward-category) 2929 (define-key map "f" 'todos-forward-category)
2921 (define-key map "j" 'todos-jump-to-category) 2930 (define-key map "j" 'todos-jump-to-category)
@@ -3581,39 +3590,48 @@ category."
3581 (todos-forward-category t)) 3590 (todos-forward-category t))
3582 3591
3583;;;###autoload 3592;;;###autoload
3584(defun todos-jump-to-category (&optional file cat) 3593(defun todos-jump-to-category (&optional file where)
3585 "Prompt for a category in a Todos file and jump to it. 3594 "Prompt for a category in a Todos file and jump to it.
3586 3595
3587With prefix argument FILE, prompt for a specific Todos file and 3596With non-nil FILE (interactively a prefix argument), prompt for a
3588choose (with TAB completion) a category in it to jump to; 3597specific Todos file and choose (with TAB completion) a category
3589otherwise, choose and jump to any category in either the current 3598in it to jump to; otherwise, choose and jump to any category in
3590Todos file or a file in `todos-category-completions-files'. 3599either the current Todos file or a file in
3600`todos-category-completions-files'.
3591 3601
3592You can also enter a non-existing category name, triggering a 3602You can also enter a non-existing category name, triggering a
3593prompt whether to add a new category by that name; on 3603prompt whether to add a new category by that name; on
3594confirmation it is added and jumped to. 3604confirmation it is added and you jump to that category.
3595 3605
3596Noninteractively, jump directly to the category named by argument 3606In noninteractive calls non-nil WHERE specifies either the goal
3597CAT; this is used in Todos Categories mode." 3607category or its file. If its value is `archive', the choice of
3608categories is restricted to the current archive file or the
3609archive you were prompted to choose; this is used by
3610`todos-jump-to-archive-category'. If its value is the name of a
3611category, jump directly to that category; this is used in Todos
3612Categories mode."
3598 (interactive "P") 3613 (interactive "P")
3599 ;; If invoked outside of Todos mode and there is not yet any Todos 3614 ;; If invoked outside of Todos mode and there is not yet any Todos
3600 ;; file, initialize one. 3615 ;; file, initialize one.
3601 (if (null todos-files) 3616 (if (null todos-files)
3602 (todos-show) 3617 (todos-show)
3603 (let ((file0 (when cat ; We're in Todos Categories mode. 3618 (let* ((archive (eq where 'archive))
3604 ;; With non-nil `todos-skip-archived-categories' 3619 (cat (unless archive noninteractive))
3605 ;; jump to archive file of a category with only 3620 (file0 (when cat ; We're in Todos Categories mode.
3606 ;; archived items. 3621 ;; With non-nil `todos-skip-archived-categories'
3607 (if (and todos-skip-archived-categories 3622 ;; jump to archive file of a category with only
3608 (zerop (todos-get-count 'todo cat)) 3623 ;; archived items.
3609 (zerop (todos-get-count 'done cat)) 3624 (if (and todos-skip-archived-categories
3610 (not (zerop (todos-get-count 'archived cat)))) 3625 (zerop (todos-get-count 'todo cat))
3611 (concat (file-name-sans-extension 3626 (zerop (todos-get-count 'done cat))
3612 todos-current-todos-file) ".toda") 3627 (not (zerop (todos-get-count 'archived cat))))
3613 ;; Otherwise, jump to current todos file. 3628 (concat (file-name-sans-extension
3614 todos-current-todos-file))) 3629 todos-current-todos-file) ".toda")
3630 ;; Otherwise, jump to current todos file.
3631 todos-current-todos-file)))
3615 (cat+file (unless cat 3632 (cat+file (unless cat
3616 (todos-read-category "Jump to category: " nil file)))) 3633 (todos-read-category "Jump to category: "
3634 (if archive 'archive) file))))
3617 (setq category (or cat (car cat+file))) 3635 (setq category (or cat (car cat+file)))
3618 (unless cat (setq file0 (cdr cat+file))) 3636 (unless cat (setq file0 (cdr cat+file)))
3619 (with-current-buffer (find-file-noselect file0 'nowarn) 3637 (with-current-buffer (find-file-noselect file0 'nowarn)
@@ -3629,6 +3647,14 @@ CAT; this is used in Todos Categories mode."
3629 (todos-category-select) 3647 (todos-category-select)
3630 (goto-char (point-min)))))) 3648 (goto-char (point-min))))))
3631 3649
3650(defun todos-jump-to-archive-category (&optional file)
3651 "Prompt for a category in a Todos archive and jump to it.
3652With prefix argument FILE, prompt for an archive and choose (with
3653TAB completion) a category in it to jump to; otherwise, choose
3654and jump to any category in the current archive."
3655 (interactive "P")
3656 (todos-jump-to-category file 'archive))
3657
3632(defun todos-go-to-source-item () 3658(defun todos-go-to-source-item ()
3633 "Display the file and category of the filtered item at point." 3659 "Display the file and category of the filtered item at point."
3634 (interactive) 3660 (interactive)