From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.bugs Subject: bug#14688: 24.3; todo-show errors: wrong-type-argument and file-error Date: Mon, 24 Jun 2013 00:18:52 +0200 Message-ID: <877ghk79o3.fsf@rosalinde.fritz.box> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1372026016 27465 80.91.229.3 (23 Jun 2013 22:20:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 23 Jun 2013 22:20:16 +0000 (UTC) Cc: 14688@debbugs.gnu.org To: Leo Liu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jun 24 00:20:15 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Uqsdp-0001qP-JO for geb-bug-gnu-emacs@m.gmane.org; Mon, 24 Jun 2013 00:20:13 +0200 Original-Received: from localhost ([::1]:33585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uqsdp-0000y8-38 for geb-bug-gnu-emacs@m.gmane.org; Sun, 23 Jun 2013 18:20:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uqsdi-0000v8-Ud for bug-gnu-emacs@gnu.org; Sun, 23 Jun 2013 18:20:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uqsdf-0000YC-0Q for bug-gnu-emacs@gnu.org; Sun, 23 Jun 2013 18:20:06 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:42838) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uqsde-0000XP-Sw for bug-gnu-emacs@gnu.org; Sun, 23 Jun 2013 18:20:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Uqsdd-0000W2-VT for bug-gnu-emacs@gnu.org; Sun, 23 Jun 2013 18:20:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Stephen Berman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 23 Jun 2013 22:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 14688 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 14688-submit@debbugs.gnu.org id=B14688.13720259481909 (code B ref 14688); Sun, 23 Jun 2013 22:20:01 +0000 Original-Received: (at 14688) by debbugs.gnu.org; 23 Jun 2013 22:19:08 +0000 Original-Received: from localhost ([127.0.0.1]:37154 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Uqsck-0000Ug-HS for submit@debbugs.gnu.org; Sun, 23 Jun 2013 18:19:07 -0400 Original-Received: from mout.gmx.net ([212.227.17.21]:50449) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Uqsch-0000U7-4a for 14688@debbugs.gnu.org; Sun, 23 Jun 2013 18:19:04 -0400 Original-Received: from mailout-de.gmx.net ([10.1.76.12]) by mrigmx.server.lan (mrigmx001) with ESMTP (Nemesis) id 0MfCFw-1UfFt42TKU-00Oryv for <14688@debbugs.gnu.org>; Mon, 24 Jun 2013 00:18:56 +0200 Original-Received: (qmail invoked by alias); 23 Jun 2013 22:18:54 -0000 Original-Received: from i59F5569F.versanet.de (EHLO rosalinde.fritz.box) [89.245.86.159] by mail.gmx.net (mp012) with SMTP; 24 Jun 2013 00:18:54 +0200 X-Authenticated: #20778731 X-Provags-ID: V01U2FsdGVkX1+I9A8bBauIvLhwFBGtKh5hiTVU6DZ92rbhiGNUZE rNoq6eVQtDwkmj User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-Y-GMX-Trusted: 0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:75487 Archived-At: 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 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'.