Mercurial > hg > xemacs-beta
annotate lisp/frame.el @ 5914:bd4d2c8ef9cc
Use the existing C-level line number cache within #'line-number.
src/ChangeLog addition:
2015-05-15 Aidan Kehoe <kehoea@parhasard.net>
* buffer.c:
* buffer.c (Fline_number): New C implementation, using the line
number cache of line-number.c, with a new optional BUFFER
argument.
* buffer.c (syms_of_buffer):
Make it available to Lisp.
* line-number.c (buffer_line_number):
New argument, RESPECT-NARROWING, describing whether to count from
the beginning of the visible region or from the beginning of the
buffer.
* line-number.h:
* line-number.h (buffer_line_number): Update its declaration.
* redisplay.c (window_line_number): Call it with the new argument.
lisp/ChangeLog addition:
2015-05-15 Aidan Kehoe <kehoea@parhasard.net>
* simple.el:
* simple.el (line-number): Moved to buffer.c; we have an existing
line number cache in C, it's a shame not to have it available.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Fri, 15 May 2015 18:11:47 +0100 |
parents | cc6f0266bc36 |
children |
rev | line source |
---|---|
428 | 1 ;;; frame.el --- multi-frame management independent of window systems. |
2 | |
1942 | 3 ;; Copyright (C) 1993, 1994, 1996, 1997, 2000, 2001, 2003 |
4 ;; Free Software Foundation, Inc. | |
428 | 5 ;; Copyright (C) 1995, 1996 Ben Wing. |
5080
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
6 ;; Copyright (C) 2010 Didier Verna |
428 | 7 |
8 ;; Maintainer: XEmacs Development Team | |
9 ;; Keywords: internal, dumped | |
10 | |
11 ;; This file is part of XEmacs. | |
12 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
13 ;; XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
14 ;; under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
15 ;; Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
16 ;; option) any later version. |
428 | 17 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
18 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
19 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
20 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
21 ;; for more details. |
428 | 22 |
23 ;; You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5264
diff
changeset
|
24 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
428 | 25 |
1942 | 26 ;;; Synched up with: FSF 21.3. |
428 | 27 |
28 ;;; Commentary: | |
29 | |
30 ;; This file is dumped with XEmacs. | |
31 | |
32 ;;; Code: | |
33 | |
1942 | 34 ;; XEmacs addition |
428 | 35 (defgroup frames nil |
36 "Support for Emacs frames and window systems." | |
37 :group 'environment) | |
38 | |
1942 | 39 ;; XEmacs change: No need for `frame-creation-function'. |
428 | 40 |
1942 | 41 ;; XEmacs change: Emacs no longer specifies the minibuffer property here. |
428 | 42 ;;; The initial value given here for this must ask for a minibuffer. |
43 ;;; There must always exist a frame with a minibuffer, and after we | |
44 ;;; delete the terminal frame, this will be the only frame. | |
45 (defcustom initial-frame-plist '(minibuffer t) | |
46 "Plist of frame properties for creating the initial X window frame. | |
47 You can set this in your `.emacs' file; for example, | |
48 (setq initial-frame-plist '(top 1 left 1 width 80 height 55)) | |
49 Properties specified here supersede the values given in `default-frame-plist'. | |
50 The format of this can also be an alist for backward compatibility. | |
51 | |
52 If the value calls for a frame without a minibuffer, and you have not created | |
53 a minibuffer frame on your own, one is created according to | |
54 `minibuffer-frame-plist'. | |
55 | |
56 You can specify geometry-related options for just the initial frame | |
57 by setting this variable in your `.emacs' file; however, they won't | |
58 take effect until Emacs reads `.emacs', which happens after first creating | |
59 the frame. If you want the frame to have the proper geometry as soon | |
60 as it appears, you need to use this three-step process: | |
61 * Specify X resources to give the geometry you want. | |
62 * Set `default-frame-plist' to override these options so that they | |
63 don't affect subsequent frames. | |
64 * Set `initial-frame-plist' in a way that matches the X resources, | |
65 to override what you put in `default-frame-plist'." | |
66 :type 'plist | |
67 :group 'frames) | |
68 | |
69 (defcustom minibuffer-frame-plist '(width 80 height 2 menubar-visible-p nil | |
1942 | 70 default-toolbar-visible-p nil) |
428 | 71 "Plist of frame properties for initially creating a minibuffer frame. |
72 You can set this in your `.emacs' file; for example, | |
73 (setq minibuffer-frame-plist '(top 1 left 1 width 80 height 2)) | |
74 Properties specified here supersede the values given in | |
75 `default-frame-plist'. | |
76 The format of this can also be an alist for backward compatibility." | |
77 :type 'plist | |
78 :group 'frames) | |
79 | |
80 (defcustom pop-up-frame-plist nil | |
81 "Plist of frame properties used when creating pop-up frames. | |
82 Pop-up frames are used for completions, help, and the like. | |
83 This variable can be set in your init file, like this: | |
84 (setq pop-up-frame-plist '(width 80 height 20)) | |
1942 | 85 These supersede the values given in `default-frame-plist', for pop-up frames. |
428 | 86 The format of this can also be an alist for backward compatibility." |
87 :type 'plist | |
88 :group 'frames) | |
89 | |
90 (setq pop-up-frame-function | |
1942 | 91 #'(lambda () |
92 (make-frame pop-up-frame-plist))) | |
428 | 93 |
94 (defcustom special-display-frame-plist '(height 14 width 80 unsplittable t) | |
95 "*Plist of frame properties used when creating special frames. | |
96 Special frames are used for buffers whose names are in | |
97 `special-display-buffer-names' and for buffers whose names match | |
98 one of the regular expressions in `special-display-regexps'. | |
99 This variable can be set in your init file, like this: | |
100 (setq special-display-frame-plist '(width 80 height 20)) | |
101 These supersede the values given in `default-frame-plist'. | |
102 The format of this can also be an alist for backward compatibility." | |
103 :type 'plist | |
104 :group 'frames) | |
105 | |
1942 | 106 ;; XEmacs addition |
428 | 107 (defun safe-alist-to-plist (cruftiness) |
108 (if (consp (car cruftiness)) | |
109 (alist-to-plist cruftiness) | |
110 cruftiness)) | |
111 | |
1942 | 112 ;; XEmacs change: require args to be a plist instead of an alist. |
428 | 113 (defun special-display-popup-frame (buffer &optional args) |
1942 | 114 "Display BUFFER in its own frame, reusing an existing window if any. |
115 Return the window chosen. | |
116 Currently we do not insist on selecting the window within its frame. | |
117 If ARGS is a plist, use it as a list of frame property specs. | |
118 If ARGS is a list whose car is t, | |
119 use (cadr ARGS) as a function to do the work. | |
120 Pass it BUFFER as first arg, and (cddr ARGS) gives the rest of the args." | |
428 | 121 ;; if we can't display simultaneous multiple frames, just return |
122 ;; nil and let the normal behavior take over. | |
123 (and (device-on-window-system-p) | |
124 (if (and args (eq t (car args))) | |
125 (apply (cadr args) buffer (cddr args)) | |
126 (let ((window (get-buffer-window buffer t))) | |
1942 | 127 (setq args (safe-alist-to-plist args)) |
128 (or | |
129 ;; If we have a window already, make it visible. | |
130 (when window | |
131 (let ((frame (window-frame window))) | |
132 (make-frame-visible frame) | |
133 (raise-frame frame) | |
134 window)) | |
135 ;; Reuse the current window if the user requested it. | |
136 (when (lax-plist-get args 'same-window) | |
137 (condition-case nil | |
138 (progn (switch-to-buffer buffer) (selected-window)) | |
139 (error nil))) | |
140 ;; Stay on the same frame if requested. | |
141 (when (or (lax-plist-get args 'same-frame) | |
142 (lax-plist-get args 'same-window)) | |
143 (let* ((pop-up-frames nil) (pop-up-windows t) | |
144 special-display-regexps special-display-buffer-names | |
145 (window (display-buffer buffer))) | |
146 ;; (set-window-dedicated-p window t) | |
147 window)) | |
148 ;; If no window yet, make one in a new frame. | |
149 (let ((frame (make-frame (append args | |
150 (safe-alist-to-plist | |
151 special-display-frame-plist))))) | |
152 (set-window-buffer (frame-selected-window frame) buffer) | |
153 (set-window-dedicated-p (frame-selected-window frame) t) | |
154 (frame-selected-window frame))))))) | |
428 | 155 |
1942 | 156 ;; XEmacs change: comment out |
428 | 157 ;(defun handle-delete-frame (event) |
1942 | 158 ; "Handle delete-frame events from the X server." |
428 | 159 ; (interactive "e") |
160 ; (let ((frame (posn-window (event-start event))) | |
161 ; (i 0) | |
162 ; (tail (frame-list))) | |
163 ; (while tail | |
164 ; (and (frame-visible-p (car tail)) | |
165 ; (not (eq (car tail) frame)) | |
166 ; (setq i (1+ i))) | |
167 ; (setq tail (cdr tail))) | |
168 ; (if (> i 0) | |
169 ; (delete-frame frame t) | |
1942 | 170 ; ;; Gildea@x.org says it is ok to ask questions before terminating. |
171 ; (save-buffers-kill-emacs)))) | |
428 | 172 |
173 ;;;; Arrangement of frames at startup | |
174 | |
1942 | 175 ;; 1) Load the window system startup file from the lisp library and read the |
176 ;; high-priority arguments (-q and the like). The window system startup | |
177 ;; file should create any frames specified in the window system defaults. | |
178 ;; | |
179 ;; 2) If no frames have been opened, we open an initial text frame. | |
180 ;; | |
181 ;; 3) Once the init file is done, we apply any newly set properties | |
182 ;; in initial-frame-plist to the frame. | |
428 | 183 |
1942 | 184 ;; These are now called explicitly at the proper times, |
185 ;; since that is easier to understand. | |
186 ;; Actually using hooks within Emacs is bad for future maintenance. --rms. | |
187 ;; (add-hook 'before-init-hook 'frame-initialize) | |
188 ;; (add-hook 'window-setup-hook 'frame-notice-user-settings) | |
189 | |
190 ;; If we create the initial frame, this is it. | |
428 | 191 (defvar frame-initial-frame nil) |
192 | |
193 ;; Record the properties used in frame-initialize to make the initial frame. | |
194 (defvar frame-initial-frame-plist) | |
195 | |
196 (defvar frame-initial-geometry-arguments nil) | |
197 | |
1942 | 198 ;; XEmacs addition |
428 | 199 (defun canonicalize-frame-plists () |
200 (setq initial-frame-plist (safe-alist-to-plist initial-frame-plist)) | |
201 (setq default-frame-plist (safe-alist-to-plist default-frame-plist))) | |
202 | |
1942 | 203 ;; startup.el calls this function before loading the user's init |
204 ;; file - if there is no frame with a minibuffer open now, create | |
205 ;; one to display messages while loading the init file. | |
428 | 206 (defun frame-initialize () |
1942 | 207 "Create an initial frame if necessary." |
428 | 208 ;; In batch mode, we actually use the initial terminal device for output. |
1942 | 209 ;; XEmacs addition |
428 | 210 (canonicalize-frame-plists) |
1942 | 211 |
428 | 212 (if (not (noninteractive)) |
213 (progn | |
1942 | 214 ;; Turn on special-display processing only if there's a window system. |
215 (setq special-display-function 'special-display-popup-frame) | |
428 | 216 |
217 ;; If there is no frame with a minibuffer besides the terminal | |
218 ;; frame, then we need to create the opening frame. Make sure | |
219 ;; it has a minibuffer, but let initial-frame-plist omit the | |
220 ;; minibuffer spec. | |
5652
cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents:
5526
diff
changeset
|
221 (or (delete* terminal-frame (minibuffer-frame-list)) |
428 | 222 (progn |
223 (setq frame-initial-frame-plist | |
224 (append initial-frame-plist default-frame-plist)) | |
1942 | 225 ;; XEmacs change: omit the scrollbar settings |
226 ; (or (assq 'horizontal-scroll-bars frame-initial-frame-alist) | |
227 ; (setq frame-initial-frame-alist | |
228 ; (cons '(horizontal-scroll-bars . t) | |
229 ; frame-initial-frame-alist))) | |
428 | 230 (setq default-minibuffer-frame |
231 (setq frame-initial-frame | |
232 (make-frame initial-frame-plist | |
5652
cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents:
5526
diff
changeset
|
233 (car (delete* terminal-device |
cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents:
5526
diff
changeset
|
234 (device-list)))))) |
428 | 235 ;; Delete any specifications for window geometry properties |
236 ;; so that we won't reapply them in frame-notice-user-settings. | |
237 ;; It would be wrong to reapply them then, | |
238 ;; because that would override explicit user resizing. | |
239 (setq initial-frame-plist | |
240 (frame-remove-geometry-props initial-frame-plist)))) | |
241 ;; At this point, we know that we have a frame open, so we | |
1942 | 242 ;; can delete the terminal frame. |
243 ;; XEmacs change: Do it the same way Fkill_emacs does it. -slb | |
428 | 244 (delete-console terminal-console) |
1942 | 245 (setq terminal-frame nil)) |
428 | 246 |
1942 | 247 ;; XEmacs change: omit the pc window-system stuff. |
248 ; ;; No, we're not running a window system. Use make-terminal-frame if | |
249 ; ;; we support that feature, otherwise arrange to cause errors. | |
250 ; (or (eq window-system 'pc) | |
251 ; (setq frame-creation-function | |
252 ; (if (fboundp 'tty-create-frame-with-faces) | |
253 ; 'tty-create-frame-with-faces | |
254 ; (function | |
255 ; (lambda (parameters) | |
256 ; (error | |
257 ; "Can't create multiple frames without a window system")))))) | |
258 )) | |
259 | |
260 (defvar frame-notice-user-settings t | |
261 "Non-nil means function `frame-notice-user-settings' wasn't run yet.") | |
428 | 262 |
1942 | 263 ;; startup.el calls this function after loading the user's init |
264 ;; file. Now default-frame-plist and initial-frame-plist contain | |
265 ;; information to which we must react; do what needs to be done. | |
428 | 266 (defun frame-notice-user-settings () |
1942 | 267 "Act on user's init file settings of frame parameters. |
268 React to settings of `default-frame-plist', `initial-frame-plist' there." | |
269 ;; XEmacs addition | |
270 (canonicalize-frame-plists) | |
428 | 271 |
1942 | 272 ;; XEmacs change: omit menu-bar manipulations. |
273 ; ;; Make menu-bar-mode and default-frame-alist consistent. | |
274 ; (when (boundp 'menu-bar-mode) | |
275 ; (let ((default (assq 'menu-bar-lines default-frame-alist))) | |
276 ; (if default | |
277 ; (setq menu-bar-mode (not (eq (cdr default) 0))) | |
278 ; (setq default-frame-alist | |
279 ; (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0)) | |
280 ; default-frame-alist))))) | |
428 | 281 |
1942 | 282 ;; XEmacs change: omit tool-bar manipulations. |
283 ; ;; Make tool-bar-mode and default-frame-alist consistent. Don't do | |
284 ; ;; it in batch mode since that would leave a tool-bar-lines | |
285 ; ;; parameter in default-frame-alist in a dumped Emacs, which is not | |
286 ; ;; what we want. | |
287 ; (when (and (boundp 'tool-bar-mode) | |
288 ; (not noninteractive)) | |
289 ; (let ((default (assq 'tool-bar-lines default-frame-alist))) | |
290 ; (if default | |
291 ; (setq tool-bar-mode (not (eq (cdr default) 0))) | |
292 ; (setq default-frame-alist | |
293 ; (cons (cons 'tool-bar-lines (if tool-bar-mode 1 0)) | |
294 ; default-frame-alist))))) | |
428 | 295 |
296 ;; Creating and deleting frames may shift the selected frame around, | |
297 ;; and thus the current buffer. Protect against that. We don't | |
298 ;; want to use save-excursion here, because that may also try to set | |
299 ;; the buffer of the selected window, which fails when the selected | |
300 ;; window is the minibuffer. | |
301 (let ((old-buffer (current-buffer))) | |
302 | |
1942 | 303 ;; XEmacs change: omit special handling for MS-DOS |
304 ; (when (and frame-notice-user-settings | |
305 ; (null frame-initial-frame)) | |
306 ; ;; This case happens when we don't have a window system, and | |
307 ; ;; also for MS-DOS frames. | |
308 ; (let ((parms (frame-parameters frame-initial-frame))) | |
309 ; ;; Don't change the frame names. | |
310 ; (setq parms (delq (assq 'name parms) parms)) | |
311 ; ;; Can't modify the minibuffer parameter, so don't try. | |
312 ; (setq parms (delq (assq 'minibuffer parms) parms)) | |
313 ; (modify-frame-parameters nil | |
314 ; (if (null window-system) | |
315 ; (append initial-frame-alist | |
316 ; default-frame-alist | |
317 ; parms | |
318 ; nil) | |
319 ; ;; initial-frame-alist and | |
320 ; ;; default-frame-alist were already | |
321 ; ;; applied in pc-win.el. | |
322 ; parms)) | |
323 ; (if (null window-system) ;; MS-DOS does this differently in pc-win.el | |
324 ; (let ((newparms (frame-parameters)) | |
325 ; (frame (selected-frame))) | |
326 ; (tty-handle-reverse-video frame newparms) | |
327 ; ;; If we changed the background color, we need to update | |
328 ; ;; the background-mode parameter, and maybe some faces, | |
329 ; ;; too. | |
330 ; (when (assq 'background-color newparms) | |
331 ; (unless (or (assq 'background-mode initial-frame-alist) | |
332 ; (assq 'background-mode default-frame-alist)) | |
333 ; (frame-set-background-mode frame)) | |
334 ; (face-set-after-frame-default frame)))))) | |
335 | |
428 | 336 ;; If the initial frame is still around, apply initial-frame-plist |
337 ;; and default-frame-plist to it. | |
1942 | 338 (when (frame-live-p frame-initial-frame) |
339 | |
340 ;; XEmacs change: omit the tool-bar manipulations | |
341 ; ;; When tool-bar has been switched off, correct the frame size | |
342 ; ;; by the lines added in x-create-frame for the tool-bar and | |
343 ; ;; switch `tool-bar-mode' off. | |
344 ; (when (display-graphic-p) | |
345 ; (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist) | |
346 ; (assq 'tool-bar-lines default-frame-alist)))) | |
347 ; (when (and tool-bar-originally-present | |
348 ; (or (null tool-bar-lines) | |
349 ; (null (cdr tool-bar-lines)) | |
350 ; (eq 0 (cdr tool-bar-lines)))) | |
351 ; (let* ((char-height (frame-char-height frame-initial-frame)) | |
352 ; (image-height tool-bar-images-pixel-height) | |
353 ; (margin (cond ((and (consp tool-bar-button-margin) | |
354 ; (integerp (cdr tool-bar-button-margin)) | |
355 ; (> tool-bar-button-margin 0)) | |
356 ; (cdr tool-bar-button-margin)) | |
357 ; ((and (integerp tool-bar-button-margin) | |
358 ; (> tool-bar-button-margin 0)) | |
359 ; tool-bar-button-margin) | |
360 ; (t 0))) | |
361 ; (relief (if (and (integerp tool-bar-button-relief) | |
362 ; (> tool-bar-button-relief 0)) | |
363 ; tool-bar-button-relief 3)) | |
364 ; (lines (/ (+ image-height | |
365 ; (* 2 margin) | |
366 ; (* 2 relief) | |
367 ; (1- char-height)) | |
368 ; char-height)) | |
369 ; (height (frame-parameter frame-initial-frame 'height)) | |
370 ; (newparms (list (cons 'height (- height lines)))) | |
371 ; (initial-top (cdr (assq 'top | |
372 ; frame-initial-geometry-arguments))) | |
373 ; (top (frame-parameter frame-initial-frame 'top))) | |
374 ; (when (and (consp initial-top) (eq '- (car initial-top))) | |
375 ; (let ((adjusted-top | |
376 ; (cond ((and (consp top) | |
377 ; (eq '+ (car top))) | |
378 ; (list '+ | |
379 ; (+ (cadr top) | |
380 ; (* lines char-height)))) | |
381 ; ((and (consp top) | |
382 ; (eq '- (car top))) | |
383 ; (list '- | |
384 ; (- (cadr top) | |
385 ; (* lines char-height)))) | |
386 ; (t (+ top (* lines char-height)))))) | |
387 ; (setq newparms | |
388 ; (append newparms | |
389 ; `((top . ,adjusted-top)) | |
390 ; nil)))) | |
391 ; (modify-frame-parameters frame-initial-frame newparms) | |
392 ; (tool-bar-mode -1))))) | |
428 | 393 |
394 ;; The initial frame we create above always has a minibuffer. | |
395 ;; If the user wants to remove it, or make it a minibuffer-only | |
396 ;; frame, then we'll have to delete the selected frame and make a | |
397 ;; new one; you can't remove or add a root window to/from an | |
398 ;; existing frame. | |
399 ;; | |
400 ;; NOTE: default-frame-plist was nil when we created the | |
401 ;; existing frame. We need to explicitly include | |
402 ;; default-frame-plist in the properties of the screen we | |
403 ;; create here, so that its new value, gleaned from the user's | |
404 ;; .emacs file, will be applied to the existing screen. | |
405 (if (not (eq (car | |
406 (or (and (lax-plist-member | |
407 initial-frame-plist 'minibuffer) | |
408 (list (lax-plist-get initial-frame-plist | |
409 'minibuffer))) | |
410 (and (lax-plist-member default-frame-plist | |
411 'minibuffer) | |
412 (list (lax-plist-get default-frame-plist | |
413 'minibuffer))) | |
414 '(t))) | |
415 t)) | |
416 ;; Create the new frame. | |
2367 | 417 (let (props ;new |
418 ) | |
428 | 419 ;; If the frame isn't visible yet, wait till it is. |
420 ;; If the user has to position the window, | |
421 ;; Emacs doesn't know its real position until | |
422 ;; the frame is seen to be visible. | |
423 | |
1942 | 424 ;; XEmacs change: check the initially-unmapped property |
428 | 425 (if (frame-property frame-initial-frame 'initially-unmapped) |
426 nil | |
427 (while (not (frame-visible-p frame-initial-frame)) | |
428 (sleep-for 1))) | |
429 (setq props (frame-properties frame-initial-frame)) | |
1942 | 430 |
428 | 431 ;; Get rid of `name' unless it was specified explicitly before. |
432 (or (lax-plist-member frame-initial-frame-plist 'name) | |
433 (setq props (lax-plist-remprop props 'name))) | |
1942 | 434 |
435 (setq props (append initial-frame-plist | |
436 default-frame-plist | |
428 | 437 props |
438 nil)) | |
1942 | 439 |
428 | 440 ;; Get rid of `reverse', because that was handled |
441 ;; when we first made the frame. | |
442 (laxputf props 'reverse nil) | |
1942 | 443 |
444 ;; XEmacs addition: Get rid of `window-id', otherwise make-frame | |
445 ;; will think we're trying to setup an external widget. | |
428 | 446 (laxremf props 'window-id) |
1942 | 447 |
428 | 448 (if (lax-plist-member frame-initial-geometry-arguments 'height) |
449 (laxremf props 'height)) | |
450 (if (lax-plist-member frame-initial-geometry-arguments 'width) | |
451 (laxremf props 'width)) | |
452 (if (lax-plist-member frame-initial-geometry-arguments 'left) | |
453 (laxremf props 'left)) | |
454 (if (lax-plist-member frame-initial-geometry-arguments 'top) | |
455 (laxremf props 'top)) | |
456 ;; Now create the replacement initial frame. | |
2367 | 457 ;(setq new |
458 (make-frame | |
459 ;; Use the geometry args that created the existing | |
460 ;; frame, rather than the props we get for it. | |
461 (append '(user-size t user-position t) | |
462 frame-initial-geometry-arguments | |
463 props)) | |
464 ;) | |
428 | 465 ;; The initial frame, which we are about to delete, may be |
466 ;; the only frame with a minibuffer. If it is, create a | |
467 ;; new one. | |
5652
cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents:
5526
diff
changeset
|
468 (or (delete* frame-initial-frame (minibuffer-frame-list)) |
428 | 469 (make-initial-minibuffer-frame nil)) |
470 | |
471 ;; If the initial frame is serving as a surrogate | |
472 ;; minibuffer frame for any frames, we need to wean them | |
473 ;; onto a new frame. The default-minibuffer-frame | |
474 ;; variable must be handled similarly. | |
475 (let ((users-of-initial | |
5367
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
476 (remove-if-not |
428 | 477 #'(lambda (frame) |
478 (and (not (eq frame frame-initial-frame)) | |
479 (eq (window-frame | |
480 (minibuffer-window frame)) | |
5367
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
481 frame-initial-frame))) |
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
482 (frame-list)))) |
428 | 483 (if (or users-of-initial |
484 (eq default-minibuffer-frame frame-initial-frame)) | |
485 | |
486 ;; Choose an appropriate frame. Prefer frames which | |
487 ;; are only minibuffers. | |
488 (let* ((new-surrogate | |
489 (car | |
5367
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
490 (or (remove-if-not |
428 | 491 #'(lambda (frame) |
492 (eq 'only | |
5367
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
493 (frame-property frame 'minibuffer))) |
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
494 (frame-list)) |
428 | 495 (minibuffer-frame-list)))) |
496 (new-minibuffer (minibuffer-window new-surrogate))) | |
497 | |
498 (if (eq default-minibuffer-frame frame-initial-frame) | |
499 (setq default-minibuffer-frame new-surrogate)) | |
500 | |
501 ;; Wean the frames using frame-initial-frame as | |
502 ;; their minibuffer frame. | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4759
diff
changeset
|
503 (mapc |
1942 | 504 #'(lambda (frame) |
505 (set-frame-property frame 'minibuffer | |
506 new-minibuffer)) | |
507 users-of-initial)))) | |
428 | 508 |
509 ;; Redirect events enqueued at this frame to the new frame. | |
510 ;; Is this a good idea? | |
511 ;; Probably not, since this whole redirect-frame-focus | |
512 ;; stuff is a load of trash, and so is this function we're in. | |
513 ;; --ben | |
514 ;(redirect-frame-focus frame-initial-frame new) | |
515 | |
516 ;; Finally, get rid of the old frame. | |
517 (delete-frame frame-initial-frame t)) | |
518 | |
519 ;; Otherwise, we don't need all that rigamarole; just apply | |
520 ;; the new properties. | |
521 (let (newprops allprops tail) | |
522 (setq allprops (append initial-frame-plist | |
523 default-frame-plist)) | |
524 (if (lax-plist-member frame-initial-geometry-arguments 'height) | |
525 (laxremf allprops 'height)) | |
526 (if (lax-plist-member frame-initial-geometry-arguments 'width) | |
527 (remf allprops 'width)) | |
528 (if (lax-plist-member frame-initial-geometry-arguments 'left) | |
529 (laxremf allprops 'left)) | |
530 (if (lax-plist-member frame-initial-geometry-arguments 'top) | |
531 (laxremf allprops 'top)) | |
532 (setq tail allprops) | |
533 ;; Find just the props that have changed since we first | |
534 ;; made this frame. Those are the ones actually set by | |
535 ;; the init file. For those props whose values we already knew | |
536 ;; (such as those spec'd by command line options) | |
537 ;; it is undesirable to specify the parm again | |
538 ;; once the user has seen the frame and been able to alter it | |
539 ;; manually. | |
540 (while tail | |
541 (let (newval oldval) | |
542 (setq oldval (lax-plist-get frame-initial-frame-plist | |
543 (car tail))) | |
544 (setq newval (lax-plist-get allprops (car tail))) | |
545 (or (eq oldval newval) | |
546 (laxputf newprops (car tail) newval))) | |
547 (setq tail (cddr tail))) | |
548 (set-frame-properties frame-initial-frame newprops) | |
1942 | 549 ;; XEmacs change: omit the background manipulation |
550 ; ;; If we changed the background color, | |
551 ; ;; we need to update the background-mode parameter | |
552 ; ;; and maybe some faces too. | |
553 ; (when (assq 'background-color newparms) | |
554 ; (unless (assq 'background-mode newparms) | |
555 ; (frame-set-background-mode frame-initial-frame)) | |
556 ; (face-set-after-frame-default frame-initial-frame))))) | |
428 | 557 ))) |
558 | |
559 ;; Restore the original buffer. | |
560 (set-buffer old-buffer) | |
561 | |
562 ;; Make sure the initial frame can be GC'd if it is ever deleted. | |
563 ;; Make sure frame-notice-user-settings does nothing if called twice. | |
1942 | 564 (setq frame-notice-user-settings nil) |
428 | 565 (setq frame-initial-frame nil))) |
566 | |
567 (defun make-initial-minibuffer-frame (device) | |
568 (let ((props (append '(minibuffer only) | |
569 (safe-alist-to-plist minibuffer-frame-plist)))) | |
570 (make-frame props device))) | |
571 | |
572 | |
573 ;;;; Creation of additional frames, and other frame miscellanea | |
574 | |
1942 | 575 (defun modify-all-frames-properties (plist) |
576 "Modify all current and future frames' parameters according to PLIST. | |
577 This changes `default-frame-plist' and possibly `initial-frame-plist'. | |
578 See `set-frame-properties' for more information." | |
579 (dolist (frame (frame-list)) | |
580 (set-frame-properties frame plist)) | |
581 | |
582 ;; XEmacs change: iterate over plists instead of alists | |
583 (map-plist | |
584 #'(lambda (prop val) | |
585 ;; initial-frame-plist needs setting only when | |
586 ;; frame-notice-user-settings is true | |
587 (and frame-notice-user-settings | |
588 (lax-plist-remprop initial-frame-plist prop)) | |
589 (lax-plist-remprop default-frame-plist prop)) | |
590 plist) | |
591 | |
592 (and frame-notice-user-settings | |
593 (setq initial-frame-plist (append initial-frame-plist plist))) | |
594 (setq default-frame-plist (append default-frame-plist plist))) | |
595 | |
428 | 596 (defun get-other-frame () |
1942 | 597 "Return some frame other than the current frame. |
598 Create one if necessary. Note that the minibuffer frame, if separate, | |
599 is not considered (see `next-frame')." | |
428 | 600 (let* ((this (selected-frame)) |
601 ;; search visible frames first | |
602 (next (next-frame this 'visible-nomini))) | |
603 ;; then search iconified frames | |
604 (if (eq this next) | |
5526
9a046b2e6494
Fix get-other-frame bug.
Didier Verna <didier@lrde.epita.fr>
parents:
5473
diff
changeset
|
605 (setq next (next-frame this 'visible-iconic-nomini))) |
428 | 606 (if (eq this next) |
607 ;; otherwise, make a new frame | |
608 (make-frame) | |
609 next))) | |
610 | |
611 (defun next-multiframe-window () | |
612 "Select the next window, regardless of which frame it is on." | |
613 (interactive) | |
614 (select-window (next-window (selected-window) | |
615 (> (minibuffer-depth) 0) | |
1942 | 616 t)) |
617 ;; XEmacs change: select-window already selects the containing frame | |
618 ;(select-frame-set-input-focus (selected-frame)) | |
619 ) | |
428 | 620 |
621 (defun previous-multiframe-window () | |
622 "Select the previous window, regardless of which frame it is on." | |
623 (interactive) | |
624 (select-window (previous-window (selected-window) | |
625 (> (minibuffer-depth) 0) | |
1942 | 626 t)) |
627 ;; XEmacs change: select-window already selects the containing frame | |
628 ;(select-frame-set-input-focus (selected-frame)) | |
629 ) | |
428 | 630 |
1942 | 631 ;; XEmacs change: Emacs has make-frame-on-display |
428 | 632 (defun make-frame-on-device (type connection &optional props) |
633 "Create a frame of type TYPE on CONNECTION. | |
634 TYPE should be a symbol naming the device type, i.e. one of | |
635 | |
636 x An X display. CONNECTION should be a standard display string | |
637 such as \"unix:0\", or nil for the display specified on the | |
638 command line or in the DISPLAY environment variable. Only if | |
639 support for X was compiled into XEmacs. | |
640 tty A standard TTY connection or terminal. CONNECTION should be | |
641 a TTY device name such as \"/dev/ttyp2\" (as determined by | |
642 the Unix command `tty') or nil for XEmacs' standard input | |
643 and output (usually the TTY in which XEmacs started). Only | |
644 if support for TTY's was compiled into XEmacs. | |
462 | 645 gtk A GTK device. |
428 | 646 mswindows A connection to a machine running Microsoft Windows NT or |
647 Windows 95/97. | |
648 pc A direct-write MS-DOS frame. Not currently implemented. | |
649 | |
650 PROPS should be a plist of properties, as in the call to `make-frame'. | |
651 | |
652 If a connection to CONNECTION already exists, it is reused; otherwise, | |
653 a new connection is opened." | |
654 (make-frame props (make-device type connection props))) | |
655 | |
1942 | 656 ;; XEmacs omission: Emacs has make-frame-command here, but it reduces to |
657 ;; make-frame for us. | |
658 | |
659 ;; XEmacs omission: the following 2 variables are not yet implemented. | |
660 ;(defvar before-make-frame-hook nil | |
661 ; "Functions to run before a frame is created.") | |
662 ; | |
663 ;(defvar after-make-frame-functions nil | |
664 ; "Functions to run after a frame is created. | |
665 ;The functions are run with one arg, the newly created frame.") | |
666 ; | |
667 (defvar after-setting-font-hook nil | |
668 "Functions to run after a frame's font has been changed.") | |
669 | |
428 | 670 ;; Alias, kept temporarily. |
671 (defalias 'new-frame 'make-frame) | |
1942 | 672 (make-obsolete 'new-frame 'make-frame) |
428 | 673 |
1942 | 674 ;; XEmacs change: Emacs has make-frame here. We have it in C, so no need for |
675 ;; frame-creation-function. | |
428 | 676 |
5367
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
677 ;; XEmacs addition: support optional DEVICE argument, use delete-if-not. |
428 | 678 (defun filtered-frame-list (predicate &optional device) |
679 "Return a list of all live frames which satisfy PREDICATE. | |
680 If optional second arg DEVICE is non-nil, restrict the frames | |
681 returned to that device." | |
5367
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
682 (delete-if-not predicate |
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
683 (if device (device-frame-list device) (frame-list)))) |
428 | 684 |
1942 | 685 ;; XEmacs addition: support optional DEVICE argument. |
428 | 686 (defun minibuffer-frame-list (&optional device) |
687 "Return a list of all frames with their own minibuffers. | |
688 If optional second arg DEVICE is non-nil, restrict the frames | |
689 returned to that device." | |
5367
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
690 (delete-if-not |
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
691 #'(lambda (frame) (eq frame (window-frame (minibuffer-window frame)))) |
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
692 (if device (device-frame-list device) (frame-list)))) |
428 | 693 |
1942 | 694 ;; XEmacs omission: Emacs has frames-on-display-list here, but that is |
695 ;; essentially equivalent to supplying the optional DEVICE argument to | |
696 ;; filtered-frame-list. | |
697 | |
698 ;; XEmacs addition: the following two functions make life a lot simpler below. | |
699 (defsubst display-frame (display) | |
700 "Return the active frame for DISPLAY. | |
701 DISPLAY may be a frame, a device, or a console. If it is omitted or nil, | |
702 it defaults to the selected frame." | |
703 (cond | |
704 ((null display) (selected-frame)) | |
705 ((framep display) display) | |
706 ((devicep display) (selected-frame display)) | |
707 ((consolep display) (selected-frame (car (console-device-list display)))) | |
708 (t (error 'wrong-type-argument "Not a frame, device, or console" display)))) | |
709 | |
710 (defsubst display-device (display) | |
711 "Return the device for DISPLAY. | |
712 DISPLAY may be a frame, a device, or a console. If it is omitted or nil, | |
713 it defaults to the selected frame." | |
714 (cond | |
715 ((null display) (selected-device)) | |
716 ((framep display) (frame-device display)) | |
717 ((devicep display) display) | |
718 ((consolep display) (car (console-device-list display))) | |
719 (t (error 'wrong-type-argument "Not a frame, device, or console" display)))) | |
720 | |
721 ;; Emacs compatibility function. We do not allow display names of the type | |
722 ;; HOST:SERVER.SCREEN as Emacs does, but we do handle devices and consoles. | |
723 (defun framep-on-display (&optional display) | |
724 "Return the type of frames on DISPLAY. | |
725 DISPLAY may be a frame, a device, or a console. If it is a frame, its type | |
726 is returned. If DISPLAY is omitted or nil, it defaults to the selected | |
727 frame. All frames on a given device or console are of the same type." | |
728 (cond | |
729 ((null display) (frame-type (selected-frame))) | |
730 ((framep display) (frame-type display)) | |
731 ((devicep display) (device-type display)) | |
732 ((consolep display) (console-type display)) | |
733 (t (error 'wrong-type-argument "Not a frame, device, or console" display)))) | |
734 | |
735 ;; XEmacs addition: Emacs does not have this function. | |
428 | 736 (defun frame-minibuffer-only-p (frame) |
737 "Return non-nil if FRAME is a minibuffer-only frame." | |
738 (eq (frame-root-window frame) (minibuffer-window frame))) | |
739 | |
740 (defun frame-remove-geometry-props (plist) | |
741 "Return the property list PLIST, but with geometry specs removed. | |
742 This deletes all bindings in PLIST for `top', `left', `width', | |
743 `height', `user-size' and `user-position' properties. | |
744 Emacs uses this to avoid overriding explicit moves and resizings from | |
745 the user during startup." | |
746 (setq plist (canonicalize-lax-plist (copy-sequence plist))) | |
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4759
diff
changeset
|
747 (mapc #'(lambda (property) |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4759
diff
changeset
|
748 (if (lax-plist-member plist property) |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4759
diff
changeset
|
749 (progn |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4759
diff
changeset
|
750 (setq frame-initial-geometry-arguments |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4759
diff
changeset
|
751 (cons property |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4759
diff
changeset
|
752 (cons (lax-plist-get plist property) |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4759
diff
changeset
|
753 frame-initial-geometry-arguments))) |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4759
diff
changeset
|
754 (setq plist (lax-plist-remprop plist property))))) |
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4759
diff
changeset
|
755 '(height width top left user-size user-position)) |
428 | 756 plist) |
757 | |
1942 | 758 ;; XEmacs change: Emacs has focus-follows-mouse here, which lets them |
759 ;; Customize it. XEmacs has it builtin. Should that change? | |
760 | |
761 ;; XEmacs change: we have focus-frame instead of multiple foo-focus-frame | |
762 ;; functions. | |
763 (defun select-frame-set-input-focus (frame) | |
764 "Select FRAME, raise it, and set input focus, if possible." | |
765 (raise-frame frame) | |
766 (focus-frame frame) ;; This also selects FRAME | |
767 ;; XEmacs change: This is a bad idea; you should in general never warp the | |
768 ;; pointer unless the user asks for it. | |
769 ;;(if focus-follows-mouse | |
770 ;; (set-mouse-position (selected-window) (1- (frame-width frame)) 0))) | |
771 ) | |
772 | |
428 | 773 (defun other-frame (arg) |
774 "Select the ARG'th different visible frame, and raise it. | |
775 All frames are arranged in a cyclic order. | |
776 This command selects the frame ARG steps away in that order. | |
777 A negative ARG moves in the opposite order. | |
778 | |
1942 | 779 To make this command work properly, you must tell Emacs |
780 how the system (or the window manager) generally handles | |
781 focus-switching between windows. If moving the mouse onto a window | |
782 selects it (gives it focus), set `focus-follows-mouse' to t. | |
783 Otherwise, that variable should be nil." | |
428 | 784 (interactive "p") |
785 (let ((frame (selected-frame))) | |
786 (while (> arg 0) | |
787 (setq frame (next-frame frame 'visible-nomini)) | |
788 (setq arg (1- arg))) | |
789 (while (< arg 0) | |
790 (setq frame (previous-frame frame 'visible-nomini)) | |
791 (setq arg (1+ arg))) | |
1942 | 792 (select-frame-set-input-focus frame))) |
793 | |
794 (defun iconify-or-deiconify-frame () | |
795 "Iconify the selected frame, or deiconify if it's currently an icon." | |
796 (interactive) | |
797 (if (lax-plist-get (frame-properties) 'visibility) | |
798 (iconify-frame) | |
799 (make-frame-visible))) | |
800 | |
801 (defun make-frame-names-alist () | |
802 (let* ((current-frame (selected-frame)) | |
803 (falist | |
804 (cons | |
805 (cons (frame-property current-frame 'name) current-frame) nil)) | |
806 (frame (next-frame current-frame t))) | |
807 (while (not (eq frame current-frame)) | |
808 (progn | |
809 (setq falist (cons (cons (frame-property frame 'name) frame) falist)) | |
810 (setq frame (next-frame frame t)))) | |
811 falist)) | |
812 | |
813 (defvar frame-name-history nil) | |
814 (defun select-frame-by-name (name) | |
815 "Select the frame on the current terminal whose name is NAME and raise it. | |
816 If there is no frame by that name, signal an error." | |
817 (interactive | |
818 (let* ((frame-names-alist (make-frame-names-alist)) | |
819 (default (car (car frame-names-alist))) | |
820 (input (completing-read | |
821 (format "Select Frame (default %s): " default) | |
822 frame-names-alist nil t nil 'frame-name-history default))) | |
823 ;; XEmacs change: use the last param of completing-read to simplify. | |
824 (list input))) | |
825 (let* ((frame-names-alist (make-frame-names-alist)) | |
826 (frame (cdr (assoc name frame-names-alist)))) | |
827 (or frame | |
828 (error "There is no frame named `%s'" name)) | |
829 (make-frame-visible frame) | |
830 ;; XEmacs change: make-frame-visible implies (raise-frame) | |
831 ;; (raise-frame frame) | |
832 ;; XEmacs change: we defined this function, might as well use it. | |
833 (select-frame-set-input-focus frame))) | |
428 | 834 |
835 ;; XEmacs-added utility functions | |
836 | |
837 (defmacro save-selected-frame (&rest body) | |
838 "Execute forms in BODY, then restore the selected frame. | |
839 The value returned is the value of the last form in BODY." | |
840 (let ((old-frame (gensym "ssf"))) | |
841 `(let ((,old-frame (selected-frame))) | |
842 (unwind-protect | |
843 (progn ,@body) | |
844 (select-frame ,old-frame))))) | |
845 | |
846 (defmacro with-selected-frame (frame &rest body) | |
847 "Execute forms in BODY with FRAME as the selected frame. | |
848 The value returned is the value of the last form in BODY." | |
849 `(save-selected-frame | |
850 (select-frame ,frame) | |
851 ,@body)) | |
852 | |
1942 | 853 ; This is in C in Emacs |
428 | 854 (defun frame-list () |
855 "Return a list of all frames on all devices/consoles." | |
856 ;; Lists are copies, so nconc is safe here. | |
5264
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5080
diff
changeset
|
857 (mapcan #'device-frame-list (device-list))) |
428 | 858 |
859 (defun frame-type (&optional frame) | |
860 "Return the type of the specified frame (e.g. `x' or `tty'). | |
861 This is equivalent to the type of the frame's device. | |
862 Value is `tty' for a tty frame (a character-only terminal), | |
863 `x' for a frame that is an X window, | |
440 | 864 `mswindows' for a frame that is a MS Windows desktop window, |
865 `msprinter' for a frame that is a MS Windows print job, | |
428 | 866 `stream' for a stream frame (which acts like a stdio stream), and |
867 `dead' for a deleted frame." | |
868 (or frame (setq frame (selected-frame))) | |
869 (if (not (frame-live-p frame)) 'dead | |
870 (device-type (frame-device frame)))) | |
871 | |
872 (defun device-or-frame-p (object) | |
873 "Return non-nil if OBJECT is a device or frame." | |
874 (or (devicep object) | |
875 (framep object))) | |
876 | |
877 (defun device-or-frame-type (device-or-frame) | |
878 "Return the type (e.g. `x' or `tty') of DEVICE-OR-FRAME. | |
879 DEVICE-OR-FRAME should be a device or a frame object. See `device-type' | |
880 for a description of the possible types." | |
881 (if (devicep device-or-frame) | |
882 (device-type device-or-frame) | |
883 (frame-type device-or-frame))) | |
884 | |
885 (defun fw-frame (obj) | |
886 "Given a frame or window, return the associated frame. | |
887 Return nil otherwise." | |
888 (cond ((windowp obj) (window-frame obj)) | |
889 ((framep obj) obj) | |
890 (t nil))) | |
891 | |
892 | |
893 ;;;; Frame configurations | |
894 | |
895 (defun current-frame-configuration () | |
896 "Return a list describing the positions and states of all frames. | |
897 Its car is `frame-configuration'. | |
898 Each element of the cdr is a list of the form (FRAME PLIST WINDOW-CONFIG), | |
899 where | |
900 FRAME is a frame object, | |
901 PLIST is a property list specifying some of FRAME's properties, and | |
902 WINDOW-CONFIG is a window configuration object for FRAME." | |
903 (cons 'frame-configuration | |
904 (mapcar (function | |
905 (lambda (frame) | |
906 (list frame | |
907 (frame-properties frame) | |
908 (current-window-configuration frame)))) | |
909 (frame-list)))) | |
910 | |
911 (defun set-frame-configuration (configuration &optional nodelete) | |
912 "Restore the frames to the state described by CONFIGURATION. | |
913 Each frame listed in CONFIGURATION has its position, size, window | |
914 configuration, and other properties set as specified in CONFIGURATION. | |
915 Ordinarily, this function deletes all existing frames not | |
916 listed in CONFIGURATION. But if optional second argument NODELETE | |
917 is given and non-nil, the unwanted frames are iconified instead." | |
918 (or (frame-configuration-p configuration) | |
919 (signal 'wrong-type-argument | |
920 (list 'frame-configuration-p configuration))) | |
1942 | 921 (let ((config-alist (cdr configuration)) |
428 | 922 frames-to-delete) |
1942 | 923 (mapc #'(lambda (frame) |
924 (let ((properties (assq frame config-alist))) | |
925 (if properties | |
926 (progn | |
927 (set-frame-properties | |
928 frame | |
929 ;; Since we can't set a frame's minibuffer status, | |
930 ;; we might as well omit the parameter altogether. | |
931 (lax-plist-remprop (nth 1 properties) 'minibuffer)) | |
932 (set-window-configuration (nth 2 properties))) | |
933 (setq frames-to-delete (cons frame frames-to-delete))))) | |
428 | 934 (frame-list)) |
935 (if nodelete | |
936 ;; Note: making frames invisible here was tried | |
937 ;; but led to some strange behavior--each time the frame | |
938 ;; was made visible again, the window manager asked afresh | |
939 ;; for where to put it. | |
1942 | 940 (mapc #'iconify-frame frames-to-delete) |
941 (mapc #'delete-frame frames-to-delete)))) | |
428 | 942 |
1942 | 943 ; XEmacs change: this function is in subr.el in Emacs. |
944 ; That's because they don't always include frame.el, while we do. | |
428 | 945 |
946 (defun frame-configuration-p (object) | |
947 "Return non-nil if OBJECT seems to be a frame configuration. | |
948 Any list whose car is `frame-configuration' is assumed to be a frame | |
949 configuration." | |
950 (and (consp object) | |
951 (eq (car object) 'frame-configuration))) | |
952 | |
953 | |
1942 | 954 ;;;; Convenience functions for accessing and interactively changing |
955 ;;;; frame parameters. | |
956 | |
957 (defun frame-height (&optional frame) | |
958 "Return number of lines available for display on FRAME. | |
959 If FRAME is omitted, describe the currently selected frame." | |
960 (frame-property frame 'height)) | |
961 | |
962 (defun frame-width (&optional frame) | |
963 "Return number of columns available for display on FRAME. | |
964 If FRAME is omitted, describe the currently selected frame." | |
965 (frame-property frame 'width)) | |
966 | |
967 (defalias 'set-default-font 'set-frame-font) | |
968 | |
969 ;; XEmacs change: this function differs significantly from Emacs. | |
970 (defun set-frame-font (font-name &optional keep-size) | |
971 "Set the font of the selected frame to FONT-NAME. | |
972 When called interactively, prompt for the name of the font to use. | |
973 To get the frame's current default font, use `(face-font-name 'default)'. | |
974 | |
975 The default behavior is to keep the numbers of lines and columns in | |
976 the frame, thus may change its pixel size. If optional KEEP-SIZE is | |
977 non-nil (interactively, prefix argument) the current frame size (in | |
978 pixels) is kept by adjusting the numbers of the lines and columns." | |
979 (interactive | |
980 (let* ((frame (selected-frame)) | |
981 (completion-ignore-case t) | |
982 (font (completing-read "Font name: " | |
983 (mapcar #'list | |
2527 | 984 (font-list "*" frame)) |
1942 | 985 nil nil nil nil |
986 (face-font-name 'default frame)))) | |
987 (list font current-prefix-arg))) | |
988 (let* ((frame (selected-frame)) | |
989 (fht (frame-pixel-height frame)) | |
990 (fwd (frame-pixel-width frame)) | |
991 (face-list-to-change (face-list))) | |
992 (when (eq (device-type) 'mswindows) | |
993 (setq face-list-to-change | |
5652
cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents:
5526
diff
changeset
|
994 (delete* 'border-glyph face-list-to-change))) |
1942 | 995 ;; FIXME: Is it sufficient to just change the default face, due to |
996 ;; face inheritance? | |
997 (dolist (face face-list-to-change) | |
998 (when (face-font-instance face) | |
999 (condition-case c | |
1000 (set-face-font face font-name frame) | |
1001 (error | |
1002 (display-error c nil) | |
1003 (sit-for 1))))) | |
1004 (if keep-size | |
1005 (set-frame-pixel-size frame fwd fht))) | |
1006 (run-hooks 'after-setting-font-hook)) | |
1007 | |
1008 (defun set-frame-property (frame prop val) | |
1009 "Set property PROP of FRAME to VAL. See `set-frame-properties'." | |
1010 (set-frame-properties frame (list prop val))) | |
1011 | |
5080
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1012 (defun set-frame-background-placement (placement) |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1013 "Set the background placement of the selected frame to PLACEMENT. |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1014 When called interactively, prompt for the placement to use." |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1015 (interactive (list (intern (completing-read "Placement: " |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1016 '(("absolute" absolute) |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1017 ("relative" relative)) |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1018 nil t)))) |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1019 (set-face-background-placement 'default placement (selected-frame))) |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1020 |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1021 (defun frame-background-placement () |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1022 "Retrieve the selected frame's background placement." |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1023 (interactive) |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1024 (face-background-placement 'default (selected-frame))) |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1025 |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1026 (defun frame-background-placement-instance () |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1027 "Retrieve the selected frame's background placement instance." |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1028 (interactive) |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1029 (face-background-placement-instance 'default (selected-frame))) |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1030 |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1031 ;; #### FIXME: misnomers ! The functions below should be called |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1032 ;; set-frame-<blabla> -- dvl. |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4783
diff
changeset
|
1033 |
1942 | 1034 ;; XEmacs change: this function differs significantly from Emacs. |
1035 (defun set-background-color (color-name) | |
1036 "Set the background color of the selected frame to COLOR-NAME. | |
1037 When called interactively, prompt for the name of the color to use. | |
1038 To get the frame's current background color, use | |
1039 `(face-background-name 'default)'." | |
1040 (interactive (list (read-color "Color: "))) | |
1041 ;; (set-face-foreground 'text-cursor color-name (selected-frame)) | |
1042 (set-face-background 'default color-name (selected-frame))) | |
1043 | |
1044 ;; XEmacs change: this function differs significantly from Emacs. | |
1045 (defun set-foreground-color (color-name) | |
1046 "Set the foreground color of the selected frame to COLOR-NAME. | |
1047 When called interactively, prompt for the name of the color to use. | |
1048 To get the frame's current foreground color, use | |
1049 `(face-foreground-name 'default)'." | |
1050 (interactive (list (read-color "Color: "))) | |
1051 (set-face-foreground 'default color-name (selected-frame))) | |
1052 | |
1053 ;; XEmacs change: this function differs significantly from Emacs. | |
1054 (defun set-cursor-color (color-name) | |
1055 "Set the text cursor color of the selected frame to COLOR-NAME. | |
1056 When called interactively, prompt for the name of the color to use. | |
1057 To get the frame's current cursor color, use | |
1058 '(face-background-name 'text-cursor)'." | |
1059 (interactive (list (read-color "Color: "))) | |
1060 (set-face-background 'text-cursor color-name (selected-frame))) | |
1061 | |
1062 ;; XEmacs change: this function differs significantly from Emacs. | |
1063 (defun set-mouse-color (color-name) | |
1064 "Set the color of the mouse pointer of the selected frame to COLOR-NAME. | |
1065 When called interactively, prompt for the name of the color to use. | |
1066 To get the frame's current mouse color, use | |
1067 `(face-foreground-name 'pointer)'." | |
1068 (interactive (list (read-color "Color: "))) | |
1069 (set-face-foreground 'pointer color-name (selected-frame))) | |
1070 | |
1071 ;; XEmacs change: this function differs significantly from Emacs. | |
1072 (defun set-border-color (color-name) | |
1073 "Set the color of the border of the selected frame to COLOR-NAME. | |
1074 When called interactively, prompt for the name of the color to use. | |
1075 To get the frame's current border color, use | |
1076 `(face-foreground-name 'border-glyph)'." | |
1077 (interactive (list (read-color "Color: "))) | |
1078 (set-face-foreground 'border-glyph color-name (selected-frame))) | |
1079 | |
1080 ;;; BEGIN XEmacs addition | |
1081 ;;; This is the traditional XEmacs auto-raise and auto-lower, which applies | |
1082 ;;; to all frames. | |
1083 | |
1084 (defcustom auto-raise-frame nil | |
1085 "*If true, frames will be raised to the top when selected. | |
1086 Under X, most ICCCM-compliant window managers will have an option to do this | |
1087 for you, but this variable is provided in case you're using a broken WM." | |
1088 :type 'boolean | |
1089 :group 'frames) | |
1090 | |
1091 (defcustom auto-lower-frame nil | |
1092 "*If true, frames will be lowered to the bottom when no longer selected. | |
1093 Under X, most ICCCM-compliant window managers will have an option to do this | |
1094 for you, but this variable is provided in case you're using a broken WM." | |
1095 :type 'boolean | |
1096 :group 'frames) | |
1097 | |
1098 (defun default-select-frame-hook () | |
1099 "Implement the `auto-raise-frame' variable. | |
1100 For use as the value of `select-frame-hook'." | |
1101 (if auto-raise-frame (raise-frame (selected-frame)))) | |
428 | 1102 |
1942 | 1103 (defun default-deselect-frame-hook () |
1104 "Implement the `auto-lower-frame' variable. | |
1105 For use as the value of `deselect-frame-hook'." | |
1106 (if auto-lower-frame (lower-frame (selected-frame))) | |
1107 (highlight-extent nil nil)) | |
1108 | |
1109 (or select-frame-hook | |
1110 (add-hook 'select-frame-hook 'default-select-frame-hook)) | |
1111 | |
1112 (or deselect-frame-hook | |
1113 (add-hook 'deselect-frame-hook 'default-deselect-frame-hook)) | |
1114 | |
1115 ;;; END XEmacs addition | |
1116 ;;; Following is the Emacs auto-raise/auto-lower interface, which lets the | |
1117 ;;; user select individual frames to auto-raise and auto-lower | |
1118 | |
1119 ;; XEmacs addition: the next two variables do not appear in Emacs | |
1120 (defvar auto-raise-specifier (make-boolean-specifier auto-raise-frame) | |
1121 "Specifier that determines which frames should auto-raise. | |
1122 A value of `t' means that a frame auto-raises; `nil' means it does not.") | |
1123 | |
1124 (defvar auto-lower-specifier (make-boolean-specifier auto-lower-frame) | |
1125 "Specifier that determines which frames should auto-lower. | |
1126 A value of `t' means that a frame auto-lowers; `nil' means it does not.") | |
1127 | |
1128 ;; XEmacs change: use specifiers instead of frame-parameters | |
1129 (defun auto-raise-mode (arg) | |
1130 "Toggle whether or not the selected frame should auto-raise. | |
1131 With arg, turn auto-raise mode on if and only if arg is positive. | |
1132 Note that this controls Emacs's own auto-raise feature. | |
1133 Some window managers allow you to enable auto-raise for certain windows. | |
1134 You can use that for Emacs windows if you wish, but if you do, | |
1135 that is beyond the control of Emacs and this command has no effect on it." | |
1136 (interactive "P") | |
1137 (if (null arg) | |
1138 (setq arg | |
1139 (if (specifier-instance auto-raise-specifier (selected-frame)) | |
1140 -1 1))) | |
1141 (if (> arg 0) | |
1142 (progn | |
1143 (raise-frame (selected-frame)) | |
1144 (add-hook 'select-frame-hook 'default-select-frame-hook)) | |
1145 (set-specifier auto-raise-specifier (> arg 0) (selected-frame)))) | |
1146 | |
1147 ;; XEmacs change: use specifiers instead of frame-parameters | |
1148 (defun auto-lower-mode (arg) | |
1149 "Toggle whether or not the selected frame should auto-lower. | |
1150 With arg, turn auto-lower mode on if and only if arg is positive. | |
1151 Note that this controls Emacs's own auto-lower feature. | |
1152 Some window managers allow you to enable auto-lower for certain windows. | |
1153 You can use that for Emacs windows if you wish, but if you do, | |
1154 that is beyond the control of Emacs and this command has no effect on it." | |
1155 (interactive "P") | |
1156 (if (null arg) | |
1157 (setq arg | |
1158 (if (specifier-instance auto-lower-specifier (selected-frame)) | |
1159 -1 1))) | |
1160 (if (> arg 0) | |
1161 (progn | |
1162 (lower-frame (selected-frame)) | |
1163 (add-hook 'deselect-frame-hook 'default-deselect-frame-hook)) | |
1164 (set-specifier auto-lower-specifier (> arg 0) (selected-frame)))) | |
428 | 1165 |
1942 | 1166 ;; XEmacs omission: XEmacs does not support changing the frame name |
1167 ;(defun set-frame-name (name) | |
1168 ; "Set the name of the selected frame to NAME. | |
1169 ;When called interactively, prompt for the name of the frame. | |
1170 ;The frame name is displayed on the modeline if the terminal displays only | |
1171 ;one frame, otherwise the name is displayed on the frame's caption bar." | |
1172 ; (interactive "sFrame name: ") | |
1173 ; (modify-frame-parameters (selected-frame) | |
1174 ; (list (cons 'name name)))) | |
1175 | |
1176 ;; XEmacs omission: XEmacs attaches scrollbars to windows, not frames. | |
1177 ;; See window-hscroll and ... what? window-start? | |
1178 ;(defun frame-current-scroll-bars (&optional frame) | |
1179 ; "Return the current scroll-bar settings in frame FRAME. | |
1180 ;Value is a cons (VERTICAL . HORISONTAL) where VERTICAL specifies the | |
1181 ;current location of the vertical scroll-bars (left, right, or nil), | |
1182 ;and HORISONTAL specifies the current location of the horisontal scroll | |
1183 ;bars (top, bottom, or nil)." | |
1184 ; (let ((vert (frame-parameter frame 'vertical-scroll-bars)) | |
1185 ; (hor nil)) | |
1186 ; (unless (memq vert '(left right nil)) | |
1187 ; (setq vert default-frame-scroll-bars)) | |
1188 ; (cons vert hor))) | |
1189 | |
1190 ;;;; Frame/display capabilities. | |
1191 (defun display-mouse-p (&optional display) | |
1192 "Return non-nil if DISPLAY has a mouse available. | |
1193 DISPLAY can be a frame, a device, a console, or nil (meaning the | |
1194 selected frame)." | |
4546
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1195 (let (type) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1196 (setq display (display-device display) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1197 type (device-type display)) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1198 (cond |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1199 ((eq 'mswindows type) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1200 (> (declare-boundp mswindows-num-mouse-buttons) 0)) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1201 ((device-on-window-system-p display) |
4759
aa5ed11f473b
Remove support for obsolete systems. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents:
4689
diff
changeset
|
1202 ;; We assume X, GTK and the rest always have a pointing device. |
4546
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1203 t) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1204 ((eq 'tty type) |
2367 | 1205 (and-fboundp 'gpm-is-supported-p |
4546
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1206 (gpm-is-supported-p display))) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1207 (t nil)))) |
1942 | 1208 |
1209 (defun display-popup-menus-p (&optional display) | |
1210 "Return non-nil if popup menus are supported on DISPLAY. | |
1211 DISPLAY can be a frame, a device, a console, or nil (meaning the selected | |
1212 frame). Support for popup menus requires that the mouse be available." | |
4546
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1213 (setq display (display-device display)) |
1942 | 1214 (and |
4546
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1215 (featurep 'menubar) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1216 (device-on-window-system-p display) |
1942 | 1217 (display-mouse-p display))) |
1218 | |
1219 (defun display-graphic-p (&optional display) | |
1220 "Return non-nil if DISPLAY is a graphic display. | |
1221 Graphical displays are those which are capable of displaying several | |
1222 frames and several different fonts at once. This is true for displays | |
1223 that use a window system such as X, and false for text-only terminals. | |
1224 DISPLAY can be a frame, a device, a console, or nil (meaning the selected | |
1225 frame)." | |
4586
732e3243f2e4
Correct a bug in #'display-graphic-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4546
diff
changeset
|
1226 (device-on-window-system-p (display-device display))) |
1942 | 1227 |
1228 (defun display-images-p (&optional display) | |
1229 "Return non-nil if DISPLAY can display images. | |
1230 DISPLAY can be a frame, a device, a console, or nil (meaning the selected | |
1231 frame)." | |
4546
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1232 (and (memq (image-instance-type (specifier-instance |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1233 (glyph-image xemacs-logo) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1234 display)) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1235 '(color-pixmap mono-pixmap)) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1236 t)) |
1942 | 1237 |
1238 (defalias 'display-multi-frame-p 'display-graphic-p) | |
1239 (defalias 'display-multi-font-p 'display-graphic-p) | |
428 | 1240 |
1942 | 1241 (defun display-selections-p (&optional display) |
1242 "Return non-nil if DISPLAY supports selections. | |
1243 A selection is a way to transfer text or other data between programs | |
1244 via special system buffers called `selection' or `cut buffer' or | |
1245 `clipboard'. | |
1246 DISPLAY can be a frame, a device, a console, or nil (meaning the selected | |
1247 frame)." | |
4546
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1248 (or |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1249 (device-on-window-system-p display) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1250 ;; GPM supports #'get-selection-foreign, but not #'own-selection. |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1251 (and-fboundp 'gpm-is-supported-p |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1252 (gpm-is-supported-p display)))) |
1942 | 1253 |
1254 (defun display-screens (&optional display) | |
1255 "Return the number of screens associated with DISPLAY." | |
1256 (device-num-screens (display-device display))) | |
1257 | |
1258 (defun display-pixel-height (&optional display) | |
1259 "Return the height of DISPLAY's screen in pixels. | |
1260 For character terminals, each character counts as a single pixel." | |
1261 (device-pixel-height (display-device display))) | |
1262 | |
1263 (defun display-pixel-width (&optional display) | |
1264 "Return the width of DISPLAY's screen in pixels. | |
1265 For character terminals, each character counts as a single pixel." | |
1266 (device-pixel-width (display-device display))) | |
1267 | |
1268 (defun display-mm-height (&optional display) | |
1269 "Return the height of DISPLAY's screen in millimeters. | |
1270 If the information is unavailable, value is nil." | |
1271 (device-mm-height (display-device display))) | |
1272 | |
1273 (defun display-mm-width (&optional display) | |
1274 "Return the width of DISPLAY's screen in millimeters. | |
1275 If the information is unavailable, value is nil." | |
1276 (device-mm-width (display-device display))) | |
1277 | |
1278 (defun display-backing-store (&optional display) | |
1279 "Return the backing store capability of DISPLAY's screen. | |
1280 The value may be `always', `when-mapped', `not-useful', or nil if | |
1281 the question is inapplicable to a certain kind of display." | |
1282 (device-backing-store (display-device display))) | |
1283 | |
1284 (defun display-save-under (&optional display) | |
1285 "Return non-nil if DISPLAY's screen supports the SaveUnder feature." | |
1286 (device-save-under (display-device display))) | |
1287 | |
1288 (defun display-planes (&optional display) | |
1289 "Return the number of planes supported by DISPLAY." | |
1290 (device-bitplanes (display-device display))) | |
1291 | |
1292 (defun display-color-cells (&optional display) | |
1293 "Return the number of color cells supported by DISPLAY." | |
1294 (device-color-cells (display-device display))) | |
1295 | |
1296 (defun display-visual-class (&optional display) | |
1297 "Returns the visual class of DISPLAY. | |
1298 The value is one of the symbols `static-gray', `gray-scale', | |
1299 `static-color', `pseudo-color', `true-color', or `direct-color'." | |
4546
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1300 (let (type planes) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1301 (setq display (display-device display) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1302 type (device-type display)) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1303 (cond |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1304 ((eq 'x type) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1305 (declare-fboundp (x-display-visual-class display))) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1306 ((eq 'gtk type) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1307 (declare-fboundp (gtk-display-visual-class display))) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1308 ((device-on-window-system-p display) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1309 (setq planes (display-planes display)) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1310 (cond ((eq planes 1) 'static-gray) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1311 ((eq planes 4) 'static-color) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1312 ((> planes 8) 'true-color) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1313 (t 'pseudo-color))) |
44129f301385
Make functions in frame.el more general.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1314 (t 'static-gray)))) |
1942 | 1315 |
1316 | |
1317 ;; XEmacs change: omit the Emacs 18 compatibility functions: | |
1318 ;; screen-height, screen-width, set-screen-height, and set-screen-width. | |
1319 | |
1320 (defun delete-other-frames (&optional frame) | |
1321 "Delete all frames except FRAME. | |
1322 If FRAME uses another frame's minibuffer, the minibuffer frame is | |
1323 left untouched. FRAME nil or omitted means use the selected frame." | |
1324 (interactive) | |
1325 (unless frame | |
1326 (setq frame (selected-frame))) | |
1327 (let* ((mini-frame (window-frame (minibuffer-window frame))) | |
5652
cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents:
5526
diff
changeset
|
1328 (frames (delete* mini-frame (delete* frame (frame-list))))) |
1942 | 1329 (mapc 'delete-frame frames))) |
1330 | |
1331 ;; XEmacs change: we still use delete-frame-hook | |
1332 ;; miscellaneous obsolescence declarations | |
1333 ;(defvaralias 'delete-frame-hook 'delete-frame-functions) | |
1334 ;(make-obsolete-variable 'delete-frame-hook 'delete-frame-functions "21.4") | |
1335 | |
1336 | |
1337 ;; Highlighting trailing whitespace. | |
1338 ;; XEmacs omission: this functionality is provided by whitespace-mode in the | |
1339 ;; text-modes package. | |
1340 | |
1341 ;(make-variable-buffer-local 'show-trailing-whitespace) | |
1342 | |
1343 ;(defcustom show-trailing-whitespace nil | |
1344 ; "*Non-nil means highlight trailing whitespace in face `trailing-whitespace'. | |
1345 ; | |
1346 ;Setting this variable makes it local to the current buffer." | |
1347 ; :tag "Highlight trailing whitespace." | |
1348 ; :type 'boolean | |
1349 ; :group 'font-lock) | |
1350 | |
1351 | |
1352 ;; Scrolling | |
1353 ;; XEmacs omission: This functionality is always enabled on XEmacs. | |
1354 | |
1355 ;(defgroup scrolling nil | |
1356 ; "Scrolling windows." | |
1357 ; :version "21.1" | |
1358 ; :group 'frames) | |
1359 | |
1360 ;(defcustom auto-hscroll-mode t | |
1361 ; "*Allow or disallow automatic scrolling windows horizontally. | |
1362 ;If non-nil, windows are automatically scrolled horizontally to make | |
1363 ;point visible." | |
1364 ; :version "21.1" | |
1365 ; :type 'boolean | |
1366 ; :group 'scrolling) | |
1367 ;(defvaralias 'automatic-hscrolling 'auto-hscroll-mode) | |
1368 | |
1369 | |
1370 ;; Blinking cursor | |
1371 ;; XEmacs omission: this functionality is provided by blink-cursor in the | |
1372 ;; edit-utils package. | |
1373 | |
1374 ; (defgroup cursor nil | |
1375 ; "Displaying text cursors." | |
1376 ; :version "21.1" | |
1377 ; :group 'frames) | |
428 | 1378 |
1942 | 1379 ; (defcustom blink-cursor-delay 0.5 |
1380 ; "*Seconds of idle time after which cursor starts to blink." | |
1381 ; :tag "Delay in seconds." | |
1382 ; :type 'number | |
1383 ; :group 'cursor) | |
1384 | |
1385 ; (defcustom blink-cursor-interval 0.5 | |
1386 ; "*Length of cursor blink interval in seconds." | |
1387 ; :tag "Blink interval in seconds." | |
1388 ; :type 'number | |
1389 ; :group 'cursor) | |
1390 | |
1391 ; (defvar blink-cursor-idle-timer nil | |
1392 ; "Timer started after `blink-cursor-delay' seconds of Emacs idle time. | |
1393 ; The function `blink-cursor-start' is called when the timer fires.") | |
1394 | |
1395 ; (defvar blink-cursor-timer nil | |
1396 ; "Timer started from `blink-cursor-start'. | |
1397 ; This timer calls `blink-cursor' every `blink-cursor-interval' seconds.") | |
1398 | |
1399 ; (defvar blink-cursor-mode nil | |
1400 ; "Non-nil means blinking cursor is active.") | |
1401 | |
1402 ; (defun blink-cursor-mode (arg) | |
1403 ; "Toggle blinking cursor mode. | |
1404 ; With a numeric argument, turn blinking cursor mode on iff ARG is positive. | |
1405 ; When blinking cursor mode is enabled, the cursor of the selected | |
1406 ; window blinks. | |
1407 | |
1408 ; Note that this command is effective only when Emacs | |
1409 ; displays through a window system, because then Emacs does its own | |
1410 ; cursor display. On a text-only terminal, this is not implemented." | |
1411 ; (interactive "P") | |
1412 ; (let ((on-p (if (null arg) | |
1413 ; (not blink-cursor-mode) | |
1414 ; (> (prefix-numeric-value arg) 0)))) | |
1415 ; (if blink-cursor-idle-timer | |
1416 ; (cancel-timer blink-cursor-idle-timer)) | |
1417 ; (if blink-cursor-timer | |
1418 ; (cancel-timer blink-cursor-timer)) | |
1419 ; (setq blink-cursor-idle-timer nil | |
1420 ; blink-cursor-timer nil | |
1421 ; blink-cursor-mode nil) | |
1422 ; (if on-p | |
1423 ; (progn | |
1424 ; ;; Hide the cursor. | |
1425 ; ;(internal-show-cursor nil nil) | |
1426 ; (setq blink-cursor-idle-timer | |
1427 ; (run-with-idle-timer blink-cursor-delay | |
1428 ; blink-cursor-delay | |
1429 ; 'blink-cursor-start)) | |
1430 ; (setq blink-cursor-mode t)) | |
1431 ; (internal-show-cursor nil t)))) | |
1432 | |
1433 ; ;; Note that this is really initialized from startup.el before | |
1434 ; ;; the init-file is read. | |
1435 | |
1436 ; (defcustom blink-cursor nil | |
1437 ; "*Non-nil means blinking cursor mode is active." | |
1438 ; :group 'cursor | |
1439 ; :tag "Blinking cursor" | |
1440 ; :type 'boolean | |
1441 ; :set #'(lambda (symbol value) | |
1442 ; (set-default symbol value) | |
1443 ; (blink-cursor-mode (or value 0)))) | |
428 | 1444 |
1942 | 1445 ; (defun blink-cursor-start () |
1446 ; "Timer function called from the timer `blink-cursor-idle-timer'. | |
1447 ; This starts the timer `blink-cursor-timer', which makes the cursor blink | |
1448 ; if appropriate. It also arranges to cancel that timer when the next | |
1449 ; command starts, by installing a pre-command hook." | |
1450 ; (when (null blink-cursor-timer) | |
1451 ; (add-hook 'pre-command-hook 'blink-cursor-end) | |
1452 ; (setq blink-cursor-timer | |
1453 ; (run-with-timer blink-cursor-interval blink-cursor-interval | |
1454 ; 'blink-cursor-timer-function)))) | |
1455 | |
1456 ; (defun blink-cursor-timer-function () | |
1457 ; "Timer function of timer `blink-cursor-timer'." | |
1458 ; (internal-show-cursor nil (not (internal-show-cursor-p)))) | |
1459 | |
1460 ; (defun blink-cursor-end () | |
1461 ; "Stop cursor blinking. | |
1462 ; This is installed as a pre-command hook by `blink-cursor-start'. | |
1463 ; When run, it cancels the timer `blink-cursor-timer' and removes | |
1464 ; itself as a pre-command hook." | |
1465 ; (remove-hook 'pre-command-hook 'blink-cursor-end) | |
1466 ; (internal-show-cursor nil t) | |
1467 ; (cancel-timer blink-cursor-timer) | |
1468 ; (setq blink-cursor-timer nil)) | |
1469 | |
428 | 1470 |
1942 | 1471 ;; Hourglass pointer |
1472 ;; XEmacs omission: this functionality is provided elsewhere. | |
1473 | |
1474 ; (defcustom display-hourglass t | |
1475 ; "*Non-nil means show an hourglass pointer when running under a window system." | |
1476 ; :tag "Hourglass pointer" | |
1477 ; :type 'boolean | |
1478 ; :group 'cursor) | |
1479 | |
1480 ; (defcustom hourglass-delay 1 | |
1481 ; "*Seconds to wait before displaying an hourglass pointer." | |
1482 ; :tag "Hourglass delay" | |
1483 ; :type 'number | |
1484 ; :group 'cursor) | |
1485 | |
1486 ; | |
1487 ; (defcustom cursor-in-non-selected-windows t | |
1488 ; "*Non-nil means show a hollow box cursor in non-selected-windows. | |
1489 ; If nil, don't show a cursor except in the selected window. | |
1490 ; Use Custom to set this variable to get the display updated." | |
1491 ; :tag "Cursor in non-selected windows" | |
1492 ; :type 'boolean | |
1493 ; :group 'cursor | |
1494 ; :set #'(lambda (symbol value) | |
1495 ; (set-default symbol value) | |
1496 ; (force-mode-line-update t))) | |
1497 | |
1498 | |
1499 ;;;; Key bindings | |
1500 ;; XEmacs change: these keybindings are in keydef.el. | |
1501 | |
1502 ;(define-key ctl-x-5-map "2" 'make-frame-command) | |
1503 ;(define-key ctl-x-5-map "1" 'delete-other-frames) | |
1504 ;(define-key ctl-x-5-map "0" 'delete-frame) | |
1505 ;(define-key ctl-x-5-map "o" 'other-frame) | |
1506 | |
1507 | |
1508 ;;; XEmacs addition: nothing below this point appears in the Emacs version. | |
1509 | |
428 | 1510 ;;; Iconifying emacs. |
1511 ;;; | |
1512 ;;; The function iconify-emacs replaces every non-iconified emacs window | |
1513 ;;; with a *single* icon. Iconified emacs windows are left alone. When | |
1514 ;;; emacs is in this globally-iconified state, de-iconifying any emacs icon | |
1515 ;;; will uniconify all frames that were visible, and iconify all frames | |
1516 ;;; that were not. This is done by temporarily changing the value of | |
1517 ;;; `map-frame-hook' to `deiconify-emacs' (which should never be called | |
1518 ;;; except from the map-frame-hook while emacs is iconified). | |
1519 ;;; | |
1520 ;;; The title of the icon representing all emacs frames is controlled by | |
1521 ;;; the variable `icon-name'. This is done by temporarily changing the | |
1522 ;;; value of `frame-icon-title-format'. Unfortunately, this changes the | |
1523 ;;; titles of all emacs icons, not just the "big" icon. | |
1524 ;;; | |
1525 ;;; It would be nice if existing icons were removed and restored by | |
1526 ;;; iconifying the emacs process, but I couldn't make that work yet. | |
1527 | |
1528 (defvar icon-name nil) ; set this at run time, not load time. | |
1529 | |
1530 (defvar iconification-data nil) | |
1531 | |
1532 (defun iconify-emacs () | |
1533 "Replace every non-iconified FRAME with a *single* icon. | |
1534 Iconified frames are left alone. When XEmacs is in this | |
1535 globally-iconified state, de-iconifying any emacs icon will uniconify | |
1536 all frames that were visible, and iconify all frames that were not." | |
1537 (interactive) | |
1538 (if iconification-data (error "already iconified?")) | |
1539 (let* ((frames (frame-list)) | |
1540 (rest frames) | |
1541 (me (selected-frame)) | |
1542 frame) | |
1543 (while rest | |
1544 (setq frame (car rest)) | |
1545 (setcar rest (cons frame (frame-visible-p frame))) | |
1546 ; (if (memq (cdr (car rest)) '(icon nil)) | |
1547 ; (progn | |
1548 ; (make-frame-visible frame) ; deiconify, and process the X event | |
1549 ; (sleep-for 500 t) ; process X events; I really want to XSync() here | |
1550 ; )) | |
1551 (or (eq frame me) (make-frame-invisible frame)) | |
1552 (setq rest (cdr rest))) | |
1553 (or (boundp 'map-frame-hook) (setq map-frame-hook nil)) | |
1554 (or icon-name | |
1555 (setq icon-name (concat invocation-name " @ " (system-name)))) | |
1556 (setq iconification-data | |
1557 (list frame-icon-title-format map-frame-hook frames) | |
1558 frame-icon-title-format icon-name | |
1559 map-frame-hook 'deiconify-emacs) | |
1560 (iconify-frame me))) | |
1561 | |
1562 | |
1563 (defun deiconify-emacs (&optional ignore) | |
1564 (or iconification-data (error "not iconified?")) | |
1565 (setq frame-icon-title-format (car iconification-data) | |
1566 map-frame-hook (car (cdr iconification-data)) | |
1567 iconification-data (car (cdr (cdr iconification-data)))) | |
1568 (while iconification-data | |
1569 (let ((visibility (cdr (car iconification-data)))) | |
1570 (cond (visibility ;; JV (Note non-nil means visible in XEmacs) | |
1571 (make-frame-visible (car (car iconification-data)))) | |
1572 ; (t ;; (eq visibility 'icon) ;; JV Not in XEmacs!!! | |
1573 ; (make-frame-visible (car (car iconification-data))) | |
1574 ; (sleep-for 500 t) ; process X events; I really want to XSync() here | |
1575 ; (iconify-frame (car (car iconification-data)))) | |
1576 ;; (t nil) | |
1577 )) | |
1578 (setq iconification-data (cdr iconification-data)))) | |
1579 | |
1580 (defun suspend-or-iconify-emacs () | |
3547 | 1581 "Call iconify-emacs if using a window system, otherwise suspend. |
1582 | |
1583 `suspend' here can mean different things; if the current TTY console was | |
1584 created by gnuclient, that console is suspended, and the related devices and | |
1585 frames are removed from the display. Otherwise the Emacs process as a whole | |
1586 is suspended--that is, the traditional Unix suspend takes place. " | |
428 | 1587 (interactive) |
1588 (cond ((device-on-window-system-p) | |
1589 (iconify-emacs)) | |
1590 ((and (eq (device-type) 'tty) | |
502 | 1591 (declare-fboundp (console-tty-controlling-process |
1592 (selected-console)))) | |
428 | 1593 (suspend-console (selected-console))) |
1594 (t | |
1595 (suspend-emacs)))) | |
1596 | |
1597 ;; This is quite a mouthful, but it should be descriptive, as it's | |
1598 ;; bound to C-z. FSF takes the easy way out by binding C-z to | |
1599 ;; different things depending on window-system. We can't do the same, | |
1600 ;; because we allow simultaneous X and TTY consoles. | |
1601 (defun suspend-emacs-or-iconify-frame () | |
3547 | 1602 "Iconify the selected frame if using a window system, otherwise suspend. |
1603 | |
1604 `suspend' here can mean different things; if the current TTY console was | |
1605 created by gnuclient, the console is suspended, and the related devices and | |
1606 frames are removed from the display. Otherwise the Emacs process as a whole | |
1607 is suspended--that is, the traditional Unix suspend takes place. " | |
428 | 1608 (interactive) |
1609 (cond ((device-on-window-system-p) | |
1610 (iconify-frame)) | |
1611 ((and (eq (frame-type) 'tty) | |
502 | 1612 (declare-fboundp (console-tty-controlling-process |
1613 (selected-console)))) | |
428 | 1614 (suspend-console (selected-console))) |
1615 (t | |
1616 (suspend-emacs)))) | |
1617 | |
1618 | |
1619 ;;; Application-specific frame-management | |
1620 | |
1621 (defcustom get-frame-for-buffer-default-frame-name nil | |
1622 "*The default frame to select; see doc of `get-frame-for-buffer'." | |
1623 :type 'string | |
1624 :group 'frames) | |
1625 | |
1626 (defcustom get-frame-for-buffer-default-instance-limit nil | |
1627 "*The default instance limit for creating new frames; | |
1628 see doc of `get-frame-for-buffer'." | |
1629 :type 'integer | |
1630 :group 'frames) | |
1631 | |
1632 (defun get-frame-name-for-buffer (buffer) | |
1633 (let ((mode (and (get-buffer buffer) | |
1634 (save-excursion (set-buffer buffer) | |
1635 major-mode)))) | |
1636 (or (get mode 'frame-name) | |
1637 get-frame-for-buffer-default-frame-name))) | |
1638 | |
1639 (defun get-frame-for-buffer-make-new-frame (buffer &optional frame-name plist) | |
1640 (let* ((fr (make-frame plist)) | |
1641 (w (frame-root-window fr))) | |
1642 ;; | |
1643 ;; Make the one buffer being displayed in this newly created | |
1644 ;; frame be the buffer of interest, instead of something | |
1645 ;; random, so that it won't be shown in two-window mode. | |
1646 ;; Avoid calling switch-to-buffer here, since that's something | |
1647 ;; people might want to call this routine from. | |
1648 ;; | |
1649 ;; (If the root window doesn't have a buffer, then that means | |
1650 ;; there is more than one window on the frame, which can only | |
1651 ;; happen if the user has done something funny on the frame- | |
1652 ;; creation-hook. If that's the case, leave it alone.) | |
1653 ;; | |
1654 (if (window-buffer w) | |
1655 (set-window-buffer w buffer)) | |
1656 fr)) | |
1657 | |
1658 (defcustom get-frame-for-buffer-default-to-current nil | |
1659 "*When non-nil, `get-frame-for-buffer' will default to the selected frame." | |
1660 :type 'boolean | |
1661 :group 'frames) | |
1662 | |
1663 (defun get-frame-for-buffer-noselect (buffer | |
1664 &optional not-this-window-p on-frame) | |
1665 "Return a frame in which to display BUFFER. | |
1666 This is a subroutine of `get-frame-for-buffer' (which see)." | |
1667 (let (name limit) | |
1668 (cond | |
1669 ((or on-frame (eq (selected-window) (minibuffer-window))) | |
1670 ;; don't switch frames if a frame was specified, or to list | |
1671 ;; completions from the minibuffer, etc. | |
1672 nil) | |
1673 | |
1674 ((setq name (get-frame-name-for-buffer buffer)) | |
1675 ;; | |
1676 ;; This buffer's mode expressed a preference for a frame of a particular | |
1677 ;; name. That always takes priority. | |
1678 ;; | |
1679 (let ((limit (get name 'instance-limit)) | |
1680 (defaults (get name 'frame-defaults)) | |
1681 (matching-frames '()) | |
1682 frames frame already-visible) | |
1683 ;; Sort the list so that iconic frames will be found last. They | |
1684 ;; will be used too, but mapped frames take precedence. And | |
1685 ;; fully visible frames come before occluded frames. | |
1686 ;; Hidden frames come after really visible ones | |
1687 (setq frames | |
1688 (sort (frame-list) | |
1689 #'(lambda (s1 s2) | |
1690 (cond ((frame-totally-visible-p s2) | |
1691 nil) | |
1692 ((not (frame-visible-p s2)) | |
1693 (frame-visible-p s1)) | |
1694 ((eq (frame-visible-p s2) 'hidden) | |
1695 (eq (frame-visible-p s1) t )) | |
1696 ((not (frame-totally-visible-p s2)) | |
1697 (and (frame-visible-p s1) | |
1698 (frame-totally-visible-p s1))))))) | |
1699 ;; but the selected frame should come first, even if it's occluded, | |
1700 ;; to minimize thrashing. | |
1701 (setq frames (cons (selected-frame) | |
5652
cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents:
5526
diff
changeset
|
1702 (delete* (selected-frame) frames))) |
428 | 1703 |
1704 (setq name (symbol-name name)) | |
1705 (while frames | |
1706 (setq frame (car frames)) | |
1707 (if (equal name (frame-name frame)) | |
1708 (if (get-buffer-window buffer frame) | |
1709 (setq already-visible frame | |
1710 frames nil) | |
1711 (setq matching-frames (cons frame matching-frames)))) | |
1712 (setq frames (cdr frames))) | |
1713 (cond (already-visible | |
1714 already-visible) | |
1715 ((or (null matching-frames) | |
1716 (eq limit 0) ; means create with reckless abandon | |
1717 (and limit (< (length matching-frames) limit))) | |
1718 (get-frame-for-buffer-make-new-frame | |
1719 buffer | |
1720 name | |
1721 (alist-to-plist (acons 'name name | |
1722 (plist-to-alist defaults))))) | |
1723 (t | |
1724 ;; do not switch any of the window/buffer associations in an | |
1725 ;; existing frame; this function only picks a frame; the | |
1726 ;; determination of which windows on it get reused is up to | |
1727 ;; display-buffer itself. | |
1728 ;; (or (window-dedicated-p (selected-window)) | |
1729 ;; (switch-to-buffer buffer)) | |
1730 (car matching-frames))))) | |
1731 | |
1732 ((setq limit get-frame-for-buffer-default-instance-limit) | |
1733 ;; | |
1734 ;; This buffer's mode did not express a preference for a frame of a | |
1735 ;; particular name, but the user wants a new frame rather than | |
1736 ;; reusing the existing one. | |
1737 (let* ((defname | |
1738 (or (plist-get default-frame-plist 'name) | |
1739 default-frame-name)) | |
1740 (frames | |
5367
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
1741 (sort (remove-if-not #'(lambda (x) |
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
1742 (or (frame-visible-p x) |
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
1743 (frame-iconified-p x))) |
8b70d37ab80e
Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5264
diff
changeset
|
1744 (frame-list)) |
428 | 1745 #'(lambda (s1 s2) |
1746 (cond ((and (frame-visible-p s1) | |
1747 (not (frame-visible-p s2)))) | |
1748 ((and (eq (frame-visible-p s1) t) | |
1749 (eq (frame-visible-p s2) 'hidden))) | |
1750 ((and (frame-visible-p s2) | |
1751 (not (frame-visible-p s1))) | |
1752 nil) | |
1753 ((and (equal (frame-name s1) defname) | |
1754 (not (equal (frame-name s2) defname)))) | |
1755 ((and (equal (frame-name s2) defname) | |
1756 (not (equal (frame-name s1) defname))) | |
1757 nil) | |
1758 ((frame-totally-visible-p s2) | |
1759 nil) | |
1760 (t)))))) | |
1761 ;; put the selected frame last. The user wants a new frame, | |
1762 ;; so don't reuse the existing one unless forced to. | |
5652
cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents:
5526
diff
changeset
|
1763 (setq frames (append (delete* (selected-frame) frames) (list frames))) |
428 | 1764 (if (or (eq limit 0) ; means create with reckless abandon |
1765 (< (length frames) limit)) | |
1766 (get-frame-for-buffer-make-new-frame buffer) | |
1767 (car frames)))) | |
1768 | |
1769 (not-this-window-p | |
1770 (let ((w-list (windows-of-buffer buffer)) | |
1771 f w | |
1772 (first-choice nil) | |
1773 (second-choice (if get-frame-for-buffer-default-to-current | |
1774 (selected-frame) | |
1775 nil)) | |
1776 (last-resort nil)) | |
1777 (while (and w-list (null first-choice)) | |
1778 (setq w (car w-list) | |
1779 f (window-frame w)) | |
1780 (cond ((eq w (selected-window)) nil) | |
1781 ((not (frame-visible-p f)) | |
1782 (if (null last-resort) | |
1783 (setq last-resort f))) | |
1784 ((eq f (selected-frame)) | |
1785 (setq first-choice f)) | |
1786 ((null second-choice) | |
1787 (setq second-choice f))) | |
1788 (setq w-list (cdr w-list))) | |
1789 (or first-choice second-choice last-resort))) | |
1790 | |
1791 (get-frame-for-buffer-default-to-current (selected-frame)) | |
1792 | |
1793 (t | |
1794 ;; | |
1795 ;; This buffer's mode did not express a preference for a frame of a | |
1796 ;; particular name. So try to find a frame already displaying this | |
1797 ;; buffer. | |
1798 ;; | |
1799 (let ((w (or (get-buffer-window buffer nil) ; check current first | |
1800 (get-buffer-window buffer 'visible) ; then visible | |
1801 (get-buffer-window buffer 0)))) ; then iconic | |
1802 (cond ((null w) | |
1803 ;; It's not in any window - return nil, meaning no frame has | |
1804 ;; preference. | |
1805 nil) | |
1806 (t | |
1807 ;; Otherwise, return the frame of the buffer's window. | |
1808 (window-frame w)))))))) | |
1809 | |
1810 | |
1811 ;; The pre-display-buffer-function is called for effect, so this needs to | |
1812 ;; actually select the frame it wants. Fdisplay_buffer() takes notice of | |
1813 ;; changes to the selected frame. | |
903 | 1814 (defun get-frame-for-buffer (buffer &optional not-this-window-p on-frame |
1815 shrink-to-fit) | |
428 | 1816 "Select and return a frame in which to display BUFFER. |
1817 Normally, the buffer will simply be displayed in the selected frame. | |
3061 | 1818 But if the symbol naming the major-mode of the buffer has a `frame-name' |
428 | 1819 property (which should be a symbol), then the buffer will be displayed in |
1820 a frame of that name. If there is no frame of that name, then one is | |
1821 created. | |
1822 | |
3061 | 1823 If the major-mode doesn't have a `frame-name' property, then the frame |
428 | 1824 named by `get-frame-for-buffer-default-frame-name' will be used. If |
1825 that is nil (the default) then the currently selected frame will used. | |
1826 | |
3061 | 1827 If the frame-name symbol has an `instance-limit' property (an integer) |
428 | 1828 then each time a buffer of the mode in question is displayed, a new frame |
1829 with that name will be created, until there are `instance-limit' of them. | |
1830 If instance-limit is 0, then a new frame will be created each time. | |
1831 | |
1832 If a buffer is already displayed in a frame, then `instance-limit' is | |
1833 ignored, and that frame is used. | |
1834 | |
3061 | 1835 If the frame-name symbol has a `frame-defaults' property, then that is |
428 | 1836 prepended to the `default-frame-plist' when creating a frame for the |
1837 first time. | |
1838 | |
1839 This function may be used as the value of `pre-display-buffer-function', | |
444 | 1840 to cause the `display-buffer' function and its callers to exhibit the |
1841 above behavior." | |
428 | 1842 (let ((frame (get-frame-for-buffer-noselect |
1843 buffer not-this-window-p on-frame))) | |
1844 (if (not (eq frame (selected-frame))) | |
1845 frame | |
1846 (select-frame frame) | |
1847 (or (frame-visible-p frame) | |
1848 ;; If the frame was already visible, just focus on it. | |
1849 ;; If it wasn't visible (it was just created, or it used | |
1850 ;; to be iconified) then uniconify, raise, etc. | |
1851 (make-frame-visible frame)) | |
1852 frame))) | |
1853 | |
1854 (defun frames-of-buffer (&optional buffer visible-only) | |
1855 "Return list of frames that BUFFER is currently being displayed on. | |
1856 If the buffer is being displayed on the currently selected frame, that frame | |
1857 is first in the list. VISIBLE-ONLY will only list non-iconified frames." | |
1858 (let ((list (windows-of-buffer buffer)) | |
1859 (cur-frame (selected-frame)) | |
1860 next-frame frames save-frame) | |
1861 | |
1862 (while list | |
1863 (if (memq (setq next-frame (window-frame (car list))) | |
1864 frames) | |
1865 nil | |
1866 (if (eq cur-frame next-frame) | |
1867 (setq save-frame next-frame) | |
1868 (and | |
1869 (or (not visible-only) | |
1870 (frame-visible-p next-frame)) | |
1871 (setq frames (append frames (list next-frame)))))) | |
1872 (setq list (cdr list))) | |
1873 | |
1874 (if save-frame | |
1875 (append (list save-frame) frames) | |
1876 frames))) | |
1877 | |
1878 (defcustom temp-buffer-shrink-to-fit nil | |
1879 "*When non-nil resize temporary output buffers to minimize blank lines." | |
1880 :type 'boolean | |
1881 :group 'frames) | |
1882 | |
1883 (defcustom temp-buffer-max-height .5 | |
1884 "*Proportion of frame to use for temp windows." | |
1885 :type 'number | |
1886 :group 'frames) | |
1887 | |
4506
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4044
diff
changeset
|
1888 ;; See also #'temp-buffer-resize-mode in help.el. |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4044
diff
changeset
|
1889 |
428 | 1890 (defun show-temp-buffer-in-current-frame (buffer) |
444 | 1891 "For use as the value of `temp-buffer-show-function': |
428 | 1892 always displays the buffer in the selected frame, regardless of the behavior |
1893 that would otherwise be introduced by the `pre-display-buffer-function', which | |
1894 is normally set to `get-frame-for-buffer' (which see)." | |
1895 (let ((pre-display-buffer-function nil)) ; turn it off, whatever it is | |
903 | 1896 (let ((window (display-buffer buffer nil nil temp-buffer-shrink-to-fit))) |
428 | 1897 (if (not (eq (last-nonminibuf-frame) (window-frame window))) |
1898 ;; only the pre-display-buffer-function should ever do this. | |
1899 (error "display-buffer switched frames on its own!!")) | |
1900 (setq minibuffer-scroll-window window) | |
1901 (set-window-start window 1) ; obeys narrowing | |
1902 (set-window-point window 1) | |
1903 nil))) | |
1904 | |
1905 (setq temp-buffer-show-function 'show-temp-buffer-in-current-frame) | |
1906 | |
1907 | |
1908 ;; from Bob Weiner <bweiner@pts.mot.com>, modified by Ben Wing | |
1909 | |
1910 ;; By adding primitives to directly access the window hierarchy, | |
1911 ;; we can move many functions into Lisp. We do it this way | |
1912 ;; because the implementations are simpler in Lisp, and because | |
1913 ;; new functions like this can be added without requiring C | |
1914 ;; additions. | |
1915 | |
1916 (defun frame-utmost-window-2 (window position left-right-p major-end-p | |
1917 minor-end-p) | |
1918 ;; LEFT-RIGHT-P means we're looking for the leftmost or rightmost | |
1919 ;; window, instead of the highest or lowest. In this case, we | |
1920 ;; say that the "major axis" goes left-to-right instead of top-to- | |
1921 ;; bottom. The "minor axis" always goes perpendicularly. | |
1922 ;; | |
1923 ;; If MAJOR-END-P is t, we're looking for a windows that abut the | |
1924 ;; end (i.e. right or bottom) of the major axis, instead of the | |
1925 ;; start. | |
1926 ;; | |
1927 ;; If MINOR-END-P is t, then we want to start counting from the | |
1928 ;; end of the minor axis instead of the beginning. | |
1929 ;; | |
1930 ;; Here's the general idea: Imagine we're trying to count the number | |
1931 ;; of windows that abut the top; call this function foo(). So, we | |
1932 ;; start with the root window. If this is a vertical combination | |
1933 ;; window, then foo() applied to the root window is the same as | |
1934 ;; foo() applied to the first child. If the root is a horizontal | |
1935 ;; combination window, then foo() applied to the root is the | |
1936 ;; same as the sum of foo() applied to each of the children. | |
1937 ;; Otherwise, the root window is a leaf window, and foo() is 1. | |
1938 ;; Now it's clear that, each time foo() encounters a leaf window, | |
1939 ;; it's encountering a different window that abuts the top. | |
1940 ;; With a little examining, you can see that foo encounters the | |
1941 ;; top-abutting windows in order from left to right. We can | |
1942 ;; modify foo() to return the nth top-abutting window by simply | |
1943 ;; keeping a global variable that is decremented each time | |
1944 ;; foo() encounters a leaf window and would return 1. If the | |
1945 ;; global counter gets to zero, we've encountered the window | |
1946 ;; we were looking for, so we exit right away using a `throw'. | |
1947 ;; Otherwise, we make sure that all normal paths return nil. | |
1948 | |
1949 (let (child) | |
1950 (cond ((setq child (if left-right-p | |
1951 (window-first-hchild window) | |
1952 (window-first-vchild window))) | |
1953 (if major-end-p | |
1954 (while (window-next-child child) | |
1955 (setq child (window-next-child child)))) | |
1956 (frame-utmost-window-2 child position left-right-p major-end-p | |
1957 minor-end-p)) | |
1958 ((setq child (if left-right-p | |
1959 (window-first-vchild window) | |
1960 (window-first-hchild window))) | |
1961 (if minor-end-p | |
1962 (while (window-next-child child) | |
1963 (setq child (window-next-child child)))) | |
1964 (while child | |
1965 (frame-utmost-window-2 child position left-right-p major-end-p | |
1966 minor-end-p) | |
1967 (setq child (if minor-end-p | |
1968 (window-previous-child child) | |
1969 (window-next-child child)))) | |
1970 nil) | |
1971 (t | |
1972 (setcar position (1- (car position))) | |
1973 (if (= (car position) 0) | |
1974 (throw 'fhw-exit window) | |
1975 nil))))) | |
1976 | |
1977 (defun frame-utmost-window-1 (frame position left-right-p major-end-p) | |
1978 (let (minor-end-p) | |
1979 (or frame (setq frame (selected-frame))) | |
1980 (or position (setq position 0)) | |
1981 (if (>= position 0) | |
1982 (setq position (1+ position)) | |
1983 (setq minor-end-p t) | |
1984 (setq position (- position))) | |
1985 (catch 'fhw-exit | |
1986 ;; we use a cons here as a simple form of call-by-reference. | |
1987 ;; scheme has "boxes" for the same purpose. | |
1988 (frame-utmost-window-2 (frame-root-window frame) (list position) | |
1989 left-right-p major-end-p minor-end-p)))) | |
1990 | |
1991 | |
1992 (defun frame-highest-window (&optional frame position) | |
1993 "Return the highest window on FRAME which is at POSITION. | |
1994 If omitted, FRAME defaults to the currently selected frame. | |
1995 POSITION is used to distinguish between multiple windows that abut | |
1996 the top of the frame: 0 means the leftmost window abutting the | |
1997 top of the frame, 1 the next-leftmost, etc. POSITION can also | |
1998 be less than zero: -1 means the rightmost window abutting the | |
1999 top of the frame, -2 the next-rightmost, etc. | |
2000 If omitted, POSITION defaults to 0, i.e. the leftmost highest window. | |
2001 If there is no window at the given POSITION, return nil." | |
2002 (frame-utmost-window-1 frame position nil nil)) | |
2003 | |
2004 (defun frame-lowest-window (&optional frame position) | |
2005 "Return the lowest window on FRAME which is at POSITION. | |
2006 If omitted, FRAME defaults to the currently selected frame. | |
2007 POSITION is used to distinguish between multiple windows that abut | |
2008 the bottom of the frame: 0 means the leftmost window abutting the | |
2009 bottom of the frame, 1 the next-leftmost, etc. POSITION can also | |
2010 be less than zero: -1 means the rightmost window abutting the | |
2011 bottom of the frame, -2 the next-rightmost, etc. | |
2012 If omitted, POSITION defaults to 0, i.e. the leftmost lowest window. | |
2013 If there is no window at the given POSITION, return nil." | |
2014 (frame-utmost-window-1 frame position nil t)) | |
2015 | |
2016 (defun frame-leftmost-window (&optional frame position) | |
2017 "Return the leftmost window on FRAME which is at POSITION. | |
2018 If omitted, FRAME defaults to the currently selected frame. | |
2019 POSITION is used to distinguish between multiple windows that abut | |
2020 the left edge of the frame: 0 means the highest window abutting the | |
2021 left edge of the frame, 1 the next-highest, etc. POSITION can also | |
2022 be less than zero: -1 means the lowest window abutting the | |
2023 left edge of the frame, -2 the next-lowest, etc. | |
2024 If omitted, POSITION defaults to 0, i.e. the highest leftmost window. | |
2025 If there is no window at the given POSITION, return nil." | |
2026 (frame-utmost-window-1 frame position t nil)) | |
2027 | |
2028 (defun frame-rightmost-window (&optional frame position) | |
2029 "Return the rightmost window on FRAME which is at POSITION. | |
2030 If omitted, FRAME defaults to the currently selected frame. | |
2031 POSITION is used to distinguish between multiple windows that abut | |
2032 the right edge of the frame: 0 means the highest window abutting the | |
2033 right edge of the frame, 1 the next-highest, etc. POSITION can also | |
2034 be less than zero: -1 means the lowest window abutting the | |
2035 right edge of the frame, -2 the next-lowest, etc. | |
2036 If omitted, POSITION defaults to 0, i.e. the highest rightmost window. | |
2037 If there is no window at the given POSITION, return nil." | |
2038 (frame-utmost-window-1 frame position t t)) | |
2039 | |
2040 | |
2041 | |
2042 ;; frame properties. | |
2043 | |
2044 (put 'cursor-color 'frame-property-alias [text-cursor background]) | |
2045 (put 'modeline 'frame-property-alias 'has-modeline-p) | |
2046 | |
2047 | |
2048 (provide 'frame) | |
2049 | |
2050 ;;; frame.el ends here |