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