From 3b9a564d2aaae83f612d55f4d9592fa5d96986eb Mon Sep 17 00:00:00 2001 From: Karl Fogel Date: Sun, 17 Dec 2023 12:17:11 -0600 Subject: [PATCH] Keep network security info buffers after use * lisp/net/nsm.el (nsm-query-user): Don't kill the two informational buffers "*Network Security Manager*" and "*Certificate Details*". Even after making a decision about a certificate, the user might want to go back to those buffers to get information from them. Note that while the diff is large, the actual change is tiny. The removal of the `unwind-protect' wrapper caused much reindentation (there's nothing to unwind now, as both unwindforms went away). The "real" diff is just the removal of the two `kill-buffer' calls at the end of the function and would look something like this: --- lisp/net/nsm.el +++ lisp/net/nsm.el @@ -918,9 +918,7 @@ nsm-query-user (goto-char (point-min)) (read-only-mode))))) ;; Return the answer. - (cadr answer)) - (kill-buffer cert-buffer) - (kill-buffer buffer))))) + (cadr answer)))))) --- lisp/net/nsm.el | 139 ++++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 70 deletions(-) diff --git a/lisp/net/nsm.el b/lisp/net/nsm.el index 09f7ac52537..9df08b33ca9 100644 --- a/lisp/net/nsm.el +++ b/lisp/net/nsm.el @@ -846,81 +846,80 @@ nsm-query-user '((?b "backward page" "See previous page") (?f "forward page" "See next page")))))) ;; Then ask the user what to do about it. - (unwind-protect - (let* ((pems (cl-loop for cert in certs - collect (gnutls-format-certificate - (plist-get cert :pem)))) - (cert-index 0) - show-details answer buf) - (while (not done) - (setq answer (if show-details - (read-multiple-choice "Viewing certificate:" - details-choices) - (read-multiple-choice "Continue connecting?" - accept-choices))) - (setq buf (if show-details cert-buffer buffer)) - - (cl-case (car answer) - (?q - ;; Exit the details window. - (set-window-buffer (get-buffer-window cert-buffer) buffer) - (setq show-details nil)) - - (?d - ;; Enter the details window. - (set-window-buffer (get-buffer-window buffer) cert-buffer) - (with-current-buffer cert-buffer - (read-only-mode -1) - (insert (nth cert-index pems)) - (goto-char (point-min)) - (read-only-mode)) - (setq show-details t)) - - (?b - ;; Scroll down. - (with-selected-window (get-buffer-window buf) - (with-current-buffer buf - (ignore-errors (scroll-down))))) - - (?f - ;; Scroll up. - (with-selected-window (get-buffer-window buf) - (with-current-buffer buf - (ignore-errors (scroll-up))))) - - (?n - ;; "No" or "next certificate". - (if show-details - (with-current-buffer cert-buffer - (read-only-mode -1) - (erase-buffer) - (setq cert-index (mod (1+ cert-index) (length pems))) - (insert (nth cert-index pems)) - (goto-char (point-min)) - (read-only-mode)) - (setq done t))) - - (?a - ;; "Always" - (setq done t)) - - (?s - ;; "Session only" - (setq done t)) - - (?p - ;; Previous certificate. + (let* ((pems (cl-loop for cert in certs + collect (gnutls-format-certificate + (plist-get cert :pem)))) + (cert-index 0) + show-details answer buf) + (while (not done) + (setq answer (if show-details + (read-multiple-choice "Viewing certificate:" + details-choices) + (read-multiple-choice "Continue connecting?" + accept-choices))) + (setq buf (if show-details cert-buffer buffer)) + + (cl-case (car answer) + (?q + ;; Exit the details window. + (set-window-buffer (get-buffer-window cert-buffer) buffer) + (setq show-details nil)) + + (?d + ;; Enter the details window. + (set-window-buffer (get-buffer-window buffer) cert-buffer) + (with-current-buffer cert-buffer + (read-only-mode -1) + (insert (nth cert-index pems)) + (goto-char (point-min)) + (read-only-mode)) + (setq show-details t)) + + (?b + ;; Scroll down. + (with-selected-window (get-buffer-window buf) + (with-current-buffer buf + (ignore-errors (scroll-down))))) + + (?f + ;; Scroll up. + (with-selected-window (get-buffer-window buf) + (with-current-buffer buf + (ignore-errors (scroll-up))))) + + (?n + ;; "No" or "next certificate". + (if show-details (with-current-buffer cert-buffer (read-only-mode -1) (erase-buffer) - (setq cert-index (mod (1- cert-index) (length pems))) + (setq cert-index (mod (1+ cert-index) (length pems))) (insert (nth cert-index pems)) (goto-char (point-min)) - (read-only-mode))))) - ;; Return the answer. - (cadr answer)) - (kill-buffer cert-buffer) - (kill-buffer buffer))))) + (read-only-mode)) + (setq done t))) + + (?a + ;; "Always" + (setq done t)) + + (?s + ;; "Session only" + (setq done t)) + + (?p + ;; Previous certificate. + (with-current-buffer cert-buffer + (read-only-mode -1) + (erase-buffer) + (setq cert-index (mod (1- cert-index) (length pems))) + (insert (nth cert-index pems)) + (goto-char (point-min)) + (read-only-mode))))) + ;; Return the answer. (We leave `buffer' and `cert-buffer' + ;; around, in case the user wants to go back and get any + ;; information from them.) + (cadr answer))))) (defun nsm-save-host (host port status what problems permanency) (let* ((id (nsm-id host port)) -- 2.43.0