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