3375
13ddc81f0b43
(count-windows): PROC argument of walk-windows takes an argument.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1 ;;; window.el --- GNU Emacs window commands aside from those written in C.
|
773
|
2
|
14169
|
3 ;; Copyright (C) 1985, 1989, 1992, 1993, 1994 Free Software Foundation, Inc.
|
841
|
4
|
773
|
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
|
24 ;;; Code:
|
36
|
25
|
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
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>
diff
changeset
|
27
|
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
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>
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>
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>
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>
diff
changeset
|
32
|
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
diff
changeset
|
43
|
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
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>
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>
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>
diff
changeset
|
47
|
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
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>
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>
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>
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>
diff
changeset
|
52
|
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
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>
diff
changeset
|
54 counts, all windows on all frames that share that minibuffer count
|
15057
|
55 too. Therefore, if you are using a separate minibuffer frame
|
|
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>
diff
changeset
|
57 `walk-windows' includes the windows in the frame from which you
|
15057
|
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>
diff
changeset
|
59
|
11302
|
60 ALL-FRAMES is the optional third argument.
|
|
61 ALL-FRAMES nil or omitted means cycle within the frames as specified above.
|
|
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>
diff
changeset
|
63 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
|
11302
|
64 ALL-FRAMES = t means include windows on all frames including invisible frames.
|
15076
|
65 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>
diff
changeset
|
66 ;; 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>
diff
changeset
|
67 (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>
diff
changeset
|
68 (setq minibuf t))
|
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
69 (let* ((walk-windows-start (selected-window))
|
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
70 (walk-windows-current walk-windows-start))
|
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
71 (while (progn
|
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
72 (setq walk-windows-current
|
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
73 (next-window walk-windows-current minibuf all-frames))
|
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
74 (funcall proc walk-windows-current)
|
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
75 (not (eq walk-windows-current walk-windows-start))))))
|
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
76
|
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
77 (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>
diff
changeset
|
78 "Return t if WINDOW (a minibuffer window) is now active."
|
11149
|
79 (eq window (active-minibuffer-window)))
|
12184
|
80
|
|
81 (defmacro save-selected-window (&rest body)
|
|
82 "Execute BODY, then select the window that was selected before BODY."
|
|
83 (list 'let
|
|
84 '((save-selected-window-window (selected-window)))
|
|
85 (list 'unwind-protect
|
|
86 (cons 'progn body)
|
|
87 (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>
diff
changeset
|
88
|
36
|
89 (defun count-windows (&optional minibuf)
|
|
90 "Returns the number of visible windows.
|
14836
|
91 Optional arg MINIBUF non-nil means count the minibuffer
|
|
92 even if it is inactive."
|
36
|
93 (let ((count 0))
|
3375
13ddc81f0b43
(count-windows): PROC argument of walk-windows takes an argument.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
94 (walk-windows (function (lambda (w)
|
36
|
95 (setq count (+ count 1))))
|
|
96 minibuf)
|
|
97 count))
|
|
98
|
|
99 (defun balance-windows ()
|
3724
|
100 "Makes all visible windows the same height (approximately)."
|
36
|
101 (interactive)
|
13523
75c6a5e1ee7a
(balance-windows): Don't count the menu bar's lines in the frame height.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
102 (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>
diff
changeset
|
103 ;; 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>
diff
changeset
|
104 ;; (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>
diff
changeset
|
105 (mbl (nth 1 (window-edges (frame-first-window (selected-frame))))))
|
3724
|
106 ;; Find all the different vpos's at which windows start,
|
|
107 ;; then count them. But ignore levels that differ by only 1.
|
|
108 (save-window-excursion
|
|
109 (let (tops (prev-top -2))
|
|
110 (walk-windows (function (lambda (w)
|
|
111 (setq tops (cons (nth 1 (window-edges w))
|
|
112 tops))))
|
|
113 'nomini)
|
|
114 (setq tops (sort tops '<))
|
|
115 (while tops
|
|
116 (if (> (car tops) (1+ prev-top))
|
|
117 (setq prev-top (car tops)
|
|
118 count (1+ count)))
|
|
119 (setq levels (cons (cons (car tops) count) levels))
|
|
120 (setq tops (cdr tops)))
|
|
121 (setq count (1+ count))))
|
|
122 ;; 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>
diff
changeset
|
123 (setq size (/ (- (frame-height) mbl) count))
|
3724
|
124 (walk-windows (function
|
|
125 (lambda (w)
|
|
126 (select-window w)
|
|
127 (let ((newtop (cdr (assq (nth 1 (window-edges))
|
|
128 levels)))
|
|
129 (newbot (or (cdr (assq (+ (window-height)
|
|
130 (nth 1 (window-edges)))
|
|
131 levels))
|
|
132 count)))
|
|
133 (setq newsizes
|
|
134 (cons (cons w (* size (- newbot newtop)))
|
11029
3f98c129f7bc
(balance-windows): Ignore minibuffer window when browsing the `levels'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
135 newsizes)))))
|
3f98c129f7bc
(balance-windows): Ignore minibuffer window when browsing the `levels'.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
136 'nomini)
|
36
|
137 (walk-windows (function (lambda (w)
|
3724
|
138 (select-window w)
|
|
139 (let ((newsize (cdr (assq w newsizes))))
|
|
140 (enlarge-window (- newsize
|
|
141 (window-height))))))
|
|
142 'nomini)))
|
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
143
|
698
|
144 ;;; I think this should be the default; I think people will prefer it--rms.
|
|
145 (defvar split-window-keep-point t
|
3724
|
146 "*If non-nil, split windows keeps the original point in both children.
|
|
147 This is often more convenient for editing.
|
|
148 If nil, adjust point in each of the two windows to minimize redisplay.
|
|
149 This is convenient on slow terminals, but point can move strangely.")
|
382
|
150
|
36
|
151 (defun split-window-vertically (&optional arg)
|
|
152 "Split current window into two windows, one above the other.
|
108
|
153 The uppermost window gets ARG lines and the other gets the rest.
|
6670
|
154 Negative arg means select the size of the lowermost window instead.
|
108
|
155 With no argument, split equally or close to it.
|
|
156 Both windows display the same buffer now current.
|
382
|
157
|
|
158 If the variable split-window-keep-point is non-nil, both new windows
|
|
159 will get the same value of point as the current window. This is often
|
|
160 more convenient for editing.
|
108
|
161
|
382
|
162 Otherwise, we chose window starts so as to minimize the amount of
|
|
163 redisplay; this is convenient on slow terminals. The new selected
|
|
164 window is the one that the current value of point appears in. The
|
|
165 value of point can change if the text around point is hidden by the
|
|
166 new mode line."
|
36
|
167 (interactive "P")
|
|
168 (let ((old-w (selected-window))
|
108
|
169 (old-point (point))
|
6670
|
170 (size (and arg (prefix-numeric-value arg)))
|
13854
|
171 (window-full-p nil)
|
|
172 new-w bottom switch moved)
|
6670
|
173 (and size (< size 0) (setq size (+ (window-height) size)))
|
|
174 (setq new-w (split-window nil size))
|
419
|
175 (or split-window-keep-point
|
108
|
176 (progn
|
382
|
177 (save-excursion
|
|
178 (set-buffer (window-buffer))
|
|
179 (goto-char (window-start))
|
13854
|
180 (setq moved (vertical-motion (window-height)))
|
382
|
181 (set-window-start new-w (point))
|
|
182 (if (> (point) (window-point new-w))
|
|
183 (set-window-point new-w (point)))
|
13854
|
184 (and (= moved (window-height))
|
|
185 (progn
|
|
186 (setq window-full-p t)
|
|
187 (vertical-motion -1)))
|
|
188 (setq bottom (point)))
|
|
189 (and window-full-p
|
|
190 (<= bottom (point))
|
|
191 (set-window-point old-w (1- bottom)))
|
|
192 (and window-full-p
|
|
193 (<= (window-start new-w) old-point)
|
|
194 (progn
|
|
195 (set-window-point new-w old-point)
|
|
196 (select-window new-w)))))
|
3253
|
197 new-w))
|
36
|
198
|
|
199 (defun split-window-horizontally (&optional arg)
|
|
200 "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>
diff
changeset
|
201 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>
diff
changeset
|
202 Negative arg means select the size of the rightmost window instead.
|
2a2208286955
(split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
203 No arg means split equally."
|
36
|
204 (interactive "P")
|
8565
2a2208286955
(split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
205 (let ((size (and arg (prefix-numeric-value arg))))
|
2a2208286955
(split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
206 (and size (< size 0)
|
2a2208286955
(split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
207 (setq size (+ (window-width) size)))
|
2a2208286955
(split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
208 (split-window nil size t)))
|
11086
22693a280a42
(one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
209
|
36
|
210 (defun enlarge-window-horizontally (arg)
|
|
211 "Make current window ARG columns wider."
|
|
212 (interactive "p")
|
|
213 (enlarge-window arg t))
|
|
214
|
|
215 (defun shrink-window-horizontally (arg)
|
|
216 "Make current window ARG columns narrower."
|
|
217 (interactive "p")
|
|
218 (shrink-window arg t))
|
|
219
|
2529
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
220 (defun shrink-window-if-larger-than-buffer (&optional window)
|
3342
|
221 "Shrink the WINDOW to be as small as possible to display its contents.
|
8721
|
222 Do not shrink to less than `window-min-height' lines.
|
3342
|
223 Do nothing if the buffer contains more lines than the present window height,
|
4364
|
224 or if some of the window's contents are scrolled out of view,
|
6905
|
225 or if the window is not the full width of the frame,
|
4364
|
226 or if the window is the only window of its frame."
|
3342
|
227 (interactive)
|
9007
|
228 (or window (setq window (selected-window)))
|
2529
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
229 (save-excursion
|
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
230 (set-buffer (window-buffer window))
|
9007
|
231 (let* ((w (selected-window)) ;save-window-excursion can't win
|
|
232 (buffer-file-name buffer-file-name)
|
|
233 (p (point))
|
|
234 (n 0)
|
|
235 (ignore-final-newline
|
|
236 ;; If buffer ends with a newline, ignore it when counting height
|
|
237 ;; unless point is after it.
|
|
238 (and (not (eobp))
|
|
239 (eq ?\n (char-after (1- (point-max))))))
|
|
240 (buffer-read-only nil)
|
|
241 (modified (buffer-modified-p))
|
|
242 (buffer (current-buffer))
|
|
243 (params (frame-parameters (window-frame window)))
|
|
244 (mini (cdr (assq 'minibuffer params)))
|
|
245 (edges (window-edges (selected-window))))
|
|
246 (if (and (< 1 (let ((frame (selected-frame)))
|
|
247 (select-frame (window-frame window))
|
|
248 (unwind-protect
|
|
249 (count-windows)
|
|
250 (select-frame frame))))
|
|
251 (= (window-width window) (frame-width (window-frame window)))
|
6019
0c0b00572d96
(shrink-window-if-larger-than-buffer): Don't shrink if the window that would
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
252 (pos-visible-in-window-p (point-min) window)
|
8778
|
253 (not (eq mini 'only))
|
6019
0c0b00572d96
(shrink-window-if-larger-than-buffer): Don't shrink if the window that would
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
254 (or (not mini)
|
0c0b00572d96
(shrink-window-if-larger-than-buffer): Don't shrink if the window that would
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
255 (< (nth 3 edges)
|
0c0b00572d96
(shrink-window-if-larger-than-buffer): Don't shrink if the window that would
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
256 (nth 1 (window-edges mini)))
|
0c0b00572d96
(shrink-window-if-larger-than-buffer): Don't shrink if the window that would
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
257 (> (nth 1 edges)
|
9007
|
258 (cdr (assq 'menu-bar-lines params)))))
|
3342
|
259 (unwind-protect
|
|
260 (progn
|
|
261 (select-window (or window w))
|
|
262 (goto-char (point-min))
|
4364
|
263 (while (pos-visible-in-window-p
|
|
264 (- (point-max)
|
|
265 (if ignore-final-newline 1 0)))
|
3342
|
266 ;; defeat file locking... don't try this at home, kids!
|
|
267 (setq buffer-file-name nil)
|
|
268 (insert ?\n) (setq n (1+ n)))
|
8672
|
269 (if (> n 0)
|
|
270 (shrink-window (min (1- n)
|
|
271 (- (window-height)
|
|
272 window-min-height)))))
|
3342
|
273 (delete-region (point-min) (point))
|
|
274 (set-buffer-modified-p modified)
|
|
275 (goto-char p)
|
|
276 (select-window w)
|
|
277 ;; Make sure we unbind buffer-read-only
|
|
278 ;; with the proper current buffer.
|
|
279 (set-buffer buffer))))))
|
2529
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
280
|
36
|
281 (define-key ctl-x-map "2" 'split-window-vertically)
|
707
|
282 (define-key ctl-x-map "3" 'split-window-horizontally)
|
36
|
283 (define-key ctl-x-map "}" 'enlarge-window-horizontally)
|
|
284 (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>
diff
changeset
|
285 (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>
diff
changeset
|
286 (define-key ctl-x-map "+" 'balance-windows)
|
656
|
287
|
|
288 ;;; windows.el ends here
|