From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daiki Ueno Newsgroups: gmane.emacs.bugs Subject: bug#6568: 23.2; easypg opens blank buffer when password is incorrect Date: Tue, 06 Jul 2010 17:47:02 +0900 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1278406854 19610 80.91.229.12 (6 Jul 2010 09:00:54 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 6 Jul 2010 09:00:54 +0000 (UTC) Cc: 6568@debbugs.gnu.org To: Leo Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jul 06 11:00:51 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OW41K-0002fY-Vk for geb-bug-gnu-emacs@m.gmane.org; Tue, 06 Jul 2010 11:00:51 +0200 Original-Received: from localhost ([127.0.0.1]:51081 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OW41J-0005R5-WB for geb-bug-gnu-emacs@m.gmane.org; Tue, 06 Jul 2010 05:00:50 -0400 Original-Received: from [140.186.70.92] (port=53395 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OW40Q-0005AQ-AL for bug-gnu-emacs@gnu.org; Tue, 06 Jul 2010 05:00:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OW40L-0004y1-BQ for bug-gnu-emacs@gnu.org; Tue, 06 Jul 2010 04:59:50 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:46695) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OW40L-0004xr-89 for bug-gnu-emacs@gnu.org; Tue, 06 Jul 2010 04:59:49 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1OW3m3-0004Si-7R; Tue, 06 Jul 2010 04:45:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Daiki Ueno Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 06 Jul 2010 08:45:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6568 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 6568-submit@debbugs.gnu.org id=B6568.127840586417129 (code B ref 6568); Tue, 06 Jul 2010 08:45:03 +0000 Original-Received: (at 6568) by debbugs.gnu.org; 6 Jul 2010 08:44:24 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OW3lQ-0004SE-Gc for submit@debbugs.gnu.org; Tue, 06 Jul 2010 04:44:24 -0400 Original-Received: from ivory4.scn-net.ne.jp ([219.117.176.192]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1OW3lN-0004S9-Lv for 6568@debbugs.gnu.org; Tue, 06 Jul 2010 04:44:23 -0400 Original-Received: from ([192.168.0.187]) (envelope sender: ) by ivory4.scn-net.ne.jp with Active!Hunter esmtp server; Tue, 6 Jul 2010 17:44:15 +0900 Original-Received: Received: from well-done.deisui.org (g187018.scn-net.ne.jp [202.83.187.18]) (authenticated) by blue17.scn-net.ne.jp (unknown) with ESMTP id o668iEa8031969; Tue, 6 Jul 2010 17:44:15 +0900 In-Reply-To: (Leo's message of "Mon, 05 Jul 2010 17:00:17 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Tue, 06 Jul 2010 04:45:03 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:38254 Archived-At: --=-=-= Leo writes: > Assume you have an encrypted file test.gpg and try to open it in emacs. > At the password prompt, type in an incorrect one. A blank buffer is > still opened. > > The tricky thing is if you save back the contents in that buffer > (because accidentally you think you have typed in a correct password), > the original content will be gone. > > It seems better for easypg not to open a blank buffer when password is > incorrect. Basically agree. I have worndered for a long time how to implement this, because error handling in find-file is too complex to control. One idea is to re-throw the error in find-file-not-found-functions (patch attached). I'm not sure if this approach is palatable as other basic Emacs commands. Anyway, testing would be much appreciated. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=epa-file-no-select-empty.diff === modified file 'lisp/epa-file.el' --- lisp/epa-file.el 2010-01-13 08:35:10 +0000 +++ lisp/epa-file.el 2010-07-06 08:36:24 +0000 @@ -101,6 +101,14 @@ (insert (epa-file--decode-coding-string string (or coding-system-for-read 'undecided))))) +(defvar epa-file-error nil) +(defun epa-file--find-file-not-found-function () + (save-window-excursion + (let ((error (copy-sequence epa-file-error))) + (ignore (kill-buffer)) + (signal 'file-error + (cons "Opening input file" (cdr error)))))) + (defvar last-coding-system-used) (defun epa-file-insert-file-contents (file &optional visit beg end replace) (barf-if-buffer-read-only) @@ -126,11 +134,16 @@ (progn (if replace (goto-char (point-min))) + (add-hook 'find-file-not-found-functions + 'epa-file--find-file-not-found-function + nil t) (condition-case error (setq string (epg-decrypt-file context local-file nil)) (error (if (setq entry (assoc file epa-file-passphrase-alist)) (setcdr entry nil)) + (make-local-variable 'epa-file-error) + (setq epa-file-error error) (signal 'file-error (cons "Opening input file" (cdr error))))) (make-local-variable 'epa-file-encrypt-to) --=-=-= Regards, -- Daiki Ueno --=-=-=--