Function: todo-insert-category-line

todo-insert-category-line is a byte-compiled function defined in todo-mode.el.gz.

Signature

(todo-insert-category-line CAT &optional NONUM)

Documentation

Insert button with category CAT's name and item counts.

With non-nil argument NONUM show only these; otherwise, insert a number in front of the button indicating the category's priority. The number and the category name are separated by the string which is the value of the user option todo-categories-number-separator.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
(defun todo-insert-category-line (cat &optional nonum)
  "Insert button with category CAT's name and item counts.
With non-nil argument NONUM show only these; otherwise, insert a
number in front of the button indicating the category's priority.
The number and the category name are separated by the string
which is the value of the user option
`todo-categories-number-separator'."
  (let ((archive (member todo-current-todo-file todo-archives))
	(num todo-categories-category-number)
	(str (todo-padded-string cat))
	(opoint (point)))
    (setq num (1+ num) todo-categories-category-number num)
    (insert-button
     (concat (if nonum
		 (make-string (+ 4 (length todo-categories-number-separator))
			      32)
	       (format " %3d%s" num todo-categories-number-separator))
	     str
	     (mapconcat (lambda (elt)
			  (concat
			   (make-string (1+ (/ (length (car elt)) 2)) 32) ; label
			   (format "%3d" (todo-get-count (cdr elt) cat)) ; count
			   ;; Add an extra space if label length is odd.
			   (when (cl-oddp (length (car elt))) " ")))
			(if archive
			    (list (cons todo-categories-done-label 'done))
			  (list (cons todo-categories-todo-label 'todo)
				(cons todo-categories-diary-label 'diary)
				(cons todo-categories-done-label 'done)
				(cons todo-categories-archived-label
				      'archived))))
	     " ") ; Make highlighting on last column look better.
     'face (if (and todo-skip-archived-categories
		    (zerop (todo-get-count 'todo cat))
		    (zerop (todo-get-count 'done cat))
		    (not (zerop (todo-get-count 'archived cat))))
	       'todo-archived-only
	     nil)
     'action (lambda (_button)
               (let ((buf (current-buffer)))
		 (todo-jump-to-category nil cat)
		 (kill-buffer buf))))
    ;; Highlight the sorted count column.
    (let* ((beg (+ opoint 7 (length str)))
	   end ovl)
      (cond ((eq nonum 'todo)
	     (setq beg (+ beg 1 (/ (length todo-categories-todo-label) 2))))
	    ((eq nonum 'diary)
	     (setq beg (+ beg 1 (length todo-categories-todo-label)
			   2 (/ (length todo-categories-diary-label) 2))))
	    ((eq nonum 'done)
	     (setq beg (+ beg 1 (length todo-categories-todo-label)
			   2 (length todo-categories-diary-label)
			   2 (/ (length todo-categories-done-label) 2))))
	    ((eq nonum 'archived)
	     (setq beg (+ beg 1 (length todo-categories-todo-label)
			   2 (length todo-categories-diary-label)
			   2 (length todo-categories-done-label)
			   2 (/ (length todo-categories-archived-label) 2)))))
      (unless (= beg (+ opoint 7 (length str))) ; Don't highlight categories.
	(setq end (+ beg 4))
	(setq ovl (make-overlay beg end))
	(overlay-put ovl 'face 'todo-sorted-column)))
    (newline)))