Commit | Line | Data |
---|---|---|
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 | |
1966902e | 7 | ;; Version: $Id: todo-mode.el,v 1.29 1997/10/28 21:47:12 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 | ;; |
1966902e | 99 | ;; $Id: todo-mode.el,v 1.29 1997/10/28 21:47:12 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 | |
123 | ;; i to insert a new entry | |
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 $ | |
1966902e OS |
270 | ;; Revision 1.29 1997/10/28 21:47:12 os10000 |
271 | ;; Implemented "insert-under-cursor" as suggested by | |
272 | ;; Kai Grossjohann <grossjohann@ls6.cs.uni-dortmund.de>. | |
273 | ;; | |
d145aa83 OS |
274 | ;; Revision 1.28 1997/10/28 21:37:05 os10000 |
275 | ;; Incorporated simplifying suggestions from | |
276 | ;; Carsten Dominik <dominik@strw.LeidenUniv.nl>. | |
277 | ;; | |
5d035cad OS |
278 | ;; Revision 1.27 1997/10/28 21:26:55 os10000 |
279 | ;; Patch from Paul Stodghill <stodghil@CS.Cornell.EDU>: | |
280 | ;; The patch below fixes todo-insert-item so that it will | |
281 | ;; insert the item in place, instead of at the top of the | |
282 | ;; buffer, when invoked with a prefix argument. | |
283 | ;; | |
49b2ae0e OS |
284 | ;; Revision 1.26 1997/10/28 21:14:51 os10000 |
285 | ;; Improvements sent in by Dave Love <d.love@dl.ac.uk>: | |
286 | ;; todo-mode.el: Doc fixes. Customization. | |
287 | ;; (todo-add-item-non-interactively): New arg -- don't dynamically bind ARG. | |
288 | ;; (todo-insert-item): Use it. | |
289 | ;; | |
85b3b166 OS |
290 | ;; Revision 1.25 1997/10/28 20:03:27 os10000 |
291 | ;; Harald Backer <harald.backer@fou.telenor.no> sent the following: | |
292 | ;; Added `todo-save-top-priorities' and option to automatically save top | |
293 | ;; priorities file when saving todo-file. Changed some default values. | |
294 | ;; Bug fixes. | |
295 | ;; | |
f1757bdd OS |
296 | ;; Revision 1.24 1997/10/28 19:41:53 os10000 |
297 | ;; Added fix from Frank Ridderbusch <ridderbusch.pad@sni.de>, | |
298 | ;; an apostrophe was missing. | |
299 | ;; | |
e05e3850 OS |
300 | ;; Revision 1.23 1997/10/24 17:30:54 os10000 |
301 | ;; Added three suggestions from Carsten | |
302 | ;; Dominik <dominik@strw.LeidenUniv.nl>: | |
303 | ;; | |
304 | ;; - recommend autoloading instead of require | |
305 | ;; - inserting from different buffer didn't work | |
306 | ;; (now fixed -- I pray) | |
307 | ;; - provided public entry point to insert items | |
308 | ;; from normal lisp code | |
309 | ;; | |
4cbc9d5a OS |
310 | ;; Revision 1.22 1997/10/24 16:53:20 os10000 |
311 | ;; Paul Stodghill <stodghil@CS.Cornell.EDU> writes: | |
312 | ;; | |
313 | ;; When invoked with a prefix, todo-insert-item | |
314 | ;; should not prompt for a category. (He adds: | |
315 | ;; At least that's what I think.) | |
316 | ;; | |
2e590030 OS |
317 | ;; Revision 1.21 1997/10/24 16:51:02 os10000 |
318 | ;; Rafael Laboissiere <rafael@icp.inpg.fr> writes: | |
319 | ;; | |
320 | ;; I was just annoyed with the fact that there is no way | |
321 | ;; to dynamically control the insertion accuracy. I mean: | |
322 | ;; the variable `todo-insert-threshold' does the job, but | |
323 | ;; it is not very handy if one wants to mix the two | |
324 | ;; behaviors (bisection and "insert right here under the | |
325 | ;; cursor"). | |
326 | ;; | |
327 | ;; Therefore I did a quick hack in the function | |
328 | ;; `todo-insert-item'. Now by giving a prefix argument to | |
329 | ;; the insert command (i.e. by typing "C-u i"), entries | |
330 | ;; are inserted exactly at the line where the cursor is. | |
331 | ;; It would be better to give the value of | |
332 | ;; `todo-insert-threshold' as a numeric argument of | |
333 | ;; `todo-insert-item' (like "M-8 i"), but it's too late | |
334 | ;; now for continuing to hack. | |
335 | ;; | |
0aa18b36 OS |
336 | ;; Revision 1.20 1997/10/17 15:41:57 os10000 |
337 | ;; Thanks to Harald Backer <harald.backer@fou.telenor.no>, we now have | |
338 | ;; the following facilities available: | |
339 | ;; | |
340 | ;; Added todo-print, todo-top-priorities and todo-jump with matching | |
341 | ;; variables; Parameterized todo-header, todo-category-beg, | |
342 | ;; todo-category-end and todo-category-sep; Added autoload comments; | |
343 | ;; todo-category-select: Modified regexp to make category names unique; | |
344 | ;; todo-forward-item: Added optional COUNT vaiable; todo-insert-item: | |
345 | ;; Rewrote completing read entry. | |
346 | ;; | |
347 | ;; Also, check out the extended list of things left to be done to this | |
348 | ;; package at the end of the documentation! | |
349 | ;; | |
e4541b67 OS |
350 | ;; Revision 1.19 1997/10/16 21:21:16 os10000 |
351 | ;; Jari Aalto <jari.aalto@poboxes.com> writes: | |
352 | ;; | |
353 | ;; I just downloaded your package and after reading the docs I | |
354 | ;; decided to do some reformatting. Hope you don't mind. Now | |
355 | ;; they are in such a format that the html page can be | |
356 | ;; automatically generated from the source file. As an example, I | |
357 | ;; generated the attached page using the following command: | |
358 | ;; ripdoc.pls < todo-mode.el | t2html.pls -a "Oliver.Seidel" -e \ | |
0aa18b36 | 359 | ;; Oliver.Seidel@cl.cam.ac.uk -simple -base |
e4541b67 OS |
360 | ;; |
361 | ;; And of course I appreciate it. Jari's stuff can be found at: | |
362 | ;; ftp://cs.uta.fi/pub/ssjaaa/, while I'm making the rev 1.18 page | |
363 | ;; available at http://www.cl.cam.ac.uk/users/os10000/doc/todo-mode.html | |
364 | ;; (That link will be valid until 10/1998 or slightly longer.) | |
365 | ;; | |
01b864bc OS |
366 | ;; Revision 1.18 1997/10/15 17:18:11 os10000 |
367 | ;; Everything seems to work in Harald Melands Emacs 20.02 and | |
368 | ;; my Emacs 19.34. Beware of the spelling in some of the | |
369 | ;; variable names. I looked up "threshold" in a dictionary | |
370 | ;; and here in Britain this appears to be the way to spell it. | |
371 | ;; | |
ab618c6e OS |
372 | ;; Revision 1.17 1997/10/15 14:30:41 os10000 |
373 | ;; Attempted to reconcile Harald's changes with mine since 1.15. | |
374 | ;; | |
b7e04170 OS |
375 | ;; Revision 1.16 1997/10/15 14:00:12 os10000 |
376 | ;; Fixed 'file-item' and added 20.02 split-string function. | |
377 | ;; | |
91e9443e OS |
378 | ;; Revision 1.15 1997/10/14 22:22:35 os10000 |
379 | ;; Added string-split (which I stole from ediff-util), changed | |
380 | ;; pop-to-buffer to switch-to-buffer and added message on how | |
381 | ;; to exit the multi-line-edit mode. | |
382 | ;; | |
2186b974 OS |
383 | ;; Revision 1.14 1997/10/09 09:24:50 os10000 |
384 | ;; Harald Meland <harald.meland@usit.uio.no> asked for | |
385 | ;; the latest version, got 1.13, and returned this. | |
386 | ;; He writes: | |
387 | ;; | |
388 | ;; Thanks a lot for the new version of todo-mode.el. As you will see I | |
389 | ;; have messed it up a bit, hopefully for the better -- I don't like | |
390 | ;; short, cryptic names for variables and functions, so I renamed most of | |
391 | ;; them, and `defalias'ed the old function names. I hope you don't mind | |
392 | ;; too much, I just kinda couldn't stop myself. | |
393 | ;; | |
394 | ;; Additionally, I included some support for multiline entries, cleaned | |
395 | ;; up (IMHO :) a lot of the code, included completion-support for which | |
396 | ;; category to install a new entry in, and possibly some other changes I | |
397 | ;; can't remember :) | |
398 | ;; | |
399 | ;; It's getting rather late, and I have just done some preliminary | |
400 | ;; testing on whether all of this really works, but so far it looks | |
401 | ;; good. | |
402 | ;; | |
7f6241ea OS |
403 | ;; Revision 1.13 1997/08/19 14:00:36 seidel |
404 | ;; - changed name to todo-mode | |
405 | ;; - fixed menu descriptions | |
406 | ;; - fixed "pressing abort while filing" | |
407 | ;; - attempted Emacs Lisp Manual *Tips* section compliance | |
408 | ;; | |
7c896f63 OS |
409 | ;; Revision 1.12 1997/08/06 10:56:15 os10000 |
410 | ;; Fixed header, typos, layout, documentation. | |
579e1c67 | 411 | ;; |
cf1ebf43 OS |
412 | ;; Revision 1.11 1997/08/06 09:14:25 os10000 |
413 | ;; Applied patch from Istvan Marko <istvan@cmdmail.amd.com> | |
414 | ;; to make menus work anywhere. | |
415 | ;; | |
49c48a1b OS |
416 | ;; Revision 1.10 1997/08/06 08:56:03 os10000 |
417 | ;; Acted upon suggestion from Shane Holder <holder@rsn.hp.com>: | |
418 | ;; Cancelling the editing of an entry will not delete it any more. | |
419 | ;; | |
03944ca7 OS |
420 | ;; Revision 1.9 1997/08/06 08:12:03 os10000 |
421 | ;; Improved documentation. Broke some lines to comply with | |
422 | ;; Richard Stallman's email to please keep in sync with the | |
423 | ;; rest of the Emacs distribution files. | |
424 | ;; | |
579e1c67 | 425 | ;; Revision 1.8 1997/08/05 22:39:04 os10000 |
7c896f63 | 426 | ;; Made todo-mode.el available under GPL. |
579e1c67 OS |
427 | ;; |
428 | ;; Revision 1.7 1997/08/05 22:34:14 os10000 | |
429 | ;; Fixed insertion routine with help from Trey Jackson | |
7f6241ea | 430 | ;; <trey@cs.berkeley.edu>; added todo-inst-tresh; |
579e1c67 OS |
431 | ;; fixed keyboard layout to remove unwanted keys. |
432 | ;; | |
433 | ;; Revision 1.6 1997/08/05 16:47:01 os10000 | |
434 | ;; Incorporated menus for XEmacs from Allan.Cochrane@soton.sc.philips.com, | |
435 | ;; fixed TYPO, fixed todo-file-cmd, cleaned up rcs history. | |
436 | ;; | |
437 | ;; Revision 1.5 1997/08/05 14:43:39 os10000 | |
438 | ;; Added improvements from Ron Gut <rgut@aware.com>. | |
439 | ;; Added category management. | |
440 | ;; | |
441 | ;; Revision 1.4 1997/08/04 16:18:45 os10000 | |
442 | ;; Added Raise/Lower item. | |
443 | ;; | |
444 | ;; Revision 1.3 1997/08/03 12:47:26 os10000 | |
445 | ;; Cleaned up variables, prefix and cursor position. | |
446 | ;; | |
447 | ;; Revision 1.2 1997/08/03 12:15:28 os10000 | |
448 | ;; It appears to work. | |
449 | ;; | |
450 | ;; Revision 1.1 1997/08/03 12:15:13 os10000 | |
451 | ;; Initial revision | |
452 | ;; | |
7e6ed9b9 OS |
453 | |
454 | ;; --------------------------------------------------------------------------- | |
455 | ||
7c896f63 OS |
456 | ;;; Code: |
457 | ||
85b3b166 OS |
458 | (eval-and-compile ; Removable for installation in |
459 | ; Emacs 20. | |
460 | (condition-case () | |
461 | (require 'custom) | |
462 | (error nil)) | |
463 | (if (and (featurep 'custom) (fboundp 'custom-declare-variable)) | |
464 | nil ;; We've got what we needed | |
465 | ;; We have the old custom-library, hack around it! | |
466 | (defmacro defgroup (&rest args) | |
467 | nil) | |
468 | (defmacro defcustom (var value doc &rest args) | |
469 | (` (defvar (, var) (, value) (, doc)))))) | |
470 | ||
3cb152f9 OS |
471 | ;; User-configurable variables: |
472 | ||
85b3b166 OS |
473 | (defgroup todo nil |
474 | "Maintain a list of todo items." | |
475 | :group 'calendar) | |
476 | ||
477 | (defcustom todo-prefix "*/*" | |
478 | "*TODO mode prefix for entries. | |
479 | ||
480 | This is useful in conjunction with `calendar' and `diary' if you use | |
481 | ||
482 | #include \"~/.todo-do\" | |
483 | ||
484 | in your diary file to include your todo list file as part of your | |
485 | diary. With the default value \"*/*\" the diary displays each entry | |
486 | every day and it may also be marked on every day of the calendar. | |
487 | Using \"&%%(equal (calendar-current-date) date)\" instead will only | |
488 | show and mark todo entreis for today, but may slow down processing of | |
489 | the diary file somewhat." | |
490 | :type 'string | |
491 | :group 'todo) | |
492 | (defcustom todo-file-do "~/.todo-do" | |
493 | "*TODO mode list file." | |
494 | :type 'file | |
495 | :group 'todo) | |
496 | (defcustom todo-file-done "~/.todo-done" | |
497 | "*TODO mode archive file." | |
498 | :type 'file | |
499 | :group 'todo) | |
500 | (defcustom todo-mode-hook nil | |
501 | "*TODO mode hooks." | |
502 | :type 'hook | |
503 | :group 'todo) | |
504 | (defcustom todo-edit-mode-hook nil | |
505 | "*TODO Edit mode hooks." | |
506 | :type 'hook | |
507 | :group 'todo) | |
508 | (defcustom todo-insert-threshold 0 | |
509 | "*TODO mode insertion accuracy. | |
510 | ||
511 | If you have 8 items in your TODO list, then you may get asked 4 | |
512 | questions by the binary insertion algorithm. However, you may not | |
513 | really have a need for such accurate priorities amongst your TODO | |
514 | items. If you now think about the binary insertion halfing the size | |
515 | of the window each time, then the threshhold is the window size at | |
516 | which it will stop. If you set the threshhold to zero, the upper and | |
517 | lower bound will coincide at the end of the loop and you will insert | |
518 | your item just before that point. If you set the threshhold to, | |
519 | e.g. 8, it will stop as soon as the window size drops below that | |
520 | amount and will insert the item in the approximate centre of that | |
521 | window." | |
522 | :type 'integer | |
523 | :group 'todo) | |
01b864bc | 524 | (defvar todo-edit-buffer " *TODO Edit*" "TODO Edit buffer name.") |
85b3b166 | 525 | (defcustom todo-file-top "~/.todo-top" |
f1757bdd | 526 | "*TODO mode top priorities file. |
85b3b166 | 527 | |
f1757bdd | 528 | Not in TODO format, but diary compatible. |
85b3b166 OS |
529 | Automatically generated when `todo-save-top-priorities' is non-nil." |
530 | :type 'string | |
531 | :group 'todo) | |
532 | ||
533 | (defcustom todo-print-function 'ps-print-buffer-with-faces | |
534 | "*Function to print the current buffer." | |
535 | :type 'symbol | |
536 | :group 'todo) | |
537 | (defcustom todo-show-priorities 1 | |
538 | "*Default number of priorities to show by \\[todo-top-priorities]. | |
539 | 0 means show all entries." | |
540 | :type 'integer | |
541 | :group 'todo) | |
542 | (defcustom todo-print-priorities 0 | |
543 | "*Default number of priorities to print by \\[todo-print]. | |
544 | 0 means print all entries." | |
545 | :type 'integer | |
546 | :group 'todo) | |
547 | (defcustom todo-remove-separator t | |
548 | "*Non-nil to remove category separators in\ | |
549 | \\[todo-top-priorities] and \\[todo-print]." | |
550 | :type 'boolean | |
551 | :group 'todo) | |
552 | (defcustom todo-save-top-priorities-too t | |
f1757bdd | 553 | "*Non-nil makes todo-save automatically save top-priorities in |
85b3b166 OS |
554 | `todo-file-top'." |
555 | :type 'boolean | |
556 | :group 'todo) | |
e4541b67 | 557 | |
7c896f63 OS |
558 | ;; Thanks for the ISO time stamp format go to Karl Eichwalder <ke@suse.de> |
559 | ;; My format string for the appt.el package is "%3b %2d, %y, %02I:%02M%p". | |
560 | ;; | |
85b3b166 | 561 | (defcustom todo-time-string-format |
ab618c6e | 562 | "%:y-%02m-%02d %02H:%02M" |
85b3b166 OS |
563 | "*TODO mode time string format for done entries. |
564 | For details see the variable `time-stamp-format'." | |
565 | :type 'string | |
566 | :group 'todo) | |
567 | ||
568 | (defcustom todo-entry-prefix-function 'todo-entry-timestamp-initials | |
569 | "*Function producing text to insert at start of todo entry." | |
570 | :type 'symbol | |
571 | :group 'todo) | |
572 | (defcustom todo-initials (or (getenv "INITIALS") (user-login-name)) | |
573 | "*Initials of todo item author." | |
574 | :type 'string | |
575 | :group 'todo) | |
e4541b67 OS |
576 | |
577 | (defun todo-entry-timestamp-initials () | |
f1757bdd | 578 | "Prepend timestamp and your initials to the head of a TODO entry." |
e4541b67 OS |
579 | (let ((time-stamp-format todo-time-string-format)) |
580 | (concat (time-stamp-string) " " todo-initials ": "))) | |
581 | ||
3cb152f9 OS |
582 | ;; --------------------------------------------------------------------------- |
583 | ||
49c48a1b OS |
584 | ;; Get some outside help ... |
585 | ||
3cb152f9 | 586 | (require 'time-stamp) |
49c48a1b OS |
587 | (require 'easymenu) |
588 | ||
589 | ;; --------------------------------------------------------------------------- | |
3cb152f9 | 590 | |
cf1ebf43 OS |
591 | ;; Set up some helpful context ... |
592 | ||
01b864bc | 593 | (defvar todo-categories nil "TODO categories.") |
85b3b166 OS |
594 | (defvar todo-cats nil |
595 | "Old variable for holding the TODO categories. | |
596 | Use `todo-categories' instead.") | |
01b864bc OS |
597 | (defvar todo-previous-line 0 "Previous line that I asked about.") |
598 | (defvar todo-previous-answer 0 "Previous answer that I got.") | |
599 | (defvar todo-mode-map nil "TODO mode keymap.") | |
600 | (defvar todo-category-number 0 "TODO category number.") | |
cf1ebf43 | 601 | |
f1757bdd | 602 | (defvar todo-tmp-buffer-name "*Tmp*") |
e4541b67 OS |
603 | |
604 | (defvar todo-category-sep (make-string 75 ?-) | |
605 | "Category separator.") | |
606 | (defvar todo-category-beg " --- " | |
607 | "Category start separator to be prepended onto category name.") | |
608 | (defvar todo-category-end "--- End" | |
609 | "Separator after a category.") | |
610 | (defvar todo-header "-*- mode: todo; " | |
611 | "Header of todo files.") | |
612 | ||
613 | ||
614 | ||
cf1ebf43 OS |
615 | ;; --------------------------------------------------------------------------- |
616 | ||
3d8105fb OS |
617 | (if todo-mode-map |
618 | nil | |
619 | (let ((map (make-keymap))) | |
620 | (suppress-keymap map t) | |
7f6241ea OS |
621 | (define-key map "+" 'todo-forward-category) |
622 | (define-key map "-" 'todo-backward-category) | |
1966902e | 623 | (define-key map "d" 'todo-file-item) ;done/delete |
7f6241ea OS |
624 | (define-key map "e" 'todo-edit-item) |
625 | (define-key map "E" 'todo-edit-multiline) | |
626 | (define-key map "f" 'todo-file-item) | |
627 | (define-key map "i" 'todo-insert-item) | |
d145aa83 | 628 | (define-key map "I" 'todo-insert-item-here) |
e4541b67 | 629 | (define-key map "j" 'todo-jump-to-category) |
7f6241ea OS |
630 | (define-key map "k" 'todo-delete-item) |
631 | (define-key map "l" 'todo-lower-item) | |
632 | (define-key map "n" 'todo-forward-item) | |
633 | (define-key map "p" 'todo-backward-item) | |
e4541b67 | 634 | (define-key map "P" 'todo-print) |
7f6241ea OS |
635 | (define-key map "q" 'todo-quit) |
636 | (define-key map "r" 'todo-raise-item) | |
637 | (define-key map "s" 'todo-save) | |
f1757bdd | 638 | (define-key map "S" 'todo-save-top-priorities) |
e4541b67 | 639 | (define-key map "t" 'todo-top-priorities) |
3d8105fb | 640 | (setq todo-mode-map map))) |
3cb152f9 | 641 | |
7f6241ea OS |
642 | (defun todo-category-select () |
643 | "Make TODO mode display the current category correctly." | |
644 | (let ((name (nth todo-category-number todo-categories))) | |
579e1c67 | 645 | (setq mode-line-buffer-identification |
01b864bc | 646 | (concat "Category: " name)) |
da2ee685 OS |
647 | (widen) |
648 | (goto-char (point-min)) | |
7f6241ea | 649 | (search-forward-regexp |
e4541b67 OS |
650 | (concat "^" |
651 | (regexp-quote (concat todo-prefix todo-category-beg name)) | |
652 | "$")) | |
7f6241ea | 653 | (let ((begin (1+ (point-at-eol)))) |
e4541b67 | 654 | (search-forward-regexp (concat "^" todo-category-end)) |
7f6241ea OS |
655 | (narrow-to-region begin (point-at-bol)) |
656 | (goto-char (point-min))))) | |
657 | (defalias 'todo-cat-slct 'todo-category-select) | |
658 | ||
659 | (defun todo-forward-category () "Go forward to TODO list of next category." | |
da2ee685 | 660 | (interactive) |
7f6241ea | 661 | (setq todo-category-number |
01b864bc | 662 | (mod (1+ todo-category-number) (length todo-categories))) |
7f6241ea OS |
663 | (todo-category-select)) |
664 | (defalias 'todo-cmd-forw 'todo-forward-category) | |
da2ee685 | 665 | |
7f6241ea | 666 | (defun todo-backward-category () "Go back to TODO list of previous category." |
da2ee685 | 667 | (interactive) |
7f6241ea | 668 | (setq todo-category-number |
01b864bc | 669 | (mod (1- todo-category-number) (length todo-categories))) |
7f6241ea OS |
670 | (todo-category-select)) |
671 | (defalias 'todo-cmd-back 'todo-backward-category) | |
da2ee685 | 672 | |
7f6241ea | 673 | (defun todo-backward-item () "Select previous entry of TODO list." |
3cb152f9 | 674 | (interactive) |
7f6241ea | 675 | (search-backward-regexp (concat "^" (regexp-quote todo-prefix)) nil t) |
cf1ebf43 | 676 | (message "")) |
7f6241ea | 677 | (defalias 'todo-cmd-prev 'todo-backward-item) |
3cb152f9 | 678 | |
e4541b67 | 679 | (defun todo-forward-item (&optional count) |
85b3b166 | 680 | "Select COUNT-th next entry of TODO list." |
e4541b67 OS |
681 | (interactive "P") |
682 | (if (listp count) (setq count (car count))) | |
7f6241ea | 683 | (end-of-line) |
e4541b67 OS |
684 | (search-forward-regexp (concat "^" (regexp-quote todo-prefix)) |
685 | nil 'goto-end count) | |
7f6241ea | 686 | (beginning-of-line) |
cf1ebf43 | 687 | (message "")) |
7f6241ea | 688 | (defalias 'todo-cmd-next 'todo-forward-item) |
3cb152f9 | 689 | |
7f6241ea | 690 | (defun todo-save () "Save the TODO list." |
da2ee685 | 691 | (interactive) |
f1757bdd OS |
692 | (save-buffer) |
693 | (if todo-save-top-priorities-too (todo-save-top-priorities)) | |
694 | ) | |
7f6241ea | 695 | (defalias 'todo-cmd-save 'todo-save) |
da2ee685 | 696 | |
7f6241ea | 697 | (defun todo-quit () "Done with TODO list for now." |
3cb152f9 | 698 | (interactive) |
da2ee685 | 699 | (widen) |
f1757bdd | 700 | (todo-save) |
7e6ed9b9 | 701 | (message "") |
cf1ebf43 | 702 | (bury-buffer)) |
7f6241ea | 703 | (defalias 'todo-cmd-done 'todo-quit) |
3cb152f9 | 704 | |
7f6241ea | 705 | (defun todo-edit-item () "Edit current TODO list entry." |
3cb152f9 | 706 | (interactive) |
7f6241ea OS |
707 | (let ((item (todo-item-string))) |
708 | (if (todo-string-multiline-p item) | |
01b864bc | 709 | (todo-edit-multiline) |
7f6241ea | 710 | (let ((new (read-from-minibuffer "Edit: " item))) |
01b864bc OS |
711 | (todo-remove-item) |
712 | (insert new "\n") | |
713 | (todo-backward-item) | |
714 | (message ""))))) | |
7f6241ea OS |
715 | (defalias 'todo-cmd-edit 'todo-edit-item) |
716 | ||
717 | (defun todo-edit-multiline () | |
718 | "Set up a buffer for editing a multiline TODO list entry." | |
719 | (interactive) | |
720 | (let ((buffer-name (generate-new-buffer-name todo-edit-buffer))) | |
e4541b67 OS |
721 | (switch-to-buffer |
722 | (make-indirect-buffer | |
723 | (file-name-nondirectory todo-file-do) buffer-name)) | |
2186b974 | 724 | (message "To exit, simply kill this buffer and return to list.") |
7f6241ea OS |
725 | (todo-edit-mode) |
726 | (narrow-to-region (todo-item-start) (todo-item-end)))) | |
3cb152f9 | 727 | |
e4541b67 | 728 | ;;;### autoload |
85b3b166 OS |
729 | (defun todo-add-category (cat) |
730 | "Add new category CAT to the TODO list." | |
3cb152f9 | 731 | (interactive) |
3cb152f9 | 732 | (save-window-excursion |
7f6241ea | 733 | (setq todo-categories (cons cat todo-categories)) |
3cb152f9 | 734 | (find-file todo-file-do) |
da2ee685 OS |
735 | (widen) |
736 | (goto-char (point-min)) | |
737 | (let ((posn (search-forward "-*- mode: todo; " 17 t))) | |
738 | (if (not (null posn)) (goto-char posn)) | |
579e1c67 | 739 | (if (equal posn nil) |
01b864bc OS |
740 | (progn |
741 | (insert "-*- mode: todo; \n") | |
742 | (forward-char -1)) | |
743 | (kill-line))) | |
7f6241ea | 744 | (insert (format "todo-categories: %S; -*-" todo-categories)) |
da2ee685 | 745 | (forward-char 1) |
e4541b67 OS |
746 | (insert (format "%s%s%s\n%s\n%s %s\n" |
747 | todo-prefix todo-category-beg cat | |
748 | todo-category-end | |
749 | todo-prefix todo-category-sep))) | |
cf1ebf43 | 750 | 0) |
da2ee685 | 751 | |
e4541b67 | 752 | ;;;### autoload |
85b3b166 OS |
753 | (defun todo-add-item-non-interactively (new-item category ARG) |
754 | "Insert NEW-ITEM in TODO list as a new entry in CATEGORY." | |
4cbc9d5a | 755 | (save-excursion |
49b2ae0e OS |
756 | (todo-show)) |
757 | (save-excursion | |
e4541b67 OS |
758 | (if (string= "" category) |
759 | (setq category (nth todo-category-number todo-categories))) | |
7f6241ea OS |
760 | (let ((cat-exists (member category todo-categories))) |
761 | (setq todo-category-number | |
01b864bc OS |
762 | (if cat-exists |
763 | (- (length todo-categories) (length cat-exists)) | |
764 | (todo-add-category category)))) | |
0aa18b36 OS |
765 | (if (not ARG) |
766 | (progn | |
767 | (todo-show) | |
768 | (setq todo-previous-line 0) | |
769 | (let ((top 1) | |
770 | (bottom (1+ (count-lines (point-min) (point-max))))) | |
771 | (while (> (- bottom top) todo-insert-threshold) | |
772 | (let* ((current (/ (+ top bottom) 2)) | |
773 | (answer (if (< current bottom) | |
774 | (todo-more-important-p current) nil))) | |
775 | (if answer | |
776 | (setq bottom current) | |
777 | (setq top (1+ current))))) | |
778 | (setq top (/ (+ top bottom) 2)) | |
779 | ;; goto-line doesn't have the desired behavior in a narrowed buffer | |
780 | (goto-char (point-min)) | |
781 | (forward-line (1- top)))) | |
782 | (beginning-of-line)) | |
7f6241ea OS |
783 | (insert new-item "\n") |
784 | (todo-backward-item) | |
f1757bdd | 785 | (todo-save) |
3d8105fb | 786 | (message ""))) |
4cbc9d5a OS |
787 | |
788 | ;;;### autoload | |
789 | (defun todo-insert-item (ARG) | |
85b3b166 OS |
790 | "Insert new TODO list entry. |
791 | With a prefix argument solicit the category, otherwise use the current | |
792 | category." | |
4cbc9d5a | 793 | (interactive "P") |
49b2ae0e | 794 | (save-excursion |
1966902e OS |
795 | (if (not (string-equal mode-name "TODO")) (todo-show)) |
796 | (let* ((new-item (concat todo-prefix " " | |
797 | (read-from-minibuffer | |
798 | "New TODO entry: " | |
799 | (if todo-entry-prefix-function | |
800 | (funcall todo-entry-prefix-function))))) | |
801 | (categories todo-categories) | |
802 | (history (cons 'categories (1+ todo-category-number))) | |
803 | (current-category (nth todo-category-number todo-categories)) | |
804 | (category | |
805 | (if ARG | |
806 | current-category | |
85b3b166 | 807 | (completing-read |
1966902e OS |
808 | (concat "Category [" |
809 | current-category "]: ") | |
810 | (todo-category-alist) nil nil nil history)))) | |
811 | (todo-add-item-non-interactively new-item category ARG)))) | |
4cbc9d5a | 812 | |
7f6241ea | 813 | (defalias 'todo-cmd-inst 'todo-insert-item) |
3d8105fb | 814 | |
d145aa83 OS |
815 | ;;;### autoload |
816 | (defun todo-insert-item-here () | |
817 | "Insert new TODO list entry under the cursor." | |
818 | (interactive) | |
1966902e | 819 | (todo-insert-item t)) |
d145aa83 | 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 | ||
910 | Number of entries for each category is given by NOF-PRIORITIES which | |
911 | defaults to \'todo-show-priorities\'. | |
912 | ||
913 | If CATEGORY-PR-PAGE is non-nil, a page separator \'^L\' is inserted | |
914 | between 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 | ||
971 | Number of entries for each category is given by NOF-PRIORITIES which | |
972 | defaults 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]. | |
986 | If CATEGORY-PR-PAGE is non-nil, a page separator \'^L\' is inserted | |
987 | between each category. | |
988 | ||
989 | Number 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. | |
1088 | Each match for SEPARATORS is a splitting point. | |
1089 | The substrings between the splitting points are made into a list | |
1090 | which is returned. | |
1091 | If 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 | ;; --------------------------------------------------------------------------- |