annotate lisp/window.el @ 765:e4093444f9f8

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