Mercurial > emacs
annotate lisp/window.el @ 27145:01abacc81cce
Changes to garbage-collect, new var strings-consed,
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Tue, 04 Jan 2000 12:35:02 +0000 |
parents | 6e6ad5d67263 |
children | 2ea744c8844a |
rev | line source |
---|---|
3375
13ddc81f0b43
(count-windows): PROC argument of walk-windows takes an argument.
Richard M. Stallman <rms@gnu.org>
parents:
3342
diff
changeset
|
1 ;;; window.el --- GNU Emacs window commands aside from those written in C. |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
2 |
14169 | 3 ;; Copyright (C) 1985, 1989, 1992, 1993, 1994 Free Software Foundation, Inc. |
841 | 4 |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
5 ;; Maintainer: FSF |
36 | 6 |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
707 | 11 ;; the Free Software Foundation; either version 2, or (at your option) |
36 | 12 ;; any later version. |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
14169 | 20 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
36 | 23 |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
24 ;;; Code: |
36 | 25 |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
26 ;;;; Window tree functions. |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
27 |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
28 (defun one-window-p (&optional nomini all-frames) |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
29 "Returns non-nil if the selected window is the only window (in its frame). |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
30 Optional arg NOMINI non-nil means don't count the minibuffer |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
31 even if it is active. |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
32 |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
33 The optional arg ALL-FRAMES t means count windows on all frames. |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
34 If it is `visible', count windows on all visible frames. |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
35 ALL-FRAMES nil or omitted means count only the selected frame, |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
36 plus the minibuffer it uses (which may be on another frame). |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
37 If ALL-FRAMES is neither nil nor t, count only the selected frame." |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
38 (let ((base-window (selected-window))) |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
39 (if (and nomini (eq base-window (minibuffer-window))) |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
40 (setq base-window (next-window base-window))) |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
41 (eq base-window |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
42 (next-window base-window (if nomini 'arg) all-frames)))) |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
43 |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
44 (defun walk-windows (proc &optional minibuf all-frames) |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
45 "Cycle through all visible windows, calling PROC for each one. |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
46 PROC is called with a window as argument. |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
47 |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
48 Optional second arg MINIBUF t means count the minibuffer window even |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
49 if not active. MINIBUF nil or omitted means count the minibuffer iff |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
50 it is active. MINIBUF neither t nor nil means not to count the |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
51 minibuffer even if it is active. |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
52 |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
53 Several frames may share a single minibuffer; if the minibuffer |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
54 counts, all windows on all frames that share that minibuffer count |
15057
3f71523422e9
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14836
diff
changeset
|
55 too. Therefore, if you are using a separate minibuffer frame |
3f71523422e9
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14836
diff
changeset
|
56 and the minibuffer is active and MINIBUF says it counts, |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
57 `walk-windows' includes the windows in the frame from which you |
15057
3f71523422e9
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
14836
diff
changeset
|
58 entered the minibuffer, as well as the minibuffer window. |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
59 |
11302
a9b5c1d727b7
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11149
diff
changeset
|
60 ALL-FRAMES is the optional third argument. |
a9b5c1d727b7
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11149
diff
changeset
|
61 ALL-FRAMES nil or omitted means cycle within the frames as specified above. |
a9b5c1d727b7
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11149
diff
changeset
|
62 ALL-FRAMES = `visible' means include windows on all visible frames. |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
63 ALL-FRAMES = 0 means include windows on all visible and iconified frames. |
11302
a9b5c1d727b7
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11149
diff
changeset
|
64 ALL-FRAMES = t means include windows on all frames including invisible frames. |
26268
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
65 If ALL-FRAMES is a frame, it means include windows on that frame. |
15076
5e9132ff1d88
(walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
15057
diff
changeset
|
66 Anything else means restrict to the selected frame." |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
67 ;; If we start from the minibuffer window, don't fail to come back to it. |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
68 (if (window-minibuffer-p (selected-window)) |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
69 (setq minibuf t)) |
26268
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
70 (save-selected-window |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
71 (if (framep all-frames) |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
72 (select-window (frame-first-window all-frames))) |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
73 (let* ((walk-windows-start (selected-window)) |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
74 (walk-windows-current walk-windows-start)) |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
75 (while (progn |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
76 (setq walk-windows-current |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
77 (next-window walk-windows-current minibuf all-frames)) |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
78 (funcall proc walk-windows-current) |
6e6ad5d67263
(walk-windows): If ALL-FRAMES is a frame,
Gerd Moellmann <gerd@gnu.org>
parents:
25263
diff
changeset
|
79 (not (eq walk-windows-current walk-windows-start))))))) |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
80 |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
81 (defun minibuffer-window-active-p (window) |
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
82 "Return t if WINDOW (a minibuffer window) is now active." |
11149
8904c26c2182
(minibuffer-window-active-p): Use active-minibuffer-window.
Richard M. Stallman <rms@gnu.org>
parents:
11086
diff
changeset
|
83 (eq window (active-minibuffer-window))) |
12184
629806145d36
(save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents:
11302
diff
changeset
|
84 |
629806145d36
(save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents:
11302
diff
changeset
|
85 (defmacro save-selected-window (&rest body) |
629806145d36
(save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents:
11302
diff
changeset
|
86 "Execute BODY, then select the window that was selected before BODY." |
629806145d36
(save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents:
11302
diff
changeset
|
87 (list 'let |
629806145d36
(save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents:
11302
diff
changeset
|
88 '((save-selected-window-window (selected-window))) |
629806145d36
(save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents:
11302
diff
changeset
|
89 (list 'unwind-protect |
629806145d36
(save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents:
11302
diff
changeset
|
90 (cons 'progn body) |
629806145d36
(save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents:
11302
diff
changeset
|
91 (list 'select-window 'save-selected-window-window)))) |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
92 |
36 | 93 (defun count-windows (&optional minibuf) |
94 "Returns the number of visible windows. | |
22328
874f007a7d9c
(shrink-window-if-larger-than-buffer):
Karl Heuer <kwzh@gnu.org>
parents:
22216
diff
changeset
|
95 This counts the windows in the selected frame and (if the minibuffer is |
874f007a7d9c
(shrink-window-if-larger-than-buffer):
Karl Heuer <kwzh@gnu.org>
parents:
22216
diff
changeset
|
96 to be counted) its minibuffer frame (if that's not the same frame). |
874f007a7d9c
(shrink-window-if-larger-than-buffer):
Karl Heuer <kwzh@gnu.org>
parents:
22216
diff
changeset
|
97 The optional arg MINIBUF non-nil means count the minibuffer |
14836 | 98 even if it is inactive." |
36 | 99 (let ((count 0)) |
3375
13ddc81f0b43
(count-windows): PROC argument of walk-windows takes an argument.
Richard M. Stallman <rms@gnu.org>
parents:
3342
diff
changeset
|
100 (walk-windows (function (lambda (w) |
36 | 101 (setq count (+ count 1)))) |
102 minibuf) | |
103 count)) | |
104 | |
105 (defun balance-windows () | |
3724
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
106 "Makes all visible windows the same height (approximately)." |
36 | 107 (interactive) |
13523
75c6a5e1ee7a
(balance-windows): Don't count the menu bar's lines in the frame height.
Richard M. Stallman <rms@gnu.org>
parents:
12184
diff
changeset
|
108 (let ((count -1) levels newsizes size |
75c6a5e1ee7a
(balance-windows): Don't count the menu bar's lines in the frame height.
Richard M. Stallman <rms@gnu.org>
parents:
12184
diff
changeset
|
109 ;; Don't count the lines that are above the uppermost windows. |
75c6a5e1ee7a
(balance-windows): Don't count the menu bar's lines in the frame height.
Richard M. Stallman <rms@gnu.org>
parents:
12184
diff
changeset
|
110 ;; (These are the menu bar lines, if any.) |
75c6a5e1ee7a
(balance-windows): Don't count the menu bar's lines in the frame height.
Richard M. Stallman <rms@gnu.org>
parents:
12184
diff
changeset
|
111 (mbl (nth 1 (window-edges (frame-first-window (selected-frame)))))) |
3724
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
112 ;; Find all the different vpos's at which windows start, |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
113 ;; then count them. But ignore levels that differ by only 1. |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
114 (save-window-excursion |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
115 (let (tops (prev-top -2)) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
116 (walk-windows (function (lambda (w) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
117 (setq tops (cons (nth 1 (window-edges w)) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
118 tops)))) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
119 'nomini) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
120 (setq tops (sort tops '<)) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
121 (while tops |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
122 (if (> (car tops) (1+ prev-top)) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
123 (setq prev-top (car tops) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
124 count (1+ count))) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
125 (setq levels (cons (cons (car tops) count) levels)) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
126 (setq tops (cdr tops))) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
127 (setq count (1+ count)))) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
128 ;; Subdivide the frame into that many vertical levels. |
13523
75c6a5e1ee7a
(balance-windows): Don't count the menu bar's lines in the frame height.
Richard M. Stallman <rms@gnu.org>
parents:
12184
diff
changeset
|
129 (setq size (/ (- (frame-height) mbl) count)) |
3724
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
130 (walk-windows (function |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
131 (lambda (w) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
132 (select-window w) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
133 (let ((newtop (cdr (assq (nth 1 (window-edges)) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
134 levels))) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
135 (newbot (or (cdr (assq (+ (window-height) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
136 (nth 1 (window-edges))) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
137 levels)) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
138 count))) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
139 (setq newsizes |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
140 (cons (cons w (* size (- newbot newtop))) |
11029
3f98c129f7bc
(balance-windows): Ignore minibuffer window when browsing the `levels'.
Richard M. Stallman <rms@gnu.org>
parents:
9007
diff
changeset
|
141 newsizes))))) |
3f98c129f7bc
(balance-windows): Ignore minibuffer window when browsing the `levels'.
Richard M. Stallman <rms@gnu.org>
parents:
9007
diff
changeset
|
142 'nomini) |
36 | 143 (walk-windows (function (lambda (w) |
3724
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
144 (select-window w) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
145 (let ((newsize (cdr (assq w newsizes)))) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
146 (enlarge-window (- newsize |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
147 (window-height)))))) |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
148 'nomini))) |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
149 |
698
793483bd29fe
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
656
diff
changeset
|
150 ;;; I think this should be the default; I think people will prefer it--rms. |
17665 | 151 (defcustom split-window-keep-point t |
3724
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
152 "*If non-nil, split windows keeps the original point in both children. |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
153 This is often more convenient for editing. |
dc73f3152d2f
(balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
3375
diff
changeset
|
154 If nil, adjust point in each of the two windows to minimize redisplay. |
17665 | 155 This is convenient on slow terminals, but point can move strangely." |
156 :type 'boolean | |
157 :group 'windows) | |
382 | 158 |
36 | 159 (defun split-window-vertically (&optional arg) |
160 "Split current window into two windows, one above the other. | |
108 | 161 The uppermost window gets ARG lines and the other gets the rest. |
6670
b2c5fca3c10c
(split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents:
6019
diff
changeset
|
162 Negative arg means select the size of the lowermost window instead. |
108 | 163 With no argument, split equally or close to it. |
164 Both windows display the same buffer now current. | |
382 | 165 |
22216
5750539e01e7
(split-window-vertically): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
21970
diff
changeset
|
166 If the variable `split-window-keep-point' is non-nil, both new windows |
382 | 167 will get the same value of point as the current window. This is often |
168 more convenient for editing. | |
108 | 169 |
382 | 170 Otherwise, we chose window starts so as to minimize the amount of |
171 redisplay; this is convenient on slow terminals. The new selected | |
172 window is the one that the current value of point appears in. The | |
173 value of point can change if the text around point is hidden by the | |
174 new mode line." | |
36 | 175 (interactive "P") |
176 (let ((old-w (selected-window)) | |
108 | 177 (old-point (point)) |
6670
b2c5fca3c10c
(split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents:
6019
diff
changeset
|
178 (size (and arg (prefix-numeric-value arg))) |
13854
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
179 (window-full-p nil) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
180 new-w bottom switch moved) |
6670
b2c5fca3c10c
(split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents:
6019
diff
changeset
|
181 (and size (< size 0) (setq size (+ (window-height) size))) |
b2c5fca3c10c
(split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents:
6019
diff
changeset
|
182 (setq new-w (split-window nil size)) |
419 | 183 (or split-window-keep-point |
108 | 184 (progn |
382 | 185 (save-excursion |
186 (set-buffer (window-buffer)) | |
187 (goto-char (window-start)) | |
13854
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
188 (setq moved (vertical-motion (window-height))) |
382 | 189 (set-window-start new-w (point)) |
190 (if (> (point) (window-point new-w)) | |
191 (set-window-point new-w (point))) | |
13854
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
192 (and (= moved (window-height)) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
193 (progn |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
194 (setq window-full-p t) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
195 (vertical-motion -1))) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
196 (setq bottom (point))) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
197 (and window-full-p |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
198 (<= bottom (point)) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
199 (set-window-point old-w (1- bottom))) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
200 (and window-full-p |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
201 (<= (window-start new-w) old-point) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
202 (progn |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
203 (set-window-point new-w old-point) |
84de7ffae8ae
(split-window-vertically): Don't change point in old
Richard M. Stallman <rms@gnu.org>
parents:
13523
diff
changeset
|
204 (select-window new-w))))) |
18279
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
205 (split-window-save-restore-data new-w old-w))) |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
206 |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
207 ;; This is to avoid compiler warnings. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
208 (defvar view-return-to-alist) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
209 |
18279
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
210 (defun split-window-save-restore-data (new-w old-w) |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
211 (save-excursion |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
212 (set-buffer (window-buffer)) |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
213 (if view-mode |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
214 (let ((old-info (assq old-w view-return-to-alist))) |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
215 (setq view-return-to-alist |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
216 (cons (cons new-w (cons (and old-info (car (cdr old-info))) t)) |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
217 view-return-to-alist)))) |
3253
f4d37be94734
(split-window-vertically): Return the new window.
Richard M. Stallman <rms@gnu.org>
parents:
2529
diff
changeset
|
218 new-w)) |
36 | 219 |
220 (defun split-window-horizontally (&optional arg) | |
221 "Split current window into two windows side by side. | |
8565
2a2208286955
(split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
parents:
7300
diff
changeset
|
222 This window becomes the leftmost of the two, and gets ARG columns. |
2a2208286955
(split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
parents:
7300
diff
changeset
|
223 Negative arg means select the size of the rightmost window instead. |
22924
13888875bea1
(split-window-horizontally): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
22328
diff
changeset
|
224 The argument includes the width of the window's scroll bar; if there |
13888875bea1
(split-window-horizontally): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
22328
diff
changeset
|
225 are no scroll bars, it includes the width of the divider column |
13888875bea1
(split-window-horizontally): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
22328
diff
changeset
|
226 to the window's right, if any. No arg means split equally." |
36 | 227 (interactive "P") |
18279
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
228 (let ((old-w (selected-window)) |
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
229 (size (and arg (prefix-numeric-value arg)))) |
8565
2a2208286955
(split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
parents:
7300
diff
changeset
|
230 (and size (< size 0) |
2a2208286955
(split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
parents:
7300
diff
changeset
|
231 (setq size (+ (window-width) size))) |
18279
a9c40a80c9b1
(split-window-save-restore-data): New function that
Richard M. Stallman <rms@gnu.org>
parents:
17665
diff
changeset
|
232 (split-window-save-restore-data (split-window nil size t) old-w))) |
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents:
11029
diff
changeset
|
233 |
36 | 234 (defun enlarge-window-horizontally (arg) |
235 "Make current window ARG columns wider." | |
236 (interactive "p") | |
237 (enlarge-window arg t)) | |
238 | |
239 (defun shrink-window-horizontally (arg) | |
240 "Make current window ARG columns narrower." | |
241 (interactive "p") | |
242 (shrink-window arg t)) | |
243 | |
23748
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
244 (defun window-buffer-height (window) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
245 "Return the height (in screen lines) of the buffer that WINDOW is displaying." |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
246 (save-excursion |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
247 (set-buffer (window-buffer window)) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
248 (goto-char (point-min)) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
249 (let ((ignore-final-newline |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
250 ;; If buffer ends with a newline, ignore it when counting height |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
251 ;; unless point is after it. |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
252 (and (not (eobp)) (eq ?\n (char-after (1- (point-max))))))) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
253 (+ 1 (nth 2 (compute-motion (point-min) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
254 '(0 . 0) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
255 (- (point-max) (if ignore-final-newline 1 0)) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
256 (cons 0 100000000) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
257 (window-width window) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
258 nil |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
259 window)))))) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
260 |
2529
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
261 (defun shrink-window-if-larger-than-buffer (&optional window) |
3342
ce8aa0ba8b08
(shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
3253
diff
changeset
|
262 "Shrink the WINDOW to be as small as possible to display its contents. |
8721
c94f87ea8a1b
(shrink-window-if-larger-than-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
8672
diff
changeset
|
263 Do not shrink to less than `window-min-height' lines. |
3342
ce8aa0ba8b08
(shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
3253
diff
changeset
|
264 Do nothing if the buffer contains more lines than the present window height, |
4364
69e5c2373d37
(shrink-window-if-larger-than-buffer): Do nothing if the
Richard M. Stallman <rms@gnu.org>
parents:
3724
diff
changeset
|
265 or if some of the window's contents are scrolled out of view, |
6905
e068218e992b
(shrink-window-if-larger-than-buffer):
Richard M. Stallman <rms@gnu.org>
parents:
6670
diff
changeset
|
266 or if the window is not the full width of the frame, |
4364
69e5c2373d37
(shrink-window-if-larger-than-buffer): Do nothing if the
Richard M. Stallman <rms@gnu.org>
parents:
3724
diff
changeset
|
267 or if the window is the only window of its frame." |
3342
ce8aa0ba8b08
(shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
3253
diff
changeset
|
268 (interactive) |
22328
874f007a7d9c
(shrink-window-if-larger-than-buffer):
Karl Heuer <kwzh@gnu.org>
parents:
22216
diff
changeset
|
269 (save-selected-window |
874f007a7d9c
(shrink-window-if-larger-than-buffer):
Karl Heuer <kwzh@gnu.org>
parents:
22216
diff
changeset
|
270 (if window |
874f007a7d9c
(shrink-window-if-larger-than-buffer):
Karl Heuer <kwzh@gnu.org>
parents:
22216
diff
changeset
|
271 (select-window window) |
874f007a7d9c
(shrink-window-if-larger-than-buffer):
Karl Heuer <kwzh@gnu.org>
parents:
22216
diff
changeset
|
272 (setq window (selected-window))) |
23748
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
273 (let* ((params (frame-parameters)) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
274 (mini (cdr (assq 'minibuffer params))) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
275 (edges (window-edges))) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
276 (if (and (< 1 (count-windows)) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
277 (= (window-width) (frame-width)) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
278 (pos-visible-in-window-p (point-min) window) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
279 (not (eq mini 'only)) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
280 (or (not mini) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
281 (< (nth 3 edges) (nth 1 (window-edges mini))) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
282 (> (nth 1 edges) (cdr (assq 'menu-bar-lines params))))) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
283 (let ((text-height (window-buffer-height window)) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
284 (window-height (window-height))) |
24492
46906de4c968
(shrink-window-if-larger-than-buffer):
Karl Heuer <kwzh@gnu.org>
parents:
23748
diff
changeset
|
285 ;; Don't try to redisplay with the cursor at the end |
46906de4c968
(shrink-window-if-larger-than-buffer):
Karl Heuer <kwzh@gnu.org>
parents:
23748
diff
changeset
|
286 ;; on its own line--that would force a scroll and spoil things. |
25263
651362fe2962
(shrink-window-if-larger-than-buffer): Don't try to
Karl Heuer <kwzh@gnu.org>
parents:
24492
diff
changeset
|
287 (when (and (eobp) (bolp) (not (bobp))) |
24492
46906de4c968
(shrink-window-if-larger-than-buffer):
Karl Heuer <kwzh@gnu.org>
parents:
23748
diff
changeset
|
288 (forward-char -1)) |
23748
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
289 (when (> window-height (1+ text-height)) |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
290 (shrink-window |
19e23f0e3cd3
(window-buffer-height): New function, split from
Richard M. Stallman <rms@gnu.org>
parents:
22924
diff
changeset
|
291 (- window-height (max (1+ text-height) window-min-height))))))))) |
16469
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
292 |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
293 (defun kill-buffer-and-window () |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
294 "Kill the current buffer and delete the selected window." |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
295 (interactive) |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
296 (if (yes-or-no-p (format "Kill buffer `%s'? " (buffer-name))) |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
297 (let ((buffer (current-buffer))) |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
298 (delete-window (selected-window)) |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
299 (kill-buffer buffer)) |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
300 (error "Aborted"))) |
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
301 |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
302 (defun quit-window (&optional kill window) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
303 "Quit the current buffer. Bury it, and maybe delete the selected frame. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
304 \(The frame is deleted if it is contains a dedicated window for the buffer.) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
305 With a prefix argument, kill the buffer instead. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
306 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
307 Noninteractively, if KILL is non-nil, then kill the current buffer, |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
308 otherwise bury it. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
309 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
310 If WINDOW is non-nil, it specifies a window; we delete that window, |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
311 and the buffer that is killed or buried is the one in that window." |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
312 (interactive "P") |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
313 (let ((buffer (window-buffer window)) |
21970
3c8d5ab91f84
(quit-window): Fixed FRAME to be the frame and never window.
Richard M. Stallman <rms@gnu.org>
parents:
21860
diff
changeset
|
314 (frame (window-frame (or window (selected-window)))) |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
315 (window-solitary |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
316 (save-selected-window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
317 (if window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
318 (select-window window)) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
319 (one-window-p t))) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
320 window-handled) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
321 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
322 (save-selected-window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
323 (if window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
324 (select-window window)) |
21860
58d299618042
(quit-window): Don't try to switch buffers
Richard M. Stallman <rms@gnu.org>
parents:
21118
diff
changeset
|
325 (or (window-minibuffer-p) |
58d299618042
(quit-window): Don't try to switch buffers
Richard M. Stallman <rms@gnu.org>
parents:
21118
diff
changeset
|
326 (window-dedicated-p (selected-window)) |
58d299618042
(quit-window): Don't try to switch buffers
Richard M. Stallman <rms@gnu.org>
parents:
21118
diff
changeset
|
327 (switch-to-buffer (other-buffer)))) |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
328 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
329 ;; Get rid of the frame, if it has just one dedicated window |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
330 ;; and other visible frames exist. |
21860
58d299618042
(quit-window): Don't try to switch buffers
Richard M. Stallman <rms@gnu.org>
parents:
21118
diff
changeset
|
331 (and (or (window-minibuffer-p) (window-dedicated-p window)) |
21118
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
332 (delq frame (visible-frame-list)) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
333 window-solitary |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
334 (if (and (eq default-minibuffer-frame frame) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
335 (= 1 (length (minibuffer-frame-list)))) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
336 (setq window nil) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
337 (delete-frame frame) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
338 (setq window-handled t))) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
339 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
340 ;; Deal with the buffer. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
341 (if kill |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
342 (kill-buffer buffer) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
343 (bury-buffer buffer)) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
344 |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
345 ;; Maybe get rid of the window. |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
346 (and window (not window-handled) (not window-solitary) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
347 (delete-window window)))) |
2aa0dc203036
(quit-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
18517
diff
changeset
|
348 |
36 | 349 (define-key ctl-x-map "2" 'split-window-vertically) |
707 | 350 (define-key ctl-x-map "3" 'split-window-horizontally) |
36 | 351 (define-key ctl-x-map "}" 'enlarge-window-horizontally) |
352 (define-key ctl-x-map "{" 'shrink-window-horizontally) | |
2529
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
353 (define-key ctl-x-map "-" 'shrink-window-if-larger-than-buffer) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
354 (define-key ctl-x-map "+" 'balance-windows) |
16469
479c96f4be3a
(kill-buffer-and-window): New command.
Richard M. Stallman <rms@gnu.org>
parents:
15076
diff
changeset
|
355 (define-key ctl-x-4-map "0" 'kill-buffer-and-window) |
656
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
419
diff
changeset
|
356 |
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
419
diff
changeset
|
357 ;;; windows.el ends here |