Fix documentation of forward-line
[emacs.git] / lisp / frame.el
blob0c1fb38c5168968517a48c8ce5b7ea80a6d28b9a
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))
220 (declare-function tool-bar-height "xdisp.c" (&optional frame pixelwise))
222 (defalias 'tool-bar-lines-needed 'tool-bar-height)
224 ;; startup.el calls this function after loading the user's init
225 ;; file. Now default-frame-alist and initial-frame-alist contain
226 ;; information to which we must react; do what needs to be done.
227 (defun frame-notice-user-settings ()
228 "Act on user's init file settings of frame parameters.
229 React to settings of `initial-frame-alist',
230 `window-system-default-frame-alist' and `default-frame-alist'
231 there (in decreasing order of priority)."
232 ;; Creating and deleting frames may shift the selected frame around,
233 ;; and thus the current buffer. Protect against that. We don't
234 ;; want to use save-excursion here, because that may also try to set
235 ;; the buffer of the selected window, which fails when the selected
236 ;; window is the minibuffer.
237 (let ((old-buffer (current-buffer))
238 (window-system-frame-alist
239 (cdr (assq initial-window-system
240 window-system-default-frame-alist))))
242 (when (and frame-notice-user-settings
243 (null frame-initial-frame))
244 ;; This case happens when we don't have a window system, and
245 ;; also for MS-DOS frames.
246 (let ((parms (frame-parameters)))
247 ;; Don't change the frame names.
248 (setq parms (delq (assq 'name parms) parms))
249 ;; Can't modify the minibuffer parameter, so don't try.
250 (setq parms (delq (assq 'minibuffer parms) parms))
251 (modify-frame-parameters
253 (if initial-window-system
254 parms
255 ;; initial-frame-alist and default-frame-alist were already
256 ;; applied in pc-win.el.
257 (append initial-frame-alist window-system-frame-alist
258 default-frame-alist parms nil)))
259 (if (null initial-window-system) ;; MS-DOS does this differently in pc-win.el
260 (let ((newparms (frame-parameters))
261 (frame (selected-frame)))
262 (tty-handle-reverse-video frame newparms)
263 ;; tty-handle-reverse-video might change the frame's
264 ;; color parameters, and we need to use the updated
265 ;; value below.
266 (setq newparms (frame-parameters))
267 ;; If we changed the background color, we need to update
268 ;; the background-mode parameter, and maybe some faces,
269 ;; too.
270 (when (assq 'background-color newparms)
271 (unless (or (assq 'background-mode initial-frame-alist)
272 (assq 'background-mode default-frame-alist))
273 (frame-set-background-mode frame))
274 (face-set-after-frame-default frame newparms))))))
276 ;; If the initial frame is still around, apply initial-frame-alist
277 ;; and default-frame-alist to it.
278 (when (frame-live-p frame-initial-frame)
279 ;; When tool-bar has been switched off, correct the frame size
280 ;; by the lines added in x-create-frame for the tool-bar and
281 ;; switch `tool-bar-mode' off.
282 (when (display-graphic-p)
283 (let* ((init-lines
284 (assq 'tool-bar-lines initial-frame-alist))
285 (other-lines
286 (or (assq 'tool-bar-lines window-system-frame-alist)
287 (assq 'tool-bar-lines default-frame-alist)))
288 (lines (or init-lines other-lines))
289 (height (tool-bar-height frame-initial-frame t)))
290 ;; Adjust frame top if either zero (nil) tool bar lines have
291 ;; been requested in the most relevant of the frame's alists
292 ;; or tool bar mode has been explicitly turned off in the
293 ;; user's init file.
294 (when (and (> height 0)
295 (or (and lines
296 (or (null (cdr lines))
297 (eq 0 (cdr lines))))
298 (not tool-bar-mode)))
299 (let* ((initial-top
300 (cdr (assq 'top frame-initial-geometry-arguments)))
301 (top (frame-parameter frame-initial-frame 'top)))
302 (when (and (consp initial-top) (eq '- (car initial-top)))
303 (let ((adjusted-top
304 (cond
305 ((and (consp top) (eq '+ (car top)))
306 (list '+ (+ (cadr top) height)))
307 ((and (consp top) (eq '- (car top)))
308 (list '- (- (cadr top) height)))
309 (t (+ top height)))))
310 (modify-frame-parameters
311 frame-initial-frame `((top . ,adjusted-top))))))
312 ;; Reset `tool-bar-mode' when zero tool bar lines have been
313 ;; requested for the window-system or default frame alists.
314 (when (and tool-bar-mode
315 (and other-lines
316 (or (null (cdr other-lines))
317 (eq 0 (cdr other-lines)))))
318 (tool-bar-mode -1)))))
320 ;; The initial frame we create above always has a minibuffer.
321 ;; If the user wants to remove it, or make it a minibuffer-only
322 ;; frame, then we'll have to delete the current frame and make a
323 ;; new one; you can't remove or add a root window to/from an
324 ;; existing frame.
326 ;; NOTE: default-frame-alist was nil when we created the
327 ;; existing frame. We need to explicitly include
328 ;; default-frame-alist in the parameters of the screen we
329 ;; create here, so that its new value, gleaned from the user's
330 ;; init file, will be applied to the existing screen.
331 (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
332 (assq 'minibuffer window-system-frame-alist)
333 (assq 'minibuffer default-frame-alist)
334 '(minibuffer . t)))
336 ;; Create the new frame.
337 (let (parms new)
338 ;; MS-Windows needs this to avoid inflooping below.
339 (if (eq system-type 'windows-nt)
340 (sit-for 0 t))
341 ;; If the frame isn't visible yet, wait till it is.
342 ;; If the user has to position the window,
343 ;; Emacs doesn't know its real position until
344 ;; the frame is seen to be visible.
345 (while (not (cdr (assq 'visibility
346 (frame-parameters frame-initial-frame))))
347 (sleep-for 1))
348 (setq parms (frame-parameters frame-initial-frame))
350 ;; Get rid of `name' unless it was specified explicitly before.
351 (or (assq 'name frame-initial-frame-alist)
352 (setq parms (delq (assq 'name parms) parms)))
353 ;; An explicit parent-id is a request to XEmbed the frame.
354 (or (assq 'parent-id frame-initial-frame-alist)
355 (setq parms (delq (assq 'parent-id parms) parms)))
357 (setq parms (append initial-frame-alist
358 window-system-frame-alist
359 default-frame-alist
360 parms
361 nil))
363 ;; Get rid of `reverse', because that was handled
364 ;; when we first made the frame.
365 (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
367 (if (assq 'height frame-initial-geometry-arguments)
368 (setq parms (assq-delete-all 'height parms)))
369 (if (assq 'width frame-initial-geometry-arguments)
370 (setq parms (assq-delete-all 'width parms)))
371 (if (assq 'left frame-initial-geometry-arguments)
372 (setq parms (assq-delete-all 'left parms)))
373 (if (assq 'top frame-initial-geometry-arguments)
374 (setq parms (assq-delete-all 'top parms)))
375 (setq new
376 (make-frame
377 ;; Use the geometry args that created the existing
378 ;; frame, rather than the parms we get for it.
379 (append frame-initial-geometry-arguments
380 '((user-size . t) (user-position . t))
381 parms)))
382 ;; The initial frame, which we are about to delete, may be
383 ;; the only frame with a minibuffer. If it is, create a
384 ;; new one.
385 (or (delq frame-initial-frame (minibuffer-frame-list))
386 (make-initial-minibuffer-frame nil))
388 ;; If the initial frame is serving as a surrogate
389 ;; minibuffer frame for any frames, we need to wean them
390 ;; onto a new frame. The default-minibuffer-frame
391 ;; variable must be handled similarly.
392 (let ((users-of-initial
393 (filtered-frame-list
394 (lambda (frame)
395 (and (not (eq frame frame-initial-frame))
396 (eq (window-frame
397 (minibuffer-window frame))
398 frame-initial-frame))))))
399 (if (or users-of-initial
400 (eq default-minibuffer-frame frame-initial-frame))
402 ;; Choose an appropriate frame. Prefer frames which
403 ;; are only minibuffers.
404 (let* ((new-surrogate
405 (car
406 (or (filtered-frame-list
407 (lambda (frame)
408 (eq (cdr (assq 'minibuffer
409 (frame-parameters frame)))
410 'only)))
411 (minibuffer-frame-list))))
412 (new-minibuffer (minibuffer-window new-surrogate)))
414 (if (eq default-minibuffer-frame frame-initial-frame)
415 (setq default-minibuffer-frame new-surrogate))
417 ;; Wean the frames using frame-initial-frame as
418 ;; their minibuffer frame.
419 (dolist (frame users-of-initial)
420 (modify-frame-parameters
421 frame (list (cons 'minibuffer new-minibuffer)))))))
423 ;; Redirect events enqueued at this frame to the new frame.
424 ;; Is this a good idea?
425 (redirect-frame-focus frame-initial-frame new)
427 ;; Finally, get rid of the old frame.
428 (delete-frame frame-initial-frame t))
430 ;; Otherwise, we don't need all that rigmarole; just apply
431 ;; the new parameters.
432 (let (newparms allparms tail)
433 (setq allparms (append initial-frame-alist
434 window-system-frame-alist
435 default-frame-alist nil))
436 (if (assq 'height frame-initial-geometry-arguments)
437 (setq allparms (assq-delete-all 'height allparms)))
438 (if (assq 'width frame-initial-geometry-arguments)
439 (setq allparms (assq-delete-all 'width allparms)))
440 (if (assq 'left frame-initial-geometry-arguments)
441 (setq allparms (assq-delete-all 'left allparms)))
442 (if (assq 'top frame-initial-geometry-arguments)
443 (setq allparms (assq-delete-all 'top allparms)))
444 (setq tail allparms)
445 ;; Find just the parms that have changed since we first
446 ;; made this frame. Those are the ones actually set by
447 ;; the init file. For those parms whose values we already knew
448 ;; (such as those spec'd by command line options)
449 ;; it is undesirable to specify the parm again
450 ;; once the user has seen the frame and been able to alter it
451 ;; manually.
452 (let (newval oldval)
453 (dolist (entry tail)
454 (setq oldval (assq (car entry) frame-initial-frame-alist))
455 (setq newval (cdr (assq (car entry) allparms)))
456 (or (and oldval (eq (cdr oldval) newval))
457 (setq newparms
458 (cons (cons (car entry) newval) newparms)))))
459 (setq newparms (nreverse newparms))
461 (let ((new-bg (assq 'background-color newparms)))
462 ;; If the `background-color' parameter is changed, apply
463 ;; it first, then make sure that the `background-mode'
464 ;; parameter and other faces are updated, before applying
465 ;; the other parameters.
466 (when new-bg
467 (modify-frame-parameters frame-initial-frame
468 (list new-bg))
469 (unless (assq 'background-mode newparms)
470 (frame-set-background-mode frame-initial-frame))
471 (face-set-after-frame-default frame-initial-frame)
472 (setq newparms (delq new-bg newparms)))
474 (when (numberp (car frame-size-history))
475 (setq frame-size-history
476 (cons (1- (car frame-size-history))
477 (cons
478 (list frame-initial-frame
479 "frame-notice-user-settings"
480 nil newparms)
481 (cdr frame-size-history)))))
483 (modify-frame-parameters frame-initial-frame newparms)))))
485 ;; Restore the original buffer.
486 (set-buffer old-buffer)
488 ;; Make sure the initial frame can be GC'd if it is ever deleted.
489 ;; Make sure frame-notice-user-settings does nothing if called twice.
490 (setq frame-notice-user-settings nil)
491 (setq frame-initial-frame nil)))
493 (defun make-initial-minibuffer-frame (display)
494 (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
495 (if display
496 (make-frame-on-display display parms)
497 (make-frame parms))))
499 ;;;; Creation of additional frames, and other frame miscellanea
501 (defun modify-all-frames-parameters (alist)
502 "Modify all current and future frames' parameters according to ALIST.
503 This changes `default-frame-alist' and possibly `initial-frame-alist'.
504 Furthermore, this function removes all parameters in ALIST from
505 `window-system-default-frame-alist'.
506 See help of `modify-frame-parameters' for more information."
507 (dolist (frame (frame-list))
508 (modify-frame-parameters frame alist))
510 (dolist (pair alist) ;; conses to add/replace
511 ;; initial-frame-alist needs setting only when
512 ;; frame-notice-user-settings is true.
513 (and frame-notice-user-settings
514 (setq initial-frame-alist
515 (assq-delete-all (car pair) initial-frame-alist)))
516 (setq default-frame-alist
517 (assq-delete-all (car pair) default-frame-alist))
518 ;; Remove any similar settings from the window-system specific
519 ;; parameters---they would override default-frame-alist.
520 (dolist (w window-system-default-frame-alist)
521 (setcdr w (assq-delete-all (car pair) (cdr w)))))
523 (and frame-notice-user-settings
524 (setq initial-frame-alist (append initial-frame-alist alist)))
525 (setq default-frame-alist (append default-frame-alist alist)))
527 (defun get-other-frame ()
528 "Return some frame other than the current frame.
529 Create one if necessary. Note that the minibuffer frame, if separate,
530 is not considered (see `next-frame')."
531 (if (equal (next-frame) (selected-frame)) (make-frame) (next-frame)))
533 (defun next-multiframe-window ()
534 "Select the next window, regardless of which frame it is on."
535 (interactive)
536 (select-window (next-window (selected-window)
537 (> (minibuffer-depth) 0)
539 (select-frame-set-input-focus (selected-frame)))
541 (defun previous-multiframe-window ()
542 "Select the previous window, regardless of which frame it is on."
543 (interactive)
544 (select-window (previous-window (selected-window)
545 (> (minibuffer-depth) 0)
547 (select-frame-set-input-focus (selected-frame)))
549 (defun window-system-for-display (display)
550 "Return the window system for DISPLAY.
551 Return nil if we don't know how to interpret DISPLAY."
552 ;; MS-Windows doesn't know how to create a GUI frame in a -nw session.
553 (if (and (eq system-type 'windows-nt)
554 (null (window-system))
555 (not (daemonp)))
557 (cl-loop for descriptor in display-format-alist
558 for pattern = (car descriptor)
559 for system = (cdr descriptor)
560 when (string-match-p pattern display) return system)))
562 (defun make-frame-on-display (display &optional parameters)
563 "Make a frame on display DISPLAY.
564 The optional argument PARAMETERS specifies additional frame parameters."
565 (interactive "sMake frame on display: ")
566 (make-frame (cons (cons 'display display) parameters)))
568 (declare-function x-close-connection "xfns.c" (terminal))
570 (defun close-display-connection (display)
571 "Close the connection to a display, deleting all its associated frames.
572 For DISPLAY, specify either a frame or a display name (a string).
573 If DISPLAY is nil, that stands for the selected frame's display."
574 (interactive
575 (list
576 (let* ((default (frame-parameter nil 'display))
577 (display (completing-read
578 (format "Close display (default %s): " default)
579 (delete-dups
580 (mapcar (lambda (frame)
581 (frame-parameter frame 'display))
582 (frame-list)))
583 nil t nil nil
584 default)))
585 (if (zerop (length display)) default display))))
586 (let ((frames (delq nil
587 (mapcar (lambda (frame)
588 (if (equal display
589 (frame-parameter frame 'display))
590 frame))
591 (frame-list)))))
592 (if (and (consp frames)
593 (not (y-or-n-p (if (cdr frames)
594 (format "Delete %s frames? " (length frames))
595 (format "Delete %s ? " (car frames))))))
596 (error "Abort!")
597 (mapc 'delete-frame frames)
598 (x-close-connection display))))
600 (defun make-frame-command ()
601 "Make a new frame, on the same terminal as the selected frame.
602 If the terminal is a text-only terminal, this also selects the
603 new frame."
604 (interactive)
605 (if (display-graphic-p)
606 (make-frame)
607 (select-frame (make-frame))))
609 (defvar before-make-frame-hook nil
610 "Functions to run before a frame is created.")
612 (defvar after-make-frame-functions nil
613 "Functions to run after a frame is created.
614 The functions are run with one arg, the newly created frame.")
616 (defvar after-setting-font-hook nil
617 "Functions to run after a frame's font has been changed.")
619 ;; Alias, kept temporarily.
620 (define-obsolete-function-alias 'new-frame 'make-frame "22.1")
622 (defvar frame-inherited-parameters '()
623 "Parameters `make-frame' copies from the `selected-frame' to the new frame.")
625 (defvar x-display-name)
627 (defun make-frame (&optional parameters)
628 "Return a newly created frame displaying the current buffer.
629 Optional argument PARAMETERS is an alist of frame parameters for
630 the new frame. Each element of PARAMETERS should have the
631 form (NAME . VALUE), for example:
633 (name . STRING) The frame should be named STRING.
635 (width . NUMBER) The frame should be NUMBER characters in width.
636 (height . NUMBER) The frame should be NUMBER text lines high.
638 You cannot specify either `width' or `height', you must specify
639 neither or both.
641 (minibuffer . t) The frame should have a minibuffer.
642 (minibuffer . nil) The frame should have no minibuffer.
643 (minibuffer . only) The frame should contain only a minibuffer.
644 (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
646 (window-system . nil) The frame should be displayed on a terminal device.
647 (window-system . x) The frame should be displayed in an X window.
649 (display . \":0\") The frame should appear on display :0.
651 (terminal . TERMINAL) The frame should use the terminal object TERMINAL.
653 In addition, any parameter specified in `default-frame-alist',
654 but not present in PARAMETERS, is applied.
656 Before creating the frame (via `frame-creation-function-alist'),
657 this function runs the hook `before-make-frame-hook'. After
658 creating the frame, it runs the hook `after-make-frame-functions'
659 with one arg, the newly created frame.
661 If a display parameter is supplied and a window-system is not,
662 guess the window-system from the display.
664 On graphical displays, this function does not itself make the new
665 frame the selected frame. However, the window system may select
666 the new frame according to its own rules."
667 (interactive)
668 (let* ((display (cdr (assq 'display parameters)))
669 (w (cond
670 ((assq 'terminal parameters)
671 (let ((type (terminal-live-p
672 (cdr (assq 'terminal parameters)))))
673 (cond
674 ((eq t type) nil)
675 ((null type) (error "Terminal %s does not exist"
676 (cdr (assq 'terminal parameters))))
677 (t type))))
678 ((assq 'window-system parameters)
679 (cdr (assq 'window-system parameters)))
680 (display
681 (or (window-system-for-display display)
682 (error "Don't know how to interpret display %S"
683 display)))
684 (t window-system)))
685 (oldframe (selected-frame))
686 (params parameters)
687 frame)
689 (unless (get w 'window-system-initialized)
690 (funcall (gui-method window-system-initialization w) display)
691 (setq x-display-name display)
692 (put w 'window-system-initialized t))
694 ;; Add parameters from `window-system-default-frame-alist'.
695 (dolist (p (cdr (assq w window-system-default-frame-alist)))
696 (unless (assq (car p) params)
697 (push p params)))
698 ;; Add parameters from `default-frame-alist'.
699 (dolist (p default-frame-alist)
700 (unless (assq (car p) params)
701 (push p params)))
702 ;; Now make the frame.
703 (run-hooks 'before-make-frame-hook)
705 ;; (setq frame-size-history '(1000))
707 (setq frame
708 (funcall (gui-method frame-creation-function w) params))
709 (normal-erase-is-backspace-setup-frame frame)
710 ;; Inherit the original frame's parameters.
711 (dolist (param frame-inherited-parameters)
712 (unless (assq param parameters) ;Overridden by explicit parameters.
713 (let ((val (frame-parameter oldframe param)))
714 (when val (set-frame-parameter frame param val)))))
716 (when (numberp (car frame-size-history))
717 (setq frame-size-history
718 (cons (1- (car frame-size-history))
719 (cons (list frame "make-frame")
720 (cdr frame-size-history)))))
722 ;; We can run `window-configuration-change-hook' for this frame now.
723 (frame-after-make-frame frame t)
724 (run-hook-with-args 'after-make-frame-functions frame)
725 frame))
727 (defun filtered-frame-list (predicate)
728 "Return a list of all live frames which satisfy PREDICATE."
729 (let* ((frames (frame-list))
730 (list frames))
731 (while (consp frames)
732 (unless (funcall predicate (car frames))
733 (setcar frames nil))
734 (setq frames (cdr frames)))
735 (delq nil list)))
737 (defun minibuffer-frame-list ()
738 "Return a list of all frames with their own minibuffers."
739 (filtered-frame-list
740 (lambda (frame)
741 (eq frame (window-frame (minibuffer-window frame))))))
743 ;; Used to be called `terminal-id' in termdev.el.
744 (defun get-device-terminal (device)
745 "Return the terminal corresponding to DEVICE.
746 DEVICE can be a terminal, a frame, nil (meaning the selected frame's terminal),
747 the name of an X display device (HOST.SERVER.SCREEN) or a tty device file."
748 (cond
749 ((or (null device) (framep device))
750 (frame-terminal device))
751 ((stringp device)
752 (let ((f (car (filtered-frame-list
753 (lambda (frame)
754 (or (equal (frame-parameter frame 'display) device)
755 (equal (frame-parameter frame 'tty) device)))))))
756 (or f (error "Display %s does not exist" device))
757 (frame-terminal f)))
758 ((terminal-live-p device) device)
760 (error "Invalid argument %s in `get-device-terminal'" device))))
762 (defun frames-on-display-list (&optional device)
763 "Return a list of all frames on DEVICE.
765 DEVICE should be a terminal, a frame,
766 or a name of an X display or tty (a string of the form
767 HOST:SERVER.SCREEN).
769 If DEVICE is omitted or nil, it defaults to the selected
770 frame's terminal device."
771 (let* ((terminal (get-device-terminal device))
772 (func #'(lambda (frame)
773 (eq (frame-terminal frame) terminal))))
774 (filtered-frame-list func)))
776 (defun framep-on-display (&optional terminal)
777 "Return the type of frames on TERMINAL.
778 TERMINAL may be a terminal id, a display name or a frame. If it
779 is a frame, its type is returned. If TERMINAL is omitted or nil,
780 it defaults to the selected frame's terminal device. All frames
781 on a given display are of the same type."
782 (or (terminal-live-p terminal)
783 (framep terminal)
784 (framep (car (frames-on-display-list terminal)))))
786 (defun frame-remove-geometry-params (param-list)
787 "Return the parameter list PARAM-LIST, but with geometry specs removed.
788 This deletes all bindings in PARAM-LIST for `top', `left', `width',
789 `height', `user-size' and `user-position' parameters.
790 Emacs uses this to avoid overriding explicit moves and resizings from
791 the user during startup."
792 (setq param-list (cons nil param-list))
793 (let ((tail param-list))
794 (while (consp (cdr tail))
795 (if (and (consp (car (cdr tail)))
796 (memq (car (car (cdr tail)))
797 '(height width top left user-position user-size)))
798 (progn
799 (setq frame-initial-geometry-arguments
800 (cons (car (cdr tail)) frame-initial-geometry-arguments))
801 (setcdr tail (cdr (cdr tail))))
802 (setq tail (cdr tail)))))
803 (setq frame-initial-geometry-arguments
804 (nreverse frame-initial-geometry-arguments))
805 (cdr param-list))
807 (declare-function x-focus-frame "frame.c" (frame))
809 (defun select-frame-set-input-focus (frame &optional norecord)
810 "Select FRAME, raise it, and set input focus, if possible.
811 If `mouse-autoselect-window' is non-nil, also move mouse pointer
812 to FRAME's selected window. Otherwise, if `focus-follows-mouse'
813 is non-nil, move mouse cursor to FRAME.
815 Optional argument NORECORD means to neither change the order of
816 recently selected windows nor the buffer list."
817 (select-frame frame norecord)
818 (raise-frame frame)
819 ;; Ensure, if possible, that FRAME gets input focus.
820 (when (memq (window-system frame) '(x w32 ns))
821 (x-focus-frame frame))
822 ;; Move mouse cursor if necessary.
823 (cond
824 (mouse-autoselect-window
825 (let ((edges (window-inside-edges (frame-selected-window frame))))
826 ;; Move mouse cursor into FRAME's selected window to avoid that
827 ;; Emacs mouse-autoselects another window.
828 (set-mouse-position frame (nth 2 edges) (nth 1 edges))))
829 (focus-follows-mouse
830 ;; Move mouse cursor into FRAME to avoid that another frame gets
831 ;; selected by the window manager.
832 (set-mouse-position frame (1- (frame-width frame)) 0))))
834 (defun other-frame (arg)
835 "Select the ARGth different visible frame on current display, and raise it.
836 All frames are arranged in a cyclic order.
837 This command selects the frame ARG steps away in that order.
838 A negative ARG moves in the opposite order.
840 To make this command work properly, you must tell Emacs
841 how the system (or the window manager) generally handles
842 focus-switching between windows. If moving the mouse onto a window
843 selects it (gives it focus), set `focus-follows-mouse' to t.
844 Otherwise, that variable should be nil."
845 (interactive "p")
846 (let ((frame (selected-frame)))
847 (while (> arg 0)
848 (setq frame (next-frame frame))
849 (while (not (eq (frame-visible-p frame) t))
850 (setq frame (next-frame frame)))
851 (setq arg (1- arg)))
852 (while (< arg 0)
853 (setq frame (previous-frame frame))
854 (while (not (eq (frame-visible-p frame) t))
855 (setq frame (previous-frame frame)))
856 (setq arg (1+ arg)))
857 (select-frame-set-input-focus frame)))
859 (defun iconify-or-deiconify-frame ()
860 "Iconify the selected frame, or deiconify if it's currently an icon."
861 (interactive)
862 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
863 (iconify-frame)
864 (make-frame-visible)))
866 (defun suspend-frame ()
867 "Do whatever is right to suspend the current frame.
868 Calls `suspend-emacs' if invoked from the controlling tty device,
869 `suspend-tty' from a secondary tty device, and
870 `iconify-or-deiconify-frame' from an X frame."
871 (interactive)
872 (let ((type (framep (selected-frame))))
873 (cond
874 ((memq type '(x ns w32)) (iconify-or-deiconify-frame))
875 ((eq type t)
876 (if (controlling-tty-p)
877 (suspend-emacs)
878 (suspend-tty)))
879 (t (suspend-emacs)))))
881 (defun make-frame-names-alist ()
882 ;; Only consider the frames on the same display.
883 (let* ((current-frame (selected-frame))
884 (falist
885 (cons
886 (cons (frame-parameter current-frame 'name) current-frame) nil))
887 (frame (next-frame nil 0)))
888 (while (not (eq frame current-frame))
889 (progn
890 (push (cons (frame-parameter frame 'name) frame) falist)
891 (setq frame (next-frame frame 0))))
892 falist))
894 (defvar frame-name-history nil)
895 (defun select-frame-by-name (name)
896 "Select the frame on the current terminal whose name is NAME and raise it.
897 If there is no frame by that name, signal an error."
898 (interactive
899 (let* ((frame-names-alist (make-frame-names-alist))
900 (default (car (car frame-names-alist)))
901 (input (completing-read
902 (format "Select Frame (default %s): " default)
903 frame-names-alist nil t nil 'frame-name-history)))
904 (if (= (length input) 0)
905 (list default)
906 (list input))))
907 (let* ((frame-names-alist (make-frame-names-alist))
908 (frame (cdr (assoc name frame-names-alist))))
909 (if frame
910 (select-frame-set-input-focus frame)
911 (error "There is no frame named `%s'" name))))
914 ;;;; Background mode.
916 (defcustom frame-background-mode nil
917 "The brightness of the background.
918 Set this to the symbol `dark' if your background color is dark,
919 `light' if your background is light, or nil (automatic by default)
920 if you want Emacs to examine the brightness for you.
922 If you change this without using customize, you should use
923 `frame-set-background-mode' to update existing frames;
924 e.g. (mapc 'frame-set-background-mode (frame-list))."
925 :group 'faces
926 :set #'(lambda (var value)
927 (set-default var value)
928 (mapc 'frame-set-background-mode (frame-list)))
929 :initialize 'custom-initialize-changed
930 :type '(choice (const dark)
931 (const light)
932 (const :tag "automatic" nil)))
934 (declare-function x-get-resource "frame.c"
935 (attribute class &optional component subclass))
937 ;; Only used if window-system is not null.
938 (declare-function x-display-grayscale-p "xfns.c" (&optional terminal))
940 (defvar inhibit-frame-set-background-mode nil)
942 (defun frame-set-background-mode (frame &optional keep-face-specs)
943 "Set up display-dependent faces on FRAME.
944 Display-dependent faces are those which have different definitions
945 according to the `background-mode' and `display-type' frame parameters.
947 If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate
948 face specs for the new background mode."
949 (unless inhibit-frame-set-background-mode
950 (let* ((frame-default-bg-mode (frame-terminal-default-bg-mode frame))
951 (bg-color (frame-parameter frame 'background-color))
952 (tty-type (tty-type frame))
953 (default-bg-mode
954 (if (or (window-system frame)
955 (and tty-type
956 (string-match "^\\(xterm\\|\\rxvt\\|dtterm\\|eterm\\)"
957 tty-type)))
958 'light
959 'dark))
960 (non-default-bg-mode (if (eq default-bg-mode 'light) 'dark 'light))
961 (bg-mode
962 (cond (frame-default-bg-mode)
963 ((equal bg-color "unspecified-fg") ; inverted colors
964 non-default-bg-mode)
965 ((not (color-values bg-color frame))
966 default-bg-mode)
967 ((>= (apply '+ (color-values bg-color frame))
968 ;; Just looking at the screen, colors whose
969 ;; values add up to .6 of the white total
970 ;; still look dark to me.
971 (* (apply '+ (color-values "white" frame)) .6))
972 'light)
973 (t 'dark)))
974 (display-type
975 (cond ((null (window-system frame))
976 (if (tty-display-color-p frame) 'color 'mono))
977 ((display-color-p frame)
978 'color)
979 ((x-display-grayscale-p frame)
980 'grayscale)
981 (t 'mono)))
982 (old-bg-mode
983 (frame-parameter frame 'background-mode))
984 (old-display-type
985 (frame-parameter frame 'display-type)))
987 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
988 (let ((locally-modified-faces nil)
989 ;; Prevent face-spec-recalc from calling this function
990 ;; again, resulting in a loop (bug#911).
991 (inhibit-frame-set-background-mode t)
992 (params (list (cons 'background-mode bg-mode)
993 (cons 'display-type display-type))))
994 (if keep-face-specs
995 (modify-frame-parameters frame params)
996 ;; If we are recomputing face specs, first collect a list
997 ;; of faces that don't match their face-specs. These are
998 ;; the faces modified on FRAME, and we avoid changing them
999 ;; below. Use a negative list to avoid consing (we assume
1000 ;; most faces are unmodified).
1001 (dolist (face (face-list))
1002 (and (not (get face 'face-override-spec))
1003 (not (face-spec-match-p face
1004 (face-user-default-spec face)
1005 (selected-frame)))
1006 (push face locally-modified-faces)))
1007 ;; Now change to the new frame parameters
1008 (modify-frame-parameters frame params)
1009 ;; For all unmodified named faces, choose face specs
1010 ;; matching the new frame parameters.
1011 (dolist (face (face-list))
1012 (unless (memq face locally-modified-faces)
1013 (face-spec-recalc face frame)))))))))
1015 (defun frame-terminal-default-bg-mode (frame)
1016 "Return the default background mode of FRAME.
1017 This checks the `frame-background-mode' variable, the X resource
1018 named \"backgroundMode\" (if FRAME is an X frame), and finally
1019 the `background-mode' terminal parameter."
1020 (or frame-background-mode
1021 (let ((bg-resource
1022 (and (window-system frame)
1023 (x-get-resource "backgroundMode" "BackgroundMode"))))
1024 (if bg-resource
1025 (intern (downcase bg-resource))))
1026 (terminal-parameter frame 'background-mode)))
1029 ;;;; Frame configurations
1031 (defun current-frame-configuration ()
1032 "Return a list describing the positions and states of all frames.
1033 Its car is `frame-configuration'.
1034 Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
1035 where
1036 FRAME is a frame object,
1037 ALIST is an association list specifying some of FRAME's parameters, and
1038 WINDOW-CONFIG is a window configuration object for FRAME."
1039 (cons 'frame-configuration
1040 (mapcar (lambda (frame)
1041 (list frame
1042 (frame-parameters frame)
1043 (current-window-configuration frame)))
1044 (frame-list))))
1046 (defun set-frame-configuration (configuration &optional nodelete)
1047 "Restore the frames to the state described by CONFIGURATION.
1048 Each frame listed in CONFIGURATION has its position, size, window
1049 configuration, and other parameters set as specified in CONFIGURATION.
1050 However, this function does not restore deleted frames.
1052 Ordinarily, this function deletes all existing frames not
1053 listed in CONFIGURATION. But if optional second argument NODELETE
1054 is given and non-nil, the unwanted frames are iconified instead."
1055 (or (frame-configuration-p configuration)
1056 (signal 'wrong-type-argument
1057 (list 'frame-configuration-p configuration)))
1058 (let ((config-alist (cdr configuration))
1059 frames-to-delete)
1060 (dolist (frame (frame-list))
1061 (let ((parameters (assq frame config-alist)))
1062 (if parameters
1063 (progn
1064 (modify-frame-parameters
1065 frame
1066 ;; Since we can't set a frame's minibuffer status,
1067 ;; we might as well omit the parameter altogether.
1068 (let* ((parms (nth 1 parameters))
1069 (mini (assq 'minibuffer parms))
1070 (name (assq 'name parms))
1071 (explicit-name (cdr (assq 'explicit-name parms))))
1072 (when mini (setq parms (delq mini parms)))
1073 ;; Leave name in iff it was set explicitly.
1074 ;; This should fix the behavior reported in
1075 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg01632.html
1076 (when (and name (not explicit-name))
1077 (setq parms (delq name parms)))
1078 parms))
1079 (set-window-configuration (nth 2 parameters)))
1080 (setq frames-to-delete (cons frame frames-to-delete)))))
1081 (mapc (if nodelete
1082 ;; Note: making frames invisible here was tried
1083 ;; but led to some strange behavior--each time the frame
1084 ;; was made visible again, the window manager asked afresh
1085 ;; for where to put it.
1086 'iconify-frame
1087 'delete-frame)
1088 frames-to-delete)))
1090 ;;;; Convenience functions for accessing and interactively changing
1091 ;;;; frame parameters.
1093 (defun frame-height (&optional frame)
1094 "Return number of lines available for display on FRAME.
1095 If FRAME is omitted, describe the currently selected frame.
1096 Exactly what is included in the return value depends on the
1097 window-system and toolkit in use - see `frame-pixel-height' for
1098 more details. The lines are in units of the default font height.
1100 The result is roughly related to the frame pixel height via
1101 height in pixels = height in lines * `frame-char-height'.
1102 However, this is only approximate, and is complicated e.g. by the
1103 fact that individual window lines and menu bar lines can have
1104 differing font heights."
1105 (cdr (assq 'height (frame-parameters frame))))
1107 (defun frame-width (&optional frame)
1108 "Return number of columns available for display on FRAME.
1109 If FRAME is omitted, describe the currently selected frame."
1110 (cdr (assq 'width (frame-parameters frame))))
1112 (declare-function x-list-fonts "xfaces.c"
1113 (pattern &optional face frame maximum width))
1115 (define-obsolete-function-alias 'set-default-font 'set-frame-font "23.1")
1117 (defun set-frame-font (font &optional keep-size frames)
1118 "Set the default font to FONT.
1119 When called interactively, prompt for the name of a font, and use
1120 that font on the selected frame. When called from Lisp, FONT
1121 should be a font name (a string), a font object, font entity, or
1122 font spec.
1124 If KEEP-SIZE is nil, keep the number of frame lines and columns
1125 fixed. If KEEP-SIZE is non-nil (or with a prefix argument), try
1126 to keep the current frame size fixed (in pixels) by adjusting the
1127 number of lines and columns.
1129 If FRAMES is nil, apply the font to the selected frame only.
1130 If FRAMES is non-nil, it should be a list of frames to act upon,
1131 or t meaning all existing graphical frames.
1132 Also, if FRAMES is non-nil, alter the user's Customization settings
1133 as though the font-related attributes of the `default' face had been
1134 \"set in this session\", so that the font is applied to future frames."
1135 (interactive
1136 (let* ((completion-ignore-case t)
1137 (font (completing-read "Font name: "
1138 ;; x-list-fonts will fail with an error
1139 ;; if this frame doesn't support fonts.
1140 (x-list-fonts "*" nil (selected-frame))
1141 nil nil nil nil
1142 (frame-parameter nil 'font))))
1143 (list font current-prefix-arg nil)))
1144 (when (or (stringp font) (fontp font))
1145 (let* ((this-frame (selected-frame))
1146 ;; FRAMES nil means affect the selected frame.
1147 (frame-list (cond ((null frames)
1148 (list this-frame))
1149 ((eq frames t)
1150 (frame-list))
1151 (t frames)))
1152 height width)
1153 (dolist (f frame-list)
1154 (when (display-multi-font-p f)
1155 (if keep-size
1156 (setq height (* (frame-parameter f 'height)
1157 (frame-char-height f))
1158 width (* (frame-parameter f 'width)
1159 (frame-char-width f))))
1160 ;; When set-face-attribute is called for :font, Emacs
1161 ;; guesses the best font according to other face attributes
1162 ;; (:width, :weight, etc.) so reset them too (Bug#2476).
1163 (set-face-attribute 'default f
1164 :width 'normal :weight 'normal
1165 :slant 'normal :font font)
1166 (if keep-size
1167 (modify-frame-parameters
1169 (list (cons 'height (round height (frame-char-height f)))
1170 (cons 'width (round width (frame-char-width f))))))))
1171 (when frames
1172 ;; Alter the user's Custom setting of the `default' face, but
1173 ;; only for font-related attributes.
1174 (let ((specs (cadr (assq 'user (get 'default 'theme-face))))
1175 (attrs '(:family :foundry :slant :weight :height :width))
1176 (new-specs nil))
1177 (if (null specs) (setq specs '((t nil))))
1178 (dolist (spec specs)
1179 ;; Each SPEC has the form (DISPLAY ATTRIBUTE-PLIST)
1180 (let ((display (nth 0 spec))
1181 (plist (copy-tree (nth 1 spec))))
1182 ;; Alter only DISPLAY conditions matching this frame.
1183 (when (or (memq display '(t default))
1184 (face-spec-set-match-display display this-frame))
1185 (dolist (attr attrs)
1186 (setq plist (plist-put plist attr
1187 (face-attribute 'default attr)))))
1188 (push (list display plist) new-specs)))
1189 (setq new-specs (nreverse new-specs))
1190 (put 'default 'customized-face new-specs)
1191 (custom-push-theme 'theme-face 'default 'user 'set new-specs)
1192 (put 'default 'face-modified nil))))
1193 (run-hooks 'after-setting-font-hook 'after-setting-font-hooks)))
1195 (defun set-frame-parameter (frame parameter value)
1196 "Set frame parameter PARAMETER to VALUE on FRAME.
1197 If FRAME is nil, it defaults to the selected frame.
1198 See `modify-frame-parameters'."
1199 (modify-frame-parameters frame (list (cons parameter value))))
1201 (defun set-background-color (color-name)
1202 "Set the background color of the selected frame to COLOR-NAME.
1203 When called interactively, prompt for the name of the color to use.
1204 To get the frame's current background color, use `frame-parameters'."
1205 (interactive (list (read-color "Background color: ")))
1206 (modify-frame-parameters (selected-frame)
1207 (list (cons 'background-color color-name)))
1208 (or window-system
1209 (face-set-after-frame-default (selected-frame)
1210 (list
1211 (cons 'background-color color-name)
1212 ;; Pass the foreground-color as
1213 ;; well, if defined, to avoid
1214 ;; losing it when faces are reset
1215 ;; to their defaults.
1216 (assq 'foreground-color
1217 (frame-parameters))))))
1219 (defun set-foreground-color (color-name)
1220 "Set the foreground color of the selected frame to COLOR-NAME.
1221 When called interactively, prompt for the name of the color to use.
1222 To get the frame's current foreground color, use `frame-parameters'."
1223 (interactive (list (read-color "Foreground color: ")))
1224 (modify-frame-parameters (selected-frame)
1225 (list (cons 'foreground-color color-name)))
1226 (or window-system
1227 (face-set-after-frame-default (selected-frame)
1228 (list
1229 (cons 'foreground-color color-name)
1230 ;; Pass the background-color as
1231 ;; well, if defined, to avoid
1232 ;; losing it when faces are reset
1233 ;; to their defaults.
1234 (assq 'background-color
1235 (frame-parameters))))))
1237 (defun set-cursor-color (color-name)
1238 "Set the text cursor color of the selected frame to COLOR-NAME.
1239 When called interactively, prompt for the name of the color to use.
1240 This works by setting the `cursor-color' frame parameter on the
1241 selected frame.
1243 You can also set the text cursor color, for all frames, by
1244 customizing the `cursor' face."
1245 (interactive (list (read-color "Cursor color: ")))
1246 (modify-frame-parameters (selected-frame)
1247 (list (cons 'cursor-color color-name))))
1249 (defun set-mouse-color (color-name)
1250 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
1251 When called interactively, prompt for the name of the color to use.
1252 To get the frame's current mouse color, use `frame-parameters'."
1253 (interactive (list (read-color "Mouse color: ")))
1254 (modify-frame-parameters (selected-frame)
1255 (list (cons 'mouse-color
1256 (or color-name
1257 (cdr (assq 'mouse-color
1258 (frame-parameters))))))))
1260 (defun set-border-color (color-name)
1261 "Set the color of the border of the selected frame to COLOR-NAME.
1262 When called interactively, prompt for the name of the color to use.
1263 To get the frame's current border color, use `frame-parameters'."
1264 (interactive (list (read-color "Border color: ")))
1265 (modify-frame-parameters (selected-frame)
1266 (list (cons 'border-color color-name))))
1268 (define-minor-mode auto-raise-mode
1269 "Toggle whether or not selected frames should auto-raise.
1270 With a prefix argument ARG, enable Auto Raise mode if ARG is
1271 positive, and disable it otherwise. If called from Lisp, enable
1272 the mode if ARG is omitted or nil.
1274 Auto Raise mode does nothing under most window managers, which
1275 switch focus on mouse clicks. It only has an effect if your
1276 window manager switches focus on mouse movement (in which case
1277 you should also change `focus-follows-mouse' to t). Then,
1278 enabling Auto Raise mode causes any graphical Emacs frame which
1279 acquires focus to be automatically raised.
1281 Note that this minor mode controls Emacs's own auto-raise
1282 feature. Window managers that switch focus on mouse movement
1283 often have their own auto-raise feature."
1284 :variable (frame-parameter nil 'auto-raise)
1285 (if (frame-parameter nil 'auto-raise)
1286 (raise-frame)))
1288 (define-minor-mode auto-lower-mode
1289 "Toggle whether or not the selected frame should auto-lower.
1290 With a prefix argument ARG, enable Auto Lower mode if ARG is
1291 positive, and disable it otherwise. If called from Lisp, enable
1292 the mode if ARG is omitted or nil.
1294 Auto Lower mode does nothing under most window managers, which
1295 switch focus on mouse clicks. It only has an effect if your
1296 window manager switches focus on mouse movement (in which case
1297 you should also change `focus-follows-mouse' to t). Then,
1298 enabling Auto Lower Mode causes any graphical Emacs frame which
1299 loses focus to be automatically lowered.
1301 Note that this minor mode controls Emacs's own auto-lower
1302 feature. Window managers that switch focus on mouse movement
1303 often have their own features for raising or lowering frames."
1304 :variable (frame-parameter nil 'auto-lower))
1306 (defun set-frame-name (name)
1307 "Set the name of the selected frame to NAME.
1308 When called interactively, prompt for the name of the frame.
1309 On text terminals, the frame name is displayed on the mode line.
1310 On graphical displays, it is displayed on the frame's title bar."
1311 (interactive "sFrame name: ")
1312 (modify-frame-parameters (selected-frame)
1313 (list (cons 'name name))))
1315 (defun frame-current-scroll-bars (&optional frame)
1316 "Return the current scroll-bar types for frame FRAME.
1317 Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies
1318 the current location of the vertical scroll-bars (`left', `right'
1319 or nil), and HORIZONTAL specifies the current location of the
1320 horizontal scroll bars (`bottom' or nil). FRAME must specify a
1321 live frame and defaults to the selected one."
1322 (let* ((frame (window-normalize-frame frame))
1323 (vertical (frame-parameter frame 'vertical-scroll-bars))
1324 (horizontal (frame-parameter frame 'horizontal-scroll-bars)))
1325 (unless (memq vertical '(left right nil))
1326 (setq vertical default-frame-scroll-bars))
1327 (cons vertical (and horizontal 'bottom))))
1329 (defun frame-monitor-attributes (&optional frame)
1330 "Return the attributes of the physical monitor dominating FRAME.
1331 If FRAME is omitted or nil, describe the currently selected frame.
1333 A frame is dominated by a physical monitor when either the
1334 largest area of the frame resides in the monitor, or the monitor
1335 is the closest to the frame if the frame does not intersect any
1336 physical monitors.
1338 See `display-monitor-attributes-list' for the list of attribute
1339 keys and their meanings."
1340 (or frame (setq frame (selected-frame)))
1341 (cl-loop for attributes in (display-monitor-attributes-list frame)
1342 for frames = (cdr (assq 'frames attributes))
1343 if (memq frame frames) return attributes))
1346 ;;;; Frame/display capabilities.
1348 (declare-function msdos-mouse-p "dosfns.c")
1350 (defun display-mouse-p (&optional display)
1351 "Return non-nil if DISPLAY has a mouse available.
1352 DISPLAY can be a display name, a frame, or nil (meaning the selected
1353 frame's display)."
1354 (let ((frame-type (framep-on-display display)))
1355 (cond
1356 ((eq frame-type 'pc)
1357 (msdos-mouse-p))
1358 ((eq frame-type 'w32)
1359 (with-no-warnings
1360 (> w32-num-mouse-buttons 0)))
1361 ((memq frame-type '(x ns))
1362 t) ;; We assume X and NeXTstep *always* have a pointing device
1364 (or (and (featurep 'xt-mouse)
1365 xterm-mouse-mode)
1366 ;; t-mouse is distributed with the GPM package. It doesn't have
1367 ;; a toggle.
1368 (featurep 't-mouse)
1369 ;; No way to check whether a w32 console has a mouse, assume
1370 ;; it always does.
1371 (boundp 'w32-use-full-screen-buffer))))))
1373 (defun display-popup-menus-p (&optional display)
1374 "Return non-nil if popup menus are supported on DISPLAY.
1375 DISPLAY can be a display name, a frame, or nil (meaning the selected
1376 frame's display).
1377 Support for popup menus requires that the mouse be available."
1378 (display-mouse-p display))
1380 (defun display-graphic-p (&optional display)
1381 "Return non-nil if DISPLAY is a graphic display.
1382 Graphical displays are those which are capable of displaying several
1383 frames and several different fonts at once. This is true for displays
1384 that use a window system such as X, and false for text-only terminals.
1385 DISPLAY can be a display name, a frame, or nil (meaning the selected
1386 frame's display)."
1387 (not (null (memq (framep-on-display display) '(x w32 ns)))))
1389 (defun display-images-p (&optional display)
1390 "Return non-nil if DISPLAY can display images.
1392 DISPLAY can be a display name, a frame, or nil (meaning the selected
1393 frame's display)."
1394 (and (display-graphic-p display)
1395 (fboundp 'image-mask-p)
1396 (fboundp 'image-size)))
1398 (defalias 'display-multi-frame-p 'display-graphic-p)
1399 (defalias 'display-multi-font-p 'display-graphic-p)
1401 (defun display-selections-p (&optional display)
1402 "Return non-nil if DISPLAY supports selections.
1403 A selection is a way to transfer text or other data between programs
1404 via special system buffers called `selection' or `clipboard'.
1405 DISPLAY can be a display name, a frame, or nil (meaning the selected
1406 frame's display)."
1407 (let ((frame-type (framep-on-display display)))
1408 (cond
1409 ((eq frame-type 'pc)
1410 ;; MS-DOS frames support selections when Emacs runs inside
1411 ;; a Windows DOS Box.
1412 (with-no-warnings
1413 (not (null dos-windows-version))))
1414 ((memq frame-type '(x w32 ns))
1417 nil))))
1419 (declare-function x-display-screens "xfns.c" (&optional terminal))
1421 (defun display-screens (&optional display)
1422 "Return the number of screens associated with DISPLAY.
1423 DISPLAY should be either a frame or a display name (a string).
1424 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1425 (let ((frame-type (framep-on-display display)))
1426 (cond
1427 ((memq frame-type '(x w32 ns))
1428 (x-display-screens display))
1430 1))))
1432 (declare-function x-display-pixel-height "xfns.c" (&optional terminal))
1434 (defun display-pixel-height (&optional display)
1435 "Return the height of DISPLAY's screen in pixels.
1436 DISPLAY can be a display name or a frame.
1437 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1439 For character terminals, each character counts as a single pixel.
1441 For graphical terminals, note that on \"multi-monitor\" setups this
1442 refers to the pixel height for all physical monitors associated
1443 with DISPLAY. To get information for each physical monitor, use
1444 `display-monitor-attributes-list'."
1445 (let ((frame-type (framep-on-display display)))
1446 (cond
1447 ((memq frame-type '(x w32 ns))
1448 (x-display-pixel-height display))
1450 (frame-height (if (framep display) display (selected-frame)))))))
1452 (declare-function x-display-pixel-width "xfns.c" (&optional terminal))
1454 (defun display-pixel-width (&optional display)
1455 "Return the width of DISPLAY's screen in pixels.
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 For character terminals, each character counts as a single pixel.
1461 For graphical terminals, note that on \"multi-monitor\" setups this
1462 refers to the pixel width for all physical monitors associated
1463 with DISPLAY. To get information for each physical monitor, use
1464 `display-monitor-attributes-list'."
1465 (let ((frame-type (framep-on-display display)))
1466 (cond
1467 ((memq frame-type '(x w32 ns))
1468 (x-display-pixel-width display))
1470 (frame-width (if (framep display) display (selected-frame)))))))
1472 (defcustom display-mm-dimensions-alist nil
1473 "Alist for specifying screen dimensions in millimeters.
1474 The functions `display-mm-height' and `display-mm-width' consult
1475 this list before asking the system.
1477 Each element has the form (DISPLAY . (WIDTH . HEIGHT)), e.g.
1478 \(\":0.0\" . (287 . 215)).
1480 If `display' is t, it specifies dimensions for all graphical displays
1481 not explicitly specified."
1482 :version "22.1"
1483 :type '(alist :key-type (choice (string :tag "Display name")
1484 (const :tag "Default" t))
1485 :value-type (cons :tag "Dimensions"
1486 (integer :tag "Width")
1487 (integer :tag "Height")))
1488 :group 'frames)
1490 (declare-function x-display-mm-height "xfns.c" (&optional terminal))
1492 (defun display-mm-height (&optional display)
1493 "Return the height of DISPLAY's screen in millimeters.
1494 If the information is unavailable, this function returns nil.
1495 DISPLAY can be a display name or a frame.
1496 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1498 You can override what the system thinks the result should be by
1499 adding an entry to `display-mm-dimensions-alist'.
1501 For graphical terminals, note that on \"multi-monitor\" setups this
1502 refers to the height in millimeters for all physical monitors
1503 associated with DISPLAY. To get information for each physical
1504 monitor, use `display-monitor-attributes-list'."
1505 (and (memq (framep-on-display display) '(x w32 ns))
1506 (or (cddr (assoc (or display (frame-parameter nil 'display))
1507 display-mm-dimensions-alist))
1508 (cddr (assoc t display-mm-dimensions-alist))
1509 (x-display-mm-height display))))
1511 (declare-function x-display-mm-width "xfns.c" (&optional terminal))
1513 (defun display-mm-width (&optional display)
1514 "Return the width of DISPLAY's screen in millimeters.
1515 If the information is unavailable, this function returns nil.
1516 DISPLAY can be a display name or a frame.
1517 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1519 You can override what the system thinks the result should be by
1520 adding an entry to `display-mm-dimensions-alist'.
1522 For graphical terminals, note that on \"multi-monitor\" setups this
1523 refers to the width in millimeters for all physical monitors
1524 associated with DISPLAY. To get information for each physical
1525 monitor, use `display-monitor-attributes-list'."
1526 (and (memq (framep-on-display display) '(x w32 ns))
1527 (or (cadr (assoc (or display (frame-parameter nil 'display))
1528 display-mm-dimensions-alist))
1529 (cadr (assoc t display-mm-dimensions-alist))
1530 (x-display-mm-width display))))
1532 (declare-function x-display-backing-store "xfns.c" (&optional terminal))
1534 ;; In NS port, the return value may be `buffered', `retained', or
1535 ;; `non-retained'. See src/nsfns.m.
1536 (defun display-backing-store (&optional display)
1537 "Return the backing store capability of DISPLAY's screen.
1538 The value may be `always', `when-mapped', `not-useful', or nil if
1539 the question is inapplicable to a certain kind of display.
1540 DISPLAY can be a display name or a frame.
1541 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1542 (let ((frame-type (framep-on-display display)))
1543 (cond
1544 ((memq frame-type '(x w32 ns))
1545 (x-display-backing-store display))
1547 'not-useful))))
1549 (declare-function x-display-save-under "xfns.c" (&optional terminal))
1551 (defun display-save-under (&optional display)
1552 "Return non-nil if DISPLAY's screen supports the SaveUnder feature.
1553 DISPLAY can be a display name or a frame.
1554 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1555 (let ((frame-type (framep-on-display display)))
1556 (cond
1557 ((memq frame-type '(x w32 ns))
1558 (x-display-save-under display))
1560 'not-useful))))
1562 (declare-function x-display-planes "xfns.c" (&optional terminal))
1564 (defun display-planes (&optional display)
1565 "Return the number of planes supported by DISPLAY.
1566 DISPLAY can be a display name or a frame.
1567 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1568 (let ((frame-type (framep-on-display display)))
1569 (cond
1570 ((memq frame-type '(x w32 ns))
1571 (x-display-planes display))
1572 ((eq frame-type 'pc)
1575 (truncate (log (length (tty-color-alist)) 2))))))
1577 (declare-function x-display-color-cells "xfns.c" (&optional terminal))
1579 (defun display-color-cells (&optional display)
1580 "Return the number of color cells supported by DISPLAY.
1581 DISPLAY can be a display name or a frame.
1582 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1583 (let ((frame-type (framep-on-display display)))
1584 (cond
1585 ((memq frame-type '(x w32 ns))
1586 (x-display-color-cells display))
1587 ((eq frame-type 'pc)
1590 (tty-display-color-cells display)))))
1592 (declare-function x-display-visual-class "xfns.c" (&optional terminal))
1594 (defun display-visual-class (&optional display)
1595 "Return the visual class of DISPLAY.
1596 The value is one of the symbols `static-gray', `gray-scale',
1597 `static-color', `pseudo-color', `true-color', or `direct-color'.
1598 DISPLAY can be a display name or a frame.
1599 If DISPLAY is omitted or nil, it defaults to the selected frame's display."
1600 (let ((frame-type (framep-on-display display)))
1601 (cond
1602 ((memq frame-type '(x w32 ns))
1603 (x-display-visual-class display))
1604 ((and (memq frame-type '(pc t))
1605 (tty-display-color-p display))
1606 'static-color)
1608 'static-gray))))
1610 (declare-function x-display-monitor-attributes-list "xfns.c"
1611 (&optional terminal))
1612 (declare-function w32-display-monitor-attributes-list "w32fns.c"
1613 (&optional display))
1614 (declare-function ns-display-monitor-attributes-list "nsfns.m"
1615 (&optional terminal))
1617 (defun display-monitor-attributes-list (&optional display)
1618 "Return a list of physical monitor attributes on DISPLAY.
1619 DISPLAY can be a display name, a terminal name, or a frame.
1620 If DISPLAY is omitted or nil, it defaults to the selected frame's display.
1621 Each element of the list represents the attributes of a physical
1622 monitor. The first element corresponds to the primary monitor.
1624 The attributes for a physical monitor are represented as an alist
1625 of attribute keys and values as follows:
1627 geometry -- Position and size in pixels in the form of (X Y WIDTH HEIGHT)
1628 workarea -- Position and size of the work area in pixels in the
1629 form of (X Y WIDTH HEIGHT)
1630 mm-size -- Width and height in millimeters in the form of
1631 (WIDTH HEIGHT)
1632 frames -- List of frames dominated by the physical monitor
1633 name (*) -- Name of the physical monitor as a string
1634 source (*) -- Source of multi-monitor information as a string
1636 where X, Y, WIDTH, and HEIGHT are integers. X and Y are coordinates
1637 of the top-left corner, and might be negative for monitors other than
1638 the primary one. Keys labeled with (*) are optional.
1640 The \"work area\" is a measure of the \"usable\" display space.
1641 It may be less than the total screen size, owing to space taken up
1642 by window manager features (docks, taskbars, etc.). The precise
1643 details depend on the platform and environment.
1645 The `source' attribute describes the source from which the information
1646 was obtained. On X, this may be one of: \"Gdk\", \"XRandr\", \"Xinerama\",
1647 or \"fallback\".
1649 A frame is dominated by a physical monitor when either the
1650 largest area of the frame resides in the monitor, or the monitor
1651 is the closest to the frame if the frame does not intersect any
1652 physical monitors. Every (non-tooltip) frame (including invisible ones)
1653 in a graphical display is dominated by exactly one physical
1654 monitor at a time, though it can span multiple (or no) physical
1655 monitors."
1656 (let ((frame-type (framep-on-display display)))
1657 (cond
1658 ((eq frame-type 'x)
1659 (x-display-monitor-attributes-list display))
1660 ((eq frame-type 'w32)
1661 (w32-display-monitor-attributes-list display))
1662 ((eq frame-type 'ns)
1663 (ns-display-monitor-attributes-list display))
1665 (let ((geometry (list 0 0 (display-pixel-width display)
1666 (display-pixel-height display))))
1667 `(((geometry . ,geometry)
1668 (workarea . ,geometry)
1669 (mm-size . (,(display-mm-width display)
1670 ,(display-mm-height display)))
1671 (frames . ,(frames-on-display-list display)))))))))
1674 ;;;; Frame geometry values
1676 (defun frame-geom-value-cons (type value &optional frame)
1677 "Return equivalent geometry value for FRAME as a cons with car `+'.
1678 A geometry value equivalent to VALUE for FRAME is returned,
1679 where the value is a cons with car `+', not numeric.
1680 TYPE is the car of the original geometry spec (TYPE . VALUE).
1681 It is `top' or `left', depending on which edge VALUE is related to.
1682 VALUE is the cdr of a frame geometry spec: (left/top . VALUE).
1683 If VALUE is a number, then it is converted to a cons value, perhaps
1684 relative to the opposite frame edge from that in the original spec.
1685 FRAME defaults to the selected frame.
1687 Examples (measures in pixels) -
1688 Assuming display height/width=1024, frame height/width=600:
1689 300 inside display edge: 300 => (+ 300)
1690 (+ 300) => (+ 300)
1691 300 inside opposite display edge: (- 300) => (+ 124)
1692 -300 => (+ 124)
1693 300 beyond display edge
1694 (= 724 inside opposite display edge): (+ -300) => (+ -300)
1695 300 beyond display edge
1696 (= 724 inside opposite display edge): (- -300) => (+ 724)
1698 In the 3rd, 4th, and 6th examples, the returned value is relative to
1699 the opposite frame edge from the edge indicated in the input spec."
1700 (cond ((and (consp value) (eq '+ (car value))) ; e.g. (+ 300), (+ -300)
1701 value)
1702 ((natnump value) (list '+ value)) ; e.g. 300 => (+ 300)
1703 (t ; e.g. -300, (- 300), (- -300)
1704 (list '+ (- (if (eq 'left type) ; => (+ 124), (+ 124), (+ 724)
1705 (x-display-pixel-width)
1706 (x-display-pixel-height))
1707 (if (integerp value) (- value) (cadr value))
1708 (if (eq 'left type)
1709 (frame-pixel-width frame)
1710 (frame-pixel-height frame)))))))
1712 (defun frame-geom-spec-cons (spec &optional frame)
1713 "Return equivalent geometry spec for FRAME as a cons with car `+'.
1714 A geometry specification equivalent to SPEC for FRAME is returned,
1715 where the value is a cons with car `+', not numeric.
1716 SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE).
1717 If VALUE is a number, then it is converted to a cons value, perhaps
1718 relative to the opposite frame edge from that in the original spec.
1719 FRAME defaults to the selected frame.
1721 Examples (measures in pixels) -
1722 Assuming display height=1024, frame height=600:
1723 top 300 below display top: (top . 300) => (top + 300)
1724 (top + 300) => (top + 300)
1725 bottom 300 above display bottom: (top - 300) => (top + 124)
1726 (top . -300) => (top + 124)
1727 top 300 above display top
1728 (= bottom 724 above display bottom): (top + -300) => (top + -300)
1729 bottom 300 below display bottom
1730 (= top 724 below display top): (top - -300) => (top + 724)
1732 In the 3rd, 4th, and 6th examples, the returned value is relative to
1733 the opposite frame edge from the edge indicated in the input spec."
1734 (cons (car spec) (frame-geom-value-cons (car spec) (cdr spec) frame)))
1737 (defun delete-other-frames (&optional frame)
1738 "Delete all frames on the current terminal, except FRAME.
1739 If FRAME uses another frame's minibuffer, the minibuffer frame is
1740 left untouched. FRAME nil or omitted means use the selected frame."
1741 (interactive)
1742 (unless frame
1743 (setq frame (selected-frame)))
1744 (let* ((mini-frame (window-frame (minibuffer-window frame)))
1745 (frames (delq mini-frame (delq frame (frame-list)))))
1746 ;; Only consider frames on the same terminal.
1747 (dolist (frame (prog1 frames (setq frames nil)))
1748 (if (eq (frame-terminal) (frame-terminal frame))
1749 (push frame frames)))
1750 ;; Delete mon-minibuffer-only frames first, because `delete-frame'
1751 ;; signals an error when trying to delete a mini-frame that's
1752 ;; still in use by another frame.
1753 (dolist (frame frames)
1754 (unless (eq (frame-parameter frame 'minibuffer) 'only)
1755 (delete-frame frame)))
1756 ;; Delete minibuffer-only frames.
1757 (dolist (frame frames)
1758 (when (eq (frame-parameter frame 'minibuffer) 'only)
1759 (delete-frame frame)))))
1761 ;; miscellaneous obsolescence declarations
1762 (define-obsolete-variable-alias 'delete-frame-hook
1763 'delete-frame-functions "22.1")
1766 ;; Blinking cursor
1768 (defgroup cursor nil
1769 "Displaying text cursors."
1770 :version "21.1"
1771 :group 'frames)
1773 (defcustom blink-cursor-delay 0.5
1774 "Seconds of idle time after which cursor starts to blink."
1775 :type 'number
1776 :group 'cursor)
1778 (defcustom blink-cursor-interval 0.5
1779 "Length of cursor blink interval in seconds."
1780 :type 'number
1781 :group 'cursor)
1783 (defcustom blink-cursor-blinks 10
1784 "How many times to blink before using a solid cursor on NS, X, and MS-Windows.
1785 Use 0 or negative value to blink forever."
1786 :version "24.4"
1787 :type 'integer
1788 :group 'cursor)
1790 (defvar blink-cursor-blinks-done 1
1791 "Number of blinks done since we started blinking on NS, X, and MS-Windows.")
1793 (defvar blink-cursor-idle-timer nil
1794 "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
1795 The function `blink-cursor-start' is called when the timer fires.")
1797 (defvar blink-cursor-timer nil
1798 "Timer started from `blink-cursor-start'.
1799 This timer calls `blink-cursor-timer-function' every
1800 `blink-cursor-interval' seconds.")
1802 (defun blink-cursor-start ()
1803 "Timer function called from the timer `blink-cursor-idle-timer'.
1804 This starts the timer `blink-cursor-timer', which makes the cursor blink
1805 if appropriate. It also arranges to cancel that timer when the next
1806 command starts, by installing a pre-command hook."
1807 (when (null blink-cursor-timer)
1808 ;; Set up the timer first, so that if this signals an error,
1809 ;; blink-cursor-end is not added to pre-command-hook.
1810 (setq blink-cursor-blinks-done 1)
1811 (setq blink-cursor-timer
1812 (run-with-timer blink-cursor-interval blink-cursor-interval
1813 'blink-cursor-timer-function))
1814 (add-hook 'pre-command-hook 'blink-cursor-end)
1815 (internal-show-cursor nil nil)))
1817 (defun blink-cursor-timer-function ()
1818 "Timer function of timer `blink-cursor-timer'."
1819 (internal-show-cursor nil (not (internal-show-cursor-p)))
1820 ;; Suspend counting blinks when the w32 menu-bar menu is displayed,
1821 ;; since otherwise menu tooltips will behave erratically.
1822 (or (and (fboundp 'w32--menu-bar-in-use)
1823 (w32--menu-bar-in-use))
1824 (setq blink-cursor-blinks-done (1+ blink-cursor-blinks-done)))
1825 ;; Each blink is two calls to this function.
1826 (when (and (> blink-cursor-blinks 0)
1827 (<= (* 2 blink-cursor-blinks) blink-cursor-blinks-done))
1828 (blink-cursor-suspend)
1829 (add-hook 'post-command-hook 'blink-cursor-check)))
1832 (defun blink-cursor-end ()
1833 "Stop cursor blinking.
1834 This is installed as a pre-command hook by `blink-cursor-start'.
1835 When run, it cancels the timer `blink-cursor-timer' and removes
1836 itself as a pre-command hook."
1837 (remove-hook 'pre-command-hook 'blink-cursor-end)
1838 (internal-show-cursor nil t)
1839 (when blink-cursor-timer
1840 (cancel-timer blink-cursor-timer)
1841 (setq blink-cursor-timer nil)))
1843 (defun blink-cursor-suspend ()
1844 "Suspend cursor blinking.
1845 This is called when no frame has focus and timers can be suspended.
1846 Timers are restarted by `blink-cursor-check', which is called when a
1847 frame receives focus."
1848 (blink-cursor-end)
1849 (when blink-cursor-idle-timer
1850 (cancel-timer blink-cursor-idle-timer)
1851 (setq blink-cursor-idle-timer nil)))
1853 (defun blink-cursor-check ()
1854 "Check if cursor blinking shall be restarted.
1855 This is done when a frame gets focus. Blink timers may be stopped by
1856 `blink-cursor-suspend'."
1857 (when (and blink-cursor-mode
1858 (not blink-cursor-idle-timer))
1859 (remove-hook 'post-command-hook 'blink-cursor-check)
1860 (setq blink-cursor-idle-timer
1861 (run-with-idle-timer blink-cursor-delay
1862 blink-cursor-delay
1863 'blink-cursor-start))))
1865 (define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1")
1867 (define-minor-mode blink-cursor-mode
1868 "Toggle cursor blinking (Blink Cursor mode).
1869 With a prefix argument ARG, enable Blink Cursor mode if ARG is
1870 positive, and disable it otherwise. If called from Lisp, enable
1871 the mode if ARG is omitted or nil.
1873 If the value of `blink-cursor-blinks' is positive (10 by default),
1874 the cursor stops blinking after that number of blinks, if Emacs
1875 gets no input during that time.
1877 See also `blink-cursor-interval' and `blink-cursor-delay'.
1879 This command is effective only on graphical frames. On text-only
1880 terminals, cursor blinking is controlled by the terminal."
1881 :init-value (not (or noninteractive
1882 no-blinking-cursor
1883 (eq system-type 'ms-dos)
1884 (not (memq window-system '(x w32 ns)))))
1885 :initialize 'custom-initialize-delay
1886 :group 'cursor
1887 :global t
1888 (blink-cursor-suspend)
1889 (remove-hook 'focus-in-hook #'blink-cursor-check)
1890 (remove-hook 'focus-out-hook #'blink-cursor-suspend)
1891 (when blink-cursor-mode
1892 (add-hook 'focus-in-hook #'blink-cursor-check)
1893 (add-hook 'focus-out-hook #'blink-cursor-suspend)
1894 (setq blink-cursor-idle-timer
1895 (run-with-idle-timer blink-cursor-delay
1896 blink-cursor-delay
1897 #'blink-cursor-start))))
1900 ;; Frame maximization/fullscreen
1902 (defun toggle-frame-maximized ()
1903 "Toggle maximization state of selected frame.
1904 Maximize selected frame or un-maximize if it is already maximized.
1906 If the frame is in fullscreen state, don't change its state, but
1907 set the frame's `fullscreen-restore' parameter to `maximized', so
1908 the frame will be maximized after disabling fullscreen state.
1910 Note that with some window managers you may have to set
1911 `frame-resize-pixelwise' to non-nil in order to make a frame
1912 appear truly maximized. In addition, you may have to set
1913 `x-frame-normalize-before-maximize' in order to enable
1914 transitions from one fullscreen state to another.
1916 See also `toggle-frame-fullscreen'."
1917 (interactive)
1918 (let ((fullscreen (frame-parameter nil 'fullscreen)))
1919 (cond
1920 ((memq fullscreen '(fullscreen fullboth))
1921 (set-frame-parameter nil 'fullscreen-restore 'maximized))
1922 ((eq fullscreen 'maximized)
1923 (set-frame-parameter nil 'fullscreen nil))
1925 (set-frame-parameter nil 'fullscreen 'maximized)))))
1927 (defun toggle-frame-fullscreen ()
1928 "Toggle fullscreen state of selected frame.
1929 Make selected frame fullscreen or restore its previous size if it
1930 is already fullscreen.
1932 Before making the frame fullscreen remember the current value of
1933 the frame's `fullscreen' parameter in the `fullscreen-restore'
1934 parameter of the frame. That value is used to restore the
1935 frame's fullscreen state when toggling fullscreen the next time.
1937 Note that with some window managers you may have to set
1938 `frame-resize-pixelwise' to non-nil in order to make a frame
1939 appear truly fullscreen. In addition, you may have to set
1940 `x-frame-normalize-before-maximize' in order to enable
1941 transitions from one fullscreen state to another.
1943 See also `toggle-frame-maximized'."
1944 (interactive)
1945 (let ((fullscreen (frame-parameter nil 'fullscreen)))
1946 (if (memq fullscreen '(fullscreen fullboth))
1947 (let ((fullscreen-restore (frame-parameter nil 'fullscreen-restore)))
1948 (if (memq fullscreen-restore '(maximized fullheight fullwidth))
1949 (set-frame-parameter nil 'fullscreen fullscreen-restore)
1950 (set-frame-parameter nil 'fullscreen nil)))
1951 (modify-frame-parameters
1952 nil `((fullscreen . fullboth) (fullscreen-restore . ,fullscreen))))))
1954 ;;;; Key bindings
1956 (define-key ctl-x-5-map "2" 'make-frame-command)
1957 (define-key ctl-x-5-map "1" 'delete-other-frames)
1958 (define-key ctl-x-5-map "0" 'delete-frame)
1959 (define-key ctl-x-5-map "o" 'other-frame)
1960 (define-key global-map [f11] 'toggle-frame-fullscreen)
1961 (define-key global-map [(meta f10)] 'toggle-frame-maximized)
1962 (define-key esc-map [f10] 'toggle-frame-maximized)
1965 ;; Misc.
1967 ;; Only marked as obsolete in 24.3.
1968 (define-obsolete-variable-alias 'automatic-hscrolling
1969 'auto-hscroll-mode "22.1")
1971 (make-variable-buffer-local 'show-trailing-whitespace)
1973 ;; Defined in dispnew.c.
1974 (make-obsolete-variable
1975 'window-system-version "it does not give useful information." "24.3")
1977 (provide 'frame)
1979 ;;; frame.el ends here