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