From: Oliver Seidel Date: Tue, 5 Aug 1997 14:43:39 +0000 (+0000) Subject: Added improvements from Ron Gut . X-Git-Tag: emacs-20.1~781 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=da2ee6858f61cda1a41d73c90f47ee5f35338ab4;p=emacs.git Added improvements from Ron Gut . Added category management. --- diff --git a/lisp/calendar/todo-mode.el b/lisp/calendar/todo-mode.el index 4fedb4e4ac8..fb5049c6008 100644 --- a/lisp/calendar/todo-mode.el +++ b/lisp/calendar/todo-mode.el @@ -1,4 +1,4 @@ -;; todomode.el -- major mode for editing Todo-List files +; todomode.el -- major mode for editing TODO list files ;; --------------------------------------------------------------------------- @@ -6,9 +6,12 @@ ;; please contact (address) O Seidel, Lessingstr 8, Eschborn, FRG ;; (e-mail ) Oliver.Seidel@cl.cam.ac.uk (2 Aug 1997) -;; $Id: todomode.el,v 1.3 1997/08/03 12:47:26 os10000 Exp os10000 $ +;; $Id: todomode.el,v 1.4 1997/08/04 16:18:45 os10000 Exp os10000 $ ;; ;; $Log: todomode.el,v $ +;; 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. ;; @@ -29,38 +32,38 @@ ;; Then you have the following facilities available: ;; ;; M-x todo-mode will enter the todo list screen, here type -;; p for the previous entry -;; n for the next entry -;; q to save the list and exit the buffer +;; + to go to next category +;; - to go to previous category ;; e to edit the current entry +;; f to file the current entry, including a +;; comment and timestamp ;; i to insert a new entry ;; k to kill the current entry -;; r raise current entryk's priority ;; l lower the current entry's priority -;; f to file the current entry, including a -;; comment and timestamp +;; n for the next entry +;; p for the previous entry +;; q to save the list and exit the buffer +;; r raise current entryk's priority +;; s to save the list ;; ;; I would recommend to add the following bindings to your global keymap: ;; -;; (global-set-key "\C-ct" 'todo-mode) +;; (global-set-key "\C-ct" 'todo-show) ;; (global-set-key "\C-ci" 'todo-cmd-inst) ;; ;; This will enable you to quickly find the todo-list, or to simply add an ;; entry, without changing to it and getting sidetracked from your current ;; project. ;; -;; I would also recommend that you execute the command -;; -;; (setq todo-prefix "*/* ") -;; -;; to have all your entries prefixed in such a way that the diary displays -;; them every day. +;; I would also recommend that use the prefix "*/*" (by leaving the +;; variable 'todo-prefix' untouched) so that the diary displays +;; each entry every day. ;; --------------------------------------------------------------------------- ;; User-configurable variables: -(defvar todo-prefix "" "TODO mode prefix when creating entries") +(defvar todo-prefix "*/*" "TODO mode prefix when creating entries") (defvar todo-file-do "~/.todo-do" "TODO mode filename of list file") (defvar todo-file-done "~/.todo-done" "TODO mode filename of archive file") (defvar todo-mode-hook nil "Hooks invoked when the *TODO* buffer is created.") @@ -69,63 +72,96 @@ (require 'time-stamp) -(defvar todo-begin (point-min) "TODO mode beginning of line") -(defvar todo-end (point-min) "TODO mode end of line") - -(setq todo-mode-map (make-keymap)) -(suppress-keymap todo-mode-map) -(define-key todo-mode-map "p" 'todo-cmd-prev) -(define-key todo-mode-map "n" 'todo-cmd-next) -(define-key todo-mode-map "q" 'todo-cmd-done) +(defvar todo-mode-map (make-sparse-keymap) "TODO mode keymap. See `todo-mode'") +(define-key todo-mode-map "+" 'todo-cmd-forw) +(define-key todo-mode-map "-" 'todo-cmd-back) (define-key todo-mode-map "e" 'todo-cmd-edit) +(define-key todo-mode-map "f" 'todo-cmd-file) (define-key todo-mode-map "i" 'todo-cmd-inst) (define-key todo-mode-map "k" 'todo-cmd-kill) -(define-key todo-mode-map "r" 'todo-cmd-rais) (define-key todo-mode-map "l" 'todo-cmd-lowr) -(define-key todo-mode-map "f" 'todo-cmd-file) +(define-key todo-mode-map "n" 'todo-cmd-next) +(define-key todo-mode-map "p" 'todo-cmd-prev) +(define-key todo-mode-map "q" 'todo-cmd-done) +(define-key todo-mode-map "r" 'todo-cmd-rais) +(define-key todo-mode-map "s" 'todo-cmd-save) -(defun todo-cmd-prev () "Select previous entry." +(defun todo-cat-slct () + (let ((todo-category-name (nth todo-category-number todo-cats))) + (setq mode-line-buffer-identification (concat "Category: " todo-category-name)) + (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)) + (goto-char (point-min)) + ) +) + +(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)) + (todo-cat-slct) + ) + ) + +(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)) + (todo-cat-slct) + ) + ) + +(defun todo-cmd-prev () "Select previous entry of TODO list." (interactive) (forward-line -1) (beginning-of-line nil) (message "") ) -(defun todo-cmd-next () "Select next entry." +(defun todo-cmd-next () "Select next entry of TODO list." (interactive) (forward-line 1) (beginning-of-line nil) (message "") ) -(defun todo-cmd-done () "Done with todo list for now." +(defun todo-cmd-save () "Save the TODO list." + (interactive) + (save-buffer) + ) + +(defun todo-cmd-done () "Done with TODO list for now." (interactive) + (widen) + (save-buffer) (beginning-of-line nil) (message "") - (save-buffer) (bury-buffer) ) -(defun todo-line () "Find current line in buffer." - (end-of-line nil) (setq todo-end (point)) - (beginning-of-line nil) (setq todo-begin (point)) - (buffer-substring todo-begin todo-end) - ) +(defun todo-line () "Find current line in buffer." (buffer-substring (point-at-bol) (point-at-eol))) -(defun todo-cmd-edit () "Edit current todo list entry." +(defun todo-cmd-edit () "Edit current TODO list entry." (interactive) - (setq todo-entry (todo-line)) - (delete-region todo-begin todo-end) - (insert (read-from-minibuffer "Edit: " todo-entry)) - (beginning-of-line nil) - (message "") + (let ((todo-entry (todo-line))) + (delete-region (point-at-bol) (point-at-eol)) + (insert (read-from-minibuffer "Edit: " todo-entry)) + (beginning-of-line nil) + (message "") + ) ) (defvar todo-prv-lne 0 "previous line that I asked about.") (defvar todo-prv-ans 0 "previous answer that I got.") (defun todo-ask (lne) "Ask whether entry is more important than at LNE." - (if (not (equal todo-prv-lne lne) ) + (if (not (equal todo-prv-lne lne)) (progn (setq todo-prv-lne lne) (goto-line todo-prv-lne) @@ -135,43 +171,86 @@ todo-prv-ans ) -(defun todo-cmd-inst () "Insert new todo list entry." +(defun todo-add-category (cat) "Add a new category to the TODO list." (interactive) - (beginning-of-line nil) - (setq todo-entry (concat "*/* " (read-from-minibuffer "New TODO entry: "))) (save-window-excursion + (setq todo-cats (cons cat todo-cats)) (find-file todo-file-do) - (setq todo-prv-lne 0) - (let* ((todo-fst 1) - (todo-lst (+ 1 (count-lines (point-min) (point-max))))) - (while (< todo-fst todo-lst) - (setq todo-cur (/ (+ todo-fst todo-lst) 2)) - (setq todo-ans (if (< todo-cur todo-lst) (todo-ask todo-cur) nil)) - (if todo-ans - (setq todo-lst todo-cur) - (setq todo-fst (+ todo-cur 1))) - ) - (goto-line todo-fst) + (widen) + (goto-char (point-min)) + (let ((posn (search-forward "-*- mode: todo; " 17 t))) + (if (not (null posn)) (goto-char posn)) + (if (equal posn nil) (progn (insert "-*- mode: todo; \n") (forward-char -1)) (kill-line)) ) - (insert (concat todo-entry "\n")) - (forward-char -1) + (insert (format "todo-cats: %S; -*-" todo-cats)) + (forward-char 1) + (insert (format "%s --- %s\n--- End\n%s %s\n" todo-prefix cat todo-prefix (make-string 75 ?-))) ) + 0 + ) + +(defun todo-cmd-inst () "Insert new TODO list entry." + (interactive) (beginning-of-line nil) - (message "") + (let* ((todo-entry (concat todo-prefix " " (read-from-minibuffer "New TODO entry: "))) + (temp-catgs todo-cats) + (todo-hstry (cons 'temp-cats (+ todo-category-number 1)))) + (save-window-excursion + (setq todo-category + (read-from-minibuffer "Category: " (nth todo-category-number todo-cats) nil nil todo-hstry)) + (let* ((ltrgt todo-category) + (lnmbr 0) + (ltext (car todo-cats)) + (lrest (cdr todo-cats))) + (setq ltext (car todo-cats)) + (while (not (or (null lrest) (string-equal ltext ltrgt))) + (setq ltext (car lrest)) + (setq lrest (cdr lrest)) + (setq lnmbr (+ 1 lnmbr)) + ) + (setq todo-category-number + (if (string-equal ltext todo-category) lnmbr (todo-add-category todo-category))) + ) + (todo-show) + (setq todo-prv-lne 0) + (let* ((todo-fst 1) + (todo-lst (+ 1 (count-lines (point-min) (point-max))))) + (while (< todo-fst todo-lst) + (let* ((todo-cur (/ (+ todo-fst todo-lst) 2)) + (todo-ans (if (< todo-cur todo-lst) (todo-ask todo-cur) nil))) + (if todo-ans + (setq todo-lst todo-cur) + (setq todo-fst (+ todo-cur 1))) + ) + ) + (goto-line todo-fst) + ) + (insert (concat todo-entry "\n")) + (forward-line -1) + ) + (beginning-of-line nil) + (message "") + ) ) -(defun todo-cmd-kill () "Delete current todo list entry." +(defun todo-cmd-kill () "Delete current TODO list entry." (interactive) (if (> (count-lines (point-min) (point-max)) 0) (progn - (setq todo-entry (todo-line)) - (setq todo-answer (y-or-n-p (concat "Permanently remove '" todo-entry "'? "))) - (if todo-answer (progn (delete-region todo-begin (+ 1 todo-end)) (forward-char -1))) + (let* ((todo-entry (todo-line)) + (todo-answer (y-or-n-p (concat "Permanently remove '" todo-entry "'? ")))) + (if todo-answer + (progn + (delete-region (point-at-bol) (+ 1 (point-at-eol))) + (forward-line -1) + ) + ) + ) + (message "") ) - (message "No entry to delete.") + (message "No TODO list entry to delete.") ) (beginning-of-line nil) - (message "") ) (defun todo-cmd-rais () "Raise priority of current entry." @@ -179,15 +258,15 @@ (if (> (count-lines (point-min) (point-max)) 0) (progn (setq todo-entry (todo-line)) - (delete-region todo-begin (+ 1 todo-end)) + (delete-region (point-at-bol) (+ 1 (point-at-eol))) (forward-line -1) (insert (concat todo-entry "\n")) - (forward-char -1) + (forward-line -1) + (message "") ) - (message "No entry to raise.") + (message "No TODO list entry to raise.") ) (beginning-of-line nil) - (message "") ) (defun todo-cmd-lowr () "Lower priority of current entry." @@ -195,54 +274,96 @@ (if (> (count-lines (point-min) (point-max)) 0) (progn (setq todo-entry (todo-line)) - (delete-region todo-begin (+ 1 todo-end)) + (delete-region (point-at-bol) (+ 1 (point-at-eol))) (forward-line 1) (insert (concat todo-entry "\n")) - (forward-char -1) + (forward-line -1) + (message "") ) - (message "No entry to raise.") + (message "No TODO list entry to raise.") ) (beginning-of-line nil) - (message "") ) -(defun todo-cmd-file () "File away the current todo list entry." +(defun todo-cmd-file () "File away the current TODO list entry." (interactive) (if (> (count-lines (point-min) (point-max)) 0) (progn - (setq time-stamp-format " %2d, %y, %02I:%02M%p %b") - (setq tmp (time-stamp-string)) - (beginning-of-line nil) - (insert (concat (substring tmp 19 22) (substring tmp 0 19))) - (end-of-line nil) - (insert (concat " (" (read-from-minibuffer "Comment: ") ")")) - (todo-line) - (append-to-file todo-begin (+ 1 todo-end) todo-file-done) - (delete-region todo-begin (+ 1 todo-end)) - (forward-char -1) + (let ((time-stamp-format "%3b %2d, %y, %02I:%02M%p")) + (beginning-of-line nil) + (insert (time-stamp-string)) + (end-of-line nil) + (insert (concat " (" (read-fromminibuffer "Comment: ") ")")) + (append-to-file (point-at-bol) (+ 1 (point-at-eol)) todo-file-done) + (delete-region (point-at-bol) (+ 1 (point-at-eol))) + (forward-line -1) + ) + (message "") ) - (message "No entry to delete.") + (message "No TODO list entry to delete.") ) (beginning-of-line nil) - (message "") ) ;; --------------------------------------------------------------------------- -(defun todo-mode () - "Major mode for editing TODO lists.\n\n\\{todo-mode-map}" +;; 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)))) + +;; --------------------------------------------------------------------------- + +(defvar todo-cats nil "TODO categories.") +(defvar todo-category-number 0 "TODO category number.") + +(defun todo-mode () "Major mode for editing TODO lists.\n\n\\{todo-mode-map}" (interactive) - (find-file todo-file-do) (setq major-mode 'todo-mode) (setq mode-name "TODO") (use-local-map todo-mode-map) + (run-hooks 'todo-mode-hook) + ) + +(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)) + (insert mrkr) + ) + ) + (save-buffer) + (kill-buffer (current-buffer)) + (find-file todo-file-do) + ) + ) (beginning-of-line nil) - (run-hooks 'todo-mode-hook) ) + (todo-cat-slct) + ) (provide 'todomode) ;; --------------------------------------------------------------------------- -;;; todomode.el ends here +;; todomode.el ends here ;; ---------------------------------------------------------------------------