Mercurial > emacs
annotate lisp/rsz-mini.el @ 8000:6d0a448be1ec
(face-equal): Do check the underline attribute.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 21 Jun 1994 20:22:56 +0000 |
parents | e70581cde056 |
children | df03bfa5b694 |
rev | line source |
---|---|
7267 | 1 ;;; rsz-mini.el --- dynamically resize minibuffer to display entire contents |
2 | |
3 ;;; Copyright (C) 1990, 1993, 1994 Free Software Foundation, Inc. | |
4 | |
5 ;;; Author: Noah Friedman <friedman@prep.ai.mit.edu> | |
6 ;;; Roland McGrath <roland@prep.ai.mit.edu> | |
7 ;;; Maintainer: friedman@prep.ai.mit.edu | |
8 ;;; Keywords: minibuffer, window, frame, display | |
9 ;;; Status: Known to work in FSF GNU Emacs 19.23. | |
7590
e70581cde056
Enable resize-minibuffer-mode when this file is loaded.
Noah Friedman <friedman@splode.com>
parents:
7512
diff
changeset
|
10 ;;; $Id$ |
7267 | 11 |
12 ;; This file is part of GNU Emacs. | |
13 | |
14 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
15 ;; it under the terms of the GNU General Public License as published by | |
16 ;; the Free Software Foundation; either version 2, or (at your option) | |
17 ;; any later version. | |
18 | |
19 ;; GNU Emacs is distributed in the hope that it will be useful, | |
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 ;; GNU General Public License for more details. | |
23 | |
24 ;; You should have received a copy of the GNU General Public License | |
25 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
26 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
27 | |
28 ;;; Commentary: | |
29 | |
30 ;;; This package allows the entire contents (or as much as possible) of the | |
31 ;;; minibuffer to be visible at once when typing. As the end of a line is | |
32 ;;; reached, the minibuffer will resize itself. When the user is done | |
33 ;;; typing, the minibuffer will return to its original size. | |
34 | |
35 ;;; In window systems where it is possible to have a frame in which the | |
36 ;;; minibuffer is the only window, the frame itself can be resized. In FSF | |
37 ;;; GNU Emacs 19.22 and earlier, the frame may not be properly returned to | |
38 ;;; its original size after it ceases to be active because | |
39 ;;; `minibuffer-exit-hook' didn't exist until version 19.23. | |
40 | |
41 ;;; Note that the minibuffer and echo area are not the same! They simply | |
42 ;;; happen to occupy roughly the same place on the frame. Messages put in | |
43 ;;; the echo area will not cause any resizing by this package. | |
44 | |
45 ;;; This package is considered a minor mode but it doesn't put anything in | |
46 ;;; minor-mode-alist because this mode is specific to the minibuffer, which | |
47 ;;; has no mode line. | |
48 | |
49 ;;; To use this package, put the following in your .emacs: | |
50 ;;; | |
51 ;;; (autoload 'resize-minibuffer-mode "rsz-mini" nil t) | |
52 ;;; | |
53 ;;; Invoking the command `resize-minibuffer-mode' will then enable this mode. | |
7590
e70581cde056
Enable resize-minibuffer-mode when this file is loaded.
Noah Friedman <friedman@splode.com>
parents:
7512
diff
changeset
|
54 ;;; Simply loading this file will enable resize-minibuffer-mode. |
7267 | 55 |
56 ;;; Code: | |
57 | |
58 | |
59 ;;;###autoload | |
60 (defvar resize-minibuffer-mode nil | |
61 "*If non-`nil', resize the minibuffer so its entire contents are visible.") | |
62 | |
63 ;;;###autoload | |
64 (defvar resize-minibuffer-window-max-height nil | |
65 "*Maximum size the minibuffer window is allowed to become. | |
66 If less than 1 or not a number, the limit is the height of the frame in | |
67 which the active minibuffer window resides.") | |
68 | |
69 ;;;###autoload | |
70 (defvar resize-minibuffer-window-exactly t | |
71 "*If non-`nil', make minibuffer exactly the size needed to display all its contents. | |
72 Otherwise, the minibuffer window can temporarily increase in size but | |
73 never get smaller while it is active.") | |
74 | |
75 | |
76 ;;;###autoload | |
77 (defvar resize-minibuffer-frame nil | |
78 "*If non-`nil' and the active minibuffer is the sole window in its frame, allow changing the frame height.") | |
79 | |
80 ;;;###autoload | |
81 (defvar resize-minibuffer-frame-max-height nil | |
82 "*Maximum size the minibuffer frame is allowed to become. | |
83 If less than 1 or not a number, there is no limit.") | |
84 | |
85 ;;;###autoload | |
86 (defvar resize-minibuffer-frame-exactly nil | |
87 "*If non-`nil', make minibuffer frame exactly the size needed to display all its contents. | |
88 Otherwise, the minibuffer frame can temporarily increase in size but | |
89 never get smaller while it is active.") | |
90 | |
91 | |
92 ;;;###autoload | |
93 (defun resize-minibuffer-mode (&optional prefix) | |
94 "Enable or disable resize-minibuffer mode. | |
95 A negative prefix argument disables this mode. A positive argument or | |
96 argument of 0 enables it. | |
97 | |
98 When this minor mode is enabled, the minibuffer is dynamically resized to | |
99 contain the entire region of text put in it as you type. | |
100 | |
101 The variable `resize-minibuffer-mode' is set to t or nil depending on | |
102 whether this mode is active or not. | |
103 | |
104 The maximum height to which the minibuffer can grow is controlled by the | |
105 variable `resize-minibuffer-window-max-height'. | |
106 | |
107 The variable `resize-minibuffer-window-exactly' determines whether the | |
108 minibuffer window should ever be shrunk to make it no larger than needed to | |
109 display its contents. | |
110 | |
7512 | 111 When using a window system, it is possible for a minibuffer to be the sole |
7267 | 112 window in a frame. Since that window is already its maximum size, the only |
113 way to make more text visible at once is to increase the size of the frame. | |
114 The variable `resize-minibuffer-frame' controls whether this should be | |
115 done. The variables `resize-minibuffer-frame-max-height' and | |
116 `resize-minibuffer-frame-exactly' are analogous to their window | |
117 counterparts." | |
118 (interactive "p") | |
119 (or prefix (setq prefix 0)) | |
120 (cond | |
121 ((>= prefix 0) | |
122 (setq resize-minibuffer-mode t)) | |
123 (t | |
124 (setq resize-minibuffer-mode nil)))) | |
125 | |
126 (defun resize-minibuffer-setup () | |
127 (cond | |
128 (resize-minibuffer-mode | |
129 (cond | |
130 ((and window-system | |
131 (eq 'only (cdr (assq 'minibuffer (frame-parameters))))) | |
132 (and resize-minibuffer-frame | |
133 (progn | |
134 (make-local-variable 'minibuffer-exit-hook) | |
135 (add-hook 'minibuffer-exit-hook 'resize-minibuffer-frame-restore) | |
136 (make-local-variable 'post-command-hook) | |
137 (add-hook 'post-command-hook 'resize-minibuffer-frame)))) | |
138 (t | |
139 (make-local-variable 'post-command-hook) | |
140 (add-hook 'post-command-hook 'resize-minibuffer-window)))))) | |
141 | |
142 (defun resize-minibuffer-count-window-lines (&optional start end) | |
143 "Return number of window lines occupied by text in region. | |
144 The number of window lines may be greater than the number of actual lines | |
145 in the buffer if any wrap on the display due to their length. | |
146 | |
147 Optional arguments START and END default to point-min and point-max, | |
148 respectively." | |
149 (or start (setq start (point-min))) | |
150 (or end (setq end (point-max))) | |
151 (if (= start end) | |
152 0 | |
153 (save-excursion | |
154 (save-restriction | |
155 (widen) | |
156 (narrow-to-region start end) | |
157 (goto-char start) | |
158 (vertical-motion (buffer-size)))))) | |
159 | |
160 | |
161 ;; Resize the minibuffer window to contain the minibuffer's contents. | |
162 ;; The minibuffer must be the current window. | |
163 (defun resize-minibuffer-window () | |
164 (let ((height (window-height)) | |
165 (lines (1+ (resize-minibuffer-count-window-lines)))) | |
166 (and (numberp resize-minibuffer-window-max-height) | |
167 (> resize-minibuffer-window-max-height 0) | |
168 (setq lines (min lines resize-minibuffer-window-max-height))) | |
169 (or (if resize-minibuffer-window-exactly | |
170 (= lines height) | |
171 (<= lines height)) | |
172 (enlarge-window (- lines height))))) | |
173 | |
174 | |
175 ;; Resize the minibuffer frame to contain the minibuffer's contents. | |
176 ;; The minibuffer frame must be the current frame. | |
177 (defun resize-minibuffer-frame () | |
178 (let ((height (frame-height)) | |
179 (lines (1+ (resize-minibuffer-count-window-lines)))) | |
180 (and (numberp resize-minibuffer-frame-max-height) | |
181 (> resize-minibuffer-frame-max-height 0) | |
182 (setq lines (min lines resize-minibuffer-frame-max-height))) | |
183 (cond | |
184 ((> lines height) | |
185 (set-frame-size (selected-frame) (frame-width) lines)) | |
186 ((and resize-minibuffer-frame-exactly | |
187 (> height (cdr (assq 'height minibuffer-frame-alist))) | |
188 (< lines height)) | |
189 (set-frame-size (selected-frame) (frame-width) lines))))) | |
190 | |
191 ;; Restore the original height of the frame. | |
192 (defun resize-minibuffer-frame-restore () | |
193 (set-frame-size (selected-frame) | |
194 (frame-width) | |
195 (cdr (assq 'height minibuffer-frame-alist)))) | |
196 | |
197 | |
198 (provide 'rsz-mini) | |
199 | |
200 (add-hook 'minibuffer-setup-hook 'resize-minibuffer-setup) | |
7590
e70581cde056
Enable resize-minibuffer-mode when this file is loaded.
Noah Friedman <friedman@splode.com>
parents:
7512
diff
changeset
|
201 (resize-minibuffer-mode) |
7267 | 202 |
203 ;; rsz-mini.el ends here |