Function: todo-rename-category

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

Signature

(todo-rename-category)

Documentation

Rename current todo category.

If this file has an archive containing this category, rename the category there as well.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
(defun todo-rename-category ()
  "Rename current todo category.
If this file has an archive containing this category, rename the
category there as well."
  (interactive)
  (let* ((cat (todo-current-category))
	 (new (read-from-minibuffer
	       (format "Rename category \"%s\" to: " cat))))
    (setq new (todo-validate-name new 'category))
    (let* ((ofile todo-current-todo-file)
	   (archive (concat (file-name-sans-extension ofile) ".toda"))
	   (buffers (append (list ofile)
			    (unless (zerop (todo-get-count 'archived cat))
			      (list archive)))))
      (dolist (buf buffers)
	(with-current-buffer (find-file-noselect buf)
	  (let (buffer-read-only)
	    (setq todo-categories (todo-set-categories))
	    (save-excursion
	      (save-restriction
		(setcar (assoc cat todo-categories) new)
		(widen)
		(goto-char (point-min))
		(todo-update-categories-sexp)
		(re-search-forward (concat (regexp-quote todo-category-beg)
					   "\\(" (regexp-quote cat) "\\)\n")
				   nil t)
		(replace-match new t t nil 1)))))))
    (force-mode-line-update))
  (save-excursion (todo-category-select)))