annotate lisp/modes/rsz-minibuf.el @ 30:ec9a17fef872 r19-15b98

Import from CVS: tag r19-15b98
author cvs
date Mon, 13 Aug 2007 08:52:29 +0200
parents 0293115a14e9
children 131b0175ea99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; rsz-minibuf.el --- dynamically resize minibuffer to display entire contents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;; Copyright (C) 1990 Roland McGrath
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; Copyright (C) 1993, 1994 Noah S. Friedman
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; Author: Noah Friedman <friedman@prep.ai.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;; Roland McGrath <roland@prep.ai.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; Modified for Lucid Emacs By: Peter Stout <pds@cs.cmu.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; Maintainer: friedman@prep.ai.mit.edu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; Keywords: minibuffer, window, frames, display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; Status: Known to work in FSF GNU Emacs 19.23 and Lucid Emacs 19.9.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
13 ;;; $Id: rsz-minibuf.el,v 1.3 1997/03/09 02:37:22 steve Exp $
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; along with this program; if not, you can either send email to this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; program's maintainer or write to: The Free Software Foundation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; This package allows the entire contents (or as much as possible) of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; minibuffer to be visible at once when typing. As the end of a line is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; reached, the minibuffer will resize itself. When the user is done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; typing, the minibuffer will return to its original size.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; In window systems where it is possible to have a frame in which the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; minibuffer is the only window, the frame itself can be resized. In FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; GNU Emacs 19.22 and earlier, the frame may not be properly returned to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; its original size after it ceases to be active because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; `minibuffer-exit-hook' didn't exist until version 19.23.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; NOTE: The code to resize frames has not been tested under Lucid Emacs,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; because detached minibuffers are broken.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; Note that the minibuffer and echo area are not the same! They simply
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; happen to occupy roughly the same place on the frame. Messages put in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; the echo area will not cause any resizing by this package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; This package is considered a minor mode but it doesn't put anything in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; minor-mode-alist because this mode is specific to the minibuffer, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; has no modeline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; To use this package, put the following in your .emacs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; (autoload 'resize-minibuffer-mode "rsz-minibuf" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;; Invoking the command `resize-minibuffer-mode' will then enable this mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (defvar resize-minibuffer-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 "*If non-`nil', resize the minibuffer so its entire contents are visible.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (defvar resize-minibuffer-window-max-height nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 "*Maximum size the minibuffer window is allowed to become.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 If less than 1 or not a number, the limit is the height of the frame in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 which the active minibuffer window resides.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (defvar resize-minibuffer-window-exactly t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 "*If non-`nil', make minibuffer exactly the size needed to display all its contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 Otherwise, the minibuffer window can temporarily increase in size but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 never get smaller while it is active.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (defvar resize-minibuffer-frame nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 "*If non-`nil' and the active minibuffer is the sole window in its frame, allow changing the frame height.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (defvar resize-minibuffer-frame-max-height nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 "*Maximum size the minibuffer frame is allowed to become.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 If less than 1 or not a number, there is no limit.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (defvar resize-minibuffer-frame-exactly nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 "*If non-`nil', make minibuffer frame exactly the size needed to display all its contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 Otherwise, the minibuffer frame can temporarily increase in size but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 never get smaller while it is active.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (defun resize-minibuffer-mode (&optional prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 "Enable or disable resize-minibuffer mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 A negative prefix argument disables this mode. A positive argument or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 argument of 0 enables it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 When this minor mode is enabled, the minibuffer is dynamically resized to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 contain the entire region of text put in it as you type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 The variable `resize-minibuffer-mode' is set to t or nil depending on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 whether this mode is active or not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 The maximum height to which the minibuffer can grow is controlled by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 variable `resize-minibuffer-window-max-height'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 The variable `resize-minibuffer-window-exactly' determines whether the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 minibuffer window should ever be shrunk to make it no larger than needed to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 display its contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
115 When using a window system, it is possible for a minibuffer to be the sole
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 window in a frame. Since that window is already its maximum size, the only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 way to make more text visible at once is to increase the size of the frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 The variable `resize-minibuffer-frame' controls whether this should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 done. The variables `resize-minibuffer-frame-max-height' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 `resize-minibuffer-frame-exactly' are analogous to their window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 counterparts."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (or prefix (setq prefix 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ((>= prefix 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (setq resize-minibuffer-mode t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (setq resize-minibuffer-mode nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;;; Glue code to make things work in both FSF and Lucid Emacsen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (if (string-match "Lucid" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (fset 'resize-frame-parameters 'screen-parameters)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (fset 'resize-frame-height 'screen-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (fset 'resize-frame-width 'screen-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (fset 'resize-selected-frame 'selected-screen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (fset 'resize-set-frame-size 'set-screen-size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (defun resize-minibuffer-frame-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 "Return the frame alist for the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 minibuffer-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (fset 'resize-frame-parameters 'frame-parameters)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (fset 'resize-frame-height 'frame-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (fset 'resize-frame-width 'frame-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (fset 'resize-selected-frame 'selected-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (fset 'resize-set-frame-size 'set-frame-size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (defun resize-minibuffer-frame-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 "Return the frame alist for the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 minibuffer-frame-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (defun resize-minibuffer-setup ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (resize-minibuffer-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ((and (not (eq 'tty (console-type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (eq 'only (cdr (assq 'minibuffer (resize-frame-parameters)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (and resize-minibuffer-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (make-local-hook 'minibuffer-exit-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (add-hook 'minibuffer-exit-hook 'resize-minibuffer-frame-restore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (make-local-hook 'post-command-hook)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
162 (add-hook 'post-command-hook 'resize-minibuffer-frame nil t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
163 (unless (and (boundp 'icomplete-mode)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
164 icomplete-mode)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
165 (resize-minibuffer-frame)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (make-local-hook 'post-command-hook)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
168 (add-hook 'post-command-hook 'resize-minibuffer-window nil t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
169 (unless (and (boundp 'icomplete-mode)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
170 icomplete-mode)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
171 (resize-minibuffer-window)))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (defun resize-minibuffer-count-window-lines (&optional start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 "Return number of window lines occupied by text in region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 The number of window lines may be greater than the number of actual lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 in the buffer if any wrap on the display due to their length.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 Optional arguments START and END default to point-min and point-max,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 respectively."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (or start (setq start (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (or end (setq end (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (if (= start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (narrow-to-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (vertical-motion (buffer-size))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; Why isn't `min' a subr?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; Do not pretend this is a real definition of `min'. It suffices for this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;; packages's purposes (and is reasonably fast for a lisp call) but a real
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;; min function would be able to take more than 2 arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (defun resize-minibuffer-min (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 "Return the lesser of X or Y."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (if (< x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 y))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; Resize the minibuffer window to contain the minibuffer's contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; The minibuffer must be the current window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (defun resize-minibuffer-window ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (let ((height (window-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (lines (1+ (resize-minibuffer-count-window-lines))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (and (numberp resize-minibuffer-window-max-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (> resize-minibuffer-window-max-height 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (setq lines (resize-minibuffer-min
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 resize-minibuffer-window-max-height)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (or (if resize-minibuffer-window-exactly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (= lines height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (<= lines height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (enlarge-window (- lines height)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;; Resize the minibuffer frame to contain the minibuffer's contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ;; The minibuffer frame must be the current frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (defun resize-minibuffer-frame ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (let ((height (resize-frame-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (lines (1+ (resize-minibuffer-count-window-lines))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (and (numberp resize-minibuffer-frame-max-height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (> resize-minibuffer-frame-max-height 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (setq lines (resize-minibuffer-min
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 resize-minibuffer-frame-max-height)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ((> lines height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (resize-set-frame-size (resize-selected-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (resize-frame-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 lines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ((and resize-minibuffer-frame-exactly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (> height (cdr (assq 'height (resize-minibuffer-frame-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (< lines height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (resize-set-frame-size (resize-selected-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (resize-frame-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 lines)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;; Restore the original height of the frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (defun resize-minibuffer-frame-restore ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (resize-set-frame-size (resize-selected-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (resize-frame-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (cdr (assq 'height (resize-minibuffer-frame-alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (provide 'rsz-minibuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (add-hook 'minibuffer-setup-hook 'resize-minibuffer-setup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 ;; rsz-minibuf.el ends here