*** emacs/lisp/calendar/todo-mode.el.~1.72.~ 2009-01-09 11:48:58.000000000 +0100 --- emacs/lisp/calendar/todo-mode.el 2009-01-21 00:39:08.000000000 +0100 *************** *** 527,554 **** (narrow-to-region (todo-item-start) (todo-item-end)))) ;;;###autoload ! (defun todo-add-category (cat) "Add new category CAT to the TODO list." ! (interactive "sCategory: ") ! (save-window-excursion ! (setq todo-categories (cons cat todo-categories)) ! (find-file todo-file-do) ! (widen) ! (goto-char (point-min)) ! (let ((posn (search-forward "-*- mode: todo; " 17 t))) ! (if posn ! (progn ! (goto-char posn) ! (kill-line)) ! (insert "-*- mode: todo; \n") ! (forward-char -1))) ! (insert (format "todo-categories: %S; -*-" todo-categories)) ! (forward-char 1) ! (insert (format "%s%s%s\n%s\n%s %s\n" ! todo-prefix todo-category-beg cat ! todo-category-end ! todo-prefix todo-category-sep))) ! 0) ;;;###autoload (defun todo-add-item-non-interactively (new-item category) --- 527,571 ---- (narrow-to-region (todo-item-start) (todo-item-end)))) ;;;###autoload ! (defun todo-add-category (&optional cat) "Add new category CAT to the TODO list." ! (interactive) ! (let ((buf (find-file-noselect todo-file-do t)) ! (prompt "Category: ")) ! (unless (zerop (buffer-size buf)) ! (and (null todo-categories) ! (null todo-cats) ! (error "Error in %s: File is non-empty but contains no category" ! todo-file-do))) ! (unless cat (setq cat (read-from-minibuffer prompt))) ! (with-current-buffer buf ! ;; reject names that could induce bugs and confusion ! (while (and (cond ((string= "" cat) ! (setq prompt "Enter a non-empty category name: ")) ! ((string-match "\\`\\s-+\\'" cat) ! (setq prompt "Enter a category name that is not only white space: ")) ! ((member cat todo-categories) ! (setq prompt "Enter a non-existing category name: "))) ! (setq cat (read-from-minibuffer prompt)))) ! ;; initialize a newly created Todo buffer for Todo mode ! (unless (file-exists-p todo-file-do) (todo-mode)) ! (setq todo-categories (cons cat todo-categories)) ! (widen) ! (goto-char (point-min)) ! (if (search-forward "-*- mode: todo; " 17 t) ! (kill-line) ! (insert "-*- mode: todo; \n") ! (forward-char -1)) ! (insert (format "todo-categories: %S; -*-" todo-categories)) ! (forward-char 1) ! (insert (format "%s%s%s\n%s\n%s %s\n" ! todo-prefix todo-category-beg cat ! todo-category-end ! todo-prefix todo-category-sep)) ! (if (interactive-p) ! ;; properly display the newly added category ! (progn (setq todo-category-number 0) (todo-show)) ! 0)))) ;;;###autoload (defun todo-add-item-non-interactively (new-item category) *************** *** 929,935 **** (defun todo-show () "Show TODO list." (interactive) ! (if (file-exists-p todo-file-do) (find-file todo-file-do) (todo-initial-setup)) (if (null todo-categories) --- 946,957 ---- (defun todo-show () "Show TODO list." (interactive) ! ;; Call todo-initial-setup only if there is neither a Todo file nor ! ;; a corresponding unsaved buffer. ! (if (or (file-exists-p todo-file-do) ! (let* ((buf (get-buffer (file-name-nondirectory todo-file-do))) ! (bufname (buffer-file-name buf))) ! (equal (expand-file-name todo-file-do) bufname))) (find-file todo-file-do) (todo-initial-setup)) (if (null todo-categories)