aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2021-04-12 12:32:07 -0400
committerStefan Monnier2021-04-12 12:32:58 -0400
commit9a6523dfd68a17ebf7049d2aae3fd02386d7cb04 (patch)
treeb042b7727c523750edba190343a001d8fe03b881
parented4b51962ea5494b92e0d078916558cab27a836a (diff)
downloademacs-9a6523dfd68a17ebf7049d2aae3fd02386d7cb04.tar.gz
emacs-9a6523dfd68a17ebf7049d2aae3fd02386d7cb04.zip
* lisp/frame.el (delete-other-frames): Add universal prefix `iconify` arg
(frame--current-backround-mode): New function, extracted from `frame-set-background-mode`. Use `color-dark-p`. (frame-set-background-mode): Use it.
-rw-r--r--doc/lispref/frames.texi5
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/frame.el125
3 files changed, 80 insertions, 53 deletions
diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi
index cd2ff8f3b31..a9d20c543da 100644
--- a/doc/lispref/frames.texi
+++ b/doc/lispref/frames.texi
@@ -2628,7 +2628,7 @@ When Emacs gets one of these commands, it generates a
2628@code{delete-frame} event, whose normal definition is a command that 2628@code{delete-frame} event, whose normal definition is a command that
2629calls the function @code{delete-frame}. @xref{Misc Events}. 2629calls the function @code{delete-frame}. @xref{Misc Events}.
2630 2630
2631@deffn Command delete-other-frames &optional frame 2631@deffn Command delete-other-frames &optional frame iconify
2632This command deletes all frames on @var{frame}'s terminal, except 2632This command deletes all frames on @var{frame}'s terminal, except
2633@var{frame}. If @var{frame} uses another frame's minibuffer, that 2633@var{frame}. If @var{frame} uses another frame's minibuffer, that
2634minibuffer frame is left untouched. The argument @var{frame} must 2634minibuffer frame is left untouched. The argument @var{frame} must
@@ -2639,6 +2639,9 @@ this command works by calling @code{delete-frame} with @var{force}
2639This function does not delete any of @var{frame}'s child frames 2639This function does not delete any of @var{frame}'s child frames
2640(@pxref{Child Frames}). If @var{frame} is a child frame, it deletes 2640(@pxref{Child Frames}). If @var{frame} is a child frame, it deletes
2641@var{frame}'s siblings only. 2641@var{frame}'s siblings only.
2642
2643With the prefix argument @var{iconify}, the frames are iconified rather
2644than deleted.
2642@end deffn 2645@end deffn
2643 2646
2644 2647
diff --git a/etc/NEWS b/etc/NEWS
index 88583d952ff..320827d881e 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -276,6 +276,9 @@ input using the minibuffer.
276* Editing Changes in Emacs 28.1 276* Editing Changes in Emacs 28.1
277 277
278+++ 278+++
279** A prefix arg now causes 'delete-other-frames' to only iconify frames
280
281+++
279** New command 'execute-extended-command-for-buffer'. 282** New command 'execute-extended-command-for-buffer'.
280This new command, bound to 'M-S-x', works like 283This new command, bound to 'M-S-x', works like
281'execute-extended-command', but limits the set of commands to the 284'execute-extended-command', but limits the set of commands to the
diff --git a/lisp/frame.el b/lisp/frame.el
index 2b6e4a60b83..bca160175a5 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -301,7 +301,7 @@ This function runs the abnormal hook `move-frame-functions'."
301(declare-function tool-bar-mode "tool-bar" (&optional arg)) 301(declare-function tool-bar-mode "tool-bar" (&optional arg))
302(declare-function tool-bar-height "xdisp.c" (&optional frame pixelwise)) 302(declare-function tool-bar-height "xdisp.c" (&optional frame pixelwise))
303 303
304(defalias 'tool-bar-lines-needed 'tool-bar-height) 304(defalias 'tool-bar-lines-needed #'tool-bar-height)
305 305
306;; startup.el calls this function after loading the user's init 306;; startup.el calls this function after loading the user's init
307;; file. Now default-frame-alist and initial-frame-alist contain 307;; file. Now default-frame-alist and initial-frame-alist contain
@@ -690,8 +690,8 @@ is not considered (see `next-frame')."
690 0)) 690 0))
691 (select-frame-set-input-focus (selected-frame))) 691 (select-frame-set-input-focus (selected-frame)))
692 692
693(defalias 'next-multiframe-window 'next-window-any-frame) 693(defalias 'next-multiframe-window #'next-window-any-frame)
694(defalias 'previous-multiframe-window 'previous-window-any-frame) 694(defalias 'previous-multiframe-window #'previous-window-any-frame)
695 695
696(defun window-system-for-display (display) 696(defun window-system-for-display (display)
697 "Return the window system for DISPLAY. 697 "Return the window system for DISPLAY.
@@ -782,7 +782,7 @@ If DISPLAY is nil, that stands for the selected frame's display."
782 (format "Delete %s frames? " (length frames)) 782 (format "Delete %s frames? " (length frames))
783 (format "Delete %s ? " (car frames)))))) 783 (format "Delete %s ? " (car frames))))))
784 (error "Abort!") 784 (error "Abort!")
785 (mapc 'delete-frame frames) 785 (mapc #'delete-frame frames)
786 (x-close-connection display)))) 786 (x-close-connection display))))
787 787
788(defun make-frame-command () 788(defun make-frame-command ()
@@ -1162,8 +1162,8 @@ e.g. (mapc \\='frame-set-background-mode (frame-list))."
1162 :group 'faces 1162 :group 'faces
1163 :set #'(lambda (var value) 1163 :set #'(lambda (var value)
1164 (set-default var value) 1164 (set-default var value)
1165 (mapc 'frame-set-background-mode (frame-list))) 1165 (mapc #'frame-set-background-mode (frame-list)))
1166 :initialize 'custom-initialize-changed 1166 :initialize #'custom-initialize-changed
1167 :type '(choice (const dark) 1167 :type '(choice (const dark)
1168 (const light) 1168 (const light)
1169 (const :tag "automatic" nil))) 1169 (const :tag "automatic" nil)))
@@ -1176,6 +1176,27 @@ e.g. (mapc \\='frame-set-background-mode (frame-list))."
1176 1176
1177(defvar inhibit-frame-set-background-mode nil) 1177(defvar inhibit-frame-set-background-mode nil)
1178 1178
1179(defun frame--current-backround-mode (frame)
1180 (let* ((frame-default-bg-mode (frame-terminal-default-bg-mode frame))
1181 (bg-color (frame-parameter frame 'background-color))
1182 (tty-type (tty-type frame))
1183 (default-bg-mode
1184 (if (or (window-system frame)
1185 (and tty-type
1186 (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
1187 tty-type)))
1188 'light
1189 'dark)))
1190 (cond (frame-default-bg-mode)
1191 ((equal bg-color "unspecified-fg") ; inverted colors
1192 (if (eq default-bg-mode 'light) 'dark 'light))
1193 ((not (color-values bg-color frame))
1194 default-bg-mode)
1195 ((color-dark-p (mapcar (lambda (c) (/ c 65535.0))
1196 (color-values bg-color frame)))
1197 'dark)
1198 (t 'light))))
1199
1179(defun frame-set-background-mode (frame &optional keep-face-specs) 1200(defun frame-set-background-mode (frame &optional keep-face-specs)
1180 "Set up display-dependent faces on FRAME. 1201 "Set up display-dependent faces on FRAME.
1181Display-dependent faces are those which have different definitions 1202Display-dependent faces are those which have different definitions
@@ -1184,30 +1205,8 @@ according to the `background-mode' and `display-type' frame parameters.
1184If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate 1205If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate
1185face specs for the new background mode." 1206face specs for the new background mode."
1186 (unless inhibit-frame-set-background-mode 1207 (unless inhibit-frame-set-background-mode
1187 (let* ((frame-default-bg-mode (frame-terminal-default-bg-mode frame)) 1208 (let* ((bg-mode
1188 (bg-color (frame-parameter frame 'background-color)) 1209 (frame--current-backround-mode frame))
1189 (tty-type (tty-type frame))
1190 (default-bg-mode
1191 (if (or (window-system frame)
1192 (and tty-type
1193 (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
1194 tty-type)))
1195 'light
1196 'dark))
1197 (non-default-bg-mode (if (eq default-bg-mode 'light) 'dark 'light))
1198 (bg-mode
1199 (cond (frame-default-bg-mode)
1200 ((equal bg-color "unspecified-fg") ; inverted colors
1201 non-default-bg-mode)
1202 ((not (color-values bg-color frame))
1203 default-bg-mode)
1204 ((>= (apply '+ (color-values bg-color frame))
1205 ;; Just looking at the screen, colors whose
1206 ;; values add up to .6 of the white total
1207 ;; still look dark to me.
1208 (* (apply '+ (color-values "white" frame)) .6))
1209 'light)
1210 (t 'dark)))
1211 (display-type 1210 (display-type
1212 (cond ((null (window-system frame)) 1211 (cond ((null (window-system frame))
1213 (if (tty-display-color-p frame) 'color 'mono)) 1212 (if (tty-display-color-p frame) 'color 'mono))
@@ -1273,6 +1272,26 @@ the `background-mode' terminal parameter."
1273 (intern (downcase bg-resource)))) 1272 (intern (downcase bg-resource))))
1274 (terminal-parameter frame 'background-mode))) 1273 (terminal-parameter frame 'background-mode)))
1275 1274
1275;; FIXME: This needs to be significantly improved before we can use it:
1276;; - Fix the "scope" to be consistent: the code below is partly per-frame
1277;; and partly all-frames :-(
1278;; - Make it interact correctly with color themes (e.g. modus-themes).
1279;; Maybe automatically disabling color themes that disagree with the
1280;; selected value of `dark-mode'.
1281;; - Check interaction with "(in|re)verse-video".
1282;;
1283;; (define-minor-mode dark-mode
1284;; "Use light text on dark background."
1285;; :global t
1286;; :group 'faces
1287;; (when (eq dark-mode
1288;; (eq 'light (frame--current-backround-mode (selected-frame))))
1289;; ;; FIXME: Change the face's SPEC instead?
1290;; (set-face-attribute 'default nil
1291;; :foreground (face-attribute 'default :background)
1292;; :background (face-attribute 'default :foreground))
1293;; (frame-set-background-mode (selected-frame))))
1294
1276 1295
1277;;;; Frame configurations 1296;;;; Frame configurations
1278 1297
@@ -1357,9 +1376,9 @@ differing font heights."
1357If FRAME is omitted, describe the currently selected frame." 1376If FRAME is omitted, describe the currently selected frame."
1358 (cdr (assq 'width (frame-parameters frame)))) 1377 (cdr (assq 'width (frame-parameters frame))))
1359 1378
1360(defalias 'frame-border-width 'frame-internal-border-width) 1379(defalias 'frame-border-width #'frame-internal-border-width)
1361(defalias 'frame-pixel-width 'frame-native-width) 1380(defalias 'frame-pixel-width #'frame-native-width)
1362(defalias 'frame-pixel-height 'frame-native-height) 1381(defalias 'frame-pixel-height #'frame-native-height)
1363 1382
1364(defun frame-inner-width (&optional frame) 1383(defun frame-inner-width (&optional frame)
1365 "Return inner width of FRAME in pixels. 1384 "Return inner width of FRAME in pixels.
@@ -1991,9 +2010,9 @@ frame's display)."
1991 (fboundp 'image-mask-p) 2010 (fboundp 'image-mask-p)
1992 (fboundp 'image-size))) 2011 (fboundp 'image-size)))
1993 2012
1994(defalias 'display-blink-cursor-p 'display-graphic-p) 2013(defalias 'display-blink-cursor-p #'display-graphic-p)
1995(defalias 'display-multi-frame-p 'display-graphic-p) 2014(defalias 'display-multi-frame-p #'display-graphic-p)
1996(defalias 'display-multi-font-p 'display-graphic-p) 2015(defalias 'display-multi-font-p #'display-graphic-p)
1997 2016
1998(defun display-selections-p (&optional display) 2017(defun display-selections-p (&optional display)
1999 "Return non-nil if DISPLAY supports selections. 2018 "Return non-nil if DISPLAY supports selections.
@@ -2340,13 +2359,15 @@ In the 3rd, 4th, and 6th examples, the returned value is relative to
2340the opposite frame edge from the edge indicated in the input spec." 2359the opposite frame edge from the edge indicated in the input spec."
2341 (cons (car spec) (frame-geom-value-cons (car spec) (cdr spec) frame))) 2360 (cons (car spec) (frame-geom-value-cons (car spec) (cdr spec) frame)))
2342 2361
2343(defun delete-other-frames (&optional frame) 2362(defun delete-other-frames (&optional frame iconify)
2344 "Delete all frames on FRAME's terminal, except FRAME. 2363 "Delete all frames on FRAME's terminal, except FRAME.
2345If FRAME uses another frame's minibuffer, the minibuffer frame is 2364If FRAME uses another frame's minibuffer, the minibuffer frame is
2346left untouched. Do not delete any of FRAME's child frames. If 2365left untouched. Do not delete any of FRAME's child frames. If
2347FRAME is a child frame, delete its siblings only. FRAME must be 2366FRAME is a child frame, delete its siblings only. FRAME must be
2348a live frame and defaults to the selected one." 2367a live frame and defaults to the selected one.
2349 (interactive) 2368If the prefix arg ICONIFY is non-nil, just iconify the frames rather than
2369deleting them."
2370 (interactive "i\nP")
2350 (setq frame (window-normalize-frame frame)) 2371 (setq frame (window-normalize-frame frame))
2351 (let ((minibuffer-frame (window-frame (minibuffer-window frame))) 2372 (let ((minibuffer-frame (window-frame (minibuffer-window frame)))
2352 (this (next-frame frame t)) 2373 (this (next-frame frame t))
@@ -2361,7 +2382,7 @@ a live frame and defaults to the selected one."
2361 (and parent (not (eq (frame-parent this) parent))) 2382 (and parent (not (eq (frame-parent this) parent)))
2362 ;; Do not delete a child frame of FRAME. 2383 ;; Do not delete a child frame of FRAME.
2363 (eq (frame-parent this) frame)) 2384 (eq (frame-parent this) frame))
2364 (delete-frame this)) 2385 (if iconify (iconify-frame this) (delete-frame this)))
2365 (setq this next)) 2386 (setq this next))
2366 ;; In a second round consider all remaining frames. 2387 ;; In a second round consider all remaining frames.
2367 (setq this (next-frame frame t)) 2388 (setq this (next-frame frame t))
@@ -2373,7 +2394,7 @@ a live frame and defaults to the selected one."
2373 (and parent (not (eq (frame-parent this) parent))) 2394 (and parent (not (eq (frame-parent this) parent)))
2374 ;; Do not delete a child frame of FRAME. 2395 ;; Do not delete a child frame of FRAME.
2375 (eq (frame-parent this) frame)) 2396 (eq (frame-parent this) frame))
2376 (delete-frame this)) 2397 (if iconify (iconify-frame this) (delete-frame this)))
2377 (setq this next)))) 2398 (setq this next))))
2378 2399
2379 2400
@@ -2399,7 +2420,7 @@ parameters `bottom-divider-width' and `right-divider-width'."
2399 :type '(choice (const :tag "Bottom only" bottom-only) 2420 :type '(choice (const :tag "Bottom only" bottom-only)
2400 (const :tag "Right only" right-only) 2421 (const :tag "Right only" right-only)
2401 (const :tag "Bottom and right" t)) 2422 (const :tag "Bottom and right" t))
2402 :initialize 'custom-initialize-default 2423 :initialize #'custom-initialize-default
2403 :set (lambda (symbol value) 2424 :set (lambda (symbol value)
2404 (set-default symbol value) 2425 (set-default symbol value)
2405 (when window-divider-mode 2426 (when window-divider-mode
@@ -2420,7 +2441,7 @@ parameter `bottom-divider-width'."
2420 :type '(restricted-sexp 2441 :type '(restricted-sexp
2421 :tag "Default width of bottom dividers" 2442 :tag "Default width of bottom dividers"
2422 :match-alternatives (window-divider-width-valid-p)) 2443 :match-alternatives (window-divider-width-valid-p))
2423 :initialize 'custom-initialize-default 2444 :initialize #'custom-initialize-default
2424 :set (lambda (symbol value) 2445 :set (lambda (symbol value)
2425 (set-default symbol value) 2446 (set-default symbol value)
2426 (when window-divider-mode 2447 (when window-divider-mode
@@ -2437,7 +2458,7 @@ parameter `right-divider-width'."
2437 :type '(restricted-sexp 2458 :type '(restricted-sexp
2438 :tag "Default width of right dividers" 2459 :tag "Default width of right dividers"
2439 :match-alternatives (window-divider-width-valid-p)) 2460 :match-alternatives (window-divider-width-valid-p))
2440 :initialize 'custom-initialize-default 2461 :initialize #'custom-initialize-default
2441 :set (lambda (symbol value) 2462 :set (lambda (symbol value)
2442 (set-default symbol value) 2463 (set-default symbol value)
2443 (when window-divider-mode 2464 (when window-divider-mode
@@ -2714,14 +2735,14 @@ See also `toggle-frame-maximized'."
2714 2735
2715;;;; Key bindings 2736;;;; Key bindings
2716 2737
2717(define-key ctl-x-5-map "2" 'make-frame-command) 2738(define-key ctl-x-5-map "2" #'make-frame-command)
2718(define-key ctl-x-5-map "1" 'delete-other-frames) 2739(define-key ctl-x-5-map "1" #'delete-other-frames)
2719(define-key ctl-x-5-map "0" 'delete-frame) 2740(define-key ctl-x-5-map "0" #'delete-frame)
2720(define-key ctl-x-5-map "o" 'other-frame) 2741(define-key ctl-x-5-map "o" #'other-frame)
2721(define-key ctl-x-5-map "5" 'other-frame-prefix) 2742(define-key ctl-x-5-map "5" #'other-frame-prefix)
2722(define-key global-map [f11] 'toggle-frame-fullscreen) 2743(define-key global-map [f11] #'toggle-frame-fullscreen)
2723(define-key global-map [(meta f10)] 'toggle-frame-maximized) 2744(define-key global-map [(meta f10)] #'toggle-frame-maximized)
2724(define-key esc-map [f10] 'toggle-frame-maximized) 2745(define-key esc-map [f10] #'toggle-frame-maximized)
2725 2746
2726 2747
2727;; Misc. 2748;; Misc.