]> git.eshelyaron.com Git - emacs.git/commitdiff
* calendar/todos.el (todos-undo-item-omit-comment): New defcustom.
authorStephen Berman <stephen.berman@gmx.net>
Fri, 13 Jul 2012 14:15:49 +0000 (15:15 +0100)
committerStephen Berman <stephen.berman@gmx.net>
Fri, 13 Jul 2012 14:15:49 +0000 (15:15 +0100)
(todos-item-undo): Use it.
(todos-allcats-file, todos-all-categories-alist): New variables.
(todos-all-categories-alist): New function.
(todos-jump-to-any-category): New command.
(todos-move-item): Remove mark overlays from buffer items were
moved from; update todos-categories-with-marks,

lisp/ChangeLog
lisp/calendar/todos.el

index eaab22994b04aace11b0f57ff42c51cfa4f85e28..05c3436b3b8bd9314d8ff6d1e1051e4122d6f1bb 100644 (file)
@@ -1,3 +1,13 @@
+2012-09-24  Stephen Berman  <stephen.berman@gmx.net>
+
+       * calendar/todos.el (todos-undo-item-omit-comment): New defcustom.
+       (todos-item-undo): Use it.
+       (todos-allcats-file, todos-all-categories-alist): New variables.
+       (todos-all-categories-alist): New function.
+       (todos-jump-to-any-category): New command.
+       (todos-move-item): Remove mark overlays from buffer items were
+       moved from; update todos-categories-with-marks,
+
 2012-09-24  Stephen Berman  <stephen.berman@gmx.net>
 
        * calendar/todos.el: Further code rearrangement; further new and
index 08fe35b9612559efc38e5d636ac8fdc5cf6f2921..b3ff3191b96a8771c673d28cac3b843731997c1d 100644 (file)
@@ -132,6 +132,15 @@ displayed correctly."
   :type 'boolean
   :group 'todos)
 
+(defcustom todos-undo-item-omit-comment 'ask
+  "Whether to omit done item comment on undoing the item.
+Nil means never omit the comment, t means always omit it, `ask'
+means prompt user and omit comment only on confirmation."
+  :type '(choice (const :tag "Never" nil)
+                (const :tag "Always" t)
+                (const :tag "Ask" ask))
+  :group 'todos)
+
 (defcustom todos-print-function 'ps-print-buffer-with-faces
   "Function called to print buffer content; see `todos-print'."
   :type 'symbol
@@ -1289,6 +1298,41 @@ editing or a bug in todos.el."
   (let ((todos-categories (todos-make-categories-list t)))
     (todos-update-categories-sexp)))
 
+(defvar todos-allcats-file (concat todos-files-directory "todos-allcats.el")
+  "Name of file containing the value of `todos-all-categories-alist'.
+The contents of this file are automatically generated and
+executed when todos.el is loaded, hence users should not edit
+it.")
+
+(defun todos-all-categories-alist ()
+  ""
+  ;; FIXME: loop through archive files for categories not in todo files?
+  (let ((files todos-files)
+       allcats)
+    (dolist (f files)
+      ;; FIXME: If file buffer is modified, save first.
+      (with-temp-buffer
+       (insert-file-contents f)
+       (let ((cats (read (buffer-substring-no-properties
+                          (line-beginning-position)
+                          (line-end-position)))))
+         (dolist (c cats)
+           (let* ((cat (assoc (car c) allcats))
+                  (catcdr (cdr cat)))
+             (unless (listp catcdr) (setq catcdr (list catcdr)))
+             (if cat
+                 (setcdr cat (append catcdr (list (todos-short-file-name f))))
+               (setq allcats (append allcats
+                                     (list
+                                      (cons (car c)
+                                            (todos-short-file-name f)))))))))))
+    allcats))
+
+(defvar todos-all-categories-alist (if (file-exists-p todos-allcats-file)
+                                      (load-file todos-allcats-file)
+                                    (todos-all-categories-alist))
+  "Alist of names of all Todos categories and their files.")
+
 ;;; Global variables and helper functions for items
 
 (defconst todos-date-pattern
@@ -3157,6 +3201,31 @@ The category is chosen by prompt, with TAB completion."
   (interactive)
   (todos-jump-to-category nil t))
 
+(defun todos-jump-to-any-category ()
+  ""
+  (interactive)
+  (let* ((cats-alist todos-all-categories-alist)
+        (cats (mapcar 'car cats-alist))
+        (completion-ignore-case todos-completion-ignore-case)
+        (cat (completing-read "Jump to category: " cats nil t))
+        (files (if (zerop (length cat))
+                   (keyboard-quit)
+                 (cdr (assoc cat cats-alist))))
+        (file (if (nlistp files)
+                  files
+                (completing-read (format "Jump to \"%s\" in which file? " cat)
+                                 files nil t))))
+    (if (zerop (length file))
+       (keyboard-quit)
+      (setq file (concat todos-files-directory file ".todo"))
+      (set-window-buffer (selected-window)
+                        (set-buffer (find-file-noselect file)))
+      (unless todos-global-current-todos-file
+       (setq todos-global-current-todos-file todos-current-todos-file))
+      (todos-category-number cat)
+      (todos-category-select)
+       (goto-char (point-min)))))
+
 (defun todos-jump-to-item ()
   "Jump to the file and category of the filtered item at point."
   (interactive)
@@ -4733,7 +4802,12 @@ entry/entries in that category."
                  (while (< (point) end)
                    (if (todos-marked-item-p)
                        (todos-remove-item)
-                     (todos-forward-item))))
+                     (todos-forward-item)))
+                 ;; FIXME: does this work?
+                 (remove-overlays (point-min) (point-max)
+                                  'before-string todos-item-mark)
+                 (setq todos-categories-with-marks
+                       (assq-delete-all cat todos-categories-with-marks)))
              (if ov (delete-overlay ov))
              (todos-remove-item))))
        (todos-update-count 'todo (- count) cat1)
@@ -4886,9 +4960,11 @@ the restored item."
                                 ": [^]]+\\]") end t)
                    (if (eq first 'first)
                        (setq first
-                             ;; FIXME: make this a user option?
-                             (when (y-or-n-p "Omit comment from restored item? ")
-                               'omit))
+                             (if (eq todos-undo-item-omit-comment 'ask)
+                                 (when (y-or-n-p
+                                        "Omit comment from restored item? ")
+                                   'omit)
+                               (when todos-undo-item-omit-comment 'omit)))
                      t)
                    (when (eq first 'omit)
                      (delete-region (match-beginning 0) (match-end 0))