]> code.delx.au - gnu-emacs/blobdiff - lisp/calendar/todo-mode.el
(calendar-scroll-left): Handle case when event-start is nil.
[gnu-emacs] / lisp / calendar / todo-mode.el
index 13ef042f736295b0d0a5468ef7927dcca98b0a30..bf54a1c7cf6347d2fd4f516c071920a860b50a2c 100644 (file)
@@ -1,7 +1,7 @@
 ;;; todo-mode.el --- major mode for editing TODO list files
 
-;; Copyright (C) 1997, 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1997, 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+;;   2008  Free Software Foundation, Inc.
 
 ;; Author: Oliver Seidel <os10000@seidel-space.de>
 ;;   [Not clear the above works, July 2000]
@@ -73,8 +73,8 @@
 ;;      the addition of two bindings to your to your global keymap.  I
 ;;      personally have the following in my initialisation file:
 ;;
-;;          (global-set-key "\C-ct" 'todo-show) ;; switch to TODO buffer
-;;         (global-set-key "\C-ci" 'todo-insert-item) ;; insert new item
+;;          (global-set-key "\C-ct" 'todo-show)  ; switch to TODO buffer
+;;         (global-set-key "\C-ci" 'todo-insert-item) ; insert new item
 ;;
 ;;      Note, however, that this recommendation has prompted some
 ;;      criticism, since the keys C-c LETTER are reserved for user
   :group 'calendar)
 
 (defcustom todo-prefix     "*/*"
-  "*TODO mode prefix for entries.
+  "TODO mode prefix for entries.
 
 This is useful in conjunction with `calendar' and `diary' if you use
 
@@ -285,23 +285,23 @@ the diary file somewhat."
   :type 'string
   :group 'todo)
 (defcustom todo-file-do    "~/.todo-do"
-  "*TODO mode list file."
+  "TODO mode list file."
   :type 'file
   :group 'todo)
 (defcustom todo-file-done  "~/.todo-done"
-  "*TODO mode archive file."
+  "TODO mode archive file."
   :type 'file
   :group 'todo)
 (defcustom todo-mode-hook  nil
-  "*TODO mode hooks."
+  "TODO mode hooks."
   :type 'hook
   :group 'todo)
 (defcustom todo-edit-mode-hook nil
-  "*TODO Edit mode hooks."
+  "TODO Edit mode hooks."
   :type 'hook
   :group 'todo)
 (defcustom todo-insert-threshold 0
-  "*TODO mode insertion accuracy.
+  "TODO mode insertion accuracy.
 
 If you have 8 items in your TODO list, then you may get asked 4
 questions by the binary insertion algorithm.  However, you may not
@@ -319,7 +319,7 @@ window."
 (defvar todo-edit-buffer " *TODO Edit*"
   "TODO Edit buffer name.")
 (defcustom todo-file-top "~/.todo-top"
-  "*TODO mode top priorities file.
+  "TODO mode top priorities file.
 
 Not in TODO format, but diary compatible.
 Automatically generated when `todo-save-top-priorities' is non-nil."
@@ -327,26 +327,26 @@ Automatically generated when `todo-save-top-priorities' is non-nil."
   :group 'todo)
 
 (defcustom todo-print-function 'ps-print-buffer-with-faces
-  "*Function to print the current buffer."
+  "Function to print the current buffer."
   :type 'symbol
   :group 'todo)
 (defcustom todo-show-priorities 1
-  "*Default number of priorities to show by \\[todo-top-priorities].
+  "Default number of priorities to show by \\[todo-top-priorities].
 0 means show all entries."
   :type 'integer
   :group 'todo)
 (defcustom todo-print-priorities 0
-  "*Default number of priorities to print by \\[todo-print].
+  "Default number of priorities to print by \\[todo-print].
 0 means print all entries."
   :type 'integer
   :group 'todo)
 (defcustom todo-remove-separator t
-  "*Non-nil to remove category separators in\
+  "Non-nil to remove category separators in\
 \\[todo-top-priorities] and \\[todo-print]."
   :type 'boolean
   :group 'todo)
 (defcustom todo-save-top-priorities-too t
-  "*Non-nil makes `todo-save' automatically save top-priorities in `todo-file-top'."
+  "Non-nil makes `todo-save' automatically save top-priorities in `todo-file-top'."
   :type 'boolean
   :group 'todo)
 
@@ -355,17 +355,17 @@ Automatically generated when `todo-save-top-priorities' is non-nil."
 ;;
 (defcustom todo-time-string-format
   "%:y-%02m-%02d %02H:%02M"
-  "*TODO mode time string format for done entries.
+  "TODO mode time string format for done entries.
 For details see the variable `time-stamp-format'."
   :type 'string
   :group 'todo)
 
 (defcustom todo-entry-prefix-function 'todo-entry-timestamp-initials
-  "*Function producing text to insert at start of todo entry."
+  "Function producing text to insert at start of todo entry."
   :type 'symbol
   :group 'todo)
 (defcustom todo-initials (or (getenv "INITIALS") (user-login-name))
-  "*Initials of todo item author."
+  "Initials of todo item author."
   :type 'string
   :group 'todo)
 
@@ -538,12 +538,12 @@ Use `todo-categories' instead.")
     (widen)
     (goto-char (point-min))
     (let ((posn (search-forward "-*- mode: todo; " 17 t)))
-      (if (not (null posn)) (goto-char posn))
-      (if (equal posn nil)
+      (if posn
           (progn
-            (insert "-*- mode: todo; \n")
-            (forward-char -1))
-        (kill-line)))
+            (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"
@@ -577,7 +577,7 @@ Use `todo-categories' instead.")
              (setq bottom current)
            (setq top (1+ current)))))
       (setq top (/ (+ top bottom) 2))
-      ;; goto-line doesn't have the desired behavior in a narrowed buffer
+      ;; goto-line doesn't have the desired behavior in a narrowed buffer.
       (goto-char (point-min))
       (forward-line (1- top)))
     (insert new-item "\n")
@@ -592,7 +592,7 @@ With a prefix argument solicit the category, otherwise use the current
 category."
   (interactive "P")
   (save-excursion
-    (if (not (string-equal mode-name "TODO")) (todo-show))
+    (if (not (derived-mode-p 'todo-mode)) (todo-show))
     (let* ((new-item (concat todo-prefix " "
                             (read-from-minibuffer
                              "New TODO entry: "
@@ -615,7 +615,7 @@ category."
   "Insert new TODO list entry under the cursor."
   (interactive "")
   (save-excursion
-    (if (not (string-equal mode-name "TODO")) (todo-show))
+    (if (not (derived-mode-p 'todo-mode)) (todo-show))
     (let* ((new-item (concat todo-prefix " "
                             (read-from-minibuffer
                              "New TODO entry: "
@@ -625,14 +625,13 @@ category."
 
 (defun todo-more-important-p (line)
   "Ask whether entry is more important than the one at LINE."
-  (if (not (equal todo-previous-line line))
-      (progn
-        (setq todo-previous-line line)
-        (goto-char (point-min))
-        (forward-line (1- todo-previous-line))
-        (let ((item (todo-item-string-start)))
-          (setq todo-previous-answer
-                (y-or-n-p (concat "More important than '" item "'? "))))))
+  (unless (equal todo-previous-line line)
+    (setq todo-previous-line line)
+    (goto-char (point-min))
+    (forward-line (1- todo-previous-line))
+    (let ((item (todo-item-string-start)))
+      (setq todo-previous-answer
+            (y-or-n-p (concat "More important than '" item "'? ")))))
   todo-previous-answer)
 (defalias 'todo-ask-p 'todo-more-important-p)
 
@@ -643,10 +642,9 @@ category."
       (let* ((todo-entry (todo-item-string-start))
              (todo-answer (y-or-n-p (concat "Permanently remove '"
                                             todo-entry "'? "))))
-        (if todo-answer
-            (progn
-              (todo-remove-item)
-              (todo-backward-item)))
+        (when todo-answer
+          (todo-remove-item)
+          (todo-backward-item))
         (message ""))
     (error "No TODO list entry to delete")))
 (defalias 'todo-cmd-kill 'todo-delete-item)
@@ -684,15 +682,14 @@ category."
   (or (> (count-lines (point-min) (point-max)) 0)
       (error "No TODO list entry to file away"))
   (let ((time-stamp-format todo-time-string-format))
-    (if (and comment (> (length comment) 0))
-       (progn
-         (goto-char (todo-item-end))
-         (insert
-          (if (save-excursion (beginning-of-line)
-                              (looking-at (regexp-quote todo-prefix)))
-              " "
-            "\n\t")
-          "(" comment ")")))
+    (when (and comment (> (length comment) 0))
+      (goto-char (todo-item-end))
+      (insert
+       (if (save-excursion (beginning-of-line)
+                           (looking-at (regexp-quote todo-prefix)))
+           " "
+         "\n\t")
+       "(" comment ")"))
     (goto-char (todo-item-end))
     (insert " [" (nth todo-category-number todo-categories) "]")
     (goto-char (todo-item-start))
@@ -755,7 +752,7 @@ between each category."
           (replace-match todo-category-break)
           (narrow-to-region beg end)    ;In case we have too few entries.
           (goto-char (point-min))
-          (if (= 0 nof-priorities)      ;Traverse entries.
+          (if (zerop nof-priorities)      ;Traverse entries.
               (goto-char end)            ;All entries
             (todo-forward-item nof-priorities))
           (setq beg (point))
@@ -912,9 +909,11 @@ Number of entries for each category is given by `todo-print-priorities'."
   (easy-menu-add todo-menu)
   (run-mode-hooks 'todo-mode-hook))
 
-(eval-when-compile
-  (defvar date)
-  (defvar entry))
+(defvar date)
+(defvar entry)
+
+;; t-c should be used from diary code, which requires calendar.
+(declare-function calendar-current-date "calendar" nil)
 
 ;; Read about this function in the setup instructions above!
 ;;;###autoload
@@ -956,5 +955,5 @@ Number of entries for each category is given by `todo-print-priorities'."
 
 (provide 'todo-mode)
 
-;;; arch-tag: 6fd91be5-776e-4464-a109-da4ea0e4e497
+;; arch-tag: 6fd91be5-776e-4464-a109-da4ea0e4e497
 ;;; todo-mode.el ends here