Function: todo-add-category

todo-add-category is an interactive and byte-compiled function defined in todo-mode.el.gz.

Signature

(todo-add-category &optional FILE CAT)

Documentation

Add a new category to a todo file.

Called interactively with prefix argument FILE, prompt for a file and then for a new category to add to that file, otherwise prompt just for a category to add to the current todo file. After adding the category, visit it in Todo mode and if option todo-add-item-if-new-category is non-nil (the default), prompt for the first item.

Non-interactively, add category CAT to file FILE; if FILE is nil, add CAT to the current todo file. After adding the category, return the new category number.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
(defun todo-add-category (&optional file cat)
  "Add a new category to a todo file.

Called interactively with prefix argument FILE, prompt for a file
and then for a new category to add to that file, otherwise prompt
just for a category to add to the current todo file.  After
adding the category, visit it in Todo mode and if option
`todo-add-item-if-new-category' is non-nil (the default), prompt
for the first item.

Non-interactively, add category CAT to file FILE; if FILE is nil,
add CAT to the current todo file.  After adding the category,
return the new category number."
  (interactive "P")
  (let (catfil file0)
    ;; If cat is passed from caller, don't prompt, unless it is "",
    ;; which means the file was just added and has no category yet.
    (if (and cat (> (length cat) 0))
	(setq file0 (or (and (stringp file) file)
			todo-current-todo-file))
      (setq catfil (todo-read-category "Enter a new category name: "
					'add (when (called-interactively-p 'any)
					       file))
	    cat (car catfil)
	    file0 (if (called-interactively-p 'any)
		      (cdr catfil)
		    file)))
    (find-file file0)
    (let ((counts (make-vector 4 0))	; [todo diary done archived]
	  (num (1+ (length todo-categories))))
      (setq todo-current-todo-file file0)
      (setq todo-categories (append todo-categories
				     (list (cons cat counts))))
      (widen)
      (goto-char (point-max))
      (save-excursion			; Save point for todo-category-select.
	(let ((inhibit-read-only t))
	  (insert todo-category-beg cat "\n\n" todo-category-done "\n")))
      (todo-update-categories-sexp)
      ;; If invoked by user, display the newly added category, if
      ;; called programmatically return the category number to the
      ;; caller.
      (if (called-interactively-p 'any)
	  (progn
	    (setq todo-category-number num)
	    (todo-category-select)
	    (when todo-add-item-if-new-category
	      (todo-insert-item--basic)))
	num))))