Function: todo-make-categories-list

todo-make-categories-list is a byte-compiled function defined in todo-mode.el.gz.

Signature

(todo-make-categories-list &optional FORCE)

Documentation

Return an alist of todo categories and their item counts.

With non-nil argument FORCE parse the entire file to build the list; otherwise, get the value by reading the sexp at the top of the file.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
(defun todo-make-categories-list (&optional force)
  "Return an alist of todo categories and their item counts.
With non-nil argument FORCE parse the entire file to build the
list; otherwise, get the value by reading the sexp at the top of
the file."
  (setq todo-categories nil)
  (save-excursion
    (save-restriction
      (widen)
      (goto-char (point-min))
      (let (counts cat archive)
	;; If the file is a todo file and has archived items, identify the
	;; archive, in order to count its items.  But skip this with
	;; `todo-convert-legacy-files', since that converts filed items to
	;; archived items.
	(when buffer-file-name	 ; During conversion there is no file yet.
	  ;; If the file is an archive, it doesn't have an archive.
	  (unless (member (file-truename buffer-file-name)
			  (funcall todo-files-function t))
	    (setq archive (concat (file-name-sans-extension
				   todo-current-todo-file) ".toda"))))
	(while (not (eobp))
	  (cond ((looking-at (concat (regexp-quote todo-category-beg)
				     "\\(.*\\)\n"))
		 (setq cat (match-string-no-properties 1))
		 ;; Counts for each category: [todo diary done archive]
		 (setq counts (make-vector 4 0))
		 (setq todo-categories
		       (append todo-categories (list (cons cat counts))))
		 ;; Add archived item count to the todo file item counts.
		 ;; Make sure to include newly created archives, e.g. due to
		 ;; todo-move-category.
		 (when (member archive (funcall todo-files-function t))
		   (let ((archive-count 0)
			 (visiting (find-buffer-visiting archive)))
		     (with-current-buffer (or visiting
					      (find-file-noselect archive))
		       (save-excursion
			 (save-restriction
			   (widen)
			   (goto-char (point-min))
			   (when (re-search-forward
				  (concat "^" (regexp-quote todo-category-beg)
					  cat "$")
				  (point-max) t)
			     (forward-line)
			     (while (not (or (looking-at
					      (concat
					       (regexp-quote todo-category-beg)
					       "\\(.*\\)\n"))
					     (eobp)))
			       (when (looking-at todo-done-string-start)
				 (setq archive-count (1+ archive-count)))
			       (forward-line)))))
		       (unless visiting (kill-buffer)))
		     (todo-update-count 'archived archive-count cat))))
		((looking-at todo-done-string-start)
		 (todo-update-count 'done 1 cat))
		((looking-at (concat "^\\("
				     (regexp-quote diary-nonmarking-symbol)
				     "\\)?" todo-date-pattern))
		 (todo-update-count 'diary 1 cat)
		 (todo-update-count 'todo 1 cat))
		((looking-at (concat todo-date-string-start todo-date-pattern))
		 (todo-update-count 'todo 1 cat))
		;; If first line is todo-categories list, use it and end loop
		;; -- unless FORCEd to scan whole file.
		((bobp)
		 (unless force
		   (setq todo-categories (read (buffer-substring-no-properties
						 (line-beginning-position)
						 (line-end-position))))
		   (goto-char (1- (point-max))))))
	  (forward-line)))))
  todo-categories)