Function: todo-delete-category
todo-delete-category is an interactive and byte-compiled function
defined in todo-mode.el.gz.
Signature
(todo-delete-category &optional ARG)
Documentation
Delete current todo category provided it contains no items.
With prefix ARG delete the category even if it does contain todo or done items.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
(defun todo-delete-category (&optional arg)
"Delete current todo category provided it contains no items.
With prefix ARG delete the category even if it does contain
todo or done items."
(interactive "P")
(let* ((file todo-current-todo-file)
(cat (todo-current-category))
(todo (todo-get-count 'todo cat))
(done (todo-get-count 'done cat))
(archived (todo-get-count 'archived cat)))
(if (and (not arg)
(or (> todo 0) (> done 0)))
(message "%s" (substitute-command-keys
(concat "To delete a non-empty category, "
"type C-u \\[todo-delete-category].")))
(when (cond ((= (length todo-categories) 1)
(todo-y-or-n-p
(concat "This is the only category in this file; "
"deleting it will also delete the file.\n"
"Do you want to proceed? ")))
((> archived 0)
(todo-y-or-n-p (format-message
(concat "This category has archived items; "
"the archived category will remain\n"
"after deleting the todo category. "
"Do you still want to delete it\n"
"(see `todo-skip-archived-categories' "
"for another option)? "))))
(t
(todo-y-or-n-p (concat "Permanently remove category \"" cat
"\"" (and arg " and all its entries")
"? "))))
(widen)
(let ((inhibit-read-only t)
(beg (re-search-backward
(concat "^" (regexp-quote (concat todo-category-beg cat))
"\n")
nil t))
(end (if (re-search-forward
(concat "\n\\(" (regexp-quote todo-category-beg)
".*\n\\)")
nil t)
(match-beginning 1)
(point-max))))
(remove-overlays beg end)
(delete-region beg end)
(if (= (length todo-categories) 1)
;; If deleted category was the only one, delete the file.
(progn
(todo-update-filelist-defcustoms)
;; Skip confirming killing the archive buffer if it has been
;; modified and not saved.
(set-buffer-modified-p nil)
(delete-file file)
(kill-buffer)
(message "Deleted todo file %s." file))
(setq todo-categories (delete (assoc cat todo-categories)
todo-categories))
(todo-update-categories-sexp)
(setq todo-category-number
(1+ (mod todo-category-number (length todo-categories))))
(todo-category-select)
(goto-char (point-min))
(message "Deleted category %s." cat)))))))