]> code.delx.au - gnu-emacs/blob - lisp/window.el
(calc-time, calc-date-notation, math-this-year, math-parse-date)
[gnu-emacs] / lisp / window.el
1 ;;; window.el --- GNU Emacs window commands aside from those written in C
2
3 ;; Copyright (C) 1985, 1989, 1992, 1993, 1994, 2000, 2001, 2002, 2004, 2005
4 ;; Free Software Foundation, Inc.
5
6 ;; Maintainer: FSF
7 ;; Keywords: internal
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; Window tree functions.
29
30 ;;; Code:
31
32 (defvar window-size-fixed nil
33 "*Non-nil in a buffer means windows displaying the buffer are fixed-size.
34 If the value is`height', then only the window's height is fixed.
35 If the value is `width', then only the window's width is fixed.
36 Any other non-nil value fixes both the width and the height.
37 Emacs won't change the size of any window displaying that buffer,
38 unless you explicitly change the size, or Emacs has no other choice.")
39 (make-variable-buffer-local 'window-size-fixed)
40
41 (defmacro save-selected-window (&rest body)
42 "Execute BODY, then select the window that was selected before BODY.
43 Also restore the selected window of each frame as it was at the start
44 of this construct.
45 However, if a window has become dead, don't get an error,
46 just refrain from reselecting it.
47 Return the value of the last form in BODY."
48 `(let ((save-selected-window-window (selected-window))
49 ;; It is necessary to save all of these, because calling
50 ;; select-window changes frame-selected-window for whatever
51 ;; frame that window is in.
52 (save-selected-window-alist
53 (mapcar (lambda (frame) (list frame (frame-selected-window frame)))
54 (frame-list))))
55 (unwind-protect
56 (progn ,@body)
57 (dolist (elt save-selected-window-alist)
58 (and (frame-live-p (car elt))
59 (window-live-p (cadr elt))
60 (set-frame-selected-window (car elt) (cadr elt))))
61 (if (window-live-p save-selected-window-window)
62 (select-window save-selected-window-window)))))
63
64 (defun window-body-height (&optional window)
65 "Return number of lines in window WINDOW for actual buffer text.
66 This does not include the mode line (if any) or the header line (if any)."
67 (or window (setq window (selected-window)))
68 (if (window-minibuffer-p window)
69 (window-height window)
70 (with-current-buffer (window-buffer window)
71 (max 1 (- (window-height window)
72 (if mode-line-format 1 0)
73 (if header-line-format 1 0))))))
74
75 (defun one-window-p (&optional nomini all-frames)
76 "Return non-nil if the selected window is the only window.
77 Optional arg NOMINI non-nil means don't count the minibuffer
78 even if it is active. Otherwise, the minibuffer is counted
79 when it is active.
80
81 The optional arg ALL-FRAMES t means count windows on all frames.
82 If it is `visible', count windows on all visible frames.
83 ALL-FRAMES nil or omitted means count only the selected frame,
84 plus the minibuffer it uses (which may be on another frame).
85 ALL-FRAMES 0 means count all windows in all visible or iconified frames.
86 If ALL-FRAMES is anything else, count only the selected frame."
87 (let ((base-window (selected-window)))
88 (if (and nomini (eq base-window (minibuffer-window)))
89 (setq base-window (next-window base-window)))
90 (eq base-window
91 (next-window base-window (if nomini 'arg) all-frames))))
92
93 (defun window-current-scroll-bars (&optional window)
94 "Return the current scroll-bar settings in window WINDOW.
95 Value is a cons (VERTICAL . HORISONTAL) where VERTICAL specifies the
96 current location of the vertical scroll-bars (left, right, or nil),
97 and HORISONTAL specifies the current location of the horisontal scroll
98 bars (top, bottom, or nil)."
99 (let ((vert (nth 2 (window-scroll-bars window)))
100 (hor nil))
101 (when (or (eq vert t) (eq hor t))
102 (let ((fcsb (frame-current-scroll-bars
103 (window-frame (or window (selected-window))))))
104 (if (eq vert t)
105 (setq vert (car fcsb)))
106 (if (eq hor t)
107 (setq hor (cdr fcsb)))))
108 (cons vert hor)))
109
110 (defun walk-windows (proc &optional minibuf all-frames)
111 "Cycle through all visible windows, calling PROC for each one.
112 PROC is called with a window as argument.
113
114 Optional second arg MINIBUF t means count the minibuffer window even
115 if not active. MINIBUF nil or omitted means count the minibuffer iff
116 it is active. MINIBUF neither t nor nil means not to count the
117 minibuffer even if it is active.
118
119 Several frames may share a single minibuffer; if the minibuffer
120 counts, all windows on all frames that share that minibuffer count
121 too. Therefore, if you are using a separate minibuffer frame
122 and the minibuffer is active and MINIBUF says it counts,
123 `walk-windows' includes the windows in the frame from which you
124 entered the minibuffer, as well as the minibuffer window.
125
126 ALL-FRAMES is the optional third argument.
127 ALL-FRAMES nil or omitted means cycle within the frames as specified above.
128 ALL-FRAMES = `visible' means include windows on all visible frames.
129 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
130 ALL-FRAMES = t means include windows on all frames including invisible frames.
131 If ALL-FRAMES is a frame, it means include windows on that frame.
132 Anything else means restrict to the selected frame."
133 ;; If we start from the minibuffer window, don't fail to come back to it.
134 (if (window-minibuffer-p (selected-window))
135 (setq minibuf t))
136 (save-selected-window
137 (if (framep all-frames)
138 (select-window (frame-first-window all-frames)))
139 (let* (walk-windows-already-seen
140 (walk-windows-current (selected-window)))
141 (while (progn
142 (setq walk-windows-current
143 (next-window walk-windows-current minibuf all-frames))
144 (not (memq walk-windows-current walk-windows-already-seen)))
145 (setq walk-windows-already-seen
146 (cons walk-windows-current walk-windows-already-seen))
147 (funcall proc walk-windows-current)))))
148
149 (defun get-window-with-predicate (predicate &optional minibuf
150 all-frames default)
151 "Return a window satisfying PREDICATE.
152
153 This function cycles through all visible windows using `walk-windows',
154 calling PREDICATE on each one. PREDICATE is called with a window as
155 argument. The first window for which PREDICATE returns a non-nil
156 value is returned. If no window satisfies PREDICATE, DEFAULT is
157 returned.
158
159 Optional second arg MINIBUF t means count the minibuffer window even
160 if not active. MINIBUF nil or omitted means count the minibuffer iff
161 it is active. MINIBUF neither t nor nil means not to count the
162 minibuffer even if it is active.
163
164 Several frames may share a single minibuffer; if the minibuffer
165 counts, all windows on all frames that share that minibuffer count
166 too. Therefore, if you are using a separate minibuffer frame
167 and the minibuffer is active and MINIBUF says it counts,
168 `walk-windows' includes the windows in the frame from which you
169 entered the minibuffer, as well as the minibuffer window.
170
171 ALL-FRAMES is the optional third argument.
172 ALL-FRAMES nil or omitted means cycle within the frames as specified above.
173 ALL-FRAMES = `visible' means include windows on all visible frames.
174 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
175 ALL-FRAMES = t means include windows on all frames including invisible frames.
176 If ALL-FRAMES is a frame, it means include windows on that frame.
177 Anything else means restrict to the selected frame."
178 (catch 'found
179 (walk-windows #'(lambda (window)
180 (when (funcall predicate window)
181 (throw 'found window)))
182 minibuf all-frames)
183 default))
184
185 (defalias 'some-window 'get-window-with-predicate)
186
187 (defun minibuffer-window-active-p (window)
188 "Return t if WINDOW (a minibuffer window) is now active."
189 (eq window (active-minibuffer-window)))
190 \f
191 (defun count-windows (&optional minibuf)
192 "Return the number of visible windows.
193 This counts the windows in the selected frame and (if the minibuffer is
194 to be counted) its minibuffer frame (if that's not the same frame).
195 The optional arg MINIBUF non-nil means count the minibuffer
196 even if it is inactive."
197 (let ((count 0))
198 (walk-windows (function (lambda (w)
199 (setq count (+ count 1))))
200 minibuf)
201 count))
202
203 (defun window-safely-shrinkable-p (&optional window)
204 "Non-nil if the WINDOW can be shrunk without shrinking other windows.
205 If WINDOW is nil or omitted, it defaults to the currently selected window."
206 (with-selected-window (or window (selected-window))
207 (let ((edges (window-edges)))
208 (or (= (nth 2 edges) (nth 2 (window-edges (previous-window))))
209 (= (nth 0 edges) (nth 0 (window-edges (next-window))))))))
210
211
212 (defun balance-windows ()
213 "Make all visible windows the same height (approximately)."
214 (interactive)
215 (let ((count -1) levels newsizes level-size
216 ;; Don't count the lines that are above the uppermost windows.
217 ;; (These are the menu bar lines, if any.)
218 (mbl (nth 1 (window-edges (frame-first-window (selected-frame)))))
219 (last-window (previous-window (frame-first-window (selected-frame))))
220 ;; Don't count the lines that are past the lowest main window.
221 total)
222 ;; Bottom edge of last window determines what size we have to work with.
223 (setq total
224 (+ (window-height last-window)
225 (nth 1 (window-edges last-window))))
226
227 ;; Find all the different vpos's at which windows start,
228 ;; then count them. But ignore levels that differ by only 1.
229 (let (tops (prev-top -2))
230 (walk-windows (function (lambda (w)
231 (setq tops (cons (nth 1 (window-edges w))
232 tops))))
233 'nomini)
234 (setq tops (sort tops '<))
235 (while tops
236 (if (> (car tops) (1+ prev-top))
237 (setq prev-top (car tops)
238 count (1+ count)))
239 (setq levels (cons (cons (car tops) count) levels))
240 (setq tops (cdr tops)))
241 (setq count (1+ count)))
242 ;; Subdivide the frame into desired number of vertical levels.
243 (setq level-size (/ (- total mbl) count))
244 (save-selected-window
245 ;; Set up NEWSIZES to map windows to their desired sizes.
246 ;; If a window ends at the bottom level, don't include
247 ;; it in NEWSIZES. Those windows get the right sizes
248 ;; by adjusting the ones above them.
249 (walk-windows (function
250 (lambda (w)
251 (let ((newtop (cdr (assq (nth 1 (window-edges w))
252 levels)))
253 (newbot (cdr (assq (+ (window-height w)
254 (nth 1 (window-edges w)))
255 levels))))
256 (if newbot
257 (setq newsizes
258 (cons (cons w (* level-size (- newbot newtop)))
259 newsizes))))))
260 'nomini)
261 ;; Make walk-windows start with the topmost window.
262 (select-window (previous-window (frame-first-window (selected-frame))))
263 (let (done (count 0))
264 ;; Give each window its precomputed size, or at least try.
265 ;; Keep trying until they all get the intended sizes,
266 ;; but not more than 3 times (to prevent infinite loop).
267 (while (and (not done) (< count 3))
268 (setq done t)
269 (setq count (1+ count))
270 (walk-windows (function (lambda (w)
271 (select-window w)
272 (let ((newsize (cdr (assq w newsizes))))
273 (when newsize
274 (enlarge-window (- newsize
275 (window-height))
276 nil t)
277 (unless (= (window-height) newsize)
278 (setq done nil))))))
279 'nomini))))))
280 \f
281 ;; I think this should be the default; I think people will prefer it--rms.
282 (defcustom split-window-keep-point t
283 "*If non-nil, \\[split-window-vertically] keeps the original point \
284 in both children.
285 This is often more convenient for editing.
286 If nil, adjust point in each of the two windows to minimize redisplay.
287 This is convenient on slow terminals, but point can move strangely.
288
289 This option applies only to `split-window-vertically' and
290 functions that call it. `split-window' always keeps the original
291 point in both children,"
292 :type 'boolean
293 :group 'windows)
294
295 (defun split-window-vertically (&optional arg)
296 "Split current window into two windows, one above the other.
297 The uppermost window gets ARG lines and the other gets the rest.
298 Negative ARG means select the size of the lowermost window instead.
299 With no argument, split equally or close to it.
300 Both windows display the same buffer now current.
301
302 If the variable `split-window-keep-point' is non-nil, both new windows
303 will get the same value of point as the current window. This is often
304 more convenient for editing. The upper window is the selected window.
305
306 Otherwise, we choose window starts so as to minimize the amount of
307 redisplay; this is convenient on slow terminals. The new selected
308 window is the one that the current value of point appears in. The
309 value of point can change if the text around point is hidden by the
310 new mode line.
311
312 Regardless of the value of `split-window-keep-point', the upper
313 window is the original one and the return value is the new, lower
314 window."
315 (interactive "P")
316 (let ((old-w (selected-window))
317 (old-point (point))
318 (size (and arg (prefix-numeric-value arg)))
319 (window-full-p nil)
320 new-w bottom switch moved)
321 (and size (< size 0) (setq size (+ (window-height) size)))
322 (setq new-w (split-window nil size))
323 (or split-window-keep-point
324 (progn
325 (save-excursion
326 (set-buffer (window-buffer))
327 (goto-char (window-start))
328 (setq moved (vertical-motion (window-height)))
329 (set-window-start new-w (point))
330 (if (> (point) (window-point new-w))
331 (set-window-point new-w (point)))
332 (and (= moved (window-height))
333 (progn
334 (setq window-full-p t)
335 (vertical-motion -1)))
336 (setq bottom (point)))
337 (and window-full-p
338 (<= bottom (point))
339 (set-window-point old-w (1- bottom)))
340 (and window-full-p
341 (<= (window-start new-w) old-point)
342 (progn
343 (set-window-point new-w old-point)
344 (select-window new-w)))))
345 (split-window-save-restore-data new-w old-w)))
346
347 ;; This is to avoid compiler warnings.
348 (defvar view-return-to-alist)
349
350 (defun split-window-save-restore-data (new-w old-w)
351 (with-current-buffer (window-buffer)
352 (if view-mode
353 (let ((old-info (assq old-w view-return-to-alist)))
354 (if old-info
355 (push (cons new-w (cons (car (cdr old-info)) t))
356 view-return-to-alist))))
357 new-w))
358
359 (defun split-window-horizontally (&optional arg)
360 "Split current window into two windows side by side.
361 This window becomes the leftmost of the two, and gets ARG columns.
362 Negative ARG means select the size of the rightmost window instead.
363 The argument includes the width of the window's scroll bar; if there
364 are no scroll bars, it includes the width of the divider column
365 to the window's right, if any. No ARG means split equally.
366
367 The original, leftmost window remains selected.
368 The return value is the new, rightmost window."
369 (interactive "P")
370 (let ((old-w (selected-window))
371 (size (and arg (prefix-numeric-value arg))))
372 (and size (< size 0)
373 (setq size (+ (window-width) size)))
374 (split-window-save-restore-data (split-window nil size t) old-w)))
375
376 \f
377 (defun set-window-text-height (window height)
378 "Sets the height in lines of the text display area of WINDOW to HEIGHT.
379 This doesn't include the mode-line (or header-line if any) or any
380 partial-height lines in the text display area.
381
382 If WINDOW is nil, the selected window is used.
383
384 Note that the current implementation of this function cannot always set
385 the height exactly, but attempts to be conservative, by allocating more
386 lines than are actually needed in the case where some error may be present."
387 (let ((delta (- height (window-text-height window))))
388 (unless (zerop delta)
389 (let ((window-min-height 1))
390 (if (and window (not (eq window (selected-window))))
391 (save-selected-window
392 (select-window window)
393 (enlarge-window delta))
394 (enlarge-window delta))))))
395
396 \f
397 (defun enlarge-window-horizontally (arg)
398 "Make current window ARG columns wider."
399 (interactive "p")
400 (enlarge-window arg t))
401
402 (defun shrink-window-horizontally (arg)
403 "Make current window ARG columns narrower."
404 (interactive "p")
405 (shrink-window arg t))
406
407 (defun window-buffer-height (window)
408 "Return the height (in screen lines) of the buffer that WINDOW is displaying."
409 (with-current-buffer (window-buffer window)
410 (max 1
411 (count-screen-lines (point-min) (point-max)
412 ;; If buffer ends with a newline, ignore it when
413 ;; counting height unless point is after it.
414 (eobp)
415 window))))
416
417 (defun count-screen-lines (&optional beg end count-final-newline window)
418 "Return the number of screen lines in the region.
419 The number of screen lines may be different from the number of actual lines,
420 due to line breaking, display table, etc.
421
422 Optional arguments BEG and END default to `point-min' and `point-max'
423 respectively.
424
425 If region ends with a newline, ignore it unless optional third argument
426 COUNT-FINAL-NEWLINE is non-nil.
427
428 The optional fourth argument WINDOW specifies the window used for obtaining
429 parameters such as width, horizontal scrolling, and so on. The default is
430 to use the selected window's parameters.
431
432 Like `vertical-motion', `count-screen-lines' always uses the current buffer,
433 regardless of which buffer is displayed in WINDOW. This makes possible to use
434 `count-screen-lines' in any buffer, whether or not it is currently displayed
435 in some window."
436 (unless beg
437 (setq beg (point-min)))
438 (unless end
439 (setq end (point-max)))
440 (if (= beg end)
441 0
442 (save-excursion
443 (save-restriction
444 (widen)
445 (narrow-to-region (min beg end)
446 (if (and (not count-final-newline)
447 (= ?\n (char-before (max beg end))))
448 (1- (max beg end))
449 (max beg end)))
450 (goto-char (point-min))
451 (1+ (vertical-motion (buffer-size) window))))))
452
453 (defun fit-window-to-buffer (&optional window max-height min-height)
454 "Make WINDOW the right size to display its contents exactly.
455 If WINDOW is omitted or nil, it defaults to the selected window.
456 If the optional argument MAX-HEIGHT is supplied, it is the maximum height
457 the window is allowed to be, defaulting to the frame height.
458 If the optional argument MIN-HEIGHT is supplied, it is the minimum
459 height the window is allowed to be, defaulting to `window-min-height'.
460
461 The heights in MAX-HEIGHT and MIN-HEIGHT include the mode-line and/or
462 header-line."
463 (interactive)
464
465 (when (null window)
466 (setq window (selected-window)))
467 (when (null max-height)
468 (setq max-height (frame-height (window-frame window))))
469
470 (let* ((buf
471 ;; Buffer that is displayed in WINDOW
472 (window-buffer window))
473 (window-height
474 ;; The current height of WINDOW
475 (window-height window))
476 (desired-height
477 ;; The height necessary to show the buffer displayed by WINDOW
478 ;; (`count-screen-lines' always works on the current buffer).
479 (with-current-buffer buf
480 (+ (count-screen-lines)
481 ;; If the buffer is empty, (count-screen-lines) is
482 ;; zero. But, even in that case, we need one text line
483 ;; for cursor.
484 (if (= (point-min) (point-max))
485 1 0)
486 ;; For non-minibuffers, count the mode-line, if any
487 (if (and (not (window-minibuffer-p window))
488 mode-line-format)
489 1 0)
490 ;; Count the header-line, if any
491 (if header-line-format 1 0))))
492 (delta
493 ;; Calculate how much the window height has to change to show
494 ;; desired-height lines, constrained by MIN-HEIGHT and MAX-HEIGHT.
495 (- (max (min desired-height max-height)
496 (or min-height window-min-height))
497 window-height))
498 ;; We do our own height checking, so avoid any restrictions due to
499 ;; window-min-height.
500 (window-min-height 1))
501
502 ;; Don't try to redisplay with the cursor at the end
503 ;; on its own line--that would force a scroll and spoil things.
504 (when (with-current-buffer buf
505 (and (eobp) (bolp) (not (bobp))))
506 (set-window-point window (1- (window-point window))))
507
508 (save-selected-window
509 (select-window window)
510
511 ;; Adjust WINDOW to the nominally correct size (which may actually
512 ;; be slightly off because of variable height text, etc).
513 (unless (zerop delta)
514 (enlarge-window delta))
515
516 ;; Check if the last line is surely fully visible. If not,
517 ;; enlarge the window.
518 (let ((end (with-current-buffer buf
519 (save-excursion
520 (goto-char (point-max))
521 (when (and (bolp) (not (bobp)))
522 ;; Don't include final newline
523 (backward-char 1))
524 (when truncate-lines
525 ;; If line-wrapping is turned off, test the
526 ;; beginning of the last line for visibility
527 ;; instead of the end, as the end of the line
528 ;; could be invisible by virtue of extending past
529 ;; the edge of the window.
530 (forward-line 0))
531 (point)))))
532 (set-window-vscroll window 0)
533 (while (and (< desired-height max-height)
534 (= desired-height (window-height window))
535 (not (pos-visible-in-window-p end window)))
536 (enlarge-window 1)
537 (setq desired-height (1+ desired-height)))))))
538
539 (defun shrink-window-if-larger-than-buffer (&optional window)
540 "Shrink the WINDOW to be as small as possible to display its contents.
541 If WINDOW is omitted or nil, it defaults to the selected window.
542 Do not shrink to less than `window-min-height' lines.
543 Do nothing if the buffer contains more lines than the present window height,
544 or if some of the window's contents are scrolled out of view,
545 or if shrinking this window would also shrink another window.
546 or if the window is the only window of its frame.
547 Return non-nil if the window was shrunk."
548 (interactive)
549 (when (null window)
550 (setq window (selected-window)))
551 (let* ((frame (window-frame window))
552 (mini (frame-parameter frame 'minibuffer))
553 (edges (window-edges window)))
554 (if (and (not (eq window (frame-root-window frame)))
555 (window-safely-shrinkable-p)
556 (pos-visible-in-window-p (point-min) window)
557 (not (eq mini 'only))
558 (or (not mini)
559 (let ((mini-window (minibuffer-window frame)))
560 (or (null mini-window)
561 (not (eq frame (window-frame mini-window)))
562 (< (nth 3 edges)
563 (nth 1 (window-edges mini-window)))
564 (> (nth 1 edges)
565 (frame-parameter frame 'menu-bar-lines))))))
566 (fit-window-to-buffer window (window-height window)))))
567
568 (defun kill-buffer-and-window ()
569 "Kill the current buffer and delete the selected window."
570 (interactive)
571 (let ((window-to-delete (selected-window))
572 (delete-window-hook (lambda ()
573 (condition-case nil
574 (delete-window)
575 (error nil)))))
576 (add-hook 'kill-buffer-hook delete-window-hook t t)
577 (if (kill-buffer (current-buffer))
578 ;; If `delete-window' failed before, we rerun it to regenerate
579 ;; the error so it can be seen in the minibuffer.
580 (when (eq (selected-window) window-to-delete)
581 (delete-window))
582 (remove-hook 'kill-buffer-hook delete-window-hook t))))
583
584 (defun quit-window (&optional kill window)
585 "Quit the current buffer. Bury it, and maybe delete the selected frame.
586 \(The frame is deleted if it is contains a dedicated window for the buffer.)
587 With a prefix argument, kill the buffer instead.
588
589 Noninteractively, if KILL is non-nil, then kill the current buffer,
590 otherwise bury it.
591
592 If WINDOW is non-nil, it specifies a window; we delete that window,
593 and the buffer that is killed or buried is the one in that window."
594 (interactive "P")
595 (let ((buffer (window-buffer window))
596 (frame (window-frame (or window (selected-window))))
597 (window-solitary
598 (save-selected-window
599 (if window
600 (select-window window))
601 (one-window-p t)))
602 window-handled)
603
604 (save-selected-window
605 (if window
606 (select-window window))
607 (or (window-minibuffer-p)
608 (window-dedicated-p (selected-window))
609 (switch-to-buffer (other-buffer))))
610
611 ;; Get rid of the frame, if it has just one dedicated window
612 ;; and other visible frames exist.
613 (and (or (window-minibuffer-p) (window-dedicated-p window))
614 (delq frame (visible-frame-list))
615 window-solitary
616 (if (and (eq default-minibuffer-frame frame)
617 (= 1 (length (minibuffer-frame-list))))
618 (setq window nil)
619 (delete-frame frame)
620 (setq window-handled t)))
621
622 ;; Deal with the buffer.
623 (if kill
624 (kill-buffer buffer)
625 (bury-buffer buffer))
626
627 ;; Maybe get rid of the window.
628 (and window (not window-handled) (not window-solitary)
629 (delete-window window))))
630
631 (defun handle-select-window (event)
632 "Handle select-window events."
633 (interactive "e")
634 (let ((window (posn-window (event-start event))))
635 (if (and (window-live-p window)
636 ;; Don't switch if we're currently in the minibuffer.
637 ;; This tries to work around problems where the minibuffer gets
638 ;; unselected unexpectedly, and where you then have to move
639 ;; your mouse all the way down to the minibuffer to select it.
640 (not (window-minibuffer-p (selected-window)))
641 ;; Don't switch to a minibuffer window unless it's active.
642 (or (not (window-minibuffer-p window))
643 (minibuffer-window-active-p window)))
644 (select-window window))))
645
646 (define-key ctl-x-map "2" 'split-window-vertically)
647 (define-key ctl-x-map "3" 'split-window-horizontally)
648 (define-key ctl-x-map "}" 'enlarge-window-horizontally)
649 (define-key ctl-x-map "{" 'shrink-window-horizontally)
650 (define-key ctl-x-map "-" 'shrink-window-if-larger-than-buffer)
651 (define-key ctl-x-map "+" 'balance-windows)
652 (define-key ctl-x-4-map "0" 'kill-buffer-and-window)
653
654 ;; arch-tag: b508dfcc-c353-4c37-89fa-e773fe10cea9
655 ;;; window.el ends here