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