Implement temp-output-buffer-show in subr.el.
authorMartin Rudalics <rudalics@gmx.at>
Sat, 22 Sep 2012 16:28:46 +0000 (18:28 +0200)
committerMartin Rudalics <rudalics@gmx.at>
Sat, 22 Sep 2012 16:28:46 +0000 (18:28 +0200)
* 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
lisp/subr.el

index 9278c77..754eafc 100644 (file)
@@ -1,3 +1,9 @@
+2012-09-22  Martin Rudalics  <rudalics@gmx.at>
+
+       * 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  <cyd@gnu.org>
 
        * files.el (ctl-x-map): Bind C-x C-q to read-only-mode
index 1351641..b9b8e62 100644 (file)
@@ -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.