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