annotate lisp/window.el @ 8273:cd8665daa5a8

(unread_command_char): Declared.
author Richard M. Stallman <rms@gnu.org>
date Mon, 18 Jul 1994 06:14:10 +0000
parents cc7cd83ccf3f
children 2a2208286955
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3375
13ddc81f0b43 (count-windows): PROC argument of walk-windows takes an argument.
Richard M. Stallman <rms@gnu.org>
parents: 3342
diff changeset
1 ;;; window.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
7300
cc7cd83ccf3f Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 6905
diff changeset
3 ;;; Copyright (C) 1985, 1989, 1992, 1993, 1994 Free Software Foundation, Inc.
841
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 820
diff changeset
4
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 707
diff changeset
5 ;; Maintainer: FSF
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
6
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
8
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
10 ;; 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
11 ;; the Free Software Foundation; either version 2, or (at your option)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
12 ;; any later version.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
13
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
18
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
22
773
9c89fd7ddd41 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 707
diff changeset
23 ;;; Code:
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
24
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
25 (defun count-windows (&optional minibuf)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
26 "Returns the number of visible windows.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
27 Optional arg NO-MINI non-nil means don't count the minibuffer
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
28 even if it is active."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
29 (let ((count 0))
3375
13ddc81f0b43 (count-windows): PROC argument of walk-windows takes an argument.
Richard M. Stallman <rms@gnu.org>
parents: 3342
diff changeset
30 (walk-windows (function (lambda (w)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
31 (setq count (+ count 1))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
32 minibuf)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
33 count))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
34
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
35 (defun balance-windows ()
3724
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
36 "Makes all visible windows the same height (approximately)."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
37 (interactive)
3724
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
38 (let ((count -1) levels newsizes size)
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
39 ;; Find all the different vpos's at which windows start,
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
40 ;; then count them. But ignore levels that differ by only 1.
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
41 (save-window-excursion
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
42 (let (tops (prev-top -2))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
43 (walk-windows (function (lambda (w)
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
44 (setq tops (cons (nth 1 (window-edges w))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
45 tops))))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
46 'nomini)
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
47 (setq tops (sort tops '<))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
48 (while tops
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
49 (if (> (car tops) (1+ prev-top))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
50 (setq prev-top (car tops)
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
51 count (1+ count)))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
52 (setq levels (cons (cons (car tops) count) levels))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
53 (setq tops (cdr tops)))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
54 (setq count (1+ count))))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
55 ;; Subdivide the frame into that many vertical levels.
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
56 (setq size (/ (frame-height) count))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
57 (walk-windows (function
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
58 (lambda (w)
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
59 (select-window w)
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
60 (let ((newtop (cdr (assq (nth 1 (window-edges))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
61 levels)))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
62 (newbot (or (cdr (assq (+ (window-height)
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
63 (nth 1 (window-edges)))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
64 levels))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
65 count)))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
66 (setq newsizes
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
67 (cons (cons w (* size (- newbot newtop)))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
68 newsizes))))))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
69 (walk-windows (function (lambda (w)
3724
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
70 (select-window w)
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
71 (let ((newsize (cdr (assq w newsizes))))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
72 (enlarge-window (- newsize
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
73 (window-height))))))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
74 'nomini)))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
75
698
793483bd29fe *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 656
diff changeset
76 ;;; I think this should be the default; I think people will prefer it--rms.
793483bd29fe *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 656
diff changeset
77 (defvar split-window-keep-point t
3724
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
78 "*If non-nil, split windows keeps the original point in both children.
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
79 This is often more convenient for editing.
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
80 If nil, adjust point in each of the two windows to minimize redisplay.
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
81 This is convenient on slow terminals, but point can move strangely.")
382
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
82
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
83 (defun split-window-vertically (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
84 "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
85 The uppermost window gets ARG lines and the other gets the rest.
6670
b2c5fca3c10c (split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents: 6019
diff changeset
86 Negative arg means select the size of the lowermost window instead.
108
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
87 With no argument, split equally or close to it.
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
88 Both windows display the same buffer now current.
382
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
89
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
90 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
91 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
92 more convenient for editing.
108
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
93
382
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
94 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
95 redisplay; this is convenient on slow terminals. The new selected
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
96 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
97 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
98 new mode line."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
99 (interactive "P")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
100 (let ((old-w (selected-window))
108
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
101 (old-point (point))
6670
b2c5fca3c10c (split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents: 6019
diff changeset
102 (size (and arg (prefix-numeric-value arg)))
108
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
103 new-w bottom switch)
6670
b2c5fca3c10c (split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents: 6019
diff changeset
104 (and size (< size 0) (setq size (+ (window-height) size)))
b2c5fca3c10c (split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents: 6019
diff changeset
105 (setq new-w (split-window nil size))
419
4fa4f423f981 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 382
diff changeset
106 (or split-window-keep-point
108
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
107 (progn
382
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
108 (save-excursion
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
109 (set-buffer (window-buffer))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
110 (goto-char (window-start))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
111 (vertical-motion (window-height))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
112 (set-window-start new-w (point))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
113 (if (> (point) (window-point new-w))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
114 (set-window-point new-w (point)))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
115 (vertical-motion -1)
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
116 (setq bottom (point)))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
117 (if (<= bottom (point))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
118 (set-window-point old-w (1- bottom)))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
119 (if (< (window-start new-w) old-point)
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
120 (progn
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
121 (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
122 (select-window new-w)))))
f4d37be94734 (split-window-vertically): Return the new window.
Richard M. Stallman <rms@gnu.org>
parents: 2529
diff changeset
123 new-w))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
124
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
125 (defun split-window-horizontally (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
126 "Split current window into two windows side by side.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
127 This window becomes the leftmost of the two, and gets
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
128 ARG columns. No arg means split equally."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
129 (interactive "P")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
130 (split-window nil (and arg (prefix-numeric-value arg)) t))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
131
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
132 (defun enlarge-window-horizontally (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
133 "Make current window ARG columns wider."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
134 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
135 (enlarge-window arg t))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
136
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
137 (defun shrink-window-horizontally (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
138 "Make current window ARG columns narrower."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
139 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
140 (shrink-window arg t))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
141
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
142 (defun shrink-window-if-larger-than-buffer (&optional window)
3342
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
143 "Shrink the WINDOW to be as small as possible to display its contents.
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
144 Do nothing if the buffer contains more lines than the present window height,
4364
69e5c2373d37 (shrink-window-if-larger-than-buffer): Do nothing if the
Richard M. Stallman <rms@gnu.org>
parents: 3724
diff changeset
145 or if some of the window's contents are scrolled out of view,
6905
e068218e992b (shrink-window-if-larger-than-buffer):
Richard M. Stallman <rms@gnu.org>
parents: 6670
diff changeset
146 or if the window is not the full width of the frame,
4364
69e5c2373d37 (shrink-window-if-larger-than-buffer): Do nothing if the
Richard M. Stallman <rms@gnu.org>
parents: 3724
diff changeset
147 or if the window is the only window of its frame."
3342
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
148 (interactive)
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
149 (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
150 (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
151 (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
152 (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
153 (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
154 (n 0)
4364
69e5c2373d37 (shrink-window-if-larger-than-buffer): Do nothing if the
Richard M. Stallman <rms@gnu.org>
parents: 3724
diff changeset
155 (ignore-final-newline
69e5c2373d37 (shrink-window-if-larger-than-buffer): Do nothing if the
Richard M. Stallman <rms@gnu.org>
parents: 3724
diff changeset
156 ;; If buffer ends with a newline, ignore it when counting height
69e5c2373d37 (shrink-window-if-larger-than-buffer): Do nothing if the
Richard M. Stallman <rms@gnu.org>
parents: 3724
diff changeset
157 ;; unless point is after it.
69e5c2373d37 (shrink-window-if-larger-than-buffer): Do nothing if the
Richard M. Stallman <rms@gnu.org>
parents: 3724
diff changeset
158 (and (not (eobp))
69e5c2373d37 (shrink-window-if-larger-than-buffer): Do nothing if the
Richard M. Stallman <rms@gnu.org>
parents: 3724
diff changeset
159 (eq ?\n (char-after (1- (point-max))))))
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
160 (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
161 (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
162 (modified (buffer-modified-p))
6019
0c0b00572d96 (shrink-window-if-larger-than-buffer): Don't shrink if the window that would
Karl Heuer <kwzh@gnu.org>
parents: 4436
diff changeset
163 (buffer (current-buffer))
0c0b00572d96 (shrink-window-if-larger-than-buffer): Don't shrink if the window that would
Karl Heuer <kwzh@gnu.org>
parents: 4436
diff changeset
164 (mini (cdr (assq 'minibuffer (frame-parameters))))
0c0b00572d96 (shrink-window-if-larger-than-buffer): Don't shrink if the window that would
Karl Heuer <kwzh@gnu.org>
parents: 4436
diff changeset
165 (edges (window-edges (selected-window))))
4364
69e5c2373d37 (shrink-window-if-larger-than-buffer): Do nothing if the
Richard M. Stallman <rms@gnu.org>
parents: 3724
diff changeset
166 (if (and (< 1 (count-windows))
6905
e068218e992b (shrink-window-if-larger-than-buffer):
Richard M. Stallman <rms@gnu.org>
parents: 6670
diff changeset
167 (= (window-width) (screen-width))
6019
0c0b00572d96 (shrink-window-if-larger-than-buffer): Don't shrink if the window that would
Karl Heuer <kwzh@gnu.org>
parents: 4436
diff changeset
168 (pos-visible-in-window-p (point-min) window)
0c0b00572d96 (shrink-window-if-larger-than-buffer): Don't shrink if the window that would
Karl Heuer <kwzh@gnu.org>
parents: 4436
diff changeset
169 (or (not mini)
0c0b00572d96 (shrink-window-if-larger-than-buffer): Don't shrink if the window that would
Karl Heuer <kwzh@gnu.org>
parents: 4436
diff changeset
170 (< (nth 3 edges)
0c0b00572d96 (shrink-window-if-larger-than-buffer): Don't shrink if the window that would
Karl Heuer <kwzh@gnu.org>
parents: 4436
diff changeset
171 (nth 1 (window-edges mini)))
0c0b00572d96 (shrink-window-if-larger-than-buffer): Don't shrink if the window that would
Karl Heuer <kwzh@gnu.org>
parents: 4436
diff changeset
172 (> (nth 1 edges)
0c0b00572d96 (shrink-window-if-larger-than-buffer): Don't shrink if the window that would
Karl Heuer <kwzh@gnu.org>
parents: 4436
diff changeset
173 (cdr (assq 'menu-bar-lines (frame-parameters))))))
3342
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
174 (unwind-protect
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
175 (progn
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
176 (select-window (or window w))
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
177 (goto-char (point-min))
4364
69e5c2373d37 (shrink-window-if-larger-than-buffer): Do nothing if the
Richard M. Stallman <rms@gnu.org>
parents: 3724
diff changeset
178 (while (pos-visible-in-window-p
69e5c2373d37 (shrink-window-if-larger-than-buffer): Do nothing if the
Richard M. Stallman <rms@gnu.org>
parents: 3724
diff changeset
179 (- (point-max)
69e5c2373d37 (shrink-window-if-larger-than-buffer): Do nothing if the
Richard M. Stallman <rms@gnu.org>
parents: 3724
diff changeset
180 (if ignore-final-newline 1 0)))
3342
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
181 ;; defeat file locking... don't try this at home, kids!
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
182 (setq buffer-file-name nil)
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
183 (insert ?\n) (setq n (1+ n)))
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
184 (if (> n 0) (shrink-window (1- n))))
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
185 (delete-region (point-min) (point))
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
186 (set-buffer-modified-p modified)
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
187 (goto-char p)
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
188 (select-window w)
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
189 ;; Make sure we unbind buffer-read-only
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
190 ;; with the proper current buffer.
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
191 (set-buffer buffer))))))
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
192
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
193 (define-key ctl-x-map "2" 'split-window-vertically)
707
e4253da532fb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 698
diff changeset
194 (define-key ctl-x-map "3" 'split-window-horizontally)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
195 (define-key ctl-x-map "}" 'enlarge-window-horizontally)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
196 (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
197 (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
198 (define-key ctl-x-map "+" 'balance-windows)
656
d74e65773062 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 419
diff changeset
199
d74e65773062 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 419
diff changeset
200 ;;; windows.el ends here