emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master cd87a5c7a1 1/2: Don't clear out local variables in `with-help-win


From: Lars Ingebrigtsen
Subject: master cd87a5c7a1 1/2: Don't clear out local variables in `with-help-window'
Date: Fri, 13 May 2022 11:14:42 -0400 (EDT)

branch: master
commit cd87a5c7a18ee0fd956ccc151ace85874a8404b1
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Don't clear out local variables in `with-help-window'
    
    * lisp/help-mode.el (help-mode-setup): Declare obsolete.
    (help-mode-finish): Ditto.
    
    * lisp/help.el (with-help-window): Don't be a wrapper around
    `with-temp-buffer-window', because that made the macro big and
    difficult to understand.
    (help--window-setup): Implement the relevant bits from
    `with-temp-buffer-window'.  Also don't clear out local variables,
    because that makes things like `text-scale-mode' not work (bug#25979).
---
 lisp/help-mode.el |  5 ++++-
 lisp/help.el      | 59 ++++++++++++++++++++++++++-----------------------------
 2 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index 4a65f40507..0e4d48e153 100644
--- a/lisp/help-mode.el
+++ b/lisp/help-mode.el
@@ -422,12 +422,15 @@ Commands:
 ;;;###autoload
 (defun help-mode-setup ()
   "Enter Help mode in the current buffer."
-  (help-mode)
+  (declare (obsolete nil "29.1"))
+  (unless (derived-mode-p 'help-mode)
+    (help-mode))
   (setq buffer-read-only nil))
 
 ;;;###autoload
 (defun help-mode-finish ()
   "Finalize Help mode setup in current buffer."
+  (declare (obsolete nil "29.1"))
   (when (derived-mode-p 'help-mode)
     (setq buffer-read-only t)
     (help-make-xrefs (current-buffer))))
diff --git a/lisp/help.el b/lisp/help.el
index d9f364e1ad..83782a8477 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -1938,40 +1938,37 @@ Return VALUE."
     ;; Return VALUE.
     value))
 
-;; `with-help-window' is a wrapper for `with-temp-buffer-window'
-;; providing the following additional twists:
-
-;; (1) It puts the buffer in `help-mode' (via `help-mode-setup') and
-;;     adds cross references (via `help-mode-finish').
-
-;; (2) It issues a message telling how to scroll and quit the help
-;;     window (via `help-window-setup').
-
-;; (3) An option (customizable via `help-window-select') to select the
-;;     help window automatically.
-
-;; (4) A marker (`help-window-point-marker') to move point in the help
-;;     window to an arbitrary buffer position.
 (defmacro with-help-window (buffer-or-name &rest body)
   "Evaluate BODY, send output to BUFFER-OR-NAME and show in a help window.
-This construct is like `with-temp-buffer-window', which see, but unlike
-that, it puts the buffer specified by BUFFER-OR-NAME in `help-mode' and
-displays a message about how to delete the help window when it's no
-longer needed.  The help window will be selected if
-`help-window-select' is non-nil.
-Most of this is done by `help-window-setup', which see."
+The return value from BODY will be returned.
+
+The help window will be selected if `help-window-select' is
+non-nil.
+
+The `temp-buffer-window-setup-hook' hook is called."
   (declare (indent 1) (debug t))
-  `(progn
-     ;; Make `help-window-point-marker' point nowhere.  The only place
-     ;; where this should be set to a buffer position is within BODY.
-     (set-marker help-window-point-marker nil)
-     (let ((temp-buffer-window-setup-hook
-           (cons 'help-mode-setup temp-buffer-window-setup-hook))
-          (temp-buffer-window-show-hook
-           (cons 'help-mode-finish temp-buffer-window-show-hook)))
-       (setq help-window-old-frame (selected-frame))
-       (with-temp-buffer-window
-       ,buffer-or-name nil 'help-window-setup (progn ,@body)))))
+  `(help--window-setup ,buffer-or-name (lambda () ,@body)))
+
+(defun help--window-setup (buffer callback)
+  ;; Make `help-window-point-marker' point nowhere.  The only place
+  ;; where this should be set to a buffer position is within BODY.
+  (set-marker help-window-point-marker nil)
+  (with-current-buffer (get-buffer-create buffer)
+    (setq buffer-read-only t
+          buffer-file-name nil)
+    (buffer-disable-undo)
+    (let ((inhibit-read-only t)
+         (inhibit-modification-hooks t))
+      (erase-buffer)
+      (delete-all-overlays)
+      (prog1
+          (let ((standard-output (current-buffer)))
+            (funcall callback)
+            (run-hooks 'temp-buffer-window-setup-hook))
+        (help-window-setup (temp-buffer-window-show (current-buffer)))
+        (unless (derived-mode-p 'help-mode)
+          (help-mode))
+        (help-make-xrefs (current-buffer))))))
 
 ;; Called from C, on encountering `help-char' when reading a char.
 ;; Don't print to *Help*; that would clobber Help history.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]