annotate lisp/window.el @ 13728:4b7903cfa7ee

(bibtex-auto-fill-function): Adapted for use with changed autofill policy of emacs-19.30 (uses now fill-prefix instead of indent-line-function). (bibtex-indent-line-function): Removed (not used any more). (bibtex-make-field): Was broken when called non-interactively. (bibtex-make-field): Point is now placed on closing brace or quote (suggested by Karl Eichwalder <ke@ke.Central.DE>). (bibtex-clean-entry): Comma after last field isn't deleted anymore (new standard in BibTeX 0.99 and 1.xx). (bibtex-enclosing-reference-maybe-empty-head): Works with entries with comma after last field. (bibtex-reference): Permits entries with comma after last field. (bibtex-font-lock-keywords): Enhanced to support new field-name characters (suggested by Martin Maechler <maechler@stat.math.ethz.ch>). (bibtex-field-name): Now numbers (not as the first sign), dashes, and underscores are allowed (suggested by Martin Maechler <maechler@stat.math.ethz.ch> and Oren Patashnik <opbibtex@labrea.Stanford.EDU>). (bibtex-make-field): Was broken on lines containing non-parenthesized entries (reported by Karl Eichwalder <ke@ke.Central.DE>). (bibtex-validate-buffer): Changed so that preamble references are ignored (same as string entries) (reported by Martin Maechler <maechler@stat.math.ethz.ch>). (bibtex-enclosing-reference-maybe-empty-head): New function to be used in case reference head may be empty. (bibtex-clean-entry, bibtex-pop-previous, bibtex-pop-next): Uses now bibtex-enclosing-reference-maybe-empty-head. (bibtex-mode): Added support for font-lock mode. (bibtex-font-lock-keywords): New variable with font-lock keywords for BibTeX mode. (bibtex-make-optional-field): Not longer interactive (suggested by Karl Eichwalder <karl@pertron.central.de>). (bibtex-maintain-sorted-entries): Set to nil, since it requires more user attention and more restricted files to have this set to t. (bibtex-maintain-sorted-entries, bibtex-sort-ignore-string-entries): Made buffer local, since it may depend on the buffer which preferences to use. (bibtex-validate-buffer): Looking for correct sort order only when bibtex-maintain-sorted-entries is non-nil. Put a comment in the `KNOWN BUGS' section about the quote-inside-quotes problem. (whole file): Changed string `true' in some documentation strings to `non-nil' (e.g. `if variable has a true/non-nil value'). (bibtex-mode-map): Changed `move/edit' to `bibtex-edit'. (bibtex-sort-entries): Now works correctly with `@String' entries inside BibTeX files (i.e. after the occurence of other references). (bibtex-validate-buffer): Inserted code which looks if entries are balanced (a single non-escaped quote inside braces was not detected till now, but bibtex-sort-entries stumbles about it). (bibtex-entry): bibtex-move-outside-of-entry is only called when bibtex-maintain-sorted-entries is nil (otherwise bibtex-find-entry-location determines the correct location). (bibtex-find-entry-location): Now uses binary search. As before, it assumes that the buffer is sorted without duplicates (but as before it is only called when bibtex-maintain-sorted-entries is t). Ignores `@String' entries if told so via variable bibtex-sort-ignore-string-entries. (bibtex-clean-entry): Respect bibtex-maintain-sorted-entries when inserting autokey. (bibtex-validate-buffer): Searching whole buffer for duplicates and correct order is now done directly instead of calling bibtex-find-entry-location (since this is to be reprogrammed to use a binary search instead a sequential one). (bibtex-parse-keys): May now be called with an optional parameter which (if t) tells bibtex-parse-keys that it should abort if input is pending. (bibtex-mode): The instance of bibtex-parse-keys called in auto-save-mode-hook is now called with this new parameter set to t, so an auto-save caused by exceeding auto-save-interval is now aborted immediately if user is still typing. (bibtex-print-help-message, bibtex-clean-entry): Use now constant strings instead of custom ones. (bibtex-clean-entry): Changed the call of bibtex-enclosing-reference to a more specific call so entries without a key (here allowed) can be handled. (bibtex-reference-key): Cleared off parentheses (caused string entries enclosed by parentheses instead of braces to be not added to bibtex-completion-candidates). (bibtex-complete-string): Made it use bibtex-string. (bibtex-keys, bibtex-buffer-last-parsed-for-keys-tick): New buffer-local variables to make parsing of BibTeX buffer for reference keys (needed by TAB completion in minibuffer when entering key) more occasional. (bibtex-parse-keys): New function to parse for keys (functionality was partially included in bibtex-entry). (bibtex-entry): Changed to use bibtex-parse-keys. (bibtex-mode): Installs bibtex-parse-keys as an auto-save-mode-hook, so whole buffer is parsed at most when it is autosaved. (bibtex-clean-entry): Calls bibtex-parse-keys on the new entry, so bibtex-keys remains consistent for new entries that are finished by calling this function (most should). (bibtex-inside-field): Be independent on current setting of bibtex-field-right-delimiter (allows more intermixing between quotes and braces). (bibtex-make-field): Last change didn't make it work correctly when called non-interactively by bibtex-entry (fixed).
author Karl Heuer <kwzh@gnu.org>
date Wed, 13 Dec 1995 20:26:13 +0000
parents 75c6a5e1ee7a
children 84de7ffae8ae
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
11086
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
25 ;;;; Window tree functions.
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
26
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
27 (defun one-window-p (&optional nomini all-frames)
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
28 "Returns non-nil if the selected window is the only window (in its frame).
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
29 Optional arg NOMINI non-nil means don't count the minibuffer
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
30 even if it is active.
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
31
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
32 The optional arg ALL-FRAMES t means count windows on all frames.
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
33 If it is `visible', count windows on all visible frames.
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
34 ALL-FRAMES nil or omitted means count only the selected frame,
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
35 plus the minibuffer it uses (which may be on another frame).
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
36 If ALL-FRAMES is neither nil nor t, count only the selected frame."
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
37 (let ((base-window (selected-window)))
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
38 (if (and nomini (eq base-window (minibuffer-window)))
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
39 (setq base-window (next-window base-window)))
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
40 (eq base-window
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
41 (next-window base-window (if nomini 'arg) all-frames))))
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
42
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
43 (defun walk-windows (proc &optional minibuf all-frames)
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
44 "Cycle through all visible windows, calling PROC for each one.
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
45 PROC is called with a window as argument.
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
46
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
47 Optional second arg MINIBUF t means count the minibuffer window even
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
48 if not active. MINIBUF nil or omitted means count the minibuffer iff
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
49 it is active. MINIBUF neither t nor nil means not to count the
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
50 minibuffer even if it is active.
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
51
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
52 Several frames may share a single minibuffer; if the minibuffer
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
53 counts, all windows on all frames that share that minibuffer count
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
54 too. Therefore, when a separate minibuffer frame is active,
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
55 `walk-windows' includes the windows in the frame from which you
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
56 entered the minibuffer, as well as the minibuffer window. But if the
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
57 minibuffer does not count, only windows from WINDOW's frame count.
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
58
11302
a9b5c1d727b7 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 11149
diff changeset
59 ALL-FRAMES is the optional third argument.
a9b5c1d727b7 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 11149
diff changeset
60 ALL-FRAMES nil or omitted means cycle within the frames as specified above.
a9b5c1d727b7 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 11149
diff changeset
61 ALL-FRAMES = `visible' means include windows on all visible frames.
11086
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
62 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
11302
a9b5c1d727b7 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 11149
diff changeset
63 ALL-FRAMES = t means include windows on all frames including invisible frames.
11086
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
64 Anything else means restrict to WINDOW's frame."
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
65 ;; If we start from the minibuffer window, don't fail to come back to it.
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
66 (if (window-minibuffer-p (selected-window))
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
67 (setq minibuf t))
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
68 (let* ((walk-windows-start (selected-window))
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
69 (walk-windows-current walk-windows-start))
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
70 (while (progn
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
71 (setq walk-windows-current
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
72 (next-window walk-windows-current minibuf all-frames))
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
73 (funcall proc walk-windows-current)
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
74 (not (eq walk-windows-current walk-windows-start))))))
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
75
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
76 (defun minibuffer-window-active-p (window)
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
77 "Return t if WINDOW (a minibuffer window) is now active."
11149
8904c26c2182 (minibuffer-window-active-p): Use active-minibuffer-window.
Richard M. Stallman <rms@gnu.org>
parents: 11086
diff changeset
78 (eq window (active-minibuffer-window)))
12184
629806145d36 (save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents: 11302
diff changeset
79
629806145d36 (save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents: 11302
diff changeset
80 (defmacro save-selected-window (&rest body)
629806145d36 (save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents: 11302
diff changeset
81 "Execute BODY, then select the window that was selected before BODY."
629806145d36 (save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents: 11302
diff changeset
82 (list 'let
629806145d36 (save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents: 11302
diff changeset
83 '((save-selected-window-window (selected-window)))
629806145d36 (save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents: 11302
diff changeset
84 (list 'unwind-protect
629806145d36 (save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents: 11302
diff changeset
85 (cons 'progn body)
629806145d36 (save-selected-window): New macro.
Karl Heuer <kwzh@gnu.org>
parents: 11302
diff changeset
86 (list 'select-window 'save-selected-window-window))))
11086
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
87
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
88 (defun count-windows (&optional minibuf)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
89 "Returns the number of visible windows.
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
90 Optional arg NO-MINI non-nil means don't count the minibuffer
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
91 even if it is active."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
92 (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
93 (walk-windows (function (lambda (w)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
94 (setq count (+ count 1))))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
95 minibuf)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
96 count))
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 balance-windows ()
3724
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
99 "Makes all visible windows the same height (approximately)."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
100 (interactive)
13523
75c6a5e1ee7a (balance-windows): Don't count the menu bar's lines in the frame height.
Richard M. Stallman <rms@gnu.org>
parents: 12184
diff changeset
101 (let ((count -1) levels newsizes size
75c6a5e1ee7a (balance-windows): Don't count the menu bar's lines in the frame height.
Richard M. Stallman <rms@gnu.org>
parents: 12184
diff changeset
102 ;; Don't count the lines that are above the uppermost windows.
75c6a5e1ee7a (balance-windows): Don't count the menu bar's lines in the frame height.
Richard M. Stallman <rms@gnu.org>
parents: 12184
diff changeset
103 ;; (These are the menu bar lines, if any.)
75c6a5e1ee7a (balance-windows): Don't count the menu bar's lines in the frame height.
Richard M. Stallman <rms@gnu.org>
parents: 12184
diff changeset
104 (mbl (nth 1 (window-edges (frame-first-window (selected-frame))))))
3724
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
105 ;; 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
106 ;; 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
107 (save-window-excursion
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
108 (let (tops (prev-top -2))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
109 (walk-windows (function (lambda (w)
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
110 (setq tops (cons (nth 1 (window-edges w))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
111 tops))))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
112 'nomini)
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
113 (setq tops (sort tops '<))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
114 (while tops
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
115 (if (> (car tops) (1+ prev-top))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
116 (setq prev-top (car tops)
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
117 count (1+ count)))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
118 (setq levels (cons (cons (car tops) count) levels))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
119 (setq tops (cdr tops)))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
120 (setq count (1+ count))))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
121 ;; Subdivide the frame into that many vertical levels.
13523
75c6a5e1ee7a (balance-windows): Don't count the menu bar's lines in the frame height.
Richard M. Stallman <rms@gnu.org>
parents: 12184
diff changeset
122 (setq size (/ (- (frame-height) mbl) count))
3724
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
123 (walk-windows (function
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
124 (lambda (w)
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
125 (select-window w)
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
126 (let ((newtop (cdr (assq (nth 1 (window-edges))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
127 levels)))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
128 (newbot (or (cdr (assq (+ (window-height)
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
129 (nth 1 (window-edges)))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
130 levels))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
131 count)))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
132 (setq newsizes
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
133 (cons (cons w (* size (- newbot newtop)))
11029
3f98c129f7bc (balance-windows): Ignore minibuffer window when browsing the `levels'.
Richard M. Stallman <rms@gnu.org>
parents: 9007
diff changeset
134 newsizes)))))
3f98c129f7bc (balance-windows): Ignore minibuffer window when browsing the `levels'.
Richard M. Stallman <rms@gnu.org>
parents: 9007
diff changeset
135 'nomini)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
136 (walk-windows (function (lambda (w)
3724
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
137 (select-window w)
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
138 (let ((newsize (cdr (assq w newsizes))))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
139 (enlarge-window (- newsize
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
140 (window-height))))))
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
141 'nomini)))
11086
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
142
698
793483bd29fe *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 656
diff changeset
143 ;;; 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
144 (defvar split-window-keep-point t
3724
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
145 "*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
146 This is often more convenient for editing.
dc73f3152d2f (balance-windows): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents: 3375
diff changeset
147 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
148 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
149
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
150 (defun split-window-vertically (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
151 "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
152 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
153 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
154 With no argument, split equally or close to it.
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
155 Both windows display the same buffer now current.
382
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
156
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
157 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
158 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
159 more convenient for editing.
108
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
160
382
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
161 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
162 redisplay; this is convenient on slow terminals. The new selected
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
163 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
164 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
165 new mode line."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
166 (interactive "P")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
167 (let ((old-w (selected-window))
108
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
168 (old-point (point))
6670
b2c5fca3c10c (split-window-vertically): If size is negative, measure from bottom.
Karl Heuer <kwzh@gnu.org>
parents: 6019
diff changeset
169 (size (and arg (prefix-numeric-value arg)))
108
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
170 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
171 (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
172 (setq new-w (split-window nil size))
419
4fa4f423f981 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 382
diff changeset
173 (or split-window-keep-point
108
8644955999f0 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 36
diff changeset
174 (progn
382
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
175 (save-excursion
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
176 (set-buffer (window-buffer))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
177 (goto-char (window-start))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
178 (vertical-motion (window-height))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
179 (set-window-start new-w (point))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
180 (if (> (point) (window-point new-w))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
181 (set-window-point new-w (point)))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
182 (vertical-motion -1)
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
183 (setq bottom (point)))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
184 (if (<= bottom (point))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
185 (set-window-point old-w (1- bottom)))
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
186 (if (< (window-start new-w) old-point)
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
187 (progn
b6465a2ae3e5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 108
diff changeset
188 (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
189 (select-window new-w)))))
f4d37be94734 (split-window-vertically): Return the new window.
Richard M. Stallman <rms@gnu.org>
parents: 2529
diff changeset
190 new-w))
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
191
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
192 (defun split-window-horizontally (&optional arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
193 "Split current window into two windows side by side.
8565
2a2208286955 (split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
parents: 7300
diff changeset
194 This window becomes the leftmost of the two, and gets ARG columns.
2a2208286955 (split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
parents: 7300
diff changeset
195 Negative arg means select the size of the rightmost window instead.
2a2208286955 (split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
parents: 7300
diff changeset
196 No arg means split equally."
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
197 (interactive "P")
8565
2a2208286955 (split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
parents: 7300
diff changeset
198 (let ((size (and arg (prefix-numeric-value arg))))
2a2208286955 (split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
parents: 7300
diff changeset
199 (and size (< size 0)
2a2208286955 (split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
parents: 7300
diff changeset
200 (setq size (+ (window-width) size)))
2a2208286955 (split-window-horizontally): If size is negative, measure from the right.
Karl Heuer <kwzh@gnu.org>
parents: 7300
diff changeset
201 (split-window nil size t)))
11086
22693a280a42 (one-window-p, walk-windows, minibuffer-window-active-p): Functions moved here.
Richard M. Stallman <rms@gnu.org>
parents: 11029
diff changeset
202
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
203 (defun enlarge-window-horizontally (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
204 "Make current window ARG columns wider."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
205 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
206 (enlarge-window arg t))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
207
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
208 (defun shrink-window-horizontally (arg)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
209 "Make current window ARG columns narrower."
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
210 (interactive "p")
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
211 (shrink-window arg t))
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
212
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
213 (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
214 "Shrink the WINDOW to be as small as possible to display its contents.
8721
c94f87ea8a1b (shrink-window-if-larger-than-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 8672
diff changeset
215 Do not shrink to less than `window-min-height' lines.
3342
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
216 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
217 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
218 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
219 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
220 (interactive)
9007
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
221 (or window (setq window (selected-window)))
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
222 (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
223 (set-buffer (window-buffer window))
9007
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
224 (let* ((w (selected-window)) ;save-window-excursion can't win
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
225 (buffer-file-name buffer-file-name)
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
226 (p (point))
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
227 (n 0)
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
228 (ignore-final-newline
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
229 ;; If buffer ends with a newline, ignore it when counting height
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
230 ;; unless point is after it.
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
231 (and (not (eobp))
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
232 (eq ?\n (char-after (1- (point-max))))))
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
233 (buffer-read-only nil)
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
234 (modified (buffer-modified-p))
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
235 (buffer (current-buffer))
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
236 (params (frame-parameters (window-frame window)))
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
237 (mini (cdr (assq 'minibuffer params)))
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
238 (edges (window-edges (selected-window))))
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
239 (if (and (< 1 (let ((frame (selected-frame)))
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
240 (select-frame (window-frame window))
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
241 (unwind-protect
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
242 (count-windows)
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
243 (select-frame frame))))
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
244 (= (window-width window) (frame-width (window-frame window)))
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
245 (pos-visible-in-window-p (point-min) window)
8778
1b047b18e860 (shrink-window-if-larger-than-buffer):
Richard M. Stallman <rms@gnu.org>
parents: 8750
diff changeset
246 (not (eq mini 'only))
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
247 (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
248 (< (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
249 (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
250 (> (nth 1 edges)
9007
2c55ff956862 (shrink-window-if-larger-than-buffer): Use WINDOW's frame
Richard M. Stallman <rms@gnu.org>
parents: 8778
diff changeset
251 (cdr (assq 'menu-bar-lines params)))))
3342
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
252 (unwind-protect
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
253 (progn
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
254 (select-window (or window w))
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
255 (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
256 (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
257 (- (point-max)
69e5c2373d37 (shrink-window-if-larger-than-buffer): Do nothing if the
Richard M. Stallman <rms@gnu.org>
parents: 3724
diff changeset
258 (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
259 ;; 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
260 (setq buffer-file-name nil)
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
261 (insert ?\n) (setq n (1+ n)))
8672
415a25bb4ee7 (shrink-window-if-larger-than-buffer):
Richard M. Stallman <rms@gnu.org>
parents: 8565
diff changeset
262 (if (> n 0)
415a25bb4ee7 (shrink-window-if-larger-than-buffer):
Richard M. Stallman <rms@gnu.org>
parents: 8565
diff changeset
263 (shrink-window (min (1- n)
415a25bb4ee7 (shrink-window-if-larger-than-buffer):
Richard M. Stallman <rms@gnu.org>
parents: 8565
diff changeset
264 (- (window-height)
415a25bb4ee7 (shrink-window-if-larger-than-buffer):
Richard M. Stallman <rms@gnu.org>
parents: 8565
diff changeset
265 window-min-height)))))
3342
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
266 (delete-region (point-min) (point))
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
267 (set-buffer-modified-p modified)
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
268 (goto-char p)
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
269 (select-window w)
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
270 ;; 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
271 ;; with the proper current buffer.
ce8aa0ba8b08 (shrink-window-if-larger-than-buffer): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents: 3253
diff changeset
272 (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
273
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
274 (define-key ctl-x-map "2" 'split-window-vertically)
707
e4253da532fb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 698
diff changeset
275 (define-key ctl-x-map "3" 'split-window-horizontally)
36
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
276 (define-key ctl-x-map "}" 'enlarge-window-horizontally)
9697c13298e5 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
277 (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
278 (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
279 (define-key ctl-x-map "+" 'balance-windows)
656
d74e65773062 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 419
diff changeset
280
d74e65773062 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 419
diff changeset
281 ;;; windows.el ends here