Mercurial > emacs
annotate lisp/window.el @ 707:e4253da532fb
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Wed, 10 Jun 1992 02:47:07 +0000 |
parents | 793483bd29fe |
children | 9c89fd7ddd41 |
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. |
707 | 2 ;;; Copyright (C) 1985, 1989, 1992 Free Software Foundation, Inc. |
36 | 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 | |
707 | 8 ;; the Free Software Foundation; either version 2, or (at your option) |
36 | 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 | |
698
793483bd29fe
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
656
diff
changeset
|
44 ;;; I think this should be the default; I think people will prefer it--rms. |
382 | 45 |
698
793483bd29fe
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
656
diff
changeset
|
46 (defvar split-window-keep-point t |
382 | 47 "*If non-nil, split windows so that both windows keep the original |
48 value of point. This is often more convenient for editing. | |
49 If nil, split windows to minimize redisplay. This is convenient on | |
50 slow terminals, but point may be moved strangely to accommodate the | |
51 redisplay.") | |
52 | |
36 | 53 (defun split-window-vertically (&optional arg) |
54 "Split current window into two windows, one above the other. | |
108 | 55 The uppermost window gets ARG lines and the other gets the rest. |
56 With no argument, split equally or close to it. | |
57 Both windows display the same buffer now current. | |
382 | 58 |
59 If the variable split-window-keep-point is non-nil, both new windows | |
60 will get the same value of point as the current window. This is often | |
61 more convenient for editing. | |
108 | 62 |
382 | 63 Otherwise, we chose window starts so as to minimize the amount of |
64 redisplay; this is convenient on slow terminals. The new selected | |
65 window is the one that the current value of point appears in. The | |
66 value of point can change if the text around point is hidden by the | |
67 new mode line." | |
36 | 68 (interactive "P") |
69 (let ((old-w (selected-window)) | |
108 | 70 (old-point (point)) |
71 new-w bottom switch) | |
36 | 72 (setq new-w (split-window nil (and arg (prefix-numeric-value arg)))) |
419 | 73 (or split-window-keep-point |
108 | 74 (progn |
382 | 75 (save-excursion |
76 (set-buffer (window-buffer)) | |
77 (goto-char (window-start)) | |
78 (vertical-motion (window-height)) | |
79 (set-window-start new-w (point)) | |
80 (if (> (point) (window-point new-w)) | |
81 (set-window-point new-w (point))) | |
82 (vertical-motion -1) | |
83 (setq bottom (point))) | |
84 (if (<= bottom (point)) | |
85 (set-window-point old-w (1- bottom))) | |
86 (if (< (window-start new-w) old-point) | |
87 (progn | |
88 (set-window-point new-w old-point) | |
89 (select-window new-w))))))) | |
36 | 90 |
91 (defun split-window-horizontally (&optional arg) | |
92 "Split current window into two windows side by side. | |
93 This window becomes the leftmost of the two, and gets | |
94 ARG columns. No arg means split equally." | |
95 (interactive "P") | |
96 (split-window nil (and arg (prefix-numeric-value arg)) t)) | |
97 | |
98 (defun enlarge-window-horizontally (arg) | |
99 "Make current window ARG columns wider." | |
100 (interactive "p") | |
101 (enlarge-window arg t)) | |
102 | |
103 (defun shrink-window-horizontally (arg) | |
104 "Make current window ARG columns narrower." | |
105 (interactive "p") | |
106 (shrink-window arg t)) | |
107 | |
108 (defun window-config-to-register (name) | |
109 "Save the current window configuration in register REG (a letter). | |
110 It can be later retrieved using \\[M-x register-to-window-config]." | |
111 (interactive "cSave window configuration in register: ") | |
112 (set-register name (current-window-configuration))) | |
113 | |
114 (defun register-to-window-config (name) | |
115 "Restore (make current) the window configuration in register REG (a letter). | |
116 Use with a register previously set with \\[window-config-to-register]." | |
117 (interactive "cRestore window configuration from register: ") | |
118 (set-window-configuration (get-register name))) | |
119 | |
120 (define-key ctl-x-map "2" 'split-window-vertically) | |
707 | 121 (define-key ctl-x-map "3" 'split-window-horizontally) |
36 | 122 (define-key ctl-x-map "6" 'window-config-to-register) |
123 (define-key ctl-x-map "7" 'register-to-window-config) | |
124 (define-key ctl-x-map "}" 'enlarge-window-horizontally) | |
125 (define-key ctl-x-map "{" 'shrink-window-horizontally) | |
656
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
419
diff
changeset
|
126 |
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
419
diff
changeset
|
127 ;;; windows.el ends here |