all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Daiki Ueno <ueno@unixuser.org>
To: Leo <sdl.web@gmail.com>
Cc: 6568@debbugs.gnu.org
Subject: bug#6568: 23.2; easypg opens blank buffer when password is incorrect
Date: Tue, 06 Jul 2010 17:47:02 +0900	[thread overview]
Message-ID: <m38w5pf14p.fsf-ueno@unixuser.org> (raw)
In-Reply-To: <m11vbhncku.fsf@cam.ac.uk> (Leo's message of "Mon, 05 Jul 2010 17:00:17 +0100")

[-- Attachment #1: Type: text/plain, Size: 804 bytes --]

Leo <sdl.web@gmail.com> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: epa-file-no-select-empty.diff --]
[-- Type: text/x-patch, Size: 1253 bytes --]

=== 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)


[-- Attachment #3: Type: text/plain, Size: 25 bytes --]


Regards,
-- 
Daiki Ueno

  reply	other threads:[~2010-07-06  8:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-05 16:00 bug#6568: 23.2; easypg opens blank buffer when password is incorrect Leo
2010-07-06  8:47 ` Daiki Ueno [this message]
2010-07-06  9:21   ` Leo
2010-07-07  9:20     ` Daiki Ueno
2010-07-07  9:53       ` Leo
     [not found]   ` <87sk3vi6pv.fsf@stupidchicken.com>
2010-07-08  1:20     ` Daiki Ueno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m38w5pf14p.fsf-ueno@unixuser.org \
    --to=ueno@unixuser.org \
    --cc=6568@debbugs.gnu.org \
    --cc=sdl.web@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.