frame.el 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669
  1. ;;; frame.el --- multi-frame management independent of window systems
  2. ;; Copyright (C) 1993-1994, 1996-1997, 2000-2012
  3. ;; Free Software Foundation, Inc.
  4. ;; Maintainer: FSF
  5. ;; Keywords: internal
  6. ;; Package: emacs
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;;; Code:
  20. (eval-when-compile (require 'cl))
  21. (defvar frame-creation-function-alist
  22. (list (cons nil
  23. (if (fboundp 'tty-create-frame-with-faces)
  24. 'tty-create-frame-with-faces
  25. (lambda (_parameters)
  26. (error "Can't create multiple frames without a window system")))))
  27. "Alist of window-system dependent functions to call to create a new frame.
  28. The window system startup file should add its frame creation
  29. function to this list, which should take an alist of parameters
  30. as its argument.")
  31. (defvar window-system-default-frame-alist nil
  32. "Window-system dependent default frame parameters.
  33. The value should be an alist of elements (WINDOW-SYSTEM . ALIST),
  34. where WINDOW-SYSTEM is a window system symbol (see `window-system')
  35. and ALIST is a frame parameter alist like `default-frame-alist'.
  36. Then, for frames on WINDOW-SYSTEM, any parameters specified in
  37. ALIST supersede the corresponding parameters specified in
  38. `default-frame-alist'.")
  39. ;; The initial value given here used to ask for a minibuffer.
  40. ;; But that's not necessary, because the default is to have one.
  41. ;; By not specifying it here, we let an X resource specify it.
  42. (defcustom initial-frame-alist nil
  43. "Alist of parameters for the initial X window frame.
  44. You can set this in your init file; for example,
  45. (setq initial-frame-alist
  46. '((top . 1) (left . 1) (width . 80) (height . 55)))
  47. Parameters specified here supersede the values given in
  48. `default-frame-alist'.
  49. If the value calls for a frame without a minibuffer, and you have
  50. not created a minibuffer frame on your own, a minibuffer frame is
  51. created according to `minibuffer-frame-alist'.
  52. You can specify geometry-related options for just the initial
  53. frame by setting this variable in your init file; however, they
  54. won't take effect until Emacs reads your init file, which happens
  55. after creating the initial frame. If you want the initial frame
  56. to have the proper geometry as soon as it appears, you need to
  57. use this three-step process:
  58. * Specify X resources to give the geometry you want.
  59. * Set `default-frame-alist' to override these options so that they
  60. don't affect subsequent frames.
  61. * Set `initial-frame-alist' in a way that matches the X resources,
  62. to override what you put in `default-frame-alist'."
  63. :type '(repeat (cons :format "%v"
  64. (symbol :tag "Parameter")
  65. (sexp :tag "Value")))
  66. :group 'frames)
  67. (defcustom minibuffer-frame-alist '((width . 80) (height . 2))
  68. "Alist of parameters for the initial minibuffer frame.
  69. This is the minibuffer frame created if `initial-frame-alist'
  70. calls for a frame without a minibuffer. The parameters specified
  71. here supersede those given in `default-frame-alist', for the
  72. initial minibuffer frame.
  73. You can set this in your init file; for example,
  74. (setq minibuffer-frame-alist
  75. '((top . 1) (left . 1) (width . 80) (height . 2)))
  76. It is not necessary to include (minibuffer . only); that is
  77. appended when the minibuffer frame is created."
  78. :type '(repeat (cons :format "%v"
  79. (symbol :tag "Parameter")
  80. (sexp :tag "Value")))
  81. :group 'frames)
  82. (defun handle-delete-frame (event)
  83. "Handle delete-frame events from the X server."
  84. (interactive "e")
  85. (let ((frame (posn-window (event-start event)))
  86. (i 0)
  87. (tail (frame-list)))
  88. (while tail
  89. (and (frame-visible-p (car tail))
  90. (not (eq (car tail) frame))
  91. (setq i (1+ i)))
  92. (setq tail (cdr tail)))
  93. (if (> i 0)
  94. (delete-frame frame t)
  95. ;; Gildea@x.org says it is ok to ask questions before terminating.
  96. (save-buffers-kill-emacs))))
  97. ;;;; Arrangement of frames at startup
  98. ;; 1) Load the window system startup file from the lisp library and read the
  99. ;; high-priority arguments (-q and the like). The window system startup
  100. ;; file should create any frames specified in the window system defaults.
  101. ;;
  102. ;; 2) If no frames have been opened, we open an initial text frame.
  103. ;;
  104. ;; 3) Once the init file is done, we apply any newly set parameters
  105. ;; in initial-frame-alist to the frame.
  106. ;; These are now called explicitly at the proper times,
  107. ;; since that is easier to understand.
  108. ;; Actually using hooks within Emacs is bad for future maintenance. --rms.
  109. ;; (add-hook 'before-init-hook 'frame-initialize)
  110. ;; (add-hook 'window-setup-hook 'frame-notice-user-settings)
  111. ;; If we create the initial frame, this is it.
  112. (defvar frame-initial-frame nil)
  113. ;; Record the parameters used in frame-initialize to make the initial frame.
  114. (defvar frame-initial-frame-alist)
  115. (defvar frame-initial-geometry-arguments nil)
  116. ;; startup.el calls this function before loading the user's init
  117. ;; file - if there is no frame with a minibuffer open now, create
  118. ;; one to display messages while loading the init file.
  119. (defun frame-initialize ()
  120. "Create an initial frame if necessary."
  121. ;; Are we actually running under a window system at all?
  122. (if (and initial-window-system
  123. (not noninteractive)
  124. (not (eq initial-window-system 'pc)))
  125. (progn
  126. ;; If there is no frame with a minibuffer besides the terminal
  127. ;; frame, then we need to create the opening frame. Make sure
  128. ;; it has a minibuffer, but let initial-frame-alist omit the
  129. ;; minibuffer spec.
  130. (or (delq terminal-frame (minibuffer-frame-list))
  131. (progn
  132. (setq frame-initial-frame-alist
  133. (append initial-frame-alist default-frame-alist nil))
  134. (or (assq 'horizontal-scroll-bars frame-initial-frame-alist)
  135. (setq frame-initial-frame-alist
  136. (cons '(horizontal-scroll-bars . t)
  137. frame-initial-frame-alist)))
  138. (setq frame-initial-frame-alist
  139. (cons (cons 'window-system initial-window-system)
  140. frame-initial-frame-alist))
  141. (setq default-minibuffer-frame
  142. (setq frame-initial-frame
  143. (make-frame frame-initial-frame-alist)))
  144. ;; Delete any specifications for window geometry parameters
  145. ;; so that we won't reapply them in frame-notice-user-settings.
  146. ;; It would be wrong to reapply them then,
  147. ;; because that would override explicit user resizing.
  148. (setq initial-frame-alist
  149. (frame-remove-geometry-params initial-frame-alist))))
  150. ;; Copy the environment of the Emacs process into the new frame.
  151. (set-frame-parameter frame-initial-frame 'environment
  152. (frame-parameter terminal-frame 'environment))
  153. ;; At this point, we know that we have a frame open, so we
  154. ;; can delete the terminal frame.
  155. (delete-frame terminal-frame)
  156. (setq terminal-frame nil))))
  157. (defvar frame-notice-user-settings t
  158. "Non-nil means function `frame-notice-user-settings' wasn't run yet.")
  159. (declare-function tool-bar-mode "tool-bar" (&optional arg))
  160. ;; startup.el calls this function after loading the user's init
  161. ;; file. Now default-frame-alist and initial-frame-alist contain
  162. ;; information to which we must react; do what needs to be done.
  163. (defun frame-notice-user-settings ()
  164. "Act on user's init file settings of frame parameters.
  165. React to settings of `initial-frame-alist',
  166. `window-system-default-frame-alist' and `default-frame-alist'
  167. there (in decreasing order of priority)."
  168. ;; Creating and deleting frames may shift the selected frame around,
  169. ;; and thus the current buffer. Protect against that. We don't
  170. ;; want to use save-excursion here, because that may also try to set
  171. ;; the buffer of the selected window, which fails when the selected
  172. ;; window is the minibuffer.
  173. (let ((old-buffer (current-buffer))
  174. (window-system-frame-alist
  175. (cdr (assq initial-window-system
  176. window-system-default-frame-alist))))
  177. (when (and frame-notice-user-settings
  178. (null frame-initial-frame))
  179. ;; This case happens when we don't have a window system, and
  180. ;; also for MS-DOS frames.
  181. (let ((parms (frame-parameters)))
  182. ;; Don't change the frame names.
  183. (setq parms (delq (assq 'name parms) parms))
  184. ;; Can't modify the minibuffer parameter, so don't try.
  185. (setq parms (delq (assq 'minibuffer parms) parms))
  186. (modify-frame-parameters
  187. nil
  188. (if initial-window-system
  189. parms
  190. ;; initial-frame-alist and default-frame-alist were already
  191. ;; applied in pc-win.el.
  192. (append initial-frame-alist window-system-frame-alist
  193. default-frame-alist parms nil)))
  194. (if (null initial-window-system) ;; MS-DOS does this differently in pc-win.el
  195. (let ((newparms (frame-parameters))
  196. (frame (selected-frame)))
  197. (tty-handle-reverse-video frame newparms)
  198. ;; If we changed the background color, we need to update
  199. ;; the background-mode parameter, and maybe some faces,
  200. ;; too.
  201. (when (assq 'background-color newparms)
  202. (unless (or (assq 'background-mode initial-frame-alist)
  203. (assq 'background-mode default-frame-alist))
  204. (frame-set-background-mode frame))
  205. (face-set-after-frame-default frame))))))
  206. ;; If the initial frame is still around, apply initial-frame-alist
  207. ;; and default-frame-alist to it.
  208. (when (frame-live-p frame-initial-frame)
  209. ;; When tool-bar has been switched off, correct the frame size
  210. ;; by the lines added in x-create-frame for the tool-bar and
  211. ;; switch `tool-bar-mode' off.
  212. (when (display-graphic-p)
  213. (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
  214. (assq 'tool-bar-lines window-system-frame-alist)
  215. (assq 'tool-bar-lines default-frame-alist))))
  216. (when (and tool-bar-originally-present
  217. (or (null tool-bar-lines)
  218. (null (cdr tool-bar-lines))
  219. (eq 0 (cdr tool-bar-lines))))
  220. (let* ((char-height (frame-char-height frame-initial-frame))
  221. (image-height tool-bar-images-pixel-height)
  222. (margin (cond ((and (consp tool-bar-button-margin)
  223. (integerp (cdr tool-bar-button-margin))
  224. (> tool-bar-button-margin 0))
  225. (cdr tool-bar-button-margin))
  226. ((and (integerp tool-bar-button-margin)
  227. (> tool-bar-button-margin 0))
  228. tool-bar-button-margin)
  229. (t 0)))
  230. (relief (if (and (integerp tool-bar-button-relief)
  231. (> tool-bar-button-relief 0))
  232. tool-bar-button-relief 3))
  233. (lines (/ (+ image-height
  234. (* 2 margin)
  235. (* 2 relief)
  236. (1- char-height))
  237. char-height))
  238. (height (frame-parameter frame-initial-frame 'height))
  239. (newparms (list (cons 'height (- height lines))))
  240. (initial-top (cdr (assq 'top
  241. frame-initial-geometry-arguments)))
  242. (top (frame-parameter frame-initial-frame 'top)))
  243. (when (and (consp initial-top) (eq '- (car initial-top)))
  244. (let ((adjusted-top
  245. (cond ((and (consp top)
  246. (eq '+ (car top)))
  247. (list '+
  248. (+ (cadr top)
  249. (* lines char-height))))
  250. ((and (consp top)
  251. (eq '- (car top)))
  252. (list '-
  253. (- (cadr top)
  254. (* lines char-height))))
  255. (t (+ top (* lines char-height))))))
  256. (setq newparms
  257. (append newparms
  258. `((top . ,adjusted-top))
  259. nil))))
  260. (modify-frame-parameters frame-initial-frame newparms)
  261. (tool-bar-mode -1)))))
  262. ;; The initial frame we create above always has a minibuffer.
  263. ;; If the user wants to remove it, or make it a minibuffer-only
  264. ;; frame, then we'll have to delete the current frame and make a
  265. ;; new one; you can't remove or add a root window to/from an
  266. ;; existing frame.
  267. ;;
  268. ;; NOTE: default-frame-alist was nil when we created the
  269. ;; existing frame. We need to explicitly include
  270. ;; default-frame-alist in the parameters of the screen we
  271. ;; create here, so that its new value, gleaned from the user's
  272. ;; .emacs file, will be applied to the existing screen.
  273. (if (not (eq (cdr (or (assq 'minibuffer initial-frame-alist)
  274. (assq 'minibuffer window-system-frame-alist)
  275. (assq 'minibuffer default-frame-alist)
  276. '(minibuffer . t)))
  277. t))
  278. ;; Create the new frame.
  279. (let (parms new)
  280. ;; If the frame isn't visible yet, wait till it is.
  281. ;; If the user has to position the window,
  282. ;; Emacs doesn't know its real position until
  283. ;; the frame is seen to be visible.
  284. (while (not (cdr (assq 'visibility
  285. (frame-parameters frame-initial-frame))))
  286. (sleep-for 1))
  287. (setq parms (frame-parameters frame-initial-frame))
  288. ;; Get rid of `name' unless it was specified explicitly before.
  289. (or (assq 'name frame-initial-frame-alist)
  290. (setq parms (delq (assq 'name parms) parms)))
  291. ;; An explicit parent-id is a request to XEmbed the frame.
  292. (or (assq 'parent-id frame-initial-frame-alist)
  293. (setq parms (delq (assq 'parent-id parms) parms)))
  294. (setq parms (append initial-frame-alist
  295. window-system-frame-alist
  296. default-frame-alist
  297. parms
  298. nil))
  299. ;; Get rid of `reverse', because that was handled
  300. ;; when we first made the frame.
  301. (setq parms (cons '(reverse) (delq (assq 'reverse parms) parms)))
  302. (if (assq 'height frame-initial-geometry-arguments)
  303. (setq parms (assq-delete-all 'height parms)))
  304. (if (assq 'width frame-initial-geometry-arguments)
  305. (setq parms (assq-delete-all 'width parms)))
  306. (if (assq 'left frame-initial-geometry-arguments)
  307. (setq parms (assq-delete-all 'left parms)))
  308. (if (assq 'top frame-initial-geometry-arguments)
  309. (setq parms (assq-delete-all 'top parms)))
  310. (setq new
  311. (make-frame
  312. ;; Use the geometry args that created the existing
  313. ;; frame, rather than the parms we get for it.
  314. (append frame-initial-geometry-arguments
  315. '((user-size . t) (user-position . t))
  316. parms)))
  317. ;; The initial frame, which we are about to delete, may be
  318. ;; the only frame with a minibuffer. If it is, create a
  319. ;; new one.
  320. (or (delq frame-initial-frame (minibuffer-frame-list))
  321. (make-initial-minibuffer-frame nil))
  322. ;; If the initial frame is serving as a surrogate
  323. ;; minibuffer frame for any frames, we need to wean them
  324. ;; onto a new frame. The default-minibuffer-frame
  325. ;; variable must be handled similarly.
  326. (let ((users-of-initial
  327. (filtered-frame-list
  328. (lambda (frame)
  329. (and (not (eq frame frame-initial-frame))
  330. (eq (window-frame
  331. (minibuffer-window frame))
  332. frame-initial-frame))))))
  333. (if (or users-of-initial
  334. (eq default-minibuffer-frame frame-initial-frame))
  335. ;; Choose an appropriate frame. Prefer frames which
  336. ;; are only minibuffers.
  337. (let* ((new-surrogate
  338. (car
  339. (or (filtered-frame-list
  340. (lambda (frame)
  341. (eq (cdr (assq 'minibuffer
  342. (frame-parameters frame)))
  343. 'only)))
  344. (minibuffer-frame-list))))
  345. (new-minibuffer (minibuffer-window new-surrogate)))
  346. (if (eq default-minibuffer-frame frame-initial-frame)
  347. (setq default-minibuffer-frame new-surrogate))
  348. ;; Wean the frames using frame-initial-frame as
  349. ;; their minibuffer frame.
  350. (dolist (frame users-of-initial)
  351. (modify-frame-parameters
  352. frame (list (cons 'minibuffer new-minibuffer)))))))
  353. ;; Redirect events enqueued at this frame to the new frame.
  354. ;; Is this a good idea?
  355. (redirect-frame-focus frame-initial-frame new)
  356. ;; Finally, get rid of the old frame.
  357. (delete-frame frame-initial-frame t))
  358. ;; Otherwise, we don't need all that rigmarole; just apply
  359. ;; the new parameters.
  360. (let (newparms allparms tail)
  361. (setq allparms (append initial-frame-alist
  362. window-system-frame-alist
  363. default-frame-alist nil))
  364. (if (assq 'height frame-initial-geometry-arguments)
  365. (setq allparms (assq-delete-all 'height allparms)))
  366. (if (assq 'width frame-initial-geometry-arguments)
  367. (setq allparms (assq-delete-all 'width allparms)))
  368. (if (assq 'left frame-initial-geometry-arguments)
  369. (setq allparms (assq-delete-all 'left allparms)))
  370. (if (assq 'top frame-initial-geometry-arguments)
  371. (setq allparms (assq-delete-all 'top allparms)))
  372. (setq tail allparms)
  373. ;; Find just the parms that have changed since we first
  374. ;; made this frame. Those are the ones actually set by
  375. ;; the init file. For those parms whose values we already knew
  376. ;; (such as those spec'd by command line options)
  377. ;; it is undesirable to specify the parm again
  378. ;; once the user has seen the frame and been able to alter it
  379. ;; manually.
  380. (let (newval oldval)
  381. (dolist (entry tail)
  382. (setq oldval (assq (car entry) frame-initial-frame-alist))
  383. (setq newval (cdr (assq (car entry) allparms)))
  384. (or (and oldval (eq (cdr oldval) newval))
  385. (setq newparms
  386. (cons (cons (car entry) newval) newparms)))))
  387. (setq newparms (nreverse newparms))
  388. (let ((new-bg (assq 'background-color newparms)))
  389. ;; If the `background-color' parameter is changed, apply
  390. ;; it first, then make sure that the `background-mode'
  391. ;; parameter and other faces are updated, before applying
  392. ;; the other parameters.
  393. (when new-bg
  394. (modify-frame-parameters frame-initial-frame
  395. (list new-bg))
  396. (unless (assq 'background-mode newparms)
  397. (frame-set-background-mode frame-initial-frame))
  398. (face-set-after-frame-default frame-initial-frame)
  399. (setq newparms (delq new-bg newparms)))
  400. (modify-frame-parameters frame-initial-frame newparms)))))
  401. ;; Restore the original buffer.
  402. (set-buffer old-buffer)
  403. ;; Make sure the initial frame can be GC'd if it is ever deleted.
  404. ;; Make sure frame-notice-user-settings does nothing if called twice.
  405. (setq frame-notice-user-settings nil)
  406. (setq frame-initial-frame nil)))
  407. (defun make-initial-minibuffer-frame (display)
  408. (let ((parms (append minibuffer-frame-alist '((minibuffer . only)))))
  409. (if display
  410. (make-frame-on-display display parms)
  411. (make-frame parms))))
  412. ;;;; Creation of additional frames, and other frame miscellanea
  413. (defun modify-all-frames-parameters (alist)
  414. "Modify all current and future frames' parameters according to ALIST.
  415. This changes `default-frame-alist' and possibly `initial-frame-alist'.
  416. Furthermore, this function removes all parameters in ALIST from
  417. `window-system-default-frame-alist'.
  418. See help of `modify-frame-parameters' for more information."
  419. (dolist (frame (frame-list))
  420. (modify-frame-parameters frame alist))
  421. (dolist (pair alist) ;; conses to add/replace
  422. ;; initial-frame-alist needs setting only when
  423. ;; frame-notice-user-settings is true.
  424. (and frame-notice-user-settings
  425. (setq initial-frame-alist
  426. (assq-delete-all (car pair) initial-frame-alist)))
  427. (setq default-frame-alist
  428. (assq-delete-all (car pair) default-frame-alist))
  429. ;; Remove any similar settings from the window-system specific
  430. ;; parameters---they would override default-frame-alist.
  431. (dolist (w window-system-default-frame-alist)
  432. (setcdr w (assq-delete-all (car pair) (cdr w)))))
  433. (and frame-notice-user-settings
  434. (setq initial-frame-alist (append initial-frame-alist alist)))
  435. (setq default-frame-alist (append default-frame-alist alist)))
  436. (defun get-other-frame ()
  437. "Return some frame other than the current frame.
  438. Create one if necessary. Note that the minibuffer frame, if separate,
  439. is not considered (see `next-frame')."
  440. (let ((s (if (equal (next-frame (selected-frame)) (selected-frame))
  441. (make-frame)
  442. (next-frame (selected-frame)))))
  443. s))
  444. (defun next-multiframe-window ()
  445. "Select the next window, regardless of which frame it is on."
  446. (interactive)
  447. (select-window (next-window (selected-window)
  448. (> (minibuffer-depth) 0)
  449. 0))
  450. (select-frame-set-input-focus (selected-frame)))
  451. (defun previous-multiframe-window ()
  452. "Select the previous window, regardless of which frame it is on."
  453. (interactive)
  454. (select-window (previous-window (selected-window)
  455. (> (minibuffer-depth) 0)
  456. 0))
  457. (select-frame-set-input-focus (selected-frame)))
  458. (declare-function x-initialize-window-system "term/x-win" ())
  459. (declare-function ns-initialize-window-system "term/ns-win" ())
  460. (defvar x-display-name) ; term/x-win
  461. (defun make-frame-on-display (display &optional parameters)
  462. "Make a frame on display DISPLAY.
  463. The optional argument PARAMETERS specifies additional frame parameters."
  464. (interactive "sMake frame on display: ")
  465. (cond ((featurep 'ns)
  466. (when (and (boundp 'ns-initialized) (not ns-initialized))
  467. (setq x-display-name display)
  468. (ns-initialize-window-system))
  469. (make-frame `((window-system . ns)
  470. (display . ,display) . ,parameters)))
  471. ((eq system-type 'windows-nt)
  472. ;; On Windows, ignore DISPLAY.
  473. (make-frame parameters))
  474. (t
  475. (unless (string-match-p "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display)
  476. (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
  477. (when (and (boundp 'x-initialized) (not x-initialized))
  478. (setq x-display-name display)
  479. (x-initialize-window-system))
  480. (make-frame `((window-system . x)
  481. (display . ,display) . ,parameters)))))
  482. (declare-function x-close-connection "xfns.c" (terminal))
  483. (defun close-display-connection (display)
  484. "Close the connection to a display, deleting all its associated frames.
  485. For DISPLAY, specify either a frame or a display name (a string).
  486. If DISPLAY is nil, that stands for the selected frame's display."
  487. (interactive
  488. (list
  489. (let* ((default (frame-parameter nil 'display))
  490. (display (completing-read
  491. (format "Close display (default %s): " default)
  492. (delete-dups
  493. (mapcar (lambda (frame)
  494. (frame-parameter frame 'display))
  495. (frame-list)))
  496. nil t nil nil
  497. default)))
  498. (if (zerop (length display)) default display))))
  499. (let ((frames (delq nil
  500. (mapcar (lambda (frame)
  501. (if (equal display
  502. (frame-parameter frame 'display))
  503. frame))
  504. (frame-list)))))
  505. (if (and (consp frames)
  506. (not (y-or-n-p (if (cdr frames)
  507. (format "Delete %s frames? " (length frames))
  508. (format "Delete %s ? " (car frames))))))
  509. (error "Abort!")
  510. (mapc 'delete-frame frames)
  511. (x-close-connection display))))
  512. (defun make-frame-command ()
  513. "Make a new frame, on the same terminal as the selected frame.
  514. If the terminal is a text-only terminal, this also selects the
  515. new frame."
  516. (interactive)
  517. (if (display-graphic-p)
  518. (make-frame)
  519. (select-frame (make-frame))))
  520. (defvar before-make-frame-hook nil
  521. "Functions to run before a frame is created.")
  522. (defvar after-make-frame-functions nil
  523. "Functions to run after a frame is created.
  524. The functions are run with one arg, the newly created frame.")
  525. (defvar after-setting-font-hook nil
  526. "Functions to run after a frame's font has been changed.")
  527. ;; Alias, kept temporarily.
  528. (define-obsolete-function-alias 'new-frame 'make-frame "22.1")
  529. (defvar frame-inherited-parameters '()
  530. ;; FIXME: Shouldn't we add `font' here as well?
  531. "Parameters `make-frame' copies from the `selected-frame' to the new frame.")
  532. (defun make-frame (&optional parameters)
  533. "Return a newly created frame displaying the current buffer.
  534. Optional argument PARAMETERS is an alist of frame parameters for
  535. the new frame. Each element of PARAMETERS should have the
  536. form (NAME . VALUE), for example:
  537. (name . STRING) The frame should be named STRING.
  538. (width . NUMBER) The frame should be NUMBER characters in width.
  539. (height . NUMBER) The frame should be NUMBER text lines high.
  540. You cannot specify either `width' or `height', you must specify
  541. neither or both.
  542. (minibuffer . t) The frame should have a minibuffer.
  543. (minibuffer . nil) The frame should have no minibuffer.
  544. (minibuffer . only) The frame should contain only a minibuffer.
  545. (minibuffer . WINDOW) The frame should use WINDOW as its minibuffer window.
  546. (window-system . nil) The frame should be displayed on a terminal device.
  547. (window-system . x) The frame should be displayed in an X window.
  548. (terminal . TERMINAL) The frame should use the terminal object TERMINAL.
  549. In addition, any parameter specified in `default-frame-alist',
  550. but not present in PARAMETERS, is applied.
  551. Before creating the frame (via `frame-creation-function-alist'),
  552. this function runs the hook `before-make-frame-hook'. After
  553. creating the frame, it runs the hook `after-make-frame-functions'
  554. with one arg, the newly created frame.
  555. On graphical displays, this function does not itself make the new
  556. frame the selected frame. However, the window system may select
  557. the new frame according to its own rules."
  558. (interactive)
  559. (let* ((w (cond
  560. ((assq 'terminal parameters)
  561. (let ((type (terminal-live-p (cdr (assq 'terminal parameters)))))
  562. (cond
  563. ((eq type t) nil)
  564. ((eq type nil) (error "Terminal %s does not exist"
  565. (cdr (assq 'terminal parameters))))
  566. (t type))))
  567. ((assq 'window-system parameters)
  568. (cdr (assq 'window-system parameters)))
  569. (t window-system)))
  570. (frame-creation-function (cdr (assq w frame-creation-function-alist)))
  571. (oldframe (selected-frame))
  572. (params parameters)
  573. frame)
  574. (unless frame-creation-function
  575. (error "Don't know how to create a frame on window system %s" w))
  576. ;; Add parameters from `window-system-default-frame-alist'.
  577. (dolist (p (cdr (assq w window-system-default-frame-alist)))
  578. (unless (assq (car p) params)
  579. (push p params)))
  580. ;; Add parameters from `default-frame-alist'.
  581. (dolist (p default-frame-alist)
  582. (unless (assq (car p) params)
  583. (push p params)))
  584. ;; Now make the frame.
  585. (run-hooks 'before-make-frame-hook)
  586. (setq frame (funcall frame-creation-function params))
  587. (normal-erase-is-backspace-setup-frame frame)
  588. ;; Inherit the original frame's parameters.
  589. (dolist (param frame-inherited-parameters)
  590. (unless (assq param parameters) ;Overridden by explicit parameters.
  591. (let ((val (frame-parameter oldframe param)))
  592. (when val (set-frame-parameter frame param val)))))
  593. (run-hook-with-args 'after-make-frame-functions frame)
  594. frame))
  595. (defun filtered-frame-list (predicate)
  596. "Return a list of all live frames which satisfy PREDICATE."
  597. (let* ((frames (frame-list))
  598. (list frames))
  599. (while (consp frames)
  600. (unless (funcall predicate (car frames))
  601. (setcar frames nil))
  602. (setq frames (cdr frames)))
  603. (delq nil list)))
  604. (defun minibuffer-frame-list ()
  605. "Return a list of all frames with their own minibuffers."
  606. (filtered-frame-list
  607. (lambda (frame)
  608. (eq frame (window-frame (minibuffer-window frame))))))
  609. ;; Used to be called `terminal-id' in termdev.el.
  610. (defun get-device-terminal (device)
  611. "Return the terminal corresponding to DEVICE.
  612. DEVICE can be a terminal, a frame, nil (meaning the selected frame's terminal),
  613. the name of an X display device (HOST.SERVER.SCREEN) or a tty device file."
  614. (cond
  615. ((or (null device) (framep device))
  616. (frame-terminal device))
  617. ((stringp device)
  618. (let ((f (car (filtered-frame-list
  619. (lambda (frame)
  620. (or (equal (frame-parameter frame 'display) device)
  621. (equal (frame-parameter frame 'tty) device)))))))
  622. (or f (error "Display %s does not exist" device))
  623. (frame-terminal f)))
  624. ((terminal-live-p device) device)
  625. (t
  626. (error "Invalid argument %s in `get-device-terminal'" device))))
  627. (defun frames-on-display-list (&optional device)
  628. "Return a list of all frames on DEVICE.
  629. DEVICE should be a terminal, a frame,
  630. or a name of an X display or tty (a string of the form
  631. HOST:SERVER.SCREEN).
  632. If DEVICE is omitted or nil, it defaults to the selected
  633. frame's terminal device."
  634. (let* ((terminal (get-device-terminal device))
  635. (func #'(lambda (frame)
  636. (eq (frame-terminal frame) terminal))))
  637. (filtered-frame-list func)))
  638. (defun framep-on-display (&optional terminal)
  639. "Return the type of frames on TERMINAL.
  640. TERMINAL may be a terminal id, a display name or a frame. If it
  641. is a frame, its type is returned. If TERMINAL is omitted or nil,
  642. it defaults to the selected frame's terminal device. All frames
  643. on a given display are of the same type."
  644. (or (terminal-live-p terminal)
  645. (framep terminal)
  646. (framep (car (frames-on-display-list terminal)))))
  647. (defun frame-remove-geometry-params (param-list)
  648. "Return the parameter list PARAM-LIST, but with geometry specs removed.
  649. This deletes all bindings in PARAM-LIST for `top', `left', `width',
  650. `height', `user-size' and `user-position' parameters.
  651. Emacs uses this to avoid overriding explicit moves and resizings from
  652. the user during startup."
  653. (setq param-list (cons nil param-list))
  654. (let ((tail param-list))
  655. (while (consp (cdr tail))
  656. (if (and (consp (car (cdr tail)))
  657. (memq (car (car (cdr tail)))
  658. '(height width top left user-position user-size)))
  659. (progn
  660. (setq frame-initial-geometry-arguments
  661. (cons (car (cdr tail)) frame-initial-geometry-arguments))
  662. (setcdr tail (cdr (cdr tail))))
  663. (setq tail (cdr tail)))))
  664. (setq frame-initial-geometry-arguments
  665. (nreverse frame-initial-geometry-arguments))
  666. (cdr param-list))
  667. (declare-function x-focus-frame "xfns.c" (frame))
  668. (defun select-frame-set-input-focus (frame &optional norecord)
  669. "Select FRAME, raise it, and set input focus, if possible.
  670. If `mouse-autoselect-window' is non-nil, also move mouse pointer
  671. to FRAME's selected window. Otherwise, if `focus-follows-mouse'
  672. is non-nil, move mouse cursor to FRAME.
  673. Optional argument NORECORD means to neither change the order of
  674. recently selected windows nor the buffer list."
  675. (select-frame frame norecord)
  676. (raise-frame frame)
  677. ;; Ensure, if possible, that FRAME gets input focus.
  678. (when (memq (window-system frame) '(x w32 ns))
  679. (x-focus-frame frame))
  680. ;; Move mouse cursor if necessary.
  681. (cond
  682. (mouse-autoselect-window
  683. (let ((edges (window-inside-edges (frame-selected-window frame))))
  684. ;; Move mouse cursor into FRAME's selected window to avoid that
  685. ;; Emacs mouse-autoselects another window.
  686. (set-mouse-position frame (nth 2 edges) (nth 1 edges))))
  687. (focus-follows-mouse
  688. ;; Move mouse cursor into FRAME to avoid that another frame gets
  689. ;; selected by the window manager.
  690. (set-mouse-position frame (1- (frame-width frame)) 0))))
  691. (defun other-frame (arg)
  692. "Select the ARGth different visible frame on current display, and raise it.
  693. All frames are arranged in a cyclic order.
  694. This command selects the frame ARG steps away in that order.
  695. A negative ARG moves in the opposite order.
  696. To make this command work properly, you must tell Emacs
  697. how the system (or the window manager) generally handles
  698. focus-switching between windows. If moving the mouse onto a window
  699. selects it (gives it focus), set `focus-follows-mouse' to t.
  700. Otherwise, that variable should be nil."
  701. (interactive "p")
  702. (let ((frame (selected-frame)))
  703. (while (> arg 0)
  704. (setq frame (next-frame frame))
  705. (while (not (eq (frame-visible-p frame) t))
  706. (setq frame (next-frame frame)))
  707. (setq arg (1- arg)))
  708. (while (< arg 0)
  709. (setq frame (previous-frame frame))
  710. (while (not (eq (frame-visible-p frame) t))
  711. (setq frame (previous-frame frame)))
  712. (setq arg (1+ arg)))
  713. (select-frame-set-input-focus frame)))
  714. (defun iconify-or-deiconify-frame ()
  715. "Iconify the selected frame, or deiconify if it's currently an icon."
  716. (interactive)
  717. (if (eq (cdr (assq 'visibility (frame-parameters))) t)
  718. (iconify-frame)
  719. (make-frame-visible)))
  720. (defun suspend-frame ()
  721. "Do whatever is right to suspend the current frame.
  722. Calls `suspend-emacs' if invoked from the controlling tty device,
  723. `suspend-tty' from a secondary tty device, and
  724. `iconify-or-deiconify-frame' from an X frame."
  725. (interactive)
  726. (let ((type (framep (selected-frame))))
  727. (cond
  728. ((memq type '(x ns w32)) (iconify-or-deiconify-frame))
  729. ((eq type t)
  730. (if (controlling-tty-p)
  731. (suspend-emacs)
  732. (suspend-tty)))
  733. (t (suspend-emacs)))))
  734. (defun make-frame-names-alist ()
  735. ;; Only consider the frames on the same display.
  736. (let* ((current-frame (selected-frame))
  737. (falist
  738. (cons
  739. (cons (frame-parameter current-frame 'name) current-frame) nil))
  740. (frame (next-frame nil 0)))
  741. (while (not (eq frame current-frame))
  742. (progn
  743. (push (cons (frame-parameter frame 'name) frame) falist)
  744. (setq frame (next-frame frame 0))))
  745. falist))
  746. (defvar frame-name-history nil)
  747. (defun select-frame-by-name (name)
  748. "Select the frame on the current terminal whose name is NAME and raise it.
  749. If there is no frame by that name, signal an error."
  750. (interactive
  751. (let* ((frame-names-alist (make-frame-names-alist))
  752. (default (car (car frame-names-alist)))
  753. (input (completing-read
  754. (format "Select Frame (default %s): " default)
  755. frame-names-alist nil t nil 'frame-name-history)))
  756. (if (= (length input) 0)
  757. (list default)
  758. (list input))))
  759. (let* ((frame-names-alist (make-frame-names-alist))
  760. (frame (cdr (assoc name frame-names-alist))))
  761. (if frame
  762. (select-frame-set-input-focus frame)
  763. (error "There is no frame named `%s'" name))))
  764. ;;;; Background mode.
  765. (defcustom frame-background-mode nil
  766. "The brightness of the background.
  767. Set this to the symbol `dark' if your background color is dark,
  768. `light' if your background is light, or nil (automatic by default)
  769. if you want Emacs to examine the brightness for you. Don't set this
  770. variable with `setq'; this won't have the expected effect."
  771. :group 'faces
  772. :set #'(lambda (var value)
  773. (set-default var value)
  774. (mapc 'frame-set-background-mode (frame-list)))
  775. :initialize 'custom-initialize-changed
  776. :type '(choice (const dark)
  777. (const light)
  778. (const :tag "automatic" nil)))
  779. (declare-function x-get-resource "frame.c"
  780. (attribute class &optional component subclass))
  781. (defvar inhibit-frame-set-background-mode nil)
  782. (defun frame-set-background-mode (frame &optional keep-face-specs)
  783. "Set up display-dependent faces on FRAME.
  784. Display-dependent faces are those which have different definitions
  785. according to the `background-mode' and `display-type' frame parameters.
  786. If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate
  787. face specs for the new background mode."
  788. (unless inhibit-frame-set-background-mode
  789. (let* ((frame-default-bg-mode (frame-terminal-default-bg-mode frame))
  790. (bg-color (frame-parameter frame 'background-color))
  791. (tty-type (tty-type frame))
  792. (default-bg-mode
  793. (if (or (window-system frame)
  794. (and tty-type
  795. (string-match "^\\(xterm\\|\\rxvt\\|dtterm\\|eterm\\)"
  796. tty-type)))
  797. 'light
  798. 'dark))
  799. (non-default-bg-mode (if (eq default-bg-mode 'light) 'dark 'light))
  800. (bg-mode
  801. (cond (frame-default-bg-mode)
  802. ((equal bg-color "unspecified-fg") ; inverted colors
  803. non-default-bg-mode)
  804. ((not (color-values bg-color frame))
  805. default-bg-mode)
  806. ((>= (apply '+ (color-values bg-color frame))
  807. ;; Just looking at the screen, colors whose
  808. ;; values add up to .6 of the white total
  809. ;; still look dark to me.
  810. (* (apply '+ (color-values "white" frame)) .6))
  811. 'light)
  812. (t 'dark)))
  813. (display-type
  814. (cond ((null (window-system frame))
  815. (if (tty-display-color-p frame) 'color 'mono))
  816. ((display-color-p frame)
  817. 'color)
  818. ((x-display-grayscale-p frame)
  819. 'grayscale)
  820. (t 'mono)))
  821. (old-bg-mode
  822. (frame-parameter frame 'background-mode))
  823. (old-display-type
  824. (frame-parameter frame 'display-type)))
  825. (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
  826. (let ((locally-modified-faces nil)
  827. ;; Prevent face-spec-recalc from calling this function
  828. ;; again, resulting in a loop (bug#911).
  829. (inhibit-frame-set-background-mode t)
  830. (params (list (cons 'background-mode bg-mode)
  831. (cons 'display-type display-type))))
  832. (if keep-face-specs
  833. (modify-frame-parameters frame params)
  834. ;; If we are recomputing face specs, first collect a list
  835. ;; of faces that don't match their face-specs. These are
  836. ;; the faces modified on FRAME, and we avoid changing them
  837. ;; below. Use a negative list to avoid consing (we assume
  838. ;; most faces are unmodified).
  839. (dolist (face (face-list))
  840. (and (not (get face 'face-override-spec))
  841. (not (face-spec-match-p face
  842. (face-user-default-spec face)
  843. (selected-frame)))
  844. (push face locally-modified-faces)))
  845. ;; Now change to the new frame parameters
  846. (modify-frame-parameters frame params)
  847. ;; For all unmodified named faces, choose face specs
  848. ;; matching the new frame parameters.
  849. (dolist (face (face-list))
  850. (unless (memq face locally-modified-faces)
  851. (face-spec-recalc face frame)))))))))
  852. (defun frame-terminal-default-bg-mode (frame)
  853. "Return the default background mode of FRAME.
  854. This checks the `frame-background-mode' variable, the X resource
  855. named \"backgroundMode\" (if FRAME is an X frame), and finally
  856. the `background-mode' terminal parameter."
  857. (or frame-background-mode
  858. (let ((bg-resource
  859. (and (window-system frame)
  860. (x-get-resource "backgroundMode" "BackgroundMode"))))
  861. (if bg-resource
  862. (intern (downcase bg-resource))))
  863. (terminal-parameter frame 'background-mode)))
  864. ;;;; Frame configurations
  865. (defun current-frame-configuration ()
  866. "Return a list describing the positions and states of all frames.
  867. Its car is `frame-configuration'.
  868. Each element of the cdr is a list of the form (FRAME ALIST WINDOW-CONFIG),
  869. where
  870. FRAME is a frame object,
  871. ALIST is an association list specifying some of FRAME's parameters, and
  872. WINDOW-CONFIG is a window configuration object for FRAME."
  873. (cons 'frame-configuration
  874. (mapcar (lambda (frame)
  875. (list frame
  876. (frame-parameters frame)
  877. (current-window-configuration frame)))
  878. (frame-list))))
  879. (defun set-frame-configuration (configuration &optional nodelete)
  880. "Restore the frames to the state described by CONFIGURATION.
  881. Each frame listed in CONFIGURATION has its position, size, window
  882. configuration, and other parameters set as specified in CONFIGURATION.
  883. However, this function does not restore deleted frames.
  884. Ordinarily, this function deletes all existing frames not
  885. listed in CONFIGURATION. But if optional second argument NODELETE
  886. is given and non-nil, the unwanted frames are iconified instead."
  887. (or (frame-configuration-p configuration)
  888. (signal 'wrong-type-argument
  889. (list 'frame-configuration-p configuration)))
  890. (let ((config-alist (cdr configuration))
  891. frames-to-delete)
  892. (dolist (frame (frame-list))
  893. (let ((parameters (assq frame config-alist)))
  894. (if parameters
  895. (progn
  896. (modify-frame-parameters
  897. frame
  898. ;; Since we can't set a frame's minibuffer status,
  899. ;; we might as well omit the parameter altogether.
  900. (let* ((parms (nth 1 parameters))
  901. (mini (assq 'minibuffer parms))
  902. (name (assq 'name parms))
  903. (explicit-name (cdr (assq 'explicit-name parms))))
  904. (when mini (setq parms (delq mini parms)))
  905. ;; Leave name in iff it was set explicitly.
  906. ;; This should fix the behavior reported in
  907. ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg01632.html
  908. (when (and name (not explicit-name))
  909. (setq parms (delq name parms)))
  910. parms))
  911. (set-window-configuration (nth 2 parameters)))
  912. (setq frames-to-delete (cons frame frames-to-delete)))))
  913. (mapc (if nodelete
  914. ;; Note: making frames invisible here was tried
  915. ;; but led to some strange behavior--each time the frame
  916. ;; was made visible again, the window manager asked afresh
  917. ;; for where to put it.
  918. 'iconify-frame
  919. 'delete-frame)
  920. frames-to-delete)))
  921. ;;;; Convenience functions for accessing and interactively changing
  922. ;;;; frame parameters.
  923. (defun frame-height (&optional frame)
  924. "Return number of lines available for display on FRAME.
  925. If FRAME is omitted, describe the currently selected frame.
  926. Exactly what is included in the return value depends on the
  927. window-system and toolkit in use - see `frame-pixel-height' for
  928. more details. The lines are in units of the default font height.
  929. The result is roughly related to the frame pixel height via
  930. height in pixels = height in lines * `frame-char-height'.
  931. However, this is only approximate, and is complicated e.g. by the
  932. fact that individual window lines and menu bar lines can have
  933. differing font heights."
  934. (cdr (assq 'height (frame-parameters frame))))
  935. (defun frame-width (&optional frame)
  936. "Return number of columns available for display on FRAME.
  937. If FRAME is omitted, describe the currently selected frame."
  938. (cdr (assq 'width (frame-parameters frame))))
  939. (declare-function x-list-fonts "xfaces.c"
  940. (pattern &optional face frame maximum width))
  941. (define-obsolete-function-alias 'set-default-font 'set-frame-font "23.1")
  942. (defun set-frame-font (font-name &optional keep-size frames)
  943. "Set the default font to FONT-NAME.
  944. When called interactively, prompt for the name of a font, and use
  945. that font on the selected frame.
  946. If KEEP-SIZE is nil, keep the number of frame lines and columns
  947. fixed. If KEEP-SIZE is non-nil (or with a prefix argument), try
  948. to keep the current frame size fixed (in pixels) by adjusting the
  949. number of lines and columns.
  950. If FRAMES is nil, apply the font to the selected frame only.
  951. If FRAMES is non-nil, it should be a list of frames to act upon,
  952. or t meaning all graphical frames. Also, if FRAME is non-nil,
  953. alter the user's Customization settings as though the
  954. font-related attributes of the `default' face had been \"set in
  955. this session\", so that the font is applied to future frames."
  956. (interactive
  957. (let* ((completion-ignore-case t)
  958. (font (completing-read "Font name: "
  959. ;; x-list-fonts will fail with an error
  960. ;; if this frame doesn't support fonts.
  961. (x-list-fonts "*" nil (selected-frame))
  962. nil nil nil nil
  963. (frame-parameter nil 'font))))
  964. (list font current-prefix-arg nil)))
  965. (when (stringp font-name)
  966. (let* ((this-frame (selected-frame))
  967. ;; FRAMES nil means affect the selected frame.
  968. (frame-list (cond ((null frames)
  969. (list this-frame))
  970. ((eq frames t)
  971. (frame-list))
  972. (t frames)))
  973. height width)
  974. (dolist (f frame-list)
  975. (when (display-multi-font-p f)
  976. (if keep-size
  977. (setq height (* (frame-parameter f 'height)
  978. (frame-char-height f))
  979. width (* (frame-parameter f 'width)
  980. (frame-char-width f))))
  981. ;; When set-face-attribute is called for :font, Emacs
  982. ;; guesses the best font according to other face attributes
  983. ;; (:width, :weight, etc.) so reset them too (Bug#2476).
  984. (set-face-attribute 'default f
  985. :width 'normal :weight 'normal
  986. :slant 'normal :font font-name)
  987. (if keep-size
  988. (modify-frame-parameters
  989. f
  990. (list (cons 'height (round height (frame-char-height f)))
  991. (cons 'width (round width (frame-char-width f))))))))
  992. (when frames
  993. ;; Alter the user's Custom setting of the `default' face, but
  994. ;; only for font-related attributes.
  995. (let ((specs (cadr (assq 'user (get 'default 'theme-face))))
  996. (attrs '(:family :foundry :slant :weight :height :width))
  997. (new-specs nil))
  998. (if (null specs) (setq specs '((t nil))))
  999. (dolist (spec specs)
  1000. ;; Each SPEC has the form (DISPLAY ATTRIBUTE-PLIST)
  1001. (let ((display (nth 0 spec))
  1002. (plist (copy-tree (nth 1 spec))))
  1003. ;; Alter only DISPLAY conditions matching this frame.
  1004. (when (or (memq display '(t default))
  1005. (face-spec-set-match-display display this-frame))
  1006. (dolist (attr attrs)
  1007. (setq plist (plist-put plist attr
  1008. (face-attribute 'default attr)))))
  1009. (push (list display plist) new-specs)))
  1010. (setq new-specs (nreverse new-specs))
  1011. (put 'default 'customized-face new-specs)
  1012. (custom-push-theme 'theme-face 'default 'user 'set new-specs)
  1013. (put 'default 'face-modified nil))))
  1014. (run-hooks 'after-setting-font-hook 'after-setting-font-hooks)))
  1015. (defun set-frame-parameter (frame parameter value)
  1016. "Set frame parameter PARAMETER to VALUE on FRAME.
  1017. If FRAME is nil, it defaults to the selected frame.
  1018. See `modify-frame-parameters'."
  1019. (modify-frame-parameters frame (list (cons parameter value))))
  1020. (defun set-background-color (color-name)
  1021. "Set the background color of the selected frame to COLOR-NAME.
  1022. When called interactively, prompt for the name of the color to use.
  1023. To get the frame's current background color, use `frame-parameters'."
  1024. (interactive (list (read-color "Background color: ")))
  1025. (modify-frame-parameters (selected-frame)
  1026. (list (cons 'background-color color-name)))
  1027. (or window-system
  1028. (face-set-after-frame-default (selected-frame))))
  1029. (defun set-foreground-color (color-name)
  1030. "Set the foreground color of the selected frame to COLOR-NAME.
  1031. When called interactively, prompt for the name of the color to use.
  1032. To get the frame's current foreground color, use `frame-parameters'."
  1033. (interactive (list (read-color "Foreground color: ")))
  1034. (modify-frame-parameters (selected-frame)
  1035. (list (cons 'foreground-color color-name)))
  1036. (or window-system
  1037. (face-set-after-frame-default (selected-frame))))
  1038. (defun set-cursor-color (color-name)
  1039. "Set the text cursor color of the selected frame to COLOR-NAME.
  1040. When called interactively, prompt for the name of the color to use.
  1041. This works by setting the `cursor-color' frame parameter on the
  1042. selected frame.
  1043. You can also set the text cursor color, for all frames, by
  1044. customizing the `cursor' face."
  1045. (interactive (list (read-color "Cursor color: ")))
  1046. (modify-frame-parameters (selected-frame)
  1047. (list (cons 'cursor-color color-name))))
  1048. (defun set-mouse-color (color-name)
  1049. "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
  1050. When called interactively, prompt for the name of the color to use.
  1051. To get the frame's current mouse color, use `frame-parameters'."
  1052. (interactive (list (read-color "Mouse color: ")))
  1053. (modify-frame-parameters (selected-frame)
  1054. (list (cons 'mouse-color
  1055. (or color-name
  1056. (cdr (assq 'mouse-color
  1057. (frame-parameters))))))))
  1058. (defun set-border-color (color-name)
  1059. "Set the color of the border of the selected frame to COLOR-NAME.
  1060. When called interactively, prompt for the name of the color to use.
  1061. To get the frame's current border color, use `frame-parameters'."
  1062. (interactive (list (read-color "Border color: ")))
  1063. (modify-frame-parameters (selected-frame)
  1064. (list (cons 'border-color color-name))))
  1065. (define-minor-mode auto-raise-mode
  1066. "Toggle whether or not selected frames should auto-raise.
  1067. With a prefix argument ARG, enable Auto Raise mode if ARG is
  1068. positive, and disable it otherwise. If called from Lisp, enable
  1069. the mode if ARG is omitted or nil.
  1070. Auto Raise mode does nothing under most window managers, which
  1071. switch focus on mouse clicks. It only has an effect if your
  1072. window manager switches focus on mouse movement (in which case
  1073. you should also change `focus-follows-mouse' to t). Then,
  1074. enabling Auto Raise mode causes any graphical Emacs frame which
  1075. acquires focus to be automatically raised.
  1076. Note that this minor mode controls Emacs's own auto-raise
  1077. feature. Window managers that switch focus on mouse movement
  1078. often have their own auto-raise feature."
  1079. :variable (frame-parameter nil 'auto-raise)
  1080. (if (frame-parameter nil 'auto-raise)
  1081. (raise-frame)))
  1082. (define-minor-mode auto-lower-mode
  1083. "Toggle whether or not the selected frame should auto-lower.
  1084. With a prefix argument ARG, enable Auto Lower mode if ARG is
  1085. positive, and disable it otherwise. If called from Lisp, enable
  1086. the mode if ARG is omitted or nil.
  1087. Auto Lower mode does nothing under most window managers, which
  1088. switch focus on mouse clicks. It only has an effect if your
  1089. window manager switches focus on mouse movement (in which case
  1090. you should also change `focus-follows-mouse' to t). Then,
  1091. enabling Auto Lower Mode causes any graphical Emacs frame which
  1092. loses focus to be automatically lowered.
  1093. Note that this minor mode controls Emacs's own auto-lower
  1094. feature. Window managers that switch focus on mouse movement
  1095. often have their own features for raising or lowering frames."
  1096. :variable (frame-parameter nil 'auto-lower))
  1097. (defun set-frame-name (name)
  1098. "Set the name of the selected frame to NAME.
  1099. When called interactively, prompt for the name of the frame.
  1100. The frame name is displayed on the modeline if the terminal displays only
  1101. one frame, otherwise the name is displayed on the frame's caption bar."
  1102. (interactive "sFrame name: ")
  1103. (modify-frame-parameters (selected-frame)
  1104. (list (cons 'name name))))
  1105. (defun frame-current-scroll-bars (&optional frame)
  1106. "Return the current scroll-bar settings in frame FRAME.
  1107. Value is a cons (VERTICAL . HORIZ0NTAL) where VERTICAL specifies the
  1108. current location of the vertical scroll-bars (left, right, or nil),
  1109. and HORIZONTAL specifies the current location of the horizontal scroll
  1110. bars (top, bottom, or nil)."
  1111. (let ((vert (frame-parameter frame 'vertical-scroll-bars))
  1112. (hor nil))
  1113. (unless (memq vert '(left right nil))
  1114. (setq vert default-frame-scroll-bars))
  1115. (cons vert hor)))
  1116. ;;;; Frame/display capabilities.
  1117. (defun selected-terminal ()
  1118. "Return the terminal that is now selected."
  1119. (frame-terminal (selected-frame)))
  1120. (declare-function msdos-mouse-p "dosfns.c")
  1121. (defun display-mouse-p (&optional display)
  1122. "Return non-nil if DISPLAY has a mouse available.
  1123. DISPLAY can be a display name, a frame, or nil (meaning the selected
  1124. frame's display)."
  1125. (let ((frame-type (framep-on-display display)))
  1126. (cond
  1127. ((eq frame-type 'pc)
  1128. (msdos-mouse-p))
  1129. ((eq system-type 'windows-nt)
  1130. (with-no-warnings
  1131. (> w32-num-mouse-buttons 0)))
  1132. ((memq frame-type '(x ns))
  1133. t) ;; We assume X and NeXTstep *always* have a pointing device
  1134. (t
  1135. (or (and (featurep 'xt-mouse)
  1136. xterm-mouse-mode)
  1137. ;; t-mouse is distributed with the GPM package. It doesn't have
  1138. ;; a toggle.
  1139. (featurep 't-mouse))))))
  1140. (defun display-popup-menus-p (&optional display)
  1141. "Return non-nil if popup menus are supported on DISPLAY.
  1142. DISPLAY can be a display name, a frame, or nil (meaning the selected
  1143. frame's display).
  1144. Support for popup menus requires that the mouse be available."
  1145. (and
  1146. (let ((frame-type (framep-on-display display)))
  1147. (memq frame-type '(x w32 pc ns)))
  1148. (display-mouse-p display)))
  1149. (defun display-graphic-p (&optional display)
  1150. "Return non-nil if DISPLAY is a graphic display.
  1151. Graphical displays are those which are capable of displaying several
  1152. frames and several different fonts at once. This is true for displays
  1153. that use a window system such as X, and false for text-only terminals.
  1154. DISPLAY can be a display name, a frame, or nil (meaning the selected
  1155. frame's display)."
  1156. (not (null (memq (framep-on-display display) '(x w32 ns)))))
  1157. (defun display-images-p (&optional display)
  1158. "Return non-nil if DISPLAY can display images.
  1159. DISPLAY can be a display name, a frame, or nil (meaning the selected
  1160. frame's display)."
  1161. (and (display-graphic-p display)
  1162. (fboundp 'image-mask-p)
  1163. (fboundp 'image-size)))
  1164. (defalias 'display-multi-frame-p 'display-graphic-p)
  1165. (defalias 'display-multi-font-p 'display-graphic-p)
  1166. (defun display-selections-p (&optional display)
  1167. "Return non-nil if DISPLAY supports selections.
  1168. A selection is a way to transfer text or other data between programs
  1169. via special system buffers called `selection' or `clipboard'.
  1170. DISPLAY can be a display name, a frame, or nil (meaning the selected
  1171. frame's display)."
  1172. (let ((frame-type (framep-on-display display)))
  1173. (cond
  1174. ((eq frame-type 'pc)
  1175. ;; MS-DOG frames support selections when Emacs runs inside
  1176. ;; the Windows' DOS Box.
  1177. (with-no-warnings
  1178. (not (null dos-windows-version))))
  1179. ((memq frame-type '(x w32 ns))
  1180. t) ;; FIXME?
  1181. (t
  1182. nil))))
  1183. (declare-function x-display-screens "xfns.c" (&optional terminal))
  1184. (defun display-screens (&optional display)
  1185. "Return the number of screens associated with DISPLAY."
  1186. (let ((frame-type (framep-on-display display)))
  1187. (cond
  1188. ((memq frame-type '(x w32 ns))
  1189. (x-display-screens display))
  1190. (t
  1191. 1))))
  1192. (declare-function x-display-pixel-height "xfns.c" (&optional terminal))
  1193. (defun display-pixel-height (&optional display)
  1194. "Return the height of DISPLAY's screen in pixels.
  1195. For character terminals, each character counts as a single pixel."
  1196. (let ((frame-type (framep-on-display display)))
  1197. (cond
  1198. ((memq frame-type '(x w32 ns))
  1199. (x-display-pixel-height display))
  1200. (t
  1201. (frame-height (if (framep display) display (selected-frame)))))))
  1202. (declare-function x-display-pixel-width "xfns.c" (&optional terminal))
  1203. (defun display-pixel-width (&optional display)
  1204. "Return the width of DISPLAY's screen in pixels.
  1205. For character terminals, each character counts as a single pixel."
  1206. (let ((frame-type (framep-on-display display)))
  1207. (cond
  1208. ((memq frame-type '(x w32 ns))
  1209. (x-display-pixel-width display))
  1210. (t
  1211. (frame-width (if (framep display) display (selected-frame)))))))
  1212. (defcustom display-mm-dimensions-alist nil
  1213. "Alist for specifying screen dimensions in millimeters.
  1214. The dimensions will be used for `display-mm-height' and
  1215. `display-mm-width' if defined for the respective display.
  1216. Each element of the alist has the form (display . (width . height)),
  1217. e.g. (\":0.0\" . (287 . 215)).
  1218. If `display' equals t, it specifies dimensions for all graphical
  1219. displays not explicitly specified."
  1220. :version "22.1"
  1221. :type '(alist :key-type (choice (string :tag "Display name")
  1222. (const :tag "Default" t))
  1223. :value-type (cons :tag "Dimensions"
  1224. (integer :tag "Width")
  1225. (integer :tag "Height")))
  1226. :group 'frames)
  1227. (declare-function x-display-mm-height "xfns.c" (&optional terminal))
  1228. (defun display-mm-height (&optional display)
  1229. "Return the height of DISPLAY's screen in millimeters.
  1230. System values can be overridden by `display-mm-dimensions-alist'.
  1231. If the information is unavailable, value is nil."
  1232. (and (memq (framep-on-display display) '(x w32 ns))
  1233. (or (cddr (assoc (or display (frame-parameter nil 'display))
  1234. display-mm-dimensions-alist))
  1235. (cddr (assoc t display-mm-dimensions-alist))
  1236. (x-display-mm-height display))))
  1237. (declare-function x-display-mm-width "xfns.c" (&optional terminal))
  1238. (defun display-mm-width (&optional display)
  1239. "Return the width of DISPLAY's screen in millimeters.
  1240. System values can be overridden by `display-mm-dimensions-alist'.
  1241. If the information is unavailable, value is nil."
  1242. (and (memq (framep-on-display display) '(x w32 ns))
  1243. (or (cadr (assoc (or display (frame-parameter nil 'display))
  1244. display-mm-dimensions-alist))
  1245. (cadr (assoc t display-mm-dimensions-alist))
  1246. (x-display-mm-width display))))
  1247. (declare-function x-display-backing-store "xfns.c" (&optional terminal))
  1248. (defun display-backing-store (&optional display)
  1249. "Return the backing store capability of DISPLAY's screen.
  1250. The value may be `always', `when-mapped', `not-useful', or nil if
  1251. the question is inapplicable to a certain kind of display."
  1252. (let ((frame-type (framep-on-display display)))
  1253. (cond
  1254. ((memq frame-type '(x w32 ns))
  1255. (x-display-backing-store display))
  1256. (t
  1257. 'not-useful))))
  1258. (declare-function x-display-save-under "xfns.c" (&optional terminal))
  1259. (defun display-save-under (&optional display)
  1260. "Return non-nil if DISPLAY's screen supports the SaveUnder feature."
  1261. (let ((frame-type (framep-on-display display)))
  1262. (cond
  1263. ((memq frame-type '(x w32 ns))
  1264. (x-display-save-under display))
  1265. (t
  1266. 'not-useful))))
  1267. (declare-function x-display-planes "xfns.c" (&optional terminal))
  1268. (defun display-planes (&optional display)
  1269. "Return the number of planes supported by DISPLAY."
  1270. (let ((frame-type (framep-on-display display)))
  1271. (cond
  1272. ((memq frame-type '(x w32 ns))
  1273. (x-display-planes display))
  1274. ((eq frame-type 'pc)
  1275. 4)
  1276. (t
  1277. (truncate (log (length (tty-color-alist)) 2))))))
  1278. (declare-function x-display-color-cells "xfns.c" (&optional terminal))
  1279. (defun display-color-cells (&optional display)
  1280. "Return the number of color cells supported by DISPLAY."
  1281. (let ((frame-type (framep-on-display display)))
  1282. (cond
  1283. ((memq frame-type '(x w32 ns))
  1284. (x-display-color-cells display))
  1285. ((eq frame-type 'pc)
  1286. 16)
  1287. (t
  1288. (tty-display-color-cells display)))))
  1289. (declare-function x-display-visual-class "xfns.c" (&optional terminal))
  1290. (defun display-visual-class (&optional display)
  1291. "Return the visual class of DISPLAY.
  1292. The value is one of the symbols `static-gray', `gray-scale',
  1293. `static-color', `pseudo-color', `true-color', or `direct-color'."
  1294. (let ((frame-type (framep-on-display display)))
  1295. (cond
  1296. ((memq frame-type '(x w32 ns))
  1297. (x-display-visual-class display))
  1298. ((and (memq frame-type '(pc t))
  1299. (tty-display-color-p display))
  1300. 'static-color)
  1301. (t
  1302. 'static-gray))))
  1303. ;;;; Frame geometry values
  1304. (defun frame-geom-value-cons (type value &optional frame)
  1305. "Return equivalent geometry value for FRAME as a cons with car `+'.
  1306. A geometry value equivalent to VALUE for FRAME is returned,
  1307. where the value is a cons with car `+', not numeric.
  1308. TYPE is the car of the original geometry spec (TYPE . VALUE).
  1309. It is `top' or `left', depending on which edge VALUE is related to.
  1310. VALUE is the cdr of a frame geometry spec: (left/top . VALUE).
  1311. If VALUE is a number, then it is converted to a cons value, perhaps
  1312. relative to the opposite frame edge from that in the original spec.
  1313. FRAME defaults to the selected frame.
  1314. Examples (measures in pixels) -
  1315. Assuming display height/width=1024, frame height/width=600:
  1316. 300 inside display edge: 300 => (+ 300)
  1317. (+ 300) => (+ 300)
  1318. 300 inside opposite display edge: (- 300) => (+ 124)
  1319. -300 => (+ 124)
  1320. 300 beyond display edge
  1321. (= 724 inside opposite display edge): (+ -300) => (+ -300)
  1322. 300 beyond display edge
  1323. (= 724 inside opposite display edge): (- -300) => (+ 724)
  1324. In the 3rd, 4th, and 6th examples, the returned value is relative to
  1325. the opposite frame edge from the edge indicated in the input spec."
  1326. (cond ((and (consp value) (eq '+ (car value))) ; e.g. (+ 300), (+ -300)
  1327. value)
  1328. ((natnump value) (list '+ value)) ; e.g. 300 => (+ 300)
  1329. (t ; e.g. -300, (- 300), (- -300)
  1330. (list '+ (- (if (eq 'left type) ; => (+ 124), (+ 124), (+ 724)
  1331. (x-display-pixel-width)
  1332. (x-display-pixel-height))
  1333. (if (integerp value) (- value) (cadr value))
  1334. (if (eq 'left type)
  1335. (frame-pixel-width frame)
  1336. (frame-pixel-height frame)))))))
  1337. (defun frame-geom-spec-cons (spec &optional frame)
  1338. "Return equivalent geometry spec for FRAME as a cons with car `+'.
  1339. A geometry specification equivalent to SPEC for FRAME is returned,
  1340. where the value is a cons with car `+', not numeric.
  1341. SPEC is a frame geometry spec: (left . VALUE) or (top . VALUE).
  1342. If VALUE is a number, then it is converted to a cons value, perhaps
  1343. relative to the opposite frame edge from that in the original spec.
  1344. FRAME defaults to the selected frame.
  1345. Examples (measures in pixels) -
  1346. Assuming display height=1024, frame height=600:
  1347. top 300 below display top: (top . 300) => (top + 300)
  1348. (top + 300) => (top + 300)
  1349. bottom 300 above display bottom: (top - 300) => (top + 124)
  1350. (top . -300) => (top + 124)
  1351. top 300 above display top
  1352. (= bottom 724 above display bottom): (top + -300) => (top + -300)
  1353. bottom 300 below display bottom
  1354. (= top 724 below display top): (top - -300) => (top + 724)
  1355. In the 3rd, 4th, and 6th examples, the returned value is relative to
  1356. the opposite frame edge from the edge indicated in the input spec."
  1357. (cons (car spec) (frame-geom-value-cons (car spec) (cdr spec) frame)))
  1358. (defun delete-other-frames (&optional frame)
  1359. "Delete all frames on the current terminal, except FRAME.
  1360. If FRAME uses another frame's minibuffer, the minibuffer frame is
  1361. left untouched. FRAME nil or omitted means use the selected frame."
  1362. (interactive)
  1363. (unless frame
  1364. (setq frame (selected-frame)))
  1365. (let* ((mini-frame (window-frame (minibuffer-window frame)))
  1366. (frames (delq mini-frame (delq frame (frame-list)))))
  1367. ;; Only consider frames on the same terminal.
  1368. (dolist (frame (prog1 frames (setq frames nil)))
  1369. (if (eq (frame-terminal) (frame-terminal frame))
  1370. (push frame frames)))
  1371. ;; Delete mon-minibuffer-only frames first, because `delete-frame'
  1372. ;; signals an error when trying to delete a mini-frame that's
  1373. ;; still in use by another frame.
  1374. (dolist (frame frames)
  1375. (unless (eq (frame-parameter frame 'minibuffer) 'only)
  1376. (delete-frame frame)))
  1377. ;; Delete minibuffer-only frames.
  1378. (dolist (frame frames)
  1379. (when (eq (frame-parameter frame 'minibuffer) 'only)
  1380. (delete-frame frame)))))
  1381. ;; miscellaneous obsolescence declarations
  1382. (define-obsolete-variable-alias 'delete-frame-hook
  1383. 'delete-frame-functions "22.1")
  1384. ;; Highlighting trailing whitespace.
  1385. (make-variable-buffer-local 'show-trailing-whitespace)
  1386. ;; Scrolling
  1387. (defgroup scrolling nil
  1388. "Scrolling windows."
  1389. :version "21.1"
  1390. :group 'frames)
  1391. (defvaralias 'automatic-hscrolling 'auto-hscroll-mode)
  1392. ;; Blinking cursor
  1393. (defgroup cursor nil
  1394. "Displaying text cursors."
  1395. :version "21.1"
  1396. :group 'frames)
  1397. (defcustom blink-cursor-delay 0.5
  1398. "Seconds of idle time after which cursor starts to blink."
  1399. :type 'number
  1400. :group 'cursor)
  1401. (defcustom blink-cursor-interval 0.5
  1402. "Length of cursor blink interval in seconds."
  1403. :type 'number
  1404. :group 'cursor)
  1405. (defvar blink-cursor-idle-timer nil
  1406. "Timer started after `blink-cursor-delay' seconds of Emacs idle time.
  1407. The function `blink-cursor-start' is called when the timer fires.")
  1408. (defvar blink-cursor-timer nil
  1409. "Timer started from `blink-cursor-start'.
  1410. This timer calls `blink-cursor-timer-function' every
  1411. `blink-cursor-interval' seconds.")
  1412. (defun blink-cursor-start ()
  1413. "Timer function called from the timer `blink-cursor-idle-timer'.
  1414. This starts the timer `blink-cursor-timer', which makes the cursor blink
  1415. if appropriate. It also arranges to cancel that timer when the next
  1416. command starts, by installing a pre-command hook."
  1417. (when (null blink-cursor-timer)
  1418. ;; Set up the timer first, so that if this signals an error,
  1419. ;; blink-cursor-end is not added to pre-command-hook.
  1420. (setq blink-cursor-timer
  1421. (run-with-timer blink-cursor-interval blink-cursor-interval
  1422. 'blink-cursor-timer-function))
  1423. (add-hook 'pre-command-hook 'blink-cursor-end)
  1424. (internal-show-cursor nil nil)))
  1425. (defun blink-cursor-timer-function ()
  1426. "Timer function of timer `blink-cursor-timer'."
  1427. (internal-show-cursor nil (not (internal-show-cursor-p))))
  1428. (defun blink-cursor-end ()
  1429. "Stop cursor blinking.
  1430. This is installed as a pre-command hook by `blink-cursor-start'.
  1431. When run, it cancels the timer `blink-cursor-timer' and removes
  1432. itself as a pre-command hook."
  1433. (remove-hook 'pre-command-hook 'blink-cursor-end)
  1434. (internal-show-cursor nil t)
  1435. (when blink-cursor-timer
  1436. (cancel-timer blink-cursor-timer)
  1437. (setq blink-cursor-timer nil)))
  1438. (define-minor-mode blink-cursor-mode
  1439. "Toggle cursor blinking (Blink Cursor mode).
  1440. With a prefix argument ARG, enable Blink Cursor mode if ARG is
  1441. positive, and disable it otherwise. If called from Lisp, enable
  1442. the mode if ARG is omitted or nil.
  1443. This command is effective only on graphical frames. On text-only
  1444. terminals, cursor blinking is controlled by the terminal."
  1445. :init-value (not (or noninteractive
  1446. no-blinking-cursor
  1447. (eq system-type 'ms-dos)
  1448. (not (memq window-system '(x w32 ns)))))
  1449. :initialize 'custom-initialize-delay
  1450. :group 'cursor
  1451. :global t
  1452. (if blink-cursor-idle-timer (cancel-timer blink-cursor-idle-timer))
  1453. (setq blink-cursor-idle-timer nil)
  1454. (blink-cursor-end)
  1455. (when blink-cursor-mode
  1456. ;; Hide the cursor.
  1457. ;;(internal-show-cursor nil nil)
  1458. (setq blink-cursor-idle-timer
  1459. (run-with-idle-timer blink-cursor-delay
  1460. blink-cursor-delay
  1461. 'blink-cursor-start))))
  1462. (define-obsolete-variable-alias 'blink-cursor 'blink-cursor-mode "22.1")
  1463. ;;;; Key bindings
  1464. (define-key ctl-x-5-map "2" 'make-frame-command)
  1465. (define-key ctl-x-5-map "1" 'delete-other-frames)
  1466. (define-key ctl-x-5-map "0" 'delete-frame)
  1467. (define-key ctl-x-5-map "o" 'other-frame)
  1468. (provide 'frame)
  1469. ;;; frame.el ends here