Package: emacs;
Reported by: Leo Liu <sdl.web <at> gmail.com>
Date: Sat, 22 Jun 2013 04:06:01 UTC
Severity: normal
Found in version 24.3
Done: Stephen Berman <stephen.berman <at> gmx.net>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 14688 in the body.
You can then email your comments to 14688 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
View this report as an mbox folder, status mbox, maintainer mbox
stephen.berman <at> gmx.net, bug-gnu-emacs <at> gnu.org
:bug#14688
; Package emacs
.
(Sat, 22 Jun 2013 04:06:01 GMT) Full text and rfc822 format available.Leo Liu <sdl.web <at> gmail.com>
:stephen.berman <at> gmx.net, bug-gnu-emacs <at> gnu.org
.
(Sat, 22 Jun 2013 04:06:02 GMT) Full text and rfc822 format available.Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
From: Leo Liu <sdl.web <at> gmail.com> To: bug-gnu-emacs <at> gnu.org Subject: 24.3; todo-show errors: wrong-type-argument and file-error Date: Sat, 22 Jun 2013 12:05:13 +0800
Make sure nothing is in ~/.emacs.d/todo 1. start emacs 2. todo-show and answer its queries and save the buffer 3. go to ~/.emacs.d/todo and delete files there 4. M-x todo-show you will get a couple of errors such as: Debugger entered--Lisp error: (wrong-type-argument stringp nil) expand-file-name(nil) find-file-noselect(nil) todo-read-category("Enter a new category name: " add nil) todo-add-category(nil "") byte-code todo-show(nil) call-interactively(todo-show record nil) command-execute(todo-show record) execute-extended-command(nil "todo-show") call-interactively(execute-extended-command nil nil) command-execute(execute-extended-command) Debugger entered--Lisp error: (file-error "Removing old name" "no such file or directory" "/home/leo/.emacs.d/todo/TODO.todo") delete-file("/home/leo/.emacs.d/todo/TODO.todo") byte-code byte-code todo-show(nil) call-interactively(todo-show record nil) command-execute(todo-show record) execute-extended-command(nil "todo-show") call-interactively(execute-extended-command nil nil) command-execute(execute-extended-command)
bug-gnu-emacs <at> gnu.org
:bug#14688
; Package emacs
.
(Sun, 23 Jun 2013 22:20:01 GMT) Full text and rfc822 format available.Message #8 received at 14688 <at> debbugs.gnu.org (full text, mbox):
From: Stephen Berman <stephen.berman <at> gmx.net> To: Leo Liu <sdl.web <at> gmail.com> Cc: 14688 <at> debbugs.gnu.org Subject: Re: bug#14688: 24.3; todo-show errors: wrong-type-argument and file-error Date: Mon, 24 Jun 2013 00:18:52 +0200
On Fri 2013-06-21 23:58:09 +0200 I installed the new version of todo-mode.el. On Sat, 22 Jun 2013 12:05:13 +0800 Leo Liu <sdl.web <at> gmail.com> wrote: > Make sure nothing is in ~/.emacs.d/todo > > 1. start emacs > 2. todo-show and answer its queries and save the buffer > 3. go to ~/.emacs.d/todo and delete files there > 4. M-x todo-show > > you will get a couple of errors such as: > > Debugger entered--Lisp error: (wrong-type-argument stringp nil) > expand-file-name(nil) > find-file-noselect(nil) > todo-read-category("Enter a new category name: " add nil) > todo-add-category(nil "") > byte-code > todo-show(nil) > call-interactively(todo-show record nil) > command-execute(todo-show record) > execute-extended-command(nil "todo-show") > call-interactively(execute-extended-command nil nil) > command-execute(execute-extended-command) > > Debugger entered--Lisp error: (file-error "Removing old name" "no such file or > directory" "/home/leo/.emacs.d/todo/TODO.todo") > delete-file("/home/leo/.emacs.d/todo/TODO.todo") > byte-code > byte-code > todo-show(nil) > call-interactively(todo-show record nil) > command-execute(todo-show record) > execute-extended-command(nil "todo-show") > call-interactively(execute-extended-command nil nil) > command-execute(execute-extended-command) Well, it took all of six hours for the prediction I made[1] to come true. It's taken me quite a bit longer to come up with a fix, and I'm not at all confident of its robustness. Still, if you confirm that it avoids the above errors, I'll probably commit it until I (or someone else) come up with something better, or until you (or someone else) find the next problem with it ;-). The patch fixes some other problems beside those you reported, but which arise similarly. I found them when I tried to reproduce your recipe. When I do exactly the above four steps in your recipe, I actually don't get the errors you reported and the category is displayed normally. However, if between steps 3 and 4 of your recipe I kill the buffer visiting the todo file, then I do get the errors. But if I don't kill the buffer and also don't save it before trying to use other Todo mode commands, other problems arise. The patch tries to avoid these problems as well as the ones you reported. Steve Berman Footnotes: [1] in this list on 11 June 2013: > since I'm the only one who's used the new version so far, there are > certain to be use cases and configurations I didn't test well enough > or even think of at all === modified file 'lisp/calendar/todo-mode.el' *** lisp/calendar/todo-mode.el 2013-06-21 14:07:46 +0000 --- lisp/calendar/todo-mode.el 2013-06-23 22:09:25 +0000 *************** *** 578,588 **** (file-name-sans-extension (file-name-nondirectory file)))) (defcustom todo-default-todo-file (todo-short-file-name ! (car (funcall todo-files-function))) "Todo file visited by first session invocation of `todo-show'." ! :type `(radio ,@(mapcar (lambda (f) (list 'const f)) ! (mapcar 'todo-short-file-name ! (funcall todo-files-function)))) :group 'todo) (defcustom todo-show-current-file t --- 578,589 ---- (file-name-sans-extension (file-name-nondirectory file)))) (defcustom todo-default-todo-file (todo-short-file-name ! (car (funcall todo-files-function))) "Todo file visited by first session invocation of `todo-show'." ! :type (when todo-files ! `(radio ,@(mapcar (lambda (f) (list 'const f)) ! (mapcar 'todo-short-file-name ! (funcall todo-files-function))))) :group 'todo) (defcustom todo-show-current-file t *************** *** 669,674 **** --- 670,696 ---- Invoking this command in Todo Archive mode visits the corresponding todo file, displaying the corresponding category." (interactive "P") + ;; If the user deletes the default todo file while its content is in + ;; a buffer and then tries to show it, ask whether to restore the + ;; file, else delete the buffer and cleanup to avoid errors and + ;; reinitialize a new default file. + (let* ((tdtf (todo-absolute-file-name todo-default-todo-file)) + (buf (and tdtf (find-buffer-visiting tdtf))) + ans) + (when (and tdtf (not (file-exists-p tdtf))) + (if (and buf (y-or-n-p + (concat + (format (concat "Todo file \"%s\" has been deleted " + "but its content is still in a buffer!\n") + todo-default-todo-file) + "Save that buffer and restore the todo file? "))) + (with-current-buffer buf (save-buffer)) + (setq todo-default-todo-file nil + todo-files (todo-files)) + (setq todo-default-todo-file (todo-short-file-name (car todo-files))) + (todo-reevaluate-default-file-defcustom) + (setq todo-global-current-todo-file nil) ; For todo-read-file-name. + (kill-buffer buf)))) (catch 'shown ;; If there is a legacy todo file but no todo file in the current ;; format, offer to convert the legacy file and show it. *************** *** 681,784 **** "old todo file to the new format? "))) (when (todo-convert-legacy-files) (throw 'shown nil))))) ! (let* ((cat) ! (show-first todo-show-first) ! (file (cond ((or solicit-file ! (and (called-interactively-p 'any) ! (memq major-mode '(todo-mode ! todo-archive-mode ! todo-filtered-items-mode)))) ! (if (funcall todo-files-function) ! (todo-read-file-name "Choose a todo file to visit: " ! nil t) ! (user-error "There are no todo files"))) ! ((and (eq major-mode 'todo-archive-mode) ! ;; Called noninteractively via todo-quit ! ;; to jump to corresponding category in ! ;; todo file. ! (not (called-interactively-p 'any))) ! (setq cat (todo-current-category)) ! (concat (file-name-sans-extension ! todo-current-todo-file) ".todo")) ! (t ! (or todo-current-todo-file ! (and todo-show-current-file ! todo-global-current-todo-file) ! (todo-absolute-file-name todo-default-todo-file) ! (todo-add-file))))) ! add-item first-file) ! (unless todo-default-todo-file ! ;; We just initialized the first todo file, so make it the default. ! (setq todo-default-todo-file (todo-short-file-name file) ! first-file t) ! (todo-reevaluate-default-file-defcustom)) ! (unless (member file todo-visited) ! ;; Can't setq t-c-t-f here, otherwise wrong file shown when ! ;; todo-show is called from todo-show-categories-table. ! (let ((todo-current-todo-file file)) ! (cond ((eq todo-show-first 'table) ! (todo-show-categories-table)) ! ((memq todo-show-first '(top diary regexp)) ! (let* ((shortf (todo-short-file-name file)) ! (fi-file (todo-absolute-file-name ! shortf todo-show-first))) ! (when (eq todo-show-first 'regexp) ! (let ((rxfiles (directory-files todo-directory t ! ".*\\.todr$" t))) ! (when (and rxfiles (> (length rxfiles) 1)) ! (let ((rxf (mapcar 'todo-short-file-name rxfiles))) ! (setq fi-file (todo-absolute-file-name ! (completing-read ! "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))) ! (message "There is no %s file for %s" ! (cond ((eq todo-show-first 'top) ! "top priorities") ! ((eq todo-show-first 'diary) ! "diary items") ! ((eq todo-show-first 'regexp) ! "regexp items")) ! shortf) ! (setq todo-show-first 'first))))))) ! (when (or (member file todo-visited) ! (eq todo-show-first 'first)) ! (set-window-buffer (selected-window) ! (set-buffer (find-file-noselect file 'nowarn))) ! ;; When quitting an archive file, show the corresponding ! ;; category in the corresponding todo file, if it exists. ! (when (assoc cat todo-categories) ! (setq todo-category-number (todo-category-number cat))) ! ;; If this is a new todo file, add its first category. ! (when (zerop (buffer-size)) ! (let (cat-added) ! (unwind-protect ! (setq todo-category-number ! (todo-add-category todo-current-todo-file "") ! add-item todo-add-item-if-new-category ! cat-added t) ! (if cat-added ! ;; If the category was added, save the file now, so we ! ;; don't risk having an empty todo file, which would ! ;; signal an error if we tried to visit it later, ! ;; since doing that looks for category boundaries. ! (save-buffer 0) ! ;; If user cancels before adding the category, clean up ! ;; and exit, so we have a fresh slate the next time. ! (delete-file file) ! (setq todo-files (delete file todo-files)) ! (when first-file ! (setq todo-default-todo-file nil ! todo-current-todo-file nil)) ! (kill-buffer) ! (keyboard-quit))))) ! (save-excursion (todo-category-select)) ! (when add-item (todo-basic-insert-item))) ! (setq todo-show-first show-first) ! (add-to-list 'todo-visited file)))) (defun todo-save () "Save the current todo file." --- 703,827 ---- "old todo file to the new format? "))) (when (todo-convert-legacy-files) (throw 'shown nil))))) ! (catch 'end ! (let* ((cat) ! (show-first todo-show-first) ! (file (cond ((or solicit-file ! (and (called-interactively-p 'any) ! (memq major-mode '(todo-mode ! todo-archive-mode ! todo-filtered-items-mode)))) ! (if (funcall todo-files-function) ! (todo-read-file-name "Choose a todo file to visit: " ! nil t) ! (user-error "There are no todo files"))) ! ((and (eq major-mode 'todo-archive-mode) ! ;; Called noninteractively via todo-quit ! ;; to jump to corresponding category in ! ;; todo file. ! (not (called-interactively-p 'any))) ! (setq cat (todo-current-category)) ! (concat (file-name-sans-extension ! todo-current-todo-file) ".todo")) ! (t ! (or todo-current-todo-file ! (and todo-show-current-file ! todo-global-current-todo-file) ! (todo-absolute-file-name todo-default-todo-file) ! (todo-add-file))))) ! add-item first-file) ! (unless todo-default-todo-file ! ;; We just initialized the first todo file, so make it the default. ! (setq todo-default-todo-file (todo-short-file-name file) ! first-file t) ! (todo-reevaluate-default-file-defcustom)) ! (unless (member file todo-visited) ! ;; Can't setq t-c-t-f here, otherwise wrong file shown when ! ;; todo-show is called from todo-show-categories-table. ! (let ((todo-current-todo-file file)) ! (cond ((eq todo-show-first 'table) ! (todo-show-categories-table)) ! ((memq todo-show-first '(top diary regexp)) ! (let* ((shortf (todo-short-file-name file)) ! (fi-file (todo-absolute-file-name ! shortf todo-show-first))) ! (when (eq todo-show-first 'regexp) ! (let ((rxfiles (directory-files todo-directory t ! ".*\\.todr$" t))) ! (when (and rxfiles (> (length rxfiles) 1)) ! (let ((rxf (mapcar 'todo-short-file-name rxfiles))) ! (setq fi-file (todo-absolute-file-name ! (completing-read ! "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))) ! (message "There is no %s file for %s" ! (cond ((eq todo-show-first 'top) ! "top priorities") ! ((eq todo-show-first 'diary) ! "diary items") ! ((eq todo-show-first 'regexp) ! "regexp items")) ! shortf) ! (setq todo-show-first 'first))))))) ! (when (or (member file todo-visited) ! (eq todo-show-first 'first)) ! ;; If the user deletes a file while its content is in a ! ;; buffer and then tries to show it, ask whether to restore ! ;; the file, else delete the buffer and cleanup to avoid ! ;; errors. ! (when (not (file-exists-p file)) ! (let ((buf (find-buffer-visiting file))) ! (if (and buf ! (y-or-n-p ! (concat ! (format (concat "Todo file \"%s\" has been deleted but " ! "its content is still in a buffer!\n") ! (todo-short-file-name file)) ! "Save that buffer and restore the todo file? "))) ! (with-current-buffer buf (save-buffer)) ! (setq todo-current-todo-file nil ! todo-global-current-todo-file nil ! todo-files (todo-files)) ! (kill-buffer buf) ! (throw 'end nil)))) ! (set-window-buffer (selected-window) ! (set-buffer (find-file-noselect file 'nowarn))) ! ;; When quitting an archive file, show the corresponding ! ;; category in the corresponding todo file, if it exists. ! (when (assoc cat todo-categories) ! (setq todo-category-number (todo-category-number cat))) ! ;; If this is a new todo file, add its first category. ! (when (zerop (buffer-size)) ! (let (cat-added) ! (unwind-protect ! (setq todo-category-number ! (todo-add-category todo-current-todo-file "") ! add-item todo-add-item-if-new-category ! cat-added t) ! (if cat-added ! ;; If the category was added, save the file now, so we ! ;; don't risk having an empty todo file, which would ! ;; signal an error if we tried to visit it later, ! ;; since doing that looks for category boundaries. ! (save-buffer 0) ! ;; If user cancels before adding the category, clean up ! ;; and exit, so we have a fresh slate the next time. ! (delete-file file) ! (setq todo-files (delete file todo-files)) ! (when first-file ! (setq todo-default-todo-file nil ! todo-current-todo-file nil) ! (todo-reevaluate-default-file-defcustom)) ! (kill-buffer) ! (keyboard-quit))))) ! (save-excursion (todo-category-select)) ! (when add-item (todo-basic-insert-item))) ! (setq todo-show-first show-first) ! (add-to-list 'todo-visited file))))) (defun todo-save () "Save the current todo file." *************** *** 4678,4684 **** (unless todo-default-todo-file ;; We just initialized the first todo file, so make it the ;; default now to avoid an infinite recursion with todo-show. ! (setq todo-default-todo-file (todo-short-file-name file))) (todo-show)))))) ;; ----------------------------------------------------------------------------- --- 4721,4728 ---- (unless todo-default-todo-file ;; We just initialized the first todo file, so make it the ;; default now to avoid an infinite recursion with todo-show. ! (setq todo-default-todo-file (todo-short-file-name file)) ! (todo-reevaluate-default-file-defcustom)) (todo-show)))))) ;; ----------------------------------------------------------------------------- *************** *** 5868,5879 **** (defun todo-reevaluate-default-file-defcustom () "Reevaluate defcustom of `todo-default-todo-file'. Called after adding or deleting a todo file." ! (eval (defcustom todo-default-todo-file (car (funcall todo-files-function)) ! "Todo file visited by first session invocation of `todo-show'." ! :type `(radio ,@(mapcar (lambda (f) (list 'const f)) ! (mapcar 'todo-short-file-name ! (funcall todo-files-function)))) ! :group 'todo))) (defun todo-reevaluate-category-completions-files-defcustom () "Reevaluate defcustom of `todo-category-completions-files'. --- 5912,5926 ---- (defun todo-reevaluate-default-file-defcustom () "Reevaluate defcustom of `todo-default-todo-file'. Called after adding or deleting a todo file." ! (eval ! (defcustom todo-default-todo-file (todo-short-file-name ! (car (funcall todo-files-function))) ! "Todo file visited by first session invocation of `todo-show'." ! :type (when todo-files ! `(radio ,@(mapcar (lambda (f) (list 'const f)) ! (mapcar 'todo-short-file-name ! (funcall todo-files-function))))) ! :group 'todo))) (defun todo-reevaluate-category-completions-files-defcustom () "Reevaluate defcustom of `todo-category-completions-files'.
bug-gnu-emacs <at> gnu.org
:bug#14688
; Package emacs
.
(Mon, 24 Jun 2013 01:26:02 GMT) Full text and rfc822 format available.Message #11 received at 14688 <at> debbugs.gnu.org (full text, mbox):
From: Leo Liu <sdl.web <at> gmail.com> To: Stephen Berman <stephen.berman <at> gmx.net> Cc: 14688 <at> debbugs.gnu.org Subject: Re: bug#14688: 24.3; todo-show errors: wrong-type-argument and file-error Date: Mon, 24 Jun 2013 09:25:39 +0800
On 2013-06-24 06:18 +0800, Stephen Berman wrote: > The patch fixes some other problems beside those you reported, but which > arise similarly. I found them when I tried to reproduce your recipe. > When I do exactly the above four steps in your recipe, I actually don't > get the errors you reported and the category is displayed normally. > However, if between steps 3 and 4 of your recipe I kill the buffer > visiting the todo file, then I do get the errors. But if I don't kill > the buffer and also don't save it before trying to use other Todo mode > commands, other problems arise. The patch tries to avoid these problems > as well as the ones you reported. The patch seems to work well. Thanks. Leo
bug-gnu-emacs <at> gnu.org
:bug#14688
; Package emacs
.
(Mon, 24 Jun 2013 19:12:01 GMT) Full text and rfc822 format available.Message #14 received at 14688 <at> debbugs.gnu.org (full text, mbox):
From: Stephen Berman <stephen.berman <at> gmx.net> To: Leo Liu <sdl.web <at> gmail.com> Cc: 14688 <at> debbugs.gnu.org Subject: Re: bug#14688: 24.3; todo-show errors: wrong-type-argument and file-error Date: Mon, 24 Jun 2013 21:11:10 +0200
On Mon, 24 Jun 2013 09:25:39 +0800 Leo Liu <sdl.web <at> gmail.com> wrote: > On 2013-06-24 06:18 +0800, Stephen Berman wrote: >> The patch fixes some other problems beside those you reported, but which >> arise similarly. I found them when I tried to reproduce your recipe. >> When I do exactly the above four steps in your recipe, I actually don't >> get the errors you reported and the category is displayed normally. >> However, if between steps 3 and 4 of your recipe I kill the buffer >> visiting the todo file, then I do get the errors. But if I don't kill >> the buffer and also don't save it before trying to use other Todo mode >> commands, other problems arise. The patch tries to avoid these problems >> as well as the ones you reported. > > The patch seems to work well. Thanks. Thanks for checking. However, I'm convinced that the problem is more pervasive, and rather than tacking similar patches to each place in the code it can arise, I'd like to see if I can modularize the fix at least to some extent. This may take a bit of time. In the mean time, I would suggest that, if you want to use the package more (BTW, thank you very much for trying it out), you should avoid deleting todo files while the library is loaded (there's no problem deleting them before loading the library). I don't think that should cause any great inconvenience or problem (or if it does, then that would indicate another bug, which it would be good to find out about); at least I never had the need to do that in all the time I was developing the package (which is why I didn't think to try and prevent the problem). If I can't come up with a better solution in a reasonably short time, I'll fall back to a piecemeal approach, starting with the patch I posted. Thanks again for testing! Steve Berman
Stephen Berman <stephen.berman <at> gmx.net>
:Leo Liu <sdl.web <at> gmail.com>
:Message #19 received at 14688-done <at> debbugs.gnu.org (full text, mbox):
From: Stephen Berman <stephen.berman <at> gmx.net> To: Leo Liu <sdl.web <at> gmail.com> Cc: 14688-done <at> debbugs.gnu.org Subject: Re: bug#14688: 24.3; todo-show errors: wrong-type-argument and file-error Date: Fri, 05 Jul 2013 16:07:44 +0200
On Mon, 24 Jun 2013 21:11:10 +0200 Stephen Berman <stephen.berman <at> gmx.net> wrote: > On Mon, 24 Jun 2013 09:25:39 +0800 Leo Liu <sdl.web <at> gmail.com> wrote: > >> On 2013-06-24 06:18 +0800, Stephen Berman wrote: >>> The patch fixes some other problems beside those you reported, but which >>> arise similarly. I found them when I tried to reproduce your recipe. >>> When I do exactly the above four steps in your recipe, I actually don't >>> get the errors you reported and the category is displayed normally. >>> However, if between steps 3 and 4 of your recipe I kill the buffer >>> visiting the todo file, then I do get the errors. But if I don't kill >>> the buffer and also don't save it before trying to use other Todo mode >>> commands, other problems arise. The patch tries to avoid these problems >>> as well as the ones you reported. >> >> The patch seems to work well. Thanks. > > Thanks for checking. However, I'm convinced that the problem is more > pervasive, and rather than tacking similar patches to each place in the > code it can arise, I'd like to see if I can modularize the fix at least > to some extent. This may take a bit of time. I've now committed a revised patch as part of revision 113288 and am closing this bug. This is more modular than my previous patch, and it also handles the interaction with external file deletion in some other cases, but I haven't had time to check all cases. Still, I've committed it now since it's better than the status quo. (The revision also includes a new file deletion command and also fixes several related bugs and does some code, doc string and comment clean up.) Steve Berman
Debbugs Internal Request <help-debbugs <at> gnu.org>
to internal_control <at> debbugs.gnu.org
.
(Sat, 03 Aug 2013 11:24:04 GMT) Full text and rfc822 format available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.