annotate lisp/window.el @ 99503:9d16e131644e

2008-11-12 Carsten Dominik <dominik@science.uva.nl> * org.texi (Clocking work time): Document the :formula property of clock tables. (Structure editing, Refiling notes): Document refiling regions. (Agenda commands): Document the double-prefix version of the `l' command in the agenda. (Handling links): Explain the effect of a double prefix arg to `C-c C-o'. (TODO basics): Add documentation for tag triggers.
author Carsten Dominik <dominik@science.uva.nl>
date Wed, 12 Nov 2008 08:06:54 +0000
parents 97cfe3bfabc8
children c094962ecbed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1 ;;; window.el --- GNU Emacs window commands aside from those written in C
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
2
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
3 ;; Copyright (C) 1985, 1989, 1992, 1993, 1994, 2000, 2001, 2002,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
4 ;; 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
5
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
6 ;; Maintainer: FSF
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
7 ;; Keywords: internal
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
8
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
9 ;; This file is part of GNU Emacs.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
10
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
14 ;; (at your option) any later version.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
15
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
19 ;; GNU General Public License for more details.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
20
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
21 ;; You should have received a copy of the GNU General Public License
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
23
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
24 ;;; Commentary:
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
25
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
26 ;; Window tree functions.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
27
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
28 ;;; Code:
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
29
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
30 (eval-when-compile (require 'cl))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
31
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
32 (defvar window-size-fixed nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
33 "*Non-nil in a buffer means windows displaying the buffer are fixed-size.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
34 If the value is `height', then only the window's height is fixed.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
35 If the value is `width', then only the window's width is fixed.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
36 Any other non-nil value fixes both the width and the height.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
37 Emacs won't change the size of any window displaying that buffer,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
38 unless you explicitly change the size, or Emacs has no other choice.")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
39 (make-variable-buffer-local 'window-size-fixed)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
40
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
41 (defmacro save-selected-window (&rest body)
99357
47fe276a8011 (save-selected-window): Make it behave like
Martin Rudalics <rudalics@gmx.at>
parents: 99326
diff changeset
42 "Execute BODY, then select the previously selected window.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
43 The value returned is the value of the last form in BODY.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
44
99357
47fe276a8011 (save-selected-window): Make it behave like
Martin Rudalics <rudalics@gmx.at>
parents: 99326
diff changeset
45 This macro saves and restores the selected window, as well as the
47fe276a8011 (save-selected-window): Make it behave like
Martin Rudalics <rudalics@gmx.at>
parents: 99326
diff changeset
46 selected window in each frame. If the previously selected window
47fe276a8011 (save-selected-window): Make it behave like
Martin Rudalics <rudalics@gmx.at>
parents: 99326
diff changeset
47 is no longer live, then whatever window is selected at the end of
47fe276a8011 (save-selected-window): Make it behave like
Martin Rudalics <rudalics@gmx.at>
parents: 99326
diff changeset
48 BODY remains selected. If the previously selected window of some
47fe276a8011 (save-selected-window): Make it behave like
Martin Rudalics <rudalics@gmx.at>
parents: 99326
diff changeset
49 frame is no longer live at the end of BODY, that frame's selected
47fe276a8011 (save-selected-window): Make it behave like
Martin Rudalics <rudalics@gmx.at>
parents: 99326
diff changeset
50 window is left alone.
47fe276a8011 (save-selected-window): Make it behave like
Martin Rudalics <rudalics@gmx.at>
parents: 99326
diff changeset
51
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
52 This macro saves and restores the current buffer, since otherwise
99357
47fe276a8011 (save-selected-window): Make it behave like
Martin Rudalics <rudalics@gmx.at>
parents: 99326
diff changeset
53 its normal operation could make a different buffer current. The
47fe276a8011 (save-selected-window): Make it behave like
Martin Rudalics <rudalics@gmx.at>
parents: 99326
diff changeset
54 order of recently selected windows and the buffer list ordering
47fe276a8011 (save-selected-window): Make it behave like
Martin Rudalics <rudalics@gmx.at>
parents: 99326
diff changeset
55 are not altered by this macro (unless they are altered in BODY)."
99326
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
56 `(let ((save-selected-window-window (selected-window))
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
57 ;; It is necessary to save all of these, because calling
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
58 ;; select-window changes frame-selected-window for whatever
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
59 ;; frame that window is in.
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
60 (save-selected-window-alist
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
61 (mapcar (lambda (frame) (cons frame (frame-selected-window frame)))
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
62 (frame-list))))
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
63 (save-current-buffer
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
64 (unwind-protect
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
65 (progn ,@body)
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
66 (dolist (elt save-selected-window-alist)
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
67 (and (frame-live-p (car elt))
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
68 (window-live-p (cdr elt))
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
69 (set-frame-selected-window (car elt) (cdr elt) 'norecord)))
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
70 (when (window-live-p save-selected-window-window)
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
71 (select-window save-selected-window-window 'norecord))))))
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
72
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
73 (defun window-body-height (&optional window)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
74 "Return number of lines in WINDOW available for actual buffer text.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
75 WINDOW defaults to the selected window.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
76
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
77 The return value does not include the mode line or the header
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
78 line, if any. If a line at the bottom of the window is only
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
79 partially visible, that line is included in the return value. If
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
80 you do not want to include a partially visible bottom line in the
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
81 return value, use `window-text-height' instead."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
82 (or window (setq window (selected-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
83 (if (window-minibuffer-p window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
84 (window-height window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
85 (with-current-buffer (window-buffer window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
86 (max 1 (- (window-height window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
87 (if mode-line-format 1 0)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
88 (if header-line-format 1 0))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
89
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
90 (defun one-window-p (&optional nomini all-frames)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
91 "Return non-nil if the selected window is the only window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
92 Optional arg NOMINI non-nil means don't count the minibuffer
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
93 even if it is active. Otherwise, the minibuffer is counted
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
94 when it is active.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
95
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
96 The optional arg ALL-FRAMES t means count windows on all frames.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
97 If it is `visible', count windows on all visible frames.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
98 ALL-FRAMES nil or omitted means count only the selected frame,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
99 plus the minibuffer it uses (which may be on another frame).
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
100 ALL-FRAMES 0 means count all windows in all visible or iconified frames.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
101 If ALL-FRAMES is anything else, count only the selected frame."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
102 (let ((base-window (selected-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
103 (if (and nomini (eq base-window (minibuffer-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
104 (setq base-window (next-window base-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
105 (eq base-window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
106 (next-window base-window (if nomini 'arg) all-frames))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
107
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
108 (defun window-current-scroll-bars (&optional window)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
109 "Return the current scroll bar settings for WINDOW.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
110 WINDOW defaults to the selected window.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
111
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
112 The return value is a cons cell (VERTICAL . HORIZONTAL) where
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
113 VERTICAL specifies the current location of the vertical scroll
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
114 bars (`left', `right', or nil), and HORIZONTAL specifies the
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
115 current location of the horizontal scroll bars (`top', `bottom',
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
116 or nil).
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
117
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
118 Unlike `window-scroll-bars', this function reports the scroll bar
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
119 type actually used, once frame defaults and `scroll-bar-mode' are
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
120 taken into account."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
121 (let ((vert (nth 2 (window-scroll-bars window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
122 (hor nil))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
123 (when (or (eq vert t) (eq hor t))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
124 (let ((fcsb (frame-current-scroll-bars
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
125 (window-frame (or window (selected-window))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
126 (if (eq vert t)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
127 (setq vert (car fcsb)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
128 (if (eq hor t)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
129 (setq hor (cdr fcsb)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
130 (cons vert hor)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
131
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
132 (defun walk-windows (proc &optional minibuf all-frames)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
133 "Cycle through all windows, calling PROC for each one.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
134 PROC must specify a function with a window as its sole argument.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
135 The optional arguments MINIBUF and ALL-FRAMES specify the set of
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
136 windows to include in the walk, see also `next-window'.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
137
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
138 MINIBUF t means include the minibuffer window even if the
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
139 minibuffer is not active. MINIBUF nil or omitted means include
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
140 the minibuffer window only if the minibuffer is active. Any
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
141 other value means do not include the minibuffer window even if
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
142 the minibuffer is active.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
143
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
144 Several frames may share a single minibuffer; if the minibuffer
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
145 is active, all windows on all frames that share that minibuffer
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
146 are included too. Therefore, if you are using a separate
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
147 minibuffer frame and the minibuffer is active and MINIBUF says it
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
148 counts, `walk-windows' includes the windows in the frame from
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
149 which you entered the minibuffer, as well as the minibuffer
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
150 window.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
151
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
152 ALL-FRAMES nil or omitted means cycle through all windows on
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
153 WINDOW's frame, plus the minibuffer window if specified by the
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
154 MINIBUF argument, see above. If the minibuffer counts, cycle
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
155 through all windows on all frames that share that minibuffer
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
156 too.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
157 ALL-FRAMES t means cycle through all windows on all existing
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
158 frames.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
159 ALL-FRAMES `visible' means cycle through all windows on all
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
160 visible frames.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
161 ALL-FRAMES 0 means cycle through all windows on all visible and
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
162 iconified frames.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
163 ALL-FRAMES a frame means cycle through all windows on that frame
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
164 only.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
165 Anything else means cycle through all windows on WINDOW's frame
99326
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
166 and no others.
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
167
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
168 This function changes neither the order of recently selected
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
169 windows nor the buffer list."
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
170 ;; If we start from the minibuffer window, don't fail to come
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
171 ;; back to it.
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
172 (when (window-minibuffer-p (selected-window))
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
173 (setq minibuf t))
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
174 ;; Make sure to not mess up the order of recently selected
99357
47fe276a8011 (save-selected-window): Make it behave like
Martin Rudalics <rudalics@gmx.at>
parents: 99326
diff changeset
175 ;; windows. Use `save-selected-window' and `select-window'
99326
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
176 ;; with second argument non-nil for this purpose.
99357
47fe276a8011 (save-selected-window): Make it behave like
Martin Rudalics <rudalics@gmx.at>
parents: 99326
diff changeset
177 (save-selected-window
99326
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
178 (when (framep all-frames)
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
179 (select-window (frame-first-window all-frames) 'norecord))
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
180 (let* (walk-windows-already-seen
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
181 (walk-windows-current (selected-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
182 (while (progn
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
183 (setq walk-windows-current
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
184 (next-window walk-windows-current minibuf all-frames))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
185 (not (memq walk-windows-current walk-windows-already-seen)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
186 (setq walk-windows-already-seen
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
187 (cons walk-windows-current walk-windows-already-seen))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
188 (funcall proc walk-windows-current)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
189
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
190 (defun get-window-with-predicate (predicate &optional minibuf
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
191 all-frames default)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
192 "Return a window satisfying PREDICATE.
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
193 More precisely, cycle through all windows using `walk-windows',
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
194 calling the function PREDICATE on each one of them with the
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
195 window as its sole argument. Return the first window for which
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
196 PREDICATE returns non-nil. If no window satisfies PREDICATE,
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
197 return DEFAULT.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
198
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
199 The optional arguments MINIBUF and ALL-FRAMES specify the set of
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
200 windows to include. See `walk-windows' for the meaning of these
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
201 arguments."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
202 (catch 'found
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
203 (walk-windows #'(lambda (window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
204 (when (funcall predicate window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
205 (throw 'found window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
206 minibuf all-frames)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
207 default))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
208
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
209 (defalias 'some-window 'get-window-with-predicate)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
210
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
211 ;; This should probably be written in C (i.e., without using `walk-windows').
99122
6fff8b7a31ca (get-buffer-window-list): Rename buffer argument to
Martin Rudalics <rudalics@gmx.at>
parents: 98886
diff changeset
212 (defun get-buffer-window-list (&optional buffer-or-name minibuf all-frames)
6fff8b7a31ca (get-buffer-window-list): Rename buffer argument to
Martin Rudalics <rudalics@gmx.at>
parents: 98886
diff changeset
213 "Return list of all windows displaying BUFFER-OR-NAME, or nil if none.
6fff8b7a31ca (get-buffer-window-list): Rename buffer argument to
Martin Rudalics <rudalics@gmx.at>
parents: 98886
diff changeset
214 BUFFER-OR-NAME may be a buffer or the name of an existing buffer
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
215 and defaults to the current buffer.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
216
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
217 The optional arguments MINIBUF and ALL-FRAMES specify the set of
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
218 windows to consider. See `walk-windows' for the precise meaning
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
219 of these arguments."
99122
6fff8b7a31ca (get-buffer-window-list): Rename buffer argument to
Martin Rudalics <rudalics@gmx.at>
parents: 98886
diff changeset
220 (let ((buffer (cond
6fff8b7a31ca (get-buffer-window-list): Rename buffer argument to
Martin Rudalics <rudalics@gmx.at>
parents: 98886
diff changeset
221 ((not buffer-or-name) (current-buffer))
6fff8b7a31ca (get-buffer-window-list): Rename buffer argument to
Martin Rudalics <rudalics@gmx.at>
parents: 98886
diff changeset
222 ((bufferp buffer-or-name) buffer-or-name)
6fff8b7a31ca (get-buffer-window-list): Rename buffer argument to
Martin Rudalics <rudalics@gmx.at>
parents: 98886
diff changeset
223 (t (get-buffer buffer-or-name))))
6fff8b7a31ca (get-buffer-window-list): Rename buffer argument to
Martin Rudalics <rudalics@gmx.at>
parents: 98886
diff changeset
224 windows)
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
225 (walk-windows (function (lambda (window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
226 (if (eq (window-buffer window) buffer)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
227 (setq windows (cons window windows)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
228 minibuf all-frames)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
229 windows))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
230
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
231 (defun minibuffer-window-active-p (window)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
232 "Return t if WINDOW is the currently active minibuffer window."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
233 (eq window (active-minibuffer-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
234
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
235 (defun count-windows (&optional minibuf)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
236 "Return the number of visible windows.
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
237 The optional argument MINIBUF specifies whether the minibuffer
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
238 window shall be counted. See `walk-windows' for the precise
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
239 meaning of this argument."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
240 (let ((count 0))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
241 (walk-windows (lambda (w) (setq count (+ count 1)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
242 minibuf)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
243 count))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
244
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
245 (defun window-safely-shrinkable-p (&optional window)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
246 "Return t if WINDOW can be shrunk without shrinking other windows.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
247 WINDOW defaults to the selected window."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
248 (with-selected-window (or window (selected-window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
249 (let ((edges (window-edges)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
250 (or (= (nth 2 edges) (nth 2 (window-edges (previous-window))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
251 (= (nth 0 edges) (nth 0 (window-edges (next-window))))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
252
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
253
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
255 ;;; `balance-windows' subroutines using `window-tree'
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
256
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
257 ;;; Translate from internal window tree format
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
258
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
259 (defun bw-get-tree (&optional window-or-frame)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
260 "Get a window split tree in our format.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
261
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
262 WINDOW-OR-FRAME must be nil, a frame, or a window. If it is nil,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
263 then the whole window split tree for `selected-frame' is returned.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
264 If it is a frame, then this is used instead. If it is a window,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
265 then the smallest tree containing that window is returned."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
266 (when window-or-frame
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
267 (unless (or (framep window-or-frame)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
268 (windowp window-or-frame))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
269 (error "Not a frame or window: %s" window-or-frame)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
270 (let ((subtree (bw-find-tree-sub window-or-frame)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
271 (when subtree
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
272 (if (integerp subtree)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
273 nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
274 (bw-get-tree-1 subtree)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
275
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
276 (defun bw-get-tree-1 (split)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
277 (if (windowp split)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
278 split
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
279 (let ((dir (car split))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
280 (edges (car (cdr split)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
281 (childs (cdr (cdr split))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
282 (list
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
283 (cons 'dir (if dir 'ver 'hor))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
284 (cons 'b (nth 3 edges))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
285 (cons 'r (nth 2 edges))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
286 (cons 't (nth 1 edges))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
287 (cons 'l (nth 0 edges))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
288 (cons 'childs (mapcar #'bw-get-tree-1 childs))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
289
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
290 (defun bw-find-tree-sub (window-or-frame &optional get-parent)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
291 (let* ((window (when (windowp window-or-frame) window-or-frame))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
292 (frame (when (windowp window) (window-frame window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
293 (wt (car (window-tree frame))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
294 (when (< 1 (length (window-list frame 0)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
295 (if window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
296 (bw-find-tree-sub-1 wt window get-parent)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
297 wt))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
298
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
299 (defun bw-find-tree-sub-1 (tree win &optional get-parent)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
300 (unless (windowp win) (error "Not a window: %s" win))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
301 (if (memq win tree)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
302 (if get-parent
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
303 get-parent
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
304 tree)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
305 (let ((childs (cdr (cdr tree)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
306 child
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
307 subtree)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
308 (while (and childs (not subtree))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
309 (setq child (car childs))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
310 (setq childs (cdr childs))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
311 (when (and child (listp child))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
312 (setq subtree (bw-find-tree-sub-1 child win get-parent))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
313 (if (integerp subtree)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
314 (progn
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
315 (if (= 1 subtree)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
316 tree
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
317 (1- subtree)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
318 subtree
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
319 ))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
320
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
321 ;;; Window or object edges
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
322
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
323 (defun bw-l (obj)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
324 "Left edge of OBJ."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
325 (if (windowp obj) (nth 0 (window-edges obj)) (cdr (assq 'l obj))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
326 (defun bw-t (obj)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
327 "Top edge of OBJ."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
328 (if (windowp obj) (nth 1 (window-edges obj)) (cdr (assq 't obj))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
329 (defun bw-r (obj)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
330 "Right edge of OBJ."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
331 (if (windowp obj) (nth 2 (window-edges obj)) (cdr (assq 'r obj))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
332 (defun bw-b (obj)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
333 "Bottom edge of OBJ."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
334 (if (windowp obj) (nth 3 (window-edges obj)) (cdr (assq 'b obj))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
335
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
336 ;;; Split directions
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
337
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
338 (defun bw-dir (obj)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
339 "Return window split tree direction if OBJ.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
340 If OBJ is a window return 'both. If it is a window split tree
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
341 then return its direction."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
342 (if (symbolp obj)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
343 obj
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
344 (if (windowp obj)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
345 'both
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
346 (let ((dir (cdr (assq 'dir obj))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
347 (unless (memq dir '(hor ver both))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
348 (error "Can't find dir in %s" obj))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
349 dir))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
350
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
351 (defun bw-eqdir (obj1 obj2)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
352 "Return t if window split tree directions are equal.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
353 OBJ1 and OBJ2 should be either windows or window split trees in
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
354 our format. The directions returned by `bw-dir' are compared and
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
355 t is returned if they are `eq' or one of them is 'both."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
356 (let ((dir1 (bw-dir obj1))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
357 (dir2 (bw-dir obj2)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
358 (or (eq dir1 dir2)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
359 (eq dir1 'both)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
360 (eq dir2 'both))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
361
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
362 ;;; Building split tree
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
363
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
364 (defun bw-refresh-edges (obj)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
365 "Refresh the edge information of OBJ and return OBJ."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
366 (unless (windowp obj)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
367 (let ((childs (cdr (assq 'childs obj)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
368 (ol 1000)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
369 (ot 1000)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
370 (or -1)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
371 (ob -1))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
372 (dolist (o childs)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
373 (when (> ol (bw-l o)) (setq ol (bw-l o)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
374 (when (> ot (bw-t o)) (setq ot (bw-t o)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
375 (when (< or (bw-r o)) (setq or (bw-r o)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
376 (when (< ob (bw-b o)) (setq ob (bw-b o))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
377 (setq obj (delq 'l obj))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
378 (setq obj (delq 't obj))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
379 (setq obj (delq 'r obj))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
380 (setq obj (delq 'b obj))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
381 (add-to-list 'obj (cons 'l ol))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
382 (add-to-list 'obj (cons 't ot))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
383 (add-to-list 'obj (cons 'r or))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
384 (add-to-list 'obj (cons 'b ob))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
385 ))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
386 obj)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
387
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
388 ;;; Balance windows
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
389
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
390 (defun balance-windows (&optional window-or-frame)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
391 "Make windows the same heights or widths in window split subtrees.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
392
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
393 When called non-interactively WINDOW-OR-FRAME may be either a
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
394 window or a frame. It then balances the windows on the implied
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
395 frame. If the parameter is a window only the corresponding window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
396 subtree is balanced."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
397 (interactive)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
398 (let (
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
399 (wt (bw-get-tree window-or-frame))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
400 (w)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
401 (h)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
402 (tried-sizes)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
403 (last-sizes)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
404 (windows (window-list nil 0)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
405 (when wt
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
406 (while (not (member last-sizes tried-sizes))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
407 (when last-sizes (setq tried-sizes (cons last-sizes tried-sizes)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
408 (setq last-sizes (mapcar (lambda (w)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
409 (window-edges w))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
410 windows))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
411 (when (eq 'hor (bw-dir wt))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
412 (setq w (- (bw-r wt) (bw-l wt))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
413 (when (eq 'ver (bw-dir wt))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
414 (setq h (- (bw-b wt) (bw-t wt))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
415 (bw-balance-sub wt w h)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
416
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
417 (defun bw-adjust-window (window delta horizontal)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
418 "Wrapper around `adjust-window-trailing-edge' with error checking.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
419 Arguments WINDOW, DELTA and HORIZONTAL are passed on to that function."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
420 ;; `adjust-window-trailing-edge' may fail if delta is too large.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
421 (while (>= (abs delta) 1)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
422 (condition-case err
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
423 (progn
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
424 (adjust-window-trailing-edge window delta horizontal)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
425 (setq delta 0))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
426 (error
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
427 ;;(message "adjust: %s" (error-message-string err))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
428 (setq delta (/ delta 2))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
429
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
430 (defun bw-balance-sub (wt w h)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
431 (setq wt (bw-refresh-edges wt))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
432 (unless w (setq w (- (bw-r wt) (bw-l wt))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
433 (unless h (setq h (- (bw-b wt) (bw-t wt))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
434 (if (windowp wt)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
435 (progn
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
436 (when w
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
437 (let ((dw (- w (- (bw-r wt) (bw-l wt)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
438 (when (/= 0 dw)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
439 (bw-adjust-window wt dw t))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
440 (when h
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
441 (let ((dh (- h (- (bw-b wt) (bw-t wt)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
442 (when (/= 0 dh)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
443 (bw-adjust-window wt dh nil)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
444 (let* ((childs (cdr (assq 'childs wt)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
445 (cw (when w (/ w (if (bw-eqdir 'hor wt) (length childs) 1))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
446 (ch (when h (/ h (if (bw-eqdir 'ver wt) (length childs) 1)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
447 (dolist (c childs)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
448 (bw-balance-sub c cw ch)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
449
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
450 (defun window-fixed-size-p (&optional window direction)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
451 "Return t if WINDOW cannot be resized in DIRECTION.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
452 WINDOW defaults to the selected window. DIRECTION can be
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
453 nil (i.e. any), `height' or `width'."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
454 (with-current-buffer (window-buffer window)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
455 (when (and (boundp 'window-size-fixed) window-size-fixed)
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
456 (not (and direction
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
457 (member (cons direction window-size-fixed)
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
458 '((height . width) (width . height))))))))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
459
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
460 ;;; A different solution to balance-windows.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
461
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
462 (defvar window-area-factor 1
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
463 "Factor by which the window area should be over-estimated.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
464 This is used by `balance-windows-area'.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
465 Changing this globally has no effect.")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
466 (make-variable-buffer-local 'window-area-factor)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
467
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
468 (defun balance-windows-area ()
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
469 "Make all visible windows the same area (approximately).
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
470 See also `window-area-factor' to change the relative size of
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
471 specific buffers."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
472 (interactive)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
473 (let* ((unchanged 0) (carry 0) (round 0)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
474 ;; Remove fixed-size windows.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
475 (wins (delq nil (mapcar (lambda (win)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
476 (if (not (window-fixed-size-p win)) win))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
477 (window-list nil 'nomini))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
478 (changelog nil)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
479 next)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
480 ;; Resizing a window changes the size of surrounding windows in complex
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
481 ;; ways, so it's difficult to balance them all. The introduction of
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
482 ;; `adjust-window-trailing-edge' made it a bit easier, but it is still
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
483 ;; very difficult to do. `balance-window' above takes an off-line
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
484 ;; approach: get the whole window tree, then balance it, then try to
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
485 ;; adjust the windows so they fit the result.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
486 ;; Here, instead, we take a "local optimization" approach, where we just
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
487 ;; go through all the windows several times until nothing needs to be
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
488 ;; changed. The main problem with this approach is that it's difficult
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
489 ;; to make sure it terminates, so we use some heuristic to try and break
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
490 ;; off infinite loops.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
491 ;; After a round without any change, we allow a second, to give a chance
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
492 ;; to the carry to propagate a minor imbalance from the end back to
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
493 ;; the beginning.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
494 (while (< unchanged 2)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
495 ;; (message "New round")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
496 (setq unchanged (1+ unchanged) round (1+ round))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
497 (dolist (win wins)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
498 (setq next win)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
499 (while (progn (setq next (next-window next))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
500 (window-fixed-size-p next)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
501 ;; (assert (eq next (or (cadr (member win wins)) (car wins))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
502 (let* ((horiz
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
503 (< (car (window-edges win)) (car (window-edges next))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
504 (areadiff (/ (- (* (window-height next) (window-width next)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
505 (buffer-local-value 'window-area-factor
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
506 (window-buffer next)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
507 (* (window-height win) (window-width win)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
508 (buffer-local-value 'window-area-factor
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
509 (window-buffer win))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
510 (max (buffer-local-value 'window-area-factor
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
511 (window-buffer win))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
512 (buffer-local-value 'window-area-factor
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
513 (window-buffer next)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
514 (edgesize (if horiz
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
515 (+ (window-height win) (window-height next))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
516 (+ (window-width win) (window-width next))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
517 (diff (/ areadiff edgesize)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
518 (when (zerop diff)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
519 ;; Maybe diff is actually closer to 1 than to 0.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
520 (setq diff (/ (* 3 areadiff) (* 2 edgesize))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
521 (when (and (zerop diff) (not (zerop areadiff)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
522 (setq diff (/ (+ areadiff carry) edgesize))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
523 ;; Change things smoothly.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
524 (if (or (> diff 1) (< diff -1)) (setq diff (/ diff 2))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
525 (if (zerop diff)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
526 ;; Make sure negligible differences don't accumulate to
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
527 ;; become significant.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
528 (setq carry (+ carry areadiff))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
529 (bw-adjust-window win diff horiz)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
530 ;; (sit-for 0.5)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
531 (let ((change (cons win (window-edges win))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
532 ;; If the same change has been seen already for this window,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
533 ;; we're most likely in an endless loop, so don't count it as
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
534 ;; a change.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
535 (unless (member change changelog)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
536 (push change changelog)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
537 (setq unchanged 0 carry 0)))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
538 ;; We've now basically balanced all the windows.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
539 ;; But there may be some minor off-by-one imbalance left over,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
540 ;; so let's do some fine tuning.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
541 ;; (bw-finetune wins)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
542 ;; (message "Done in %d rounds" round)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
543 ))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
544
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
545
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
546 (defcustom display-buffer-function nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
547 "If non-nil, function to call to handle `display-buffer'.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
548 It will receive two args, the buffer and a flag which if non-nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
549 means that the currently selected window is not acceptable. It
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
550 should choose or create a window, display the specified buffer in
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
551 it, and return the window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
552
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
553 Commands such as `switch-to-buffer-other-window' and
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
554 `find-file-other-window' work using this function."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
555 :type '(choice
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
556 (const nil)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
557 (function :tag "function"))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
558 :group 'windows)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
559
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
560 (defun special-display-p (buffer-name)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
561 "Return non-nil if a buffer named BUFFER-NAME gets a special frame.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
562 If the value is t, `display-buffer' or `pop-to-buffer' would
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
563 create a special frame for that buffer using the default frame
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
564 parameters.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
565
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
566 If the value is a list, it is a list of frame parameters that
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
567 would be used to make a frame for that buffer. The variables
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
568 `special-display-buffer-names' and `special-display-regexps'
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
569 control this."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
570 (let (tmp)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
571 (cond
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
572 ((not (stringp buffer-name)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
573 ;; Make sure to return t in the following two cases.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
574 ((member buffer-name special-display-buffer-names) t)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
575 ((setq tmp (assoc buffer-name special-display-buffer-names)) (cdr tmp))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
576 ((catch 'found
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
577 (dolist (regexp special-display-regexps)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
578 (cond
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
579 ((stringp regexp)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
580 (when (string-match-p regexp buffer-name)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
581 (throw 'found t)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
582 ((and (consp regexp) (stringp (car regexp))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
583 (string-match-p (car regexp) buffer-name))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
584 (throw 'found (cdr regexp))))))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
585
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
586 (defcustom special-display-buffer-names nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
587 "List of buffer names that should have their own special frames.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
588 Displaying a buffer with `display-buffer' or `pop-to-buffer', if
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
589 its name is in this list, makes a special frame for it using
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
590 `special-display-function'. See also `special-display-regexps'.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
591
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
592 An element of the list can be a list instead of just a string.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
593 There are two ways to use a list as an element:
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
594 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
595 In the first case, the FRAME-PARAMETERS are pairs of the form
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
596 \(PARAMETER . VALUE); these parameter values are used to create
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
597 the frame. In the second case, FUNCTION is called with BUFFER as
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
598 the first argument, followed by the OTHER-ARGS--it can display
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
599 BUFFER in any way it likes. All this is done by the function
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
600 found in `special-display-function'.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
601
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
602 If the specified frame parameters include (same-buffer . t), the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
603 buffer is displayed in the currently selected window. Otherwise, if
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
604 they include (same-frame . t), the buffer is displayed in a new window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
605 in the currently selected frame.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
606
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
607 If this variable appears \"not to work\", because you add a name to it
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
608 but that buffer still appears in the selected window, look at the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
609 values of `same-window-buffer-names' and `same-window-regexps'.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
610 Those variables take precedence over this one."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
611 :type '(repeat (choice :tag "Buffer"
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
612 :value ""
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
613 (string :format "%v")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
614 (cons :tag "With attributes"
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
615 :format "%v"
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
616 :value ("" . nil)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
617 (string :format "%v")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
618 (repeat :tag "Attributes"
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
619 (cons :format "%v"
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
620 (symbol :tag "Parameter")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
621 (sexp :tag "Value"))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
622 :group 'frames)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
623
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
624 (defcustom special-display-regexps nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
625 "List of regexps saying which buffers should have their own special frames.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
626 When displaying a buffer with `display-buffer' or
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
627 `pop-to-buffer', if any regexp in this list matches the buffer
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
628 name, it makes a special frame for the buffer by calling
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
629 `special-display-function'.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
630
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
631 An element of the list can be a list instead of just a string.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
632 There are two ways to use a list as an element:
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
633 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
634 In the first case, the FRAME-PARAMETERS are pairs of the form
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
635 \(PARAMETER . VALUE); these parameter values are used to create
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
636 the frame. In the second case, FUNCTION is called with BUFFER as
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
637 the first argument, followed by the OTHER-ARGS--it can display
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
638 the buffer in any way it likes. All this is done by the function
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
639 found in `special-display-function'.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
640
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
641 If the specified frame parameters include (same-buffer . t), the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
642 buffer is displayed in the currently selected window. Otherwise,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
643 if they include (same-frame . t), the buffer is displayed in a
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
644 new window in the currently selected frame.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
645
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
646 If this variable appears \"not to work\", because you add a
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
647 regexp to it but the matching buffers still appear in the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
648 selected window, look at the values of `same-window-buffer-names'
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
649 and `same-window-regexps'. Those variables take precedence over
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
650 this one."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
651 :type '(repeat (choice :tag "Buffer"
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
652 :value ""
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
653 (regexp :format "%v")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
654 (cons :tag "With attributes"
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
655 :format "%v"
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
656 :value ("" . nil)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
657 (regexp :format "%v")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
658 (repeat :tag "Attributes"
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
659 (cons :format "%v"
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
660 (symbol :tag "Parameter")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
661 (sexp :tag "Value"))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
662 :group 'frames)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
663
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
664 (defcustom special-display-function 'special-display-popup-frame
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
665 "Function to call to make a new frame for a special buffer.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
666 It is called with two arguments, the buffer and optional buffer
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
667 specific data, and should return a window displaying that buffer.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
668 The default value normally makes a separate frame for the buffer,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
669 using `special-display-frame-alist' to specify the frame
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
670 parameters.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
671
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
672 But if the buffer specific data includes (same-buffer . t) then
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
673 the buffer is displayed in the current selected window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
674 Otherwise if it includes (same-frame . t) then the buffer is
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
675 displayed in a new window in the currently selected frame.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
676
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
677 A buffer is special if it is listed in
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
678 `special-display-buffer-names' or matches a regexp in
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
679 `special-display-regexps'."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
680 :type 'function
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
681 :group 'frames)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
682
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
683 (defun same-window-p (buffer-name)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
684 "Return non-nil if a buffer named BUFFER-NAME would be shown in the \"same\" window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
685 This function returns non-nil if `display-buffer' or
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
686 `pop-to-buffer' would show a buffer named BUFFER-NAME in the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
687 selected rather than \(as usual\) some other window. See
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
688 `same-window-buffer-names' and `same-window-regexps'."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
689 (cond
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
690 ((not (stringp buffer-name)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
691 ;; The elements of `same-window-buffer-names' can be buffer
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
692 ;; names or cons cells whose cars are buffer names.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
693 ((member buffer-name same-window-buffer-names))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
694 ((assoc buffer-name same-window-buffer-names))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
695 ((catch 'found
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
696 (dolist (regexp same-window-regexps)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
697 ;; The elements of `same-window-regexps' can be regexps
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
698 ;; or cons cells whose cars are regexps.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
699 (when (or (and (stringp regexp)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
700 (string-match regexp buffer-name))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
701 (and (consp regexp) (stringp (car regexp))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
702 (string-match-p (car regexp) buffer-name)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
703 (throw 'found t)))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
704
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
705 (defcustom same-window-buffer-names nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
706 "List of names of buffers that should appear in the \"same\" window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
707 `display-buffer' and `pop-to-buffer' show a buffer whose name is
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
708 on this list in the selected rather than some other window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
709
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
710 An element of this list can be a cons cell instead of just a
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
711 string. In that case the car must be a string specifying the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
712 buffer name. This is for compatibility with
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
713 `special-display-buffer-names'; the cdr of the cons cell is
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
714 ignored.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
715
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
716 See also `same-window-regexps'."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
717 :type '(repeat (string :format "%v"))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
718 :group 'windows)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
719
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
720 (defcustom same-window-regexps nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
721 "List of regexps saying which buffers should appear in the \"same\" window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
722 `display-buffer' and `pop-to-buffer' show a buffer whose name
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
723 matches a regexp on this list in the selected rather than some
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
724 other window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
725
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
726 An element of this list can be a cons cell instead of just a
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
727 string. In that case the car must be a string, which specifies
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
728 the buffer name. This is for compatibility with
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
729 `special-display-buffer-names'; the cdr of the cons cell is
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
730 ignored.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
731
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
732 See also `same-window-buffer-names'."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
733 :type '(repeat (regexp :format "%v"))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
734 :group 'windows)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
735
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
736 (defcustom pop-up-frames nil
98577
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
737 "Whether `display-buffer' should make a separate frame.
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
738 If nil, never make a seperate frame.
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
739 If the value is `graphic-only', make a separate frame
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
740 on graphic displays only.
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
741 Any other non-nil value means always make a separate frame."
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
742 :type '(choice
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
743 (const :tag "Never" nil)
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
744 (const :tag "On graphic displays only" graphic-only)
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
745 (const :tag "Always" t))
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
746 :group 'windows)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
747
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
748 (defcustom display-buffer-reuse-frames nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
749 "Non-nil means `display-buffer' should reuse frames.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
750 If the buffer in question is already displayed in a frame, raise
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
751 that frame."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
752 :type 'boolean
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
753 :version "21.1"
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
754 :group 'windows)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
755
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
756 (defcustom pop-up-windows t
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
757 "Non-nil means `display-buffer' should make a new window."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
758 :type 'boolean
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
759 :group 'windows)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
760
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
761 (defcustom split-height-threshold 80
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
762 "Minimum height of window to be split vertically.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
763 If the value is a number, `display-buffer' can split a window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
764 only if it has at least as many lines. If the value is nil,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
765 `display-buffer' cannot split a window vertically.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
766
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
767 If the window is the only window on its frame, `display-buffer'
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
768 can split it regardless of this value."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
769 :type '(choice (const nil) (number :tag "lines"))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
770 :version "23.1"
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
771 :group 'windows)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
772
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
773 (defcustom split-width-threshold 160
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
774 "Minimum width of window to be split horizontally.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
775 If the value is a number, `display-buffer' can split a window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
776 only if it has at least as many columns. If the value is nil,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
777 `display-buffer' cannot split a window horizontally."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
778 :type '(choice (const nil) (number :tag "columns"))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
779 :version "23.1"
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
780 :group 'windows)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
781
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
782 (defcustom split-window-preferred-function nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
783 "Function used by `display-buffer' to split windows.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
784 If non-nil, a function called with a window as single argument
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
785 supposed to split that window and return the new window. If the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
786 function returns nil the window is not split.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
787
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
788 If nil, `display-buffer' will split the window respecting the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
789 values of `split-height-threshold' and `split-width-threshold'."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
790 :type '(choice (const nil) (function :tag "Function"))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
791 :version "23.1"
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
792 :group 'windows)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
793
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
794 (defun window--splittable-p (window &optional horizontal)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
795 "Return non-nil if WINDOW can be split evenly.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
796 Optional argument HORIZONTAL non-nil means check whether WINDOW
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
797 can be split horizontally.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
798
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
799 WINDOW can be split vertically when the following conditions
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
800 hold:
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
801
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
802 - `window-size-fixed' is either nil or equals `width' for the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
803 buffer of WINDOW.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
804
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
805 - `split-height-threshold' is a number and WINDOW is at least as
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
806 high as `split-height-threshold'.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
807
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
808 - When WINDOW is split evenly, the emanating windows are at least
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
809 `window-min-height' lines tall and can accommodate at least one
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
810 line plus - if WINDOW has one - a mode line.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
811
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
812 WINDOW can be split horizontally when the following conditions
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
813 hold:
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
814
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
815 - `window-size-fixed' is either nil or equals `height' for the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
816 buffer of WINDOW.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
817
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
818 - `split-width-threshold' is a number and WINDOW is at least as
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
819 wide as `split-width-threshold'.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
820
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
821 - When WINDOW is split evenly, the emanating windows are at least
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
822 `window-min-width' or two (whichever is larger) columns wide."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
823 (when (window-live-p window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
824 (with-current-buffer (window-buffer window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
825 (if horizontal
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
826 ;; A window can be split horizontally when its width is not
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
827 ;; fixed, it is at least `split-width-threshold' columns wide
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
828 ;; and at least twice as wide as `window-min-width' and 2 (the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
829 ;; latter value is hardcoded).
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
830 (and (memq window-size-fixed '(nil height))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
831 ;; Testing `window-full-width-p' here hardly makes any
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
832 ;; sense nowadays. This can be done more intuitively by
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
833 ;; setting up `split-width-threshold' appropriately.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
834 (numberp split-width-threshold)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
835 (>= (window-width window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
836 (max split-width-threshold
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
837 (* 2 (max window-min-width 2)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
838 ;; A window can be split vertically when its height is not
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
839 ;; fixed, it is at least `split-height-threshold' lines high,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
840 ;; and it is at least twice as high as `window-min-height' and 2
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
841 ;; if it has a modeline or 1.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
842 (and (memq window-size-fixed '(nil width))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
843 (numberp split-height-threshold)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
844 (>= (window-height window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
845 (max split-height-threshold
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
846 (* 2 (max window-min-height
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
847 (if mode-line-format 2 1))))))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
848
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
849 (defun window--try-to-split-window (window)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
850 "Split WINDOW if it is splittable.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
851 See `window--splittable-p' for how to determine whether a window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
852 is splittable. If WINDOW can be split, return the value returned
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
853 by `split-window' (or `split-window-preferred-function')."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
854 (when (and (window-live-p window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
855 (not (frame-parameter (window-frame window) 'unsplittable)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
856 (if (functionp split-window-preferred-function)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
857 ;; `split-window-preferred-function' is specified, so use it.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
858 (funcall split-window-preferred-function window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
859 (or (and (window--splittable-p window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
860 ;; Split window vertically.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
861 (split-window window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
862 (and (window--splittable-p window t)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
863 ;; Split window horizontally.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
864 (split-window window nil t))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
865 (and (eq window (frame-root-window (window-frame window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
866 (not (window-minibuffer-p window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
867 ;; If WINDOW is the only window on its frame and not the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
868 ;; minibuffer window, attempt to split it vertically
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
869 ;; disregarding the value of `split-height-threshold'.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
870 (let ((split-height-threshold 0))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
871 (and (window--splittable-p window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
872 (split-window window))))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
873
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
874 (defun window--frame-usable-p (frame)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
875 "Return FRAME if it can be used to display a buffer."
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
876 (when (frame-live-p frame)
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
877 (let ((window (frame-root-window frame)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
878 ;; `frame-root-window' may be an internal window which is considered
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
879 ;; "dead" by `window-live-p'. Hence if `window' is not live we
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
880 ;; implicitly know that `frame' has a visible window we can use.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
881 (when (or (not (window-live-p window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
882 (and (not (window-minibuffer-p window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
883 (not (window-dedicated-p window))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
884 frame))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
885
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
886 (defcustom even-window-heights t
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
887 "If non-nil `display-buffer' will try to even window heights.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
888 Otherwise `display-buffer' will leave the window configuration
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
889 alone. Heights are evened only when `display-buffer' chooses a
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
890 window that appears above or below the selected window."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
891 :type 'boolean
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
892 :group 'windows)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
893
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
894 (defun window--even-window-heights (window)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
895 "Even heights of WINDOW and selected window.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
896 Do this only if these windows are vertically adjacent to each
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
897 other, `even-window-heights' is non-nil, and the selected window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
898 is higher than WINDOW."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
899 (when (and even-window-heights
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
900 (not (eq window (selected-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
901 ;; Don't resize minibuffer windows.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
902 (not (window-minibuffer-p (selected-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
903 (> (window-height (selected-window)) (window-height window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
904 (eq (window-frame window) (window-frame (selected-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
905 (let ((sel-edges (window-edges (selected-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
906 (win-edges (window-edges window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
907 (and (= (nth 0 sel-edges) (nth 0 win-edges))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
908 (= (nth 2 sel-edges) (nth 2 win-edges))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
909 (or (= (nth 1 sel-edges) (nth 3 win-edges))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
910 (= (nth 3 sel-edges) (nth 1 win-edges))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
911 (let ((window-min-height 1))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
912 ;; Don't throw an error if we can't even window heights for
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
913 ;; whatever reason.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
914 (condition-case nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
915 (enlarge-window (/ (- (window-height window) (window-height)) 2))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
916 (error nil)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
917
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
918 (defun window--display-buffer-1 (window)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
919 "Raise the frame containing WINDOW.
98487
93f3b87e5666 (window--display-buffer-1): Don't care about
Martin Rudalics <rudalics@gmx.at>
parents: 98165
diff changeset
920 Do not raise the selected frame. Return WINDOW."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
921 (let* ((frame (window-frame window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
922 (visible (frame-visible-p frame)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
923 (unless (or (not visible)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
924 ;; Assume the selected frame is already visible enough.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
925 (eq frame (selected-frame))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
926 ;; Assume the frame from which we invoked the minibuffer
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
927 ;; is visible.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
928 (and (minibuffer-window-active-p (selected-window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
929 (eq frame (window-frame (minibuffer-selected-window)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
930 (raise-frame frame))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
931 window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
932
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
933 (defun window--display-buffer-2 (buffer window)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
934 "Display BUFFER in WINDOW and make its frame visible.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
935 Return WINDOW."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
936 (when (and (buffer-live-p buffer) (window-live-p window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
937 (set-window-buffer window buffer)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
938 (window--display-buffer-1 window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
939
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
940 (defun display-buffer (buffer-or-name &optional not-this-window frame)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
941 "Make buffer BUFFER-OR-NAME appear in some window but don't select it.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
942 BUFFER-OR-NAME must be a buffer or the name of an existing
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
943 buffer. Return the window chosen to display BUFFER-OR-NAME or
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
944 nil if no such window is found.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
945
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
946 Optional argument NOT-THIS-WINDOW non-nil means display the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
947 buffer in a window other than the selected one, even if it is
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
948 already displayed in the selected window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
949
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
950 Optional argument FRAME specifies which frames to investigate
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
951 when the specified buffer is already displayed. If the buffer is
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
952 already displayed in some window on one of these frames simply
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
953 return that window. Possible values of FRAME are:
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
954
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
955 `visible' - consider windows on all visible frames.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
956
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
957 0 - consider windows on all visible or iconified frames.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
958
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
959 t - consider windows on all frames.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
960
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
961 A specific frame - consider windows on that frame only.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
962
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
963 nil - consider windows on the selected frame \(actually the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
964 last non-minibuffer frame\) only. If, however, either
98577
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
965 `display-buffer-reuse-frames' or `pop-up-frames' is non-nil
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
966 \(non-nil and not graphic-only on a text-only terminal),
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
967 consider all visible or iconified frames."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
968 (interactive "BDisplay buffer:\nP")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
969 (let* ((can-use-selected-window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
970 ;; The selected window is usable unless either NOT-THIS-WINDOW
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
971 ;; is non-nil, it is dedicated to its buffer, or it is the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
972 ;; `minibuffer-window'.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
973 (not (or not-this-window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
974 (window-dedicated-p (selected-window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
975 (window-minibuffer-p))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
976 (buffer (if (bufferp buffer-or-name)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
977 buffer-or-name
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
978 (get-buffer buffer-or-name)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
979 (name-of-buffer (buffer-name buffer))
98577
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
980 ;; On text-only terminals do not pop up a new frame when
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
981 ;; `pop-up-frames' equals graphic-only.
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
982 (use-pop-up-frames (if (eq pop-up-frames 'graphic-only)
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
983 (display-graphic-p)
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
984 pop-up-frames))
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
985 ;; `frame-to-use' is the frame where to show `buffer' - either
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
986 ;; the selected frame or the last nonminibuffer frame.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
987 (frame-to-use
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
988 (or (window--frame-usable-p (selected-frame))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
989 (window--frame-usable-p (last-nonminibuffer-frame))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
990 ;; `window-to-use' is the window we use for showing `buffer'.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
991 window-to-use)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
992 (cond
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
993 ((not (buffer-live-p buffer))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
994 (error "No such buffer %s" buffer))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
995 (display-buffer-function
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
996 ;; Let `display-buffer-function' do the job.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
997 (funcall display-buffer-function buffer not-this-window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
998 ((and (not not-this-window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
999 (eq (window-buffer (selected-window)) buffer))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1000 ;; The selected window already displays BUFFER and
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1001 ;; `not-this-window' is nil, so use it.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1002 (window--display-buffer-1 (selected-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1003 ((and can-use-selected-window (same-window-p name-of-buffer))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1004 ;; If the buffer's name tells us to use the selected window do so.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1005 (window--display-buffer-2 buffer (selected-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1006 ((let ((frames (or frame
98577
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
1007 (and (or use-pop-up-frames
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
1008 display-buffer-reuse-frames
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1009 (not (last-nonminibuffer-frame)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1010 0)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1011 (last-nonminibuffer-frame))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1012 (and (setq window-to-use (get-buffer-window buffer frames))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1013 (or can-use-selected-window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1014 (not (eq (selected-window) window-to-use)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1015 ;; If the buffer is already displayed in some window use that.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1016 (window--display-buffer-1 window-to-use))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1017 ((and special-display-function
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1018 ;; `special-display-p' returns either t or a list of frame
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1019 ;; parameters to pass to `special-display-function'.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1020 (let ((pars (special-display-p name-of-buffer)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1021 (when pars
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1022 (funcall special-display-function
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1023 buffer (if (listp pars) pars))))))
98577
457b5cef3f44 (pop-up-frames): Add choice graphic-only.
Martin Rudalics <rudalics@gmx.at>
parents: 98487
diff changeset
1024 ((or use-pop-up-frames (not frame-to-use))
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1025 ;; We want or need a new frame.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1026 (window--display-buffer-2
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1027 buffer (frame-selected-window (funcall pop-up-frame-function))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1028 ((and pop-up-windows
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1029 ;; Make a new window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1030 (or (not (frame-parameter frame-to-use 'unsplittable))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1031 ;; If the selected frame cannot be split look at
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1032 ;; `last-nonminibuffer-frame'.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1033 (and (eq frame-to-use (selected-frame))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1034 (setq frame-to-use (last-nonminibuffer-frame))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1035 (window--frame-usable-p frame-to-use)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1036 (not (frame-parameter frame-to-use 'unsplittable))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1037 ;; Attempt to split largest or least recently used window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1038 (setq window-to-use
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1039 (or (window--try-to-split-window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1040 (get-largest-window frame-to-use t))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1041 (window--try-to-split-window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1042 (get-lru-window frame-to-use t))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1043 (window--display-buffer-2 buffer window-to-use)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1044 ((setq window-to-use
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1045 ;; Reuse an existing window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1046 (or (get-lru-window frame-to-use)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1047 (get-buffer-window buffer 'visible)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1048 (get-largest-window 'visible nil)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1049 (get-buffer-window buffer 0)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1050 (get-largest-window 0 nil)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1051 (frame-selected-window (funcall pop-up-frame-function))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1052 (window--even-window-heights window-to-use)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1053 (window--display-buffer-2 buffer window-to-use)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1054
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1055 (defun pop-to-buffer (buffer-or-name &optional other-window norecord)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1056 "Select buffer BUFFER-OR-NAME in some window, preferably a different one.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1057 BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1058 nil. If BUFFER-OR-NAME is a string not naming an existent
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1059 buffer, create a buffer with that name. If BUFFER-OR-NAME is
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1060 nil, choose some other buffer.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1061
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1062 If `pop-up-windows' is non-nil, windows can be split to display
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1063 the buffer. If optional second arg OTHER-WINDOW is non-nil,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1064 insist on finding another window even if the specified buffer is
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1065 already visible in the selected window, and ignore
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1066 `same-window-regexps' and `same-window-buffer-names'.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1067
98141
2184b626a9cc (pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents: 98135
diff changeset
1068 If the window to show BUFFER-OR-NAME is not on the selected
2184b626a9cc (pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents: 98135
diff changeset
1069 frame, raise that window's frame and give it input focus.
2184b626a9cc (pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents: 98135
diff changeset
1070
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1071 This function returns the buffer it switched to. This uses the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1072 function `display-buffer' as a subroutine; see the documentation
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1073 of `display-buffer' for additional customization information.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1074
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1075 Optional third arg NORECORD non-nil means do not put this buffer
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1076 at the front of the list of recently selected ones."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1077 (let ((buffer
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1078 ;; FIXME: This behavior is carried over from the previous C version
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1079 ;; of pop-to-buffer, but really we should use just
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1080 ;; `get-buffer' here.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1081 (if (null buffer-or-name) (other-buffer (current-buffer))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1082 (or (get-buffer buffer-or-name)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1083 (let ((buf (get-buffer-create buffer-or-name)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1084 (set-buffer-major-mode buf)
98141
2184b626a9cc (pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents: 98135
diff changeset
1085 buf))))
2184b626a9cc (pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents: 98135
diff changeset
1086 (old-window (selected-window))
2184b626a9cc (pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents: 98135
diff changeset
1087 (old-frame (selected-frame))
2184b626a9cc (pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents: 98135
diff changeset
1088 new-window new-frame)
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1089 (set-buffer buffer)
98607
234a18b5c81e (pop-to-buffer): Fix misplacement of arg norecord in
Martin Rudalics <rudalics@gmx.at>
parents: 98577
diff changeset
1090 (setq new-window (display-buffer buffer other-window))
98141
2184b626a9cc (pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents: 98135
diff changeset
1091 (unless (eq new-window old-window)
98165
8b39b6502384 (pop-to-buffer): Select window before calling
Martin Rudalics <rudalics@gmx.at>
parents: 98141
diff changeset
1092 ;; `display-buffer' has chosen another window, select it.
98607
234a18b5c81e (pop-to-buffer): Fix misplacement of arg norecord in
Martin Rudalics <rudalics@gmx.at>
parents: 98577
diff changeset
1093 (select-window new-window norecord)
98141
2184b626a9cc (pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents: 98135
diff changeset
1094 (setq new-frame (window-frame new-window))
2184b626a9cc (pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents: 98135
diff changeset
1095 (unless (eq new-frame old-frame)
2184b626a9cc (pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents: 98135
diff changeset
1096 ;; `display-buffer' has chosen another frame, make sure it gets
2184b626a9cc (pop-to-buffer): If the window for buffer-or-name is
Martin Rudalics <rudalics@gmx.at>
parents: 98135
diff changeset
1097 ;; input focus and is risen.
98165
8b39b6502384 (pop-to-buffer): Select window before calling
Martin Rudalics <rudalics@gmx.at>
parents: 98141
diff changeset
1098 (select-frame-set-input-focus new-frame)))
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1099 buffer))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1100
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1101 ;; I think this should be the default; I think people will prefer it--rms.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1102 (defcustom split-window-keep-point t
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1103 "If non-nil, \\[split-window-vertically] keeps the original point \
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1104 in both children.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1105 This is often more convenient for editing.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1106 If nil, adjust point in each of the two windows to minimize redisplay.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1107 This is convenient on slow terminals, but point can move strangely.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1108
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1109 This option applies only to `split-window-vertically' and
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1110 functions that call it. `split-window' always keeps the original
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1111 point in both children."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1112 :type 'boolean
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1113 :group 'windows)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1114
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1115 (defun split-window-vertically (&optional size)
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1116 "Split selected window into two windows, one above the other.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1117 The upper window gets SIZE lines and the lower one gets the rest.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1118 SIZE negative means the lower window gets -SIZE lines and the
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1119 upper one the rest. With no argument, split windows equally or
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1120 close to it. Both windows display the same buffer, now current.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1121
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1122 If the variable `split-window-keep-point' is non-nil, both new
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1123 windows will get the same value of point as the selected window.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1124 This is often more convenient for editing. The upper window is
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1125 the selected window.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1126
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1127 Otherwise, we choose window starts so as to minimize the amount of
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1128 redisplay; this is convenient on slow terminals. The new selected
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1129 window is the one that the current value of point appears in. The
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1130 value of point can change if the text around point is hidden by the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1131 new mode line.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1132
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1133 Regardless of the value of `split-window-keep-point', the upper
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1134 window is the original one and the return value is the new, lower
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1135 window."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1136 (interactive "P")
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1137 (let ((old-window (selected-window))
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1138 (old-point (point))
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1139 (size (and size (prefix-numeric-value size)))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1140 moved-by-window-height moved new-window bottom)
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1141 (and size (< size 0)
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1142 ;; Handle negative SIZE value.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1143 (setq size (+ (window-height) size)))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1144 (setq new-window (split-window nil size))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1145 (unless split-window-keep-point
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1146 (save-excursion
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1147 (set-buffer (window-buffer))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1148 (goto-char (window-start))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1149 (setq moved (vertical-motion (window-height)))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1150 (set-window-start new-window (point))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1151 (when (> (point) (window-point new-window))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1152 (set-window-point new-window (point)))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1153 (when (= moved (window-height))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1154 (setq moved-by-window-height t)
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1155 (vertical-motion -1))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1156 (setq bottom (point)))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1157 (and moved-by-window-height
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1158 (<= bottom (point))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1159 (set-window-point old-window (1- bottom)))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1160 (and moved-by-window-height
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1161 (<= (window-start new-window) old-point)
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1162 (set-window-point new-window old-point)
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1163 (select-window new-window)))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1164 (split-window-save-restore-data new-window old-window)))
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1165
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1166 ;; This is to avoid compiler warnings.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1167 (defvar view-return-to-alist)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1168
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1169 (defun split-window-save-restore-data (new-window old-window)
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1170 (with-current-buffer (window-buffer)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1171 (when view-mode
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1172 (let ((old-info (assq old-window view-return-to-alist)))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1173 (when old-info
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1174 (push (cons new-window (cons (car (cdr old-info)) t))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1175 view-return-to-alist))))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1176 new-window))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1177
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1178 (defun split-window-horizontally (&optional size)
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1179 "Split selected window into two windows side by side.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1180 The selected window becomes the left one and gets SIZE columns.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1181 SIZE negative means the right window gets -SIZE lines.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1182
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1183 SIZE includes the width of the window's scroll bar; if there are
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1184 no scroll bars, it includes the width of the divider column to
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1185 the window's right, if any. SIZE omitted or nil means split
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1186 window equally.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1187
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1188 The selected window remains selected. Return the new window."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1189 (interactive "P")
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1190 (let ((old-window (selected-window))
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1191 (size (and size (prefix-numeric-value size))))
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1192 (and size (< size 0)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1193 ;; Handle negative SIZE value.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1194 (setq size (+ (window-width) size)))
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1195 (split-window-save-restore-data (split-window nil size t) old-window)))
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1196
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1197
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1198 (defun set-window-text-height (window height)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1199 "Sets the height in lines of the text display area of WINDOW to HEIGHT.
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1200 HEIGHT doesn't include the mode line or header line, if any, or
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1201 any partial-height lines in the text display area.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1202
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1203 Note that the current implementation of this function cannot
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1204 always set the height exactly, but attempts to be conservative,
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1205 by allocating more lines than are actually needed in the case
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1206 where some error may be present."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1207 (let ((delta (- height (window-text-height window))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1208 (unless (zerop delta)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1209 ;; Setting window-min-height to a value like 1 can lead to very
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1210 ;; bizarre displays because it also allows Emacs to make *other*
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1211 ;; windows 1-line tall, which means that there's no more space for
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1212 ;; the modeline.
99326
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
1213 (let ((window-min-height (min 2 height))) ; One text line plus a modeline.
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1214 (if (and window (not (eq window (selected-window))))
99357
47fe276a8011 (save-selected-window): Make it behave like
Martin Rudalics <rudalics@gmx.at>
parents: 99326
diff changeset
1215 (save-selected-window
99326
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
1216 (select-window window 'norecord)
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1217 (enlarge-window delta))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1218 (enlarge-window delta))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1219
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1220
98886
49a2b54dc78a (enlarge-window-horizontally, shrink-window-horizontally):
Martin Rudalics <rudalics@gmx.at>
parents: 98607
diff changeset
1221 (defun enlarge-window-horizontally (columns)
49a2b54dc78a (enlarge-window-horizontally, shrink-window-horizontally):
Martin Rudalics <rudalics@gmx.at>
parents: 98607
diff changeset
1222 "Make selected window COLUMNS wider.
49a2b54dc78a (enlarge-window-horizontally, shrink-window-horizontally):
Martin Rudalics <rudalics@gmx.at>
parents: 98607
diff changeset
1223 Interactively, if no argument is given, make selected window one
49a2b54dc78a (enlarge-window-horizontally, shrink-window-horizontally):
Martin Rudalics <rudalics@gmx.at>
parents: 98607
diff changeset
1224 column wider."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1225 (interactive "p")
98886
49a2b54dc78a (enlarge-window-horizontally, shrink-window-horizontally):
Martin Rudalics <rudalics@gmx.at>
parents: 98607
diff changeset
1226 (enlarge-window columns t))
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1227
98886
49a2b54dc78a (enlarge-window-horizontally, shrink-window-horizontally):
Martin Rudalics <rudalics@gmx.at>
parents: 98607
diff changeset
1228 (defun shrink-window-horizontally (columns)
49a2b54dc78a (enlarge-window-horizontally, shrink-window-horizontally):
Martin Rudalics <rudalics@gmx.at>
parents: 98607
diff changeset
1229 "Make selected window COLUMNS narrower.
49a2b54dc78a (enlarge-window-horizontally, shrink-window-horizontally):
Martin Rudalics <rudalics@gmx.at>
parents: 98607
diff changeset
1230 Interactively, if no argument is given, make selected window one
49a2b54dc78a (enlarge-window-horizontally, shrink-window-horizontally):
Martin Rudalics <rudalics@gmx.at>
parents: 98607
diff changeset
1231 column narrower."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1232 (interactive "p")
98886
49a2b54dc78a (enlarge-window-horizontally, shrink-window-horizontally):
Martin Rudalics <rudalics@gmx.at>
parents: 98607
diff changeset
1233 (shrink-window columns t))
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1234
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1235 (defun window-buffer-height (window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1236 "Return the height (in screen lines) of the buffer that WINDOW is displaying."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1237 (with-current-buffer (window-buffer window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1238 (max 1
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1239 (count-screen-lines (point-min) (point-max)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1240 ;; If buffer ends with a newline, ignore it when
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1241 ;; counting height unless point is after it.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1242 (eobp)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1243 window))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1244
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1245 (defun count-screen-lines (&optional beg end count-final-newline window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1246 "Return the number of screen lines in the region.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1247 The number of screen lines may be different from the number of actual lines,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1248 due to line breaking, display table, etc.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1249
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1250 Optional arguments BEG and END default to `point-min' and `point-max'
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1251 respectively.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1252
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1253 If region ends with a newline, ignore it unless optional third argument
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1254 COUNT-FINAL-NEWLINE is non-nil.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1255
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1256 The optional fourth argument WINDOW specifies the window used for obtaining
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1257 parameters such as width, horizontal scrolling, and so on. The default is
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1258 to use the selected window's parameters.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1259
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1260 Like `vertical-motion', `count-screen-lines' always uses the current buffer,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1261 regardless of which buffer is displayed in WINDOW. This makes possible to use
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1262 `count-screen-lines' in any buffer, whether or not it is currently displayed
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1263 in some window."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1264 (unless beg
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1265 (setq beg (point-min)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1266 (unless end
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1267 (setq end (point-max)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1268 (if (= beg end)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1269 0
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1270 (save-excursion
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1271 (save-restriction
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1272 (widen)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1273 (narrow-to-region (min beg end)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1274 (if (and (not count-final-newline)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1275 (= ?\n (char-before (max beg end))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1276 (1- (max beg end))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1277 (max beg end)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1278 (goto-char (point-min))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1279 (1+ (vertical-motion (buffer-size) window))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1280
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1281 (defun fit-window-to-buffer (&optional window max-height min-height)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1282 "Adjust height of WINDOW to display its buffer's contents exactly.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1283 WINDOW defaults to the selected window.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1284 Optional argument MAX-HEIGHT specifies the maximum height of the
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1285 window and defaults to the height of WINDOW's frame.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1286 Optional argument MIN-HEIGHT specifies the minimum height of the
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1287 window and defaults to `window-min-height'.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1288 Both, MAX-HEIGHT and MIN-HEIGHT are specified in lines and
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1289 include the mode line and header line, if any.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1290 Always return nil."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1291 (interactive)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1292
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1293 (when (null window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1294 (setq window (selected-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1295 (when (null max-height)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1296 (setq max-height (frame-height (window-frame window))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1297
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1298 (let* ((buf
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1299 ;; Buffer that is displayed in WINDOW
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1300 (window-buffer window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1301 (window-height
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1302 ;; The current height of WINDOW
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1303 (window-height window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1304 (desired-height
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1305 ;; The height necessary to show the buffer displayed by WINDOW
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1306 ;; (`count-screen-lines' always works on the current buffer).
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1307 (with-current-buffer buf
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1308 (+ (count-screen-lines)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1309 ;; If the buffer is empty, (count-screen-lines) is
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1310 ;; zero. But, even in that case, we need one text line
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1311 ;; for cursor.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1312 (if (= (point-min) (point-max))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1313 1 0)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1314 ;; For non-minibuffers, count the mode-line, if any
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1315 (if (and (not (window-minibuffer-p window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1316 mode-line-format)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1317 1 0)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1318 ;; Count the header-line, if any
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1319 (if header-line-format 1 0))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1320 (delta
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1321 ;; Calculate how much the window height has to change to show
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1322 ;; desired-height lines, constrained by MIN-HEIGHT and MAX-HEIGHT.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1323 (- (max (min desired-height max-height)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1324 (or min-height window-min-height))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1325 window-height)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1326
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1327 ;; Don't try to redisplay with the cursor at the end
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1328 ;; on its own line--that would force a scroll and spoil things.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1329 (when (with-current-buffer buf
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1330 (and (eobp) (bolp) (not (bobp))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1331 (set-window-point window (1- (window-point window))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1332
99357
47fe276a8011 (save-selected-window): Make it behave like
Martin Rudalics <rudalics@gmx.at>
parents: 99326
diff changeset
1333 (save-selected-window
99326
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
1334 (select-window window 'norecord)
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1335
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1336 ;; Adjust WINDOW to the nominally correct size (which may actually
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1337 ;; be slightly off because of variable height text, etc).
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1338 (unless (zerop delta)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1339 (enlarge-window delta))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1340
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1341 ;; Check if the last line is surely fully visible. If not,
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1342 ;; enlarge the window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1343 (let ((end (with-current-buffer buf
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1344 (save-excursion
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1345 (goto-char (point-max))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1346 (when (and (bolp) (not (bobp)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1347 ;; Don't include final newline
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1348 (backward-char 1))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1349 (when truncate-lines
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1350 ;; If line-wrapping is turned off, test the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1351 ;; beginning of the last line for visibility
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1352 ;; instead of the end, as the end of the line
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1353 ;; could be invisible by virtue of extending past
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1354 ;; the edge of the window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1355 (forward-line 0))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1356 (point)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1357 (set-window-vscroll window 0)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1358 (while (and (< desired-height max-height)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1359 (= desired-height (window-height window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1360 (not (pos-visible-in-window-p end window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1361 (enlarge-window 1)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1362 (setq desired-height (1+ desired-height)))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1363
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1364 (defun shrink-window-if-larger-than-buffer (&optional window)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1365 "Shrink height of WINDOW if its buffer doesn't need so many lines.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1366 More precisely, shrink WINDOW vertically to be as small as
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1367 possible, while still showing the full contents of its buffer.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1368 WINDOW defaults to the selected window.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1369
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1370 Do not shrink to less than `window-min-height' lines. Do nothing
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1371 if the buffer contains more lines than the present window height,
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1372 or if some of the window's contents are scrolled out of view, or
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1373 if shrinking this window would also shrink another window, or if
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1374 the window is the only window of its frame.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1375
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1376 Return non-nil if the window was shrunk, nil otherwise."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1377 (interactive)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1378 (when (null window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1379 (setq window (selected-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1380 (let* ((frame (window-frame window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1381 (mini (frame-parameter frame 'minibuffer))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1382 (edges (window-edges window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1383 (if (and (not (eq window (frame-root-window frame)))
99326
100dbcced8f3 (save-selected-window-norecord): New macro
Martin Rudalics <rudalics@gmx.at>
parents: 99275
diff changeset
1384 (window-safely-shrinkable-p window)
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1385 (pos-visible-in-window-p (point-min) window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1386 (not (eq mini 'only))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1387 (or (not mini)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1388 (let ((mini-window (minibuffer-window frame)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1389 (or (null mini-window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1390 (not (eq frame (window-frame mini-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1391 (< (nth 3 edges)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1392 (nth 1 (window-edges mini-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1393 (> (nth 1 edges)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1394 (frame-parameter frame 'menu-bar-lines))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1395 (fit-window-to-buffer window (window-height window)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1396
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1397 (defun kill-buffer-and-window ()
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1398 "Kill the current buffer and delete the selected window."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1399 (interactive)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1400 (let ((window-to-delete (selected-window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1401 (buffer-to-kill (current-buffer))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1402 (delete-window-hook (lambda ()
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1403 (condition-case nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1404 (delete-window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1405 (error nil)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1406 (unwind-protect
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1407 (progn
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1408 (add-hook 'kill-buffer-hook delete-window-hook t t)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1409 (if (kill-buffer (current-buffer))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1410 ;; If `delete-window' failed before, we rerun it to regenerate
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1411 ;; the error so it can be seen in the echo area.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1412 (when (eq (selected-window) window-to-delete)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1413 (delete-window))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1414 ;; If the buffer is not dead for some reason (probably because
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1415 ;; of a `quit' signal), remove the hook again.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1416 (condition-case nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1417 (with-current-buffer buffer-to-kill
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1418 (remove-hook 'kill-buffer-hook delete-window-hook t))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1419 (error nil)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1420
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1421 (defun quit-window (&optional kill window)
99249
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1422 "Bury or kill (with KILL non-nil) the buffer displayed in WINDOW.
99394
97cfe3bfabc8 (quit-window): Restore prefix argument behavior
Martin Rudalics <rudalics@gmx.at>
parents: 99357
diff changeset
1423 With a prefix argument, kill the buffer instead.
97cfe3bfabc8 (quit-window): Restore prefix argument behavior
Martin Rudalics <rudalics@gmx.at>
parents: 99357
diff changeset
1424
99249
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1425 KILL defaults to nil, WINDOW to the selected window. If WINDOW
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1426 is dedicated or a minibuffer window, delete it and, if it's the
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1427 only window on its frame, delete its frame as well provided there
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1428 are other frames left. Otherwise, display some other buffer in
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1429 the window."
99394
97cfe3bfabc8 (quit-window): Restore prefix argument behavior
Martin Rudalics <rudalics@gmx.at>
parents: 99357
diff changeset
1430 (interactive "P")
99249
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1431 (let* ((window (or window (selected-window)))
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1432 (buffer (window-buffer window)))
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1433 (if (or (window-minibuffer-p window) (window-dedicated-p window))
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1434 (if (eq window (frame-root-window (window-frame window)))
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1435 ;; If this is the only window on its frame, try to delete the
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1436 ;; frame (`delete-windows-on' knows how to do that).
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1437 (delete-windows-on buffer (selected-frame))
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1438 ;; Other windows are left, delete this window. But don't
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1439 ;; throw an error if that fails for some reason.
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1440 (condition-case nil
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1441 (delete-window window)
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1442 (error nil)))
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1443 ;; The window is neither dedicated nor a minibuffer window,
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1444 ;; display another buffer in it.
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1445 (with-selected-window window
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1446 (switch-to-buffer (other-buffer))))
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1447 ;; Deal with the buffer.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1448 (if kill
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1449 (kill-buffer buffer)
99249
57c1a97ddf78 (quit-window): Simplify code. Say in doc-string
Martin Rudalics <rudalics@gmx.at>
parents: 99122
diff changeset
1450 (bury-buffer buffer))))
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1451
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1452 (defvar recenter-last-op nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1453 "Indicates the last recenter operation performed.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1454 Possible values: `top', `middle', `bottom'.")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1455
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1456 (defun recenter-top-bottom (&optional arg)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1457 "Move current line to window center, top, and bottom, successively.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1458 With no prefix argument, the first call redraws the frame and
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1459 centers point vertically within the window. Successive calls
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1460 scroll the window, placing point on the top, bottom, and middle
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1461 consecutively. The cycling order is middle -> top -> bottom.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1462
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1463 A prefix argument is handled like `recenter':
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1464 With numeric prefix ARG, move current line to window-line ARG.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1465 With plain `C-u', move current line to window center.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1466
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1467 Top and bottom destinations are actually `scroll-margin' lines
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1468 the from true window top and bottom."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1469 (interactive "P")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1470 (cond
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1471 (arg (recenter arg)) ; Always respect ARG.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1472 ((or (not (eq this-command last-command))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1473 (eq recenter-last-op 'bottom))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1474 (setq recenter-last-op 'middle)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1475 (recenter))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1476 (t
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1477 (let ((this-scroll-margin
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1478 (min (max 0 scroll-margin)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1479 (truncate (/ (window-body-height) 4.0)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1480 (cond ((eq recenter-last-op 'middle)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1481 (setq recenter-last-op 'top)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1482 (recenter this-scroll-margin))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1483 ((eq recenter-last-op 'top)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1484 (setq recenter-last-op 'bottom)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1485 (recenter (- -1 this-scroll-margin))))))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1486
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1487 (define-key global-map [?\C-l] 'recenter-top-bottom)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1488
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1489 (defvar mouse-autoselect-window-timer nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1490 "Timer used by delayed window autoselection.")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1491
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1492 (defvar mouse-autoselect-window-position nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1493 "Last mouse position recorded by delayed window autoselection.")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1494
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1495 (defvar mouse-autoselect-window-window nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1496 "Last window recorded by delayed window autoselection.")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1497
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1498 (defvar mouse-autoselect-window-state nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1499 "When non-nil, special state of delayed window autoselection.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1500 Possible values are `suspend' \(suspend autoselection after a menu or
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1501 scrollbar interaction\) and `select' \(the next invocation of
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1502 'handle-select-window' shall select the window immediately\).")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1503
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1504 (defun mouse-autoselect-window-cancel (&optional force)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1505 "Cancel delayed window autoselection.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1506 Optional argument FORCE means cancel unconditionally."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1507 (unless (and (not force)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1508 ;; Don't cancel for select-window or select-frame events
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1509 ;; or when the user drags a scroll bar.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1510 (or (memq this-command
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1511 '(handle-select-window handle-switch-frame))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1512 (and (eq this-command 'scroll-bar-toolkit-scroll)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1513 (memq (nth 4 (event-end last-input-event))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1514 '(handle end-scroll)))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1515 (setq mouse-autoselect-window-state nil)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1516 (when (timerp mouse-autoselect-window-timer)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1517 (cancel-timer mouse-autoselect-window-timer))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1518 (remove-hook 'pre-command-hook 'mouse-autoselect-window-cancel)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1519
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1520 (defun mouse-autoselect-window-start (mouse-position &optional window suspend)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1521 "Start delayed window autoselection.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1522 MOUSE-POSITION is the last position where the mouse was seen as returned
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1523 by `mouse-position'. Optional argument WINDOW non-nil denotes the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1524 window where the mouse was seen. Optional argument SUSPEND non-nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1525 means suspend autoselection."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1526 ;; Record values for MOUSE-POSITION, WINDOW, and SUSPEND.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1527 (setq mouse-autoselect-window-position mouse-position)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1528 (when window (setq mouse-autoselect-window-window window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1529 (setq mouse-autoselect-window-state (when suspend 'suspend))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1530 ;; Install timer which runs `mouse-autoselect-window-select' after
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1531 ;; `mouse-autoselect-window' seconds.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1532 (setq mouse-autoselect-window-timer
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1533 (run-at-time
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1534 (abs mouse-autoselect-window) nil 'mouse-autoselect-window-select)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1535
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1536 (defun mouse-autoselect-window-select ()
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1537 "Select window with delayed window autoselection.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1538 If the mouse position has stabilized in a non-selected window, select
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1539 that window. The minibuffer window is selected only if the minibuffer is
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1540 active. This function is run by `mouse-autoselect-window-timer'."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1541 (condition-case nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1542 (let* ((mouse-position (mouse-position))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1543 (window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1544 (condition-case nil
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1545 (window-at (cadr mouse-position) (cddr mouse-position)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1546 (car mouse-position))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1547 (error nil))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1548 (cond
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1549 ((or (menu-or-popup-active-p)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1550 (and window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1551 (not (coordinates-in-window-p (cdr mouse-position) window))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1552 ;; A menu / popup dialog is active or the mouse is on the scroll-bar
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1553 ;; of WINDOW, temporarily suspend delayed autoselection.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1554 (mouse-autoselect-window-start mouse-position nil t))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1555 ((eq mouse-autoselect-window-state 'suspend)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1556 ;; Delayed autoselection was temporarily suspended, reenable it.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1557 (mouse-autoselect-window-start mouse-position))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1558 ((and window (not (eq window (selected-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1559 (or (not (numberp mouse-autoselect-window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1560 (and (> mouse-autoselect-window 0)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1561 ;; If `mouse-autoselect-window' is positive, select
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1562 ;; window if the window is the same as before.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1563 (eq window mouse-autoselect-window-window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1564 ;; Otherwise select window if the mouse is at the same
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1565 ;; position as before. Observe that the first test after
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1566 ;; starting autoselection usually fails since the value of
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1567 ;; `mouse-autoselect-window-position' recorded there is the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1568 ;; position where the mouse has entered the new window and
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1569 ;; not necessarily where the mouse has stopped moving.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1570 (equal mouse-position mouse-autoselect-window-position))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1571 ;; The minibuffer is a candidate window if it's active.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1572 (or (not (window-minibuffer-p window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1573 (eq window (active-minibuffer-window))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1574 ;; Mouse position has stabilized in non-selected window: Cancel
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1575 ;; delayed autoselection and try to select that window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1576 (mouse-autoselect-window-cancel t)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1577 ;; Select window where mouse appears unless the selected window is the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1578 ;; minibuffer. Use `unread-command-events' in order to execute pre-
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1579 ;; and post-command hooks and trigger idle timers. To avoid delaying
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1580 ;; autoselection again, set `mouse-autoselect-window-state'."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1581 (unless (window-minibuffer-p (selected-window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1582 (setq mouse-autoselect-window-state 'select)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1583 (setq unread-command-events
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1584 (cons (list 'select-window (list window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1585 unread-command-events))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1586 ((or (and window (eq window (selected-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1587 (not (numberp mouse-autoselect-window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1588 (equal mouse-position mouse-autoselect-window-position))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1589 ;; Mouse position has either stabilized in the selected window or at
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1590 ;; `mouse-autoselect-window-position': Cancel delayed autoselection.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1591 (mouse-autoselect-window-cancel t))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1592 (t
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1593 ;; Mouse position has not stabilized yet, resume delayed
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1594 ;; autoselection.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1595 (mouse-autoselect-window-start mouse-position window))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1596 (error nil)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1597
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1598 (defun handle-select-window (event)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1599 "Handle select-window events."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1600 (interactive "e")
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1601 (let ((window (posn-window (event-start event))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1602 (unless (or (not (window-live-p window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1603 ;; Don't switch if we're currently in the minibuffer.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1604 ;; This tries to work around problems where the
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1605 ;; minibuffer gets unselected unexpectedly, and where
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1606 ;; you then have to move your mouse all the way down to
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1607 ;; the minibuffer to select it.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1608 (window-minibuffer-p (selected-window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1609 ;; Don't switch to minibuffer window unless it's active.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1610 (and (window-minibuffer-p window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1611 (not (minibuffer-window-active-p window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1612 ;; Don't switch when autoselection shall be delayed.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1613 (and (numberp mouse-autoselect-window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1614 (not (zerop mouse-autoselect-window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1615 (not (eq mouse-autoselect-window-state 'select))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1616 (progn
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1617 ;; Cancel any delayed autoselection.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1618 (mouse-autoselect-window-cancel t)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1619 ;; Start delayed autoselection from current mouse
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1620 ;; position and window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1621 (mouse-autoselect-window-start (mouse-position) window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1622 ;; Executing a command cancels delayed autoselection.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1623 (add-hook
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1624 'pre-command-hook 'mouse-autoselect-window-cancel))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1625 (when mouse-autoselect-window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1626 ;; Reset state of delayed autoselection.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1627 (setq mouse-autoselect-window-state nil)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1628 ;; Run `mouse-leave-buffer-hook' when autoselecting window.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1629 (run-hooks 'mouse-leave-buffer-hook))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1630 (select-window window))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1631
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1632 (defun delete-other-windows-vertically (&optional window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1633 "Delete the windows in the same column with WINDOW, but not WINDOW itself.
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1634 This may be a useful alternative binding for \\[delete-other-windows]
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1635 if you often split windows horizontally."
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1636 (interactive)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1637 (let* ((window (or window (selected-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1638 (edges (window-edges window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1639 (w window) delenda)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1640 (while (not (eq (setq w (next-window w 1)) window))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1641 (let ((e (window-edges w)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1642 (when (and (= (car e) (car edges))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1643 (= (caddr e) (caddr edges)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1644 (push w delenda))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1645 (mapc 'delete-window delenda)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1646
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1647 (defun truncated-partial-width-window-p (&optional window)
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1648 "Return non-nil if lines in WINDOW are specifically truncated due to its width.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1649 WINDOW defaults to the selected window.
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1650 Return nil if WINDOW is not a partial-width window
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1651 (regardless of the value of `truncate-lines').
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1652 Otherwise, consult the value of `truncate-partial-width-windows'
99275
0ecdd7e63016 (window-body-height, window-current-scroll-bars)
Martin Rudalics <rudalics@gmx.at>
parents: 99249
diff changeset
1653 for the buffer shown in WINDOW."
98135
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1654 (unless window
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1655 (setq window (selected-window)))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1656 (unless (window-full-width-p window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1657 (let ((t-p-w-w (buffer-local-value 'truncate-partial-width-windows
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1658 (window-buffer window))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1659 (if (integerp t-p-w-w)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1660 (< (window-width window) t-p-w-w)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1661 t-p-w-w))))
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1662
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1663 (define-key ctl-x-map "2" 'split-window-vertically)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1664 (define-key ctl-x-map "3" 'split-window-horizontally)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1665 (define-key ctl-x-map "}" 'enlarge-window-horizontally)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1666 (define-key ctl-x-map "{" 'shrink-window-horizontally)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1667 (define-key ctl-x-map "-" 'shrink-window-if-larger-than-buffer)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1668 (define-key ctl-x-map "+" 'balance-windows)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1669 (define-key ctl-x-4-map "0" 'kill-buffer-and-window)
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1670
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1671 ;; arch-tag: b508dfcc-c353-4c37-89fa-e773fe10cea9
d4db403fda8d Fix EOL mishap in previous commit.
Juanma Barranquero <lekktu@gmail.com>
parents: 98126
diff changeset
1672 ;;; window.el ends here