Function: todo-filter-items

todo-filter-items is a byte-compiled function defined in todo-mode.el.gz.

Signature

(todo-filter-items FILTER &optional NEW MULTIFILE)

Documentation

Display a list of items filtered by FILTER.

The values of FILTER can be top for top priority items, a cons of top and a number passed by the caller, diary for diary items, or regexp for items matching a regular expression entered by the user. The items can come from any categories in the current todo file or, with non-nil MULTIFILE, from several files. If NEW is nil, visit an appropriate file containing the list of filtered items; if there is no such file, or with non-nil NEW, build the list and display it.

See the documentation strings of the commands todo-filter-top-priorities, todo-filter-diary-items, todo-filter-regexp-items, and those of the corresponding multifile commands for further details.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
(defun todo-filter-items (filter &optional new multifile)
  "Display a list of items filtered by FILTER.
The values of FILTER can be `top' for top priority items, a cons
of `top' and a number passed by the caller, `diary' for diary
items, or `regexp' for items matching a regular expression
entered by the user.  The items can come from any categories in
the current todo file or, with non-nil MULTIFILE, from several
files.  If NEW is nil, visit an appropriate file containing the
list of filtered items; if there is no such file, or with non-nil
NEW, build the list and display it.

See the documentation strings of the commands
`todo-filter-top-priorities', `todo-filter-diary-items',
`todo-filter-regexp-items', and those of the corresponding
multifile commands for further details."
  (let* ((top (eq filter 'top))
	 (diary (eq filter 'diary))
	 (regexp (eq filter 'regexp))
	 (buf (cond (top todo-top-priorities-buffer)
		    (diary todo-diary-items-buffer)
		    (regexp todo-regexp-items-buffer)))
	 (flist (if multifile
		    (or todo-filter-files
			(progn (todo-multiple-filter-files)
			       todo-multiple-filter-files))
		  (list todo-current-todo-file)))
	 (fname (if (equal flist 'quit)
		    ;; Pressed `cancel' in t-m-f-f file selection dialog.
		    (keyboard-quit)
		  (concat todo-directory
			  (mapconcat #'todo-short-file-name flist "-")
			  (cond (top ".todt")
				(diary ".tody")
				(regexp ".todr")))))
	 (multi (> (length flist) 1))
	 (rxfiles (when regexp
		    (directory-files todo-directory t "\\.todr\\'" t)))
	 (file-exists (or (file-exists-p fname) rxfiles))
	 bufname)
    (cond ((and top new (natnump new))
	   (todo-filter-items-1 (cons 'top new) flist))
	  ((and (not new) file-exists)
	   (when (and rxfiles (> (length rxfiles) 1))
	     (let ((rxf (mapcar #'todo-short-file-name rxfiles)))
	       (setq fname (todo-absolute-file-name
			    (completing-read "Choose a regexp items file: "
					     rxf)
                            'regexp))))
	   (find-file fname)
	   (unless (derived-mode-p 'todo-filtered-items-mode)
	     (todo-filtered-items-mode))
	   (todo-prefix-overlays)
	   (todo-check-filtered-items-file))
	  (t
	   (todo-filter-items-1 filter flist)))
    (dolist (s (split-string (todo-short-file-name fname) "-"))
      (setq bufname (if bufname
			(concat bufname (if (member s (mapcar
						       #'todo-short-file-name
						       todo-files))
					    ", " "-")
                                s)
		      s)))
    (rename-buffer (format (concat "%s for file" (if multi "s" "") " \"%s\"")
                           buf bufname))))