annotate lisp/window.el @ 221:ce8e0192266e

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Mon, 01 Apr 1991 21:16:55 +0000
parents 8644955999f0
children b6465a2ae3e5
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
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
44 (defun split-window-vertically (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
45 "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
46 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
47 With no argument, split equally or close to it.
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
48 Both windows display the same buffer now current.
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
49 The new selected window is the one that the current value of point
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
50 appears in.
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
51
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
52 The value of point can change if the text around point
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
53 is hidden by the new mode line."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
54 (interactive "P")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
55 (let ((old-w (selected-window))
108
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
56 (old-point (point))
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
57 new-w bottom switch)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
58 (setq new-w (split-window nil (and arg (prefix-numeric-value arg))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
59 (save-excursion
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
60 (set-buffer (window-buffer))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
61 (goto-char (window-start))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
62 (vertical-motion (window-height))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
63 (set-window-start new-w (point))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
64 (if (> (point) (window-point new-w))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
65 (set-window-point new-w (point)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
66 (vertical-motion -1)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
67 (setq bottom (point)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
68 (if (<= bottom (point))
108
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
69 (set-window-point old-w (1- bottom)))
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
70 (if (< (window-start new-w) old-point)
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
71 (progn
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
72 (set-window-point new-w old-point)
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
73 (select-window new-w)))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
74
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
75 (defun split-window-horizontally (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
76 "Split current window into two windows side by side.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
77 This window becomes the leftmost of the two, and gets
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
78 ARG columns. No arg means split equally."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
79 (interactive "P")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
80 (split-window nil (and arg (prefix-numeric-value arg)) t))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
81
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
82 (defun enlarge-window-horizontally (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
83 "Make current window ARG columns wider."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
84 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
85 (enlarge-window arg t))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
86
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
87 (defun shrink-window-horizontally (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
88 "Make current window ARG columns narrower."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
89 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
90 (shrink-window arg t))
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 window-config-to-register (name)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
93 "Save the current window configuration in register REG (a letter).
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
94 It can be later retrieved using \\[M-x register-to-window-config]."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
95 (interactive "cSave window configuration in register: ")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
96 (set-register name (current-window-configuration)))
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 register-to-window-config (name)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
99 "Restore (make current) the window configuration in register REG (a letter).
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
100 Use with a register previously set with \\[window-config-to-register]."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
101 (interactive "cRestore window configuration from register: ")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
102 (set-window-configuration (get-register name)))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
103
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
104 (define-key ctl-x-map "2" 'split-window-vertically)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
105 (define-key ctl-x-map "5" 'split-window-horizontally)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
106 (define-key ctl-x-map "6" 'window-config-to-register)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
107 (define-key ctl-x-map "7" 'register-to-window-config)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
108 (define-key ctl-x-map "}" 'enlarge-window-horizontally)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
109 (define-key ctl-x-map "{" 'shrink-window-horizontally)