Mercurial > hg > xemacs-beta
annotate lisp/resize-minibuffer.el @ 5882:bbe4146603db
Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
lisp/ChangeLog addition:
2015-04-01 Aidan Kehoe <kehoea@parhasard.net>
When calling #'string-match with a REGEXP without regular
expression special characters, call #'search, #'mismatch, #'find,
etc. instead, making our code less likely to side-effect other
functions' match data and a little faster.
* apropos.el (apropos-command):
* apropos.el (apropos):
Call (position ?\n ...) rather than (string-match "\n" ...) here.
* buff-menu.el:
* buff-menu.el (buffers-menu-omit-invisible-buffers):
Don't fire up the regexp engine just to check if a string starts
with a space.
* buff-menu.el (select-buffers-tab-buffers-by-mode):
Don't fire up the regexp engine just to compare mode basenames.
* buff-menu.el (format-buffers-tab-line):
* buff-menu.el (build-buffers-tab-internal): Moved to being a
label within the following.
* buff-menu.el (buffers-tab-items): Use the label.
* bytecomp.el (byte-compile-log-1):
Don't fire up the regexp engine just to look for a newline.
* cus-edit.el (get):
Ditto.
* cus-edit.el (custom-variable-value-create):
Ditto, but for a colon.
* descr-text.el (describe-text-sexp):
Ditto.
* descr-text.el (describe-char-unicode-data):
Use #'split-string-by-char given that we're just looking for a
semicolon.
* descr-text.el (describe-char):
Don't fire up the regexp engine just to look for a newline.
* disass.el (disassemble-internal):
Ditto.
* files.el (file-name-sans-extension):
Implement this using #'position.
* files.el (file-name-extension):
Correct this function's docstring, implement it in terms of
#'position.
* files.el (insert-directory):
Don't fire up the regexp engine to split a string by space; don't
reverse the list of switches, this is actually a longstand bug as
far as I can see.
* gnuserv.el (gnuserv-process-filter):
Use #'position here, instead of consing inside #'split-string
needlessly.
* gtk-file-dialog.el (gtk-file-dialog-update-dropdown):
Use #'split-string-by-char here, don't fire up #'split-string for
directory-sep-char.
* gtk-font-menu.el (hack-font-truename):
Implement this more cheaply in terms of #'find,
#'split-string-by-char, #'equal, rather than #'string-match,
#'split-string, #'string-equal.
* hyper-apropos.el (hyper-apropos-grok-functions):
* hyper-apropos.el (hyper-apropos-grok-variables):
Look for a newline using #'position rather than #'string-match in
these functions.
* info.el (Info-insert-dir):
* info.el (Info-insert-file-contents):
* info.el (Info-follow-reference):
* info.el (Info-extract-menu-node-name):
* info.el (Info-menu):
Look for fixed strings using #'position or #'search as appropriate
in this file.
* ldap.el (ldap-decode-string):
* ldap.el (ldap-encode-string):
#'encode-coding-string, #'decode-coding-string are always
available, don't check if they're fboundp.
* ldap.el (ldap-decode-address):
* ldap.el (ldap-encode-address):
Use #'split-string-by-char in these functions.
* lisp-mnt.el (lm-creation-date):
* lisp-mnt.el (lm-last-modified-date):
Don't fire up the regexp engine just to look for spaces in this file.
* menubar-items.el (default-menubar):
Use (not (mismatch ...)) rather than #'string-match here, for
simple regexp.
Use (search "beta" ...) rather than (string-match "beta" ...)
* menubar-items.el (sort-buffers-menu-alphabetically):
* menubar-items.el (sort-buffers-menu-by-mode-then-alphabetically):
* menubar-items.el (group-buffers-menu-by-mode-then-alphabetically):
Don't fire up the regexp engine to check if a string starts with
a space or an asterisk.
Use the more fine-grained results of #'compare-strings; compare
case-insensitively for the buffer menu.
* menubar-items.el (list-all-buffers):
* menubar-items.el (tutorials-menu-filter):
Use #'equal rather than #'string-equal, which, in this context,
has the drawback of not having a bytecode, and no redeeming
features.
* minibuf.el:
* minibuf.el (un-substitute-in-file-name):
Use #'count, rather than counting the occurences of $ using the
regexp engine.
* minibuf.el (read-file-name-internal-1):
Don't fire up the regexp engine to search for ?=.
* mouse.el (mouse-eval-sexp):
Check for newline with #'find.
* msw-font-menu.el (mswindows-reset-device-font-menus):
Split a string by newline with #'split-string-by-char.
* mule/japanese.el:
* mule/japanese.el ("Japanese"):
Use #'search rather than #'string-match; canoncase before
comparing; fix a bug I had introduced where I had been making case
insensitive comparisons where the case mattered.
* mule/korea-util.el (default-korean-keyboard):
Look for ?3 using #'find, not #'string-march.
* mule/korea-util.el (quail-hangul-switch-hanja):
Search for a fixed string using #'search.
* mule/mule-cmds.el (set-locale-for-language-environment):
#'position, #'substitute rather than #'string-match,
#'replace-in-string.
* newcomment.el (comment-make-extra-lines):
Use #'search rather than #'string-match for a simple string.
* package-get.el (package-get-remote-filename):
Use #'position when looking for ?@
* process.el (setenv):
* process.el (read-envvar-name):
Use #'position when looking for ?=.
* replace.el (map-query-replace-regexp):
Use #'split-string-by-char instead of using an inline
implementation of it.
* select.el (select-convert-from-cf-text):
* select.el (select-convert-from-cf-unicodetext):
Use #'position rather than #'string-match in these functions.
* setup-paths.el (paths-emacs-data-root-p):
Use #'search when looking for simple string.
* sound.el (load-sound-file):
Use #'split-string-by-char rather than an inline reimplementation
of same.
* startup.el (splash-screen-window-body):
* startup.el (splash-screen-tty-body):
Search for simple strings using #'search.
* version.el (emacs-version):
Ditto.
* x-font-menu.el (hack-font-truename):
Implement this more cheaply in terms of #'find,
#'split-string-by-char, #'equal, rather than #'string-match,
#'split-string, #'string-equal.
* x-font-menu.el (x-reset-device-font-menus-core):
Use #'split-string-by-char here.
* x-init.el (x-initialize-keyboard):
Search for a simple string using #'search.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 01 Apr 2015 14:28:20 +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 |