* textmodes/makeinfo.el (makeinfo-buffer): Make it work also for
[emacs.git] / lisp / frame.el
blob08d4a136e1ca6f7e8c60cc3c78c05e2200027b86
1 ;;; frame.el --- multi-frame management independent of window systems
3 ;; Copyright (C) 1993-1994, 1996-1997, 2000-2014 Free Software
4 ;; Foundation, Inc.
6 ;; Maintainer: emacs-devel@gnu.org
7 ;; Keywords: internal
8 ;; Package: emacs
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;;; Code:
28 (eval-when-compile (require 'cl-lib))
30 (defvar frame-creation-function-alist
31 (list (cons nil
32 (if (fboundp 'tty-create-frame-with-faces)
33 'tty-create-frame-with-faces
34 (lambda (_parameters)
35 (error "Can't create multiple frames without a window system")))))
36 "Alist of window-system dependent functions to call to create a new frame.
37 The window system startup file should add its frame creation
38 function to this list, which should take an alist of parameters
39 as its argument.")
41 (defvar window-system-default-frame-alist nil
42 "Window-system dependent default frame parameters.
43 The value should be an alist of elements (WINDOW-SYSTEM . ALIST),
44 where WINDOW-SYSTEM is a window system symbol (see `window-system')
45 and ALIST is a frame parameter alist like `default-frame-alist'.
46 Then, for frames on WINDOW-SYSTEM, any parameters specified in
47 ALIST supersede the corresponding parameters specified in
48 `default-frame-alist'.")
50 (defvar display-format-alist nil
51 "Alist of patterns to decode display names.
52 The car of each entry is a regular expression matching a display
53 name string. The cdr is a symbol giving the window-system that
54 handles the corresponding kind of display.")
56 ;; The initial value given here used to ask for a minibuffer.
57 ;; But that's not necessary, because the default is to have one.
58 ;; By not specifying it here, we let an X resource specify it.
59 (defcustom initial-frame-alist nil
60 "Alist of parameters for the initial X window frame.
61 You can set this in your init file; for example,
63 (setq initial-frame-alist
64 '((top . 1) (left . 1) (width . 80) (height . 55)))
66 Parameters specified here supersede the values given in
67 `default-frame-alist'.
69 If the value calls for a frame without a minibuffer, and you have
70 not created a minibuffer frame on your own, a minibuffer frame is
71 created according to `minibuffer-frame-alist'.
73 You can specify geometry-related options for just the initial
74 frame by setting this variable in your init file; however, they
75 won't take effect until Emacs reads your init file, which happens
76 after creating the initial frame. If you want the initial frame
77 to have the proper geometry as soon as it appears, you need to
78 use this three-step process:
79 * Specify X resources to give the geometry you want.
80 * Set `default-frame-alist' to override these options so that they
81 don't affect subsequent frames.
82 * Set `initial-frame-alist' in a way that matches the X resources,
83 to override what you put in `default-frame-alist'."
84 :type '(repeat (cons :format "%v"
85 (symbol :tag "Parameter")
86 (sexp :tag "Value")))
87 :group 'frames)
89 (defcustom minibuffer-frame-alist '((width . 80) (height . 2))
90 "Alist of parameters for the initial minibuffer frame.
91 This is the minibuffer frame created if `initial-frame-alist'
92 calls for a frame without a minibuffer. The parameters specified
93 here supersede those given in `default-frame-alist', for the
94 initial minibuffer frame.
96 You can set this in your init file; for example,
98 (setq minibuffer-frame-alist
99 '((top . 1) (left . 1) (width . 80) (height . 2)))
101 It is not necessary to include (minibuffer . only); that is
102 appended when the minibuffer frame is created."
103 :type '(repeat (cons :format "%v"
104 (symbol :tag "Parameter")
105 (sexp :tag "Value")))
106 :group 'frames)
108 (defun handle-delete-frame (event)
109 "Handle delete-frame events from the X server."
110 (interactive "e")
111 (let ((frame (posn-window (event-start event)))
112 (i 0)
113 (tail (frame-list)))
114 (while tail
115 (and (frame-visible-p (car tail))
116 (not (eq (car tail) frame))
117 (setq i (1+ i)))
118 (setq tail (cdr tail)))
119 (if (> i 0)
120 (delete-frame frame t)
121 ;; Gildea@x.org says it is ok to ask questions before terminating.
122 (save-buffers-kill-emacs))))
124 (defun handle-focus-in (_event)
125 "Handle a focus-in event.
126 Focus-in events are usually bound to this function.
127 Focus-in events occur when a frame has focus, but a switch-frame event
128 is not generated.
129 This function runs the hook `focus-in-hook'."
130 (interactive "e")
131 (run-hooks 'focus-in-hook))
133 (defun handle-focus-out (_event)
134 "Handle a focus-out event.
135 Focus-out events are usually bound to this function.
136 Focus-out events occur when no frame has focus.
137 This function runs the hook `focus-out-hook'."
138 (interactive "e")
139 (run-hooks 'focus-out-hook))
141 ;;;; Arrangement of frames at startup
143 ;; 1) Load the window system startup file from the lisp library and read the
144 ;; high-priority arguments (-q and the like). The window system startup
145 ;; file should create any frames specified in the window system defaults.
147 ;; 2) If no frames have been opened, we open an initial text frame.
149 ;; 3) Once the init file is done, we apply any newly set parameters
150 ;; in initial-frame-alist to the frame.
152 ;; These are now called explicitly at the proper times,
153 ;; since that is easier to understand.
154 ;; Actually using hooks within Emacs is bad for future maintenance. --rms.
155 ;; (add-hook 'before-init-hook 'frame-initialize)
156 ;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
158 ;; If we create the initial frame, this is it.
159 (defvar frame-initial-frame nil)
161 ;; Record the parameters used in frame-initialize to make the initial frame.
162 (defvar frame-initial-frame-alist)
164 (defvar frame-initial-geometry-arguments nil)
166 ;; startup.el calls this function before loading the user's init
167 ;; file - if there is no frame with a minibuffer open now, create
168 ;; one to display messages while loading the init file.
169 (defun frame-initialize ()
170 "Create an initial frame if necessary."
171 ;; Are we actually running under a window system at all?
172 (if (and initial-window-system
173 (not noninteractive)
174 (not (eq initial-window-system 'pc)))
175 (progn
176 ;; If there is no frame with a minibuffer besides the terminal
177 ;; frame, then we need to create the opening frame. Make sure
178 ;; it has a minibuffer, but let initial-frame-alist omit the
179 ;; minibuffer spec.
180 (or (delq terminal-frame (minibuffer-frame-list))
181 (progn
182 (setq frame-initial-frame-alist
183 (append initial-frame-alist default-frame-alist nil))
184 (or (assq 'horizontal-scroll-bars frame-initial-frame-alist)
185 (setq frame-initial-frame-alist
186 (cons '(horizontal-scroll-bars . t)
187 frame-initial-frame-alist)))
188 (setq frame-initial-frame-alist
189 (cons (cons 'window-system initial-window-system)
190 frame-initial-frame-alist))
191 (setq default-minibuffer-frame
192 (setq frame-initial-frame
193 (make-frame frame-initial-frame-alist)))
194 ;; Delete any specifications for window geometry parameters
195 ;; so that we won't reapply them in frame-notice-user-settings.
196 ;; It would be wrong to reapply them then,
197 ;; because that would override explicit user resizing.
198 (setq initial-frame-alist
199 (frame-remove-geometry-params initial-frame-alist))))
200 ;; Copy the environment of the Emacs process into the new frame.
201 (set-frame-parameter frame-initial-frame 'environment
202 (frame-parameter terminal-frame 'environment))
203 ;; At this point, we know that we have a frame open, so we
204 ;; can delete the terminal frame.
205 (delete-frame terminal-frame)
206 (setq terminal-frame nil))))
208 (defvar frame-notice-user-settings t
209 "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
211 (declare-function tool-bar-mode "tool-bar" (&optional arg))
213 (defalias 'tool-bar-lines-needed 'tool-bar-height)
215 ;; startup.el calls this function after loading the user's init
216 ;; file. Now default-frame-alist and initial-frame-alist contain
217 ;; information to which we must react; do what needs to be done.
218 (defun frame-notice-user-settings ()
219 "Act on user's init file settings of frame parameters.
220 React to settings of `initial-frame-alist',
221 `window-system-default-frame-alist' and `default-frame-alist'
222 there (in decreasing order of priority)."
223 ;; Creating and deleting frames may shift the selected frame around,
224 ;; and thus the current buffer. Protect against that. We don't
225 ;; want to use save-excursion here, because that may also try to set
226 ;; the buffer of the selected window, which fails when the selected
227 ;; window is the minibuffer.
228 (let ((old-buffer (current-buffer))
229 (window-system-frame-alist
230 (cdr (assq initial-window-system
231 window-system-default-frame-alist))))
233 (when (and frame-notice-user-settings
234 (null frame-initial-frame))
235 ;; This case happens when we don't have a window system, and
236 ;; also for MS-DOS frames.
237 (let ((parms (frame-parameters)))
238 ;; Don't change the frame names.
239 (setq parms (delq (assq 'name parms) parms))
240 ;; Can't modify the minibuffer parameter, so don't try.
241 (setq parms (delq (assq 'minibuffer parms) parms))
242 (modify-frame-parameters
244 (if initial-window-system
245 parms
246 ;; initial-frame-alist and default-frame-alist were already
247 ;; applied in pc-win.el.
248 (append initial-frame-alist window-system-frame-alist
249 default-frame-alist parms nil)))
250 (if (null initial-window-system) ;; MS-DOS does this differently in pc-win.el
251 (let ((newparms (frame-parameters))
252 (frame (selected-frame)))
253 (tty-handle-reverse-video frame newparms)
254 ;; If we changed the background color, we need to update
255 ;; the background-mode parameter, and maybe some faces,
256 ;; too.
257 (when (assq 'background-color newparms)
258 (unless (or (assq 'background-mode initial-frame-alist)
259 (assq 'background-mode default-frame-alist))
260 (frame-set-background-mode frame))
261 (face-set-after-frame-default frame))))))
263 ;; If the initial frame is still around, apply initial-frame-alist
264 ;; and default-frame-alist to it.
265 (when (frame-live-p frame-initial-frame)
267 ;; When tool-bar has been switched off, correct the frame size
268 ;; by the lines added in x-create-frame for the tool-bar and
269 ;; switch `tool-bar-mode' off.
270 (when (display-graphic-p)
271 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
272 (assq 'tool-bar-lines window-system-frame-alist)
273 (assq 'tool-bar-lines default-frame-alist))))
274 (when (and tool-bar-originally-present
275 (or (null tool-bar-lines)
276 (null (cdr tool-bar-lines))
277 (eq 0 (cdr tool-bar-lines))))
278 (let* ((char-height (frame-char-height frame-initial-frame))
279 (image-height tool-bar-images-pixel-height)
280 (margin (cond ((and (consp tool-bar-button-margin)
281 (integerp (cdr tool-bar-button-margin))
282 (> tool-bar-button-margin 0))
283 (cdr tool-bar-button-margin))
284 ((and (integerp tool-bar-button-margin)
285 (> tool-bar-button-margin 0))
286 tool-bar-button-margin)
287 (t 0)))
288 (relief (if (and (integerp tool-bar-button-relief)
289 (> tool-bar-button-relief 0))
290 tool-bar-button-relief 3))
291 (lines (/ (+ image-height
292 (* 2 margin)
293 (* 2 relief)
294 (1- char-height))
295 char-height))
296 (height (frame-parameter frame-initial-frame 'height))
297 (newparms (list (cons 'height (- height lines))))
298 (initial-top (cdr (assq 'top
299 frame-initial-geometry-arguments)))
300 (top (frame-parameter frame-initial-frame 'top)))
301 (when (and (consp initial-top) (eq '- (car initial-top)))
302 (let ((adjusted-top
303 (cond ((and (consp top)
304 (eq '+ (car top)))
305 (list '+
306 (+ (cadr top)
307 (* lines char-height))))
308 ((and (consp top)
309 (eq '- (car top)))
310 (list '-
311 (- (cadr top)
312 (* lines char-height))))
313 (t (+ top (* lines char-height))))))
314 (setq newparms
315 (append newparms
316 `((top . ,adjusted-top))
317 nil))))
318 (modify-frame-parameters frame-initial-frame newparms)
319 (tool-bar-mode -1)))))
321 ;; The initial frame we create above always has a minibuffer.
322 ;; If the user wants to remove it, or make it a minibuffer-only
323 ;; frame, then we'll have to delete the current frame and make a
324 ;; new one; you can't remove or add a root window to/from an
325 ;; existing frame.
327 ;; NOTE: default-frame-alist was nil when we created the
328 ;; existing frame. We need to explicitly include
329 ;; default-frame-alist in the parameters of the screen we
330 ;; create here, so that its new value, gleaned from the user's
331 ;; init file, will be applied to the existing screen.
332 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
333 (assq 'minibuffer window-system-frame-alist)
334 (assq 'minibuffer default-frame-alist)
335 '(minibuffer . t)))
337 ;; Create the new frame.
338 (let (parms new)
339 ;; MS-Windows needs this to avoid inflooping below.
340 (if (eq system-type 'windows-nt)
341 (sit-for 0 t))
342 ;; If the frame isn't visible yet, wait till it is.
343 ;; If the user has to position the window,
344 ;; Emacs doesn't know its real position until
345 ;; the frame is seen to be visible.
346 (while (not (cdr (assq 'visibility
347 (frame-parameters frame-initial-frame))))
348 (sleep-for 1))
349 (setq parms (frame-parameters frame-initial-frame))
351 ;; Get rid of `name' unless it was specified explicitly before.
352 (or (assq 'name frame-initial-frame-alist)
353 (setq parms (delq (assq 'name parms) parms)))
354 ;; An explicit parent-id is a request to XEmbed the frame.
355 (or (assq 'parent-id frame-initial-frame-alist)
356 (setq parms (delq (assq 'parent-id parms) parms)))
358 (setq parms (append initial-frame-alist
359 window-system-frame-alist
360 default-frame-alist
361 parms
362 nil))
364 ;; Get rid of `reverse', because that was handled
365 ;; when we first made the frame.
366 (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
368 (if (assq 'height frame-initial-geometry-arguments)
369 (setq parms (assq-delete-all 'height parms)))
370 (if (assq 'width frame-initial-geometry-arguments)
371 (setq parms (assq-delete-all 'width parms)))
372 (if (assq 'left frame-initial-geometry-arguments)
373 (setq parms (assq-delete-all 'left parms)))
374 (if (assq 'top frame-initial-geometry-arguments)
375 (setq parms (assq-delete-all 'top parms)))
376 (setq new
377 (make-frame
378 ;; Use the geometry args that created the existing
379 ;; frame, rather than the parms we get for it.
380 (append frame-initial-geometry-arguments
381 '((user-size . t) (user-position . t))
382 parms)))
383 ;; The initial frame, which we are about to delete, may be
384 ;; the only frame with a minibuffer. If it is, create a
385 ;; new one.
386 (or (delq frame-initial-frame (minibuffer-frame-list))
387 (make-initial-minibuffer-frame nil))
389 ;; If the initial frame is serving as a surrogate
390 ;; minibuffer frame for any frames, we need to wean them
391 ;; onto a new frame. The default-minibuffer-frame
392 ;; variable must be handled similarly.
393 (let ((users-of-initial
394 (filtered-frame-list
395 (lambda (frame)
396 (and (not (eq frame frame-initial-frame))
397 (eq (window-frame
398 (minibuffer-window frame))
399 frame-initial-frame))))))
400 (if (or users-of-initial
401 (eq default-minibuffer-frame frame-initial-frame))
403 ;; Choose an appropriate frame. Prefer frames which
404 ;; are only minibuffers.
405 (let* ((new-surrogate
406 (car
407 (or (filtered-frame-list
408 (lambda (frame)
409 (eq (cdr (assq 'minibuffer
410 (frame-parameters frame)))
411 'only)))
412 (minibuffer-frame-list))))
413 (new-minibuffer (minibuffer-window new-surrogate)))
415 (if (eq default-minibuffer-frame frame-initial-frame)
416 (setq default-minibuffer-frame new-surrogate))
418 ;; Wean the frames using frame-initial-frame as
419 ;; their minibuffer frame.
420 (dolist (frame users-of-initial)
421 (modify-frame-parameters
422 frame (list (cons 'minibuffer new-minibuffer)))))))
424 ;; Redirect events enqueued at this frame to the new frame.
425 ;; Is this a good idea?
426 (redirect-frame-focus frame-initial-frame new)
428 ;; Finally, get rid of the old frame.
429 (delete-frame frame-initial-frame t))
431 ;; Otherwise, we don't need all that rigmarole; just apply
432 ;; the new parameters.
433 (let (newparms allparms tail)
434 (setq allparms (append initial-frame-alist
435 window-system-frame-alist
436 default-frame-alist nil))
437 (if (assq 'height frame-initial-geometry-arguments)
438 (setq allparms (assq-delete-all 'height allparms)))
439 (if (assq 'width frame-initial-geometry-arguments)
440 (setq allparms (assq-delete-all 'width allparms)))
441 (if (assq 'left frame-initial-geometry-arguments)
442 (setq allparms (assq-delete-all 'left allparms)))
443 (if (assq 'top frame-initial-geometry-arguments)
444 (setq allparms (assq-delete-all 'top allparms)))
445 (setq tail allparms)
446 ;; Find just the parms that have changed since we first
447 ;; made this frame. Those are the ones actually set by
448 ;; the init file. For those parms whose values we already knew
449 ;; (such as those spec'd by command line options)
450 ;; it is undesirable to specify the parm again
451 ;; once the user has seen the frame and been able to alter it
452 ;; manually.
453 (let (newval oldval)
454 (dolist (entry tail)
455 (setq oldval (assq (car entry) frame-initial-frame-alist))
456 (setq newval (cdr (assq (car entry) allparms)))
457 (or (and oldval (eq (cdr oldval) newval))
458 (setq newparms
459 (cons (cons (car entry) newval) newparms)))))
460 (setq newparms (nreverse newparms))
462 (let ((new-bg (assq 'background-color newparms)))
463 ;; If the `background-color' parameter is changed, apply
464 ;; it first, then make sure that the `background-mode'
465 ;; parameter and other faces are updated, before applying
466 ;; the other parameters.
467 (when new-bg
468 (modify-frame-parameters frame-initial-frame
469 (list new-bg))
470 (unless (assq 'background-mode newparms)
471 (frame-set-background-mode frame-initial-frame))
472 (face-set-after-frame-default frame-initial-frame)
473 (setq newparms (delq new-bg newparms)))
474 (modify-frame-parameters frame-initial-frame newparms)))))
476 ;; Restore the original buffer.
477 (set-buffer old-buffer)
479 ;; Make sure the initial frame can be GC'd if it is ever deleted.
480 ;; Make sure frame-notice-user-settings does nothing if called twice.
481 (setq frame-notice-user-settings nil)
482 (setq frame-initial-frame nil)))
484 (defun make-initial-minibuffer-frame (display)
485 (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
486 (if display
487 (make-frame-on-display display parms)
488 (make-frame parms))))
490 ;;;; Creation of additional frames, and other frame miscellanea
492 (defun modify-all-frames-parameters (alist)
493 "Modify all current and future frames' parameters according to ALIST.
494 This changes `default-frame-alist' and possibly `initial-frame-alist'.
495 Furthermore, this function removes all parameters in ALIST from
496 `window-system-default-frame-alist'.
497 See help of `modify-frame-parameters' for more information."
498 (dolist (frame (frame-list))
499 (modify-frame-parameters frame alist))
501 (dolist (pair alist) ;; conses to add/replace
502 ;; initial-frame-alist needs setting only when
503 ;; frame-notice-user-settings is true.
504 (and frame-notice-user-settings
505 (setq initial-frame-alist
506 (assq-delete-all (car pair) initial-frame-alist)))
507 (setq default-frame-alist
508 (assq-delete-all (car pair) default-frame-alist))
509 ;; Remove any similar settings from the window-system specific
510 ;; parameters---they would override default-frame-alist.
511 (dolist (w window-system-default-frame-alist)
512 (setcdr w (assq-delete-all (car pair) (cdr w)))))
514 (and frame-notice-user-settings
515 (setq initial-frame-alist (append initial-frame-alist alist)))
516 (setq default-frame-alist (append default-frame-alist alist)))
518 (defun get-other-frame ()
519 "Return some frame other than the current frame.
520 Create one if necessary. Note that the minibuffer frame, if separate,
521 is not considered (see `next-frame')."
522 (if (equal (next-frame) (selected-frame)) (make-frame) (next-frame)))
524 (defun next-multiframe-window ()
525 "Select the next window, regardless of which frame it is on."
526 (interactive)
527 (select-window (next-window (selected-window)
528 (> (minibuffer-depth) 0)
530 (select-frame-set-input-focus (selected-frame)))
532 (defun previous-multiframe-window ()
533 "Select the previous window, regardless of which frame it is on."
534 (interactive)
535 (select-window (previous-window (selected-window)
536 (> (minibuffer-depth) 0)
538 (select-frame-set-input-focus (selected-frame)))
540 (defun window-system-for-display (display)
541 "Return the window system for DISPLAY.
542 Return nil if we don't know how to interpret DISPLAY."
543 ;; MS-Windows doesn't know how to create a GUI frame in a -nw session.
544 (if (and (eq system-type 'windows-nt)
545 (null (window-system)))
547 (cl-loop for descriptor in display-format-alist
548 for pattern = (car descriptor)
549 for system = (cdr descriptor)
550 when (string-match-p pattern display) return system)))
552 (defun make-frame-on-display (display &optional parameters)
553 "Make a frame on display DISPLAY.
554 The optional argument PARAMETERS specifies additional frame parameters."
555 (interactive "sMake frame on display: ")
556 (make-frame (cons (cons 'display display) parameters)))
558 (declare-function x-close-connection "xfns.c" (terminal))
560 (defun close-display-connection (display)
561 "Close the connection to a display, deleting all its associated frames.
562 For DISPLAY, specify either a frame or a display name (a string).
563 If DISPLAY is nil, that stands for the selected frame's display."
564 (interactive
565 (list
566 (let* ((default (frame-parameter nil 'display))
567 (display (completing-read
568 (format "Close display (default %s): " default)
569 (delete-dups
570 (mapcar (lambda (frame)
571 (frame-parameter frame 'display))
572 (frame-list)))
573 nil t nil nil
574 default)))
575 (if (zerop (length display)) default display))))
576 (let ((frames (delq nil
577 (mapcar (lambda (frame)
578 (if (equal display
579 (frame-parameter frame 'display))
580 frame))
581 (frame-list)))))
582 (if (and (consp frames)
583 (not (y-or-n-p (if (cdr frames)
584 (format "Delete %s frames? " (length frames))
585 (format "Delete %s ? " (car frames))))))
586 (error "Abort!")
587 (mapc 'delete-frame frames)
588 (x-close-connection display))))
590 (defun make-frame-command ()
591 "Make a new frame, on the same terminal as the selected frame.
592 If the terminal is a text-only terminal, this also selects the
593 new frame."
594 (interactive)
595 (if (display-graphic-p)
596 (make-frame)
597 (select-frame (make-frame))))
599 (defvar before-make-frame-hook nil
600 "Functions to run before a frame is created.")
602 (defvar after-make-frame-functions nil
603 "Functions to run after a frame is created.
604 The functions are run with one arg, the newly created frame.")
606 (defvar after-setting-font-hook nil
607 "Functions to run after a frame's font has been changed.")
609 ;; Alias, kept temporarily.
610 (define-obsolete-function-alias 'new-frame 'make-frame "22.1")
612 (defvar frame-inherited-parameters '()
613 "Parameters `make-frame' copies from the `selected-frame' to the new frame.")
615 (defvar x-display-name)
617 (defun make-frame (&optional parameters)
618 "Return a newly created frame displaying the current buffer.
619 Optional argument PARAMETERS is an alist of frame parameters for
620 the new frame. Each element of PARAMETERS should have the
621 form (NAME . VALUE), for example:
623 (name . STRING) The frame should be named STRING.
625 (width . NUMBER) The frame should be NUMBER characters in width.
626 (height . NUMBER) The frame should be NUMBER text lines high.
628 You cannot specify either `width' or `height', you must specify
629 neither or both.
631 (minibuffer . t) The frame should have a minibuffer.
632 (minibuffer . nil) The frame should have no minibuffer.
633 (minibuffer . only) The frame should contain only a minibuffer.
634 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
636 (window-system . nil) The frame should be displayed on a terminal device.
637 (window-system . x) The frame should be displayed in an X window.
639 (display . \":0\") The frame should appear on display :0.
641 (terminal . TERMINAL) The frame should use the terminal object TERMINAL.
643 In addition, any parameter specified in `default-frame-alist',
644 but not present in PARAMETERS, is applied.
646 Before creating the frame (via `frame-creation-function-alist'),
647 this function runs the hook `before-make-frame-hook'. After
648 creating the frame, it runs the hook `after-make-frame-functions'
649 with one arg, the newly created frame.
651 If a display parameter is supplied and a window-system is not,
652 guess the window-system from the display.
654 On graphical displays, this function does not itself make the new
655 frame the selected frame. However, the window system may select
656 the new frame according to its own rules."
657 (interactive)
658 (let* ((display (cdr (assq 'display parameters)))
659 (w (cond
660 ((assq 'terminal parameters)
661 (let ((type (terminal-live-p (cdr (assq 'terminal parameters)))))
662 (cond
663 ((eq type t) nil)
664 ((eq type nil) (error "Terminal %s does not exist"
665 (cdr (assq 'terminal parameters))))
666 (t type))))
667 ((assq 'window-system parameters)
668 (cdr (assq 'window-system parameters)))
669 (display
670 (or (window-system-for-display display)
671 (error "Don't know how to interpret display %S"
672 display)))
673 (t window-system)))
674 (frame-creation-function (cdr (assq w frame-creation-function-alist)))
675 (oldframe (selected-frame))
676 (params parameters)
677 frame)
678 (unless frame-creation-function
679 (error "Don't know how to create a frame on window system %s" w))
681 (unless (get w 'window-system-initialized)
682 (funcall (cdr (assq w window-system-initialization-alist)) display)
683 (setq x-display-name display)
684 (put w 'window-system-initialized t))
686 ;; Add parameters from `window-system-default-frame-alist'.
687 (dolist (p (cdr (assq w window-system-default-frame-alist)))
688 (unless (assq (car p) params)
689 (push p params)))
690 ;; Add parameters from `default-frame-alist'.
691 (dolist (p default-frame-alist)
692 (unless (assq (car p) params)
693 (push p params)))
694 ;; Now make the frame.
695 (run-hooks 'before-make-frame-hook)
696 (setq frame (funcall frame-creation-function params))
697 (normal-erase-is-backspace-setup-frame frame)
698 ;; Inherit the original frame's parameters.
699 (dolist (param frame-inherited-parameters)
700 (unless (assq param parameters) ;Overridden by explicit parameters.
701 (let ((val (frame-parameter oldframe param)))
702 (when val (set-frame-parameter frame param val)))))
703 (run-hook-with-args 'after-make-frame-functions frame)
704 frame))
706 (defun filtered-frame-list (predicate)
707 "Return a list of all live frames which satisfy PREDICATE."
708 (let* ((frames (frame-list))
709 (list frames))
710 (while (consp frames)
711 (unless (funcall predicate (car frames))
712 (setcar frames nil))
713 (setq frames (cdr frames)))
714 (delq nil list)))
716 (defun minibuffer-frame-list ()
717 "Return a list of all frames with their own minibuffers."
718 (filtered-frame-list
719 (lambda (frame)
720 (eq frame (window-frame (minibuffer-window frame))))))
722 ;; Used to be called `terminal-id' in termdev.el.
723 (defun get-device-terminal (device)
724 "Return the terminal corresponding to DEVICE.
725 DEVICE can be a terminal, a frame, nil (meaning the selected frame's terminal),
726 the name of an X display device (HOST.SERVER.SCREEN) or a tty device file."
727 (cond
728 ((or (null device) (framep device))
729 (frame-terminal device))
730 ((stringp device)
731 (let ((f (car (filtered-frame-list
732 (lambda (frame)
733 (or (equal (frame-parameter frame 'display) device)
734 (equal (frame-parameter frame 'tty) device)))))))
735 (or f (error "Display %s does not exist" device))
736 (frame-terminal f)))
737 ((terminal-live-p device) device)
739 (error "Invalid argument %s in `get-device-terminal'" device))))
741 (defun frames-on-display-list (&optional device)
742 "Return a list of all frames on DEVICE.
744 DEVICE should be a terminal, a frame,
745 or a name of an X display or tty (a string of the form
746 HOST:SERVER.SCREEN).
748 If DEVICE is omitted or nil, it defaults to the selected
749 frame's terminal device."
750 (let* ((terminal (get-device-terminal device))
751 (func #'(lambda (frame)
752 (eq (frame-terminal frame) terminal))))
753 (filtered-frame-list func)))
755 (defun framep-on-display (&optional terminal)
756 "Return the type of frames on TERMINAL.
757 TERMINAL may be a terminal id, a display name or a frame. If it
758 is a frame, its type is returned. If TERMINAL is omitted or nil,
759 it defaults to the selected frame's terminal device. All frames
760 on a given display are of the same type."
761 (or (terminal-live-p terminal)
762 (framep terminal)
763 (framep (car (frames-on-display-list terminal)))))
765 (defun frame-remove-geometry-params (param-list)
766 "Return the parameter list PARAM-LIST, but with geometry specs removed.
767 This deletes all bindings in PARAM-LIST for `top', `left', `width',
768 `height', `user-size' and `user-position' parameters.
769 Emacs uses this to avoid overriding explicit moves and resizings from
770 the user during startup."
771 (setq param-list (cons nil param-list))
772 (let ((tail param-list))
773 (while (consp (cdr tail))
774 (if (and (consp (car (cdr tail)))
775 (memq (car (car (cdr tail)))
776 '(height width top left user-position user-size)))
777 (progn
778 (setq frame-initial-geometry-arguments
779 (cons (car (cdr tail)) frame-initial-geometry-arguments))
780 (setcdr tail (cdr (cdr tail))))
781 (setq tail (cdr tail)))))
782 (setq frame-initial-geometry-arguments
783 (nreverse frame-initial-geometry-arguments))
784 (cdr param-list))
786 (declare-function x-focus-frame "frame.c" (frame))
788 (defun select-frame-set-input-focus (frame &optional norecord)
789 "Select FRAME, raise it, and set input focus, if possible.
790 If `mouse-autoselect-window' is non-nil, also move mouse pointer
791 to FRAME's selected window. Otherwise, if `focus-follows-mouse'
792 is non-nil, move mouse cursor to FRAME.
794 Optional argument NORECORD means to neither change the order of
795 recently selected windows nor the buffer list."
796 (select-frame frame norecord)
797 (raise-frame frame)
798 ;; Ensure, if possible, that FRAME gets input focus.
799 (when (memq (window-system frame) '(x w32 ns))
800 (x-focus-frame frame))
801 ;; Move mouse cursor if necessary.
802 (cond
803 (mouse-autoselect-window
804 (let ((edges (window-inside-edges (frame-selected-window frame))))
805 ;; Move mouse cursor into FRAME's selected window to avoid that
806 ;; Emacs mouse-autoselects another window.
807 (set-mouse-position frame (nth 2 edges) (nth 1 edges))))
808 (focus-follows-mouse
809 ;; Move mouse cursor into FRAME to avoid that another frame gets
810 ;; selected by the window manager.
811 (set-mouse-position frame (1- (frame-width frame)) 0))))
813 (defun other-frame (arg)
814 "Select the ARGth different visible frame on current display, and raise it.
815 All frames are arranged in a cyclic order.
816 This command selects the frame ARG steps away in that order.
817 A negative ARG moves in the opposite order.
819 To make this command work properly, you must tell Emacs
820 how the system (or the window manager) generally handles
821 focus-switching between windows. If moving the mouse onto a window
822 selects it (gives it focus), set `focus-follows-mouse' to t.
823 Otherwise, that variable should be nil."
824 (interactive "p")
825 (let ((frame (selected-frame)))
826 (while (> arg 0)
827 (setq frame (next-frame frame))
828 (while (not (eq (frame-visible-p frame) t))
829 (setq frame (next-frame frame)))
830 (setq arg (1- arg)))
831 (while (< arg 0)
832 (setq frame (previous-frame frame))
833 (while (not (eq (frame-visible-p frame) t))
834 (setq frame (previous-frame frame)))
835 (setq arg (1+ arg)))
836 (select-frame-set-input-focus frame)))
838 (defun iconify-or-deiconify-frame ()
839 "Iconify the selected frame, or deiconify if it's currently an icon."
840 (interactive)
841 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
842 (iconify-frame)
843 (make-frame-visible)))
845 (defun suspend-frame ()
846 "Do whatever is right to suspend the current frame.
847 Calls `suspend-emacs' if invoked from the controlling tty device,
848 `suspend-tty' from a secondary tty device, and
849 `iconify-or-deiconify-frame' from an X frame."
850 (interactive)
851 (let ((type (framep (selected-frame))))
852 (cond
853 ((memq type '(x ns w32)) (iconify-or-deiconify-frame))
854 ((eq type t)
855 (if (controlling-tty-p)
856 (suspend-emacs)
857 (suspend-tty)))
858 (t (suspend-emacs)))))
860 (defun make-frame-names-alist ()
861 ;; Only consider the frames on the same display.
862 (let* ((current-frame (selected-frame))
863 (falist
864 (cons
865 (cons (frame-parameter current-frame 'name) current-frame) nil))
866 (frame (next-frame nil 0)))
867 (while (not (eq frame current-frame))
868 (progn
869 (push (cons (frame-parameter frame 'name) frame) falist)
870 (setq frame (next-frame frame 0))))
871 falist))
873 (defvar frame-name-history nil)
874 (defun select-frame-by-name (name)
875 "Select the frame on the current terminal whose name is NAME and raise it.
876 If there is no frame by that name, signal an error."
877 (interactive
878 (let* ((frame-names-alist (make-frame-names-alist))
879 (default (car (car frame-names-alist)))
880 (input (completing-read
881 (format "Select Frame (default %s): " default)
882 frame-names-alist nil t nil 'frame-name-history)))
883 (if (= (length input) 0)
884 (list default)
885 (list input))))
886 (let* ((frame-names-alist (make-frame-names-alist))
887 (frame (cdr (assoc name frame-names-alist))))
888 (if frame
889 (select-frame-set-input-focus frame)
890 (error "There is no frame named `%s'" name))))
893 ;;;; Background mode.
895 (defcustom frame-background-mode nil
896 "The brightness of the background.
897 Set this to the symbol `dark' if your background color is dark,
898 `light' if your background is light, or nil (automatic by default)
899 if you want Emacs to examine the brightness for you.
901 If you change this without using customize, you should use
902 `frame-set-background-mode' to update existing frames;
903 e.g. (mapc 'frame-set-background-mode (frame-list))."
904 :group 'faces
905 :set #'(lambda (var value)
906 (set-default var value)
907 (mapc 'frame-set-background-mode (frame-list)))
908 :initialize 'custom-initialize-changed
909 :type '(choice (const dark)
910 (const light)
911 (const :tag "automatic" nil)))
913 (declare-function x-get-resource "frame.c"
914 (attribute class &optional component subclass))
916 ;; Only used if window-system is not null.
917 (declare-function x-display-grayscale-p "xfns.c" (&optional terminal))
919 (defvar inhibit-frame-set-background-mode nil)
921 (defun frame-set-background-mode (frame &optional keep-face-specs)
922 "Set up display-dependent faces on FRAME.
923 Display-dependent faces are those which have different definitions
924 according to the `background-mode' and `display-type' frame parameters.
926 If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate
927 face specs for the new background mode."
928 (unless inhibit-frame-set-background-mode
929 (let* ((frame-default-bg-mode (frame-terminal-default-bg-mode frame))
930 (bg-color (frame-parameter frame 'background-color))
931 (tty-type (tty-type frame))
932 (default-bg-mode
933 (if (or (window-system frame)
934 (and tty-type
935 (string-match "^\\(xterm\\|\\rxvt\\|dtterm\\|eterm\\)"
936 tty-type)))
937 'light
938 'dark))
939 (non-default-bg-mode (if (eq default-bg-mode 'light) 'dark 'light))
940 (bg-mode
941 (cond (frame-default-bg-mode)
942 ((equal bg-color "unspecified-fg") ; inverted colors
943 non-default-bg-mode)
944 ((not (color-values bg-color frame))
945 default-bg-mode)
946 ((>= (apply '+ (color-values bg-color frame))
947 ;; Just looking at the screen, colors whose
948 ;; values add up to .6 of the white total
949 ;; still look dark to me.
950 (* (apply '+ (color-values "white" frame)) .6))
951 'light)
952 (t 'dark)))
953 (display-type
954 (cond ((null (window-system frame))
955 (if (tty-display-color-p frame) 'color 'mono))
956 ((display-color-p frame)
957 'color)
958 ((x-display-grayscale-p frame)
959 'grayscale)
960 (t 'mono)))
961 (old-bg-mode
962 (frame-parameter frame 'background-mode))
963 (old-display-type
964 (frame-parameter frame 'display-type)))
966 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
967 (let ((locally-modified-faces nil)
968 ;; Prevent face-spec-recalc from calling this function
969 ;; again, resulting in a loop (bug#911).
970 (inhibit-frame-set-background-mode t)
971 (params (list (cons 'background-mode bg-mode)
972 (cons 'display-type display-type))))
973 (if keep-face-specs
974 (modify-frame-parameters frame params)
975 ;; If we are recomputing face specs, first collect a list
976 ;; of faces that don't match their face-specs. These are
977 ;; the faces modified on FRAME, and we avoid changing them
978 ;; below. Use a negative list to avoid consing (we assume
979 ;; most faces are unmodified).
980 (dolist (face (face-list))
981 (and (not (get face 'face-override-spec))
982 (not (face-spec-match-p face
983 (face-user-default-spec face)
984 (selected-frame)))
985 (push face locally-modified-faces)))
986 ;; Now change to the new frame parameters
987 (modify-frame-parameters frame params)
988 ;; For all unmodified named faces, choose face specs
989 ;; matching the new frame parameters.
990 (dolist (face (face-list))
991 (unless (memq face locally-modified-faces)
992 (face-spec-recalc face frame)))))))))
994 (defun frame-terminal-default-bg-mode (frame)
995 "Return the default background mode of FRAME.
996 This checks the `frame-background-mode' variable, the X resource
997 named \"backgroundMode\" (if FRAME is an X frame), and finally
998 the `background-mode' terminal parameter."
999 (or frame-background-mode
1000 (let ((bg-resource
1001 (and (window-system frame)
1002 (x-get-resource "backgroundMode" "BackgroundMode"))))
1003 (if bg-resource
1004 (intern (downcase bg-resource))))
1005 (terminal-parameter frame 'background-mode)))
1008 ;;;; Frame configurations
1010 (defun current-frame-configuration ()
1011 "Return a list describing the positions and states of all frames.
1012 Its car is `frame-configuration'.
1013 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
1014 where
1015 FRAME is a frame object,
1016 ALIST is an association list specifying some of FRAME's parameters, and
1017 WINDOW-CONFIG is a window configuration object for FRAME."
1018 (cons 'frame-configuration
1019 (mapcar (lambda (frame)
1020 (list frame
1021 (frame-parameters frame)
1022 (current-window-configuration frame)))
1023 (frame-list))))
1025 (defun set-frame-configuration (configuration &optional nodelete)
1026 "Restore the frames to the state described by CONFIGURATION.
1027 Each frame listed in CONFIGURATION has its position, size, window
1028 configuration, and other parameters set as specified in CONFIGURATION.
1029 However, this function does not restore deleted frames.
1031 Ordinarily, this function deletes all existing frames not
1032 listed in CONFIGURATION. But if optional second argument NODELETE
1033 is given and non-nil, the unwanted frames are iconified instead."
1034 (or (frame-configuration-p configuration)
1035 (signal 'wrong-type-argument
1036 (list 'frame-configuration-p configuration)))
1037 (let ((config-alist (cdr configuration))
1038 frames-to-delete)
1039 (dolist (frame (frame-list))
1040 (let ((parameters (assq frame config-alist)))
1041 (if parameters
1042 (progn
1043 (modify-frame-parameters
1044 frame
1045 ;; Since we can't set a frame's minibuffer status,
1046 ;; we might as well omit the parameter altogether.
1047 (let* ((parms (nth 1 parameters))
1048 (mini (assq 'minibuffer parms))
1049 (name (assq 'name parms))
1050 (explicit-name (cdr (assq 'explicit-name parms))))
1051 (when mini (setq parms (delq mini parms)))
1052 ;; Leave name in iff it was set explicitly.
1053 ;; This should fix the behavior reported in
1054 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg01632.html
1055 (when (and name (not explicit-name))
1056 (setq parms (delq name parms)))
1057 parms))
1058 (set-window-configuration (nth 2 parameters)))
1059 (setq frames-to-delete (cons frame frames-to-delete)))))
1060 (mapc (if nodelete
1061 ;; Note: making frames invisible here was tried
1062 ;; but led to some strange behavior--each time the frame
1063 ;; was made visible again, the window manager asked afresh
1064 ;; for where to put it.
1065 'iconify-frame
1066 'delete-frame)
1067 frames-to-delete)))
1069 ;;;; Convenience functions for accessing and interactively changing
1070 ;;;; frame parameters.
1072 (defun frame-height (&optional frame)
1073 "Return number of lines available for display on FRAME.
1074 If FRAME is omitted, describe the currently selected frame.
1075 Exactly what is included in the return value depends on the
1076 window-system and toolkit in use - see `frame-pixel-height' for
1077 more details. The lines are in units of the default font height.
1079 The result is roughly related to the frame pixel height via
1080 height in pixels = height in lines * `frame-char-height'.
1081 However, this is only approximate, and is complicated e.g. by the
1082 fact that individual window lines and menu bar lines can have
1083 differing font heights."
1084 (cdr (assq 'height (frame-parameters frame))))
1086 (defun frame-width (&optional frame)
1087 "Return number of columns available for display on FRAME.
1088 If FRAME is omitted, describe the currently selected frame."
1089 (cdr (assq 'width (frame-parameters frame))))
1091 (declare-function x-list-fonts "xfaces.c"
1092 (pattern &optional face frame maximum width))
1094 (define-obsolete-function-alias 'set-default-font 'set-frame-font "23.1")
1096 (defun set-frame-font (font &optional keep-size frames)
1097 "Set the default font to FONT.
1098 When called interactively, prompt for the name of a font, and use
1099 that font on the selected frame. When called from Lisp, FONT
1100 should be a font name (a string), a font object, font entity, or
1101 font spec.
1103 If KEEP-SIZE is nil, keep the number of frame lines and columns
1104 fixed. If KEEP-SIZE is non-nil (or with a prefix argument), try
1105 to keep the current frame size fixed (in pixels) by adjusting the
1106 number of lines and columns.
1108 If FRAMES is nil, apply the font to the selected frame only.
1109 If FRAMES is non-nil, it should be a list of frames to act upon,
1110 or t meaning all existing graphical frames.
1111 Also, if FRAMES is non-nil, alter the user's Customization settings
1112 as though the font-related attributes of the `default' face had been
1113 \"set in this session\", so that the font is applied to future frames."
1114 (interactive
1115 (let* ((completion-ignore-case t)
1116 (font (completing-read "Font name: "
1117 ;; x-list-fonts will fail with an error
1118 ;; if this frame doesn't support fonts.
1119 (x-list-fonts "*" nil (selected-frame))
1120 nil nil nil nil
1121 (frame-parameter nil 'font))))
1122 (list font current-prefix-arg nil)))
1123 (when (or (stringp font) (fontp font))
1124 (let* ((this-frame (selected-frame))
1125 ;; FRAMES nil means affect the selected frame.
1126 (frame-list (cond ((null frames)
1127 (list this-frame))
1128 ((eq frames t)
1129 (frame-list))
1130 (t frames)))
1131 height width)
1132 (dolist (f frame-list)
1133 (when (display-multi-font-p f)
1134 (if keep-size
1135 (setq height (* (frame-parameter f 'height)
1136 (frame-char-height f))
1137 width (* (frame-parameter f 'width)
1138 (frame-char-width f))))
1139 ;; When set-face-attribute is called for :font, Emacs
1140 ;; guesses the best font according to other face attributes
1141 ;; (:width, :weight, etc.) so reset them too (Bug#2476).
1142 (set-face-attribute 'default f
1143 :width 'normal :weight 'normal
1144 :slant 'normal :font font)
1145 (if keep-size
1146 (modify-frame-parameters
1148 (list (cons 'height (round height (frame-char-height f)))
1149 (cons 'width (round width (frame-char-width f))))))))
1150 (when frames
1151 ;; Alter the user's Custom setting of the `default' face, but
1152 ;; only for font-related attributes.
1153 (let ((specs (cadr (assq 'user (get 'default 'theme-face))))
1154 (attrs '(:family :foundry :slant :weight :height :width))
1155 (new-specs nil))
1156 (if (null specs) (setq specs '((t nil))))
1157 (dolist (spec specs)
1158 ;; Each SPEC has the form (DISPLAY ATTRIBUTE-PLIST)
1159 (let ((display (nth 0 spec))
1160 (plist (copy-tree (nth 1 spec))))
1161 ;; Alter only DISPLAY conditions matching this frame.
1162 (when (or (memq display '(t default))
1163 (face-spec-set-match-display display this-frame))
1164 (dolist (attr attrs)
1165 (setq plist (plist-put plist attr
1166 (face-attribute 'default attr)))))
1167 (push (list display plist) new-specs)))
1168 (setq new-specs (nreverse new-specs))
1169 (put 'default 'customized-face new-specs)
1170 (custom-push-theme 'theme-face 'default 'user 'set new-specs)
1171 (put 'default 'face-modified nil))))
1172 (run-hooks 'after-setting-font-hook 'after-setting-font-hooks)))
1174 (defun set-frame-parameter (frame parameter value)
1175 "Set frame parameter PARAMETER to VALUE on FRAME.
1176 If FRAME is nil, it defaults to the selected frame.
1177 See `modify-frame-parameters'."
1178 (modify-frame-parameters frame (list (cons parameter value))))
1180 (defun set-background-color (color-name)
1181 "Set the background color of the selected frame to COLOR-NAME.
1182 When called interactively, prompt for the name of the color to use.
1183 To get the frame's current background color, use `frame-parameters'."
1184 (interactive (list (read-color "Background color: ")))
1185 (modify-frame-parameters (selected-frame)
1186 (list (cons 'background-color color-name)))
1187 (or window-system
1188 (face-set-after-frame-default (selected-frame))))
1190 (defun set-foreground-color (color-name)
1191 "Set the foreground color of the selected frame to COLOR-NAME.
1192 When called interactively, prompt for the name of the color to use.
1193 To get the frame's current foreground color, use `frame-parameters'."
1194 (interactive (list (read-color "Foreground color: ")))
1195 (modify-frame-parameters (selected-frame)
1196 (list (cons 'foreground-color color-name)))
1197 (or window-system
1198 (face-set-after-frame-default (selected-frame))))
1200 (defun set-cursor-color (color-name)
1201 "Set the text cursor color of the selected frame to COLOR-NAME.
1202 When called interactively, prompt for the name of the color to use.
1203 This works by setting the `cursor-color' frame parameter on the
1204 selected frame.
1206 You can also set the text cursor color, for all frames, by
1207 customizing the `cursor' face."
1208 (interactive (list (read-color "Cursor color: ")))
1209 (modify-frame-parameters (selected-frame)
1210 (list (cons 'cursor-color color-name))))
1212 (defun set-mouse-color (color-name)
1213 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
1214 When called interactively, prompt for the name of the color to use.
1215 To get the frame's current mouse color, use `frame-parameters'."
1216 (interactive (list (read-color "Mouse color: ")))
1217 (modify-frame-parameters (selected-frame)
1218 (list (cons 'mouse-color
1219 (or color-name
1220 (cdr (assq 'mouse-color
1221 (frame-parameters))))))))
1223 (defun set-border-color (color-name)
1224 "Set the color of the border of the selected frame to COLOR-NAME.
1225 When called interactively, prompt for the name of the color to use.
1226 To get the frame's current border color, use `frame-parameters'."
1227 (interactive (list (read-color "Border color: ")))
1228 (modify-frame-parameters (selected-frame)
1229 (list (cons 'border-color color-name))))
1231 (define-minor-mode auto-raise-mode
1232 "Toggle whether or not selected frames should auto-raise.
1233 With a prefix argument ARG, enable Auto Raise mode if ARG is
1234 positive, and disable it otherwise. If called from Lisp, enable
1235 the mode if ARG is omitted or nil.
1237 Auto Raise mode does nothing under most window managers, which
1238 switch focus on mouse clicks. It only has an effect if your
1239 window manager switches focus on mouse movement (in which case
1240 you should also change `focus-follows-mouse' to t). Then,
1241 enabling Auto Raise mode causes any graphical Emacs frame which
1242 acquires focus to be automatically raised.
1244 Note that this minor mode controls Emacs's own auto-raise
1245 feature. Window managers that switch focus on mouse movement
1246 often have their own auto-raise feature."
1247 :variable (frame-parameter nil 'auto-raise)
1248 (if (frame-parameter nil 'auto-raise)
1249 (raise-frame)))
1251 (define-minor-mode auto-lower-mode
1252 "Toggle whether or not the selected frame should auto-lower.
1253 With a prefix argument ARG, enable Auto Lower mode if ARG is
1254 positive, and disable it otherwise. If called from Lisp, enable
1255 the mode if ARG is omitted or nil.
1257 Auto Lower mode does nothing under most window managers, which
1258 switch focus on mouse clicks. It only has an effect if your
1259 window manager switches focus on mouse movement (in which case
1260 you should also change `focus-follows-mouse' to t). Then,
1261 enabling Auto Lower Mode causes any graphical Emacs frame which
1262 loses focus to be automatically lowered.
1264 Note that this minor mode controls Emacs's own auto-lower
1265 feature. Window managers that switch focus on mouse movement
1266 often have their own features for raising or lowering frames."
1267 :variable (frame-parameter nil 'auto-lower))
1269 (defun set-frame-name (name)
1270 "Set the name of the selected frame to NAME.
1271 When called interactively, prompt for the name of the frame.
1272 On text terminals, the frame name is displayed on the mode line.
1273 On graphical displays, it is displayed on the frame's title bar."
1274 (interactive "sFrame name: ")
1275 (modify-frame-parameters (selected-frame)
1276 (list (cons 'name name))))
1278 (defun frame-current-scroll-bars (&optional frame)
1279 "Return the current scroll-bar settings in frame FRAME.
1280 Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies the
1281 current location of the vertical scroll-bars (left, right, or nil),
1282 and HORIZONTAL specifies the current location of the horizontal scroll
1283 bars (top, bottom, or nil)."
1284 (let ((vert (frame-parameter frame 'vertical-scroll-bars))
1285 (hor nil))
1286 (unless (memq vert '(left right nil))
1287 (setq vert default-frame-scroll-bars))
1288 (cons vert hor)))
1290 (defun frame-monitor-attributes (&optional frame)
1291 "Return the attributes of the physical monitor dominating FRAME.
1292 If FRAME is omitted or nil, describe the currently selected frame.
1294 A frame is dominated by a physical monitor when either the
1295 largest area of the frame resides in the monitor, or the monitor
1296 is the closest to the frame if the frame does not intersect any
1297 physical monitors.
1299 See `display-monitor-attributes-list' for the list of attribute
1300 keys and their meanings."
1301 (or frame (setq frame (selected-frame)))
1302 (cl-loop for attributes in (display-monitor-attributes-list frame)
1303 for frames = (cdr (assq 'frames attributes))
1304 if (memq frame frames) return attributes))
1307 ;;;; Frame/display capabilities.
1309 (declare-function msdos-mouse-p "dosfns.c")
1311 (defun display-mouse-p (&optional display)
1312 "Return non-nil if DISPLAY has a mouse available.
1313 DISPLAY can be a display name, a frame, or nil (meaning the selected
1314 frame's display)."
1315 (let ((frame-type (framep-on-display display)))
1316 (cond
1317 ((eq frame-type 'pc)
1318 (msdos-mouse-p))
1319 ((eq frame-type 'w32)
1320 (with-no-warnings
1321 (> w32-num-mouse-buttons 0)))
1322 ((memq frame-type '(x ns))
1323 t) ;; We assume X and NeXTstep *always* have a pointing device
1325 (or (and (featurep 'xt-mouse)
1326 xterm-mouse-mode)
1327 ;; t-mouse is distributed with the GPM package. It doesn't have
1328 ;; a toggle.
1329 (featurep 't-mouse)
1330 ;; No way to check whether a w32 console has a mouse, assume
1331 ;; it always does.
1332 (boundp 'w32-use-full-screen-buffer))))))
1334 (defun display-popup-menus-p (&optional display)
1335 "Return non-nil if popup menus are supported on DISPLAY.
1336 DISPLAY can be a display name, a frame, or nil (meaning the selected
1337 frame's display).
1338 Support for popup menus requires that the mouse be available."
1339 (display-mouse-p display))
1341 (defun display-graphic-p (&optional display)
1342 "Return non-nil if DISPLAY is a graphic display.
1343 Graphical displays are those which are capable of displaying several
1344 frames and several different fonts at once. This is true for displays
1345 that use a window system such as X, and false for text-only terminals.
1346 DISPLAY can be a display name, a frame, or nil (meaning the selected
1347 frame's display)."
1348 (not (null (memq (framep-on-display display) '(x w32 ns)))))
1350 (defun display-images-p (&optional display)
1351 "Return non-nil if DISPLAY can display images.
1353 DISPLAY can be a display name, a frame, or nil (meaning the selected
1354 frame's display)."
1355 (and (display-graphic-p display)
1356 (fboundp 'image-mask-p)
1357 (fboundp 'image-size)))
1359 (defalias 'display-multi-frame-p 'display-graphic-p)
1360 (defalias 'display-multi-font-p 'display-graphic-p)
1362 (defun display-selections-p (&optional display)
1363 "Return non-nil if DISPLAY supports selections.
1364 A selection is a way to transfer text or other data between programs
1365 via special system buffers called `selection' or `clipboard'.
1366 DISPLAY can be a display name, a frame, or nil (meaning the selected
1367 frame's display)."
1368 (let ((frame-type (framep-on-display display)))
1369 (cond
1370 ((eq frame-type 'pc)
1371 ;; MS-DOG frames support selections when Emacs runs inside
1372 ;; the Windows' DOS Box.
1373 (with-no-warnings
1374 (not (null dos-windows-version))))
1375 ((memq frame-type '(x w32 ns))
1378 nil))))
1380 (declare-function x-display-screens "xfns.c" (&optional terminal))
1382 (defun display-screens (&optional display)
1383 "Return the number of screens associated with DISPLAY.
1384 DISPLAY should be either a frame or a display name (a string).
1385 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1386 (let ((frame-type (framep-on-display display)))
1387 (cond
1388 ((memq frame-type '(x w32 ns))
1389 (x-display-screens display))
1391 1))))
1393 (declare-function x-display-pixel-height "xfns.c" (&optional terminal))
1395 (defun display-pixel-height (&optional display)
1396 "Return the height of DISPLAY's screen in pixels.
1397 DISPLAY can be a display name or a frame.
1398 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1400 For character terminals, each character counts as a single pixel.
1402 For graphical terminals, note that on \"multi-monitor\" setups this
1403 refers to the pixel height for all physical monitors associated
1404 with DISPLAY. To get information for each physical monitor, use
1405 `display-monitor-attributes-list'."
1406 (let ((frame-type (framep-on-display display)))
1407 (cond
1408 ((memq frame-type '(x w32 ns))
1409 (x-display-pixel-height display))
1411 (frame-height (if (framep display) display (selected-frame)))))))
1413 (declare-function x-display-pixel-width "xfns.c" (&optional terminal))
1415 (defun display-pixel-width (&optional display)
1416 "Return the width of DISPLAY's screen in pixels.
1417 DISPLAY can be a display name or a frame.
1418 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1420 For character terminals, each character counts as a single pixel.
1422 For graphical terminals, note that on \"multi-monitor\" setups this
1423 refers to the pixel width for all physical monitors associated
1424 with DISPLAY. To get information for each physical monitor, use
1425 `display-monitor-attributes-list'."
1426 (let ((frame-type (framep-on-display display)))
1427 (cond
1428 ((memq frame-type '(x w32 ns))
1429 (x-display-pixel-width display))
1431 (frame-width (if (framep display) display (selected-frame)))))))
1433 (defcustom display-mm-dimensions-alist nil
1434 "Alist for specifying screen dimensions in millimeters.
1435 The functions `display-mm-height' and `display-mm-width' consult
1436 this list before asking the system.
1438 Each element has the form (DISPLAY . (WIDTH . HEIGHT)), e.g.
1439 \(\":0.0\" . (287 . 215)).
1441 If `display' is t, it specifies dimensions for all graphical displays
1442 not explicitly specified."
1443 :version "22.1"
1444 :type '(alist :key-type (choice (string :tag "Display name")
1445 (const :tag "Default" t))
1446 :value-type (cons :tag "Dimensions"
1447 (integer :tag "Width")
1448 (integer :tag "Height")))
1449 :group 'frames)
1451 (declare-function x-display-mm-height "xfns.c" (&optional terminal))
1453 (defun display-mm-height (&optional display)
1454 "Return the height of DISPLAY's screen in millimeters.
1455 If the information is unavailable, this function returns nil.
1456 DISPLAY can be a display name or a frame.
1457 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1459 You can override what the system thinks the result should be by
1460 adding an entry to `display-mm-dimensions-alist'.
1462 For graphical terminals, note that on \"multi-monitor\" setups this
1463 refers to the height in millimeters for all physical monitors
1464 associated with DISPLAY. To get information for each physical
1465 monitor, use `display-monitor-attributes-list'."
1466 (and (memq (framep-on-display display) '(x w32 ns))
1467 (or (cddr (assoc (or display (frame-parameter nil 'display))
1468 display-mm-dimensions-alist))
1469 (cddr (assoc t display-mm-dimensions-alist))
1470 (x-display-mm-height display))))
1472 (declare-function x-display-mm-width "xfns.c" (&optional terminal))
1474 (defun display-mm-width (&optional display)
1475 "Return the width of DISPLAY's screen in millimeters.
1476 If the information is unavailable, this function returns nil.
1477 DISPLAY can be a display name or a frame.
1478 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1480 You can override what the system thinks the result should be by
1481 adding an entry to `display-mm-dimensions-alist'.
1483 For graphical terminals, note that on \"multi-monitor\" setups this
1484 refers to the width in millimeters for all physical monitors
1485 associated with DISPLAY. To get information for each physical
1486 monitor, use `display-monitor-attributes-list'."
1487 (and (memq (framep-on-display display) '(x w32 ns))
1488 (or (cadr (assoc (or display (frame-parameter nil 'display))
1489 display-mm-dimensions-alist))
1490 (cadr (assoc t display-mm-dimensions-alist))
1491 (x-display-mm-width display))))
1493 (declare-function x-display-backing-store "xfns.c" (&optional terminal))
1495 ;; In NS port, the return value may be `buffered', `retained', or
1496 ;; `non-retained'. See src/nsfns.m.
1497 (defun display-backing-store (&optional display)
1498 "Return the backing store capability of DISPLAY's screen.
1499 The value may be `always', `when-mapped', `not-useful', or nil if
1500 the question is inapplicable to a certain kind of display.
1501 DISPLAY can be a display name or a frame.
1502 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1503 (let ((frame-type (framep-on-display display)))
1504 (cond
1505 ((memq frame-type '(x w32 ns))
1506 (x-display-backing-store display))
1508 'not-useful))))
1510 (declare-function x-display-save-under "xfns.c" (&optional terminal))
1512 (defun display-save-under (&optional display)
1513 "Return non-nil if DISPLAY's screen supports the SaveUnder feature.
1514 DISPLAY can be a display name or a frame.
1515 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1516 (let ((frame-type (framep-on-display display)))
1517 (cond
1518 ((memq frame-type '(x w32 ns))
1519 (x-display-save-under display))
1521 'not-useful))))
1523 (declare-function x-display-planes "xfns.c" (&optional terminal))
1525 (defun display-planes (&optional display)
1526 "Return the number of planes supported by DISPLAY.
1527 DISPLAY can be a display name or a frame.
1528 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1529 (let ((frame-type (framep-on-display display)))
1530 (cond
1531 ((memq frame-type '(x w32 ns))
1532 (x-display-planes display))
1533 ((eq frame-type 'pc)
1536 (truncate (log (length (tty-color-alist)) 2))))))
1538 (declare-function x-display-color-cells "xfns.c" (&optional terminal))
1540 (defun display-color-cells (&optional display)
1541 "Return the number of color cells supported by DISPLAY.
1542 DISPLAY can be a display name or a frame.
1543 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1544 (let ((frame-type (framep-on-display display)))
1545 (cond
1546 ((memq frame-type '(x w32 ns))
1547 (x-display-color-cells display))
1548 ((eq frame-type 'pc)
1551 (tty-display-color-cells display)))))
1553 (declare-function x-display-visual-class "xfns.c" (&optional terminal))
1555 (defun display-visual-class (&optional display)
1556 "Return the visual class of DISPLAY.
1557 The value is one of the symbols `static-gray', `gray-scale',
1558 `static-color', `pseudo-color', `true-color', or `direct-color'.
1559 DISPLAY can be a display name or a frame.
1560 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1561 (let ((frame-type (framep-on-display display)))
1562 (cond
1563 ((memq frame-type '(x w32 ns))
1564 (x-display-visual-class display))
1565 ((and (memq frame-type '(pc t))
1566 (tty-display-color-p display))
1567 'static-color)
1569 'static-gray))))
1571 (declare-function x-display-monitor-attributes-list "xfns.c"
1572 (&optional terminal))
1573 (declare-function w32-display-monitor-attributes-list "w32fns.c"
1574 (&optional display))
1575 (declare-function ns-display-monitor-attributes-list "nsfns.m"
1576 (&optional terminal))
1578 (defun display-monitor-attributes-list (&optional display)
1579 "Return a list of physical monitor attributes on DISPLAY.
1580 DISPLAY can be a display name, a terminal name, or a frame.
1581 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1582 Each element of the list represents the attributes of a physical
1583 monitor. The first element corresponds to the primary monitor.
1585 The attributes for a physical monitor are represented as an alist
1586 of attribute keys and values as follows:
1588 geometry -- Position and size in pixels in the form of (X Y WIDTH HEIGHT)
1589 workarea -- Position and size of the work area in pixels in the
1590 form of (X Y WIDTH HEIGHT)
1591 mm-size -- Width and height in millimeters in the form of
1592 (WIDTH HEIGHT)
1593 frames -- List of frames dominated by the physical monitor
1594 name (*) -- Name of the physical monitor as a string
1595 source (*) -- Source of multi-monitor information as a string
1597 where X, Y, WIDTH, and HEIGHT are integers. X and Y are coordinates
1598 of the top-left corner, and might be negative for monitors other than
1599 the primary one. Keys labeled with (*) are optional.
1601 The \"work area\" is a measure of the \"usable\" display space.
1602 It may be less than the total screen size, owing to space taken up
1603 by window manager features (docks, taskbars, etc.). The precise
1604 details depend on the platform and environment.
1606 The `source' attribute describes the source from which the information
1607 was obtained. On X, this may be one of: \"Gdk\", \"XRandr\", \"Xinerama\",
1608 or \"fallback\".
1610 A frame is dominated by a physical monitor when either the
1611 largest area of the frame resides in the monitor, or the monitor
1612 is the closest to the frame if the frame does not intersect any
1613 physical monitors. Every (non-tooltip) frame (including invisible ones)
1614 in a graphical display is dominated by exactly one physical
1615 monitor at a time, though it can span multiple (or no) physical
1616 monitors."
1617 (let ((frame-type (framep-on-display display)))
1618 (cond
1619 ((eq frame-type 'x)
1620 (x-display-monitor-attributes-list display))
1621 ((eq frame-type 'w32)
1622 (w32-display-monitor-attributes-list display))
1623 ((eq frame-type 'ns)
1624 (ns-display-monitor-attributes-list display))
1626 (let ((geometry (list 0 0 (display-pixel-width display)
1627 (display-pixel-height display))))
1628 `(((geometry . ,geometry)
1629 (workarea . ,geometry)
1630 (mm-size . (,(display-mm-width display)
1631 ,(display-mm-height display)))
1632 (frames . ,(frames-on-display-list display)))))))))
1635 ;;;; Frame geometry values
1637 (defun frame-geom-value-cons (type value &optional frame)
1638 "Return equivalent geometry value for FRAME as a cons with car `+'.
1639 A geometry value equivalent to VALUE for FRAME is returned,
1640 where the value is a cons with car `+', not numeric.
1641 TYPE is the car of the original geometry spec (TYPE . VALUE).
1642 It is `top' or `left', depending on which edge VALUE is related to.
1643 VALUE is the cdr of a frame geometry spec: (left/top . VALUE).
1644 If VALUE is a number, then it is converted to a cons value, perhaps
1645 relative to the opposite frame edge from that in the original spec.
1646 FRAME defaults to the selected frame.
1648 Examples (measures in pixels) -
1649 Assuming display height/width=1024, frame height/width=600:
1650 300 inside display edge: 300 => (+ 300)
1651 (+ 300) => (+ 300)
1652 300 inside opposite display edge: (- 300) => (+ 124)
1653 -300 => (+ 124)
1654 300 beyond display edge
1655 (= 724 inside opposite display edge): (+ -300) => (+ -300)
1656 300 beyond display edge
1657 (= 724 inside opposite display edge): (- -300) => (+ 724)
1659 In the 3rd, 4th, and 6th examples, the returned value is relative to
1660 the opposite frame edge from the edge indicated in the input spec."
1661 (cond ((and (consp value) (eq '+ (car value))) ; e.g. (+ 300), (+ -300)
1662 value)
1663 ((natnump value) (list '+ value)) ; e.g. 300 => (+ 300)
1664 (t ; e.g. -300, (- 300), (- -300)
1665 (list '+ (- (if (eq 'left type) ; => (+ 124), (+ 124), (+ 724)
1666 (x-display-pixel-width)
1667 (x-display-pixel-height))
1668 (if (integerp value) (- value) (cadr value))
1669 (if (eq 'left type)
1670 (frame-pixel-width frame)
1671 (frame-pixel-height frame)))))))
1673 (defun frame-geom-spec-cons (spec &optional frame)
1674 "Return equivalent geometry spec for FRAME as a cons with car `+'.
1675 A geometry specification equivalent to SPEC for FRAME is returned,
1676 where the value is a cons with car `+', not numeric.
1677 SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE).
1678 If VALUE is a number, then it is converted to a cons value, perhaps
1679 relative to the opposite frame edge from that in the original spec.
1680 FRAME defaults to the selected frame.
1682 Examples (measures in pixels) -
1683 Assuming display height=1024, frame height=600:
1684 top 300 below display top: (top . 300) => (top + 300)
1685 (top + 300) => (top + 300)
1686 bottom 300 above display bottom: (top - 300) => (top + 124)
1687 (top . -300) => (top + 124)
1688 top 300 above display top
1689 (= bottom 724 above display bottom): (top + -300) => (top + -300)
1690 bottom 300 below display bottom
1691 (= top 724 below display top): (top - -300) => (top + 724)
1693 In the 3rd, 4th, and 6th examples, the returned value is relative to
1694 the opposite frame edge from the edge indicated in the input spec."
1695 (cons (car spec) (frame-geom-value-cons (car spec) (cdr spec) frame)))
1698 (defun delete-other-frames (&optional frame)
1699 "Delete all frames on the current terminal, except FRAME.
1700 If FRAME uses another frame's minibuffer, the minibuffer frame is
1701 left untouched. FRAME nil or omitted means use the selected frame."
1702 (interactive)
1703 (unless frame
1704 (setq frame (selected-frame)))
1705 (let* ((mini-frame (window-frame (minibuffer-window frame)))
1706 (frames (delq mini-frame (delq frame (frame-list)))))
1707 ;; Only consider frames on the same terminal.
1708 (dolist (frame (prog1 frames (setq frames nil)))
1709 (if (eq (frame-terminal) (frame-terminal frame))
1710 (push frame frames)))
1711 ;; Delete mon-minibuffer-only frames first, because `delete-frame'
1712 ;; signals an error when trying to delete a mini-frame that's
1713 ;; still in use by another frame.
1714 (dolist (frame frames)
1715 (unless (eq (frame-parameter frame 'minibuffer) 'only)
1716 (delete-frame frame)))
1717 ;; Delete minibuffer-only frames.
1718 (dolist (frame frames)
1719 (when (eq (frame-parameter frame 'minibuffer) 'only)
1720 (delete-frame frame)))))
1722 ;; miscellaneous obsolescence declarations
1723 (define-obsolete-variable-alias 'delete-frame-hook
1724 'delete-frame-functions "22.1")
1727 ;; Blinking cursor
1729 (defgroup cursor nil
1730 "Displaying text cursors."
1731 :version "21.1"
1732 :group 'frames)
1734 (defcustom blink-cursor-delay 0.5
1735 "Seconds of idle time after which cursor starts to blink."
1736 :type 'number
1737 :group 'cursor)
1739 (defcustom blink-cursor-interval 0.5
1740 "Length of cursor blink interval in seconds."
1741 :type 'number
1742 :group 'cursor)
1744 (defcustom blink-cursor-blinks 10
1745 "How many times to blink before using a solid cursor on NS, X, and MS-Windows.
1746 Use 0 or negative value to blink forever."
1747 :version "24.4"
1748 :type 'integer
1749 :group 'cursor)
1751 (defvar blink-cursor-blinks-done 1
1752 "Number of blinks done since we started blinking on NS, X, and MS-Windows.")
1754 (defvar blink-cursor-idle-timer nil
1755 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1756 The function `blink-cursor-start' is called when the timer fires.")
1758 (defvar blink-cursor-timer nil
1759 "Timer started from `blink-cursor-start'.
1760 This timer calls `blink-cursor-timer-function' every
1761 `blink-cursor-interval' seconds.")
1763 (defun blink-cursor-start ()
1764 "Timer function called from the timer `blink-cursor-idle-timer'.
1765 This starts the timer `blink-cursor-timer', which makes the cursor blink
1766 if appropriate. It also arranges to cancel that timer when the next
1767 command starts, by installing a pre-command hook."
1768 (when (null blink-cursor-timer)
1769 ;; Set up the timer first, so that if this signals an error,
1770 ;; blink-cursor-end is not added to pre-command-hook.
1771 (setq blink-cursor-blinks-done 1)
1772 (setq blink-cursor-timer
1773 (run-with-timer blink-cursor-interval blink-cursor-interval
1774 'blink-cursor-timer-function))
1775 (add-hook 'pre-command-hook 'blink-cursor-end)
1776 (internal-show-cursor nil nil)))
1778 (defun blink-cursor-timer-function ()
1779 "Timer function of timer `blink-cursor-timer'."
1780 (internal-show-cursor nil (not (internal-show-cursor-p)))
1781 ;; Each blink is two calls to this function.
1782 (setq blink-cursor-blinks-done (1+ blink-cursor-blinks-done))
1783 (when (and (> blink-cursor-blinks 0)
1784 (<= (* 2 blink-cursor-blinks) blink-cursor-blinks-done))
1785 (blink-cursor-suspend)
1786 (add-hook 'post-command-hook 'blink-cursor-check)))
1789 (defun blink-cursor-end ()
1790 "Stop cursor blinking.
1791 This is installed as a pre-command hook by `blink-cursor-start'.
1792 When run, it cancels the timer `blink-cursor-timer' and removes
1793 itself as a pre-command hook."
1794 (remove-hook 'pre-command-hook 'blink-cursor-end)
1795 (internal-show-cursor nil t)
1796 (when blink-cursor-timer
1797 (cancel-timer blink-cursor-timer)
1798 (setq blink-cursor-timer nil)))
1800 (defun blink-cursor-suspend ()
1801 "Suspend cursor blinking.
1802 This is called when no frame has focus and timers can be suspended.
1803 Timers are restarted by `blink-cursor-check', which is called when a
1804 frame receives focus."
1805 (blink-cursor-end)
1806 (when blink-cursor-idle-timer
1807 (cancel-timer blink-cursor-idle-timer)
1808 (setq blink-cursor-idle-timer nil)))
1810 (defun blink-cursor-check ()
1811 "Check if cursor blinking shall be restarted.
1812 This is done when a frame gets focus. Blink timers may be stopped by
1813 `blink-cursor-suspend'."
1814 (when (and blink-cursor-mode
1815 (not blink-cursor-idle-timer))
1816 (remove-hook 'post-command-hook 'blink-cursor-check)
1817 (setq blink-cursor-idle-timer
1818 (run-with-idle-timer blink-cursor-delay
1819 blink-cursor-delay
1820 'blink-cursor-start))))
1822 (define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1")
1824 (define-minor-mode blink-cursor-mode
1825 "Toggle cursor blinking (Blink Cursor mode).
1826 With a prefix argument ARG, enable Blink Cursor mode if ARG is
1827 positive, and disable it otherwise. If called from Lisp, enable
1828 the mode if ARG is omitted or nil.
1830 If the value of `blink-cursor-blinks' is positive (10 by default),
1831 the cursor stops blinking after that number of blinks, if Emacs
1832 gets no input during that time.
1834 See also `blink-cursor-interval' and `blink-cursor-delay'.
1836 This command is effective only on graphical frames. On text-only
1837 terminals, cursor blinking is controlled by the terminal."
1838 :init-value (not (or noninteractive
1839 no-blinking-cursor
1840 (eq system-type 'ms-dos)
1841 (not (memq window-system '(x w32 ns)))))
1842 :initialize 'custom-initialize-delay
1843 :group 'cursor
1844 :global t
1845 (blink-cursor-suspend)
1846 (remove-hook 'focus-in-hook #'blink-cursor-check)
1847 (remove-hook 'focus-out-hook #'blink-cursor-suspend)
1848 (when blink-cursor-mode
1849 (add-hook 'focus-in-hook #'blink-cursor-check)
1850 (add-hook 'focus-out-hook #'blink-cursor-suspend)
1851 (setq blink-cursor-idle-timer
1852 (run-with-idle-timer blink-cursor-delay
1853 blink-cursor-delay
1854 #'blink-cursor-start))))
1857 ;; Frame maximization/fullscreen
1859 (defun toggle-frame-maximized ()
1860 "Toggle maximization state of the selected frame.
1861 Maximize the selected frame or un-maximize if it is already maximized.
1862 Respect window manager screen decorations.
1863 If the frame is in fullscreen mode, don't change its mode,
1864 just toggle the temporary frame parameter `maximized',
1865 so the frame will go to the right maximization state
1866 after disabling fullscreen mode.
1868 Note that with some window managers you may have to set
1869 `frame-resize-pixelwise' to non-nil in order to make a frame
1870 appear truly maximized.
1872 See also `toggle-frame-fullscreen'."
1873 (interactive)
1874 (if (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth))
1875 (modify-frame-parameters
1877 `((maximized
1878 . ,(unless (eq (frame-parameter nil 'maximized) 'maximized)
1879 'maximized))))
1880 (modify-frame-parameters
1882 `((fullscreen
1883 . ,(unless (eq (frame-parameter nil 'fullscreen) 'maximized)
1884 'maximized))))))
1886 (defun toggle-frame-fullscreen ()
1887 "Toggle fullscreen mode of the selected frame.
1888 Enable fullscreen mode of the selected frame or disable if it is
1889 already fullscreen. Ignore window manager screen decorations.
1890 When turning on fullscreen mode, remember the previous value of the
1891 maximization state in the temporary frame parameter `maximized'.
1892 Restore the maximization state when turning off fullscreen mode.
1894 Note that with some window managers you may have to set
1895 `frame-resize-pixelwise' to non-nil in order to make a frame
1896 appear truly fullscreen.
1898 See also `toggle-frame-maximized'."
1899 (interactive)
1900 (modify-frame-parameters
1902 `((maximized
1903 . ,(unless (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth))
1904 (frame-parameter nil 'fullscreen)))
1905 (fullscreen
1906 . ,(if (memq (frame-parameter nil 'fullscreen) '(fullscreen fullboth))
1907 (if (eq (frame-parameter nil 'maximized) 'maximized)
1908 'maximized)
1909 'fullscreen)))))
1912 ;;;; Key bindings
1914 (define-key ctl-x-5-map "2" 'make-frame-command)
1915 (define-key ctl-x-5-map "1" 'delete-other-frames)
1916 (define-key ctl-x-5-map "0" 'delete-frame)
1917 (define-key ctl-x-5-map "o" 'other-frame)
1918 (define-key global-map [f11] 'toggle-frame-fullscreen)
1919 (define-key global-map [(meta f10)] 'toggle-frame-maximized)
1920 (define-key esc-map [f10] 'toggle-frame-maximized)
1923 ;; Misc.
1925 ;; Only marked as obsolete in 24.3.
1926 (define-obsolete-variable-alias 'automatic-hscrolling
1927 'auto-hscroll-mode "22.1")
1929 (make-variable-buffer-local 'show-trailing-whitespace)
1931 ;; Defined in dispnew.c.
1932 (make-obsolete-variable
1933 'window-system-version "it does not give useful information." "24.3")
1935 (provide 'frame)
1937 ;;; frame.el ends here