Mercurial > emacs
annotate lisp/window.el @ 782:a6d00bdb2b60
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 15 Jul 1992 17:54:00 +0000 |
parents | c2dbf1fe0506 |
children | cd6b1e1da3fc |
rev | line source |
---|---|
656
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
419
diff
changeset
|
1 ;;; windows.el --- GNU Emacs window commands aside from those written in C. |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
2 |
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
3 ;; Maintainer: FSF |
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
4 ;; Last-Modified: 21 Dec 1987 |
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
5 |
707 | 6 ;;; Copyright (C) 1985, 1989, 1992 Free Software Foundation, Inc. |
36 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
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 | |
707 | 12 ;; the Free Software Foundation; either version 2, or (at your option) |
36 | 13 ;; any later version. |
14 | |
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. | |
19 | |
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. | |
23 | |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
24 ;;; Code: |
36 | 25 |
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)) | |
35 | |
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) | |
779 | 43 (let ((size (/ (frame-height) count))) |
36 | 44 (walk-windows (function (lambda (w) |
45 (select-window w) | |
46 (enlarge-window (- size (window-height))))) | |
47 'nomini)))) | |
48 | |
698
793483bd29fe
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
656
diff
changeset
|
49 ;;; I think this should be the default; I think people will prefer it--rms. |
382 | 50 |
698
793483bd29fe
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
656
diff
changeset
|
51 (defvar split-window-keep-point t |
382 | 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.") | |
57 | |
36 | 58 (defun split-window-vertically (&optional arg) |
59 "Split current window into two windows, one above the other. | |
108 | 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. | |
382 | 63 |
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. | |
108 | 67 |
382 | 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." | |
36 | 73 (interactive "P") |
74 (let ((old-w (selected-window)) | |
108 | 75 (old-point (point)) |
76 new-w bottom switch) | |
36 | 77 (setq new-w (split-window nil (and arg (prefix-numeric-value arg)))) |
419 | 78 (or split-window-keep-point |
108 | 79 (progn |
382 | 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))))))) | |
36 | 95 |
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)) | |
102 | |
103 (defun enlarge-window-horizontally (arg) | |
104 "Make current window ARG columns wider." | |
105 (interactive "p") | |
106 (enlarge-window arg t)) | |
107 | |
108 (defun shrink-window-horizontally (arg) | |
109 "Make current window ARG columns narrower." | |
110 (interactive "p") | |
111 (shrink-window arg t)) | |
112 | |
113 (defun window-config-to-register (name) | |
114 "Save the current window configuration in register REG (a letter). | |
115 It can be later retrieved using \\[M-x register-to-window-config]." | |
116 (interactive "cSave window configuration in register: ") | |
117 (set-register name (current-window-configuration))) | |
118 | |
119 (defun register-to-window-config (name) | |
120 "Restore (make current) the window configuration in register REG (a letter). | |
121 Use with a register previously set with \\[window-config-to-register]." | |
122 (interactive "cRestore window configuration from register: ") | |
123 (set-window-configuration (get-register name))) | |
124 | |
125 (define-key ctl-x-map "2" 'split-window-vertically) | |
707 | 126 (define-key ctl-x-map "3" 'split-window-horizontally) |
36 | 127 (define-key ctl-x-map "6" 'window-config-to-register) |
128 (define-key ctl-x-map "7" 'register-to-window-config) | |
129 (define-key ctl-x-map "}" 'enlarge-window-horizontally) | |
130 (define-key ctl-x-map "{" 'shrink-window-horizontally) | |
656
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
419
diff
changeset
|
131 |
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
419
diff
changeset
|
132 ;;; windows.el ends here |