Function: Electric-pop-up-window
Electric-pop-up-window is a byte-compiled function defined in
electric.el.gz.
Signature
(Electric-pop-up-window BUFFER &optional MAX-HEIGHT)
Source Code
;; Defined in /usr/src/emacs/lisp/electric.el.gz
;; This function is like pop-to-buffer, sort of.
;; The algorithm is
;; If there is a window displaying buffer
;; Select it
;; Else if there is only one window
;; Split it, selecting the window on the bottom with height being
;; the lesser of max-height (if non-nil) and the number of lines in
;; the buffer to be displayed subject to window-min-height constraint.
;; Else
;; Switch to buffer in the current window.
;;
;; Then if max-height is nil, and not all of the lines in the buffer
;; are displayed, grab the whole frame.
;;
;; Returns selected window on buffer positioned at point-min.
(defun Electric-pop-up-window (buffer &optional max-height)
(let* ((win (or (get-buffer-window buffer) (selected-window)))
(buf (get-buffer buffer))
(one-window (one-window-p t))
(pop-up-windows t)
(pop-up-frames nil))
(if (not buf)
(error "Buffer %s does not exist" buffer)
(cond ((and (eq (window-buffer win) buf))
(select-window win))
(one-window
(pop-to-buffer buffer)
(setq win (selected-window)))
(t
(switch-to-buffer buf)))
;; Don't shrink the window, but expand it if necessary.
(goto-char (point-min))
(unless (= (point-max) (window-end win t))
;; This call is executed even if the window existed before, was
;; reused, ... contradicting a claim in the comment before this
;; function.
(fit-window-to-buffer win max-height nil nil nil t))
win)))