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