From 43bf5e8e4de7e2e45069f3fe591c658a61126378 Mon Sep 17 00:00:00 2001 From: Martin Rudalics Date: Sat, 22 Sep 2012 18:28:46 +0200 Subject: [PATCH] Implement temp-output-buffer-show in subr.el. * subr.el (temp-output-buffer-show): New function. (with-output-to-temp-buffer): Call temp-output-buffer-show instead of internal-temp-output-buffer-show. --- lisp/ChangeLog | 6 ++++++ lisp/subr.el | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9278c778636..754eafc81a3 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2012-09-22 Martin Rudalics + + * subr.el (temp-output-buffer-show): New function. + (with-output-to-temp-buffer): Call temp-output-buffer-show + instead of internal-temp-output-buffer-show. + 2012-09-22 Chong Yidong * files.el (ctl-x-map): Bind C-x C-q to read-only-mode diff --git a/lisp/subr.el b/lisp/subr.el index 13516419b6f..b9b8e627672 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3138,6 +3138,45 @@ in which case `save-window-excursion' cannot help." (unwind-protect (progn ,@body) (set-window-configuration ,c))))) +(defun temp-output-buffer-show (buffer) + "Internal function for `with-output-to-temp-buffer'." + (with-current-buffer buffer + (set-buffer-modified-p nil) + (goto-char (point-min))) + + (if temp-buffer-show-function + (funcall temp-buffer-show-function buffer) + (with-current-buffer buffer + (let* ((window + (let ((window-combination-limit + ;; When `window-combination-limit' equals + ;; `temp-buffer' or `temp-buffer-resize' and + ;; `temp-buffer-resize-mode' is enabled in this + ;; buffer bind it to t so resizing steals space + ;; preferably from the window that was split. + (if (or (eq window-combination-limit 'temp-buffer) + (and (eq window-combination-limit + 'temp-buffer-resize) + temp-buffer-resize-mode)) + t + window-combination-limit))) + (display-buffer buffer))) + (frame (and window (window-frame window)))) + (when window + (unless (eq frame (selected-frame)) + (make-frame-visible frame)) + (setq minibuffer-scroll-window window) + (set-window-hscroll window 0) + ;; Don't try this with NOFORCE non-nil! + (set-window-start window (point-min) t) + ;; This hould not be necessary. + (set-window-point window (point-min)) + ;; Run `temp-buffer-show-hook', with the chosen window selected. + (with-selected-window window + (run-hooks 'temp-buffer-show-hook)))))) + ;; Return nil. + nil) + (defmacro with-output-to-temp-buffer (bufname &rest body) "Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer. @@ -3183,7 +3222,7 @@ if it uses `temp-buffer-show-function'." (run-hooks 'temp-buffer-setup-hook))))) (standard-output ,buf)) (prog1 (progn ,@body) - (internal-temp-output-buffer-show ,buf))))) + (temp-output-buffer-show ,buf))))) (defmacro with-temp-file (file &rest body) "Create a new buffer, evaluate BODY there, and write the buffer to FILE. -- 2.39.2