diff options
| author | Stephen Berman | 2013-06-05 00:34:11 +0200 |
|---|---|---|
| committer | Stephen Berman | 2013-06-05 00:34:11 +0200 |
| commit | c66f681c4fced52f47e12dc80e47a8b6075e2401 (patch) | |
| tree | b31651e080f783f1ccf504a355dde2c5128fed79 | |
| parent | 37f482490bcda6a7cf8a0c821eeab8e586148766 (diff) | |
| download | emacs-c66f681c4fced52f47e12dc80e47a8b6075e2401.tar.gz emacs-c66f681c4fced52f47e12dc80e47a8b6075e2401.zip | |
* todos.el (todos-add-item-if-new-category): Change default value.
(todos-show, todos-jump-to-category, todos-add-file)
(todos-add-category): Update doc string to reflect new default
prompt for item insertion.
(todos-add-file): Add omitted argument to called-interactively-p.
(todos-show): Improve handling of adding first category.
| -rw-r--r-- | lisp/calendar/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/calendar/todos.el | 55 |
2 files changed, 49 insertions, 15 deletions
diff --git a/lisp/calendar/ChangeLog b/lisp/calendar/ChangeLog index a7dbf7a4c37..8462032f222 100644 --- a/lisp/calendar/ChangeLog +++ b/lisp/calendar/ChangeLog | |||
| @@ -1,5 +1,14 @@ | |||
| 1 | 2013-06-04 Stephen Berman <stephen.berman@gmx.net> | 1 | 2013-06-04 Stephen Berman <stephen.berman@gmx.net> |
| 2 | 2 | ||
| 3 | * todos.el (todos-add-item-if-new-category): Change default value. | ||
| 4 | (todos-show, todos-jump-to-category, todos-add-file) | ||
| 5 | (todos-add-category): Update doc string to reflect new default | ||
| 6 | prompt for item insertion. | ||
| 7 | (todos-add-file): Add omitted argument to called-interactively-p. | ||
| 8 | (todos-show): Improve handling of adding first category. | ||
| 9 | |||
| 10 | 2013-06-04 Stephen Berman <stephen.berman@gmx.net> | ||
| 11 | |||
| 3 | * todos.el: Allow prompting for first item on adding a new | 12 | * todos.el: Allow prompting for first item on adding a new |
| 4 | category. Fix handling of default todo file on adding first file. | 13 | category. Fix handling of default todo file on adding first file. |
| 5 | (todos-add-item-if-new-category): New defcustom. | 14 | (todos-add-item-if-new-category): New defcustom. |
diff --git a/lisp/calendar/todos.el b/lisp/calendar/todos.el index 6d3d9ec0ccb..0f0d00ba1d8 100644 --- a/lisp/calendar/todos.el +++ b/lisp/calendar/todos.el | |||
| @@ -173,7 +173,9 @@ file was last visited. | |||
| 173 | Calling this command before any Todos file exists prompts for a | 173 | Calling this command before any Todos file exists prompts for a |
| 174 | file name and an initial category (defaulting to | 174 | file name and an initial category (defaulting to |
| 175 | `todos-initial-file' and `todos-initial-category'), creates both | 175 | `todos-initial-file' and `todos-initial-category'), creates both |
| 176 | of these, visits the file and displays the category. | 176 | of these, visits the file and displays the category, and if |
| 177 | option `todos-add-item-if-new-category' is non-nil (the default), | ||
| 178 | prompts for the first item. | ||
| 177 | 179 | ||
| 178 | The first invocation of this command on an existing Todos file | 180 | The first invocation of this command on an existing Todos file |
| 179 | interacts with the option `todos-show-first': if its value is | 181 | interacts with the option `todos-show-first': if its value is |
| @@ -194,7 +196,6 @@ Invoking this command in Todos Archive mode visits the | |||
| 194 | corresponding Todos file, displaying the corresponding category." | 196 | corresponding Todos file, displaying the corresponding category." |
| 195 | (interactive "P") | 197 | (interactive "P") |
| 196 | (let* ((cat) | 198 | (let* ((cat) |
| 197 | (add-item nil) | ||
| 198 | (show-first todos-show-first) | 199 | (show-first todos-show-first) |
| 199 | (file (cond ((or solicit-file | 200 | (file (cond ((or solicit-file |
| 200 | (and (called-interactively-p 'any) | 201 | (and (called-interactively-p 'any) |
| @@ -218,10 +219,12 @@ corresponding Todos file, displaying the corresponding category." | |||
| 218 | (and todos-show-current-file | 219 | (and todos-show-current-file |
| 219 | todos-global-current-todos-file) | 220 | todos-global-current-todos-file) |
| 220 | (todos-absolute-file-name todos-default-todos-file) | 221 | (todos-absolute-file-name todos-default-todos-file) |
| 221 | (todos-add-file)))))) | 222 | (todos-add-file))))) |
| 223 | add-item first-file) | ||
| 222 | (unless todos-default-todos-file | 224 | (unless todos-default-todos-file |
| 223 | ;; We just initialized the first todo file, so make it the default. | 225 | ;; We just initialized the first todo file, so make it the default. |
| 224 | (setq todos-default-todos-file (todos-short-file-name file)) | 226 | (setq todos-default-todos-file (todos-short-file-name file) |
| 227 | first-file t) | ||
| 225 | (todos-reevaluate-default-file-defcustom)) | 228 | (todos-reevaluate-default-file-defcustom)) |
| 226 | (unless (member file todos-visited) | 229 | (unless (member file todos-visited) |
| 227 | ;; Can't setq t-c-t-f here, otherwise wrong file shown when | 230 | ;; Can't setq t-c-t-f here, otherwise wrong file shown when |
| @@ -265,9 +268,26 @@ corresponding Todos file, displaying the corresponding category." | |||
| 265 | (setq todos-category-number (todos-category-number cat))) | 268 | (setq todos-category-number (todos-category-number cat))) |
| 266 | ;; If this is a new Todos file, add its first category. | 269 | ;; If this is a new Todos file, add its first category. |
| 267 | (when (zerop (buffer-size)) | 270 | (when (zerop (buffer-size)) |
| 268 | (setq todos-category-number (todos-add-category todos-current-todos-file | 271 | (let (cat-added) |
| 269 | "") | 272 | (unwind-protect |
| 270 | add-item todos-add-item-if-new-category)) | 273 | (setq todos-category-number |
| 274 | (todos-add-category todos-current-todos-file "") | ||
| 275 | add-item todos-add-item-if-new-category | ||
| 276 | cat-added t) | ||
| 277 | (if cat-added | ||
| 278 | ;; If the category was added, save the file now, so we | ||
| 279 | ;; don't end up with an empty file, which would signal | ||
| 280 | ;; an error if we tried to visit it later. | ||
| 281 | (save-buffer 0) | ||
| 282 | ;; If user cancels before adding the category, clean up | ||
| 283 | ;; and exit, so we have a fresh slate the next time. | ||
| 284 | (delete-file file) | ||
| 285 | (setq todos-files (delete file todos-files)) | ||
| 286 | (when first-file | ||
| 287 | (setq todos-default-todos-file nil | ||
| 288 | todos-current-todos-file nil)) | ||
| 289 | (kill-buffer) | ||
| 290 | (keyboard-quit))))) | ||
| 271 | (save-excursion (todos-category-select)) | 291 | (save-excursion (todos-category-select)) |
| 272 | (when add-item (todos-basic-insert-item))) | 292 | (when add-item (todos-basic-insert-item))) |
| 273 | (setq todos-show-first show-first) | 293 | (setq todos-show-first show-first) |
| @@ -353,9 +373,10 @@ in it to jump to; otherwise, choose and jump to any category in | |||
| 353 | either the current Todos file or a file in | 373 | either the current Todos file or a file in |
| 354 | `todos-category-completions-files'. | 374 | `todos-category-completions-files'. |
| 355 | 375 | ||
| 356 | You can also enter a non-existing category name, triggering a | 376 | Also accept a non-existing category name and ask whether to add a |
| 357 | prompt whether to add a new category by that name; on | 377 | new category by that name; on confirmation, add it and jump to |
| 358 | confirmation it is added and you jump to that category. | 378 | that category, and if option `todos-add-item-if-new-category' is |
| 379 | non-nil (the default), then prompt for the first item. | ||
| 359 | 380 | ||
| 360 | In noninteractive calls non-nil WHERE specifies either the goal | 381 | In noninteractive calls non-nil WHERE specifies either the goal |
| 361 | category or its file. If its value is `archive', the choice of | 382 | category or its file. If its value is `archive', the choice of |
| @@ -458,7 +479,9 @@ empty line above the done items separator." | |||
| 458 | 479 | ||
| 459 | (defun todos-add-file () | 480 | (defun todos-add-file () |
| 460 | "Name and initialize a new Todos file. | 481 | "Name and initialize a new Todos file. |
| 461 | Interactively, prompt for a category and display it. | 482 | Interactively, prompt for a category and display it, and if |
| 483 | option `todos-add-item-if-new-category' is non-nil (the default), | ||
| 484 | prompt for the first item. | ||
| 462 | Noninteractively, return the name of the new file. | 485 | Noninteractively, return the name of the new file. |
| 463 | 486 | ||
| 464 | This command does not save the file to disk; to do that type | 487 | This command does not save the file to disk; to do that type |
| @@ -474,7 +497,7 @@ This command does not save the file to disk; to do that type | |||
| 474 | (kill-buffer file)) | 497 | (kill-buffer file)) |
| 475 | (setq todos-files (funcall todos-files-function)) | 498 | (setq todos-files (funcall todos-files-function)) |
| 476 | (todos-reevaluate-filelist-defcustoms) | 499 | (todos-reevaluate-filelist-defcustoms) |
| 477 | (if (called-interactively-p) | 500 | (if (called-interactively-p 'any) |
| 478 | (progn | 501 | (progn |
| 479 | (set-window-buffer (selected-window) | 502 | (set-window-buffer (selected-window) |
| 480 | (set-buffer (find-file-noselect file))) | 503 | (set-buffer (find-file-noselect file))) |
| @@ -512,8 +535,10 @@ this command should be used with caution." | |||
| 512 | 535 | ||
| 513 | Called interactively with prefix argument FILE, prompt for a file | 536 | Called interactively with prefix argument FILE, prompt for a file |
| 514 | and then for a new category to add to that file, otherwise prompt | 537 | and then for a new category to add to that file, otherwise prompt |
| 515 | just for a category to add to the current Todos file. After adding | 538 | just for a category to add to the current Todos file. After |
| 516 | the category, visit it in Todos mode. | 539 | adding the category, visit it in Todos mode and if option |
| 540 | `todos-add-item-if-new-category' is non-nil (the default), prompt | ||
| 541 | for the first item. | ||
| 517 | 542 | ||
| 518 | Non-interactively, add category CAT to file FILE; if FILE is nil, | 543 | Non-interactively, add category CAT to file FILE; if FILE is nil, |
| 519 | add CAT to the current Todos file. After adding the category, | 544 | add CAT to the current Todos file. After adding the category, |
| @@ -978,7 +1003,7 @@ marking of the next N items." | |||
| 978 | ;;; Item editing options | 1003 | ;;; Item editing options |
| 979 | ;; ----------------------------------------------------------------------------- | 1004 | ;; ----------------------------------------------------------------------------- |
| 980 | 1005 | ||
| 981 | (defcustom todos-add-item-if-new-category nil | 1006 | (defcustom todos-add-item-if-new-category t |
| 982 | "Non-nil to prompt for an item after adding a new category." | 1007 | "Non-nil to prompt for an item after adding a new category." |
| 983 | :type 'boolean | 1008 | :type 'boolean |
| 984 | :group 'todos-edit) | 1009 | :group 'todos-edit) |