*** empty log message ***
[emacs.git] / lisp / window.el
blob9cd82d8b0d10d39e8416f2b3b1a30b7b3d38e3b4
1 ;;; windows.el --- GNU Emacs window commands aside from those written in C.
3 ;; Maintainer: FSF
4 ;; Last-Modified: 21 Dec 1987
6 ;;; Copyright (C) 1985, 1989, 1992 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 ;;; Code:
26 (defun count-windows (&optional minibuf)
27 "Returns the number of visible windows.
28 Optional arg NO-MINI non-nil means don't count the minibuffer
29 even if it is active."
30 (let ((count 0))
31 (walk-windows (function (lambda ()
32 (setq count (+ count 1))))
33 minibuf)
34 count))
36 (defun balance-windows ()
37 "Makes all visible windows the same size (approximately)."
38 (interactive)
39 (let ((count 0))
40 (walk-windows (function (lambda (w)
41 (setq count (+ count 1))))
42 'nomini)
43 (let ((size (/ (frame-height) count)))
44 (walk-windows (function (lambda (w)
45 (select-window w)
46 (enlarge-window (- size (window-height)))))
47 'nomini))))
49 ;;; I think this should be the default; I think people will prefer it--rms.
51 (defvar split-window-keep-point t
52 "*If non-nil, split windows so that both windows keep the original
53 value of point. This is often more convenient for editing.
54 If nil, split windows to minimize redisplay. This is convenient on
55 slow terminals, but point may be moved strangely to accommodate the
56 redisplay.")
58 (defun split-window-vertically (&optional arg)
59 "Split current window into two windows, one above the other.
60 The uppermost window gets ARG lines and the other gets the rest.
61 With no argument, split equally or close to it.
62 Both windows display the same buffer now current.
64 If the variable split-window-keep-point is non-nil, both new windows
65 will get the same value of point as the current window. This is often
66 more convenient for editing.
68 Otherwise, we chose window starts so as to minimize the amount of
69 redisplay; this is convenient on slow terminals. The new selected
70 window is the one that the current value of point appears in. The
71 value of point can change if the text around point is hidden by the
72 new mode line."
73 (interactive "P")
74 (let ((old-w (selected-window))
75 (old-point (point))
76 new-w bottom switch)
77 (setq new-w (split-window nil (and arg (prefix-numeric-value arg))))
78 (or split-window-keep-point
79 (progn
80 (save-excursion
81 (set-buffer (window-buffer))
82 (goto-char (window-start))
83 (vertical-motion (window-height))
84 (set-window-start new-w (point))
85 (if (> (point) (window-point new-w))
86 (set-window-point new-w (point)))
87 (vertical-motion -1)
88 (setq bottom (point)))
89 (if (<= bottom (point))
90 (set-window-point old-w (1- bottom)))
91 (if (< (window-start new-w) old-point)
92 (progn
93 (set-window-point new-w old-point)
94 (select-window new-w)))))))
96 (defun split-window-horizontally (&optional arg)
97 "Split current window into two windows side by side.
98 This window becomes the leftmost of the two, and gets
99 ARG columns. No arg means split equally."
100 (interactive "P")
101 (split-window nil (and arg (prefix-numeric-value arg)) t))
103 (defun enlarge-window-horizontally (arg)
104 "Make current window ARG columns wider."
105 (interactive "p")
106 (enlarge-window arg t))
108 (defun shrink-window-horizontally (arg)
109 "Make current window ARG columns narrower."
110 (interactive "p")
111 (shrink-window arg t))
113 (define-key ctl-x-map "2" 'split-window-vertically)
114 (define-key ctl-x-map "3" 'split-window-horizontally)
115 (define-key ctl-x-map "}" 'enlarge-window-horizontally)
116 (define-key ctl-x-map "{" 'shrink-window-horizontally)
118 ;;; windows.el ends here