aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Berman2013-06-04 16:51:01 +0200
committerStephen Berman2013-06-04 16:51:01 +0200
commit37f482490bcda6a7cf8a0c821eeab8e586148766 (patch)
tree7aab6539b78fbd073358d44a06897a85a91c5aea
parent6d12ff8b3344d4284f78e0be56cda076f9a3d6e7 (diff)
downloademacs-37f482490bcda6a7cf8a0c821eeab8e586148766.tar.gz
emacs-37f482490bcda6a7cf8a0c821eeab8e586148766.zip
* 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.
-rw-r--r--lisp/calendar/ChangeLog10
-rw-r--r--lisp/calendar/todos.el38
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 @@
12013-06-04 Stephen Berman <stephen.berman@gmx.net> 12013-06-04 Stephen Berman <stephen.berman@gmx.net>
2 2
3 * todos.el: Allow prompting for first item on adding a new
4 category. Fix handling of default todo file on adding first file.
5 (todos-add-item-if-new-category): New defcustom.
6 (todos-show, todos-jump-to-category, todos-add-category): Use it.
7 (todos-short-file-name): Return nil if file name is not a string.
8 (todos-add-file): Recalculate todos-files after adding a file.
9 (todos-show): If first file was just added, make it the default.
10
112013-06-04 Stephen Berman <stephen.berman@gmx.net>
12
3 * todos.el (todos-read-category, todos-merge-category): 13 * todos.el (todos-read-category, todos-merge-category):
4 Fix argument value to accord with documented change from 2013-05-14. 14 Fix argument value to accord with documented change from 2013-05-14.
5 15
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'."
96(defun todos-short-file-name (file) 96(defun todos-short-file-name (file)
97 "Return short form of Todos FILE. 97 "Return short form of Todos FILE.
98This lacks the extension and directory components." 98This lacks the extension and directory components."
99 (file-name-sans-extension (file-name-nondirectory file))) 99 (when (stringp file)
100 (file-name-sans-extension (file-name-nondirectory file))))
100 101
101(defcustom todos-visit-files-commands (list 'find-file 'dired-find-file) 102(defcustom todos-visit-files-commands (list 'find-file 'dired-find-file)
102 "List of file finding commands for `todos-display-as-todos-file'. 103 "List of file finding commands for `todos-display-as-todos-file'.
@@ -193,6 +194,7 @@ Invoking this command in Todos Archive mode visits the
193corresponding Todos file, displaying the corresponding category." 194corresponding Todos file, displaying the corresponding category."
194 (interactive "P") 195 (interactive "P")
195 (let* ((cat) 196 (let* ((cat)
197 (add-item nil)
196 (show-first todos-show-first) 198 (show-first todos-show-first)
197 (file (cond ((or solicit-file 199 (file (cond ((or solicit-file
198 (and (called-interactively-p 'any) 200 (and (called-interactively-p 'any)
@@ -217,6 +219,10 @@ corresponding Todos file, displaying the corresponding category."
217 todos-global-current-todos-file) 219 todos-global-current-todos-file)
218 (todos-absolute-file-name todos-default-todos-file) 220 (todos-absolute-file-name todos-default-todos-file)
219 (todos-add-file)))))) 221 (todos-add-file))))))
222 (unless todos-default-todos-file
223 ;; We just initialized the first todo file, so make it the default.
224 (setq todos-default-todos-file (todos-short-file-name file))
225 (todos-reevaluate-default-file-defcustom))
220 (unless (member file todos-visited) 226 (unless (member file todos-visited)
221 ;; Can't setq t-c-t-f here, otherwise wrong file shown when 227 ;; Can't setq t-c-t-f here, otherwise wrong file shown when
222 ;; todos-show is called from todos-show-categories-table. 228 ;; todos-show is called from todos-show-categories-table.
@@ -259,9 +265,11 @@ corresponding Todos file, displaying the corresponding category."
259 (setq todos-category-number (todos-category-number cat))) 265 (setq todos-category-number (todos-category-number cat)))
260 ;; If this is a new Todos file, add its first category. 266 ;; If this is a new Todos file, add its first category.
261 (when (zerop (buffer-size)) 267 (when (zerop (buffer-size))
262 (setq todos-category-number 268 (setq todos-category-number (todos-add-category todos-current-todos-file
263 (todos-add-category todos-current-todos-file ""))) 269 "")
264 (save-excursion (todos-category-select))) 270 add-item todos-add-item-if-new-category))
271 (save-excursion (todos-category-select))
272 (when add-item (todos-basic-insert-item)))
265 (setq todos-show-first show-first) 273 (setq todos-show-first show-first)
266 (add-to-list 'todos-visited file))) 274 (add-to-list 'todos-visited file)))
267 275
@@ -375,9 +383,12 @@ Categories mode."
375 todos-current-todos-file) ".toda") 383 todos-current-todos-file) ".toda")
376 ;; Otherwise, jump to current todos file. 384 ;; Otherwise, jump to current todos file.
377 todos-current-todos-file))) 385 todos-current-todos-file)))
378 (cat+file (unless cat 386 (len (length todos-categories))
379 (todos-read-category "Jump to category: " 387 (cat+file (unless cat
380 (if archive 'archive) file)))) 388 (todos-read-category "Jump to category: "
389 (if archive 'archive) file)))
390 (add-item (and todos-add-item-if-new-category
391 (> (length todos-categories) len))))
381 (setq category (or cat (car cat+file))) 392 (setq category (or cat (car cat+file)))
382 (unless cat (setq file0 (cdr cat+file))) 393 (unless cat (setq file0 (cdr cat+file)))
383 (with-current-buffer (find-file-noselect file0 'nowarn) 394 (with-current-buffer (find-file-noselect file0 'nowarn)
@@ -391,7 +402,8 @@ Categories mode."
391 (setq todos-global-current-todos-file todos-current-todos-file)) 402 (setq todos-global-current-todos-file todos-current-todos-file))
392 (todos-category-number category) 403 (todos-category-number category)
393 (todos-category-select) 404 (todos-category-select)
394 (goto-char (point-min)))))) 405 (goto-char (point-min))
406 (when add-item (todos-basic-insert-item))))))
395 407
396(defun todos-next-item (&optional count) 408(defun todos-next-item (&optional count)
397 "Move point down to the beginning of the next item. 409 "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
460 (erase-buffer) 472 (erase-buffer)
461 (write-region (point-min) (point-max) file nil 'nomessage nil t) 473 (write-region (point-min) (point-max) file nil 'nomessage nil t)
462 (kill-buffer file)) 474 (kill-buffer file))
475 (setq todos-files (funcall todos-files-function))
463 (todos-reevaluate-filelist-defcustoms) 476 (todos-reevaluate-filelist-defcustoms)
464 (if (called-interactively-p) 477 (if (called-interactively-p)
465 (progn 478 (progn
@@ -537,7 +550,9 @@ return the new category number."
537 (if (called-interactively-p 'any) 550 (if (called-interactively-p 'any)
538 (progn 551 (progn
539 (setq todos-category-number num) 552 (setq todos-category-number num)
540 (todos-category-select)) 553 (todos-category-select)
554 (when todos-add-item-if-new-category
555 (todos-basic-insert-item)))
541 num)))) 556 num))))
542 557
543(defun todos-rename-category () 558(defun todos-rename-category ()
@@ -963,6 +978,11 @@ marking of the next N items."
963;;; Item editing options 978;;; Item editing options
964;; ----------------------------------------------------------------------------- 979;; -----------------------------------------------------------------------------
965 980
981(defcustom todos-add-item-if-new-category nil
982 "Non-nil to prompt for an item after adding a new category."
983 :type 'boolean
984 :group 'todos-edit)
985
966(defcustom todos-include-in-diary nil 986(defcustom todos-include-in-diary nil
967 "Non-nil to allow new Todo items to be included in the diary." 987 "Non-nil to allow new Todo items to be included in the diary."
968 :type 'boolean 988 :type 'boolean