-
Notifications
You must be signed in to change notification settings - Fork 22
/
frame-cmds.el
2063 lines (1915 loc) · 97.4 KB
/
frame-cmds.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; frame-cmds.el --- Frame and window commands (interactive functions).
;;
;; Filename: frame-cmds.el
;; Description: Frame and window commands (interactive functions).
;; Author: Drew Adams
;; Maintainer: Drew Adams (concat "drew.adams" "@" "oracle" ".com")
;; Copyright (C) 1996-2018, Drew Adams, all rights reserved.
;; Created: Tue Mar 5 16:30:45 1996
;; Version: 0
;; Package-Requires: ((frame-fns "0"))
;; Last-Updated: Thu Jul 19 07:14:42 2018 (-0700)
;; By: dradams
;; Update #: 3121
;; URL: https://www.emacswiki.org/emacs/download/frame-cmds.el
;; Doc URL: https://emacswiki.org/emacs/FrameModes
;; Doc URL: https://www.emacswiki.org/emacs/OneOnOneEmacs
;; Doc URL: https://www.emacswiki.org/emacs/Frame_Tiling_Commands
;; Keywords: internal, extensions, mouse, frames, windows, convenience
;; Compatibility: GNU Emacs: 20.x, 21.x, 22.x, 23.x, 24.x, 25.x, 26.x
;;
;; Features that might be required by this library:
;;
;; `avoid', `frame-fns', `misc-fns', `strings', `thingatpt',
;; `thingatpt+'.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; Frame and window commands (interactive functions).
;;
;;
;; Summary:
;;
;; Load this library from your init file (~/.emacs or _emacs).
;; Add the suggested key bindings (below) to your init file.
;; Use `M-up|down|left|right' to move frames around incrementally.
;; Use `C-S-v', `M-S-v', `C-S-next', `C-S-prior' to move frames to screen edges.
;; Use `C-M-up|down|left|right' to resize frames incrementally.
;; Use `C-M-z' or `C-x C-z' to iconify/hide all frames.
;; Use `C-M-z' in a lone frame to restore all frames.
;; Use `C-mouse-1' in the minibuffer to restore all frames.
;; Use `C-mouse-1' in Dired to mark/unmark a file.
;; Use `C-mouse-3' on the mode line to remove window from frame.
;; Use `tile-frames-horizontally', `-vertically' to tile frames.
;; Use `C-x o' to select `other-window' or `other-frame'.
;;
;; Commands to incrementally resize frames are `enlarge-frame' and
;; `enlarge-frame-horizontally'. Sarir Khamsi
;; [[email protected]] originally wrote `enlarge-frame',
;; which he called `sk-grow-frame'.
;;
;; Note on saving changes made with the commands defined here:
;;
;; Some of the commands defined here change frame properties.
;; You can save any changes you have made, by using Customize.
;; To visit a Customize buffer of all unsaved changes you have
;; made, use command `customize-customized'.
;;
;; Frame parameter changes, such as background color, can be saved
;; for future use by all frames or all frames of a certain
;; kind. For that, you must change the frame parameters of the
;; correponding frame-alist variable.
;;
;; There is no single variable for saving changes to parameters of
;; the current frame. Instead, there are several different
;; frame-alist variables, which you can use to define different
;; kinds of frames. These include: `default-frame-alist',
;; `initial-frame-alist', and `special-display-frame-alist'. The
;; complete list of such frame alist variables is available using
;; function `frame-alist-var-names', defined here.
;;
;; Example: Suppose you change the background color of a frame and
;; want to make that the default background color for new frames in
;; the future. You will need to update the value of variable
;; `default-frame-alist' to use the `background-color' parameter
;; setting of the changed frame.
;;
;; You can easily copy one or all parameter values from any given
;; frame to any frame alist (such as `default-frame-alist'), by
;; using the commands `set-frame-alist-parameter-from-frame' and
;; `set-all-frame-alist-parameters-from-frame'. Those commands are
;; defined here.
;;
;; NOTE: If you also use library `fit-frame.el', and you are on MS
;; Windows, then load that library before `frame-cmds.el'. The
;; commands `maximize-frame' and `restore-frame' defined here are
;; more general and non-Windows-specific than the commands of the
;; same name defined in `fit-frame.el'.
;;
;;
;; User options defined here:
;;
;; `available-screen-pixel-bounds', `enlarge-font-tries',
;; `frame-config-register', `frame-parameters-to-exclude',
;; `move-frame-wrap-within-display-flag'
;; `rename-frame-when-iconify-flag', `show-hide-show-function',
;; `window-mgr-title-bar-pixel-height'.
;;
;; Commands defined here:
;;
;; `create-frame-tiled-horizontally',
;; `create-frame-tiled-vertically', `decrease-frame-transparency'
;; (Emacs 23+), `delete-1-window-frames-on',
;; `delete/iconify-window', `delete/iconify-windows-on',
;; `delete-other-frames', `delete-windows-for', `enlarge-font',
;; `enlarge-frame', `enlarge-frame-horizontally',
;; `hide-everything', `hide-frame', `iconify-everything',
;; `iconify/map-frame', `iconify/show-frame',
;; `increase-frame-transparency' (Emacs 23+),
;; `jump-to-frame-config-register', `maximize-frame',
;; `maximize-frame-horizontally', `maximize-frame-vertically',
;; `mouse-iconify/map-frame', `mouse-iconify/show-frame',
;; `mouse-remove-window', `mouse-show-hide-mark-unmark',
;; `move-frame-down', `move-frame-left', `move-frame-right',
;; `move-frame-to-screen-bottom', `move-frame-to-screen-left',
;; `move-frame-to-screen-right', `move-frame-to-screen-top',
;; `move-frame-to-screen-top-left', `move-frame-up',
;; `name-all-frames-numerically', `name-frame-numerically',
;; `other-window-or-frame', `remove-window', `remove-windows-on',
;; `rename-frame', `rename-non-minibuffer-frame', `restore-frame',
;; `restore-frame-horizontally', `restore-frame-vertically',
;; `save-frame-config',
;; `set-all-frame-alist-parameters-from-frame',
;; `set-frame-alist-parameter-from-frame', `show-*Help*-buffer',
;; `show-a-frame-on', `show-buffer-menu', `show-frame',
;; `show-hide', `shrink-frame', `shrink-frame-horizontally',
;; `split-frame-horizontally', `split-frame-vertically',
;; `tear-off-window', `tear-off-window-if-not-alone',
;; `tell-customize-var-has-changed', `tile-frames',
;; `tile-frames-horizontally', `tile-frames-side-by-side',
;; `tile-frames-top-to-bottom', `tile-frames-vertically',
;; `toggle-max-frame', `toggle-max-frame-horizontally',
;; `toggle-max-frame-vertically'.
;;
;; Non-interactive functions defined here:
;;
;; `assq-delete-all' (Emacs 20), `butlast' (Emacs 20),
;; `frcmds-available-screen-pixel-bounds',
;; `frcmds-available-screen-pixel-height',
;; `frcmds-available-screen-pixel-width',
;; `frcmds-effective-screen-pixel-bounds',
;; `frcmds-enlarged-font-name', `frcmds-extra-pixels-width',
;; `frcmds-extra-pixels-height', `frcmds-frame-alist-var-names',
;; `frcmds-frame-parameter-names', `frcmds-frame-iconified-p',
;; `frcmds-frame-number', `frcmds-new-frame-position',
;; `frcmds-read-args-for-tiling',
;; `frcmds-read-buffer-for-delete-windows',
;; `frcmds-set-difference', `frcmds-smart-tool-bar-pixel-height',
;; `frcmds-split-frame-1', `frcmds-tile-frames', `nbutlast' (Emacs
;; 20).
;;
;; Error symbols defined here:
;;
;; `font-too-small', `font-size'.
;;
;;
;; ***** NOTE: The following EMACS PRIMITIVE has been ADVISED HERE:
;;
;; `delete-window' - If only one window in frame, `delete-frame'.
;;
;;
;; ***** NOTE: The following EMACS PRIMITIVE has been REDEFINED HERE:
;;
;; `delete-windows-on' -
;; 1) Reads buffer differently. Only buffers showing windows are candidates.
;; 2) Calls `delete-window', so this also deletes frames where
;; window showing the BUFFER is the only window.
;; (That's true also for vanilla Emacs 23+, but not before.)
;;
;;
;; Suggested key bindings:
;;
;; (global-set-key [(meta up)] 'move-frame-up)
;; (global-set-key [(meta down)] 'move-frame-down)
;; (global-set-key [(meta left)] 'move-frame-left)
;; (global-set-key [(meta right)] 'move-frame-right)
;; (global-set-key [(meta shift ?v)] 'move-frame-to-screen-top) ; like `M-v'
;; (global-set-key [(control shift ?v)] 'move-frame-to-screen-bottom) ; like `C-v'
;; (global-set-key [(control shift prior)] 'move-frame-to-screen-left) ; like `C-prior'
;; (global-set-key [(control shift next)] 'move-frame-to-screen-right) ; like `C-next'
;; (global-set-key [(control shift home)] 'move-frame-to-screen-top-left)
;; (global-set-key [(control meta down)] 'enlarge-frame)
;; (global-set-key [(control meta right)] 'enlarge-frame-horizontally)
;; (global-set-key [(control meta up)] 'shrink-frame)
;; (global-set-key [(control meta left)] 'shrink-frame-horizontally)
;; (global-set-key (kbd "C-M-S-<down>") 'increase-frame-transparency)
;; (global-set-key (kbd "C-M-S-<up>") 'decrease-frame-transparency)
;; (global-set-key [(control ?x) (control ?z)] 'iconify-everything)
;; (global-set-key [vertical-line S-down-mouse-1] 'iconify-everything)
;; (global-set-key [(control ?z)] 'iconify/show-frame)
;; (global-set-key [mode-line mouse-3] 'mouse-iconify/show-frame)
;; (global-set-key [mode-line C-mouse-3] 'mouse-remove-window)
;; (global-set-key [(control meta ?z)] 'show-hide)
;; (global-set-key [vertical-line C-down-mouse-1] 'show-hide)
;; (global-set-key [C-down-mouse-1] 'mouse-show-hide-mark-unmark)
;; (substitute-key-definition 'delete-window 'remove-window global-map)
;; (define-key ctl-x-map "o" 'other-window-or-frame)
;; (define-key ctl-x-4-map "1" 'delete-other-frames)
;; (define-key ctl-x-5-map "1" 'tear-off-window)
;; (define-key ctl-x-5-map "h" 'show-*Help*-buffer)
;; (substitute-key-definition 'delete-window 'delete-windows-for global-map)
;; (define-key global-map "\C-xt." 'save-frame-config)
;; (define-key ctl-x-map "o" 'other-window-or-frame)
;;
;; (defalias 'doremi-prefix (make-sparse-keymap))
;; (defvar doremi-map (symbol-function 'doremi-prefix) "Keymap for Do Re Mi commands.")
;; (define-key global-map "\C-xt" 'doremi-prefix)
;; (define-key doremi-map "." 'save-frame-config)
;;
;; Customize the menu. Uncomment this to try it out.
;;
;; (defvar menu-bar-frames-menu (make-sparse-keymap "Frames"))
;; (define-key global-map [menu-bar frames]
;; (cons "Frames" menu-bar-frames-menu)))
;; (define-key menu-bar-frames-menu [set-all-params-from-frame]
;; '(menu-item "Set All Frame Parameters from Frame" set-all-frame-alist-parameters-from-frame
;; :help "Set frame parameters of a frame to their current values in frame"))
;; (define-key menu-bar-frames-menu [set-params-from-frame]
;; '(menu-item "Set Frame Parameter from Frame..." set-frame-alist-parameter-from-frame
;; :help "Set parameter of a frame alist to its current value in frame"))
;; (define-key menu-bar-frames-menu [separator-frame-1] '("--"))
;; (define-key menu-bar-frames-menu [tile-frames-vertically]
;; '(menu-item "Tile Frames Vertically..." tile-frames-vertically
;; :help "Tile all visible frames vertically"))
;; (define-key menu-bar-frames-menu [tile-frames-horizontally]
;; '(menu-item "Tile Frames Horizontally..." tile-frames-horizontally
;; :help "Tile all visible frames horizontally"))
;; (define-key menu-bar-frames-menu [separator-frame-2] '("--"))
;; (define-key menu-bar-frames-menu [toggle-max-frame-vertically]
;; '(menu-item "Toggle Max Frame Vertically" toggle-max-frame-vertically
;; :help "Maximize or restore the selected frame vertically"
;; :enable (frame-parameter nil 'restore-height)))
;; (define-key menu-bar-frames-menu [toggle-max-frame-horizontally]
;; '(menu-item "Toggle Max Frame Horizontally" toggle-max-frame-horizontally
;; :help "Maximize or restore the selected frame horizontally"
;; :enable (frame-parameter nil 'restore-width)))
;; (define-key menu-bar-frames-menu [toggle-max-frame]
;; '(menu-item "Toggle Max Frame" toggle-max-frame
;; :help "Maximize or restore the selected frame (in both directions)"
;; :enable (or (frame-parameter nil 'restore-width) (frame-parameter nil 'restore-height))))
;; (define-key menu-bar-frames-menu [maximize-frame-vertically]
;; '(menu-item "Maximize Frame Vertically" maximize-frame-vertically
;; :help "Maximize the selected frame vertically"))
;; (define-key menu-bar-frames-menu [maximize-frame-horizontally]
;; '(menu-item "Maximize Frame Horizontally" maximize-frame-horizontally
;; :help "Maximize the selected frame horizontally"))
;; (define-key menu-bar-frames-menu [maximize-frame]
;; '(menu-item "Maximize Frame" maximize-frame
;; :help "Maximize the selected frame (in both directions)"))
;; (define-key menu-bar-frames-menu [separator-frame-3] '("--"))
;; (define-key menu-bar-frames-menu [iconify-everything]
;; '(menu-item "Iconify All Frames" iconify-everything
;; :help "Iconify all frames of session at once"))
;; (define-key menu-bar-frames-menu [show-hide]
;; '(menu-item "Hide Frames / Show Buffers" show-hide
;; :help "Show, if only one frame visible; else hide.")))
;;
;; (defvar menu-bar-doremi-menu (make-sparse-keymap "Do Re Mi"))
;; (define-key global-map [menu-bar doremi]
;; (cons "Do Re Mi" menu-bar-doremi-menu))
;; (define-key menu-bar-doremi-menu [doremi-push-current-frame-config]
;; '("Save Frame Configuration" . save-frame-config))
;;
;; See also these files for other frame commands:
;;
;; `autofit-frame.el' - Automatically fit each frame to its
;; selected window. Uses `fit-frame.el'.
;;
;; `fit-frame.el' - 1) Fit a frame to its selected window.
;; 2) Incrementally resize a frame.
;;
;; `doremi-frm.el' - Incrementally adjust frame properties
;; using arrow keys and/or mouse wheel.
;;
;; `thumb-frm.el' - Shrink frames to a thumbnail size and
;; restore them again.
;;
;; `zoom-frm.el' - Zoom a frame or buffer, so that its text
;; appears larger or smaller.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change Log:
;;
;; 2018/01/05 dadams
;; frcmds-available-screen-pixel-bounds:
;; Use display-monitor-attributes-list to compute, if option is nil.
;; frcmds-new-frame-position: Correct for use with multiple monitors.
;; 2018/01/02 dadams
;; available-screen-pixel-bounds: Change :type to allow nil.
;; 2017/10/22 dadams
;; remove-windows-on: Added optional arg ALL-FRAMES.
;; Just repeat get-buffer-window with ALL-FRAMES until no window.
;; delete/iconify-windows-on: Removed second arg to frames-on.
;; 2017/08/19 dadams
;; delete-window: Use with-selected-window for Emacs 22+.
;; Updated Emacs-Wiki URLs.
;; 2017/05/06 dadams
;; maximize-frame: Sidestep nil frame parameters.
;; 2017/02/07 dadams
;; Added decrease-frame-transparency, increase-frame-transparency. Suggest bind to C-M-up|down.
;; 2016/01/24 dadams
;; Added: tear-off-window, tear-off-window-if-not-alone.
;; 2015/08/14 dadams
;; tell-customize-var-has-changed: Use symbol-value, not eval.
;; 2014/12/09 dadams
;; Added: frcmds-frame-pixel-height.
;; frcmds-split-frame-1: Use frame-pixel-width and frcmds-frame-pixel-height, instead of working
;; with width and height frame parameters (char-based).
;; frcmds-tile-frames:
;; If Emacs 24.4+, use PIXELWISE arg with set-frame-size.
;; Otherwise: * Always subtract frcmds-extra-pixels-width.
;; * Do not subtract borders.
;; * Increment origin by one border-width.
;; 2014/12/07 dadams
;; Added: split-frame-horizontally, split-frame-vertically.
;; frcmds-tile-frames: Added optional args, so can tile within a rectangle.
;; create-frame-tiled-(horizontally|vertically): Keep same font size.
;; 2014/12/06 dadams
;; Added: create-frame-tiled-horizontally, create-frame-tiled-vertically.
;; Added aliases: tile-frames-side-by-side, tile-frames-top-to-bottom.
;; window-mgr-title-bar-pixel-height: Changed default value for ns to 50. Thx to Nate Eagleson.
;; 2014/10/15 dadams
;; window-mgr-title-bar-pixel-height: Added default value for ns (Next). Thx to Nate Eagleson.
;; 2014/10/13 dadams
;; Removed extra, empty Package-Requires.
;; 2014/07/21 dadams
;; Do not redefine delete-window - just advise it.
;; delete/iconify-window: Just use delete-window, not old-delete-window.
;; 2014/04/19 dadams
;; Added: frcmds-frame-number, name-all-frames-numerically, name-frame-numerically.
;; Renamed: available-screen-pixel-* to frcmds-available-screen-pixel-*,
;; enlarged-font-name to frcmds-enlarged-font-name,
;; extra-pixels-* to frcmds-extra-pixels-*,
;; frame-alist-var-names to frcmds-frame-alist-var-names,
;; frame-parameter-names to frcmds-frame-parameter-names,
;; frame-iconified-p to frcmds-frame-iconified-p,
;; new-frame-position to frcmds-new-frame-position,
;; read-args-for-tile-frames to frcmds-read-args-for-tiling,
;; read-buffer-for-delete-windows to frcmds-read-buffer-for-delete-windows,
;; frame-cmds-set-difference to frcmds-set-difference,
;; smart-tool-bar-pixel-height to frcmds-smart-tool-bar-pixel-height,
;; tile-frames to frcmds-tile-frames.
;; rename-non-minibuffer-frame: Pass OLD-NAME and NEW-NAME to rename-frame.
;; Group Frame-Commands: Added :prefix frcmds-.
;;
;; 2014/02/24 dadams
;; rename-frame, rename-non-minibuffer-frame: Fixed default buffer name for non-interactive.
;; 2013/09/21 dadams
;; maximize-frame: Apply frame-geom-value-numeric to new-* also. Bug report thx: Mike Fitzgerald.
;; 2013/07/21 dadams
;; Added Package-Requires to header, at least temporarily, but should not need to specify version.
;; 2013/07/12 dadams
;; set-frame-alist-parameter-from-frame: Use lax completion, so do not limit to known parameters.
;; frame-parameter-names: Updated for Emacs 24.
;; 2013/07/05 dadams
;; Added: move-frame-to-screen-top-left.
;; move-frame-to-screen-*: Read FRAME name in interactive spec.
;; 2013/07/04 dadams
;; show-hide-show-function: Use function-item instead of const for jump-to-frame-config-register.
;; 2013/05/15 dadams
;; Added error symbols font-too-small and font-size.
;; enlarged-font-name: Signal font-too-small error.
;; 2013/04/29 dadams
;; Added: deiconify-everything, (mouse-)iconify/show-frame (renamed (mouse-)iconify/map-frame).
;; iconify/show-frame: Negative prefix arg now deiconifies all.
;; 2013/03/12 dadams
;; maximize-frame: Corrected new-left, new-top.
;; Corrected arg to modify-frame-parameters - use frame-geom-value-numeric
;; Do not alias if function name is already fboundp.
;; toggle-max-frame-*: Use toggle-max-frame, not restore-frame (the alias).
;; toggle-max-frame: If no restore-* parameter then first maximize.
;; Condition last four parameters on orig-*, not restore-*.
;; 2013/02/06 dadams
;; move-frame-(up|down|left|right): Set N to 1 if nil.
;; 2013/01/17 dadams
;; Added: move-frame-to-screen-(top|bottom|left|right).
;; move-frame-(up|down|left|right): Redefined so prefix arg moves increments of char size.
;; 2012/02/29 dadams
;; Added, for Emacs 20 only: nbutlast, butlast. To avoid runtime load of cl.el.
;; Added frame-cmds-set-difference, to avoid runtime load of cl.el.
;; set-all-frame-alist-parameters-from-frame: Use frame-cmds-set-difference.
;; 2011/07/25 dadams
;; save-frame-config: Use fboundp, not featurep.
;; 2011/01/04 dadams
;; Removed autoload cookie from non-interactive function.
;; 2010/10/19 dadams
;; enlarge-font: Only do frame-update-faces if Emacs 20 (obsolete in 21).
;; 2010/06/04 dadams
;; Added: (toggle-max|restore)-frame(-horizontally|-vertically). Thx to Uday Reddy for suggestion.
;; Renamed max-frame to maximize-frame.
;; maximize-frame: Save original location & position params for later restoration.
;; 2010/05/25 dadams
;; Added: max-frame, maximize-frame-horizontally, maximize-frame-vertically.
;; 2009/10/02 dadams
;; delete-windows-on: Return nil. Make BUFFER optional: default is current buffer.
;; 2009/08/03 dadams
;; delete-window: Wrap with save-current-buffer. Thx to Larry Denenberg.
;; 2009/05/17 dadams
;; Updated to reflect thumb-frm.el name changes.
;; 2009/01/30 dadams
;; enlarge-font, enlarged-font-name, enlarge-font-tries:
;; Removed temporary workaround - Emacs 23 bug #119 was finally fixed.
;; 2009/01/01 dadams
;; Removed compile-time require of doremi-frm.el to avoid infinite recursion.
;; 2008/12/13 dadams
;; enlarge-font: Redefined for Emacs 23 - just use :height face attribute.
;; enlarge-font-tries, enlarged-font-name: Not used for Emacs 23.
;; 2008/10/31 dadams
;; Updated frame-parameter-names for Emacs 23.
;; 2008/07/29 dadams
;; Option available-screen-pixel-bounds: Use nil as default value.
;; available-screen-pixel-bounds: Redefined as the code that defined the option's default value.
;; Added: effective-screen-pixel-bounds - code taken from old available-screen-pixel-bounds,
;; but also convert frame geom value to numeric.
;; Everywhere:
;; Use effective-screen-pixel-bounds in place of available-screen-pixel-bounds function.
;; Use available-screen-pixel-bounds function instead of option.
;; available-screen-pixel-(width|height): Added optional INCLUDE-MINI-P arg.
;; new-frame-position: Call available-screen-pixel-(width|height) with arg.
;; save-frame-config: push-current-frame-config -> doremi-push-current-frame-config.
;; Soft-require doremi-frm.el when byte-compile.
;; 2008/06/02 dadams
;; Added: available-screen-pixel-bounds (option and function).
;; tile-frames, available-screen-pixel-(width|height):
;; Redefined to use available-screen-pixel-bounds. Thx to Nathaniel Cunningham for input.
;; 2008/05/29 dadams
;; Fixes for Mac by Nathaniel Cunningham and David Reitter:
;; window-mgr-title-bar-pixel-height, tile-frames, smart-tool-bar-pixel-height (added).
;; 2007/12/27 dadams
;; tile-frames: Restored border calculation, but using only external border.
;; Renamed window-mgr-*-width to window-mgr-*-height and changed default value from 32 to 27.
;; 2007/12/20 dadams
;; Added: frame-extra-pixels(width|height). Use in tile-frames. Thx to David Reitter.
;; frame-horizontal-extra-pixels: Changed default value from 30 to 32.
;; 2007/10/11 dadams
;; Added: assq-delete-all (for Emacs 20).
;; 2007/09/02 dadams
;; Added: available-screen-pixel-(width|height). Use in tile-frames, new-frame-position.
;; 2007/06/12 dadams
;; tile-frames: Corrected use of fboundp for thumbnail-frame-p.
;; 2007/05/27 dadams
;; enlarged-font-name:
;; Do nothing if null assq of ascii. Not sure what this means, but gets around Emacs 23 bug.
;; 2006/08/22 dadams
;; Added: delete-windows-for, read-buffer-for-delete-windows.
;; delete-windows-on: Use read-buffer-for-delete-windows.
;; Removed old-delete-windows-on (not used).
;; 2006/05/30 dadams
;; delete-windows-on: Return nil if buffer arg is nil. Thanks to Slawomir Nowaczyk.
;; 2006/01/07 dadams
;; Added :link for sending bug report.
;; 2006/01/06 dadams
;; Renamed group. Added :link.
;; 2006/01/04 dadams
;; Added: other-window-or-frame.
;; 2005/12/29 dadams
;; mouse-show-hide-mark-unmark: dired-mouse-mark/unmark -> diredp-mouse-mark/unmark.
;; 2005/12/13 dadams
;; Added: delete-other-frames.
;; 2005/11/18 dadams
;; enlarge-font: Try to increment or decrment further, testing for an existing font.
;; Added: enlarge-font-tries, enlarged-font-name.
;; 2005/10/03 dadams
;; Removed require of icomplete+.el (no longer redefines read-from-minibuffer).
;; 2005/07/03 dadams
;; Renamed: args-for-tile-frames to read-args-for-tile-frames.
;; 2005/06/19 dadams
;; tile-frames: Don't tile thumbnail frames.
;; 2005/05/29 dadams
;; Moved here from frame+.el and fit-frame.el: enlarge-frame*, shrink-frame*.
;; Added: move-frame-up|down|left|right, move-frame-wrap-within-display-flag,
;; new-frame-position.
;; 2005/05/28 dadams
;; show-a-frame-on: Use another-buffer as default for read-buffer, if available.
;; 2005/05/15 dadams
;; Renamed: minibuffer-frame to 1on1-minibuffer-frame.
;; 2005/05/10 dadams
;; remove-window: Removed definition; just defalias it to delete-window.
;; delete-window: (one-window-p) -> (one-window-p t).
;; set-frame-alist-parameter-from-frame: No longer use destructive fns.
;; 2005/01/19 dadams
;; set-all-frame-alist-parameters-from-frame:
;; Added really-all-p and use frame-parameters-to-exclude.
;; Added: frame-parameters-to-exclude, tell-customize-var-has-changed.
;; 2005/01/18 dadams
;; Added: set-all-frame-alist-parameters-from-frame, set-frame-alist-parameter-from-frame,
;; frame-alist-var-names, frame-parameter-names.
;; Added Note on saving changes.
;; 2005/01/08 dadams
;; Moved enlarge-font here from doremi-frm.el, where it was called doremi-grow-font.
;; 2005/01/04 dadams
;; Added rename-frame-when-iconify-flag.
;; Use it in iconify-everything, (mouse-)iconify/map-frame.
;; Added (defgroup frame-cmds).
;; 2004/12/23 dadams
;; frame-config-register, show-hide-show-function, window-mgr-title-bar-pixel-width:
;; Changed defvar to defcustom.
;; 2004/12/21 dadams
;; hide-everything, iconify-everything: bind thumbify-instead-of-iconify-flag to nil.
;; 2004/12/10 dadams
;; tile-frames: Change 15 to (frame-char-height fr) for scroll-bar-width.
;; tile-frames-*: Corrected doc strings for non-interactive case.
;; 2004/12/09 dadams
;; Changed compile-time require of strings to a soft require.
;; 2004/10/11 dadams
;; args-for-tile-frames: Fixed bug when non-existant frame in name history.
;; tile-frames: show-frame at end (for case where use prefix arg)
;; 2004/09/11 dadams
;; Moved to doremi-frm.el: frame-config-ring*, frame-config-wo-parameters,
;; push-frame-config.
;; 2004/09/07 dadams
;; Added: jump-to-frame-config-register, push-frame-config, save-frame-config.
;; 2004/09/01 dadams
;; Added: frame-config-register, show-hide-show-function,
;; jump-to-frame-config-register.
;; Rewrote to record frame config: iconify-everything, hide-everything.
;; Rewrote to use show-hide-show-function: show-hide.
;; 2004/03/22 dadams
;; Added: tile-frames, tile-frames-vertically, args-for-tile-frames.
;; Rewrote tile-frames-horizontally to use tile-frames.
;; 2004/03/19 dadams
;; Added tile-frames-horizontally.
;; 2000/11/27 dadams
;; hide-frame: fixed bug: Added get-a-frame for frame name read.
;; 2000/09/27 dadams
;; 1. Added: frame-iconified-p.
;; 2. remove-window: only make-frame-invisible if not iconified (HACK).
;; 1999/10/05 dadams
;; rename-frame: fixed bug if only 1 frame and old-name was a frame.
;; 1999/08/25 dadams
;; Added: hide-everything, show-buffer-menu, show-hide.
;; 1999/03/17 dadams
;; delete-1-window-frames-on: ensure a buffer object (not a name).
;; 1996/04/26 dadams
;; delete/iconify-windows-on, show-a-frame-on: Do nothing if null buffer.
;; 1996/03/12 dadams
;; delete/iconify-window: Unless one-window-p, do old-delete-window outside of
;; save-window-excursion.
;; 1996/03/08 dadams
;; 1. delete-windows-on: a. Fixed incorrect interactive spec (bad paren).
;; b. Second arg FRAME also provided interactively now.
;; 2. Added: delete/iconify-window, delete/iconify-windows-on.
;; 1996/02/27 dadams
;; show-frame: Call make-frame-visible.
;; 1996/02/09 dadams
;; Added show-*Help*-buffer.
;; 1996/01/30 dadams
;; 1. show-frame: Don't make-frame-visible. Done by raise-frame anyway.
;; 2. Added show-a-frame-on.
;; 1996/01/09 dadams
;; Added delete-windows-on and made it interactive.
;; 1996/01/08 dadams
;; Added rename-non-minibuffer-frame. Use in iconify-everything,
;; iconify/map-frame, mouse-iconify/map-frame.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:
(eval-when-compile (require 'cl)) ;; case, incf (plus, for Emacs 20: dolist, dotimes)
(require 'frame-fns) ;; frame-geom-value-cons, frame-geom-value-numeric, frames-on, get-frame-name,
;; get-a-frame, read-frame
(require 'strings nil t) ;; (no error if not found) read-buffer
(require 'misc-fns nil t) ;; (no error if not found) another-buffer
;; Don't require even to byte-compile, because doremi-frm.el soft-requires frame-cmds.el
;; (eval-when-compile (require 'doremi-frm nil t)) ;; (no error if not found)
;; ;; doremi-push-current-frame-config
;; Not required here, because this library requires `frame-cmds.el': `thumb-frm.el'.
;; However, `frame-cmds.el' soft-uses `thumfr-thumbnail-frame-p', which is defined
;; in `thumb-frm.el'.
;; Quiet byte-compiler.
(defvar 1on1-minibuffer-frame) ; In `oneonone.el'
(defvar frame-alpha-lower-limit) ; Emacs 23+
(defvar mac-tool-bar-display-mode)
;;;;;;;;;;;;;;;;;;;;;;;
;;; USER OPTIONS (VARIABLES) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defgroup Frame-Commands nil
"Miscellaneous frame and window commands."
:group 'frames
:prefix "frcmds-"
:link `(url-link :tag "Send Bug Report"
,(concat "mailto:" "drew.adams" "@" "oracle" ".com?subject=\
frame-cmds.el bug: \
&body=Describe bug here, starting with `emacs -q'. \
Don't forget to mention your Emacs and library versions."))
:link '(url-link :tag "Other Libraries by Drew"
"https://www.emacswiki.org/emacs/DrewsElispLibraries")
:link '(url-link :tag "Download"
"https://www.emacswiki.org/emacs/download/frame-cmds.el")
:link '(url-link :tag "Description - `delete-window'"
"https://www.emacswiki.org/emacs/FrameModes")
:link '(url-link :tag "Description - Frame Renaming"
"https://www.emacswiki.org/emacs/FrameTitle")
:link '(url-link :tag "Description - Frame Resizing"
"https://www.emacswiki.org/emacs/Shrink-Wrapping_Frames")
:link '(url-link :tag "Description - Frame Customization"
"https://www.emacswiki.org/emacs/CustomizingAndSaving")
:link '(url-link :tag "Description - Frame Tiling"
"https://www.emacswiki.org/emacs/Frame_Tiling_Commands")
:link '(url-link :tag "Description - General"
"https://www.emacswiki.org/emacs/FrameModes")
:link '(emacs-commentary-link :tag "Commentary" "frame-cmds"))
(defcustom rename-frame-when-iconify-flag t
"*Non-nil means frames are renamed when iconified.
The new name is the name of the current buffer."
:type 'boolean :group 'Frame-Commands)
(defcustom frame-config-register ?\C-l ; Control-L is the name of the register.
"*Character naming register for saving/restoring frame configuration."
:type 'character :group 'Frame-Commands)
(defcustom show-hide-show-function 'jump-to-frame-config-register
"*Function to show stuff that is hidden or iconified by `show-hide'.
Candidates include `jump-to-frame-config-register' and `show-buffer-menu'."
:type '(choice (function-item :tag "Restore frame configuration" jump-to-frame-config-register)
(function :tag "Another function"))
:group 'Frame-Commands)
;; Use `cond', not `case', for Emacs 20 byte-compiler.
(defcustom window-mgr-title-bar-pixel-height (cond ((eq window-system 'mac) 22)
;; For older versions of OS X, 40 might be better.
((eq window-system 'ns) 50)
(t 27))
"*Height of frame title bar provided by the window manager, in pixels.
You might alternatively call this constant the title-bar \"width\" or
\"thickness\". There is no way for Emacs to determine this, so you
must set it."
:type 'integer :group 'Frame-Commands)
(defcustom enlarge-font-tries 100
"*Number of times to try to change font-size, when looking for a font.
The font-size portion of a font name is incremented or decremented at
most this many times, before giving up and raising an error."
:type 'integer :group 'Frame-Commands)
(defcustom frame-parameters-to-exclude '((window-id) (buffer-list) (name) (title) (icon-name))
"*Parameters to exclude in `set-all-frame-alist-parameters-from-frame'.
An alist of the same form as that returned by `frame-parameters'.
The cdr of each alist element is ignored.
These frame parameters are not copied to the target alist."
:type '(repeat (cons symbol sexp)) :group 'Frame-Commands)
(defcustom move-frame-wrap-within-display-flag t
"*Non-nil means wrap frame movements within the display.
Commands `move-frame-up', `move-frame-down', `move-frame-left', and
`move-frame-right' then move the frame back onto the display when it
moves off of it.
If nil, you can move the frame as far off the display as you like."
:type 'boolean :group 'Frame-Commands)
(defcustom available-screen-pixel-bounds nil
"*Upper left and lower right of available screen space for tiling frames.
Integer list: (x0 y0 x1 y1), where (x0, y0) is the upper left position
and (x1, y1) is the lower right position. Coordinates are in pixels,
measured from the screen absolute origin, (0, 0), at the upper left.
If this is nil, then the available space is calculated. That should
give good results in most cases."
:type '(choice
(const :tag "Calculate automatically" nil)
(list :tag "List of (x0 y0 x1 y1)"
(integer :tag "X0 (upper left) - pixels from screen left")
(integer :tag "Y0 (upper left) - pixels from screen top")
(integer :tag "X1 (lower right) - pixels from screen left" )
(integer :tag "Y1 (lower right) - pixels from screen top")))
:group 'Frame-Commands)
;;; FUNCTIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;###autoload
(defun save-frame-config ()
"Save current frame configuration.
You can restore it with \\[jump-to-frame-config-register]."
(interactive)
(frame-configuration-to-register frame-config-register)
(when (fboundp 'doremi-push-current-frame-config) ; In `doremi-frm.el'.
(doremi-push-current-frame-config))
(message
(substitute-command-keys
(if (fboundp 'doremi-frame-configs) ; In `doremi-frm.el'.
(format "Use `\\[jump-to-frame-config-register]' (`C-x r j %c') or \
`\\[doremi-frame-configs]' to restore frames as before (undo)." frame-config-register)
"Use `\\[jump-to-frame-config-register]' to restore frames as before (undo)."))))
;;;###autoload
(defun jump-to-frame-config-register ()
"Restore frame configuration saved in `frame-config-register'."
(interactive)
(jump-to-register frame-config-register))
;;;###autoload
(defun deiconify-everything ()
"Deiconify any iconified frames."
(interactive)
(frame-configuration-to-register frame-config-register)
(dolist (frame (frame-list))
(when (eq 'icon (frame-visible-p frame)) (make-frame-visible frame))))
;;;###autoload
(defun iconify-everything ()
"Iconify all frames of session at once.
Remembers frame configuration in register `C-l' (Control-L).
To restore this frame configuration, use `\\[jump-to-register] C-l'."
(interactive)
(frame-configuration-to-register frame-config-register)
(let ((thumfr-thumbify-dont-iconify-flag nil)) ; Defined in `thumb-frm.el'.
(dolist (frame (visible-frame-list))
(when rename-frame-when-iconify-flag (rename-non-minibuffer-frame frame))
(iconify-frame frame))))
;;;###autoload
(defun hide-everything ()
"Hide all frames of session at once.
Iconify minibuffer frame; make all others invisible.
Remembers frame configuration in register `C-l' (Control-L).
To restore this frame configuration, use `\\[jump-to-register] C-l'."
(interactive)
(frame-configuration-to-register frame-config-register)
(let ((minibuf-frame-name (and (boundp '1on1-minibuffer-frame)
(cdr (assq 'name (frame-parameters
1on1-minibuffer-frame)))))
(thumfr-thumbify-dont-iconify-flag nil)) ; Defined in `thumb-frm.el'.
(dolist (frame (frame-list))
(if (eq minibuf-frame-name (cdr (assq 'name (frame-parameters frame))))
(iconify-frame frame) ; minibuffer frame
(make-frame-invisible frame t))))) ; other frames
;;;###autoload
(defun show-hide ()
"1 frame visible: `show-hide-show-function'; else: `hide-everything'.
This acts as a toggle between showing all frames and showing only an
iconified minibuffer frame."
(interactive)
(if (< (length (visible-frame-list)) 2) (funcall show-hide-show-function) (hide-everything)))
;;;###autoload
(defun show-buffer-menu ()
"Call `buffer-menu' after making all frames visible.
Useful after using `hide-everything' because of a Windows bug that
doesn't let you display frames that have been made visible after
being made invisible."
(interactive)
(let ((minibuf-frame-name (and (boundp '1on1-minibuffer-frame)
(cdr (assq 'name (frame-parameters 1on1-minibuffer-frame))))))
(dolist (frame (frame-list))
(if (eq minibuf-frame-name (cdr (assq 'name (frame-parameters frame))))
(make-frame-visible frame) ; minibuffer frame
(iconify-frame frame))) ; other frames
(buffer-menu)))
;;;###autoload
(defun mouse-show-hide-mark-unmark (event)
"In minibuffer: `show-hide'. In dired: mark/unmark; else: buffer menu."
(interactive "e")
(if (window-minibuffer-p (posn-window (event-start event)))
(show-hide)
(or (and (memq major-mode '(dired-mode vc-dired-mode))
(fboundp 'diredp-mouse-mark/unmark)
(diredp-mouse-mark/unmark event)) ; Return nil if not on a file or dir.
(mouse-buffer-menu event))))
;;;###autoload
(defalias 'iconify/map-frame 'iconify/show-frame) ; `.../map...' is the old name.
;;;###autoload
(defun iconify/show-frame (&optional all-action)
"Iconify selected frame if now shown. Show it if now iconified.
A non-negative prefix arg iconifies all shown frames.
A negative prefix arg deiconifies all iconified frames."
(interactive "P")
(cond ((not all-action)
(when rename-frame-when-iconify-flag (rename-non-minibuffer-frame))
(iconify-or-deiconify-frame))
((natnump (prefix-numeric-value all-action))
(iconify-everything))
(t
(deiconify-everything))))
;;;###autoload
(defalias 'mouse-iconify/map-frame 'mouse-iconify/show-frame) ; `.../map...' is the old name.
;;;###autoload
(defun mouse-iconify/show-frame (event)
"Iconify frame you click, if now shown. Show it if now iconified."
(interactive "e")
(select-window (posn-window (event-start event)))
(when rename-frame-when-iconify-flag (rename-non-minibuffer-frame))
(iconify-or-deiconify-frame))
;; ADVISE ORIGINAL (built-in):
;;
;; If WINDOW is the only one in its frame, `delete-frame'.
(defadvice delete-window (around delete-frame-if-one-win activate)
"If WINDOW is the only one in its frame, then `delete-frame' too."
(if (fboundp 'with-selected-window) ; Emacs 22+
(with-selected-window
(or (ad-get-arg 0) (selected-window))
(if (one-window-p t) (delete-frame) ad-do-it))
(save-current-buffer
(select-window (or (ad-get-arg 0) (selected-window)))
(if (one-window-p t) (delete-frame) ad-do-it))))
;;;###autoload
(defun delete-windows-for (&optional buffer)
"`delete-window' or prompt for buffer and delete its windows.
With no prefix arg, delete the selected window.
With a prefix arg, prompt for a buffer and delete all windows, on any
frame, that show that buffer."
(interactive (list (and current-prefix-arg (frcmds-read-buffer-for-delete-windows))))
(if buffer (delete-windows-on buffer) (delete-window)))
;; REPLACES ORIGINAL (built-in):
;;
;; 1) Use `read-buffer' in interactive spec.
;; 2) Do not raise an error if BUFFER is a string that does not name a buffer.
;; 3) Call `delete-window', so if you use the advised `delete-window' here then this also deletes
;; frames where window showing the BUFFER is the only window.
;;
;;;###autoload
(defun delete-windows-on (&optional buffer frame)
"Delete windows showing BUFFER.
Optional arg BUFFER defaults to the current buffer.
Optional second arg FRAME controls which frames are considered.
If nil or omitted, delete all windows showing BUFFER in any frame.
If t, delete only windows showing BUFFER in the selected frame.
If `visible', delete all windows showing BUFFER in any visible frame.
If a frame, delete only windows showing BUFFER in that frame.
Interactively, FRAME depends on the prefix arg, as follows:
Without a prefix arg (prefix = nil), FRAME is nil (all frames).
With prefix arg >= 0, FRAME is t (this frame only).
With prefix arg < 0, FRAME is `visible' (all visible frames)."
(interactive
(list (frcmds-read-buffer-for-delete-windows)
(and current-prefix-arg
(or (natnump (prefix-numeric-value current-prefix-arg)) 'visible))))
(unless buffer (setq buffer (current-buffer))) ; Like Emacs 23+ - unlike Emacs 21-22.
;; `get-buffer-window' interprets FRAME oppositely for t and nil, so switch.
(setq frame (if (eq t frame) nil (if (eq nil frame) t frame)))
(let (win)
;; Vanilla Emacs version raises an error if BUFFER is a string that does not name a buffer.
;; We do not raise an error - we do nothing.
(and (get-buffer buffer)
(while (setq win (get-buffer-window buffer frame)) (delete-window win))
nil))) ; Return nil always, like vanilla Emacs.
(defun frcmds-read-buffer-for-delete-windows ()
"Read buffer name for delete-windows commands.
Only displayed buffers are completion candidates."
(completing-read "Delete windows on buffer: "
(let ((all-bufs (buffer-list))
(cand-bufs ()))
(dolist (buf all-bufs)
(when (get-buffer-window buf t)
(push (list (buffer-name buf)) cand-bufs)))
cand-bufs)
nil t nil 'minibuffer-history (buffer-name (current-buffer)) t))
(defsubst frcmds-frame-iconified-p (frame)
"Return non-nil if FRAME is `frame-live-p' and `frame-visible-p'."
(and (frame-live-p frame) (eq (frame-visible-p frame) 'icon)))
;; (defun remove-window (&optional window)
;; "Remove WINDOW from the display. Default is `selected-window'.
;; If WINDOW is the only one in its frame, then:
;; If WINDOW is dedicated to its buffer, then make its frame invisible.
;; Otherwise, delete its frame (as well as the window)."
;; (interactive)
;; (setq window (or window (selected-window)))
;; (select-window window)
;; (if (and (window-dedicated-p (selected-window))
;; (one-window-p t))
;; (let ((fr (selected-frame)))
;; ;; HACK because of Emacs bug: `raise-frame' won't raise a frame
;; ;; that was first iconified and then made invisible.
;; ;; So, here we don't make an iconified frame invisible.
;; (unless (frcmds-frame-iconified-p fr)
;; (make-frame-invisible fr)))
;; (delete-window)))
;; REMOVED old definition, above, because of problems with invisible
;; *Completions* frame when use completion window with subsequent args
;; to a command. Just use `delete-window' now, which deletes frame if
;; `one-window-p'. Use a `defalias' because its easier than replacing
;; all my calls to `remove-window' with `delete-window'.
;;
;;;###autoload
(defalias 'remove-window 'delete-window)
;;;###autoload
(defun remove-windows-on (buffer &optional all-frames)
"Remove all windows showing BUFFER.
This calls `remove-window' on each window showing BUFFER.
When called from Lisp, optional arg ALL-FRAMES controls which frames
are considered. See `get-buffer-window' for its interpretation."
(interactive
(list (read-buffer "Remove all windows showing buffer: " (current-buffer) 'existing)
t))
(setq buffer (get-buffer buffer)) ; Convert to buffer.
(when buffer ; Do nothing if null BUFFER.
(let (win) (while (setq win (get-buffer-window buffer all-frames)) (remove-window win)))))
;;;###autoload
(defun mouse-remove-window (event)
"Remove the window you click on. (This calls `remove-window'.)
This command must be bound to a mouse click."
(interactive "e")
(mouse-minibuffer-check event)
(remove-window (posn-window (event-start event))))
;;;###autoload
(defun delete/iconify-window (&optional window frame-p)
"Delete or iconify WINDOW (default: `selected-window').
If WINDOW is the only one in its frame (`one-window-p'), then optional
arg FRAME-P determines the behavior regarding the frame, as follows:
If FRAME-P is nil, then the frame is deleted (with the window).
If FRAME-P is t, then the frame is iconified.
If FRAME-P is a symbol naming a function, the function is applied
to WINDOW as its only arg.
If the result is nil, then the frame is deleted.
If the result is non-nil, then the frame is iconified.
If FRAME-P is anything else, then behavior is as if FRAME-P were the
symbol `window-dedicated-p': the frame is iconified if
WINDOW is dedicated, otherwise the frame is deleted.
Interactively, FRAME-P depends on the prefix arg, as follows:
Without a prefix arg (prefix = nil), FRAME-P is `window-dedicated-p'.
With prefix arg < 0, FRAME-P is t. The frame is iconified.
With prefix arg >= 0, FRAME-P is nil. The frame is deleted."
(interactive
(list nil (if current-prefix-arg
(not (natnump (prefix-numeric-value current-prefix-arg)))
'window-dedicated-p)))
(setq window (or window (selected-window)))
(let ((one-win-p t))
(save-window-excursion
(select-window window)
(if (one-window-p)
(if frame-p
(if (eq t frame-p)
(iconify-frame)
(unless (and (symbolp frame-p) (fboundp frame-p))
(setq frame-p 'window-dedicated-p))
(if (funcall frame-p window) (iconify-frame) (delete-frame)))
(delete-frame)) ; Default.
(setq one-win-p nil)))
;; Do this outside `save-window-excursion'.
(unless one-win-p (delete-window window))))
;;;###autoload
(defun delete/iconify-windows-on (buffer &optional frame frame-p)
"For each window showing BUFFER: delete it or iconify its frame.
\(This calls `delete/iconify-window' on each window showing BUFFER.)
Optional second arg FRAME controls which frames are considered.
If nil or omitted, treat all windows showing BUFFER in any frame.
If t, treat only windows showing BUFFER in the selected frame.
If `visible', treat all windows showing BUFFER in any visible frame.
If a frame, treat only windows showing BUFFER in that frame.
Optional third arg FRAME-P controls what to do with one-window frames.
If FRAME-P is nil, then one-window frames showing BUFFER are deleted.
If FRAME-P is t, then one-window frames are iconified.