Mercurial > hg > xemacs-beta
annotate lisp/resize-minibuffer.el @ 5753:dbd8305e13cb
Warn about non-string non-integer ARG to #'gensym, bytecomp.el.
lisp/ChangeLog addition:
2013-08-21 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el:
* bytecomp.el (gensym):
* bytecomp.el (byte-compile-gensym): New.
Warn that gensym called in a for-effect context is unlikely to be
useful.
Warn about non-string non-integer ARGs, this is incorrect.
Am not changing the function to error with same, most code that
makes the mistake is has no problems, which is why it has survived
so long.
* window-xemacs.el (save-window-excursion/mapping):
* window.el (save-window-excursion):
Call #'gensym with a string, not a symbol.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 21 Aug 2013 19:02:59 +0100 |
parents | 91b3aa59f49b |
children |
rev | line source |
---|---|
771 | 1 ;;; resize-minibuffer.el --- dynamically resize minibuffer to display entire contents |
2 | |
3 ;; Copyright (C) 1990 Roland McGrath | |
4 ;; Copyright (C) 1993, 1994 Noah S. Friedman | |
5 | |
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 | |
12 ;; This file is part of XEmacs. | |
13 | |
5404
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
3936
diff
changeset
|
14 ;; XEmacs is free software: you can redistribute it and/or modify it |
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
3936
diff
changeset
|
15 ;; under the terms of the GNU General Public License as published by the |
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
3936
diff
changeset
|
16 ;; Free Software Foundation, either version 3 of the License, or (at your |
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
3936
diff
changeset
|
17 ;; option) any later version. |
771 | 18 |
5404
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
3936
diff
changeset
|
19 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
3936
diff
changeset
|
20 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
3936
diff
changeset
|
21 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
3936
diff
changeset
|
22 ;; for more details. |
771 | 23 |
24 ;; You should have received a copy of the GNU General Public License | |
5404
91b3aa59f49b
Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
3936
diff
changeset
|
25 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
771 | 26 |
27 ;;; Synched up with: Not synched. Copied from rsz-minibuf.el to | |
28 ;;; resize-minibuffer.el to avoid current problems where, when there's a | |
29 ;;; file in dump and a file with the same name in packages, a dumping | |
30 ;;; XEmacs will find the wrong one! | |
31 | |
32 ;;; Commentary: | |
33 | |
34 ;; This file has received maintenance by the XEmacs development team. | |
35 | |
36 ;; This package allows the entire contents (or as much as possible) of the | |
37 ;; minibuffer to be visible at once when typing. As the end of a line is | |
38 ;; reached, the minibuffer will resize itself. When the user is done | |
39 ;; typing, the minibuffer will return to its original size. | |
40 | |
41 ;; In window systems where it is possible to have a frame in which the | |
42 ;; minibuffer is the only window, the frame itself can be resized. In FSF | |
43 ;; GNU Emacs 19.22 and earlier, the frame may not be properly returned to | |
44 ;; its original size after it ceases to be active because | |
45 ;; `minibuffer-exit-hook' didn't exist until version 19.23. | |
46 | |
47 ;; NOTE: The code to resize frames has not been tested under Lucid Emacs, | |
48 ;; because detached minibuffers are broken. | |
49 | |
50 ;; Note that the minibuffer and echo area are not the same! They simply | |
51 ;; happen to occupy roughly the same place on the frame. Messages put in | |
52 ;; the echo area will not cause any resizing by this package. | |
53 | |
54 ;; This package is considered a minor mode but it doesn't put anything in | |
55 ;; minor-mode-alist because this mode is specific to the minibuffer, which | |
56 ;; has no modeline. | |
57 | |
58 ;; To use this package, put the following in your .emacs: | |
59 ;; | |
60 ;; (autoload 'resize-minibuffer-mode "rsz-minibuf" nil t) | |
61 ;; | |
62 ;; Invoking the command `resize-minibuffer-mode' will then enable this mode. | |
63 | |
64 ;;; Code: | |
65 | |
66 | |
67 | |
68 (defgroup resize-minibuffer nil | |
69 "Dynamically resize minibuffer to display entire contents" | |
70 :group 'frames) | |
71 | |
72 | |
73 (defcustom resize-minibuffer-mode nil | |
74 "*If non-`nil', resize the minibuffer so its entire contents are visible." | |
75 :type 'boolean | |
76 :require 'rsz-minibuf | |
77 :group 'resize-minibuffer) | |
78 | |
79 (defcustom resize-minibuffer-window-max-height nil | |
80 "*Maximum size the minibuffer window is allowed to become. | |
81 If less than 1 or not a number, the limit is the height of the frame in | |
82 which the active minibuffer window resides." | |
83 :type '(choice (const nil) integer) | |
84 :group 'resize-minibuffer) | |
85 | |
3929 | 86 ;; #### Yeah, I know. The relation between the echo area and the |
87 ;; minibuffer needs rethinking. It's not really possible to unify them at | |
88 ;; present. -- sjt | |
89 (defcustom resize-minibuffer-idle-height nil | |
90 "When minibuffer is idle, crop its window to this height. | |
91 Must be a positive integer or nil. nil indicates no limit. | |
92 Effective only when `undisplay-echo-area-function' respects it. One such | |
93 function is `undisplay-echo-area-resize-window'.") | |
94 | |
771 | 95 (defcustom resize-minibuffer-window-exactly t |
96 "*If non-`nil', make minibuffer exactly the size needed to display all its contents. | |
97 Otherwise, the minibuffer window can temporarily increase in size but | |
98 never get smaller while it is active." | |
99 :type 'boolean | |
100 :group 'resize-minibuffer) | |
101 | |
102 | |
103 (defcustom resize-minibuffer-frame nil | |
104 "*If non-`nil' and the active minibuffer is the sole window in its frame, allow changing the frame height." | |
105 :type 'boolean | |
106 :group 'resize-minibuffer) | |
107 | |
108 (defcustom resize-minibuffer-frame-max-height nil | |
109 "*Maximum size the minibuffer frame is allowed to become. | |
110 If less than 1 or not a number, there is no limit.") | |
111 | |
112 (defcustom resize-minibuffer-frame-exactly nil | |
113 "*If non-`nil', make minibuffer frame exactly the size needed to display all its contents. | |
114 Otherwise, the minibuffer frame can temporarily increase in size but | |
115 never get smaller while it is active." | |
116 :type 'boolean | |
117 :group 'resize-minibuffer) | |
118 | |
119 | |
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 | |
138 When using a window system, it is possible for a minibuffer to be the sole | |
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 (defun resize-minibuffer-setup () | |
154 (cond | |
155 (resize-minibuffer-mode | |
156 (cond | |
157 ((and (not (eq 'tty (console-type))) | |
158 (eq 'only (plist-get (frame-properties) 'minibuffer))) | |
159 (and resize-minibuffer-frame | |
160 (progn | |
161 (make-local-hook 'minibuffer-exit-hook) | |
162 (add-hook 'minibuffer-exit-hook 'resize-minibuffer-frame-restore | |
163 nil t) | |
164 (make-local-hook 'post-command-hook) | |
165 (add-hook 'post-command-hook 'resize-minibuffer-frame nil t) | |
776 | 166 (unless (and-boundp 'icomplete-mode icomplete-mode) |
771 | 167 (resize-minibuffer-frame))))) |
168 (t | |
169 (make-local-hook 'post-command-hook) | |
170 (add-hook 'post-command-hook 'resize-minibuffer-window nil t) | |
776 | 171 (unless (and-boundp 'icomplete-mode icomplete-mode) |
771 | 172 (resize-minibuffer-window))))))) |
173 | |
174 (defun resize-minibuffer-count-window-lines (&optional start end) | |
175 "Return number of window lines occupied by text in region. | |
176 The number of window lines may be greater than the number of actual lines | |
177 in the buffer if any wrap on the display due to their length. | |
178 | |
179 Optional arguments START and END default to point-min and point-max, | |
180 respectively." | |
181 (or start (setq start (point-min))) | |
182 (or end (setq end (point-max))) | |
183 (if (= start end) | |
184 0 | |
185 (save-excursion | |
186 (save-restriction | |
187 (widen) | |
188 (narrow-to-region start end) | |
189 (goto-char start) | |
190 (vertical-motion (buffer-size)))))) | |
191 | |
192 | |
193 ;; Resize the minibuffer window to contain the minibuffer's contents. | |
194 ;; The minibuffer must be the current window. | |
195 (defun resize-minibuffer-window () | |
196 (let ((height (window-height)) | |
197 (lines (1+ (resize-minibuffer-count-window-lines)))) | |
198 (and (numberp resize-minibuffer-window-max-height) | |
199 (> resize-minibuffer-window-max-height 0) | |
200 (setq lines (min | |
201 lines | |
202 resize-minibuffer-window-max-height))) | |
203 (or (if resize-minibuffer-window-exactly | |
204 (= lines height) | |
205 (<= lines height)) | |
206 (enlarge-window (- lines height))))) | |
207 | |
208 | |
209 ;; Resize the minibuffer frame to contain the minibuffer's contents. | |
210 ;; The minibuffer frame must be the current frame. | |
211 (defun resize-minibuffer-frame () | |
212 (let ((height (frame-height)) | |
213 (lines (1+ (resize-minibuffer-count-window-lines)))) | |
214 (and (numberp resize-minibuffer-frame-max-height) | |
215 (> resize-minibuffer-frame-max-height 0) | |
216 (setq lines (min | |
217 lines | |
218 resize-minibuffer-frame-max-height))) | |
219 (cond | |
220 ((> lines height) | |
221 (set-frame-size (selected-frame) (frame-width) lines)) | |
222 ((and resize-minibuffer-frame-exactly | |
223 (> height (plist-get minibuffer-frame-plist 'height)) | |
224 (< lines height)) | |
225 (set-frame-size (selected-frame) (frame-width) lines))))) | |
226 | |
227 ;; Restore the original height of the frame. | |
228 (defun resize-minibuffer-frame-restore () | |
229 (set-frame-size (selected-frame) (frame-width) | |
230 (plist-get minibuffer-frame-plist 'height))) | |
231 | |
232 | |
233 (provide 'rsz-minibuf) | |
234 | |
235 (add-hook 'minibuffer-setup-hook 'resize-minibuffer-setup) | |
236 | |
237 ;;; rsz-minibuf.el ends here |