Mercurial > emacs
annotate lisp/window.el @ 3333:962106f58afe
(interval_deletion_adjustment): Delete unreachable abort.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 31 May 1993 00:08:24 +0000 |
parents | f4d37be94734 |
children | ce8aa0ba8b08 |
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. |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
2 |
841 | 3 ;;; Copyright (C) 1985, 1989, 1992 Free Software Foundation, Inc. |
4 | |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
5 ;; Maintainer: FSF |
36 | 6 |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
707 | 11 ;; the Free Software Foundation; either version 2, or (at your option) |
36 | 12 ;; any later version. |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
707
diff
changeset
|
23 ;;; Code: |
36 | 24 |
25 (defun count-windows (&optional minibuf) | |
26 "Returns the number of visible windows. | |
27 Optional arg NO-MINI non-nil means don't count the minibuffer | |
28 even if it is active." | |
29 (let ((count 0)) | |
30 (walk-windows (function (lambda () | |
31 (setq count (+ count 1)))) | |
32 minibuf) | |
33 count)) | |
34 | |
35 (defun balance-windows () | |
36 "Makes all visible windows the same size (approximately)." | |
37 (interactive) | |
38 (let ((count 0)) | |
39 (walk-windows (function (lambda (w) | |
40 (setq count (+ count 1)))) | |
41 'nomini) | |
779 | 42 (let ((size (/ (frame-height) count))) |
36 | 43 (walk-windows (function (lambda (w) |
44 (select-window w) | |
45 (enlarge-window (- size (window-height))))) | |
46 'nomini)))) | |
47 | |
698
793483bd29fe
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
656
diff
changeset
|
48 ;;; I think this should be the default; I think people will prefer it--rms. |
382 | 49 |
698
793483bd29fe
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
656
diff
changeset
|
50 (defvar split-window-keep-point t |
382 | 51 "*If non-nil, split windows so that both windows keep the original |
52 value of point. This is often more convenient for editing. | |
53 If nil, split windows to minimize redisplay. This is convenient on | |
54 slow terminals, but point may be moved strangely to accommodate the | |
55 redisplay.") | |
56 | |
36 | 57 (defun split-window-vertically (&optional arg) |
58 "Split current window into two windows, one above the other. | |
108 | 59 The uppermost window gets ARG lines and the other gets the rest. |
60 With no argument, split equally or close to it. | |
61 Both windows display the same buffer now current. | |
382 | 62 |
63 If the variable split-window-keep-point is non-nil, both new windows | |
64 will get the same value of point as the current window. This is often | |
65 more convenient for editing. | |
108 | 66 |
382 | 67 Otherwise, we chose window starts so as to minimize the amount of |
68 redisplay; this is convenient on slow terminals. The new selected | |
69 window is the one that the current value of point appears in. The | |
70 value of point can change if the text around point is hidden by the | |
71 new mode line." | |
36 | 72 (interactive "P") |
73 (let ((old-w (selected-window)) | |
108 | 74 (old-point (point)) |
75 new-w bottom switch) | |
36 | 76 (setq new-w (split-window nil (and arg (prefix-numeric-value arg)))) |
419 | 77 (or split-window-keep-point |
108 | 78 (progn |
382 | 79 (save-excursion |
80 (set-buffer (window-buffer)) | |
81 (goto-char (window-start)) | |
82 (vertical-motion (window-height)) | |
83 (set-window-start new-w (point)) | |
84 (if (> (point) (window-point new-w)) | |
85 (set-window-point new-w (point))) | |
86 (vertical-motion -1) | |
87 (setq bottom (point))) | |
88 (if (<= bottom (point)) | |
89 (set-window-point old-w (1- bottom))) | |
90 (if (< (window-start new-w) old-point) | |
91 (progn | |
92 (set-window-point new-w old-point) | |
3253
f4d37be94734
(split-window-vertically): Return the new window.
Richard M. Stallman <rms@gnu.org>
parents:
2529
diff
changeset
|
93 (select-window new-w))))) |
f4d37be94734
(split-window-vertically): Return the new window.
Richard M. Stallman <rms@gnu.org>
parents:
2529
diff
changeset
|
94 new-w)) |
36 | 95 |
96 (defun split-window-horizontally (&optional arg) | |
97 "Split current window into two windows side by side. | |
98 This window becomes the leftmost of the two, and gets | |
99 ARG columns. No arg means split equally." | |
100 (interactive "P") | |
101 (split-window nil (and arg (prefix-numeric-value arg)) t)) | |
102 | |
103 (defun enlarge-window-horizontally (arg) | |
104 "Make current window ARG columns wider." | |
105 (interactive "p") | |
106 (enlarge-window arg t)) | |
107 | |
108 (defun shrink-window-horizontally (arg) | |
109 "Make current window ARG columns narrower." | |
110 (interactive "p") | |
111 (shrink-window arg t)) | |
112 | |
2529
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
113 (defun shrink-window-if-larger-than-buffer (&optional window) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
114 "Shrink the WINDOW to be as small as possible to display its contents. Do |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
115 nothing if only one window is displayed or if the buffer contains more lines |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
116 than the present window height." |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
117 (save-excursion |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
118 (set-buffer (window-buffer window)) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
119 (let ((w (selected-window)) ;save-window-excursion can't win |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
120 (buffer-file-name buffer-file-name) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
121 (p (point)) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
122 (n 0) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
123 (window-min-height 0) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
124 (buffer-read-only nil) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
125 (modified (buffer-modified-p)) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
126 (buffer (current-buffer))) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
127 (unwind-protect |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
128 (progn |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
129 (select-window (or window w)) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
130 (goto-char (point-min)) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
131 (while (pos-visible-in-window-p (point-max)) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
132 ;; defeat file locking... don't try this at home, kids! |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
133 (setq buffer-file-name nil) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
134 (insert ?\n) (setq n (1+ n))) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
135 (if (> n 0) (shrink-window (1- n)))) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
136 (delete-region (point-min) (point)) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
137 (set-buffer-modified-p modified) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
138 (goto-char p) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
139 (select-window w) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
140 ;; Make sure we unbind buffer-read-only |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
141 ;; with the proper current buffer. |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
142 (set-buffer buffer))))) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
143 |
36 | 144 (define-key ctl-x-map "2" 'split-window-vertically) |
707 | 145 (define-key ctl-x-map "3" 'split-window-horizontally) |
36 | 146 (define-key ctl-x-map "}" 'enlarge-window-horizontally) |
147 (define-key ctl-x-map "{" 'shrink-window-horizontally) | |
2529
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
148 (define-key ctl-x-map "-" 'shrink-window-if-larger-than-buffer) |
bb127c1081af
(shrink-window-if-larger-than-buffer): Moved from electric.el to windows.el,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
149 (define-key ctl-x-map "+" 'balance-windows) |
656
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
419
diff
changeset
|
150 |
d74e65773062
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
419
diff
changeset
|
151 ;;; windows.el ends here |