(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
[emacs.git] / lisp / calendar / todo-mode.el
blobbcf298e9b9ad8ee2e95adb38ae0f7cd0b71e513c
1 ;; todo-mode.el -- Major mode for editing TODO list files
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
5 ;; Author: Oliver.Seidel@cl.cam.ac.uk (was valid on Aug 2, 1997)
6 ;; Created: 2 Aug 1997
7 ;; Version: $Id: todo-mode.el,v 1.37 1999/03/18 08:53:48 os10000 Exp os10000 $
8 ;; Keywords: Categorised TODO list editor, todo-mode
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
27 ;; ---------------------------------------------------------------------------
29 ;;; Commentary:
31 ;; Mode Description
33 ;; TODO is a major mode for EMACS which offers functionality to
34 ;; treat most lines in one buffer as a list of items one has to
35 ;; do. There are facilities to add new items, which are
36 ;; categorised, to edit or even delete items from the buffer.
37 ;; The buffer contents are currently compatible with the diary,
38 ;; so that the list of todo-items will show up in the FANCY diary
39 ;; mode.
41 ;; Notice: Besides the major mode, this file also exports the
42 ;; function `todo-show' which will change to the one specific
43 ;; TODO file that has been specified in the todo-file-do
44 ;; variable. If this file does not conform to the TODO mode
45 ;; conventions, the todo-show function will add the appropriate
46 ;; header and footer. I don't anticipate this to cause much
47 ;; grief, but be warned, in case you attempt to read a plain text
48 ;; file.
50 ;; Preface, Quickstart Installation
52 ;; To get this to work, make emacs execute the line
54 ;; (autoload 'todo-mode "todo-mode"
55 ;; "Major mode for editing TODO lists." t)
56 ;; (autoload 'todo-show "todo-mode"
57 ;; "Show TODO items." t)
58 ;; (autoload 'todo-insert-item "todo-mode"
59 ;; "Add TODO item." t)
61 ;; You may now enter new items by typing "M-x todo-insert-item",
62 ;; or enter your TODO list file by typing "M-x todo-show".
64 ;; -------------------------------------------------------------
66 ;; oh no, it doesn't work any more ... but Alex Schroeder
67 ;; <a.schroeder@bsiag.ch> writes:
69 ;; -------------------------------------------------------------
71 ;; 1. Call todo-show (I called todo-insert first)
72 ;; 2. Add some categories (I called todo-insert)
73 ;; 3. Save the buffer, restart Emacs (perhaps restarting Emacs is not
74 ;; required)
75 ;; 4. Only now can you start to add entries.
77 ;; This is a bit cumbersome, and it should be documented. You probably
79 ;; -------------------------------------------------------------
81 ;; and right he is. My apologies, I'll try to fix it sometime.
83 ;; -------------------------------------------------------------
85 ;; The TODO list file has a special format and some auxiliary
86 ;; information, which will be added by the todo-show function if
87 ;; it attempts to visit an un-initialised file. Hence it is
88 ;; recommended to use the todo-show function for the first time,
89 ;; in order to initialise the file, but it is not necessary
90 ;; afterwards.
92 ;; As these commands are quite long to type, I would recommend
93 ;; the addition of two bindings to your to your global keymap. I
94 ;; personally have the following in my initialisation file:
96 ;; (global-set-key "\C-ct" 'todo-show) ;; switch to TODO buffer
97 ;; (global-set-key "\C-ci" 'todo-insert-item) ;; insert new item
99 ;; Note, however, that this recommendation has prompted some
100 ;; criticism, since the keys C-c LETTER are reserved for user
101 ;; functions. I believe my recommendation is acceptable, since
102 ;; the Emacs Lisp Manual *Tips* section also details that the
103 ;; mode itself should not bind any functions to those keys. The
104 ;; express aim of the above two bindings is to work outside the
105 ;; mode, which doesn't need the show function and offers a
106 ;; different binding for the insert function. They serve as
107 ;; shortcuts and are not even needed (since the TODO mode will be
108 ;; entered by visiting the TODO file, and later by switching to
109 ;; its buffer).
111 ;; If you are an advanced user of this package, please consult
112 ;; the whole source code for autoloads, because there are several
113 ;; extensions that are not explicitly listed in the above quick
114 ;; installation.
116 ;; Version
118 ;; Which version of todo-mode.el does this documentation refer to?
120 ;; $Id: todo-mode.el,v 1.37 1999/03/18 08:53:48 os10000 Exp os10000 $
122 ;; Pre-Requisites
124 ;; This package will require the following packages to be
125 ;; available on the load-path:
127 ;; cl
128 ;; custom
129 ;; easymenu
130 ;; time-stamp
132 ;; Operation
134 ;; You will have the following facilities available:
136 ;; M-x todo-show will enter the todo list screen, here type
138 ;; spc will toggle the display of sub-trees
140 ;; + to go to next category
141 ;; - to go to previous category
142 ;; d to file the current entry, including a
143 ;; comment and timestamp
144 ;; e to edit the current entry
145 ;; E to edit a multi-line entry
146 ;; f to file the current entry, including a
147 ;; comment and timestamp
148 ;; i to insert a new entry, with prefix, omit category
149 ;; I to insert a new entry at current cursor position
150 ;; j jump to category
151 ;; k to kill the current entry
152 ;; l to lower the current entry's priority
153 ;; n for the next entry
154 ;; p for the previous entry
155 ;; P print
156 ;; q to save the list and exit the buffer
157 ;; r to raise the current entry's priority
158 ;; s to save the list
159 ;; S to save the list of top priorities
160 ;; t show top priority items for each category
162 ;; When you add a new entry, you are asked for the text and then
163 ;; for the category. I for example have categories for things
164 ;; that I want to do in the office (like mail my mum), that I
165 ;; want to do in town (like buy cornflakes) and things I want to
166 ;; do at home (move my suitcases). The categories can be
167 ;; selected with the cursor keys and if you type in the name of a
168 ;; category which didn't exist before, an empty category of the
169 ;; desired name will be added and filled with the new entry.
171 ;; Configuration
173 ;; Variable todo-prefix
175 ;; I would like to recommend that you use the prefix "*/*" (by
176 ;; leaving the variable 'todo-prefix' untouched) so that the
177 ;; diary displays each entry every day.
179 ;; To understand what I mean, please read the documentation that
180 ;; goes with the calendar since that will tell you how you can
181 ;; set up the fancy diary display and use the #include command to
182 ;; include your todo list file as part of your diary.
184 ;; If you have the diary package set up to usually display more
185 ;; than one day's entries at once, consider using
187 ;; "&%%(equal (calendar-current-date) date)"
189 ;; as the value of `todo-prefix'. Please note that this may slow
190 ;; down the processing of your diary file some.
192 ;; Carsten Dominik <dominik@strw.LeidenUniv.nl> suggested that
194 ;; "&%%(todo-cp)"
196 ;; might be nicer and to that effect a function has been declared
197 ;; further down in the code. You may wish to auto-load this.
199 ;; Carsten also writes that that *changing* the prefix after the
200 ;; todo list is already established is not as simple as changing
201 ;; the variable - the todo files have to be changed by hand.
203 ;; Variable todo-file-do
205 ;; This variable is fairly self-explanatory. You have to store
206 ;; your TODO list somewhere. This variable tells the package
207 ;; where to go and find this file.
209 ;; Variable todo-file-done
211 ;; Even when you're done, you may wish to retain the entries.
212 ;; Given that they're timestamped and you are offered to add a
213 ;; comment, this can make a useful diary of past events. It will
214 ;; even blend in with the EMACS diary package. So anyway, this
215 ;; variable holds the name of the file for the filed todo-items.
217 ;; Variable todo-file-top
219 ;; File storing the top priorities of your TODO list when
220 ;; todo-save-top-priorities is non-nil. Nice to include in your
221 ;; diary instead of the complete TODO list.
223 ;; Variable todo-mode-hook
225 ;; Just like other modes, too, this mode offers to call your
226 ;; functions before it goes about its business. This variable
227 ;; will be inspected for any functions you may wish to have
228 ;; called once the other TODO mode preparations have been
229 ;; completed.
231 ;; Variable todo-insert-threshold
233 ;; Another nifty feature is the insertion accuracy. If you have
234 ;; 8 items in your TODO list, then you may get asked 4 questions
235 ;; by the binary insertion algorithm. However, you may not
236 ;; really have a need for such accurate priorities amongst your
237 ;; TODO items. If you now think about the binary insertion
238 ;; halfing the size of the window each time, then the threshhold
239 ;; is the window size at which it will stop. If you set the
240 ;; threshhold to zero, the upper and lower bound will coincide at
241 ;; the end of the loop and you will insert your item just before
242 ;; that point. If you set the threshhold to, e.g. 8, it will stop
243 ;; as soon as the window size drops below that amount and will
244 ;; insert the item in the approximate centre of that window. I
245 ;; got the idea for this feature after reading a very helpful
246 ;; e-mail reply from Trey Jackson <trey@cs.berkeley.edu> who
247 ;; corrected some of my awful coding and pointed me towards some
248 ;; good reading. Thanks Trey!
250 ;; Things to do
252 ;; These originally were my ideas, but now also include all the
253 ;; suggestions that I included before forgetting them:
255 ;; o Fancy fonts for todo/top-priority buffer
256 ;; o Remove todo-prefix option in todo-top-priorities
257 ;; o Rename category
258 ;; o Move entry from one category to another one
259 ;; o Entries which both have the generic */* prefix and a
260 ;; "deadline" entry which are understood by diary, indicating
261 ;; an event (unless marked by &)
262 ;; o The optional COUNT variable of todo-forward-item should be
263 ;; applied to the other functions performing similar tasks
264 ;; o Modularization could be done for repeaded elements of
265 ;; the code, like the completing-read lines of code.
266 ;; o license / version function
267 ;; o export to diary file
268 ;; o todo-report-bug
269 ;; o GNATS support
270 ;; o elide multiline (as in bbdb, or, to a lesser degree, in
271 ;; outline mode)
272 ;; o rewrite complete package to store data as lisp objects
273 ;; and have display modes for display, for diary export,
274 ;; etc. (Richard Stallman pointed out this is a bad idea)
275 ;; o so base todo-mode.el on generic-mode.el instead
277 ;; History and Gossip
279 ;; Many thanks to all the ones who have contributed to the
280 ;; evolution of this package! I hope I have listed all of you
281 ;; somewhere in the documentation or at least in the RCS history!
283 ;; Enjoy this package and express your gratitude by sending nice
284 ;; things to my parents' address!
286 ;; Oliver Seidel
287 ;; (Lessingstr. 8, 65760 Eschborn, Federal Republic of Germany)
290 ;; ---------------------------------------------------------------------------
292 ;;; Change Log:
294 ;; $Log: todo-mode.el,v $
295 ;; Revision 1.37 1999/03/18 08:53:48 os10000
296 ;; Marc Zonzon <Marc.Zonzon@univ-rennes1.fr> on 18.Mar.99 writes that I
297 ;; should remove the single space between ### and autoload. And now I
298 ;; have.
300 ;; Revision 1.36 1999/03/17 11:10:29 os10000
301 ;; Alastair Burt <alastair.burt@dfki.de> sent in a patch on 17.Mar.98
302 ;; which removes duplicates from the category list and saves the buffer
303 ;; after category addition. Thanks.
305 ;; Uwe Brauer <oub@sunma4.mat.ucm.es> sent in a request on 3.Apr.98 to
306 ;; implement a "move-between-categories" function. I haven't done that
307 ;; yet. Thanks.
309 ;; "Edward S. Hirgelt" <ehirgelt@directinterfaces.com> fixed a problem
310 ;; with multi-line editing 29.Oct.98. Thanks.
312 ;; tom <tom@pixelpark.com> sent in a replacement for the outmoded
313 ;; time-format that I had been using on 13.Nov.98. Thanks.
315 ;; Jerome Thebert <thebertj@felixstowe.rms.slb.com> sent in a binding to
316 ;; show/hide continuation lines using the space bar on 11.Jan.99.
317 ;; Instead of leaving it as a hook, I integrated it. Thanks.
319 ;; Sorry again to everybody. I sat on your patches for a year.
321 ;; Revision 1.35 1998/09/29 18:20:36 os10000
322 ;; Alex Schroeder startup description added.
324 ;; Revision 1.34 1998/01/12 11:43:22 os10000
325 ;; Added patch from Don Hejna <djhejna@oasis.ambit.com>.
327 ;; Revision 1.33 1997/12/04 17:45:22 os10000
328 ;; Another patch by Michael Cook to fix annotation.
330 ;; Revision 1.32 1997/12/03 12:18:20 os10000
331 ;; Added category patch by Michael R Cook <mcook@cognex.com>.
333 ;; Revision 1.31 1997/10/28 22:16:24 os10000
334 ;; Three insertion options:
335 ;; i without prefix: ask for category, do binary insertion
336 ;; i with prefix: do binary insertion in current category
337 ;; uppercase I: insert directly under cursor
339 ;; Revision 1.30 1997/10/28 21:59:48 os10000
340 ;; Improved documentation, fixed insertion with prefix.
342 ;; Revision 1.29 1997/10/28 21:47:12 os10000
343 ;; Implemented "insert-under-cursor" as suggested by
344 ;; Kai Grossjohann <grossjohann@ls6.cs.uni-dortmund.de>.
346 ;; Revision 1.28 1997/10/28 21:37:05 os10000
347 ;; Incorporated simplifying suggestions from
348 ;; Carsten Dominik <dominik@strw.LeidenUniv.nl>.
350 ;; Revision 1.27 1997/10/28 21:26:55 os10000
351 ;; Patch from Paul Stodghill <stodghil@CS.Cornell.EDU>:
352 ;; The patch below fixes todo-insert-item so that it will
353 ;; insert the item in place, instead of at the top of the
354 ;; buffer, when invoked with a prefix argument.
356 ;; Revision 1.26 1997/10/28 21:14:51 os10000
357 ;; Improvements sent in by Dave Love <d.love@dl.ac.uk>:
358 ;; todo-mode.el: Doc fixes. Customization.
359 ;; (todo-add-item-non-interactively): New arg -- don't dynamically bind ARG.
360 ;; (todo-insert-item): Use it.
362 ;; Revision 1.25 1997/10/28 20:03:27 os10000
363 ;; Harald Backer <harald.backer@fou.telenor.no> sent the following:
364 ;; Added `todo-save-top-priorities' and option to automatically save top
365 ;; priorities file when saving todo-file. Changed some default values.
366 ;; Bug fixes.
368 ;; Revision 1.24 1997/10/28 19:41:53 os10000
369 ;; Added fix from Frank Ridderbusch <ridderbusch.pad@sni.de>,
370 ;; an apostrophe was missing.
372 ;; Revision 1.23 1997/10/24 17:30:54 os10000
373 ;; Added three suggestions from Carsten
374 ;; Dominik <dominik@strw.LeidenUniv.nl>:
376 ;; - recommend autoloading instead of require
377 ;; - inserting from different buffer didn't work
378 ;; (now fixed -- I pray)
379 ;; - provided public entry point to insert items
380 ;; from normal lisp code
382 ;; Revision 1.22 1997/10/24 16:53:20 os10000
383 ;; Paul Stodghill <stodghil@CS.Cornell.EDU> writes:
385 ;; When invoked with a prefix, todo-insert-item
386 ;; should not prompt for a category. (He adds:
387 ;; At least that's what I think.)
389 ;; Revision 1.21 1997/10/24 16:51:02 os10000
390 ;; Rafael Laboissiere <rafael@icp.inpg.fr> writes:
392 ;; I was just annoyed with the fact that there is no way
393 ;; to dynamically control the insertion accuracy. I mean:
394 ;; the variable `todo-insert-threshold' does the job, but
395 ;; it is not very handy if one wants to mix the two
396 ;; behaviors (bisection and "insert right here under the
397 ;; cursor").
399 ;; Therefore I did a quick hack in the function
400 ;; `todo-insert-item'. Now by giving a prefix argument to
401 ;; the insert command (i.e. by typing "C-u i"), entries
402 ;; are inserted exactly at the line where the cursor is.
403 ;; It would be better to give the value of
404 ;; `todo-insert-threshold' as a numeric argument of
405 ;; `todo-insert-item' (like "M-8 i"), but it's too late
406 ;; now for continuing to hack.
408 ;; Revision 1.20 1997/10/17 15:41:57 os10000
409 ;; Thanks to Harald Backer <harald.backer@fou.telenor.no>, we now have
410 ;; the following facilities available:
412 ;; Added todo-print, todo-top-priorities and todo-jump with matching
413 ;; variables; Parameterized todo-header, todo-category-beg,
414 ;; todo-category-end and todo-category-sep; Added autoload comments;
415 ;; todo-category-select: Modified regexp to make category names unique;
416 ;; todo-forward-item: Added optional COUNT vaiable; todo-insert-item:
417 ;; Rewrote completing read entry.
419 ;; Also, check out the extended list of things left to be done to this
420 ;; package at the end of the documentation!
422 ;; Revision 1.19 1997/10/16 21:21:16 os10000
423 ;; Jari Aalto <jari.aalto@poboxes.com> writes:
425 ;; I just downloaded your package and after reading the docs I
426 ;; decided to do some reformatting. Hope you don't mind. Now
427 ;; they are in such a format that the html page can be
428 ;; automatically generated from the source file. As an example, I
429 ;; generated the attached page using the following command:
430 ;; ripdoc.pls < todo-mode.el | t2html.pls -a "Oliver.Seidel" -e \
431 ;; Oliver.Seidel@cl.cam.ac.uk -simple -base
433 ;; And of course I appreciate it. Jari's stuff can be found at:
434 ;; ftp://cs.uta.fi/pub/ssjaaa/, while I'm making the rev 1.18 page
435 ;; available at http://www.cl.cam.ac.uk/users/os10000/doc/todo-mode.html
436 ;; (That link will be valid until 10/1998 or slightly longer.)
438 ;; Revision 1.18 1997/10/15 17:18:11 os10000
439 ;; Everything seems to work in Harald Melands Emacs 20.02 and
440 ;; my Emacs 19.34. Beware of the spelling in some of the
441 ;; variable names. I looked up "threshold" in a dictionary
442 ;; and here in Britain this appears to be the way to spell it.
444 ;; Revision 1.17 1997/10/15 14:30:41 os10000
445 ;; Attempted to reconcile Harald's changes with mine since 1.15.
447 ;; Revision 1.16 1997/10/15 14:00:12 os10000
448 ;; Fixed 'file-item' and added 20.02 split-string function.
450 ;; Revision 1.15 1997/10/14 22:22:35 os10000
451 ;; Added string-split (which I stole from ediff-util), changed
452 ;; pop-to-buffer to switch-to-buffer and added message on how
453 ;; to exit the multi-line-edit mode.
455 ;; Revision 1.14 1997/10/09 09:24:50 os10000
456 ;; Harald Meland <harald.meland@usit.uio.no> asked for
457 ;; the latest version, got 1.13, and returned this.
458 ;; He writes:
460 ;; Thanks a lot for the new version of todo-mode.el. As you will see I
461 ;; have messed it up a bit, hopefully for the better -- I don't like
462 ;; short, cryptic names for variables and functions, so I renamed most of
463 ;; them, and `defalias'ed the old function names. I hope you don't mind
464 ;; too much, I just kinda couldn't stop myself.
466 ;; Additionally, I included some support for multiline entries, cleaned
467 ;; up (IMHO :) a lot of the code, included completion-support for which
468 ;; category to install a new entry in, and possibly some other changes I
469 ;; can't remember :)
471 ;; It's getting rather late, and I have just done some preliminary
472 ;; testing on whether all of this really works, but so far it looks
473 ;; good.
475 ;; Revision 1.13 1997/08/19 14:00:36 seidel
476 ;; - changed name to todo-mode
477 ;; - fixed menu descriptions
478 ;; - fixed "pressing abort while filing"
479 ;; - attempted Emacs Lisp Manual *Tips* section compliance
481 ;; Revision 1.12 1997/08/06 10:56:15 os10000
482 ;; Fixed header, typos, layout, documentation.
484 ;; Revision 1.11 1997/08/06 09:14:25 os10000
485 ;; Applied patch from Istvan Marko <istvan@cmdmail.amd.com>
486 ;; to make menus work anywhere.
488 ;; Revision 1.10 1997/08/06 08:56:03 os10000
489 ;; Acted upon suggestion from Shane Holder <holder@rsn.hp.com>:
490 ;; Cancelling the editing of an entry will not delete it any more.
492 ;; Revision 1.9 1997/08/06 08:12:03 os10000
493 ;; Improved documentation. Broke some lines to comply with
494 ;; Richard Stallman's email to please keep in sync with the
495 ;; rest of the Emacs distribution files.
497 ;; Revision 1.8 1997/08/05 22:39:04 os10000
498 ;; Made todo-mode.el available under GPL.
500 ;; Revision 1.7 1997/08/05 22:34:14 os10000
501 ;; Fixed insertion routine with help from Trey Jackson
502 ;; <trey@cs.berkeley.edu>; added todo-inst-tresh;
503 ;; fixed keyboard layout to remove unwanted keys.
505 ;; Revision 1.6 1997/08/05 16:47:01 os10000
506 ;; Incorporated menus for XEmacs from Allan.Cochrane@soton.sc.philips.com,
507 ;; fixed TYPO, fixed todo-file-cmd, cleaned up rcs history.
509 ;; Revision 1.5 1997/08/05 14:43:39 os10000
510 ;; Added improvements from Ron Gut <rgut@aware.com>.
511 ;; Added category management.
513 ;; Revision 1.4 1997/08/04 16:18:45 os10000
514 ;; Added Raise/Lower item.
516 ;; Revision 1.3 1997/08/03 12:47:26 os10000
517 ;; Cleaned up variables, prefix and cursor position.
519 ;; Revision 1.2 1997/08/03 12:15:28 os10000
520 ;; It appears to work.
522 ;; Revision 1.1 1997/08/03 12:15:13 os10000
523 ;; Initial revision
526 ;; ---------------------------------------------------------------------------
528 ;;; Code:
530 (eval-and-compile ; Removable for installation in
531 ; Emacs 20.
532 (condition-case ()
533 (require 'custom)
534 (error nil))
535 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
536 nil ;; We've got what we needed
537 ;; We have the old custom-library, hack around it!
538 (defmacro defgroup (&rest args)
539 nil)
540 (defmacro defcustom (var value doc &rest args)
541 (` (defvar (, var) (, value) (, doc))))))
543 ;; User-configurable variables:
545 (defgroup todo nil
546 "Maintain a list of todo items."
547 :group 'calendar)
549 (defcustom todo-prefix "*/*"
550 "*TODO mode prefix for entries.
552 This is useful in conjunction with `calendar' and `diary' if you use
554 #include \"~/.todo-do\"
556 in your diary file to include your todo list file as part of your
557 diary. With the default value \"*/*\" the diary displays each entry
558 every day and it may also be marked on every day of the calendar.
559 Using \"&%%(equal (calendar-current-date) date)\" instead will only
560 show and mark todo entreis for today, but may slow down processing of
561 the diary file somewhat."
562 :type 'string
563 :group 'todo)
564 (defcustom todo-file-do "~/.todo-do"
565 "*TODO mode list file."
566 :type 'file
567 :group 'todo)
568 (defcustom todo-file-done "~/.todo-done"
569 "*TODO mode archive file."
570 :type 'file
571 :group 'todo)
572 (defcustom todo-mode-hook nil
573 "*TODO mode hooks."
574 :type 'hook
575 :group 'todo)
576 (defcustom todo-edit-mode-hook nil
577 "*TODO Edit mode hooks."
578 :type 'hook
579 :group 'todo)
580 (defcustom todo-insert-threshold 0
581 "*TODO mode insertion accuracy.
583 If you have 8 items in your TODO list, then you may get asked 4
584 questions by the binary insertion algorithm. However, you may not
585 really have a need for such accurate priorities amongst your TODO
586 items. If you now think about the binary insertion halfing the size
587 of the window each time, then the threshhold is the window size at
588 which it will stop. If you set the threshhold to zero, the upper and
589 lower bound will coincide at the end of the loop and you will insert
590 your item just before that point. If you set the threshhold to,
591 e.g. 8, it will stop as soon as the window size drops below that
592 amount and will insert the item in the approximate centre of that
593 window."
594 :type 'integer
595 :group 'todo)
596 (defvar todo-edit-buffer " *TODO Edit*" "TODO Edit buffer name.")
597 (defcustom todo-file-top "~/.todo-top"
598 "*TODO mode top priorities file.
600 Not in TODO format, but diary compatible.
601 Automatically generated when `todo-save-top-priorities' is non-nil."
602 :type 'string
603 :group 'todo)
605 (defcustom todo-print-function 'ps-print-buffer-with-faces
606 "*Function to print the current buffer."
607 :type 'symbol
608 :group 'todo)
609 (defcustom todo-show-priorities 1
610 "*Default number of priorities to show by \\[todo-top-priorities].
611 0 means show all entries."
612 :type 'integer
613 :group 'todo)
614 (defcustom todo-print-priorities 0
615 "*Default number of priorities to print by \\[todo-print].
616 0 means print all entries."
617 :type 'integer
618 :group 'todo)
619 (defcustom todo-remove-separator t
620 "*Non-nil to remove category separators in\
621 \\[todo-top-priorities] and \\[todo-print]."
622 :type 'boolean
623 :group 'todo)
624 (defcustom todo-save-top-priorities-too t
625 "*Non-nil makes todo-save automatically save top-priorities in
626 `todo-file-top'."
627 :type 'boolean
628 :group 'todo)
630 ;; Thanks for the ISO time stamp format go to Karl Eichwalder <ke@suse.de>
631 ;; My format string for the appt.el package is "%3b %2d, %y, %02I:%02M%p".
633 (defcustom todo-time-string-format
634 "%04y-%02m-%02d %02H:%02M"
635 "*TODO mode time string format for done entries.
636 For details see the variable `time-stamp-format'."
637 :type 'string
638 :group 'todo)
640 (defcustom todo-entry-prefix-function 'todo-entry-timestamp-initials
641 "*Function producing text to insert at start of todo entry."
642 :type 'symbol
643 :group 'todo)
644 (defcustom todo-initials (or (getenv "INITIALS") (user-login-name))
645 "*Initials of todo item author."
646 :type 'string
647 :group 'todo)
649 (defun todo-entry-timestamp-initials ()
650 "Prepend timestamp and your initials to the head of a TODO entry."
651 (let ((time-stamp-format todo-time-string-format))
652 (concat (time-stamp-string) " " todo-initials ": ")))
654 ;; ---------------------------------------------------------------------------
656 ;; Get some outside help ...
658 (require 'cl)
659 (require 'easymenu)
660 (require 'time-stamp)
662 ;; ---------------------------------------------------------------------------
664 ;; Set up some helpful context ...
666 (defvar todo-categories nil "TODO categories.")
667 (defvar todo-cats nil
668 "Old variable for holding the TODO categories.
669 Use `todo-categories' instead.")
670 (defvar todo-previous-line 0 "Previous line that I asked about.")
671 (defvar todo-previous-answer 0 "Previous answer that I got.")
672 (defvar todo-mode-map nil "TODO mode keymap.")
673 (defvar todo-category-number 0 "TODO category number.")
675 (defvar todo-tmp-buffer-name "*Tmp*")
677 (defvar todo-category-sep (make-string 75 ?-)
678 "Category separator.")
679 (defvar todo-category-beg " --- "
680 "Category start separator to be prepended onto category name.")
681 (defvar todo-category-end "--- End"
682 "Separator after a category.")
683 (defvar todo-header "-*- mode: todo; "
684 "Header of todo files.")
688 ;; ---------------------------------------------------------------------------
690 (if todo-mode-map
692 (let ((map (make-keymap)))
693 (suppress-keymap map t)
694 (define-key map "?" 'todo-help)
695 (define-key map " " 'todo-hide-show-subtree)
696 (define-key map "+" 'todo-forward-category)
697 (define-key map "-" 'todo-backward-category)
698 (define-key map "d" 'todo-file-item) ;done/delete
699 (define-key map "e" 'todo-edit-item)
700 (define-key map "E" 'todo-edit-multiline)
701 (define-key map "f" 'todo-file-item)
702 (define-key map "i" 'todo-insert-item)
703 (define-key map "I" 'todo-insert-item-here)
704 (define-key map "j" 'todo-jump-to-category)
705 (define-key map "k" 'todo-delete-item)
706 (define-key map "l" 'todo-lower-item)
707 (define-key map "n" 'todo-forward-item)
708 (define-key map "p" 'todo-backward-item)
709 (define-key map "P" 'todo-print)
710 (define-key map "q" 'todo-quit)
711 (define-key map "r" 'todo-raise-item)
712 (define-key map "s" 'todo-save)
713 (define-key map "S" 'todo-save-top-priorities)
714 (define-key map "t" 'todo-top-priorities)
715 (setq todo-mode-map map)))
717 (defun todo-category-select ()
718 "Make TODO mode display the current category correctly."
719 (let ((name (nth todo-category-number todo-categories)))
720 (setq mode-line-buffer-identification
721 (concat "Category: " (format "%18s" name)))
722 (widen)
723 (goto-char (point-min))
724 (search-forward-regexp
725 (concat "^"
726 (regexp-quote (concat todo-prefix todo-category-beg name))
727 "$"))
728 (let ((begin (1+ (point-at-eol))))
729 (search-forward-regexp (concat "^" todo-category-end))
730 (narrow-to-region begin (point-at-bol))
731 (goto-char (point-min)))))
732 (defalias 'todo-cat-slct 'todo-category-select)
734 (defun todo-help () "Show TODO mode help."
735 (interactive)
736 (describe-function 'todo-mode))
738 (defun todo-hide-show-subtree () "Hide or Show subtrees in the TODO list."
739 (interactive)
740 (save-excursion
741 (end-of-line)
742 (if (outline-visible)
743 (hide-subtree)
744 (show-subtree))))
746 (defun todo-forward-category () "Go forward to TODO list of next category."
747 (interactive)
748 (setq todo-category-number
749 (mod (1+ todo-category-number) (length todo-categories)))
750 (todo-category-select))
751 (defalias 'todo-cmd-forw 'todo-forward-category)
753 (defun todo-backward-category () "Go back to TODO list of previous category."
754 (interactive)
755 (setq todo-category-number
756 (mod (1- todo-category-number) (length todo-categories)))
757 (todo-category-select))
758 (defalias 'todo-cmd-back 'todo-backward-category)
760 (defun todo-backward-item () "Select previous entry of TODO list."
761 (interactive)
762 (search-backward-regexp (concat "^" (regexp-quote todo-prefix)) nil t)
763 (message ""))
764 (defalias 'todo-cmd-prev 'todo-backward-item)
766 (defun todo-forward-item (&optional count)
767 "Select COUNT-th next entry of TODO list."
768 (interactive "P")
769 (if (listp count) (setq count (car count)))
770 (end-of-line)
771 (search-forward-regexp (concat "^" (regexp-quote todo-prefix))
772 nil 'goto-end count)
773 (beginning-of-line)
774 (message ""))
775 (defalias 'todo-cmd-next 'todo-forward-item)
777 (defun todo-save () "Save the TODO list."
778 (interactive)
779 (save-buffer)
780 (if todo-save-top-priorities-too (todo-save-top-priorities))
782 (defalias 'todo-cmd-save 'todo-save)
784 (defun todo-quit () "Done with TODO list for now."
785 (interactive)
786 (widen)
787 (todo-save)
788 (message "")
789 (bury-buffer))
790 (defalias 'todo-cmd-done 'todo-quit)
792 (defun todo-edit-item () "Edit current TODO list entry."
793 (interactive)
794 (let ((item (todo-item-string)))
795 (if (todo-string-multiline-p item)
796 (todo-edit-multiline)
797 (let ((new (read-from-minibuffer "Edit: " item)))
798 (todo-remove-item)
799 (insert new "\n")
800 (todo-backward-item)
801 (message "")))))
802 (defalias 'todo-cmd-edit 'todo-edit-item)
804 (defun todo-edit-multiline ()
805 "Set up a buffer for editing a multiline TODO list entry."
806 (interactive)
807 (let ((buffer-name (generate-new-buffer-name todo-edit-buffer)))
808 (switch-to-buffer
809 (make-indirect-buffer
810 (find-buffer-visiting todo-file-do) buffer-name))
811 (message "To exit, simply kill this buffer and return to list.")
812 (todo-edit-mode)
813 (narrow-to-region (todo-item-start) (todo-item-end))))
815 (defun todo-add-category (cat)
816 "Add new category CAT to the TODO list."
817 (interactive "sCategory: ")
818 (save-window-excursion
819 (pushnew cat todo-categories)
820 (find-file todo-file-do)
821 (widen)
822 (goto-char (point-min))
823 (let ((posn (search-forward "-*- mode: todo; " 17 t)))
824 (if (not (null posn)) (goto-char posn))
825 (if (equal posn nil)
826 (progn
827 (insert "-*- mode: todo; \n")
828 (forward-char -1))
829 (kill-line)))
830 (insert (format "todo-categories: %S; -*-" todo-categories))
831 (forward-char 1)
832 (insert (format "%s%s%s\n%s\n%s %s\n"
833 todo-prefix todo-category-beg cat
834 todo-category-end
835 todo-prefix todo-category-sep))
836 (save-buffer))
839 (defun todo-add-item-non-interactively (new-item category)
840 "Insert NEW-ITEM in TODO list as a new entry in CATEGORY."
841 (save-excursion
842 (todo-show))
843 (save-excursion
844 (if (string= "" category)
845 (setq category (nth todo-category-number todo-categories)))
846 (setq todo-category-number
847 (or (position category todo-categories :test 'equal)
848 (todo-add-category category)))
849 (todo-show)
850 (setq todo-previous-line 0)
851 (let ((top 1)
852 (bottom (1+ (count-lines (point-min) (point-max)))))
853 (while (> (- bottom top) todo-insert-threshold)
854 (let* ((current (/ (+ top bottom) 2))
855 (answer (if (< current bottom)
856 (todo-more-important-p current) nil)))
857 (if answer
858 (setq bottom current)
859 (setq top (1+ current)))))
860 (setq top (/ (+ top bottom) 2))
861 ;; goto-line doesn't have the desired behavior in a narrowed buffer
862 (goto-char (point-min))
863 (forward-line (1- top)))
864 (insert new-item "\n")
865 (todo-backward-item)
866 (progn ;;; horrible os10000 hack to make items appear when inserting into empty buffer
867 (widen)
868 (show-all)
869 (todo-forward-category)
870 (todo-backward-category))
871 (todo-save)
872 (message "")))
874 ;;;###autoload
875 (defun todo-insert-item (ARG)
876 "Insert new TODO list entry.
877 With a prefix argument solicit the category, otherwise use the current
878 category."
879 (interactive "P")
880 (save-excursion
881 (if (not (string-equal mode-name "TODO")) (todo-show))
882 (let* ((new-item (concat todo-prefix " "
883 (read-from-minibuffer
884 "New TODO entry: "
885 (if todo-entry-prefix-function
886 (funcall todo-entry-prefix-function)))))
887 (categories todo-categories)
888 (history (cons 'categories (1+ todo-category-number)))
889 (current-category (nth todo-category-number todo-categories))
890 (category
891 (if ARG
892 current-category
893 (completing-read
894 (concat "Category ["
895 current-category "]: ")
896 (todo-category-alist) nil nil nil history))))
897 (todo-add-item-non-interactively new-item category))))
899 (defalias 'todo-cmd-inst 'todo-insert-item)
901 (defun todo-insert-item-here ()
902 "Insert new TODO list entry under the cursor."
903 (interactive "")
904 (save-excursion
905 (if (not (string-equal mode-name "TODO")) (todo-show))
906 (let* ((new-item (concat todo-prefix " "
907 (read-from-minibuffer
908 "New TODO entry: "
909 (if todo-entry-prefix-function
910 (funcall todo-entry-prefix-function))))))
911 (insert (concat new-item "\n")))))
913 (defun todo-more-important-p (line)
914 "Ask whether entry is more important than the one at LINE."
915 (if (not (equal todo-previous-line line))
916 (progn
917 (setq todo-previous-line line)
918 (goto-char (point-min))
919 (forward-line (1- todo-previous-line))
920 (let ((item (todo-item-string-start)))
921 (setq todo-previous-answer
922 (y-or-n-p (concat "More important than '" item "'? "))))))
923 todo-previous-answer)
924 (defalias 'todo-ask-p 'todo-more-important-p)
926 (defun todo-delete-item () "Delete current TODO list entry."
927 (interactive)
928 (if (> (count-lines (point-min) (point-max)) 0)
929 (let* ((todo-entry (todo-item-string-start))
930 (todo-answer (y-or-n-p (concat "Permanently remove '"
931 todo-entry "'? "))))
932 (if todo-answer
933 (progn
934 (todo-remove-item)
935 (todo-backward-item)))
936 (message ""))
937 (error "No TODO list entry to delete")))
938 (defalias 'todo-cmd-kill 'todo-delete-item)
940 (defun todo-raise-item () "Raise priority of current entry."
941 (interactive)
942 (if (> (count-lines (point-min) (point)) 0)
943 (let ((item (todo-item-string)))
944 (todo-remove-item)
945 (todo-backward-item)
946 (save-excursion
947 (insert item "\n"))
948 (message ""))
949 (error "No TODO list entry to raise")))
950 (defalias 'todo-cmd-rais 'todo-raise-item)
952 (defun todo-lower-item () "Lower priority of current entry."
953 (interactive)
954 (if (> (count-lines (point) (point-max)) 1)
955 ;; Assume there is a final newline
956 (let ((item (todo-item-string)))
957 (todo-remove-item)
958 (todo-forward-item)
959 (save-excursion
960 (insert item "\n"))
961 (message ""))
962 (error "No TODO list entry to lower")))
963 (defalias 'todo-cmd-lowr 'todo-lower-item)
965 (defun todo-file-item (&optional comment)
966 "File the current TODO list entry away,
967 annotated with an optional COMMENT."
968 (interactive "sComment: ")
969 (or (> (count-lines (point-min) (point-max)) 0)
970 (error "No TODO list entry to file away"))
971 (let ((time-stamp-format todo-time-string-format))
972 (if (and comment (> (length comment) 0))
973 (progn
974 (goto-char (todo-item-end))
975 (insert
976 (if (save-excursion (beginning-of-line)
977 (looking-at (regexp-quote todo-prefix)))
979 "\n\t")
980 "(" comment ")")))
981 (goto-char (todo-item-end))
982 (insert " [" (nth todo-category-number todo-categories) "]")
983 (goto-char (todo-item-start))
984 (let ((temp-point (point)))
985 (if (looking-at (regexp-quote todo-prefix))
986 (replace-match (time-stamp-string))
987 ;; Standard prefix -> timestamp
988 ;; Else prefix non-standard item start with timestamp
989 (insert (time-stamp-string)))
990 (append-to-file temp-point (1+ (todo-item-end)) todo-file-done)
991 (delete-region temp-point (1+ (todo-item-end))))
992 (todo-backward-item)
993 (message "")))
995 ;; ---------------------------------------------------------------------------
997 ;; Utility functions:
999 (defun todo-top-priorities (&optional nof-priorities category-pr-page)
1000 "List top priorities for each category.
1002 Number of entries for each category is given by NOF-PRIORITIES which
1003 defaults to \'todo-show-priorities\'.
1005 If CATEGORY-PR-PAGE is non-nil, a page separator \'^L\' is inserted
1006 between each category."
1008 (interactive "P")
1009 (or nof-priorities (setq nof-priorities todo-show-priorities))
1010 (if (listp nof-priorities) ;universal argument
1011 (setq nof-priorities (car nof-priorities)))
1012 (let ((todo-print-buffer-name "*Tmp*")
1013 ;;(todo-print-category-number 0)
1014 (todo-category-break (if category-pr-page "\f" ""))
1015 (cat-end
1016 (concat
1017 (if todo-remove-separator
1018 (concat todo-category-end "\n"
1019 (regexp-quote todo-prefix) " " todo-category-sep "\n")
1020 (concat todo-category-end "\n"))))
1021 beg end)
1022 (todo-show)
1023 (save-excursion
1024 (save-restriction
1025 (widen)
1026 (copy-to-buffer todo-print-buffer-name (point-min) (point-max))
1027 (set-buffer todo-print-buffer-name)
1028 (goto-char (point-min))
1029 (if (re-search-forward (regexp-quote todo-header) nil t)
1030 (progn
1031 (beginning-of-line 1)
1032 (kill-line))) ;Remove mode line
1033 (while (re-search-forward ;Find category start
1034 (regexp-quote (concat todo-prefix todo-category-beg))
1035 nil t)
1036 (setq beg (+ (point-at-eol) 1)) ;Start of first entry.
1037 (re-search-forward cat-end nil t)
1038 (setq end (match-beginning 0))
1039 (replace-match todo-category-break)
1040 (narrow-to-region beg end) ;In case we have too few entries.
1041 (goto-char (point-min))
1042 (if (= 0 nof-priorities) ;Traverse entries.
1043 (goto-char end) ;All entries
1044 (todo-forward-item nof-priorities))
1045 (setq beg (point))
1046 (delete-region beg end)
1047 (widen))
1048 (and (looking-at "\f") (replace-match "")) ;Remove trailing form-feed.
1049 (goto-char (point-min)) ;Due to display buffer
1051 ;; Could have used switch-to-buffer as it has a norecord argument,
1052 ;; which is nice when we are called from e.g. todo-print.
1053 ;; Else we could have used pop-to-buffer.
1054 (display-buffer todo-print-buffer-name)
1055 (message "Type C-x 1 to remove %s window. M-C-v to scroll the help."
1056 todo-print-buffer-name)
1059 (defun todo-save-top-priorities (&optional nof-priorities)
1060 "Save top priorities for each category in `todo-file-top'.
1062 Number of entries for each category is given by NOF-PRIORITIES which
1063 defaults to `todo-show-priorities'."
1064 (interactive "P")
1065 (save-window-excursion
1066 (save-excursion
1067 (save-restriction
1068 (todo-top-priorities nof-priorities)
1069 (set-buffer todo-tmp-buffer-name)
1070 (write-file todo-file-top)
1071 (kill-this-buffer)
1072 ))))
1074 ;;;###autoload
1075 (defun todo-print (&optional category-pr-page)
1076 "Print todo summary using \\\[todo-print-function].
1077 If CATEGORY-PR-PAGE is non-nil, a page separator \'^L\' is inserted
1078 between each category.
1080 Number of entries for each category is given by
1081 \'todo-print-priorities\'."
1082 (interactive "P")
1083 (if todo-print-function
1084 (progn
1085 (save-window-excursion
1086 (save-excursion
1087 (save-restriction
1088 (todo-top-priorities todo-print-priorities
1089 category-pr-page)
1090 (set-buffer todo-tmp-buffer-name)
1091 (and (funcall todo-print-function)
1092 (kill-this-buffer))
1093 (message "Todo printing done."))
1095 (message "todo-print-function undefinded")
1098 (defun todo-jump-to-category ()
1099 "Jump to a category. Default is previous category."
1100 (interactive)
1101 (let* ((categories todo-categories)
1102 (history (cons 'categories (1+ todo-category-number)))
1103 (category (completing-read
1104 (concat "Category ["
1105 (nth todo-category-number todo-categories) "]: ")
1106 (todo-category-alist) nil nil nil history)))
1107 (if (string= "" category)
1108 (setq category (nth todo-category-number todo-categories)))
1109 (setq todo-category-number
1110 (or (position category todo-categories :test 'equal)
1111 (todo-add-category category)))
1112 (todo-show)))
1114 (defun todo-line-string () "Return current line in buffer as a string."
1115 (buffer-substring (point-at-bol) (point-at-eol)))
1117 (defun todo-item-string-start ()
1118 "Return the start of this TODO list entry as a string."
1119 ;; Suitable for putting in the minibuffer when asking the user
1120 (let ((item (todo-item-string)))
1121 (if (> (length item) 60)
1122 (setq item (concat (substring item 0 56) "...")))
1123 item))
1125 (defun todo-item-start () "Return point at start of current TODO list item."
1126 (save-excursion
1127 (beginning-of-line)
1128 (if (not (looking-at (regexp-quote todo-prefix)))
1129 (search-backward-regexp
1130 (concat "^" (regexp-quote todo-prefix)) nil t))
1131 (point)))
1133 (defun todo-item-end () "Return point at end of current TODO list item."
1134 (save-excursion
1135 (end-of-line)
1136 (search-forward-regexp
1137 (concat "^" (regexp-quote todo-prefix)) nil 'goto-end)
1138 (1- (point-at-bol))))
1140 (defun todo-remove-item () "Delete the current entry from the TODO list."
1141 (delete-region (todo-item-start) (1+ (todo-item-end))))
1143 (defun todo-item-string () "Return current TODO list entry as a string."
1144 (buffer-substring (todo-item-start) (todo-item-end)))
1146 (defun todo-string-count-lines (string)
1147 "Return the number of lines STRING spans."
1148 (length (split-string string "\n")))
1150 (defun todo-string-multiline-p (string)
1151 "Return non-nil if STRING spans several lines."
1152 (> (todo-string-count-lines string) 1))
1154 (defun todo-category-alist ()
1155 "Generate an alist for use in `completing-read' from `todo-categories'."
1156 (mapcar (lambda (cat) (cons cat nil))
1157 todo-categories))
1159 ;; utility functions: These are available in XEmacs, but not in Emacs 19.34
1161 (if (not (fboundp 'point-at-bol))
1162 (defun point-at-bol () "Return value of point at beginning of line."
1163 (save-excursion
1164 (beginning-of-line)
1165 (point))))
1167 (if (not (fboundp 'point-at-eol))
1168 (defun point-at-eol () "Return value of point at end of line."
1169 (save-excursion
1170 (end-of-line)
1171 (point))))
1173 ;; splits at a white space, returns a list
1174 (if (not (fboundp 'split-string))
1175 (defun split-string (string &optional separators)
1176 "Splits STRING into substrings where there are matches for SEPARATORS.
1177 Each match for SEPARATORS is a splitting point.
1178 The substrings between the splitting points are made into a list
1179 which is returned.
1180 If SEPARATORS is absent, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
1181 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
1182 (start 0)
1183 (list nil))
1184 (while (string-match rexp string start)
1185 (or (eq (match-beginning 0) 0)
1186 (setq list
1187 (cons (substring string start (match-beginning 0))
1188 list)))
1189 (setq start (match-end 0)))
1190 (or (eq start (length string))
1191 (setq list
1192 (cons (substring string start)
1193 list)))
1194 (nreverse list))))
1196 ;; ---------------------------------------------------------------------------
1198 (easy-menu-define todo-menu todo-mode-map "Todo Menu"
1199 '("Todo"
1200 ["Next category" todo-forward-category t]
1201 ["Previous category" todo-backward-category t]
1202 ["Jump to category" todo-jump-to-category t]
1203 ["Show top priority items" todo-top-priorities t]
1204 ["Print categories" todo-print t]
1205 "---"
1206 ["Edit item" todo-edit-item t]
1207 ["File item" todo-file-item t]
1208 ["Insert new item" todo-insert-item t]
1209 ["Insert item here" todo-insert-item-here t]
1210 ["Kill item" todo-delete-item t]
1211 "---"
1212 ["Lower item priority" todo-lower-item t]
1213 ["Raise item priority" todo-raise-item t]
1214 "---"
1215 ["Next item" todo-forward-item t]
1216 ["Previous item" todo-backward-item t]
1217 "---"
1218 ["Save" todo-save t]
1219 ["Save Top Priorities" todo-save-top-priorities t]
1220 "---"
1221 ["Quit" todo-quit t]
1224 ;; As calendar reads .todo-do before todo-mode is loaded.
1225 ;;;###autoload
1226 (defun todo-mode () "Major mode for editing TODO lists.\n\n\\{todo-mode-map}"
1227 (interactive)
1228 (setq major-mode 'todo-mode)
1229 (setq mode-name "TODO")
1230 (use-local-map todo-mode-map)
1231 (easy-menu-add todo-menu)
1232 (setq paragraph-separate "\*/\*")
1233 (setq fill-prefix "\t\t")
1234 (setq outline-regexp "\\*/\\*")
1235 (outline-minor-mode 1)
1236 (hide-other)
1237 (auto-fill-mode 1)
1238 (run-hooks 'todo-mode-hook))
1240 ;; Read about this function in the setup instructions above!
1241 ;;;###autoload
1242 (defun todo-cp ()
1243 "Make a diary entry appear only in the current date's diary"
1244 (if (equal (calendar-current-date) date)
1245 entry
1246 nil))
1248 (defun todo-edit-mode ()
1249 "Major mode for editing items in the TODO list\n\n\\{todo-edit-mode-map}"
1250 (text-mode)
1251 (setq major-mode 'todo-edit-mode)
1252 (setq mode-name "TODO Edit")
1253 (run-hooks 'todo-edit-mode-hook))
1255 ;;;###autoload
1256 (defun todo-show () "Show TODO list."
1257 (interactive)
1258 (if (file-exists-p todo-file-do)
1259 (find-file todo-file-do)
1260 (todo-initial-setup))
1261 (if (null todo-categories)
1262 (if (null todo-cats)
1263 (error "Error in %s: No categories in list `todo-categories'"
1264 todo-file-do)
1265 (goto-char (point-min))
1266 (and (search-forward "todo-cats:" nil t)
1267 (replace-match "todo-categories:"))
1268 (make-local-variable 'todo-categories)
1269 (setq todo-categories todo-cats)))
1270 (beginning-of-line)
1271 (todo-category-select))
1273 (defun todo-initial-setup () "Set up things to work properly in TODO mode."
1274 (find-file todo-file-do)
1275 (erase-buffer)
1276 (todo-mode)
1277 (todo-add-category "Todo"))
1279 (provide 'todo-mode)
1281 ;; ---------------------------------------------------------------------------
1282 ;;; todo-mode.el ends here
1283 ;; ---------------------------------------------------------------------------