comparison lisp/calendar/todo-mode.el @ 19179:dce72c66de1e

Fixed insertion routine with help from Trey Jackson <tjackson@ichips.intel.com>; added todo-ins-thresh; fixed keyboard layout to remove unwanted keys.
author Oliver Seidel <os10000@seidel-space.de>
date Tue, 05 Aug 1997 22:34:14 +0000
parents 8af428cb3906
children 5de82ccd80eb
comparison
equal deleted inserted replaced
19178:fa3161c7360b 19179:dce72c66de1e
4 4
5 ;; Note: You may copy this file freely for non-commercial use; otherwise, 5 ;; Note: You may copy this file freely for non-commercial use; otherwise,
6 ;; please contact (address) O Seidel, Lessingstr 8, Eschborn, FRG 6 ;; please contact (address) O Seidel, Lessingstr 8, Eschborn, FRG
7 ;; (e-mail ) Oliver.Seidel@cl.cam.ac.uk (2 Aug 1997) 7 ;; (e-mail ) Oliver.Seidel@cl.cam.ac.uk (2 Aug 1997)
8 8
9 ;; $Id: todomode.el,v 1.5 1997/08/05 14:43:39 os10000 Exp os10000 $ 9 ;; $Id: todomode.el,v 1.6 1997/08/05 16:47:01 os10000 Exp os10000 $
10 ;; 10 ;;
11 ;; $Log: todomode.el,v $ 11 ;; $Log: todomode.el,v $
12 ;; Revision 1.6 1997/08/05 16:47:01 os10000
13 ;; Incorporated menus for XEmacs from Allan.Cochrane@soton.sc.philips.com,
14 ;; fixed TYPO, fixed todo-file-cmd, cleaned up rcs history.
15 ;;
12 ;; Revision 1.5 1997/08/05 14:43:39 os10000 16 ;; Revision 1.5 1997/08/05 14:43:39 os10000
13 ;; Added improvements from Ron Gut <rgut@aware.com>. 17 ;; Added improvements from Ron Gut <rgut@aware.com>.
14 ;; Added category management. 18 ;; Added category management.
15 ;; 19 ;;
16 ;; Revision 1.4 1997/08/04 16:18:45 os10000 20 ;; Revision 1.4 1997/08/04 16:18:45 os10000
82 ;; For this, please read the documentation that goes with the calendar 86 ;; For this, please read the documentation that goes with the calendar
83 ;; since that will tell you how you can set up the fancy diary display 87 ;; since that will tell you how you can set up the fancy diary display
84 ;; and use the #include command to include your todo list file as part 88 ;; and use the #include command to include your todo list file as part
85 ;; of your diary. 89 ;; of your diary.
86 ;; 90 ;;
91 ;; Another nifty feature is the insertion accuracy. If you have 8 items
92 ;; in your TODO list, then you may get asked 4 questions by the binary
93 ;; insertion algorithm. However, you may not really have a need for such
94 ;; accurate priorities amongst your TODO items. If you now think about
95 ;; the binary insertion halfing the size of the window each time, then
96 ;; the threshhold is the window size at which it will stop. If you set
97 ;; the threshhold to zero, the upper and lower bound will coincide at the
98 ;; end of the loop and you will insert your item just before that point.
99 ;; If you set the threshhold to i.e. 8, it will stop as soon as the window
100 ;; size drops below that amount and will insert the item in the approximate
101 ;; centre of that window. I got the idea for this feature after reading
102 ;; a very helpful e-mail reply from Trey Jackson <tjackson@ichips.intel.com>
103 ;; who corrected some of my awful coding and pointed me towards some good
104 ;; reading. Thanks Trey!
105 ;;
87 ;; Enjoy this package and express your gratitude by sending valuables 106 ;; Enjoy this package and express your gratitude by sending valuables
88 ;; to my parents' address as listed above!!! 107 ;; to my parents' address as listed above!!!
89 ;; 108 ;;
90 ;; Oliver Seidel 109 ;; Oliver Seidel
91 110
95 114
96 (defvar todo-prefix "*/*" "TODO mode prefix when creating entries") 115 (defvar todo-prefix "*/*" "TODO mode prefix when creating entries")
97 (defvar todo-file-do "~/.todo-do" "TODO mode filename of list file") 116 (defvar todo-file-do "~/.todo-do" "TODO mode filename of list file")
98 (defvar todo-file-done "~/.todo-done" "TODO mode filename of archive file") 117 (defvar todo-file-done "~/.todo-done" "TODO mode filename of archive file")
99 (defvar todo-mode-hook nil "Hooks invoked when the *TODO* buffer is created.") 118 (defvar todo-mode-hook nil "Hooks invoked when the *TODO* buffer is created.")
119 (defvar todo-ins-thresh 0 "TODO mode insertion accuracy.")
100 120
101 ;; --------------------------------------------------------------------------- 121 ;; ---------------------------------------------------------------------------
102 122
103 (require 'time-stamp) 123 (require 'time-stamp)
104 124
105 (defvar todo-mode-map (make-sparse-keymap) "TODO mode keymap. See `todo-mode'") 125 (defvar todo-mode-map nil "TODO mode keymap. See `todo-mode'")
106 (define-key todo-mode-map "+" 'todo-cmd-forw) 126 (if todo-mode-map
107 (define-key todo-mode-map "-" 'todo-cmd-back) 127 nil
108 (define-key todo-mode-map "e" 'todo-cmd-edit) 128 (let ((map (make-keymap)))
109 (define-key todo-mode-map "f" 'todo-cmd-file) 129 (suppress-keymap map t)
110 (define-key todo-mode-map "i" 'todo-cmd-inst) 130 (define-key map "+" 'todo-cmd-forw)
111 (define-key todo-mode-map "k" 'todo-cmd-kill) 131 (define-key map "-" 'todo-cmd-back)
112 (define-key todo-mode-map "l" 'todo-cmd-lowr) 132 (define-key map "e" 'todo-cmd-edit)
113 (define-key todo-mode-map "n" 'todo-cmd-next) 133 (define-key map "f" 'todo-cmd-file)
114 (define-key todo-mode-map "p" 'todo-cmd-prev) 134 (define-key map "i" 'todo-cmd-inst)
115 (define-key todo-mode-map "q" 'todo-cmd-done) 135 (define-key map "k" 'todo-cmd-kill)
116 (define-key todo-mode-map "r" 'todo-cmd-rais) 136 (define-key map "l" 'todo-cmd-lowr)
117 (define-key todo-mode-map "s" 'todo-cmd-save) 137 (define-key map "n" 'todo-cmd-next)
138 (define-key map "p" 'todo-cmd-prev)
139 (define-key map "q" 'todo-cmd-done)
140 (define-key map "r" 'todo-cmd-rais)
141 (define-key map "s" 'todo-cmd-save)
142 (setq todo-mode-map map)))
118 143
119 (defun todo-cat-slct () 144 (defun todo-cat-slct ()
120 (let ((todo-category-name (nth todo-category-number todo-cats))) 145 (let ((todo-category-name (nth todo-category-number todo-cats)))
121 (setq mode-line-buffer-identification (concat "Category: " todo-category-name)) 146 (setq mode-line-buffer-identification (concat "Category: " todo-category-name))
122 (widen) 147 (widen)
187 ) 212 )
188 ) 213 )
189 214
190 (defvar todo-prv-lne 0 "previous line that I asked about.") 215 (defvar todo-prv-lne 0 "previous line that I asked about.")
191 (defvar todo-prv-ans 0 "previous answer that I got.") 216 (defvar todo-prv-ans 0 "previous answer that I got.")
192
193 (defun todo-ask (lne) "Ask whether entry is more important than at LNE."
194 (if (not (equal todo-prv-lne lne))
195 (progn
196 (setq todo-prv-lne lne)
197 (goto-line todo-prv-lne)
198 (setq todo-prv-ans (y-or-n-p (concat "More important than '" (todo-line) "'? ")))
199 )
200 )
201 todo-prv-ans
202 )
203 217
204 (defun todo-add-category (cat) "Add a new category to the TODO list." 218 (defun todo-add-category (cat) "Add a new category to the TODO list."
205 (interactive) 219 (interactive)
206 (save-window-excursion 220 (save-window-excursion
207 (setq todo-cats (cons cat todo-cats)) 221 (setq todo-cats (cons cat todo-cats))
217 (insert (format "%s --- %s\n--- End\n%s %s\n" todo-prefix cat todo-prefix (make-string 75 ?-))) 231 (insert (format "%s --- %s\n--- End\n%s %s\n" todo-prefix cat todo-prefix (make-string 75 ?-)))
218 ) 232 )
219 0 233 0
220 ) 234 )
221 235
222 (defun todo-cmd-inst () "Insert new TODO list entry." 236 (defun todo-cmd-inst ()
237 "Insert new TODO list entry."
223 (interactive) 238 (interactive)
224 (beginning-of-line nil) 239 (beginning-of-line nil)
225 (let* ((todo-entry (concat todo-prefix " " (read-from-minibuffer "New TODO entry: "))) 240 (let* ((todo-entry (concat todo-prefix " " (read-from-minibuffer "New TODO entry: ")))
226 (temp-catgs todo-cats) 241 (temp-catgs todo-cats)
227 (todo-hstry (cons 'temp-catgs (+ todo-category-number 1)))) 242 (todo-hstry (cons 'temp-catgs (+ todo-category-number 1))))
228 (save-window-excursion 243 (save-window-excursion
229 (setq todo-category 244 (setq todo-category
230 (read-from-minibuffer "Category: " (nth todo-category-number todo-cats) nil nil todo-hstry)) 245 (read-from-minibuffer "Category: "
231 (let* ((ltrgt todo-category) 246 (nth todo-category-number todo-cats)
232 (lnmbr 0) 247 nil nil todo-hstry))
233 (ltext (car todo-cats)) 248
234 (lrest (cdr todo-cats))) 249 (let ((cat-exists (member todo-category todo-cats)))
235 (setq ltext (car todo-cats)) 250 (setq todo-category-number
236 (while (not (or (null lrest) (string-equal ltext ltrgt))) 251 (if cat-exists
237 (setq ltext (car lrest)) 252 (- (length todo-cats) (length cat-exists))
238 (setq lrest (cdr lrest)) 253 (todo-add-category todo-category))))
239 (setq lnmbr (+ 1 lnmbr))
240 )
241 (setq todo-category-number
242 (if (string-equal ltext todo-category) lnmbr (todo-add-category todo-category)))
243 )
244 (todo-show) 254 (todo-show)
245 (setq todo-prv-lne 0) 255 (setq todo-prv-lne 0)
246 (let* ((todo-fst 1) 256
247 (todo-lst (+ 1 (count-lines (point-min) (point-max))))) 257 (let ((todo-fst 1)
248 (while (< todo-fst todo-lst) 258 (todo-lst (+ 1 (count-lines (point-min) (point-max)))))
249 (let* ((todo-cur (/ (+ todo-fst todo-lst) 2)) 259 (while (> (- todo-lst todo-fst) todo-ins-thresh)
250 (todo-ans (if (< todo-cur todo-lst) (todo-ask todo-cur) nil))) 260 (let* ((todo-cur (/ (+ todo-fst todo-lst) 2))
251 (if todo-ans 261 (todo-ans (if (< todo-cur todo-lst) (todo-ask todo-cur) nil)))
252 (setq todo-lst todo-cur) 262 (if todo-ans
253 (setq todo-fst (+ todo-cur 1))) 263 (setq todo-lst todo-cur)
254 ) 264 (setq todo-fst (+ todo-cur 1)))))
255 ) 265
256 (goto-line todo-fst) 266 (setq todo-fst (/ (+ todo-fst todo-lst) 2))
257 ) 267 ;; goto-line doesn't have the desired behavior in a narrowed buffer
268 (goto-char (point-min))
269 (message (format "todo-fst=%d" todo-fst))
270 (forward-line (- todo-fst 1)))
271
258 (insert (concat todo-entry "\n")) 272 (insert (concat todo-entry "\n"))
259 (forward-line -1) 273 (forward-line -1))
260 )
261 (beginning-of-line nil) 274 (beginning-of-line nil)
262 (message "") 275 (message "")))
263 ) 276
264 ) 277 (defun todo-ask (lne)
278 "Ask whether entry is more important than at LNE."
279 (if (not (equal todo-prv-lne lne))
280 (progn
281 (setq todo-prv-lne lne)
282 (goto-char (point-min))
283 (forward-line (- todo-prv-lne 1))
284 (setq todo-prv-ans (y-or-n-p (concat "More important than '" (todo-line) "'? ")))))
285 todo-prv-ans)
265 286
266 (defun todo-cmd-kill () "Delete current TODO list entry." 287 (defun todo-cmd-kill () "Delete current TODO list entry."
267 (interactive) 288 (interactive)
268 (if (> (count-lines (point-min) (point-max)) 0) 289 (if (> (count-lines (point-min) (point-max)) 0)
269 (progn 290 (progn