From 37f482490bcda6a7cf8a0c821eeab8e586148766 Mon Sep 17 00:00:00 2001 From: Stephen Berman Date: Tue, 4 Jun 2013 16:51:01 +0200 Subject: [PATCH] * todos.el: Allow prompting for first item on adding a new category. Fix handling of default todo file on adding first file. (todos-add-item-if-new-category): New defcustom. (todos-show, todos-jump-to-category, todos-add-category): Use it. (todos-short-file-name): Return nil if file name is not a string. (todos-add-file): Recalculate todos-files after adding a file. (todos-show): If first file was just added, make it the default. --- lisp/calendar/ChangeLog | 10 ++++++++++ lisp/calendar/todos.el | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/lisp/calendar/ChangeLog b/lisp/calendar/ChangeLog index f341a337e6a..a7dbf7a4c37 100644 --- a/lisp/calendar/ChangeLog +++ b/lisp/calendar/ChangeLog @@ -1,5 +1,15 @@ 2013-06-04 Stephen Berman + * todos.el: Allow prompting for first item on adding a new + category. Fix handling of default todo file on adding first file. + (todos-add-item-if-new-category): New defcustom. + (todos-show, todos-jump-to-category, todos-add-category): Use it. + (todos-short-file-name): Return nil if file name is not a string. + (todos-add-file): Recalculate todos-files after adding a file. + (todos-show): If first file was just added, make it the default. + +2013-06-04 Stephen Berman + * todos.el (todos-read-category, todos-merge-category): Fix argument value to accord with documented change from 2013-05-14. diff --git a/lisp/calendar/todos.el b/lisp/calendar/todos.el index 6622f9fde36..6d3d9ec0ccb 100644 --- a/lisp/calendar/todos.el +++ b/lisp/calendar/todos.el @@ -96,7 +96,8 @@ makes it return the value of the variable `todos-archives'." (defun todos-short-file-name (file) "Return short form of Todos FILE. This lacks the extension and directory components." - (file-name-sans-extension (file-name-nondirectory file))) + (when (stringp file) + (file-name-sans-extension (file-name-nondirectory file)))) (defcustom todos-visit-files-commands (list 'find-file 'dired-find-file) "List of file finding commands for `todos-display-as-todos-file'. @@ -193,6 +194,7 @@ Invoking this command in Todos Archive mode visits the corresponding Todos file, displaying the corresponding category." (interactive "P") (let* ((cat) + (add-item nil) (show-first todos-show-first) (file (cond ((or solicit-file (and (called-interactively-p 'any) @@ -217,6 +219,10 @@ corresponding Todos file, displaying the corresponding category." todos-global-current-todos-file) (todos-absolute-file-name todos-default-todos-file) (todos-add-file)))))) + (unless todos-default-todos-file + ;; We just initialized the first todo file, so make it the default. + (setq todos-default-todos-file (todos-short-file-name file)) + (todos-reevaluate-default-file-defcustom)) (unless (member file todos-visited) ;; Can't setq t-c-t-f here, otherwise wrong file shown when ;; todos-show is called from todos-show-categories-table. @@ -259,9 +265,11 @@ corresponding Todos file, displaying the corresponding category." (setq todos-category-number (todos-category-number cat))) ;; If this is a new Todos file, add its first category. (when (zerop (buffer-size)) - (setq todos-category-number - (todos-add-category todos-current-todos-file ""))) - (save-excursion (todos-category-select))) + (setq todos-category-number (todos-add-category todos-current-todos-file + "") + add-item todos-add-item-if-new-category)) + (save-excursion (todos-category-select)) + (when add-item (todos-basic-insert-item))) (setq todos-show-first show-first) (add-to-list 'todos-visited file))) @@ -375,9 +383,12 @@ Categories mode." todos-current-todos-file) ".toda") ;; Otherwise, jump to current todos file. todos-current-todos-file))) - (cat+file (unless cat - (todos-read-category "Jump to category: " - (if archive 'archive) file)))) + (len (length todos-categories)) + (cat+file (unless cat + (todos-read-category "Jump to category: " + (if archive 'archive) file))) + (add-item (and todos-add-item-if-new-category + (> (length todos-categories) len)))) (setq category (or cat (car cat+file))) (unless cat (setq file0 (cdr cat+file))) (with-current-buffer (find-file-noselect file0 'nowarn) @@ -391,7 +402,8 @@ Categories mode." (setq todos-global-current-todos-file todos-current-todos-file)) (todos-category-number category) (todos-category-select) - (goto-char (point-min)))))) + (goto-char (point-min)) + (when add-item (todos-basic-insert-item)))))) (defun todos-next-item (&optional count) "Move point down to the beginning of the next item. @@ -460,6 +472,7 @@ This command does not save the file to disk; to do that type (erase-buffer) (write-region (point-min) (point-max) file nil 'nomessage nil t) (kill-buffer file)) + (setq todos-files (funcall todos-files-function)) (todos-reevaluate-filelist-defcustoms) (if (called-interactively-p) (progn @@ -537,7 +550,9 @@ return the new category number." (if (called-interactively-p 'any) (progn (setq todos-category-number num) - (todos-category-select)) + (todos-category-select) + (when todos-add-item-if-new-category + (todos-basic-insert-item))) num)))) (defun todos-rename-category () @@ -963,6 +978,11 @@ marking of the next N items." ;;; Item editing options ;; ----------------------------------------------------------------------------- +(defcustom todos-add-item-if-new-category nil + "Non-nil to prompt for an item after adding a new category." + :type 'boolean + :group 'todos-edit) + (defcustom todos-include-in-diary nil "Non-nil to allow new Todo items to be included in the diary." :type 'boolean -- 2.11.4.GIT