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