emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-24 r117144: todo-mode.el: Remove dependence on auto-


From: Stephen Berman
Subject: [Emacs-diffs] emacs-24 r117144: todo-mode.el: Remove dependence on auto-mode-alist.
Date: Fri, 23 May 2014 16:54:54 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117144
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/17482
author: Stephen Berman  <address@hidden>
committer: Stephen Berman <address@hidden>
branch nick: emacs-24
timestamp: Fri 2014-05-23 18:54:35 +0200
message:
  todo-mode.el: Remove dependence on auto-mode-alist.
  
  * calendar/todo-mode.el: Remove dependence on auto-mode-alist,
  to avoid errors when trying to create or visit a file foo.todo
  located outside to todo-directory, and to allow having such files
  without them being tied to Todo mode.
  (todo-show, todo-move-category, todo-merge-category, todo-find-archive)
  (todo-archive-done-item, todo-find-filtered-items-file)
  (todo-filter-items, todo-find-item, todo-diary-goto-entry)
  (todo-category-completions, todo-read-category): When visiting a
  Todo file, make sure we're in the right mode and the buffer local
  variables are set.
  (todo-make-categories-list, todo-reset-nondiary-marker)
  (todo-reset-done-string, todo-reset-comment-string): After
  processing all Todo files, kill the buffers of those files that
  weren't being visited before the processing.
  (todo-display-as-todo-file, todo-add-to-buffer-list)
  (todo-visit-files-commands): Comment out.
  (todo-modes-set-3, todo-mode): Comment out additions to find-file-hook.
  (auto-mode-alist): Remove add-to-list calls making Todo file
  extensions unrestrictedly tied to Todo modes.
  
  * doc/misc/todo-mode.texi: Update in light of changes due to bug#17482.
  Replace numerous mistaken uses of literal quotes with proper
  Texinfo markup.
  (Todo Mode Entry Points): Comment out reference to using find-file
  or Dired to visit Todo files, since this has been disabled (bug#17482).
modified:
  doc/misc/ChangeLog             changelog-20091113204419-o5vbwnq5f7feedwu-6331
  doc/misc/todo-mode.texi        todomode.texi-20130804212326-csuj921rpk9gy1gz-1
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/calendar/todo-mode.el     todos.el-20120911155047-0ytqo2nidwqquefa-1
=== modified file 'doc/misc/ChangeLog'
--- a/doc/misc/ChangeLog        2014-05-06 08:48:52 +0000
+++ b/doc/misc/ChangeLog        2014-05-23 16:54:35 +0000
@@ -1,3 +1,11 @@
+2014-05-23  Stephen Berman  <address@hidden>
+
+       * todo-mode.texi: Update in light of changes due to bug#17482.
+       Replace numerous mistaken uses of literal quotes with proper
+       Texinfo markup.
+       (Todo Mode Entry Points): Comment out reference to using find-file
+       or Dired to visit Todo files, since this has been disabled (bug#17482).
+
 2014-05-06  Michael Albinus  <address@hidden>
 
        * tramp.texi (Frequently Asked Questions): Mention HISTFILE

=== modified file 'doc/misc/todo-mode.texi'
--- a/doc/misc/todo-mode.texi   2014-05-07 17:34:53 +0000
+++ b/doc/misc/todo-mode.texi   2014-05-23 16:54:35 +0000
@@ -258,15 +258,15 @@
 @code{todo-insert-item}, since these commands are bound to @kbd{t},
 @kbd{j} and @kbd{i}, respectively, in Todo mode.
 
-You can also visit a Todo file via @code{find-file} or Dired, like any
-other file, and since Emacs recognizes it, the buffer will automatically
-be in the appropriate Todo mode.  Moreover, as long as the command you
-use to visit the file is listed in the option
address@hidden (which by default contains
address@hidden and @code{dired-find-file}), it will also correctly
-display the file's first category on first visiting the file (otherwise
-you have to use one of the commands for navigating between categories in
-order to get a proper display).
address@hidden You can also visit a Todo file via @code{find-file} or Dired, 
like any
address@hidden other file, and since Emacs recognizes it, the buffer will 
automatically
address@hidden be in the appropriate Todo mode.  Moreover, as long as the 
command you
address@hidden use to visit the file is listed in the option
address@hidden @code{todo-visit-files-commands} (which by default contains
address@hidden @code{find-file} and @code{dired-find-file}), it will also 
correctly
address@hidden display the file's first category on first visiting the file 
(otherwise
address@hidden you have to use one of the commands for navigating between 
categories in
address@hidden order to get a proper display).
 
 You can leave Todo mode by typing @kbd{q} (@code{todo-quit}), which
 buries the current todo file buffer.  Doing this also saves any changes
@@ -295,7 +295,7 @@
 number key.
 
 The predefined key bindings in Todo are more or less mnemonic.  As a
-rule, key sequences beginning with @kbd{C} (capital `C', not the
+rule, key sequences beginning with @kbd{C} (capital @samp{C}, not the
 control key) are bound to commands applying to categories, sequences
 beginning with @kbd{F} apply to (non-archive) file-level commands, and
 those beginning with @kbd{A} apply to archives (a special type of Todo
@@ -669,9 +669,9 @@
 @samp{region} (@kbd{r}): Use the text of the selected region as the
 text of the new item, and insert this in accordance with the item
 insertion options and other parameters passed.  If the option
-`todo-use-only-highlighted-region' is non-nil, then use the region
-only when it is highlighted; otherwise, use the region regardless of
-highlighting.
address@hidden is non-nil, then use the
+region only when it is highlighted; otherwise, use the region
+regardless of highlighting.
 @end enumerate
 
 Note that the parameters are divided into five numbered groups; within
@@ -715,9 +715,9 @@
 @noindent Notice that the pair @samp{k=>nonmarking} is now absent, since it
 belongs to the same group as the selected pair @samp{y=>diary}, hence
 is no longer available for this sequence.  Since @kbd{y} is a
-continuation key, it is still available, but now the string ":GO!" is
-appended to the pair to remind you that pressing this key again will
-complete the sequence.
+continuation key, it is still available, but now the string
address@hidden:GO!} is appended to the pair to remind you that pressing this
+key again will complete the sequence.
 
 
 
@@ -821,10 +821,10 @@
 
 @noindent
 Editing the text of a lengthy item in the minibuffer can be
-inconvenient; therefore, if you type `e e' or `e h' on an item whose
-text contains more than one logical line, the effect is the same as if
-you had typed `e m', that is, you switch a special buffer in Todo Edit
-mode.
+inconvenient; therefore, if you type @kbd{e e} or @kbd{e h} on an item
+whose text contains more than one logical line, the effect is the same
+as if you had typed @kbd{e m}, that is, you switch a special buffer in
+Todo Edit mode.
 
 When you pass any of the parameters of the preceding group, except for
 the @samp{date} parameter, this completes the item editing invocation
@@ -916,10 +916,10 @@
 Press a key (so far `e d'): f=>full c=>calendar a=>today n=>dayname y=>year 
m=>month d=>daynum
 @end example
 
-In addition to the item-level invocations `e y', to change the current
-item's diary inclusion status, and `e k', to change the current item's
-calendar marking status, Todo mode also has two related category-level
-commands:
+In addition to the item-level invocations @kbd{e y}, to change the
+current item's diary inclusion status, and @kbd{e k}, to change the
+current item's calendar marking status, Todo mode also has two related
+category-level commands:
 
 @table @kbd
 
@@ -932,7 +932,7 @@
 @end table
 
 @noindent
-Like `e k', `C e k' automatically removes @code{todo-nondiary-marker}
+Like @kbd{e k}, @kbd{C e k} automatically removes @code{todo-nondiary-marker}
 from all items it is present on, since only diary items can bear
 @code{diary-nonmarking-symbol}.
 
@@ -944,7 +944,7 @@
 category, and take a prefix argument to reverse the effect.  (If you
 really want to toggle the diary-inclusion and calendar-marking status
 of all items in the category, you can do this by marking all the items
-and then invoking `e y' or `e k', @pxref{Marked Items}).
+and then invoking @kbd{e y} or @kbd{e k}, @pxref{Marked Items}).
 
 @node  Relocating and Removing Items,  , Editing Item Headers and Text, Item 
Editing
 @subsection Relocating and Removing Items
@@ -1050,14 +1050,15 @@
 
 @anchor{todo-item-done}
 @item d
-This command (@code{todo-item-done}) removes the todo item at point from
-the todo list, appends to the original header a header consisting of
address@hidden (by default ``DONE '') and the current date, and
-if @code{todo-always-add-time-string} is enabled, also the current time,
-and adds the resulting done item to the top of the done items section of
-the category.  Invoked with a prefix argument, it also prompts you to
-enter a comment, which is appended to the end of the done item, prefixed
-with @code{todo-comment-string} (by default ``COMMENT: '').
+This command (@code{todo-item-done}) removes the todo item at point
+from the todo list, appends to the original header a header consisting
+of @code{todo-done-string} (by default @samp{DONE }) and the current
+date, and if @code{todo-always-add-time-string} is enabled, also the
+current time, and adds the resulting done item to the top of the done
+items section of the category.  Invoked with a prefix argument, it
+also prompts you to enter a comment, which is appended to the end of
+the done item, prefixed with @code{todo-comment-string} (by default
address@hidden: }).
 @end table
 
 A category's done items section is located below the last todo (i.e.,
@@ -1255,7 +1256,7 @@
 
 Since it is natural to visit an archive from the corresponding todo
 file, it would be convenient to easily return to the todo file when you
-have finished browsing the archive.  If you type `q' to quit Todo
+have finished browsing the archive.  If you type @kbd{q} to quit Todo
 Archive mode, this switches to the corresponding todo file and shows the
 todo category corresponding to the archive category you were just
 visiting.
@@ -1396,13 +1397,13 @@
 
 Each row of the table is also buttonized; pressing one of these exits
 the buffer (killing it), returns to the buffer of the file from which
-you had invoked `F c', and displays the category that was named in the
-row button you pressed (i.e., pressing this button jumps to that
-category).  However, if the category named in the row is in a todo file
-and all of its items have been archived, and you have enabled the option
address@hidden, then pressing the button jumps to
-the archive category instead of the empty todo category.  You can
-recognize such categories by their items counts in the table---all
+you had invoked @kbd{F c}, and displays the category that was named in
+the row button you pressed (i.e., pressing this button jumps to that
+category).  However, if the category named in the row is in a todo
+file and all of its items have been archived, and you have enabled the
+option @code{todo-skip-archived-categories}, then pressing the button
+jumps to the archive category instead of the empty todo category.  You
+can recognize such categories by their items counts in the table---all
 columns but the archived one have counts of zero---and in addition,
 their lines in the table are also distinguished from the others by a
 different face (@pxref{Faces}).
@@ -1586,7 +1587,7 @@
 current category.  To exclude a category or file from filtering by @kbd{F t t}
 and @kbd{F t m}, set the number to @samp{0}.
 @item
-You can invoke `F t t' and `F t m' with a numeric prefix argument,
+You can invoke @kbd{F t t} and @kbd{F t m} with a numeric prefix argument,
 which specifies the number of top priorities in each category just for
 this invocation, overriding both @code{todo-top-priorities-overrides} and
 @code{todo-top-priorities}.
@@ -1681,7 +1682,7 @@
 Aside from explicitly invoking an item filtering command to display a
 saved list of items filtered by a given method from given todo files,
 there are two other ways to visit a saved file of filtered items.  You
-can invoke a command similar to `find-file':
+can invoke a command similar to @code{find-file}:
 
 @table @kbd
 @item F f

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-05-23 16:17:14 +0000
+++ b/lisp/ChangeLog    2014-05-23 16:54:35 +0000
@@ -1,3 +1,25 @@
+2014-05-23  Stephen Berman  <address@hidden>
+
+       * calendar/todo-mode.el: Remove dependence on auto-mode-alist,
+       to avoid errors when trying to create or visit a file foo.todo
+       located outside to todo-directory, and to allow having such files
+       without them being tied to Todo mode (bug#17482).
+       (todo-show, todo-move-category, todo-merge-category, todo-find-archive)
+       (todo-archive-done-item, todo-find-filtered-items-file)
+       (todo-filter-items, todo-find-item, todo-diary-goto-entry)
+       (todo-category-completions, todo-read-category): When visiting a
+       Todo file, make sure we're in the right mode and the buffer local
+       variables are set.
+       (todo-make-categories-list, todo-reset-nondiary-marker)
+       (todo-reset-done-string, todo-reset-comment-string): After
+       processing all Todo files, kill the buffers of those files that
+       weren't being visited before the processing.
+       (todo-display-as-todo-file, todo-add-to-buffer-list)
+       (todo-visit-files-commands): Comment out.
+       (todo-modes-set-3, todo-mode): Comment out additions to find-file-hook.
+       (auto-mode-alist): Remove add-to-list calls making Todo file
+       extensions unrestrictedly tied to Todo modes.
+
 2014-05-23  Stefan Monnier  <address@hidden>
 
        * emacs-lisp/nadvice.el (advice--member-p): Change second arg.

=== modified file 'lisp/calendar/todo-mode.el'
--- a/lisp/calendar/todo-mode.el        2014-05-23 12:10:50 +0000
+++ b/lisp/calendar/todo-mode.el        2014-05-23 16:54:35 +0000
@@ -566,13 +566,13 @@
 ;;; Entering and exiting
 ;; 
-----------------------------------------------------------------------------
 
-(defcustom todo-visit-files-commands (list 'find-file 'dired-find-file)
-  "List of file finding commands for `todo-display-as-todo-file'.
-Invoking these commands to visit a todo file or todo archive file
-calls `todo-show' or `todo-find-archive', so that the file is
-displayed correctly."
-  :type '(repeat function)
-  :group 'todo)
+;; (defcustom todo-visit-files-commands (list 'find-file 'dired-find-file)
+;;   "List of file finding commands for `todo-display-as-todo-file'.
+;; Invoking these commands to visit a todo file or todo archive file
+;; calls `todo-show' or `todo-find-archive', so that the file is
+;; displayed correctly."
+;;   :type '(repeat function)
+;;   :group 'todo)
 
 (defun todo-short-file-name (file)
   "Return the short form of todo file FILE's name.
@@ -740,9 +740,12 @@
                                             "Choose a regexp items file: "
                                             rxf) 'regexp))))))
                     (if (file-exists-p fi-file)
-                        (set-window-buffer
-                         (selected-window)
-                         (set-buffer (find-file-noselect fi-file 'nowarn)))
+                        (progn
+                          (set-window-buffer
+                           (selected-window)
+                           (set-buffer (find-file-noselect fi-file 'nowarn)))
+                          (unless (derived-mode-p 'todo-filtered-items-mode)
+                            (todo-filtered-items-mode)))
                       (message "There is no %s file for %s"
                                (cond ((eq todo-show-first 'top)
                                       "top priorities")
@@ -757,6 +760,9 @@
          (unless (todo-check-file file) (throw 'end nil))
          (set-window-buffer (selected-window)
                             (set-buffer (find-file-noselect file 'nowarn)))
+         (if (equal (file-name-extension (buffer-file-name)) "toda")
+             (unless (derived-mode-p 'todo-archive-mode) (todo-archive-mode))
+           (unless (derived-mode-p 'todo-mode) (todo-mode)))
          ;; When quitting an archive file, show the corresponding
          ;; category in the corresponding todo file, if it exists.
          (when (assoc cat todo-categories)
@@ -1449,6 +1455,10 @@
                 (if (member buf (funcall todo-files-function t))
                     (concat (file-name-sans-extension nfile) ".toda")
                   nfile))
+             (if (equal (file-name-extension (buffer-file-name)) "toda")
+                 (unless (derived-mode-p 'todo-archive-mode)
+                   (todo-archive-mode))
+               (unless (derived-mode-p 'todo-mode) (todo-mode)))
              (let* ((nfile-short (todo-short-file-name nfile))
                     (prompt (concat
                              (format "Todo file \"%s\" already has "
@@ -1564,6 +1574,7 @@
             (done-count (todo-get-count 'done cat)))
        ;; Merge into goal todo category.
        (with-current-buffer (get-buffer (find-file-noselect gfile))
+         (unless (derived-mode-p 'todo-mode) (todo-mode))
          (widen)
          (goto-char (point-min))
          (let ((buffer-read-only nil))
@@ -2995,6 +3006,7 @@
       (when place
        (set-window-buffer (selected-window)
                           (set-buffer (find-file-noselect archive)))
+       (unless (derived-mode-p 'todo-archive-mode) (todo-archive-mode))
        (if (member place '(other-archive other-cat))
            (setq todo-category-number 1)
          (todo-category-number cat))
@@ -3070,6 +3082,7 @@
          (if (not (or marked all item))
              (throw 'end (message "Only done items can be archived"))
            (with-current-buffer archive
+             (unless (derived-mode-p 'todo-archive-mode) (todo-archive-mode))
              (let (buffer-read-only)
                (widen)
                (goto-char (point-min))
@@ -3091,12 +3104,12 @@
                (todo-update-categories-sexp)
                ;; If archive is new, save to file now (with
                ;; write-region to avoid prompt for file to save to)
-               ;; to update todo-archives, and to let auto-mode-alist
-               ;; take effect below on visiting the archive.
+               ;; to update todo-archives, and set the mode for
+               ;; visiting the archive below.
                (unless (nth 7 (file-attributes afile))
                  (write-region nil nil afile t t)
                  (setq todo-archives (funcall todo-files-function t))
-                 (kill-buffer))))
+                 (todo-archive-mode))))
            (with-current-buffer tbuf
              (cond
               (all
@@ -3957,7 +3970,9 @@
     (setq file (completing-read "Choose a filtered items file: "
                                falist nil t nil nil (car falist)))
     (setq file (cdr (assoc-string file falist)))
-    (find-file file)))
+    (find-file file)
+    (unless (derived-mode-p 'todo-filtered-items-mode)
+      (todo-filtered-items-mode))))
 
 (defun todo-go-to-source-item ()
   "Display the file and category of the filtered item at point."
@@ -4088,6 +4103,8 @@
                            (completing-read "Choose a regexp items file: "
                                             rxf) 'regexp))))
           (find-file fname)
+          (unless (derived-mode-p 'todo-filtered-items-mode)
+            (todo-filtered-items-mode))
           (todo-prefix-overlays)
           (todo-check-filtered-items-file))
          (t
@@ -4341,6 +4358,9 @@
                   todo-global-current-todo-file)))
     (find-file-noselect file)
     (with-current-buffer (find-buffer-visiting file)
+      (if archive
+         (unless (derived-mode-p 'todo-archive-mode) (todo-archive-mode))
+       (unless (derived-mode-p 'todo-mode) (todo-mode)))
       (save-restriction
        (widen)
        (goto-char (point-min))
@@ -4917,23 +4937,28 @@
                 ;; Make sure to include newly created archives, e.g. due to
                 ;; todo-move-category.
                 (when (member archive (funcall todo-files-function t))
-                  (let ((archive-count 0))
-                    (with-current-buffer (find-file-noselect archive)
-                      (widen)
-                      (goto-char (point-min))
-                      (when (re-search-forward
-                             (concat "^" (regexp-quote todo-category-beg)
-                                     cat "$")
-                             (point-max) t)
-                        (forward-line)
-                        (while (not (or (looking-at
-                                         (concat
-                                          (regexp-quote todo-category-beg)
-                                          "\\(.*\\)\n"))
-                                        (eobp)))
-                          (when (looking-at todo-done-string-start)
-                            (setq archive-count (1+ archive-count)))
-                          (forward-line))))
+                  (let ((archive-count 0)
+                        (visiting (find-buffer-visiting archive)))
+                    (with-current-buffer (or visiting
+                                             (find-file-noselect archive))
+                      (save-excursion
+                        (save-restriction
+                          (widen)
+                          (goto-char (point-min))
+                          (when (re-search-forward
+                                 (concat "^" (regexp-quote todo-category-beg)
+                                         cat "$")
+                                 (point-max) t)
+                            (forward-line)
+                            (while (not (or (looking-at
+                                             (concat
+                                              (regexp-quote todo-category-beg)
+                                              "\\(.*\\)\n"))
+                                            (eobp)))
+                              (when (looking-at todo-done-string-start)
+                                (setq archive-count (1+ archive-count)))
+                              (forward-line)))))
+                      (unless visiting (kill-buffer)))
                     (todo-update-count 'archived archive-count cat))))
                ((looking-at todo-done-string-start)
                 (todo-update-count 'done 1 cat))
@@ -5157,6 +5182,11 @@
     (if (not (and (file-exists-p file)
                  (find-file-other-window file)))
        (message "Unable to locate this diary entry")
+      ;; If it's a Todo file, make sure it's in Todo mode.
+      (when (and (equal (file-name-directory (file-truename file))
+                       (file-truename todo-directory))
+                (not (derived-mode-p 'todo-mode)))
+       (todo-mode))
       (when (eq major-mode 'todo-mode) (widen))
       (goto-char (point-min))
       (when (re-search-forward (format "%s.*\\(%s\\)" date content) nil t)
@@ -5596,6 +5626,9 @@
        (add-to-list 'files curfile))
       (dolist (f files listall)
        (with-current-buffer (find-file-noselect f 'nowarn)
+         (if archive
+             (unless (derived-mode-p 'todo-archive-mode) (todo-archive-mode))
+           (unless (derived-mode-p 'todo-mode) (todo-mode)))
          ;; Ensure category is properly displayed in case user
          ;; switches to file via a non-Todo mode command.  And if
          ;; done items in category are visible, keep them visible.
@@ -5681,6 +5714,7 @@
           (categories (cond (file0
                              (with-current-buffer
                                  (find-file-noselect file0 'nowarn)
+                               (unless (derived-mode-p 'todo-mode) (todo-mode))
                                (let ((todo-current-todo-file file0))
                                  todo-categories)))
                             ((and add (not file))
@@ -5960,23 +5994,28 @@
                  (regexp-quote diary-nonmarking-symbol) "\\)?"))
     (when (not (equal value oldvalue))
       (dolist (f files)
-       (with-current-buffer (find-file-noselect f)
-         (let (buffer-read-only)
-           (widen)
-           (goto-char (point-min))
-           (while (not (eobp))
-             (if (re-search-forward
-                  (concat "^\\(" todo-done-string-start "[^][]+] \\)?"
-                          "\\(?1:" (regexp-quote (car oldvalue))
-                          "\\)" todo-date-pattern "\\( "
-                          diary-time-regexp "\\)?\\(?2:"
-                          (regexp-quote (cadr oldvalue)) "\\)")
-                  nil t)
-                 (progn
-                   (replace-match (nth 0 value) t t nil 1)
-                   (replace-match (nth 1 value) t t nil 2))
-               (forward-line)))
-           (todo-category-select)))))))
+       (let ((buf (find-buffer-visiting f)))
+         (with-current-buffer (find-file-noselect f)
+           (let (buffer-read-only)
+             (widen)
+             (goto-char (point-min))
+             (while (not (eobp))
+               (if (re-search-forward
+                    (concat "^\\(" todo-done-string-start "[^][]+] \\)?"
+                            "\\(?1:" (regexp-quote (car oldvalue))
+                            "\\)" todo-date-pattern "\\( "
+                            diary-time-regexp "\\)?\\(?2:"
+                            (regexp-quote (cadr oldvalue)) "\\)")
+                    nil t)
+                   (progn
+                     (replace-match (nth 0 value) t t nil 1)
+                     (replace-match (nth 1 value) t t nil 2))
+                 (forward-line)))
+             (if buf
+                 (when (derived-mode-p 'todo-mode 'todo-archive-mode)
+                   (todo-category-select))
+               (save-buffer)
+               (kill-buffer)))))))))
 
 (defun todo-reset-done-separator-string (symbol value)
   "The :set function for `todo-done-separator-string'."
@@ -6004,18 +6043,23 @@
          (concat "^\\[" (regexp-quote todo-done-string)))
     (when (not (equal value oldvalue))
       (dolist (f files)
-       (with-current-buffer (find-file-noselect f)
-         (let (buffer-read-only)
-           (widen)
-           (goto-char (point-min))
-           (while (not (eobp))
-             (if (re-search-forward
-                  (concat "^" (regexp-quote todo-nondiary-start)
-                          "\\(" (regexp-quote oldvalue) "\\)")
-                  nil t)
-                 (replace-match value t t nil 1)
-               (forward-line)))
-           (todo-category-select)))))))
+       (let ((buf (find-buffer-visiting f)))
+         (with-current-buffer (find-file-noselect f)
+           (let (buffer-read-only)
+             (widen)
+             (goto-char (point-min))
+             (while (not (eobp))
+               (if (re-search-forward
+                    (concat "^" (regexp-quote todo-nondiary-start)
+                            "\\(" (regexp-quote oldvalue) "\\)")
+                    nil t)
+                   (replace-match value t t nil 1)
+                 (forward-line)))
+             (if buf
+                 (when (derived-mode-p 'todo-mode 'todo-archive-mode)
+                   (todo-category-select))
+               (save-buffer)
+               (kill-buffer)))))))))
 
 (defun todo-reset-comment-string (symbol value)
   "The :set function for user option `todo-comment-string'."
@@ -6025,19 +6069,23 @@
     (custom-set-default symbol value)
     (when (not (equal value oldvalue))
       (dolist (f files)
-       (with-current-buffer (find-file-noselect f)
-         (let (buffer-read-only)
-           (save-excursion
+       (let ((buf (find-buffer-visiting f)))
+         (with-current-buffer (find-file-noselect f)
+           (let (buffer-read-only)
              (widen)
              (goto-char (point-min))
              (while (not (eobp))
                (if (re-search-forward
-                    (concat
-                            "\\[\\(" (regexp-quote oldvalue) "\\): [^]]*\\]")
+                    (concat "\\[\\(" (regexp-quote oldvalue)
+                            "\\): [^]]*\\]")
                     nil t)
                    (replace-match value t t nil 1)
                  (forward-line)))
-             (todo-category-select))))))))
+             (if buf
+                 (when (derived-mode-p 'todo-mode 'todo-archive-mode)
+                   (todo-category-select))
+               (save-buffer)
+               (kill-buffer)))))))))
 
 (defun todo-reset-highlight-item (symbol value)
   "The :set function for user option `todo-highlight-item'."
@@ -6435,20 +6483,20 @@
 `todo-show-current-file' is set to non-nil."
   (setq todo-global-current-todo-file todo-current-todo-file))
 
-(defun todo-display-as-todo-file ()
-  "Show todo files correctly when visited from outside of Todo mode.
-Added to `find-file-hook' in Todo mode and Todo Archive mode."
-  (and (member this-command todo-visit-files-commands)
-       (= (- (point-max) (point-min)) (buffer-size))
-       (member major-mode '(todo-mode todo-archive-mode))
-       (todo-category-select)))
+;; (defun todo-display-as-todo-file ()
+;;   "Show todo files correctly when visited from outside of Todo mode.
+;; Added to `find-file-hook' in Todo mode and Todo Archive mode."
+;;   (and (member this-command todo-visit-files-commands)
+;;        (= (- (point-max) (point-min)) (buffer-size))
+;;        (member major-mode '(todo-mode todo-archive-mode))
+;;        (todo-category-select)))
 
-(defun todo-add-to-buffer-list ()
-  "Add name of just visited todo file to `todo-file-buffers'.
-This function is added to `find-file-hook' in Todo mode."
-  (let ((filename (file-truename (buffer-file-name))))
-    (when (member filename todo-files)
-      (add-to-list 'todo-file-buffers filename))))
+;; (defun todo-add-to-buffer-list ()
+;;   "Add name of just visited todo file to `todo-file-buffers'.
+;; This function is added to `find-file-hook' in Todo mode."
+;;   (let ((filename (file-truename (buffer-file-name))))
+;;     (when (member filename todo-files)
+;;       (add-to-list 'todo-file-buffers filename))))
 
 (defun todo-update-buffer-list ()
   "Make current Todo mode buffer file car of `todo-file-buffers'.
@@ -6503,7 +6551,8 @@
   "Make some settings that apply to multiple Todo modes."
   (setq-local todo-categories (todo-set-categories))
   (setq-local todo-category-number 1)
-  (add-hook 'find-file-hook 'todo-display-as-todo-file nil t))
+  ;; (add-hook 'find-file-hook 'todo-display-as-todo-file nil t)
+  )
 
 (put 'todo-mode 'mode-class 'special)
 
@@ -6522,7 +6571,7 @@
     (setq-local todo-current-todo-file (file-truename (buffer-file-name))))
   (setq-local todo-show-done-only nil)
   (setq-local todo-categories-with-marks nil)
-  (add-hook 'find-file-hook 'todo-add-to-buffer-list nil t)
+  ;; (add-hook 'find-file-hook 'todo-add-to-buffer-list nil t)
   (add-hook 'post-command-hook 'todo-update-buffer-list nil t)
   (when todo-show-current-file
     (add-hook 'pre-command-hook 'todo-show-current-file nil t))
@@ -6591,13 +6640,6 @@
   (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))
-
 ;; 
-----------------------------------------------------------------------------
 (provide 'todo-mode)
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]