From: Stephen Berman Date: Fri, 20 Dec 2013 17:16:47 +0000 (+0100) Subject: Todo mode bug fixes and new features. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~289 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2f99433b944d602c382bfa87c8e3e27b1eaaed3b;p=emacs.git Todo mode bug fixes and new features. * calendar/todo-mode.el: Bug fixes and new features. (todo-toggle-item-highlighting): Use eval-and-compile instead of eval-when-compile. (todo-move-category): Allow choosing a non-existing todo file to move the category to, and create that file. (todo-default-priority): New user option. (todo-set-item-priority): Use it. (todo-desktop-save-buffer, todo-restore-desktop-buffer): New functions. (desktop-restore-file-buffer): Declare. (desktop-buffer-mode-handlers): Add todo-restore-desktop-buffer. (todo-modes-set-2): Locally set desktop-save-buffer to todo-desktop-save-buffer. (todo-mode, todo-archive-mode, todo-filtered-items-mode) (auto-mode-alist): Add autoload cookie. Fixes: debbugs:15225 --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index b3315ca8c56..e367749fb39 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,20 @@ +2013-12-20 Stephen Berman + + * calendar/todo-mode.el: Bug fixes and new features (bug#15225). + (todo-toggle-item-highlighting): Use eval-and-compile instead of + eval-when-compile. + (todo-move-category): Allow choosing a non-existing todo file to + move the category to, and create that file. + (todo-default-priority): New user option. + (todo-set-item-priority): Use it. + (todo-desktop-save-buffer, todo-restore-desktop-buffer): New functions. + (desktop-restore-file-buffer): Declare. + (desktop-buffer-mode-handlers): Add todo-restore-desktop-buffer. + (todo-modes-set-2): Locally set desktop-save-buffer to + todo-desktop-save-buffer. + (todo-mode, todo-archive-mode, todo-filtered-items-mode) + (auto-mode-alist): Add autoload cookie. + 2013-12-20 Bozhidar Batsov * emacs-lisp/subr-x.el: Renamed from helpers.el. diff --git a/lisp/calendar/todo-mode.el b/lisp/calendar/todo-mode.el index 943aa8b34b5..3dcb305f05a 100644 --- a/lisp/calendar/todo-mode.el +++ b/lisp/calendar/todo-mode.el @@ -1040,7 +1040,7 @@ empty line above the done items separator." (defun todo-toggle-item-highlighting () "Highlight or unhighlight the todo item the cursor is on." (interactive) - (eval-when-compile (require 'hl-line)) + (eval-and-compile (require 'hl-line)) (when (memq major-mode '(todo-mode todo-archive-mode todo-filtered-items-mode)) (if hl-line-mode @@ -1360,8 +1360,9 @@ todo or done items." (defun todo-move-category () "Move current category to a different todo file. -If current category has archived items, also move those to the -archive of the file moved to, creating it if it does not exist." +If the todo file chosen does not exist, it is created. +If the current category has archived items, also move those to +the archive of the file moved to, creating it if it does not exist." (interactive) (when (or (> (length todo-categories) 1) (todo-y-or-n-p (concat "This is the only category in this file; " @@ -1370,15 +1371,22 @@ archive of the file moved to, creating it if it does not exist." (let* ((ofile todo-current-todo-file) (cat (todo-current-category)) (nfile (todo-read-file-name - "Choose a todo file to move this category to: " nil t)) + "Todo file to move this category to: " nil)) (archive (concat (file-name-sans-extension ofile) ".toda")) (buffers (append (list ofile) (unless (zerop (todo-get-count 'archived cat)) (list archive)))) new) - (while (equal (file-truename nfile) (file-truename ofile)) + (while (equal nfile (file-truename ofile)) (setq nfile (todo-read-file-name - "Choose a file distinct from this file: " nil t))) + "Choose a file distinct from this file: " nil))) + (unless (member nfile todo-files) + (with-current-buffer (get-buffer-create nfile) + (erase-buffer) + (write-region (point-min) (point-max) nfile nil 'nomessage nil t) + (kill-buffer nfile)) + (setq todo-files (funcall todo-files-function)) + (todo-reevaluate-filelist-defcustoms)) (dolist (buf buffers) (with-current-buffer (find-file-noselect buf) (widen) @@ -1633,6 +1641,12 @@ current time, if nil, they include it." :type 'boolean :group 'todo-edit) +(defcustom todo-default-priority 'first + "Default priority of new and moved items." + :type '(choice (const :tag "Highest priority" first) + (const :tag "Lowest priority" last)) + :group 'todo-edit) + (defcustom todo-item-mark "*" "String used to mark items. To ensure item marking works, change the value of this option @@ -2617,7 +2631,9 @@ meaning to raise or lower the item's priority by one." ;; todo item. (when (> maxnum 1) (while (not priority) - (setq candidate (read-number prompt)) + (setq candidate (read-number prompt + (if (eq todo-default-priority 'first) + 1 maxnum))) (setq prompt (when (or (< candidate 1) (> candidate maxnum)) (format "Priority must be an integer between 1 and %d.\n" maxnum))) @@ -5263,6 +5279,22 @@ Overrides `diary-goto-entry'." (add-function :override diary-goto-entry-function #'todo-diary-goto-entry) +(defun todo-desktop-save-buffer (_dir) + `((catnum . ,(todo-category-number (todo-current-category))))) + +(declare-function desktop-restore-file-buffer "desktop" + (buffer-filename buffer-name buffer-misc)) + +(defun todo-restore-desktop-buffer (file buffer misc) + (desktop-restore-file-buffer file buffer misc) + (with-current-buffer buffer + (widen) + (let ((todo-category-number (cdr (assq 'catnum misc)))) + (todo-category-select)))) + +(add-to-list 'desktop-buffer-mode-handlers + '(todo-mode . todo-restore-desktop-buffer)) + (defun todo-done-item-p () "Return non-nil if item at point is a done item." (save-excursion @@ -6480,6 +6512,8 @@ Added to `window-configuration-change-hook' in Todo mode." "Make some settings that apply to multiple Todo modes." (add-to-invisibility-spec 'todo) (setq buffer-read-only t) + (when (and (boundp 'desktop-save-mode) desktop-save-mode) + (setq-local desktop-save-buffer 'todo-desktop-save-buffer)) (when (boundp 'hl-line-range-function) (setq-local hl-line-range-function (lambda() (save-excursion @@ -6495,6 +6529,7 @@ Added to `window-configuration-change-hook' in Todo mode." (put 'todo-mode 'mode-class 'special) +;;;###autoload (define-derived-mode todo-mode special-mode "Todo" "Major mode for displaying, navigating and editing todo lists. @@ -6521,6 +6556,7 @@ Added to `window-configuration-change-hook' in Todo mode." ;; If todo-mode is parent, all todo-mode key bindings appear to be ;; available in todo-archive-mode (e.g. shown by C-h m). +;;;###autoload (define-derived-mode todo-archive-mode special-mode "Todo-Arch" "Major mode for archived todo categories. @@ -6569,6 +6605,7 @@ Added to `window-configuration-change-hook' in Todo mode." (put 'todo-filtered-items-mode 'mode-class 'special) +;;;###autoload (define-derived-mode todo-filtered-items-mode special-mode "Todo-Fltr" "Mode for displaying and reprioritizing top priority Todo. @@ -6576,8 +6613,11 @@ Added to `window-configuration-change-hook' in Todo mode." (todo-modes-set-1) (todo-modes-set-2)) +;;;###autoload (add-to-list 'auto-mode-alist '("\\.todo\\'" . todo-mode)) +;;;###autoload (add-to-list 'auto-mode-alist '("\\.toda\\'" . todo-archive-mode)) +;;;###autoload (add-to-list 'auto-mode-alist '("\\.tod[tyr]\\'" . todo-filtered-items-mode)) ;; -----------------------------------------------------------------------------