| 1 | ;;; frame.el --- multi-frame management independent of window systems. |
| 2 | |
| 3 | ;; Copyright (C) 1993, 1994, 1996, 1997, 2000 Free Software Foundation, Inc. |
| 4 | |
| 5 | ;; Maintainer: FSF |
| 6 | ;; Keywords: internal |
| 7 | |
| 8 | ;; This file is part of GNU Emacs. |
| 9 | |
| 10 | ;; GNU Emacs is free software; you can redistribute it and/or modify |
| 11 | ;; it under the terms of the GNU General Public License as published by |
| 12 | ;; the Free Software Foundation; either version 2, or (at your option) |
| 13 | ;; any later version. |
| 14 | |
| 15 | ;; GNU Emacs is distributed in the hope that it will be useful, |
| 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | ;; GNU General Public License for more details. |
| 19 | |
| 20 | ;; You should have received a copy of the GNU General Public License |
| 21 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
| 22 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 23 | ;; Boston, MA 02111-1307, USA. |
| 24 | |
| 25 | ;;; Code: |
| 26 | |
| 27 | (defvar frame-creation-function nil |
| 28 | "Window-system dependent function to call to create a new frame. |
| 29 | The window system startup file should set this to its frame creation |
| 30 | function, which should take an alist of parameters as its argument.") |
| 31 | |
| 32 | ;;; The initial value given here for used to ask for a minibuffer. |
| 33 | ;;; But that's not necessary, because the default is to have one. |
| 34 | ;;; By not specifying it here, we let an X resource specify it. |
| 35 | (defcustom initial-frame-alist nil |
| 36 | "*Alist of frame parameters for creating the initial X window frame. |
| 37 | You can set this in your `.emacs' file; for example, |
| 38 | (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55))) |
| 39 | Parameters specified here supersede the values given in `default-frame-alist'. |
| 40 | |
| 41 | If the value calls for a frame without a minibuffer, and you have not created |
| 42 | a minibuffer frame on your own, one is created according to |
| 43 | `minibuffer-frame-alist'. |
| 44 | |
| 45 | You can specify geometry-related options for just the initial frame |
| 46 | by setting this variable in your `.emacs' file; however, they won't |
| 47 | take effect until Emacs reads `.emacs', which happens after first creating |
| 48 | the frame. If you want the frame to have the proper geometry as soon |
| 49 | as it appears, you need to use this three-step process: |
| 50 | * Specify X resources to give the geometry you want. |
| 51 | * Set `default-frame-alist' to override these options so that they |
| 52 | don't affect subsequent frames. |
| 53 | * Set `initial-frame-alist' in a way that matches the X resources, |
| 54 | to override what you put in `default-frame-alist'." |
| 55 | :type '(repeat (cons :format "%v" |
| 56 | (symbol :tag "Parameter") |
| 57 | (sexp :tag "Value"))) |
| 58 | :group 'frames) |
| 59 | |
| 60 | (defcustom minibuffer-frame-alist '((width . 80) (height . 2)) |
| 61 | "*Alist of frame parameters for initially creating a minibuffer frame. |
| 62 | You can set this in your `.emacs' file; for example, |
| 63 | (setq minibuffer-frame-alist |
| 64 | '((top . 1) (left . 1) (width . 80) (height . 2))) |
| 65 | Parameters specified here supersede the values given in |
| 66 | `default-frame-alist', for a minibuffer frame." |
| 67 | :type '(repeat (cons :format "%v" |
| 68 | (symbol :tag "Parameter") |
| 69 | (sexp :tag "Value"))) |
| 70 | :group 'frames) |
| 71 | |
| 72 | (defcustom pop-up-frame-alist nil |
| 73 | "*Alist of frame parameters used when creating pop-up frames. |
| 74 | Pop-up frames are used for completions, help, and the like. |
| 75 | This variable can be set in your init file, like this: |
| 76 | (setq pop-up-frame-alist '((width . 80) (height . 20))) |
| 77 | These supersede the values given in `default-frame-alist', |
| 78 | for pop-up frames." |
| 79 | :type '(repeat (cons :format "%v" |
| 80 | (symbol :tag "Parameter") |
| 81 | (sexp :tag "Value"))) |
| 82 | :group 'frames) |
| 83 | |
| 84 | (setq pop-up-frame-function |
| 85 | (function (lambda () |
| 86 | (make-frame pop-up-frame-alist)))) |
| 87 | |
| 88 | (defcustom special-display-frame-alist |
| 89 | '((height . 14) (width . 80) (unsplittable . t)) |
| 90 | "*Alist of frame parameters used when creating special frames. |
| 91 | Special frames are used for buffers whose names are in |
| 92 | `special-display-buffer-names' and for buffers whose names match |
| 93 | one of the regular expressions in `special-display-regexps'. |
| 94 | This variable can be set in your init file, like this: |
| 95 | (setq special-display-frame-alist '((width . 80) (height . 20))) |
| 96 | These supersede the values given in `default-frame-alist'." |
| 97 | :type '(repeat (cons :format "%v" |
| 98 | (symbol :tag "Parameter") |
| 99 | (sexp :tag "Value"))) |
| 100 | :group 'frames) |
| 101 | |
| 102 | (defun special-display-popup-frame (buffer &optional args) |
| 103 | "Display BUFFER in its own frame, reusing an existing window if any. |
| 104 | Return the window chosen. |
| 105 | Currently we do not insist on selecting the window within its frame. |
| 106 | If ARGS is an alist, use it as a list of frame parameter specs. |
| 107 | If ARGS is a list whose car is a symbol, |
| 108 | use (car ARGS) as a function to do the work. |
| 109 | Pass it BUFFER as first arg, and (cdr ARGS) gives the rest of the args." |
| 110 | (if (and args (symbolp (car args))) |
| 111 | (apply (car args) buffer (cdr args)) |
| 112 | (let ((window (get-buffer-window buffer t))) |
| 113 | (if window |
| 114 | ;; If we have a window already, make it visible. |
| 115 | (let ((frame (window-frame window))) |
| 116 | (make-frame-visible frame) |
| 117 | (raise-frame frame) |
| 118 | window) |
| 119 | ;; If no window yet, make one in a new frame. |
| 120 | (let ((frame (make-frame (append args special-display-frame-alist)))) |
| 121 | (set-window-buffer (frame-selected-window frame) buffer) |
| 122 | (set-window-dedicated-p (frame-selected-window frame) t) |
| 123 | (frame-selected-window frame)))))) |
| 124 | |
| 125 | (defun handle-delete-frame (event) |
| 126 | "Handle delete-frame events from the X server." |
| 127 | (interactive "e") |
| 128 | (let ((frame (posn-window (event-start event))) |
| 129 | (i 0) |
| 130 | (tail (frame-list))) |
| 131 | (while tail |
| 132 | (and (frame-visible-p (car tail)) |
| 133 | (not (eq (car tail) frame)) |
| 134 | (setq i (1+ i))) |
| 135 | (setq tail (cdr tail))) |
| 136 | (if (> i 0) |
| 137 | (delete-frame frame t) |
| 138 | ;; Gildea@x.org says it is ok to ask questions before terminating. |
| 139 | (save-buffers-kill-emacs)))) |
| 140 | \f |
| 141 | ;;;; Arrangement of frames at startup |
| 142 | |
| 143 | ;;; 1) Load the window system startup file from the lisp library and read the |
| 144 | ;;; high-priority arguments (-q and the like). The window system startup |
| 145 | ;;; file should create any frames specified in the window system defaults. |
| 146 | ;;; |
| 147 | ;;; 2) If no frames have been opened, we open an initial text frame. |
| 148 | ;;; |
| 149 | ;;; 3) Once the init file is done, we apply any newly set parameters |
| 150 | ;;; in initial-frame-alist to the frame. |
| 151 | |
| 152 | ;; These are now called explicitly at the proper times, |
| 153 | ;; since that is easier to understand. |
| 154 | ;; Actually using hooks within Emacs is bad for future maintenance. --rms. |
| 155 | ;; (add-hook 'before-init-hook 'frame-initialize) |
| 156 | ;; (add-hook 'window-setup-hook 'frame-notice-user-settings) |
| 157 | |
| 158 | ;;; If we create the initial frame, this is it. |
| 159 | (defvar frame-initial-frame nil) |
| 160 | |
| 161 | ;; Record the parameters used in frame-initialize to make the initial frame. |
| 162 | (defvar frame-initial-frame-alist) |
| 163 | |
| 164 | (defvar frame-initial-geometry-arguments nil) |
| 165 | |
| 166 | ;;; startup.el calls this function before loading the user's init |
| 167 | ;;; file - if there is no frame with a minibuffer open now, create |
| 168 | ;;; one to display messages while loading the init file. |
| 169 | (defun frame-initialize () |
| 170 | "Create an in initial frame if necessary." |
| 171 | ;; Are we actually running under a window system at all? |
| 172 | (if (and window-system (not noninteractive) (not (eq window-system 'pc))) |
| 173 | (progn |
| 174 | ;; Turn on special-display processing only if there's a window system. |
| 175 | (setq special-display-function 'special-display-popup-frame) |
| 176 | |
| 177 | ;; If there is no frame with a minibuffer besides the terminal |
| 178 | ;; frame, then we need to create the opening frame. Make sure |
| 179 | ;; it has a minibuffer, but let initial-frame-alist omit the |
| 180 | ;; minibuffer spec. |
| 181 | (or (delq terminal-frame (minibuffer-frame-list)) |
| 182 | (progn |
| 183 | (setq frame-initial-frame-alist |
| 184 | (append initial-frame-alist default-frame-alist nil)) |
| 185 | (or (assq 'horizontal-scroll-bars frame-initial-frame-alist) |
| 186 | (setq frame-initial-frame-alist |
| 187 | (cons '(horizontal-scroll-bars . t) |
| 188 | frame-initial-frame-alist))) |
| 189 | (setq default-minibuffer-frame |
| 190 | (setq frame-initial-frame |
| 191 | (make-frame frame-initial-frame-alist))) |
| 192 | ;; Delete any specifications for window geometry parameters |
| 193 | ;; so that we won't reapply them in frame-notice-user-settings. |
| 194 | ;; It would be wrong to reapply them then, |
| 195 | ;; because that would override explicit user resizing. |
| 196 | (setq initial-frame-alist |
| 197 | (frame-remove-geometry-params initial-frame-alist)))) |
| 198 | ;; At this point, we know that we have a frame open, so we |
| 199 | ;; can delete the terminal frame. |
| 200 | (delete-frame terminal-frame) |
| 201 | (setq terminal-frame nil)) |
| 202 | |
| 203 | ;; No, we're not running a window system. Use make-terminal-frame if |
| 204 | ;; we support that feature, otherwise arrange to cause errors. |
| 205 | (or (eq window-system 'pc) |
| 206 | (setq frame-creation-function |
| 207 | (if (fboundp 'tty-create-frame-with-faces) |
| 208 | 'tty-create-frame-with-faces |
| 209 | (function |
| 210 | (lambda (parameters) |
| 211 | (error |
| 212 | "Can't create multiple frames without a window system")))))))) |
| 213 | |
| 214 | (defvar frame-notice-user-settings t |
| 215 | "Non-nil means function `frame-notice-user-settings' wasn't run yet.") |
| 216 | |
| 217 | ;;; startup.el calls this function after loading the user's init |
| 218 | ;;; file. Now default-frame-alist and initial-frame-alist contain |
| 219 | ;;; information to which we must react; do what needs to be done. |
| 220 | (defun frame-notice-user-settings () |
| 221 | "Act on user's init file settings of frame parameters. |
| 222 | React to settings of `default-frame-alist', `initial-frame-alist' there." |
| 223 | ;; Make menu-bar-mode and default-frame-alist consistent. |
| 224 | (when (boundp 'menu-bar-mode) |
| 225 | (let ((default (assq 'menu-bar-lines default-frame-alist))) |
| 226 | (if default |
| 227 | (setq menu-bar-mode (not (eq (cdr default) 0))) |
| 228 | (setq default-frame-alist |
| 229 | (cons (cons 'menu-bar-lines (if menu-bar-mode 1 0)) |
| 230 | default-frame-alist))))) |
| 231 | |
| 232 | ;; Make tool-bar-mode and default-frame-alist consistent. Don't do |
| 233 | ;; it in batch mode since that would leave a tool-bar-lines |
| 234 | ;; parameter in default-frame-alist in a dumped Emacs, which is not |
| 235 | ;; what we want. For some reason, menu-bar-mode is not bound |
| 236 | ;; in this case, but tool-bar-mode is. |
| 237 | (when (and (boundp 'tool-bar-mode) |
| 238 | (not noninteractive)) |
| 239 | (let ((default (assq 'tool-bar-lines default-frame-alist))) |
| 240 | (if default |
| 241 | (setq tool-bar-mode (not (eq (cdr default) 0))) |
| 242 | (setq default-frame-alist |
| 243 | (cons (cons 'tool-bar-lines (if tool-bar-mode 1 0)) |
| 244 | default-frame-alist))))) |
| 245 | |
| 246 | ;; Creating and deleting frames may shift the selected frame around, |
| 247 | ;; and thus the current buffer. Protect against that. We don't |
| 248 | ;; want to use save-excursion here, because that may also try to set |
| 249 | ;; the buffer of the selected window, which fails when the selected |
| 250 | ;; window is the minibuffer. |
| 251 | (let ((old-buffer (current-buffer))) |
| 252 | |
| 253 | (when (and frame-notice-user-settings |
| 254 | (null frame-initial-frame)) |
| 255 | ;; This case happens when we don't have a window system. |
| 256 | (let ((parms (frame-parameters frame-initial-frame))) |
| 257 | ;; Don't change the frame names. |
| 258 | (setq parms (delq (assq 'name parms) parms)) |
| 259 | ;; Can't modify the minibuffer parameter, so don't try. |
| 260 | (setq parms (delq (assq 'minibuffer parms) parms)) |
| 261 | (modify-frame-parameters nil |
| 262 | (append initial-frame-alist |
| 263 | default-frame-alist |
| 264 | parms |
| 265 | nil)))) |
| 266 | |
| 267 | ;; If the initial frame is still around, apply initial-frame-alist |
| 268 | ;; and default-frame-alist to it. |
| 269 | (if (frame-live-p frame-initial-frame) |
| 270 | |
| 271 | ;; The initial frame we create above always has a minibuffer. |
| 272 | ;; If the user wants to remove it, or make it a minibuffer-only |
| 273 | ;; frame, then we'll have to delete the current frame and make a |
| 274 | ;; new one; you can't remove or add a root window to/from an |
| 275 | ;; existing frame. |
| 276 | ;; |
| 277 | ;; NOTE: default-frame-alist was nil when we created the |
| 278 | ;; existing frame. We need to explicitly include |
| 279 | ;; default-frame-alist in the parameters of the screen we |
| 280 | ;; create here, so that its new value, gleaned from the user's |
| 281 | ;; .emacs file, will be applied to the existing screen. |
| 282 | (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist) |
| 283 | (assq 'minibuffer default-frame-alist) |
| 284 | '(minibuffer . t))) |
| 285 | t)) |
| 286 | ;; Create the new frame. |
| 287 | (let (parms new) |
| 288 | ;; If the frame isn't visible yet, wait till it is. |
| 289 | ;; If the user has to position the window, |
| 290 | ;; Emacs doesn't know its real position until |
| 291 | ;; the frame is seen to be visible. |
| 292 | (while (not (cdr (assq 'visibility |
| 293 | (frame-parameters frame-initial-frame)))) |
| 294 | (sleep-for 1)) |
| 295 | (setq parms (frame-parameters frame-initial-frame)) |
| 296 | ;; Get rid of `name' unless it was specified explicitly before. |
| 297 | (or (assq 'name frame-initial-frame-alist) |
| 298 | (setq parms (delq (assq 'name parms) parms))) |
| 299 | (setq parms (append initial-frame-alist |
| 300 | default-frame-alist |
| 301 | parms |
| 302 | nil)) |
| 303 | ;; Get rid of `reverse', because that was handled |
| 304 | ;; when we first made the frame. |
| 305 | (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms))) |
| 306 | (if (assq 'height frame-initial-geometry-arguments) |
| 307 | (setq parms (assq-delete-all 'height parms))) |
| 308 | (if (assq 'width frame-initial-geometry-arguments) |
| 309 | (setq parms (assq-delete-all 'width parms))) |
| 310 | (if (assq 'left frame-initial-geometry-arguments) |
| 311 | (setq parms (assq-delete-all 'left parms))) |
| 312 | (if (assq 'top frame-initial-geometry-arguments) |
| 313 | (setq parms (assq-delete-all 'top parms))) |
| 314 | (setq new |
| 315 | (make-frame |
| 316 | ;; Use the geometry args that created the existing |
| 317 | ;; frame, rather than the parms we get for it. |
| 318 | (append frame-initial-geometry-arguments |
| 319 | '((user-size . t) (user-position . t)) |
| 320 | parms))) |
| 321 | ;; The initial frame, which we are about to delete, may be |
| 322 | ;; the only frame with a minibuffer. If it is, create a |
| 323 | ;; new one. |
| 324 | (or (delq frame-initial-frame (minibuffer-frame-list)) |
| 325 | (make-initial-minibuffer-frame nil)) |
| 326 | |
| 327 | ;; If the initial frame is serving as a surrogate |
| 328 | ;; minibuffer frame for any frames, we need to wean them |
| 329 | ;; onto a new frame. The default-minibuffer-frame |
| 330 | ;; variable must be handled similarly. |
| 331 | (let ((users-of-initial |
| 332 | (filtered-frame-list |
| 333 | (function (lambda (frame) |
| 334 | (and (not (eq frame frame-initial-frame)) |
| 335 | (eq (window-frame |
| 336 | (minibuffer-window frame)) |
| 337 | frame-initial-frame))))))) |
| 338 | (if (or users-of-initial |
| 339 | (eq default-minibuffer-frame frame-initial-frame)) |
| 340 | |
| 341 | ;; Choose an appropriate frame. Prefer frames which |
| 342 | ;; are only minibuffers. |
| 343 | (let* ((new-surrogate |
| 344 | (car |
| 345 | (or (filtered-frame-list |
| 346 | (function |
| 347 | (lambda (frame) |
| 348 | (eq (cdr (assq 'minibuffer |
| 349 | (frame-parameters frame))) |
| 350 | 'only)))) |
| 351 | (minibuffer-frame-list)))) |
| 352 | (new-minibuffer (minibuffer-window new-surrogate))) |
| 353 | |
| 354 | (if (eq default-minibuffer-frame frame-initial-frame) |
| 355 | (setq default-minibuffer-frame new-surrogate)) |
| 356 | |
| 357 | ;; Wean the frames using frame-initial-frame as |
| 358 | ;; their minibuffer frame. |
| 359 | (mapcar |
| 360 | (function |
| 361 | (lambda (frame) |
| 362 | (modify-frame-parameters |
| 363 | frame (list (cons 'minibuffer new-minibuffer))))) |
| 364 | users-of-initial)))) |
| 365 | |
| 366 | ;; Redirect events enqueued at this frame to the new frame. |
| 367 | ;; Is this a good idea? |
| 368 | (redirect-frame-focus frame-initial-frame new) |
| 369 | |
| 370 | ;; Finally, get rid of the old frame. |
| 371 | (delete-frame frame-initial-frame t)) |
| 372 | |
| 373 | ;; Otherwise, we don't need all that rigamarole; just apply |
| 374 | ;; the new parameters. |
| 375 | (let (newparms allparms tail) |
| 376 | (setq allparms (append initial-frame-alist |
| 377 | default-frame-alist nil)) |
| 378 | (if (assq 'height frame-initial-geometry-arguments) |
| 379 | (setq allparms (assq-delete-all 'height allparms))) |
| 380 | (if (assq 'width frame-initial-geometry-arguments) |
| 381 | (setq allparms (assq-delete-all 'width allparms))) |
| 382 | (if (assq 'left frame-initial-geometry-arguments) |
| 383 | (setq allparms (assq-delete-all 'left allparms))) |
| 384 | (if (assq 'top frame-initial-geometry-arguments) |
| 385 | (setq allparms (assq-delete-all 'top allparms))) |
| 386 | (setq tail allparms) |
| 387 | ;; Find just the parms that have changed since we first |
| 388 | ;; made this frame. Those are the ones actually set by |
| 389 | ;; the init file. For those parms whose values we already knew |
| 390 | ;; (such as those spec'd by command line options) |
| 391 | ;; it is undesirable to specify the parm again |
| 392 | ;; once the user has seen the frame and been able to alter it |
| 393 | ;; manually. |
| 394 | (while tail |
| 395 | (let (newval oldval) |
| 396 | (setq oldval (assq (car (car tail)) |
| 397 | frame-initial-frame-alist)) |
| 398 | (setq newval (cdr (assq (car (car tail)) allparms))) |
| 399 | (or (and oldval (eq (cdr oldval) newval)) |
| 400 | (setq newparms |
| 401 | (cons (cons (car (car tail)) newval) newparms)))) |
| 402 | (setq tail (cdr tail))) |
| 403 | (setq newparms (nreverse newparms)) |
| 404 | (modify-frame-parameters frame-initial-frame |
| 405 | newparms) |
| 406 | ;; If we changed the background color, |
| 407 | ;; we need to update the background-mode parameter |
| 408 | ;; and maybe some faces too. |
| 409 | (when (assq 'background-color newparms) |
| 410 | (unless (assq 'background-mode newparms) |
| 411 | (frame-set-background-mode frame-initial-frame)) |
| 412 | (face-set-after-frame-default frame-initial-frame))))) |
| 413 | |
| 414 | ;; Restore the original buffer. |
| 415 | (set-buffer old-buffer) |
| 416 | |
| 417 | ;; Make sure the initial frame can be GC'd if it is ever deleted. |
| 418 | ;; Make sure frame-notice-user-settings does nothing if called twice. |
| 419 | (setq frame-notice-user-settings nil) |
| 420 | (setq frame-initial-frame nil))) |
| 421 | |
| 422 | (defun make-initial-minibuffer-frame (display) |
| 423 | (let ((parms (append minibuffer-frame-alist '((minibuffer . only))))) |
| 424 | (if display |
| 425 | (make-frame-on-display display parms) |
| 426 | (make-frame parms)))) |
| 427 | |
| 428 | ;;;; Creation of additional frames, and other frame miscellanea |
| 429 | |
| 430 | (defun get-other-frame () |
| 431 | "Return some frame other than the current frame. |
| 432 | Create one if necessary. Note that the minibuffer frame, if separate, |
| 433 | is not considered (see `next-frame')." |
| 434 | (let ((s (if (equal (next-frame (selected-frame)) (selected-frame)) |
| 435 | (make-frame) |
| 436 | (next-frame (selected-frame))))) |
| 437 | s)) |
| 438 | |
| 439 | (defun next-multiframe-window () |
| 440 | "Select the next window, regardless of which frame it is on." |
| 441 | (interactive) |
| 442 | (select-window (next-window (selected-window) |
| 443 | (> (minibuffer-depth) 0) |
| 444 | t))) |
| 445 | |
| 446 | (defun previous-multiframe-window () |
| 447 | "Select the previous window, regardless of which frame it is on." |
| 448 | (interactive) |
| 449 | (select-window (previous-window (selected-window) |
| 450 | (> (minibuffer-depth) 0) |
| 451 | t))) |
| 452 | |
| 453 | (defun make-frame-on-display (display &optional parameters) |
| 454 | "Make a frame on display DISPLAY. |
| 455 | The optional second argument PARAMETERS specifies additional frame parameters." |
| 456 | (interactive "sMake frame on display: ") |
| 457 | (or (string-match "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display) |
| 458 | (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN")) |
| 459 | (make-frame (cons (cons 'display display) parameters))) |
| 460 | |
| 461 | (defun make-frame-command () |
| 462 | "Make a new frame, and select it if the terminal displays only one frame." |
| 463 | (interactive) |
| 464 | (if (and window-system (not (eq window-system 'pc))) |
| 465 | (make-frame) |
| 466 | (select-frame (make-frame)))) |
| 467 | |
| 468 | (defvar before-make-frame-hook nil |
| 469 | "Functions to run before a frame is created.") |
| 470 | |
| 471 | (defvar after-make-frame-functions nil |
| 472 | "Functions to run after a frame is created. |
| 473 | The functions are run with one arg, the newly created frame.") |
| 474 | |
| 475 | (defvar after-setting-font-hooks nil |
| 476 | "Functions to run after a frame's font has been changed.") |
| 477 | |
| 478 | ;; Alias, kept temporarily. |
| 479 | (defalias 'new-frame 'make-frame) |
| 480 | |
| 481 | (defun make-frame (&optional parameters) |
| 482 | "Return a newly created frame displaying the current buffer. |
| 483 | Optional argument PARAMETERS is an alist of parameters for the new frame. |
| 484 | Each element of PARAMETERS should have the form (NAME . VALUE), for example: |
| 485 | |
| 486 | (name . STRING) The frame should be named STRING. |
| 487 | |
| 488 | (width . NUMBER) The frame should be NUMBER characters in width. |
| 489 | (height . NUMBER) The frame should be NUMBER text lines high. |
| 490 | |
| 491 | You cannot specify either `width' or `height', you must use neither or both. |
| 492 | |
| 493 | (minibuffer . t) The frame should have a minibuffer. |
| 494 | (minibuffer . nil) The frame should have no minibuffer. |
| 495 | (minibuffer . only) The frame should contain only a minibuffer. |
| 496 | (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window. |
| 497 | |
| 498 | Before the frame is created (via `frame-creation-function'), functions on the |
| 499 | hook `before-make-frame-hook' are run. After the frame is created, functions |
| 500 | on `after-make-frame-functions' are run with one arg, the newly created frame." |
| 501 | (interactive) |
| 502 | (run-hooks 'before-make-frame-hook) |
| 503 | (let ((frame (funcall frame-creation-function parameters))) |
| 504 | (run-hook-with-args 'after-make-frame-functions frame) |
| 505 | frame)) |
| 506 | |
| 507 | (defun filtered-frame-list (predicate) |
| 508 | "Return a list of all live frames which satisfy PREDICATE." |
| 509 | (let* ((frames (frame-list)) |
| 510 | (list frames)) |
| 511 | (while (consp frames) |
| 512 | (unless (funcall predicate (car frames)) |
| 513 | (setcar frames nil)) |
| 514 | (setq frames (cdr frames))) |
| 515 | (delq nil list))) |
| 516 | |
| 517 | (defun minibuffer-frame-list () |
| 518 | "Return a list of all frames with their own minibuffers." |
| 519 | (filtered-frame-list |
| 520 | (function (lambda (frame) |
| 521 | (eq frame (window-frame (minibuffer-window frame))))))) |
| 522 | |
| 523 | (defun frames-on-display-list (&optional display) |
| 524 | "Return a list of all frames on DISPLAY. |
| 525 | DISPLAY is a name of a display, a string of the form HOST:SERVER.SCREEN. |
| 526 | If DISPLAY is omitted or nil, it defaults to the selected frame's display." |
| 527 | (let* ((display (or display (frame-parameter nil 'display))) |
| 528 | (func #'(lambda (frame) |
| 529 | (eq (frame-parameter frame 'display) display)))) |
| 530 | (filtered-frame-list func))) |
| 531 | |
| 532 | (defun framep-on-display (&optional display) |
| 533 | "Return the type of frames on DISPLAY. |
| 534 | DISPLAY may be a display name or a frame. If it is a frame, its type is |
| 535 | returned. |
| 536 | If DISPLAY is omitted or nil, it defaults to the selected frame's display. |
| 537 | All frames on a given display are of the same type." |
| 538 | (or (framep display) |
| 539 | (framep (car (frames-on-display-list display))))) |
| 540 | |
| 541 | (defun frame-remove-geometry-params (param-list) |
| 542 | "Return the parameter list PARAM-LIST, but with geometry specs removed. |
| 543 | This deletes all bindings in PARAM-LIST for `top', `left', `width', |
| 544 | `height', `user-size' and `user-position' parameters. |
| 545 | Emacs uses this to avoid overriding explicit moves and resizings from |
| 546 | the user during startup." |
| 547 | (setq param-list (cons nil param-list)) |
| 548 | (let ((tail param-list)) |
| 549 | (while (consp (cdr tail)) |
| 550 | (if (and (consp (car (cdr tail))) |
| 551 | (memq (car (car (cdr tail))) |
| 552 | '(height width top left user-position user-size))) |
| 553 | (progn |
| 554 | (setq frame-initial-geometry-arguments |
| 555 | (cons (car (cdr tail)) frame-initial-geometry-arguments)) |
| 556 | (setcdr tail (cdr (cdr tail)))) |
| 557 | (setq tail (cdr tail))))) |
| 558 | (setq frame-initial-geometry-arguments |
| 559 | (nreverse frame-initial-geometry-arguments)) |
| 560 | (cdr param-list)) |
| 561 | |
| 562 | |
| 563 | (defcustom focus-follows-mouse t |
| 564 | "*Non-nil if window system changes focus when you move the mouse." |
| 565 | :type 'boolean |
| 566 | :group 'frames |
| 567 | :version "20.3") |
| 568 | |
| 569 | (defun other-frame (arg) |
| 570 | "Select the ARG'th different visible frame, and raise it. |
| 571 | All frames are arranged in a cyclic order. |
| 572 | This command selects the frame ARG steps away in that order. |
| 573 | A negative ARG moves in the opposite order." |
| 574 | (interactive "p") |
| 575 | (let ((frame (selected-frame))) |
| 576 | (while (> arg 0) |
| 577 | (setq frame (next-frame frame)) |
| 578 | (while (not (eq (frame-visible-p frame) t)) |
| 579 | (setq frame (next-frame frame))) |
| 580 | (setq arg (1- arg))) |
| 581 | (while (< arg 0) |
| 582 | (setq frame (previous-frame frame)) |
| 583 | (while (not (eq (frame-visible-p frame) t)) |
| 584 | (setq frame (previous-frame frame))) |
| 585 | (setq arg (1+ arg))) |
| 586 | (select-frame frame) |
| 587 | (raise-frame frame) |
| 588 | ;; Ensure, if possible, that frame gets input focus. |
| 589 | (when (eq window-system 'w32) |
| 590 | (w32-focus-frame frame)) |
| 591 | (cond (focus-follows-mouse |
| 592 | (unless (eq window-system 'w32) |
| 593 | (set-mouse-position (selected-frame) (1- (frame-width)) 0))) |
| 594 | (t |
| 595 | (when (eq window-system 'x) |
| 596 | (x-focus-frame frame)))))) |
| 597 | |
| 598 | (defun make-frame-names-alist () |
| 599 | (let* ((current-frame (selected-frame)) |
| 600 | (falist |
| 601 | (cons |
| 602 | (cons (frame-parameter current-frame 'name) current-frame) nil)) |
| 603 | (frame (next-frame nil t))) |
| 604 | (while (not (eq frame current-frame)) |
| 605 | (progn |
| 606 | (setq falist (cons (cons (frame-parameter frame 'name) frame) falist)) |
| 607 | (setq frame (next-frame frame t)))) |
| 608 | falist)) |
| 609 | |
| 610 | (defvar frame-name-history nil) |
| 611 | (defun select-frame-by-name (name) |
| 612 | "Select the frame whose name is NAME and raise it. |
| 613 | If there is no frame by that name, signal an error." |
| 614 | (interactive |
| 615 | (let* ((frame-names-alist (make-frame-names-alist)) |
| 616 | (default (car (car frame-names-alist))) |
| 617 | (input (completing-read |
| 618 | (format "Select Frame (default %s): " default) |
| 619 | frame-names-alist nil t nil 'frame-name-history))) |
| 620 | (if (= (length input) 0) |
| 621 | (list default) |
| 622 | (list input)))) |
| 623 | (let* ((frame-names-alist (make-frame-names-alist)) |
| 624 | (frame (cdr (assoc name frame-names-alist)))) |
| 625 | (or frame |
| 626 | (error "There is no frame named `%s'" name)) |
| 627 | (make-frame-visible frame) |
| 628 | (raise-frame frame) |
| 629 | (select-frame frame) |
| 630 | ;; Ensure, if possible, that frame gets input focus. |
| 631 | (if (eq window-system 'w32) |
| 632 | (w32-focus-frame frame) |
| 633 | (when focus-follows-mouse |
| 634 | (set-mouse-position (selected-frame) (1- (frame-width)) 0))))) |
| 635 | \f |
| 636 | ;;;; Frame configurations |
| 637 | |
| 638 | (defun current-frame-configuration () |
| 639 | "Return a list describing the positions and states of all frames. |
| 640 | Its car is `frame-configuration'. |
| 641 | Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG), |
| 642 | where |
| 643 | FRAME is a frame object, |
| 644 | ALIST is an association list specifying some of FRAME's parameters, and |
| 645 | WINDOW-CONFIG is a window configuration object for FRAME." |
| 646 | (cons 'frame-configuration |
| 647 | (mapcar (function |
| 648 | (lambda (frame) |
| 649 | (list frame |
| 650 | (frame-parameters frame) |
| 651 | (current-window-configuration frame)))) |
| 652 | (frame-list)))) |
| 653 | |
| 654 | (defun set-frame-configuration (configuration &optional nodelete) |
| 655 | "Restore the frames to the state described by CONFIGURATION. |
| 656 | Each frame listed in CONFIGURATION has its position, size, window |
| 657 | configuration, and other parameters set as specified in CONFIGURATION. |
| 658 | Ordinarily, this function deletes all existing frames not |
| 659 | listed in CONFIGURATION. But if optional second argument NODELETE |
| 660 | is given and non-nil, the unwanted frames are iconified instead." |
| 661 | (or (frame-configuration-p configuration) |
| 662 | (signal 'wrong-type-argument |
| 663 | (list 'frame-configuration-p configuration))) |
| 664 | (let ((config-alist (cdr configuration)) |
| 665 | frames-to-delete) |
| 666 | (mapcar (function |
| 667 | (lambda (frame) |
| 668 | (let ((parameters (assq frame config-alist))) |
| 669 | (if parameters |
| 670 | (progn |
| 671 | (modify-frame-parameters |
| 672 | frame |
| 673 | ;; Since we can't set a frame's minibuffer status, |
| 674 | ;; we might as well omit the parameter altogether. |
| 675 | (let* ((parms (nth 1 parameters)) |
| 676 | (mini (assq 'minibuffer parms))) |
| 677 | (if mini (setq parms (delq mini parms))) |
| 678 | parms)) |
| 679 | (set-window-configuration (nth 2 parameters))) |
| 680 | (setq frames-to-delete (cons frame frames-to-delete)))))) |
| 681 | (frame-list)) |
| 682 | (if nodelete |
| 683 | ;; Note: making frames invisible here was tried |
| 684 | ;; but led to some strange behavior--each time the frame |
| 685 | ;; was made visible again, the window manager asked afresh |
| 686 | ;; for where to put it. |
| 687 | (mapcar 'iconify-frame frames-to-delete) |
| 688 | (mapcar 'delete-frame frames-to-delete)))) |
| 689 | \f |
| 690 | ;;;; Convenience functions for accessing and interactively changing |
| 691 | ;;;; frame parameters. |
| 692 | |
| 693 | (defun frame-height (&optional frame) |
| 694 | "Return number of lines available for display on FRAME. |
| 695 | If FRAME is omitted, describe the currently selected frame." |
| 696 | (cdr (assq 'height (frame-parameters frame)))) |
| 697 | |
| 698 | (defun frame-width (&optional frame) |
| 699 | "Return number of columns available for display on FRAME. |
| 700 | If FRAME is omitted, describe the currently selected frame." |
| 701 | (cdr (assq 'width (frame-parameters frame)))) |
| 702 | |
| 703 | (defalias 'set-default-font 'set-frame-font) |
| 704 | (defun set-frame-font (font-name) |
| 705 | "Set the font of the selected frame to FONT-NAME. |
| 706 | When called interactively, prompt for the name of the font to use. |
| 707 | To get the frame's current default font, use `frame-parameters'." |
| 708 | (interactive |
| 709 | (list |
| 710 | (let ((completion-ignore-case t)) |
| 711 | (completing-read "Font name: " |
| 712 | (mapcar #'list |
| 713 | ;; x-list-fonts will fail with an error |
| 714 | ;; if this frame doesn't support fonts. |
| 715 | (x-list-fonts "*" nil (selected-frame))))))) |
| 716 | (modify-frame-parameters (selected-frame) |
| 717 | (list (cons 'font font-name))) |
| 718 | (run-hooks 'after-setting-font-hooks)) |
| 719 | |
| 720 | (defun set-background-color (color-name) |
| 721 | "Set the background color of the selected frame to COLOR-NAME. |
| 722 | When called interactively, prompt for the name of the color to use. |
| 723 | To get the frame's current background color, use `frame-parameters'." |
| 724 | (interactive (list (facemenu-read-color))) |
| 725 | (modify-frame-parameters (selected-frame) |
| 726 | (list (cons 'background-color color-name)))) |
| 727 | |
| 728 | (defun set-foreground-color (color-name) |
| 729 | "Set the foreground color of the selected frame to COLOR-NAME. |
| 730 | When called interactively, prompt for the name of the color to use. |
| 731 | To get the frame's current foreground color, use `frame-parameters'." |
| 732 | (interactive (list (facemenu-read-color))) |
| 733 | (modify-frame-parameters (selected-frame) |
| 734 | (list (cons 'foreground-color color-name)))) |
| 735 | |
| 736 | (defun set-cursor-color (color-name) |
| 737 | "Set the text cursor color of the selected frame to COLOR-NAME. |
| 738 | When called interactively, prompt for the name of the color to use. |
| 739 | To get the frame's current cursor color, use `frame-parameters'." |
| 740 | (interactive (list (facemenu-read-color))) |
| 741 | (modify-frame-parameters (selected-frame) |
| 742 | (list (cons 'cursor-color color-name)))) |
| 743 | |
| 744 | (defun set-mouse-color (color-name) |
| 745 | "Set the color of the mouse pointer of the selected frame to COLOR-NAME. |
| 746 | When called interactively, prompt for the name of the color to use. |
| 747 | To get the frame's current mouse color, use `frame-parameters'." |
| 748 | (interactive (list (facemenu-read-color))) |
| 749 | (modify-frame-parameters (selected-frame) |
| 750 | (list (cons 'mouse-color |
| 751 | (or color-name |
| 752 | (cdr (assq 'mouse-color |
| 753 | (frame-parameters)))))))) |
| 754 | |
| 755 | (defun set-border-color (color-name) |
| 756 | "Set the color of the border of the selected frame to COLOR-NAME. |
| 757 | When called interactively, prompt for the name of the color to use. |
| 758 | To get the frame's current border color, use `frame-parameters'." |
| 759 | (interactive (list (facemenu-read-color))) |
| 760 | (modify-frame-parameters (selected-frame) |
| 761 | (list (cons 'border-color color-name)))) |
| 762 | |
| 763 | (defun auto-raise-mode (arg) |
| 764 | "Toggle whether or not the selected frame should auto-raise. |
| 765 | With arg, turn auto-raise mode on if and only if arg is positive. |
| 766 | Note that this controls Emacs's own auto-raise feature. |
| 767 | Some window managers allow you to enable auto-raise for certain windows. |
| 768 | You can use that for Emacs windows if you wish, but if you do, |
| 769 | that is beyond the control of Emacs and this command has no effect on it." |
| 770 | (interactive "P") |
| 771 | (if (null arg) |
| 772 | (setq arg |
| 773 | (if (cdr (assq 'auto-raise (frame-parameters (selected-frame)))) |
| 774 | -1 1))) |
| 775 | (if (> arg 0) |
| 776 | (raise-frame (selected-frame))) |
| 777 | (modify-frame-parameters (selected-frame) |
| 778 | (list (cons 'auto-raise (> arg 0))))) |
| 779 | |
| 780 | (defun auto-lower-mode (arg) |
| 781 | "Toggle whether or not the selected frame should auto-lower. |
| 782 | With arg, turn auto-lower mode on if and only if arg is positive. |
| 783 | Note that this controls Emacs's own auto-lower feature. |
| 784 | Some window managers allow you to enable auto-lower for certain windows. |
| 785 | You can use that for Emacs windows if you wish, but if you do, |
| 786 | that is beyond the control of Emacs and this command has no effect on it." |
| 787 | (interactive "P") |
| 788 | (if (null arg) |
| 789 | (setq arg |
| 790 | (if (cdr (assq 'auto-lower (frame-parameters (selected-frame)))) |
| 791 | -1 1))) |
| 792 | (modify-frame-parameters (selected-frame) |
| 793 | (list (cons 'auto-lower (> arg 0))))) |
| 794 | (defun set-frame-name (name) |
| 795 | "Set the name of the selected frame to NAME. |
| 796 | When called interactively, prompt for the name of the frame. |
| 797 | The frame name is displayed on the modeline if the terminal displays only |
| 798 | one frame, otherwise the name is displayed on the frame's caption bar." |
| 799 | (interactive "sFrame name: ") |
| 800 | (modify-frame-parameters (selected-frame) |
| 801 | (list (cons 'name name)))) |
| 802 | \f |
| 803 | ;;;; Frame/display capabilities. |
| 804 | (defun display-mouse-p (&optional display) |
| 805 | "Return non-nil if DISPLAY has a mouse available. |
| 806 | DISPLAY can be a display name, a frame, or nil (meaning the selected |
| 807 | frame's display)." |
| 808 | (let ((frame-type (framep-on-display display))) |
| 809 | (cond |
| 810 | ((eq frame-type 'pc) |
| 811 | (msdos-mouse-p)) |
| 812 | ((eq system-type 'windows-nt) |
| 813 | (> w32-num-mouse-buttons 0)) |
| 814 | ((memq frame-type '(x mac)) |
| 815 | t) ;; We assume X and Mac *always* have a pointing device |
| 816 | (t |
| 817 | (or (and (featurep 'xt-mouse) |
| 818 | xterm-mouse-mode) |
| 819 | ;; t-mouse is distributed with the GPM package. It doesn't have |
| 820 | ;; a toggle. |
| 821 | (featurep 't-mouse)))))) |
| 822 | |
| 823 | (defun display-popup-menus-p (&optional display) |
| 824 | "Return non-nil if popup menus are supported on DISPLAY. |
| 825 | DISPLAY can be a display name, a frame, or nil (meaning the selected |
| 826 | frame's display). |
| 827 | Support for popup menus requires that the mouse be available." |
| 828 | (and |
| 829 | (let ((frame-type (framep-on-display display))) |
| 830 | (memq frame-type '(x w32 pc mac))) |
| 831 | (display-mouse-p display))) |
| 832 | |
| 833 | (defun display-graphic-p (&optional display) |
| 834 | "Return non-nil if DISPLAY is a graphic display. |
| 835 | Graphical displays are those which are capable of displaying several |
| 836 | frames and several different fonts at once. This is true for displays |
| 837 | that use a window system such as X, and false for text-only terminals. |
| 838 | DISPLAY can be a display name, a frame, or nil (meaning the selected |
| 839 | frame's display)." |
| 840 | (not (null (memq (framep-on-display display) '(x w32 mac))))) |
| 841 | |
| 842 | (defalias 'display-multi-frame-p 'display-graphic-p) |
| 843 | (defalias 'display-multi-font-p 'display-graphic-p) |
| 844 | |
| 845 | (defun display-selections-p (&optional display) |
| 846 | "Return non-nil if DISPLAY supports selections. |
| 847 | A selection is a way to transfer text or other data between programs |
| 848 | via special system buffers called `selection' or `cut buffer' or |
| 849 | `clipboard'. |
| 850 | DISPLAY can be a display name, a frame, or nil (meaning the selected |
| 851 | frame's display)." |
| 852 | (let ((frame-type (framep-on-display display))) |
| 853 | (cond |
| 854 | ((eq frame-type 'pc) |
| 855 | ;; MS-DOG frames support selections when Emacs runs inside |
| 856 | ;; the Windows' DOS Box. |
| 857 | (not (null dos-windows-version))) |
| 858 | ((memq frame-type '(x w32 mac)) |
| 859 | t) ;; FIXME? |
| 860 | (t |
| 861 | nil)))) |
| 862 | |
| 863 | (defun display-screens (&optional display) |
| 864 | "Return the number of screens associated with DISPLAY." |
| 865 | (let ((frame-type (framep-on-display display))) |
| 866 | (cond |
| 867 | ((memq frame-type '(x w32)) |
| 868 | (x-display-screens display)) |
| 869 | (t ;; FIXME: is this correct for the Mac? |
| 870 | 1)))) |
| 871 | |
| 872 | (defun display-pixel-height (&optional display) |
| 873 | "Return the height of DISPLAY's screen in pixels. |
| 874 | For character terminals, each character counts as a single pixel." |
| 875 | (let ((frame-type (framep-on-display display))) |
| 876 | (cond |
| 877 | ((memq frame-type '(x w32 mac)) |
| 878 | (x-display-pixel-height display)) |
| 879 | (t |
| 880 | (frame-height (if (framep display) display (selected-frame))))))) |
| 881 | |
| 882 | (defun display-pixel-width (&optional display) |
| 883 | "Return the width of DISPLAY's screen in pixels. |
| 884 | For character terminals, each character counts as a single pixel." |
| 885 | (let ((frame-type (framep-on-display display))) |
| 886 | (cond |
| 887 | ((memq frame-type '(x w32 mac)) |
| 888 | (x-display-pixel-width display)) |
| 889 | (t |
| 890 | (frame-width (if (framep display) display (selected-frame))))))) |
| 891 | |
| 892 | (defun display-mm-height (&optional display) |
| 893 | "Return the height of DISPLAY's screen in millimeters. |
| 894 | If the information is unavailable, value is nil." |
| 895 | (and (memq (framep-on-display display) '(x w32 mac)) |
| 896 | (x-display-mm-height display))) |
| 897 | |
| 898 | (defun display-mm-width (&optional display) |
| 899 | "Return the width of DISPLAY's screen in millimeters. |
| 900 | If the information is unavailable, value is nil." |
| 901 | (and (memq (framep-on-display display) '(x w32 mac)) |
| 902 | (x-display-mm-width display))) |
| 903 | |
| 904 | (defun display-backing-store (&optional display) |
| 905 | "Return the backing store capability of DISPLAY's screen. |
| 906 | The value may be `always', `when-mapped', `not-useful', or nil if |
| 907 | the question is inapplicable to a certain kind of display." |
| 908 | (let ((frame-type (framep-on-display display))) |
| 909 | (cond |
| 910 | ((memq frame-type '(x w32 mac)) |
| 911 | (x-display-backing-store display)) |
| 912 | (t |
| 913 | 'not-useful)))) |
| 914 | |
| 915 | (defun display-save-under (&optional display) |
| 916 | "Return non-nil if DISPLAY's screen supports the SaveUnder feature." |
| 917 | (let ((frame-type (framep-on-display display))) |
| 918 | (cond |
| 919 | ((memq frame-type '(x w32 mac)) |
| 920 | (x-display-save-under display)) |
| 921 | (t |
| 922 | 'not-useful)))) |
| 923 | |
| 924 | (defun display-planes (&optional display) |
| 925 | "Return the number of planes supported by DISPLAY." |
| 926 | (let ((frame-type (framep-on-display display))) |
| 927 | (cond |
| 928 | ((memq frame-type '(x w32 mac)) |
| 929 | (x-display-planes display)) |
| 930 | ((eq frame-type 'pc) |
| 931 | 4) |
| 932 | (t |
| 933 | (truncate (log (length (tty-color-alist)) 2)))))) |
| 934 | |
| 935 | (defun display-color-cells (&optional display) |
| 936 | "Return the number of color cells supported by DISPLAY." |
| 937 | (let ((frame-type (framep-on-display display))) |
| 938 | (cond |
| 939 | ((memq frame-type '(x w32 mac)) |
| 940 | (x-display-color-cells display)) |
| 941 | ((eq frame-type 'pc) |
| 942 | 16) |
| 943 | (t |
| 944 | (length (tty-color-alist)))))) |
| 945 | |
| 946 | (defun display-visual-class (&optional display) |
| 947 | "Returns the visual class of DISPLAY. |
| 948 | The value is one of the symbols `static-gray', `gray-scale', |
| 949 | `static-color', `pseudo-color', `true-color', or `direct-color'." |
| 950 | (let ((frame-type (framep-on-display display))) |
| 951 | (cond |
| 952 | ((memq frame-type '(x w32 mac)) |
| 953 | (x-display-visual-class display)) |
| 954 | ((and (memq frame-type '(pc t)) |
| 955 | (tty-display-color-p display)) |
| 956 | 'static-color) |
| 957 | (t |
| 958 | 'static-gray)))) |
| 959 | |
| 960 | \f |
| 961 | ;;;; Aliases for backward compatibility with Emacs 18. |
| 962 | (defalias 'screen-height 'frame-height) |
| 963 | (defalias 'screen-width 'frame-width) |
| 964 | |
| 965 | (defun set-screen-width (cols &optional pretend) |
| 966 | "Obsolete function to change the size of the screen to COLS columns. |
| 967 | Optional second arg non-nil means that redisplay should use COLS columns |
| 968 | but that the idea of the actual width of the frame should not be changed. |
| 969 | This function is provided only for compatibility with Emacs 18; new code |
| 970 | should use `set-frame-width instead'." |
| 971 | (set-frame-width (selected-frame) cols pretend)) |
| 972 | |
| 973 | (defun set-screen-height (lines &optional pretend) |
| 974 | "Obsolete function to change the height of the screen to LINES lines. |
| 975 | Optional second arg non-nil means that redisplay should use LINES lines |
| 976 | but that the idea of the actual height of the screen should not be changed. |
| 977 | This function is provided only for compatibility with Emacs 18; new code |
| 978 | should use `set-frame-height' instead." |
| 979 | (set-frame-height (selected-frame) lines pretend)) |
| 980 | |
| 981 | (defun delete-other-frames (&optional frame) |
| 982 | "Delete all frames except FRAME. |
| 983 | FRAME nil or omitted means delete all frames except the selected frame." |
| 984 | (interactive) |
| 985 | (unless frame |
| 986 | (setq frame (selected-frame))) |
| 987 | (mapcar 'delete-frame (delq frame (frame-list)))) |
| 988 | |
| 989 | |
| 990 | (make-obsolete 'screen-height 'frame-height) ;before 19.15 |
| 991 | (make-obsolete 'screen-width 'frame-width) ;before 19.15 |
| 992 | (make-obsolete 'set-screen-width 'set-frame-width) ;before 19.15 |
| 993 | (make-obsolete 'set-screen-height 'set-frame-height) ;before 19.15 |
| 994 | |
| 995 | \f |
| 996 | ;;; Highlighting trailing whitespace. |
| 997 | |
| 998 | (make-variable-buffer-local 'show-trailing-whitespace) |
| 999 | |
| 1000 | (defcustom show-trailing-whitespace nil |
| 1001 | "*Non-nil means highlight trailing whitespace in face `trailing-whitespace'." |
| 1002 | :tag "Highlight trailing whitespace." |
| 1003 | :set #'(lambda (symbol value) (set-default symbol value)) |
| 1004 | :type 'boolean |
| 1005 | :group 'font-lock) |
| 1006 | |
| 1007 | |
| 1008 | \f |
| 1009 | ;;; Scrolling |
| 1010 | |
| 1011 | (defgroup scrolling nil |
| 1012 | "Scrolling windows." |
| 1013 | :version "21.1" |
| 1014 | :group 'frames) |
| 1015 | |
| 1016 | (defcustom automatic-hscrolling t |
| 1017 | "*Allow or disallow autmatic scrolling windows horizontally. |
| 1018 | If non-nil, windows are automatically scrolled horizontally to make |
| 1019 | point visible." |
| 1020 | :version "21.1" |
| 1021 | :type 'boolean |
| 1022 | :group 'scrolling) |
| 1023 | |
| 1024 | \f |
| 1025 | ;;; Blinking cursor |
| 1026 | |
| 1027 | (defgroup cursor nil |
| 1028 | "Displaying text cursors." |
| 1029 | :version "21.1" |
| 1030 | :group 'frames) |
| 1031 | |
| 1032 | (defcustom blink-cursor-delay 0.5 |
| 1033 | "*Seconds of idle time after which cursor starts to blink." |
| 1034 | :tag "Delay in seconds." |
| 1035 | :type 'number |
| 1036 | :group 'cursor) |
| 1037 | |
| 1038 | (defcustom blink-cursor-interval 0.5 |
| 1039 | "*Length of cursor blink interval in seconds." |
| 1040 | :tag "Blink interval in seconds." |
| 1041 | :type 'number |
| 1042 | :group 'cursor) |
| 1043 | |
| 1044 | (defvar blink-cursor-idle-timer nil |
| 1045 | "Timer started after `blink-cursor-delay' seconds of Emacs idle time. |
| 1046 | The function `blink-cursor-start' is called when the timer fires.") |
| 1047 | |
| 1048 | (defvar blink-cursor-timer nil |
| 1049 | "Timer started from `blink-cursor-start'. |
| 1050 | This timer calls `blink-cursor' every `blink-cursor-interval' seconds.") |
| 1051 | |
| 1052 | (defvar blink-cursor-mode nil |
| 1053 | "Non-nil means blinking cursor is active.") |
| 1054 | |
| 1055 | (defun blink-cursor-mode (arg) |
| 1056 | "Toggle blinking cursor mode. |
| 1057 | With arg, turn blinking cursor mode on iff arg is positive. |
| 1058 | When blinking cursor mode is enabled, the cursor of the selected |
| 1059 | window blinks." |
| 1060 | (interactive "P") |
| 1061 | (let ((on-p (if (null arg) |
| 1062 | (not blink-cursor-mode) |
| 1063 | (> (prefix-numeric-value arg) 0)))) |
| 1064 | (if blink-cursor-idle-timer |
| 1065 | (cancel-timer blink-cursor-idle-timer)) |
| 1066 | (if blink-cursor-timer |
| 1067 | (cancel-timer blink-cursor-timer)) |
| 1068 | (setq blink-cursor-idle-timer nil |
| 1069 | blink-cursor-timer nil |
| 1070 | blink-cursor-mode nil) |
| 1071 | (if on-p |
| 1072 | (progn |
| 1073 | ;; Hide the cursor. |
| 1074 | ;(internal-show-cursor nil nil) |
| 1075 | (setq blink-cursor-idle-timer |
| 1076 | (run-with-idle-timer blink-cursor-delay |
| 1077 | blink-cursor-delay |
| 1078 | 'blink-cursor-start)) |
| 1079 | (setq blink-cursor-mode t)) |
| 1080 | (internal-show-cursor nil t)))) |
| 1081 | |
| 1082 | ;; Note that this is really initialized from startup.el before |
| 1083 | ;; the init-file is read. |
| 1084 | |
| 1085 | (defcustom blink-cursor nil |
| 1086 | "*Non-nil means blinking cursor mode is active." |
| 1087 | :group 'cursor |
| 1088 | :tag "Blinking cursor" |
| 1089 | :type 'boolean |
| 1090 | :set #'(lambda (symbol value) |
| 1091 | (set-default symbol value) |
| 1092 | (blink-cursor-mode (or value 0)))) |
| 1093 | |
| 1094 | (defun blink-cursor-start () |
| 1095 | "Timer function called from the timer `blink-cursor-idle-timer'. |
| 1096 | This starts the timer `blink-cursor-timer', which makes the cursor blink |
| 1097 | if appropriate. It also arranges to cancel that timer when the next |
| 1098 | command starts, by installing a pre-command hook." |
| 1099 | (when (null blink-cursor-timer) |
| 1100 | (add-hook 'pre-command-hook 'blink-cursor-end) |
| 1101 | (setq blink-cursor-timer |
| 1102 | (run-with-timer blink-cursor-interval blink-cursor-interval |
| 1103 | 'blink-cursor-timer-function)))) |
| 1104 | |
| 1105 | (defun blink-cursor-timer-function () |
| 1106 | "Timer function of timer `blink-cursor-timer'." |
| 1107 | (internal-show-cursor nil (not (internal-show-cursor-p)))) |
| 1108 | |
| 1109 | (defun blink-cursor-end () |
| 1110 | "Stop cursor blinking. |
| 1111 | This is installed as a pre-command hook by `blink-cursor-start'. |
| 1112 | When run, it cancels the timer `blink-cursor-timer' and removes |
| 1113 | itself as a pre-command hook." |
| 1114 | (remove-hook 'pre-command-hook 'blink-cursor-end) |
| 1115 | (internal-show-cursor nil t) |
| 1116 | (cancel-timer blink-cursor-timer) |
| 1117 | (setq blink-cursor-timer nil)) |
| 1118 | |
| 1119 | |
| 1120 | \f |
| 1121 | ;;; Busy-cursor. |
| 1122 | |
| 1123 | (defcustom busy-cursor t |
| 1124 | "*Non-nil means show a busy-cursor when running under a window system." |
| 1125 | :tag "Busy-cursor" |
| 1126 | :type 'boolean |
| 1127 | :group 'cursor |
| 1128 | :get #'(lambda (symbol) display-busy-cursor) |
| 1129 | :set #'(lambda (symbol value) |
| 1130 | (set-default symbol value) |
| 1131 | (setq display-busy-cursor value))) |
| 1132 | |
| 1133 | (defcustom busy-cursor-delay-seconds 1 |
| 1134 | "*Seconds to wait before displaying a busy-cursor." |
| 1135 | :tag "Busy-cursor delay" |
| 1136 | :type 'number |
| 1137 | :group 'cursor |
| 1138 | :get #'(lambda (symbol) busy-cursor-delay) |
| 1139 | :set #'(lambda (symbol value) |
| 1140 | (set-default symbol value) |
| 1141 | (setq busy-cursor-delay value))) |
| 1142 | |
| 1143 | \f |
| 1144 | (defcustom show-cursor-in-non-selected-windows t |
| 1145 | "*Non-nil means show a hollow box cursor in non-selected-windows. |
| 1146 | If nil, don't show a cursor except in the selected window." |
| 1147 | :tag "Cursor in non-selected windows" |
| 1148 | :type 'boolean |
| 1149 | :group 'cursor |
| 1150 | :get #'(lambda (symbol) cursor-in-non-selected-windows) |
| 1151 | :set #'(lambda (symbol value) |
| 1152 | (set-default symbol value) |
| 1153 | (setq cursor-in-non-selected-windows value) |
| 1154 | (force-mode-line-update t))) |
| 1155 | |
| 1156 | \f |
| 1157 | ;;;; Key bindings |
| 1158 | |
| 1159 | (define-key ctl-x-5-map "2" 'make-frame-command) |
| 1160 | (define-key ctl-x-5-map "1" 'delete-other-frames) |
| 1161 | (define-key ctl-x-5-map "0" 'delete-frame) |
| 1162 | (define-key ctl-x-5-map "o" 'other-frame) |
| 1163 | |
| 1164 | (provide 'frame) |
| 1165 | |
| 1166 | ;;; frame.el ends here |