]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix problem of having the wrong window selected after saving foo.gpg
authorLars Ingebrigtsen <larsi@gnus.org>
Wed, 30 Sep 2020 15:36:39 +0000 (17:36 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Wed, 30 Sep 2020 15:36:39 +0000 (17:36 +0200)
* lisp/epa.el (epa--select-keys): Restore the window configuration
after selecting the key to use (bug#43703).  This also ensures
that the buffer we were editing ends up as the current buffer
after saving it, instead of selecting a different window.

lisp/epa.el

index 609ac5d191769c4a8d33d27ef1b5bd585cb98ee0..a2fb7f2bd1d1c784ff6916092cfc78337439dcf7 100644 (file)
@@ -435,33 +435,35 @@ q  trust status questionable.  -  trust status unspecified.
   (unless (and epa-keys-buffer
                (buffer-live-p epa-keys-buffer))
     (setq epa-keys-buffer (generate-new-buffer "*Keys*")))
-  (with-current-buffer epa-keys-buffer
-    (epa-key-list-mode)
-    ;; C-c C-c is the usual way to finish the selection (bug#11159).
-    (define-key (current-local-map) "\C-c\C-c" 'exit-recursive-edit)
-    (let ((inhibit-read-only t)
-         buffer-read-only)
-      (erase-buffer)
-      (insert prompt "\n"
-             (substitute-command-keys "\
+  (let ((conf (current-window-configuration)))
+    (with-current-buffer epa-keys-buffer
+      (epa-key-list-mode)
+      ;; C-c C-c is the usual way to finish the selection (bug#11159).
+      (define-key (current-local-map) "\C-c\C-c" 'exit-recursive-edit)
+      (let ((inhibit-read-only t)
+           buffer-read-only)
+        (erase-buffer)
+        (insert prompt "\n"
+               (substitute-command-keys "\
 - `\\[epa-mark-key]' to mark a key on the line
 - `\\[epa-unmark-key]' to unmark a key on the line\n"))
-      (insert-button "[Cancel]"
-                     'action (lambda (_button) (abort-recursive-edit)))
-      (insert " ")
-      (insert-button "[OK]"
-                     'action (lambda (_button) (exit-recursive-edit)))
-      (insert "\n\n")
-      (epa--insert-keys keys)
-      (setq epa-exit-buffer-function #'abort-recursive-edit)
-      (goto-char (point-min))
-      (let ((display-buffer-mark-dedicated 'soft))
-        (pop-to-buffer (current-buffer))))
-    (unwind-protect
-       (progn
-         (recursive-edit)
-         (epa--marked-keys))
-      (kill-buffer epa-keys-buffer))))
+        (insert-button "[Cancel]"
+                       'action (lambda (_button) (abort-recursive-edit)))
+        (insert " ")
+        (insert-button "[OK]"
+                       'action (lambda (_button) (exit-recursive-edit)))
+        (insert "\n\n")
+        (epa--insert-keys keys)
+        (setq epa-exit-buffer-function #'abort-recursive-edit)
+        (goto-char (point-min))
+        (let ((display-buffer-mark-dedicated 'soft))
+          (pop-to-buffer (current-buffer))))
+      (unwind-protect
+         (progn
+           (recursive-edit)
+           (epa--marked-keys))
+        (kill-buffer epa-keys-buffer)
+        (set-window-configuration conf)))))
 
 ;;;###autoload
 (defun epa-select-keys (context prompt &optional names secret)