todo-mode.el 20 KB
Newer Older
Oliver Seidel's avatar
Oliver Seidel committed
1
;;; todo-mode.el -- Major mode for editing TODO list files
Oliver Seidel's avatar
Oliver Seidel committed
2

Oliver Seidel's avatar
Oliver Seidel committed
3
;; Copyright (C) 1997 Free Software Foundation, Inc.
Oliver Seidel's avatar
Oliver Seidel committed
4

Oliver Seidel's avatar
Oliver Seidel committed
5 6 7 8
;; Author: Oliver.Seidel@cl.cam.ac.uk (was valid on Aug 2, 1997)
;; Created: 2 Aug 1997
;; Version: $Id:$
;; Keywords: Categorised TODO list editor, todo-mode
Oliver Seidel's avatar
Oliver Seidel committed
9

Oliver Seidel's avatar
Oliver Seidel committed
10
;; This file is part of GNU Emacs.
11

Oliver Seidel's avatar
Oliver Seidel committed
12
;; GNU Emacs is free software; you can redistribute it and/or modify
13 14 15
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
Oliver Seidel's avatar
Oliver Seidel committed
16 17

;; GNU Emacs is distributed in the hope that it will be useful,
18 19 20
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
Oliver Seidel's avatar
Oliver Seidel committed
21

22 23 24 25 26 27 28
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;; ---------------------------------------------------------------------------

Oliver Seidel's avatar
Oliver Seidel committed
29 30
;;; Commentary:

31 32
;; Quickstart Installation:
;; ========================
33
;;
34
;; To get this to work, make emacs execute the line
35
;;
Oliver Seidel's avatar
Oliver Seidel committed
36
;; (require 'todo-mode)				;; load the TODO package
37
;;
Oliver Seidel's avatar
Oliver Seidel committed
38 39 40 41 42 43 44 45 46 47 48 49
;; You may now enter new items by typing "M-x todo-cmd-inst", or enter
;; your the TODO list file by typing "M-x todo-show".
;;
;; The TODO list file has a special format and some auxiliary information,
;; which will be added by the todo-show function if it attempts to visit
;; an un-initialised file.  Hence it is recommended to use the todo-show
;; function for the first time, in order to initialise the file, but it
;; is not necessary afterwards.
;;
;; As these commands are quite long to type, I would recommend the addition
;; of two bindings to your to your global keymap.  I personally have the
;; following in my initialisation file:
50
;;
51 52
;; (global-set-key "\C-ct" 'todo-show)		;; switch to TODO buffer
;; (global-set-key "\C-ci" 'todo-cmd-inst)	;; insert new item
Oliver Seidel's avatar
Oliver Seidel committed
53
;;
Oliver Seidel's avatar
Oliver Seidel committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
;; Note, however, that this recommendation has prompted some criticism,
;; since the keys C-c LETTER are reserved for user functions.  I believe
;; my recommendation is acceptable, since the Emacs Lisp Manual *Tips*
;; section also details that the mode itself should not bind any functions
;; to those keys.  The express aim of the above two bindings is to work
;; outside the mode, which doesn't need the show function and offers
;; a different binding for the insert function.  They serve as shortcuts
;; and are not even needed (since the TODO mode will be entered by
;; visiting the TODO file, and later by switching to its buffer).
;;
;;
;;
;; Pre-Requisites
;; ==============
;;
;; This package will require the following packages to be available on
;; the load-path:
;;                 - time-stamp
;;                 - easymenu
;;
74
;;
Oliver Seidel's avatar
Oliver Seidel committed
75
;;
76
;; Description:
77
;; ============
78
;;
79 80 81 82 83 84
;; TODO is a major mode for EMACS which offers functionality to treat
;; most lines in one buffer as a list of items one has to do.  There
;; are facilities to add new items, which are categorised, to edit or
;; even delete items from the buffer.  The buffer contents are currently
;; compatible with the diary, so that the list of todo-items will show
;; up in the FANCY diary mode.
85
;;
86 87 88 89 90 91 92 93 94 95 96
;; Notice:  Besides the major mode, this file also exports the function
;; "todo-show" which will change to the one specific TODO file that has
;; been specified in the todo-file-do variable.  If this file does not
;; conform to the TODO mode conventions, the todo-show function will add
;; the appropriate header and footer.  I don't anticipate this to cause
;; much grief, but be warned, in case you attempt to read a plain text file.
;;
;;
;;
;; Operation:
;; ==========
97 98
;;
;; You will have the following facilities available:
99
;;
100 101
;; M-x todo-show              will enter the todo list screen, here type
;;
102 103
;; +                          to go to next category
;; -                          to go to previous category
104
;; e                          to edit the current entry
105 106
;; f                          to file the current entry, including a
;;                                                 comment and timestamp
107 108
;; i                          to insert a new entry
;; k                          to kill the current entry
109
;; l                          to lower the current entry's priority
110 111 112
;; n                          for the next entry
;; p                          for the previous entry
;; q                          to save the list and exit the buffer
113
;; r                          to raise the current entry's priority
114
;; s                          to save the list
115
;;
116 117 118 119 120 121
;; When you add a new entry, you are asked for the text and then for the
;; category.  I for example have categories for things that I want to do
;; in the office (like mail my mum), that I want to do in town (like buy
;; cornflakes) and things I want to do at home (move my suitcases).  The
;; categories can be selected with the cursor keys and if you type in the
;; name of a category which didn't exist before, an empty category of the
122
;; desired name will be added and filled with the new entry.
123
;;
124 125
;;
;;
126 127
;; Configuration:
;; ==============
128
;;
129 130 131 132 133
;; --- todo-prefix
;;
;; I would like to recommend that you use the prefix "*/*" (by
;; leaving the variable 'todo-prefix' untouched) so that the diary
;; displays each entry every day.
134
;;
135 136 137 138
;; To understand what I mean, please read the documentation that goes
;; with the calendar since that will tell you how you can set up the
;; fancy diary display and use the #include command to include your
;; todo list file as part of your diary.
139
;;
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
;;
;; --- todo-file-do
;;
;; This variable is fairly self-explanatory.  You have to store your TODO
;; list somewhere.  This variable tells the package where to go and find
;; this file.
;;
;;
;; --- todo-file-done
;;
;; Even when you're done, you may wish to retain the entries.  Given
;; that they're timestamped and you are offered to add a comment, this
;; can make a useful diary of past events.  It will even blend in with
;; the EMACS diary package.  So anyway, this variable holds the name
;; of the file for the filed todo-items.
;;
;;
;; --- todo-mode-hook
;;
;; Just like other modes, too, this mode offers to call your functions
;; before it goes about its business.  This variable will be inspected
;; for any functions you may wish to have called once the other TODO
;; mode preparations have been completed.
;;
;;
;; --- todo-ins-thresh
;;
167 168 169 170 171 172 173 174 175 176 177
;; Another nifty feature is the insertion accuracy.  If you have 8 items
;; in your TODO list, then you may get asked 4 questions by the binary
;; insertion algorithm.  However, you may not really have a need for such
;; accurate priorities amongst your TODO items.  If you now think about
;; the binary insertion halfing the size of the window each time, then
;; the threshhold is the window size at which it will stop.  If you set
;; the threshhold to zero, the upper and lower bound will coincide at the
;; end of the loop and you will insert your item just before that point.
;; If you set the threshhold to i.e. 8, it will stop as soon as the window
;; size drops below that amount and will insert the item in the approximate
;; centre of that window.  I got the idea for this feature after reading
Oliver Seidel's avatar
Oliver Seidel committed
178
;; a very helpful e-mail reply from Trey Jackson <trey@cs.berkeley.edu>
179 180 181
;; who corrected some of my awful coding and pointed me towards some good
;; reading.  Thanks Trey!
;;
182 183
;;
;;
Oliver Seidel's avatar
Oliver Seidel committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
;;
;; Things to do:
;; =============
;;
;; - licence / version function
;; - export to diary file
;; - todo-report-bug
;; - GNATS support
;; - add idea from Urban Boquist <boquist@cs.chalmers.se>: multi-line-entries
;; - 'e' opens buffer for multi-line entry
;; - elide multiline
;; - rewrite complete package to store data as lisp objects and have
;;   display modes for display, for diary export, etc.
;;
;;
;;
200 201 202
;; History and Gossip:
;; ===================
;;
203 204 205 206 207 208
;; Many thanks to all the ones who have contributed to the evolution of this
;; package!  I hope I have listed all of you somewhere in the documentation
;; or at least in the RCS history!
;;
;; Enjoy this package and express your gratitude by sending nice things
;; to my parents' address!
209 210
;;
;; Oliver Seidel
211
;;
212
;; (O Seidel, Lessingstr. 8, 65760 Eschborn, Federal Republic of Germany)
213 214 215 216
;;

;; ---------------------------------------------------------------------------

Oliver Seidel's avatar
Oliver Seidel committed
217 218 219 220 221 222 223
;; ---------------------------------------------------------------------------

;;; Change Log:

;; $Log: todo-mode.el,v $
;; Revision 1.12  1997/08/06  10:56:15  os10000
;; Fixed header, typos, layout, documentation.
224
;;
225 226 227 228
;; Revision 1.11  1997/08/06  09:14:25  os10000
;; Applied patch from Istvan Marko <istvan@cmdmail.amd.com>
;; to make menus work anywhere.
;;
229 230 231 232
;; Revision 1.10  1997/08/06  08:56:03  os10000
;; Acted upon suggestion from Shane Holder <holder@rsn.hp.com>:
;; Cancelling the editing of an entry will not delete it any more.
;;
233 234 235 236 237
;; Revision 1.9  1997/08/06 08:12:03  os10000
;; Improved documentation.  Broke some lines to comply with
;; Richard Stallman's email to please keep in sync with the
;; rest of the Emacs distribution files.
;;
238
;; Revision 1.8  1997/08/05 22:39:04  os10000
Oliver Seidel's avatar
Oliver Seidel committed
239
;; Made todo-mode.el available under GPL.
240 241 242
;;
;; Revision 1.7  1997/08/05 22:34:14  os10000
;; Fixed insertion routine with help from Trey Jackson
Oliver Seidel's avatar
Oliver Seidel committed
243
;; <trey@cs.berkeley.edu>; added todo-ins-thresh;
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
;; fixed keyboard layout to remove unwanted keys.
;;
;; Revision 1.6  1997/08/05 16:47:01  os10000
;; Incorporated menus for XEmacs from Allan.Cochrane@soton.sc.philips.com,
;; fixed TYPO, fixed todo-file-cmd, cleaned up rcs history.
;;
;; Revision 1.5  1997/08/05  14:43:39  os10000
;; Added improvements from Ron Gut <rgut@aware.com>.
;; Added category management.
;;
;; Revision 1.4  1997/08/04  16:18:45  os10000
;; Added Raise/Lower item.
;;
;; Revision 1.3  1997/08/03  12:47:26  os10000
;; Cleaned up variables, prefix and cursor position.
;;
;; Revision 1.2  1997/08/03 12:15:28  os10000
;; It appears to work.
;;
;; Revision 1.1  1997/08/03 12:15:13  os10000
;; Initial revision
;;
266 267 268

;; ---------------------------------------------------------------------------

Oliver Seidel's avatar
Oliver Seidel committed
269 270
;;; Code:

Oliver Seidel's avatar
Oliver Seidel committed
271 272
;; User-configurable variables:

273 274 275 276 277
(defvar todo-prefix	"*/*"		"TODO mode prefix for entries.")
(defvar todo-file-do	"~/.todo-do"	"TODO mode list file.")
(defvar todo-file-done	"~/.todo-done"	"TODO mode archive file.")
(defvar todo-mode-hook	nil		"TODO mode hooks.")
(defvar todo-ins-thresh	0		"TODO mode insertion accuracy.")
Oliver Seidel's avatar
Oliver Seidel committed
278

Oliver Seidel's avatar
Oliver Seidel committed
279 280 281 282 283 284 285 286

;; Thanks for the ISO time stamp format go to Karl Eichwalder <ke@suse.de>
;; My format string for the appt.el package is "%3b %2d, %y, %02I:%02M%p".
;;
(defvar todo-time-string-format "%y-%02m-%02d %02H:%02M"
  "TODO mode time string format for done entries.
For details see the variable `time-stamp-format'.")

Oliver Seidel's avatar
Oliver Seidel committed
287 288
;; ---------------------------------------------------------------------------

289 290
;; Get some outside help ...

Oliver Seidel's avatar
Oliver Seidel committed
291
(require 'time-stamp)
292 293 294
(require 'easymenu)

;; ---------------------------------------------------------------------------
Oliver Seidel's avatar
Oliver Seidel committed
295

296 297 298 299 300 301 302 303 304 305
;; Set up some helpful context ...

(defvar todo-cats		nil	"TODO categories.")
(defvar todo-prv-lne		0	"previous line that I asked about.")
(defvar todo-prv-ans		0	"previous answer that I got.")
(defvar todo-mode-map		nil	"TODO mode keymap.")
(defvar todo-category-number	0	"TODO category number.")

;; ---------------------------------------------------------------------------

306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
(if todo-mode-map
    nil
  (let ((map (make-keymap)))
    (suppress-keymap map t)
    (define-key map "+" 'todo-cmd-forw)
    (define-key map "-" 'todo-cmd-back)
    (define-key map "e" 'todo-cmd-edit)
    (define-key map "f" 'todo-cmd-file)
    (define-key map "i" 'todo-cmd-inst)
    (define-key map "k" 'todo-cmd-kill)
    (define-key map "l" 'todo-cmd-lowr)
    (define-key map "n" 'todo-cmd-next)
    (define-key map "p" 'todo-cmd-prev)
    (define-key map "q" 'todo-cmd-done)
    (define-key map "r" 'todo-cmd-rais)
    (define-key map "s" 'todo-cmd-save)
    (setq todo-mode-map map)))
Oliver Seidel's avatar
Oliver Seidel committed
323

324 325
(defun todo-cat-slct ()
  (let ((todo-category-name (nth todo-category-number todo-cats)))
326 327
    (setq mode-line-buffer-identification
	  (concat "Category: " todo-category-name))
328 329 330 331 332 333
    (widen)
    (goto-char (point-min))
    (search-forward (concat "--- " todo-category-name))
    (setq begin (+ (point-at-eol) 1))
    (search-forward "--- End")
    (narrow-to-region begin (point-at-bol))
334
    (goto-char (point-min))))
335 336 337 338 339 340

(defun todo-cmd-forw () "Go forward to TODO list of next category."
  (interactive)
  (let ((todo-cat-cnt (- (length todo-cats) 1)))
    (setq todo-category-number (if (< todo-category-number todo-cat-cnt)
				   (+ todo-category-number 1) 0))
341
    (todo-cat-slct)))
342 343 344 345 346 347

(defun todo-cmd-back () "Go back to TODO list of previous category."
  (interactive)
  (let ((todo-cat-cnt (- (length todo-cats) 1)))
    (setq todo-category-number (if (> todo-category-number 0)
				   (- todo-category-number 1) todo-cat-cnt))
348
    (todo-cat-slct)))
349 350

(defun todo-cmd-prev () "Select previous entry of TODO list."
Oliver Seidel's avatar
Oliver Seidel committed
351 352 353
  (interactive)
  (forward-line -1)
  (beginning-of-line nil)
354
  (message ""))
Oliver Seidel's avatar
Oliver Seidel committed
355

356
(defun todo-cmd-next () "Select next entry of TODO list."
Oliver Seidel's avatar
Oliver Seidel committed
357 358 359
  (interactive)
  (forward-line 1)
  (beginning-of-line nil)
360
  (message ""))
Oliver Seidel's avatar
Oliver Seidel committed
361

362 363
(defun todo-cmd-save () "Save the TODO list."
  (interactive)
364
  (save-buffer))
365 366

(defun todo-cmd-done () "Done with TODO list for now."
Oliver Seidel's avatar
Oliver Seidel committed
367
  (interactive)
368 369
  (widen)
  (save-buffer)
370 371
  (beginning-of-line nil)
  (message "")
372
  (bury-buffer))
Oliver Seidel's avatar
Oliver Seidel committed
373

374 375
(defun todo-line () "Find current line in buffer."
  (buffer-substring (point-at-bol) (point-at-eol)))
Oliver Seidel's avatar
Oliver Seidel committed
376

377
(defun todo-cmd-edit () "Edit current TODO list entry."
Oliver Seidel's avatar
Oliver Seidel committed
378
  (interactive)
379
  (let ((todo-entry (read-from-minibuffer "Edit: " (todo-line))))
380
    (delete-region (point-at-bol) (point-at-eol))
381
    (insert todo-entry)
382
    (beginning-of-line nil)
383
    (message "")))
Oliver Seidel's avatar
Oliver Seidel committed
384

385
(defun todo-add-category (cat) "Add a new category to the TODO list."
Oliver Seidel's avatar
Oliver Seidel committed
386 387
  (interactive)
  (save-window-excursion
388
    (setq todo-cats (cons cat todo-cats))
Oliver Seidel's avatar
Oliver Seidel committed
389
    (find-file todo-file-do)
390 391 392 393
    (widen)
    (goto-char (point-min))
    (let ((posn (search-forward "-*- mode: todo; " 17 t)))
      (if (not (null posn)) (goto-char posn))
394 395 396 397 398
      (if (equal posn nil)
	  (progn
	    (insert "-*- mode: todo; \n")
	    (forward-char -1))
	(kill-line)))
399 400
    (insert (format "todo-cats: %S; -*-" todo-cats))
    (forward-char 1)
401
    (insert (format "%s --- %s\n--- End\n%s %s\n"
402 403
		    todo-prefix cat todo-prefix (make-string 75 ?-))))
  0)
404

405 406
(defun todo-cmd-inst ()
  "Insert new TODO list entry."
407
  (interactive)
Oliver Seidel's avatar
Oliver Seidel committed
408
  (beginning-of-line nil)
409 410
  (let* ((todo-entry (concat todo-prefix " "
			     (read-from-minibuffer "New TODO entry: ")))
411 412
         (temp-catgs todo-cats)
         (todo-hstry (cons 'temp-catgs (+ todo-category-number 1))))
413 414
    (save-window-excursion
      (setq todo-category
415 416 417 418 419 420 421 422 423
            (read-from-minibuffer "Category: "
                                  (nth todo-category-number todo-cats)
                                  nil nil todo-hstry))

      (let ((cat-exists (member todo-category todo-cats)))
        (setq todo-category-number
              (if cat-exists
                  (- (length todo-cats) (length cat-exists))
                (todo-add-category todo-category))))
424 425
      (todo-show)
      (setq todo-prv-lne 0)
426 427 428 429 430

      (let ((todo-fst 1)
            (todo-lst (+ 1 (count-lines (point-min) (point-max)))))
        (while (> (- todo-lst todo-fst) todo-ins-thresh)
          (let* ((todo-cur (/ (+ todo-fst todo-lst) 2))
431
                 (todo-ans (if (< todo-cur todo-lst)
Oliver Seidel's avatar
Oliver Seidel committed
432
			       (todo-ask-p todo-cur) nil)))
433 434 435 436 437 438 439 440 441
            (if todo-ans
                (setq todo-lst todo-cur)
              (setq todo-fst (+ todo-cur 1)))))

	(setq todo-fst (/ (+ todo-fst todo-lst) 2))
        ;; goto-line doesn't have the desired behavior in a narrowed buffer
        (goto-char (point-min))
        (forward-line (- todo-fst 1)))
      
442
      (insert (concat todo-entry "\n"))
443
      (forward-line -1))
444
    (beginning-of-line nil)
Oliver Seidel's avatar
Oliver Seidel committed
445
    (save-buffer)
446 447
    (message "")))

Oliver Seidel's avatar
Oliver Seidel committed
448
(defun todo-ask-p (lne) 
449 450 451 452 453 454
  "Ask whether entry is more important than at LNE."
  (if (not (equal todo-prv-lne lne))
      (progn
        (setq todo-prv-lne lne)
        (goto-char (point-min))
        (forward-line (- todo-prv-lne 1))
455 456 457
        (setq todo-prv-ans (y-or-n-p
			    (concat "More important than '"
				    (todo-line) "'? ")))))
458
  todo-prv-ans)
Oliver Seidel's avatar
Oliver Seidel committed
459

460
(defun todo-cmd-kill () "Delete current TODO list entry."
Oliver Seidel's avatar
Oliver Seidel committed
461 462 463
  (interactive)
  (if (> (count-lines (point-min) (point-max)) 0)
      (progn
464
	(let* ((todo-entry (todo-line))
465 466
	       (todo-answer (y-or-n-p (concat "Permanently remove '"
					      todo-entry "'? "))))
467 468 469
	  (if todo-answer
	      (progn
		(delete-region (point-at-bol) (+ 1 (point-at-eol))) 
470 471
		(forward-line -1))))
	(message ""))
Oliver Seidel's avatar
Oliver Seidel committed
472
    (error "No TODO list entry to delete"))
473
  (beginning-of-line nil))
Oliver Seidel's avatar
Oliver Seidel committed
474

Oliver Seidel's avatar
Oliver Seidel committed
475 476 477 478 479
(defun todo-cmd-rais () "Raise priority of current entry."
  (interactive)
  (if (> (count-lines (point-min) (point-max)) 0)
      (progn
	(setq todo-entry (todo-line))
480
	(delete-region (point-at-bol) (+ 1 (point-at-eol))) 
Oliver Seidel's avatar
Oliver Seidel committed
481 482
	(forward-line -1)
	(insert (concat todo-entry "\n"))
483
	(forward-line -1)
484
	(message ""))
Oliver Seidel's avatar
Oliver Seidel committed
485
    (error "No TODO list entry to raise"))
486
  (beginning-of-line nil))
Oliver Seidel's avatar
Oliver Seidel committed
487 488 489 490 491 492

(defun todo-cmd-lowr () "Lower priority of current entry."
  (interactive)
  (if (> (count-lines (point-min) (point-max)) 0)
      (progn
	(setq todo-entry (todo-line))
493
	(delete-region (point-at-bol) (+ 1 (point-at-eol))) 
Oliver Seidel's avatar
Oliver Seidel committed
494 495
	(forward-line 1)
	(insert (concat todo-entry "\n"))
496
	(forward-line -1)
497
	(message ""))
Oliver Seidel's avatar
Oliver Seidel committed
498
    (error "No TODO list entry to lower"))
499
  (beginning-of-line nil))
Oliver Seidel's avatar
Oliver Seidel committed
500

501
(defun todo-cmd-file () "File away the current TODO list entry."
Oliver Seidel's avatar
Oliver Seidel committed
502 503 504
  (interactive)
  (if (> (count-lines (point-min) (point-max)) 0)
      (progn
Oliver Seidel's avatar
Oliver Seidel committed
505 506
	(let ((todo-comment (read-from-minibuffer "Comment: "))
	      (time-stamp-format todo-time-string-format))
507
	  (beginning-of-line nil)
508
	  (delete-region (point-at-bol) (search-forward todo-prefix))
509 510
	  (insert (time-stamp-string))
	  (end-of-line nil)
Oliver Seidel's avatar
Oliver Seidel committed
511
	  (insert (concat " (" todo-comment ")"))
512 513
	  (append-to-file (point-at-bol) (+ 1 (point-at-eol)) todo-file-done)
	  (delete-region (point-at-bol) (+ 1 (point-at-eol)))
514 515
	  (forward-line -1))
	(message ""))
Oliver Seidel's avatar
Oliver Seidel committed
516
    (error "No TODO list entry to file away"))
517
  (beginning-of-line nil))
Oliver Seidel's avatar
Oliver Seidel committed
518 519 520

;; ---------------------------------------------------------------------------

521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
;; utility functions:  These are available in XEmacs, but not in Emacs 19.34

(if (not (fboundp 'point-at-bol))
    (defun point-at-bol ()
      (save-excursion
	(beginning-of-line)
	(point))))

(if (not (fboundp 'point-at-eol))
    (defun point-at-eol ()
      (save-excursion
	(end-of-line)
	(point))))

;; ---------------------------------------------------------------------------

537
(easy-menu-define todo-menu todo-mode-map "Todo Menu"
Oliver Seidel's avatar
Oliver Seidel committed
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
		  '("Todo"
		    ["Next category"        todo-cmd-forw t]
		    ["Previous category"    todo-cmd-back t]
		    "---"
		    ["Edit item"            todo-cmd-edit t]
		    ["File item"            todo-cmd-file t]
		    ["Insert new item"      todo-cmd-inst t]
		    ["Kill item"            todo-cmd-kill t]
		    "---"
		    ["Lower item priority"  todo-cmd-lowr t]
		    ["Raise item priority"  todo-cmd-rais t]
		    "---"
		    ["Next item"            todo-cmd-next t]
		    ["Previous item"        todo-cmd-prev t]
		    "---"
		    ["Save"                 todo-cmd-save t]
		    "---"
		    ["Quit"                 todo-cmd-done t]
		    ))
557

558
(defun todo-mode () "Major mode for editing TODO lists.\n\n\\{todo-mode-map}"
Oliver Seidel's avatar
Oliver Seidel committed
559 560 561 562
  (interactive)
  (setq major-mode 'todo-mode)
  (setq mode-name "TODO")
  (use-local-map todo-mode-map)
563 564
  (easy-menu-add todo-menu)
  (run-hooks 'todo-mode-hook))
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579

(defun todo-show () "Show TODO list."
  (interactive)
  (find-file todo-file-do)
  (if (null todo-cats)
      (progn
	(todo-add-category "Todo")
	(goto-char (point-min))
	(goto-char (search-forward "--- End"))
	(let ((bol (point-at-bol)))
	  (forward-line 1)
	  (let* ((eol (+ (point-at-eol) 1))
		 (mrkr (buffer-substring bol eol)))
	    (delete-region bol eol)
	    (goto-char (point-max))
580
	    (insert mrkr)))
581 582
	(save-buffer)
	(kill-buffer (current-buffer))
583
	(find-file todo-file-do)))
584
  (beginning-of-line nil)
585
  (todo-cat-slct))
Oliver Seidel's avatar
Oliver Seidel committed
586

Oliver Seidel's avatar
Oliver Seidel committed
587
(provide 'todo-mode)
Oliver Seidel's avatar
Oliver Seidel committed
588 589 590

;; ---------------------------------------------------------------------------

Oliver Seidel's avatar
Oliver Seidel committed
591
;;; todo-mode.el ends here
Oliver Seidel's avatar
Oliver Seidel committed
592 593

;; ---------------------------------------------------------------------------