- "Enable or disable resize-minibuffer mode.
-A negative prefix argument disables this mode. A positive argument or
-argument of 0 enables it.
-
-When this minor mode is enabled, the minibuffer is dynamically resized to
-contain the entire region of text put in it as you type.
-
-The variable `resize-minibuffer-mode' is set to t or nil depending on
-whether this mode is active or not.
-
-The maximum height to which the minibuffer can grow is controlled by the
-variable `resize-minibuffer-window-max-height'.
-
-The variable `resize-minibuffer-window-exactly' determines whether the
-minibuffer window should ever be shrunk to make it no larger than needed to
-display its contents.
-
-When using a window system, it is possible for a minibuffer to be the sole
-window in a frame. Since that window is already its maximum size, the only
-way to make more text visible at once is to increase the size of the frame.
-The variable `resize-minibuffer-frame' controls whether this should be
-done. The variables `resize-minibuffer-frame-max-height' and
-`resize-minibuffer-frame-exactly' are analogous to their window
-counterparts."
- (interactive "p")
- (or prefix (setq prefix 0))
- (cond
- ((>= prefix 0)
- (setq resize-minibuffer-mode t))
- (t
- (setq resize-minibuffer-mode nil))))
-
-(defun resize-minibuffer-setup ()
- (cond
- (resize-minibuffer-mode
- (cond
- ((and window-system
- (eq 'only (cdr (assq 'minibuffer (frame-parameters)))))
- ;; Checking for resize-minibuffer-frame is done outside the cond
- ;; predicate because that should always be t if this is a minibuffer
- ;; frame; it just shouldn't do anything if this flag is nil.
- (and resize-minibuffer-frame
- (progn
- ;; Can't trust the height stored in minibuffer-frame-alist
- ;; since the frame can be resized by the window manager and
- ;; that variable isn't updated.
- (make-local-variable 'resize-minibuffer-frame-original-height)
- (setq resize-minibuffer-frame-original-height (frame-height))
-
- (make-local-hook 'post-command-hook)
- (add-hook 'post-command-hook 'resize-minibuffer-frame 'append t)
-
- (make-local-hook 'minibuffer-exit-hook)
- (add-hook 'minibuffer-exit-hook 'resize-minibuffer-frame-restore
- nil t)
-
- (resize-minibuffer-frame))))
- (t
- (make-local-variable 'post-command-hook)
- ;; Copy this because add-hook modifies the list structure.
- (setq post-command-hook (copy-sequence post-command-hook))
- (add-hook 'post-command-hook 'resize-minibuffer-window 'append)
-
- (make-local-variable 'minibuffer-exit-hook)
- (add-hook 'minibuffer-exit-hook 'resize-minibuffer-window-restore)
-
- (resize-minibuffer-window))))))
-
-(defun resize-minibuffer-count-window-lines (&optional start end)
- "Return number of window lines occupied by text in region.
-The number of window lines may be greater than the number of actual lines
-in the buffer if any wrap on the display due to their length.
-
-Optional arguments START and END default to point-min and point-max,
-respectively."
- (or start (setq start (point-min)))
- (or end (setq end (point-max)))
- (if (= start end)
- 0
- (save-excursion
- (save-restriction
- (widen)
- (narrow-to-region start end)
- (goto-char start)
- (vertical-motion (buffer-size))))))