Mercurial > emacs
annotate lisp/window.el @ 698:793483bd29fe
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 08 Jun 1992 03:55:58 +0000 |
parents | d74e65773062 |
children | e4253da532fb |
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. |
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
419
diff
changeset
|
2 |
36 | 3 ;; Copyright (C) 1985, 1989 Free Software Foundation, Inc. |
4 | |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 ;; it under the terms of the GNU General Public License as published by | |
9 ;; the Free Software Foundation; either version 1, or (at your option) | |
10 ;; any later version. | |
11 | |
12 ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 ;; GNU General Public License for more details. | |
16 | |
17 ;; You should have received a copy of the GNU General Public License | |
18 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | |
21 | |
22 (defun count-windows (&optional minibuf) | |
23 "Returns the number of visible windows. | |
24 Optional arg NO-MINI non-nil means don't count the minibuffer | |
25 even if it is active." | |
26 (let ((count 0)) | |
27 (walk-windows (function (lambda () | |
28 (setq count (+ count 1)))) | |
29 minibuf) | |
30 count)) | |
31 | |
32 (defun balance-windows () | |
33 "Makes all visible windows the same size (approximately)." | |
34 (interactive) | |
35 (let ((count 0)) | |
36 (walk-windows (function (lambda (w) | |
37 (setq count (+ count 1)))) | |
38 'nomini) | |
39 (let ((size (/ (screen-height) count))) | |
40 (walk-windows (function (lambda (w) | |
41 (select-window w) | |
42 (enlarge-window (- size (window-height))))) | |
43 'nomini)))) | |
44 | |
698
793483bd29fe
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
656
diff
changeset
|
45 ;;; I think this should be the default; I think people will prefer it--rms. |
382 | 46 |
698
793483bd29fe
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
656
diff
changeset
|
47 (defvar split-window-keep-point t |
382 | 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) | |
656
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
419
diff
changeset
|
127 |
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
419
diff
changeset
|
128 ;;; windows.el ends here |