annotate lisp/window.el @ 538:c3e1fe268e78

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Thu, 06 Feb 1992 01:02:59 +0000
parents 4fa4f423f981
children d74e65773062
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
1 ;; GNU Emacs window commands aside from those written in C.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1985, 1989 Free Software Foundation, Inc.
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
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
8 ;; the Free Software Foundation; either version 1, or (at your option)
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
382
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
44 ;;; Many people find the minimal-redisplay window splitting annoying,
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
45 ;;; so we make it an option.
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
46
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
47 (defvar split-window-keep-point nil
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
48 "*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
49 value of point. This is often more convenient for editing.
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
50 If nil, split windows to minimize redisplay. This is convenient on
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
51 slow terminals, but point may be moved strangely to accommodate the
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
52 redisplay.")
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
53
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
54 (defun split-window-vertically (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
55 "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
56 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
57 With no argument, split equally or close to it.
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
58 Both windows display the same buffer now current.
382
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
59
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
60 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
61 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
62 more convenient for editing.
108
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
63
382
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
64 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
65 redisplay; this is convenient on slow terminals. The new selected
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
66 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
67 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
68 new mode line."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
69 (interactive "P")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
70 (let ((old-w (selected-window))
108
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
71 (old-point (point))
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
72 new-w bottom switch)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
73 (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
74 (or split-window-keep-point
108
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
75 (progn
382
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
76 (save-excursion
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
77 (set-buffer (window-buffer))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
78 (goto-char (window-start))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
79 (vertical-motion (window-height))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
80 (set-window-start new-w (point))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
81 (if (> (point) (window-point new-w))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
82 (set-window-point new-w (point)))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
83 (vertical-motion -1)
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
84 (setq bottom (point)))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
85 (if (<= bottom (point))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
86 (set-window-point old-w (1- bottom)))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
87 (if (< (window-start new-w) old-point)
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
88 (progn
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
89 (set-window-point new-w old-point)
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
90 (select-window new-w)))))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
91
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
92 (defun split-window-horizontally (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
93 "Split current window into two windows side by side.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
94 This window becomes the leftmost of the two, and gets
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
95 ARG columns. No arg means split equally."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
96 (interactive "P")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
97 (split-window nil (and arg (prefix-numeric-value arg)) t))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
98
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
99 (defun enlarge-window-horizontally (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
100 "Make current window ARG columns wider."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
101 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
102 (enlarge-window arg t))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
103
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
104 (defun shrink-window-horizontally (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
105 "Make current window ARG columns narrower."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
106 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
107 (shrink-window arg t))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
108
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
109 (defun window-config-to-register (name)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
110 "Save the current window configuration in register REG (a letter).
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
111 It can be later retrieved using \\[M-x register-to-window-config]."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
112 (interactive "cSave window configuration in register: ")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
113 (set-register name (current-window-configuration)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
114
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
115 (defun register-to-window-config (name)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
116 "Restore (make current) the window configuration in register REG (a letter).
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
117 Use with a register previously set with \\[window-config-to-register]."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
118 (interactive "cRestore window configuration from register: ")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
119 (set-window-configuration (get-register name)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
120
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
121 (define-key ctl-x-map "2" 'split-window-vertically)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
122 (define-key ctl-x-map "5" 'split-window-horizontally)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
123 (define-key ctl-x-map "6" 'window-config-to-register)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
124 (define-key ctl-x-map "7" 'register-to-window-config)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
125 (define-key ctl-x-map "}" 'enlarge-window-horizontally)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
126 (define-key ctl-x-map "{" 'shrink-window-horizontally)