Commit | Line | Data |
---|---|---|
475f9031 | 1 | ;;; ediff-wind.el --- window manipulation utilities |
b578f267 | 2 | |
ddc90f39 | 3 | ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc. |
475f9031 KH |
4 | |
5 | ;; Author: Michael Kifer <kifer@cs.sunysb.edu> | |
6 | ||
7 | ;; This file is part of GNU Emacs. | |
8 | ||
9 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 | ;; it under the terms of the GNU General Public License as published by | |
11 | ;; the Free Software Foundation; either version 2, or (at your option) | |
12 | ;; any later version. | |
13 | ||
14 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | ;; GNU General Public License for more details. | |
18 | ||
19 | ;; You should have received a copy of the GNU General Public License | |
b578f267 EN |
20 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
21 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 | ;; Boston, MA 02111-1307, USA. | |
475f9031 | 23 | |
b578f267 | 24 | ;;; Code: |
ddc90f39 MK |
25 | |
26 | (provide 'ediff-wind) | |
475f9031 | 27 | |
bbe6126c MK |
28 | ;; Compiler pacifier |
29 | (defvar icon-title-format) | |
30 | (defvar top-toolbar-height) | |
31 | (defvar bottom-toolbar-height) | |
32 | (defvar left-toolbar-height) | |
33 | (defvar right-toolbar-height) | |
34 | (defvar left-toolbar-width) | |
35 | (defvar right-toolbar-width) | |
36 | (defvar default-menubar) | |
37 | (defvar frame-icon-title-format) | |
ddc90f39 MK |
38 | (defvar ediff-diff-status) |
39 | ||
40 | (eval-when-compile | |
41 | (let ((load-path (cons (expand-file-name ".") load-path))) | |
42 | (or (featurep 'ediff-init) | |
43 | (load "ediff-init.el" nil nil 'nosuffix)) | |
44 | (or (featurep 'ediff-util) | |
45 | (load "ediff-util.el" nil nil 'nosuffix)) | |
46 | (or (featurep 'ediff-help) | |
47 | (load "ediff-help.el" nil nil 'nosuffix)) | |
48 | (or (featurep 'ediff-tbar) | |
49 | (load "ediff-tbar.el" 'noerror nil 'nosuffix)) | |
50 | )) | |
bbe6126c MK |
51 | ;; end pacifier |
52 | ||
ddc90f39 MK |
53 | (require 'ediff-init) |
54 | ||
55 | ;; be careful with ediff-tbar | |
56 | (if ediff-xemacs-p | |
57 | (condition-case nil | |
58 | (require 'ediff-tbar) | |
59 | (error | |
60 | (defun ediff-compute-toolbar-width () 0))) | |
61 | (defun ediff-compute-toolbar-width () 0)) | |
62 | ||
63 | (defgroup ediff-window nil | |
64 | "Ediff window manipulation" | |
65 | :prefix "ediff-" | |
66 | :group 'ediff | |
67 | :group 'frames) | |
68 | ||
475f9031 | 69 | |
ddc90f39 | 70 | (defcustom ediff-window-setup-function (if (ediff-window-display-p) |
18b5607f KH |
71 | 'ediff-setup-windows-multiframe |
72 | 'ediff-setup-windows-plain) | |
475f9031 KH |
73 | "*Function called to set up windows. |
74 | Ediff provides a choice of two functions: ediff-setup-windows-plain, for | |
75 | doing everything in one frame, and ediff-setup-windows-multiframe, | |
76 | which sets the control panel in a separate frame. Also, if the latter | |
77 | function detects that one of the buffers A/B is seen in some other frame, | |
78 | it will try to keep that buffer in that frame. | |
79 | ||
80 | If you don't like the two functions provided---write your own one. | |
81 | The basic guidelines: | |
82 | 1. It should leave the control buffer current and the control window | |
83 | selected. | |
84 | 2. It should set ediff-window-A, ediff-window-B, ediff-window-C, | |
85 | and ediff-control-window to contain window objects that display | |
86 | the corresponding buffers. | |
87 | 3. It should accept the following arguments: | |
88 | buffer-A, buffer-B, buffer-C, control-buffer | |
89 | Buffer C may not be used in jobs that compare only two buffers. | |
90 | If you plan to do something fancy, take a close look at how the two | |
ddc90f39 MK |
91 | provided functions are written." |
92 | :type 'function | |
93 | :group 'ediff-window) | |
475f9031 KH |
94 | |
95 | ;; indicates if we are in a multiframe setup | |
96 | (ediff-defvar-local ediff-multiframe nil "") | |
97 | ||
98 | ;; Share of the frame occupied by the merge window (buffer C) | |
99 | (ediff-defvar-local ediff-merge-window-share 0.45 "") | |
100 | ||
101 | ;; The control window. | |
102 | (ediff-defvar-local ediff-control-window nil "") | |
103 | ;; Official window for buffer A | |
104 | (ediff-defvar-local ediff-window-A nil "") | |
105 | ;; Official window for buffer B | |
106 | (ediff-defvar-local ediff-window-B nil "") | |
107 | ;; Official window for buffer C | |
108 | (ediff-defvar-local ediff-window-C nil "") | |
109 | ;; Ediff's window configuration. | |
110 | ;; Used to minimize the need to rearrange windows. | |
111 | (ediff-defvar-local ediff-window-config-saved "" "") | |
112 | ||
e756eb9f MK |
113 | ;; Association between buff-type and ediff-window-* |
114 | (defconst ediff-window-alist | |
115 | '((A . ediff-window-A) | |
116 | (?A . ediff-window-A) | |
117 | (B . ediff-window-B) | |
118 | (?B . ediff-window-B) | |
119 | (C . ediff-window-C) | |
120 | (?C . ediff-window-C))) | |
121 | ||
475f9031 | 122 | |
ddc90f39 | 123 | (defcustom ediff-split-window-function 'split-window-vertically |
475f9031 KH |
124 | "*The function used to split the main window between buffer-A and buffer-B. |
125 | You can set it to a horizontal split instead of the default vertical split | |
126 | by setting this variable to `split-window-horizontally'. | |
127 | You can also have your own function to do fancy splits. | |
128 | This variable has no effect when buffer-A/B are shown in different frames. | |
ddc90f39 MK |
129 | In this case, Ediff will use those frames to display these buffers." |
130 | :type 'function | |
131 | :group 'ediff-window) | |
475f9031 | 132 | |
ddc90f39 | 133 | (defcustom ediff-merge-split-window-function 'split-window-horizontally |
475f9031 KH |
134 | "*The function used to split the main window between buffer-A and buffer-B. |
135 | You can set it to a vertical split instead of the default horizontal split | |
136 | by setting this variable to `split-window-vertically'. | |
137 | You can also have your own function to do fancy splits. | |
138 | This variable has no effect when buffer-A/B/C are shown in different frames. | |
ddc90f39 MK |
139 | In this case, Ediff will use those frames to display these buffers." |
140 | :type 'function | |
141 | :group 'ediff-window) | |
475f9031 KH |
142 | |
143 | (defconst ediff-control-frame-parameters | |
4ae69eac MK |
144 | (list |
145 | '(name . "Ediff") | |
146 | ;;'(unsplittable . t) | |
147 | '(minibuffer . nil) | |
148 | '(user-position . t) ; Emacs only | |
149 | '(vertical-scroll-bars . nil) ; Emacs only | |
150 | '(scrollbar-width . 0) ; XEmacs only | |
151 | '(menu-bar-lines . 0) ; Emacs only | |
4ae69eac MK |
152 | ;; don't lower and auto-raise |
153 | '(auto-lower . nil) | |
154 | '(auto-raise . t) | |
155 | ;; this blocks queries from window manager as to where to put | |
156 | ;; ediff's control frame. we put the frame outside the display, | |
157 | ;; so the initial frame won't jump all over the screen | |
158 | (cons 'top (if (fboundp 'ediff-display-pixel-height) | |
159 | (1+ (ediff-display-pixel-height)) | |
160 | 3000)) | |
161 | (cons 'left (if (fboundp 'ediff-display-pixel-width) | |
162 | (1+ (ediff-display-pixel-width)) | |
163 | 3000)) | |
164 | ) | |
475f9031 KH |
165 | "Frame parameters for displaying Ediff Control Panel. |
166 | Do not specify width and height here. These are computed automatically.") | |
167 | ||
6853a937 MK |
168 | ;; position of the mouse; used to decide whether to warp the mouse into ctl |
169 | ;; frame | |
170 | (ediff-defvar-local ediff-mouse-pixel-position nil "") | |
171 | ||
172 | ;; not used for now | |
50893fe9 | 173 | (defvar ediff-mouse-pixel-threshold 30 |
6853a937 MK |
174 | "If the user moves mouse more than this many pixels, Ediff won't warp mouse into control window.") |
175 | ||
ddc90f39 | 176 | (defcustom ediff-grab-mouse t |
6853a937 MK |
177 | "*If t, Ediff will always grab the mouse and put it in the control frame. |
178 | If 'maybe, Ediff will do it sometimes, but not after operations that require | |
179 | relatively long time. If nil, the mouse will be entirely user's | |
ddc90f39 MK |
180 | responsibility." |
181 | :type 'boolean | |
182 | :group 'ediff-window) | |
6853a937 | 183 | |
ddc90f39 | 184 | (defcustom ediff-control-frame-position-function 'ediff-make-frame-position |
475f9031 KH |
185 | "Function to call to determine the desired location for the control panel. |
186 | Expects three parameters: the control buffer, the desired width and height | |
187 | of the control frame. It returns an association list | |
ddc90f39 | 188 | of the form \(\(top . <position>\) \(left . <position>\)\)" |
1e70790f | 189 | :type 'function |
ddc90f39 | 190 | :group 'ediff-window) |
475f9031 | 191 | |
ddc90f39 | 192 | (defcustom ediff-control-frame-upward-shift (if ediff-xemacs-p 42 14) |
475f9031 KH |
193 | "*The upward shift of control frame from the top of buffer A's frame. |
194 | Measured in pixels. | |
195 | This is used by the default control frame positioning function, | |
196 | `ediff-make-frame-position'. This variable is provided for easy | |
ddc90f39 MK |
197 | customization of the default." |
198 | :type 'integer | |
199 | :group 'ediff-window) | |
475f9031 | 200 | |
ddc90f39 | 201 | (defcustom ediff-narrow-control-frame-leftward-shift (if ediff-xemacs-p 7 3) |
475f9031 KH |
202 | "*The leftward shift of control frame from the right edge of buf A's frame. |
203 | Measured in characters. | |
204 | This is used by the default control frame positioning function, | |
205 | `ediff-make-frame-position' to adjust the position of the control frame | |
206 | when it shows the short menu. This variable is provided for easy | |
ddc90f39 MK |
207 | customization of the default." |
208 | :type 'integer | |
209 | :group 'ediff-window) | |
475f9031 | 210 | |
ddc90f39 | 211 | (defcustom ediff-wide-control-frame-rightward-shift 7 |
475f9031 KH |
212 | "*The rightward shift of control frame from the left edge of buf A's frame. |
213 | Measured in characters. | |
214 | This is used by the default control frame positioning function, | |
215 | `ediff-make-frame-position' to adjust the position of the control frame | |
216 | when it shows the full menu. This variable is provided for easy | |
ddc90f39 MK |
217 | customization of the default." |
218 | :type 'integer | |
219 | :group 'ediff-window) | |
475f9031 KH |
220 | |
221 | ||
222 | ;; Wide frame display | |
223 | ||
224 | ;; t means Ediff is using wide display | |
225 | (ediff-defvar-local ediff-wide-display-p nil "") | |
226 | ;; keeps frame config for toggling wide display | |
227 | (ediff-defvar-local ediff-wide-display-orig-parameters nil | |
228 | "Frame parameters to be restored when the user wants to toggle the wide | |
229 | display off.") | |
230 | (ediff-defvar-local ediff-wide-display-frame nil | |
231 | "Frame to be used for wide display.") | |
232 | (ediff-defvar-local ediff-make-wide-display-function 'ediff-make-wide-display | |
233 | "The value is a function that is called to create a wide display. | |
234 | The function is called without arguments. It should resize the frame in | |
235 | which buffers A, B, and C are to be displayed, and it should save the old | |
236 | frame parameters in `ediff-wide-display-orig-parameters'. | |
237 | The variable `ediff-wide-display-frame' should be set to contain | |
238 | the frame used for the wide display.") | |
239 | ||
240 | ;; Frame used for the control panel in a windowing system. | |
241 | (ediff-defvar-local ediff-control-frame nil "") | |
242 | ||
ddc90f39 | 243 | (defcustom ediff-prefer-iconified-control-frame nil |
475f9031 KH |
244 | "*If t, keep control panel iconified when help message is off. |
245 | This has effect only on a windowing system. | |
50893fe9 | 246 | If t, hitting `?' to toggle control panel off iconifies it. |
475f9031 KH |
247 | |
248 | This is only useful in Emacs and only for certain kinds of window managers, | |
249 | such as TWM and its derivatives, since the window manager must permit | |
250 | keyboard input to go into icons. XEmacs completely ignores keyboard input | |
ddc90f39 MK |
251 | into icons, regardless of the window manager." |
252 | :type 'boolean | |
253 | :group 'ediff-window) | |
475f9031 KH |
254 | |
255 | ;;; Functions | |
256 | ||
257 | (defun ediff-get-window-by-clicking (wind prev-wind wind-number) | |
258 | (let (event) | |
259 | (message | |
260 | "Select windows by clicking. Please click on Window %d " wind-number) | |
261 | (while (not (ediff-mouse-event-p (setq event (ediff-read-event)))) | |
262 | (if (sit-for 1) ; if sequence of events, wait till the final word | |
263 | (beep 1)) | |
264 | (message "Please click on Window %d " wind-number)) | |
265 | (ediff-read-event) ; discard event | |
266 | (setq wind (if ediff-xemacs-p | |
267 | (event-window event) | |
268 | (posn-window (event-start event)))) | |
269 | )) | |
270 | ||
271 | ||
272 | ;; Select the lowest window on the frame. | |
273 | (defun ediff-select-lowest-window () | |
18b5607f KH |
274 | (if ediff-xemacs-p |
275 | (select-window (frame-lowest-window)) | |
276 | (let* ((lowest-window (selected-window)) | |
277 | (bottom-edge (car (cdr (cdr (cdr (window-edges)))))) | |
278 | (last-window (save-excursion | |
279 | (other-window -1) (selected-window))) | |
280 | (window-search t)) | |
281 | (while window-search | |
282 | (let* ((this-window (next-window)) | |
283 | (next-bottom-edge | |
284 | (car (cdr (cdr (cdr (window-edges this-window))))))) | |
285 | (if (< bottom-edge next-bottom-edge) | |
286 | (progn | |
287 | (setq bottom-edge next-bottom-edge) | |
288 | (setq lowest-window this-window))) | |
289 | ||
290 | (select-window this-window) | |
291 | (if (eq last-window this-window) | |
292 | (progn | |
293 | (select-window lowest-window) | |
294 | (setq window-search nil)))))))) | |
475f9031 | 295 | |
475f9031 KH |
296 | |
297 | ;;; Common window setup routines | |
298 | ||
299 | ;; Set up the window configuration. If POS is given, set the points to | |
300 | ;; the beginnings of the buffers. | |
301 | ;; When 3way comparison is added, this will have to choose the appropriate | |
302 | ;; setup function based on ediff-job-name | |
303 | (defun ediff-setup-windows (buffer-A buffer-B buffer-C control-buffer) | |
304 | ;; Make sure we are not in the minibuffer window when we try to delete | |
305 | ;; all other windows. | |
6853a937 | 306 | (run-hooks 'ediff-before-setup-windows-hook) |
475f9031 KH |
307 | (if (eq (selected-window) (minibuffer-window)) |
308 | (other-window 1)) | |
309 | ||
18b5607f KH |
310 | ;; in case user did a no-no on a tty |
311 | (or (ediff-window-display-p) | |
312 | (setq ediff-window-setup-function 'ediff-setup-windows-plain)) | |
313 | ||
475f9031 KH |
314 | (or (ediff-keep-window-config control-buffer) |
315 | (funcall | |
e756eb9f | 316 | (ediff-with-current-buffer control-buffer ediff-window-setup-function) |
475f9031 | 317 | buffer-A buffer-B buffer-C control-buffer)) |
6853a937 | 318 | (run-hooks 'ediff-after-setup-windows-hook)) |
475f9031 KH |
319 | |
320 | ;; Just set up 3 windows. | |
321 | ;; Usually used without windowing systems | |
322 | ;; With windowing, we want to use dedicated frames. | |
323 | (defun ediff-setup-windows-plain (buffer-A buffer-B buffer-C control-buffer) | |
e756eb9f | 324 | (ediff-with-current-buffer control-buffer |
475f9031 KH |
325 | (setq ediff-multiframe nil)) |
326 | (if ediff-merge-job | |
327 | (ediff-setup-windows-plain-merge | |
328 | buffer-A buffer-B buffer-C control-buffer) | |
329 | (ediff-setup-windows-plain-compare | |
330 | buffer-A buffer-B buffer-C control-buffer))) | |
331 | ||
332 | (defun ediff-setup-windows-plain-merge (buf-A buf-B buf-C control-buffer) | |
18b5607f KH |
333 | ;; skip dedicated and unsplittable frames |
334 | (ediff-destroy-control-frame control-buffer) | |
4ae69eac | 335 | (let ((window-min-height 1) |
475f9031 KH |
336 | split-window-function |
337 | merge-window-share merge-window-lines | |
338 | wind-A wind-B wind-C) | |
e756eb9f | 339 | (ediff-with-current-buffer control-buffer |
475f9031 KH |
340 | (setq merge-window-share ediff-merge-window-share |
341 | ;; this lets us have local versions of ediff-split-window-function | |
342 | split-window-function ediff-split-window-function)) | |
343 | (delete-other-windows) | |
344 | (split-window-vertically) | |
345 | (ediff-select-lowest-window) | |
346 | (ediff-setup-control-buffer control-buffer) | |
347 | ||
348 | ;; go to the upper window and split it betw A, B, and possibly C | |
349 | (other-window 1) | |
350 | (setq merge-window-lines | |
351 | (max 2 (round (* (window-height) merge-window-share)))) | |
352 | (switch-to-buffer buf-A) | |
353 | (setq wind-A (selected-window)) | |
354 | ||
6853a937 MK |
355 | ;; XEmacs used to have a lot of trouble with display |
356 | ;; It did't set things right unless we tell it to sit still | |
357 | ;; 19.12 seems ok. | |
358 | ;;(if ediff-xemacs-p (sit-for 0)) | |
475f9031 KH |
359 | |
360 | (split-window-vertically (max 2 (- (window-height) merge-window-lines))) | |
361 | (if (eq (selected-window) wind-A) | |
362 | (other-window 1)) | |
363 | (setq wind-C (selected-window)) | |
364 | (switch-to-buffer buf-C) | |
365 | ||
366 | (select-window wind-A) | |
367 | (funcall split-window-function) | |
368 | ||
369 | (if (eq (selected-window) wind-A) | |
370 | (other-window 1)) | |
371 | (switch-to-buffer buf-B) | |
372 | (setq wind-B (selected-window)) | |
373 | ||
e756eb9f | 374 | (ediff-with-current-buffer control-buffer |
475f9031 KH |
375 | (setq ediff-window-A wind-A |
376 | ediff-window-B wind-B | |
377 | ediff-window-C wind-C)) | |
378 | ||
379 | (ediff-select-lowest-window) | |
380 | (ediff-setup-control-buffer control-buffer) | |
381 | )) | |
382 | ||
383 | ||
384 | ;; This function handles all comparison jobs, including 3way jobs | |
385 | (defun ediff-setup-windows-plain-compare (buf-A buf-B buf-C control-buffer) | |
386 | ;; skip dedicated and unsplittable frames | |
18b5607f | 387 | (ediff-destroy-control-frame control-buffer) |
4ae69eac | 388 | (let ((window-min-height 1) |
475f9031 KH |
389 | split-window-function wind-width-or-height |
390 | three-way-comparison | |
18b5607f | 391 | wind-A-start wind-B-start wind-A wind-B wind-C) |
e756eb9f | 392 | (ediff-with-current-buffer control-buffer |
475f9031 KH |
393 | (setq wind-A-start (ediff-overlay-start |
394 | (ediff-get-value-according-to-buffer-type | |
395 | 'A ediff-narrow-bounds)) | |
396 | wind-B-start (ediff-overlay-start | |
397 | (ediff-get-value-according-to-buffer-type | |
398 | 'B ediff-narrow-bounds)) | |
475f9031 KH |
399 | ;; this lets us have local versions of ediff-split-window-function |
400 | split-window-function ediff-split-window-function | |
401 | three-way-comparison ediff-3way-comparison-job)) | |
402 | (delete-other-windows) | |
403 | (split-window-vertically) | |
404 | (ediff-select-lowest-window) | |
405 | (ediff-setup-control-buffer control-buffer) | |
406 | ||
407 | ;; go to the upper window and split it betw A, B, and possibly C | |
408 | (other-window 1) | |
409 | (switch-to-buffer buf-A) | |
410 | (setq wind-A (selected-window)) | |
411 | (if three-way-comparison | |
412 | (setq wind-width-or-height | |
413 | (/ (if (eq split-window-function 'split-window-vertically) | |
414 | (window-height wind-A) | |
415 | (window-width wind-A)) | |
416 | 3))) | |
417 | ||
6853a937 MK |
418 | ;; XEmacs used to have a lot of trouble with display |
419 | ;; It did't set things right unless we told it to sit still | |
420 | ;; 19.12 seems ok. | |
421 | ;;(if ediff-xemacs-p (sit-for 0)) | |
475f9031 KH |
422 | |
423 | (funcall split-window-function wind-width-or-height) | |
424 | ||
425 | (if (eq (selected-window) wind-A) | |
426 | (other-window 1)) | |
427 | (switch-to-buffer buf-B) | |
428 | (setq wind-B (selected-window)) | |
429 | ||
430 | (if three-way-comparison | |
431 | (progn | |
432 | (funcall split-window-function) ; equally | |
433 | (if (eq (selected-window) wind-B) | |
434 | (other-window 1)) | |
435 | (switch-to-buffer buf-C) | |
436 | (setq wind-C (selected-window)))) | |
437 | ||
e756eb9f | 438 | (ediff-with-current-buffer control-buffer |
475f9031 KH |
439 | (setq ediff-window-A wind-A |
440 | ediff-window-B wind-B | |
441 | ediff-window-C wind-C)) | |
442 | ||
443 | ;; It is unlikely that we will want to implement 3way window comparison. | |
444 | ;; So, only buffers A and B are used here. | |
18b5607f | 445 | (if ediff-windows-job |
475f9031 KH |
446 | (progn |
447 | (set-window-start wind-A wind-A-start) | |
448 | (set-window-start wind-B wind-B-start))) | |
449 | ||
450 | (ediff-select-lowest-window) | |
451 | (ediff-setup-control-buffer control-buffer) | |
452 | )) | |
453 | ||
454 | ||
4ae69eac | 455 | ;; dispatch an appropriate window setup function |
475f9031 | 456 | (defun ediff-setup-windows-multiframe (buf-A buf-B buf-C control-buf) |
e756eb9f | 457 | (ediff-with-current-buffer control-buf |
475f9031 KH |
458 | (setq ediff-multiframe t)) |
459 | (if ediff-merge-job | |
460 | (ediff-setup-windows-multiframe-merge buf-A buf-B buf-C control-buf) | |
461 | (ediff-setup-windows-multiframe-compare buf-A buf-B buf-C control-buf))) | |
462 | ||
463 | (defun ediff-setup-windows-multiframe-merge (buf-A buf-B buf-C control-buf) | |
464 | ;;; Algorithm: | |
bbe6126c MK |
465 | ;;; 1. Never use frames that have dedicated windows in them---it is bad to |
466 | ;;; destroy dedicated windows. | |
467 | ;;; 2. If A and B are in the same frame but C's frame is different--- use one | |
468 | ;;; frame for A and B and use a separate frame for C. | |
469 | ;;; 3. If C's frame is non-existent, then: if the first suitable | |
470 | ;;; non-dedicated frame is different from A&B's, then use it for C. | |
471 | ;;; Otherwise, put A,B, and C in one frame. | |
472 | ;;; 4. If buffers A, B, C are is separate frames, use them to display these | |
473 | ;;; buffers. | |
475f9031 | 474 | |
18b5607f KH |
475 | ;; Skip dedicated or iconified frames. |
476 | ;; Unsplittable frames are taken care of later. | |
475f9031 KH |
477 | (ediff-skip-unsuitable-frames 'ok-unsplittable) |
478 | ||
4ae69eac | 479 | (let* ((window-min-height 1) |
475f9031 KH |
480 | (wind-A (ediff-get-visible-buffer-window buf-A)) |
481 | (wind-B (ediff-get-visible-buffer-window buf-B)) | |
482 | (wind-C (ediff-get-visible-buffer-window buf-C)) | |
18b5607f KH |
483 | (frame-A (if wind-A (window-frame wind-A))) |
484 | (frame-B (if wind-B (window-frame wind-B))) | |
485 | (frame-C (if wind-C (window-frame wind-C))) | |
475f9031 KH |
486 | ;; on wide display, do things in one frame |
487 | (force-one-frame | |
e756eb9f | 488 | (ediff-with-current-buffer control-buf ediff-wide-display-p)) |
475f9031 KH |
489 | ;; this lets us have local versions of ediff-split-window-function |
490 | (split-window-function | |
e756eb9f | 491 | (ediff-with-current-buffer control-buf ediff-split-window-function)) |
475f9031 | 492 | (orig-wind (selected-window)) |
18b5607f | 493 | (orig-frame (selected-frame)) |
475f9031 | 494 | (use-same-frame (or force-one-frame |
bbe6126c | 495 | ;; A and C must be in one frame |
475f9031 | 496 | (eq frame-A (or frame-C orig-frame)) |
bbe6126c | 497 | ;; B and C must be in one frame |
475f9031 | 498 | (eq frame-B (or frame-C orig-frame)) |
bbe6126c | 499 | ;; A or B is not visible |
18b5607f KH |
500 | (not (frame-live-p frame-A)) |
501 | (not (frame-live-p frame-B)) | |
bbe6126c MK |
502 | ;; A or B is not suitable for display |
503 | (not (ediff-window-ok-for-display wind-A)) | |
504 | (not (ediff-window-ok-for-display wind-B)) | |
505 | ;; A and B in the same frame, and no good frame | |
506 | ;; for C | |
18b5607f KH |
507 | (and (eq frame-A frame-B) |
508 | (not (frame-live-p frame-C))) | |
475f9031 | 509 | )) |
bbe6126c | 510 | ;; use-same-frame-for-AB implies wind A and B are ok for display |
475f9031 KH |
511 | (use-same-frame-for-AB (and (not use-same-frame) |
512 | (eq frame-A frame-B))) | |
e756eb9f | 513 | (merge-window-share (ediff-with-current-buffer control-buf |
475f9031 KH |
514 | ediff-merge-window-share)) |
515 | merge-window-lines | |
516 | designated-minibuffer-frame | |
517 | done-A done-B done-C) | |
518 | ||
519 | ;; buf-A on its own | |
520 | (if (and (window-live-p wind-A) | |
bbe6126c | 521 | (null use-same-frame) ; implies wind-A is suitable |
475f9031 | 522 | (null use-same-frame-for-AB)) |
bbe6126c MK |
523 | (progn ; bug A on its own |
524 | ;; buffer buf-A is seen in live wind-A | |
475f9031 KH |
525 | (select-window wind-A) |
526 | (delete-other-windows) | |
475f9031 KH |
527 | (setq wind-A (selected-window)) |
528 | (setq done-A t))) | |
529 | ||
530 | ;; buf-B on its own | |
bbe6126c MK |
531 | (if (and (window-live-p wind-B) |
532 | (null use-same-frame) ; implies wind-B is suitable | |
533 | (null use-same-frame-for-AB)) | |
534 | (progn ; buf B on its own | |
535 | ;; buffer buf-B is seen in live wind-B | |
475f9031 KH |
536 | (select-window wind-B) |
537 | (delete-other-windows) | |
475f9031 KH |
538 | (setq wind-B (selected-window)) |
539 | (setq done-B t))) | |
540 | ||
541 | ;; buf-C on its own | |
bbe6126c MK |
542 | (if (and (window-live-p wind-C) |
543 | (ediff-window-ok-for-display wind-C) | |
544 | (null use-same-frame)) ; buf C on its own | |
475f9031 | 545 | (progn |
bbe6126c | 546 | ;; buffer buf-C is seen in live wind-C |
475f9031 KH |
547 | (select-window wind-C) |
548 | (delete-other-windows) | |
475f9031 KH |
549 | (setq wind-C (selected-window)) |
550 | (setq done-C t))) | |
551 | ||
bbe6126c MK |
552 | (if (and use-same-frame-for-AB ; implies wind A and B are suitable |
553 | (window-live-p wind-A)) | |
475f9031 | 554 | (progn |
bbe6126c MK |
555 | ;; wind-A must already be displaying buf-A |
556 | (select-window wind-A) | |
475f9031 KH |
557 | (delete-other-windows) |
558 | (setq wind-A (selected-window)) | |
559 | ||
560 | (funcall split-window-function) | |
561 | (if (eq (selected-window) wind-A) | |
562 | (other-window 1)) | |
563 | (switch-to-buffer buf-B) | |
564 | (setq wind-B (selected-window)) | |
565 | ||
566 | (setq done-A t | |
567 | done-B t))) | |
568 | ||
569 | (if use-same-frame | |
bbe6126c | 570 | (let ((window-min-height 1)) |
ddc90f39 MK |
571 | (if (and (eq frame-A frame-B) |
572 | (eq frame-B frame-C) | |
573 | (frame-live-p frame-A)) | |
574 | (select-frame frame-A) | |
575 | ;; avoid dedicated and non-splittable windows | |
576 | (ediff-skip-unsuitable-frames)) | |
475f9031 KH |
577 | (delete-other-windows) |
578 | (setq merge-window-lines | |
579 | (max 2 (round (* (window-height) merge-window-share)))) | |
580 | (switch-to-buffer buf-A) | |
581 | (setq wind-A (selected-window)) | |
582 | ||
475f9031 KH |
583 | (split-window-vertically |
584 | (max 2 (- (window-height) merge-window-lines))) | |
585 | (if (eq (selected-window) wind-A) | |
586 | (other-window 1)) | |
587 | (setq wind-C (selected-window)) | |
588 | (switch-to-buffer buf-C) | |
589 | ||
590 | (select-window wind-A) | |
591 | ||
592 | (funcall split-window-function) | |
593 | (if (eq (selected-window) wind-A) | |
594 | (other-window 1)) | |
595 | (switch-to-buffer buf-B) | |
596 | (setq wind-B (selected-window)) | |
597 | ||
598 | (setq done-A t | |
599 | done-B t | |
600 | done-C t) | |
601 | )) | |
602 | ||
bbe6126c MK |
603 | (or done-A ; Buf A to be set in its own frame, |
604 | ;;; or it was set before because use-same-frame = 1 | |
605 | (progn | |
606 | ;; Buf-A was not set up yet as it wasn't visible, | |
607 | ;; and use-same-frame = nil, use-same-frame-for-AB = nil | |
475f9031 KH |
608 | (select-window orig-wind) |
609 | (delete-other-windows) | |
610 | (switch-to-buffer buf-A) | |
611 | (setq wind-A (selected-window)) | |
612 | )) | |
bbe6126c MK |
613 | (or done-B ; Buf B to be set in its own frame, |
614 | ;;; or it was set before because use-same-frame = 1 | |
615 | (progn | |
616 | ;; Buf-B was not set up yet as it wasn't visible | |
617 | ;; and use-same-frame = nil, use-same-frame-for-AB = nil | |
475f9031 KH |
618 | (select-window orig-wind) |
619 | (delete-other-windows) | |
620 | (switch-to-buffer buf-B) | |
621 | (setq wind-B (selected-window)) | |
622 | )) | |
623 | ||
bbe6126c MK |
624 | (or done-C ; Buf C to be set in its own frame, |
625 | ;;; or it was set before because use-same-frame = 1 | |
626 | (progn | |
627 | ;; Buf-C was not set up yet as it wasn't visible | |
628 | ;; and use-same-frame = nil | |
475f9031 KH |
629 | (select-window orig-wind) |
630 | (delete-other-windows) | |
631 | (switch-to-buffer buf-C) | |
632 | (setq wind-C (selected-window)) | |
633 | )) | |
634 | ||
e756eb9f | 635 | (ediff-with-current-buffer control-buf |
475f9031 KH |
636 | (setq ediff-window-A wind-A |
637 | ediff-window-B wind-B | |
638 | ediff-window-C wind-C) | |
18b5607f KH |
639 | (setq frame-A (window-frame ediff-window-A) |
640 | designated-minibuffer-frame | |
641 | (window-frame (minibuffer-window frame-A)))) | |
642 | ||
643 | (ediff-setup-control-frame control-buf designated-minibuffer-frame) | |
475f9031 KH |
644 | )) |
645 | ||
646 | ||
647 | ;; Window setup for all comparison jobs, including 3way comparisons | |
648 | (defun ediff-setup-windows-multiframe-compare (buf-A buf-B buf-C control-buf) | |
649 | ;;; Algorithm: | |
650 | ;;; If a buffer is seen in a frame, use that frame for that buffer. | |
651 | ;;; If it is not seen, use the current frame. | |
652 | ;;; If both buffers are not seen, they share the current frame. If one | |
653 | ;;; of the buffers is not seen, it is placed in the current frame (where | |
654 | ;;; ediff started). If that frame is displaying the other buffer, it is | |
655 | ;;; shared between the two buffers. | |
656 | ;;; However, if we decide to put both buffers in one frame | |
657 | ;;; and the selected frame isn't splittable, we create a new frame and | |
658 | ;;; put both buffers there, event if one of this buffers is visible in | |
659 | ;;; another frame. | |
660 | ||
661 | ;; Skip dedicated or iconified frames. | |
662 | ;; Unsplittable frames are taken care of later. | |
663 | (ediff-skip-unsuitable-frames 'ok-unsplittable) | |
664 | ||
4ae69eac | 665 | (let* ((window-min-height 1) |
475f9031 KH |
666 | (wind-A (ediff-get-visible-buffer-window buf-A)) |
667 | (wind-B (ediff-get-visible-buffer-window buf-B)) | |
668 | (wind-C (ediff-get-visible-buffer-window buf-C)) | |
18b5607f KH |
669 | (frame-A (if wind-A (window-frame wind-A))) |
670 | (frame-B (if wind-B (window-frame wind-B))) | |
671 | (frame-C (if wind-C (window-frame wind-C))) | |
e756eb9f | 672 | (ctl-frame-exists-p (ediff-with-current-buffer control-buf |
18b5607f | 673 | (frame-live-p ediff-control-frame))) |
475f9031 KH |
674 | ;; on wide display, do things in one frame |
675 | (force-one-frame | |
e756eb9f | 676 | (ediff-with-current-buffer control-buf ediff-wide-display-p)) |
475f9031 KH |
677 | ;; this lets us have local versions of ediff-split-window-function |
678 | (split-window-function | |
e756eb9f | 679 | (ediff-with-current-buffer control-buf ediff-split-window-function)) |
475f9031 | 680 | (three-way-comparison |
e756eb9f | 681 | (ediff-with-current-buffer control-buf ediff-3way-comparison-job)) |
475f9031 KH |
682 | (orig-wind (selected-window)) |
683 | (use-same-frame (or force-one-frame | |
684 | (eq frame-A frame-B) | |
bbe6126c MK |
685 | (not (ediff-window-ok-for-display wind-A)) |
686 | (not (ediff-window-ok-for-display wind-B)) | |
475f9031 KH |
687 | (if three-way-comparison |
688 | (or (eq frame-A frame-C) | |
689 | (eq frame-B frame-C) | |
bbe6126c | 690 | (not (ediff-window-ok-for-display wind-C)) |
18b5607f KH |
691 | (not (frame-live-p frame-A)) |
692 | (not (frame-live-p frame-B)) | |
693 | (not (frame-live-p frame-C)))) | |
694 | (and (not (frame-live-p frame-B)) | |
475f9031 | 695 | (or ctl-frame-exists-p |
18b5607f KH |
696 | (eq frame-A (selected-frame)))) |
697 | (and (not (frame-live-p frame-A)) | |
475f9031 | 698 | (or ctl-frame-exists-p |
18b5607f KH |
699 | (eq frame-B (selected-frame)))))) |
700 | wind-A-start wind-B-start | |
475f9031 KH |
701 | designated-minibuffer-frame |
702 | done-A done-B done-C) | |
703 | ||
e756eb9f | 704 | (ediff-with-current-buffer control-buf |
475f9031 KH |
705 | (setq wind-A-start (ediff-overlay-start |
706 | (ediff-get-value-according-to-buffer-type | |
707 | 'A ediff-narrow-bounds)) | |
708 | wind-B-start (ediff-overlay-start | |
709 | (ediff-get-value-according-to-buffer-type | |
18b5607f | 710 | 'B ediff-narrow-bounds)))) |
475f9031 KH |
711 | |
712 | (if (and (window-live-p wind-A) (null use-same-frame)) ; buf-A on its own | |
713 | (progn | |
bbe6126c MK |
714 | ;; buffer buf-A is seen in live wind-A |
715 | (select-window wind-A) ; must be displaying buf-A | |
475f9031 | 716 | (delete-other-windows) |
475f9031 KH |
717 | (setq wind-A (selected-window)) |
718 | (setq done-A t))) | |
719 | ||
720 | (if (and (window-live-p wind-B) (null use-same-frame)) ; buf B on its own | |
721 | (progn | |
bbe6126c MK |
722 | ;; buffer buf-B is seen in live wind-B |
723 | (select-window wind-B) ; must be displaying buf-B | |
475f9031 | 724 | (delete-other-windows) |
475f9031 KH |
725 | (setq wind-B (selected-window)) |
726 | (setq done-B t))) | |
727 | ||
728 | (if (and (window-live-p wind-C) (null use-same-frame)) ; buf C on its own | |
729 | (progn | |
bbe6126c MK |
730 | ;; buffer buf-C is seen in live wind-C |
731 | (select-window wind-C) ; must be displaying buf-C | |
475f9031 | 732 | (delete-other-windows) |
475f9031 KH |
733 | (setq wind-C (selected-window)) |
734 | (setq done-C t))) | |
735 | ||
736 | (if use-same-frame | |
bbe6126c | 737 | (let (wind-width-or-height) ; this affects 3way setups only |
ddc90f39 MK |
738 | (if (and (eq frame-A frame-B) (frame-live-p frame-A)) |
739 | (select-frame frame-A) | |
740 | ;; avoid dedicated and non-splittable windows | |
741 | (ediff-skip-unsuitable-frames)) | |
475f9031 KH |
742 | (delete-other-windows) |
743 | (switch-to-buffer buf-A) | |
744 | (setq wind-A (selected-window)) | |
745 | ||
475f9031 KH |
746 | (if three-way-comparison |
747 | (setq wind-width-or-height | |
748 | (/ | |
749 | (if (eq split-window-function 'split-window-vertically) | |
750 | (window-height wind-A) | |
751 | (window-width wind-A)) | |
752 | 3))) | |
753 | ||
754 | (funcall split-window-function wind-width-or-height) | |
755 | (if (eq (selected-window) wind-A) | |
756 | (other-window 1)) | |
757 | (switch-to-buffer buf-B) | |
758 | (setq wind-B (selected-window)) | |
759 | ||
760 | (if three-way-comparison | |
761 | (progn | |
762 | (funcall split-window-function) ; equally | |
763 | (if (memq (selected-window) (list wind-A wind-B)) | |
764 | (other-window 1)) | |
765 | (switch-to-buffer buf-C) | |
766 | (setq wind-C (selected-window)))) | |
767 | (setq done-A t | |
768 | done-B t | |
769 | done-C t) | |
770 | )) | |
771 | ||
772 | (or done-A ; Buf A to be set in its own frame | |
bbe6126c MK |
773 | ;;; or it was set before because use-same-frame = 1 |
774 | (progn | |
775 | ;; Buf-A was not set up yet as it wasn't visible, | |
776 | ;; and use-same-frame = nil | |
475f9031 KH |
777 | (select-window orig-wind) |
778 | (delete-other-windows) | |
779 | (switch-to-buffer buf-A) | |
780 | (setq wind-A (selected-window)) | |
781 | )) | |
782 | (or done-B ; Buf B to be set in its own frame | |
bbe6126c MK |
783 | ;;; or it was set before because use-same-frame = 1 |
784 | (progn | |
785 | ;; Buf-B was not set up yet as it wasn't visible, | |
786 | ;; and use-same-frame = nil | |
475f9031 KH |
787 | (select-window orig-wind) |
788 | (delete-other-windows) | |
789 | (switch-to-buffer buf-B) | |
790 | (setq wind-B (selected-window)) | |
791 | )) | |
792 | ||
793 | (if three-way-comparison | |
794 | (or done-C ; Buf C to be set in its own frame | |
bbe6126c MK |
795 | ;;; or it was set before because use-same-frame = 1 |
796 | (progn | |
797 | ;; Buf-C was not set up yet as it wasn't visible, | |
798 | ;; and use-same-frame = nil | |
475f9031 KH |
799 | (select-window orig-wind) |
800 | (delete-other-windows) | |
801 | (switch-to-buffer buf-C) | |
802 | (setq wind-C (selected-window)) | |
803 | ))) | |
804 | ||
e756eb9f | 805 | (ediff-with-current-buffer control-buf |
475f9031 KH |
806 | (setq ediff-window-A wind-A |
807 | ediff-window-B wind-B | |
808 | ediff-window-C wind-C) | |
18b5607f KH |
809 | |
810 | (setq frame-A (window-frame ediff-window-A) | |
811 | designated-minibuffer-frame | |
812 | (window-frame (minibuffer-window frame-A)))) | |
475f9031 | 813 | |
bbe6126c MK |
814 | ;; It is unlikely that we'll implement a version of ediff-windows that |
815 | ;; would compare 3 windows at once. So, we don't use buffer C here. | |
18b5607f | 816 | (if ediff-windows-job |
475f9031 KH |
817 | (progn |
818 | (set-window-start wind-A wind-A-start) | |
819 | (set-window-start wind-B wind-B-start))) | |
820 | ||
18b5607f | 821 | (ediff-setup-control-frame control-buf designated-minibuffer-frame) |
475f9031 KH |
822 | )) |
823 | ||
bbe6126c | 824 | ;; skip unsplittable frames and frames that have dedicated windows. |
475f9031 KH |
825 | ;; create a new splittable frame if none is found |
826 | (defun ediff-skip-unsuitable-frames (&optional ok-unsplittable) | |
18b5607f | 827 | (if (ediff-window-display-p) |
475f9031 KH |
828 | (let (last-window) |
829 | (while (and (not (eq (selected-window) last-window)) | |
830 | (or | |
bbe6126c | 831 | (ediff-frame-has-dedicated-windows (selected-frame)) |
18b5607f | 832 | (ediff-frame-iconified-p (selected-frame)) |
4ae69eac MK |
833 | (< (frame-height (selected-frame)) |
834 | (* 3 window-min-height)) | |
475f9031 KH |
835 | (if ok-unsplittable |
836 | nil | |
18b5607f | 837 | (ediff-frame-unsplittable-p (selected-frame))))) |
475f9031 KH |
838 | ;; remember where started |
839 | (or last-window (setq last-window (selected-window))) | |
840 | ;; try new window | |
841 | (other-window 1 t)) | |
842 | (if (eq (selected-window) last-window) | |
843 | ;; fed up, no appropriate frame | |
844 | (progn | |
f9d5a20f | 845 | (select-frame (make-frame '((unsplittable))))))))) |
475f9031 | 846 | |
bbe6126c MK |
847 | (defun ediff-frame-has-dedicated-windows (frame) |
848 | (let ((cur-fr (selected-frame)) | |
849 | ans) | |
850 | (select-frame frame) | |
851 | (walk-windows | |
852 | (function (lambda (wind) | |
853 | (if (window-dedicated-p wind) | |
854 | (setq ans t)))) | |
855 | 'ignore-minibuffer | |
856 | frame) | |
857 | (select-frame cur-fr) | |
858 | ans)) | |
859 | ||
860 | ;; window is ok, if it is only one window on the frame, not counting the | |
861 | ;; minibuffer, or none of the frame's windows is dedicated. | |
862 | ;; The idea is that it is bad to destroy dedicated windows while creating an | |
863 | ;; ediff window setup | |
864 | (defun ediff-window-ok-for-display (wind) | |
865 | (and | |
866 | (window-live-p wind) | |
867 | (or | |
868 | ;; only one window | |
869 | (eq wind (next-window wind 'ignore-minibuffer (window-frame wind))) | |
870 | ;; none is dedicated | |
871 | (not (ediff-frame-has-dedicated-windows (window-frame wind))) | |
872 | ))) | |
873 | ||
475f9031 | 874 | ;; Prepare or refresh control frame |
18b5607f | 875 | (defun ediff-setup-control-frame (ctl-buffer designated-minibuffer-frame) |
4ae69eac | 876 | (let ((window-min-height 1) |
475f9031 | 877 | ctl-frame-iconified-p dont-iconify-ctl-frame deiconify-ctl-frame |
bbe6126c MK |
878 | ctl-frame old-ctl-frame lines |
879 | ;; user-grabbed-mouse | |
475f9031 KH |
880 | fheight fwidth adjusted-parameters) |
881 | ||
e756eb9f | 882 | (ediff-with-current-buffer ctl-buffer |
18b5607f | 883 | (if ediff-xemacs-p (set-buffer-menubar nil)) |
6853a937 MK |
884 | ;;(setq user-grabbed-mouse (ediff-user-grabbed-mouse)) |
885 | (run-hooks 'ediff-before-setup-control-frame-hook)) | |
475f9031 | 886 | |
e756eb9f MK |
887 | (setq old-ctl-frame (ediff-with-current-buffer ctl-buffer ediff-control-frame)) |
888 | (ediff-with-current-buffer ctl-buffer | |
4ae69eac MK |
889 | (setq ctl-frame (if (frame-live-p old-ctl-frame) |
890 | old-ctl-frame | |
891 | (make-frame ediff-control-frame-parameters)) | |
892 | ediff-control-frame ctl-frame)) | |
475f9031 KH |
893 | |
894 | (setq ctl-frame-iconified-p (ediff-frame-iconified-p ctl-frame)) | |
18b5607f | 895 | (select-frame ctl-frame) |
475f9031 KH |
896 | (if (window-dedicated-p (selected-window)) |
897 | () | |
898 | (delete-other-windows) | |
899 | (switch-to-buffer ctl-buffer)) | |
900 | ||
901 | ;; must be before ediff-setup-control-buffer | |
6853a937 | 902 | ;; just a precaution--we should be in ctl-buffer already |
e756eb9f | 903 | (ediff-with-current-buffer ctl-buffer |
6853a937 MK |
904 | (make-local-variable 'frame-title-format) |
905 | (make-local-variable 'frame-icon-title-format) ; XEmacs | |
906 | (make-local-variable 'icon-title-format)) ; Emacs | |
475f9031 KH |
907 | |
908 | (ediff-setup-control-buffer ctl-buffer) | |
909 | (setq dont-iconify-ctl-frame | |
910 | (not (string= ediff-help-message ediff-brief-help-message))) | |
911 | (setq deiconify-ctl-frame | |
912 | (and (eq this-command 'ediff-toggle-help) | |
913 | dont-iconify-ctl-frame)) | |
914 | ||
915 | ;; 1 more line for the modeline | |
4ae69eac | 916 | (setq lines (1+ (count-lines (point-min) (point-max))) |
475f9031 | 917 | fheight lines |
bf5d92c5 MK |
918 | fwidth (max (+ (ediff-help-message-line-length) 2) |
919 | (ediff-compute-toolbar-width)) | |
ddc90f39 MK |
920 | adjusted-parameters |
921 | (list | |
922 | ;; possibly change surrogate minibuffer | |
923 | (cons 'minibuffer | |
924 | (minibuffer-window | |
925 | designated-minibuffer-frame)) | |
926 | (cons 'width fwidth) | |
927 | (cons 'height fheight)) | |
928 | ) | |
4ae69eac | 929 | (if ediff-use-long-help-message |
6853a937 MK |
930 | (setq adjusted-parameters |
931 | (cons '(auto-raise . nil) adjusted-parameters))) | |
475f9031 KH |
932 | |
933 | ;; In XEmacs, buffer menubar needs to be killed before frame parameters | |
6853a937 | 934 | ;; are changed. |
18b5607f KH |
935 | (if ediff-xemacs-p |
936 | (progn | |
ddc90f39 MK |
937 | (set-specifier top-toolbar-height (list ctl-frame 2)) |
938 | (sit-for 0) | |
18b5607f | 939 | (set-specifier top-toolbar-height (list ctl-frame 0)) |
ddc90f39 | 940 | ;;(set-specifier bottom-toolbar-height (list ctl-frame 0)) |
18b5607f KH |
941 | (set-specifier left-toolbar-width (list ctl-frame 0)) |
942 | (set-specifier right-toolbar-width (list ctl-frame 0)) | |
6853a937 | 943 | )) |
475f9031 | 944 | |
4ae69eac MK |
945 | ;; Under OS/2 (emx) we have to call modify frame parameters twice, in order |
946 | ;; to make sure that at least once we do it for non-iconified frame. If | |
947 | ;; appears that in the OS/2 port of Emacs, one can't modify frame | |
948 | ;; parameters of iconified frames. As a precaution, we do likewise for | |
949 | ;; windows-nt. | |
950 | (if (memq system-type '(emx windows-nt windows-95)) | |
18b5607f | 951 | (modify-frame-parameters ctl-frame adjusted-parameters)) |
475f9031 | 952 | |
ddc90f39 MK |
953 | ;; make or zap toolbar (if not requested) |
954 | (ediff-make-bottom-toolbar ctl-frame) | |
475f9031 | 955 | |
ddc90f39 MK |
956 | (goto-char (point-min)) |
957 | ||
6853a937 | 958 | (modify-frame-parameters ctl-frame adjusted-parameters) |
bbe6126c | 959 | (make-frame-visible ctl-frame) |
475f9031 KH |
960 | |
961 | ;; This works around a bug in 19.25 and earlier. There, if frame gets | |
962 | ;; iconified, the current buffer changes to that of the frame that | |
963 | ;; becomes exposed as a result of this iconification. | |
964 | ;; So, we make sure the current buffer doesn't change. | |
18b5607f | 965 | (select-frame ctl-frame) |
475f9031 KH |
966 | (ediff-refresh-control-frame) |
967 | ||
6853a937 MK |
968 | (cond ((and ediff-prefer-iconified-control-frame |
969 | (not ctl-frame-iconified-p) (not dont-iconify-ctl-frame)) | |
970 | (iconify-frame ctl-frame)) | |
971 | ((or deiconify-ctl-frame (not ctl-frame-iconified-p)) | |
972 | (raise-frame ctl-frame))) | |
475f9031 | 973 | |
bbe6126c | 974 | (set-window-dedicated-p (selected-window) t) |
ddc90f39 MK |
975 | |
976 | ;; Now move the frame. We must do it separately due to an obscure bug in | |
977 | ;; XEmacs | |
978 | (modify-frame-parameters | |
979 | ctl-frame | |
980 | (funcall ediff-control-frame-position-function ctl-buffer fwidth fheight)) | |
475f9031 | 981 | |
bbe6126c | 982 | ;; synchronize so the cursor will move to control frame |
6853a937 | 983 | ;; per RMS suggestion |
4ae69eac MK |
984 | (if (ediff-window-display-p) |
985 | (let ((count 7)) | |
986 | (sit-for .1) | |
987 | (while (and (not (frame-visible-p ctl-frame)) (> count 0)) | |
988 | (setq count (1- count)) | |
989 | (sit-for .3)))) | |
6853a937 | 990 | |
475f9031 | 991 | (or (ediff-frame-iconified-p ctl-frame) |
6853a937 | 992 | ;; don't warp the mouse, unless ediff-grab-mouse = t |
4ae69eac MK |
993 | (ediff-reset-mouse ctl-frame |
994 | (or (eq this-command 'ediff-quit) | |
995 | (not (eq ediff-grab-mouse t))))) | |
475f9031 KH |
996 | |
997 | (if ediff-xemacs-p | |
e756eb9f | 998 | (ediff-with-current-buffer ctl-buffer |
bbe6126c MK |
999 | (make-local-hook 'select-frame-hook) |
1000 | (add-hook 'select-frame-hook 'ediff-xemacs-select-frame-hook nil t) | |
475f9031 KH |
1001 | )) |
1002 | ||
e756eb9f | 1003 | (ediff-with-current-buffer ctl-buffer |
6853a937 | 1004 | (run-hooks 'ediff-after-setup-control-frame-hook)) |
18b5607f | 1005 | )) |
ddc90f39 | 1006 | |
18b5607f KH |
1007 | |
1008 | (defun ediff-destroy-control-frame (ctl-buffer) | |
e756eb9f | 1009 | (ediff-with-current-buffer ctl-buffer |
18b5607f KH |
1010 | (if (and (ediff-window-display-p) (frame-live-p ediff-control-frame)) |
1011 | (let ((ctl-frame ediff-control-frame)) | |
1012 | (if ediff-xemacs-p | |
1013 | (set-buffer-menubar default-menubar)) | |
18b5607f KH |
1014 | (setq ediff-control-frame nil) |
1015 | (delete-frame ctl-frame) | |
1016 | ))) | |
1017 | (ediff-skip-unsuitable-frames) | |
6853a937 MK |
1018 | ;;(ediff-reset-mouse nil) |
1019 | ) | |
475f9031 KH |
1020 | |
1021 | ||
1022 | ;; finds a good place to clip control frame | |
1023 | (defun ediff-make-frame-position (ctl-buffer ctl-frame-width ctl-frame-height) | |
e756eb9f | 1024 | (ediff-with-current-buffer ctl-buffer |
18b5607f KH |
1025 | (let* ((frame-A (window-frame ediff-window-A)) |
1026 | (frame-A-parameters (frame-parameters frame-A)) | |
6853a937 MK |
1027 | (frame-A-top (eval (cdr (assoc 'top frame-A-parameters)))) |
1028 | (frame-A-left (eval (cdr (assoc 'left frame-A-parameters)))) | |
18b5607f | 1029 | (frame-A-width (frame-width frame-A)) |
475f9031 KH |
1030 | (ctl-frame ediff-control-frame) |
1031 | horizontal-adjustment upward-adjustment | |
6853a937 | 1032 | ctl-frame-top ctl-frame-left) |
475f9031 KH |
1033 | |
1034 | ;; Multiple control frames are clipped based on the value of | |
1035 | ;; ediff-control-buffer-number. This is done in order not to obscure | |
1036 | ;; other active control panels. | |
1037 | (setq horizontal-adjustment (* 2 ediff-control-buffer-number) | |
1038 | upward-adjustment (* -14 ediff-control-buffer-number)) | |
1039 | ||
6853a937 MK |
1040 | (setq ctl-frame-top |
1041 | (- frame-A-top upward-adjustment ediff-control-frame-upward-shift) | |
1042 | ctl-frame-left | |
1043 | (+ frame-A-left | |
4ae69eac | 1044 | (if ediff-use-long-help-message |
6853a937 MK |
1045 | (* (ediff-frame-char-width ctl-frame) |
1046 | (+ ediff-wide-control-frame-rightward-shift | |
1047 | horizontal-adjustment)) | |
1048 | (- (* frame-A-width (ediff-frame-char-width frame-A)) | |
1049 | (* (ediff-frame-char-width ctl-frame) | |
1050 | (+ ctl-frame-width | |
1051 | ediff-narrow-control-frame-leftward-shift | |
1052 | horizontal-adjustment)))))) | |
6853a937 MK |
1053 | (setq ctl-frame-top |
1054 | (min ctl-frame-top | |
1055 | (- (ediff-display-pixel-height) | |
1056 | (* 2 ctl-frame-height | |
1057 | (ediff-frame-char-height ctl-frame)))) | |
1058 | ctl-frame-left | |
1059 | (min ctl-frame-left | |
1060 | (- (ediff-display-pixel-width) | |
1061 | (* ctl-frame-width (ediff-frame-char-width ctl-frame))))) | |
4ae69eac MK |
1062 | ;; keep ctl frame within the visible bounds |
1063 | (setq ctl-frame-top (max ctl-frame-top 1) | |
1064 | ctl-frame-left (max ctl-frame-left 1)) | |
6853a937 MK |
1065 | |
1066 | (list (cons 'top ctl-frame-top) | |
1067 | (cons 'left ctl-frame-left)) | |
1068 | ))) | |
475f9031 | 1069 | |
18b5607f | 1070 | (defun ediff-xemacs-select-frame-hook () |
6853a937 | 1071 | (if (and (equal (selected-frame) ediff-control-frame) |
4ae69eac | 1072 | (not ediff-use-long-help-message)) |
18b5607f | 1073 | (raise-frame ediff-control-frame))) |
475f9031 KH |
1074 | |
1075 | (defun ediff-make-wide-display () | |
1076 | "Construct an alist of parameters for the wide display. | |
1077 | Saves the old frame parameters in `ediff-wide-display-orig-parameters'. | |
1078 | The frame to be resized is kept in `ediff-wide-display-frame'. | |
1079 | This function modifies only the left margin and the width of the display. | |
1080 | It assumes that it is called from within the control buffer." | |
18b5607f KH |
1081 | (if (not (fboundp 'ediff-display-pixel-width)) |
1082 | (error "Can't determine display width.")) | |
1083 | (let* ((frame-A (window-frame ediff-window-A)) | |
1084 | (frame-A-params (frame-parameters frame-A)) | |
475f9031 | 1085 | (cw (ediff-frame-char-width frame-A)) |
18b5607f | 1086 | (wd (- (/ (ediff-display-pixel-width) cw) 5))) |
475f9031 | 1087 | (setq ediff-wide-display-orig-parameters |
6853a937 | 1088 | (list (cons 'left (max 0 (eval (cdr (assoc 'left frame-A-params))))) |
475f9031 KH |
1089 | (cons 'width (cdr (assoc 'width frame-A-params)))) |
1090 | ediff-wide-display-frame frame-A) | |
18b5607f | 1091 | (modify-frame-parameters frame-A (list (cons 'left cw) |
475f9031 KH |
1092 | (cons 'width wd))))) |
1093 | ||
1094 | ||
1095 | ||
1096 | ;; Revise the mode line to display which difference we have selected | |
1097 | ;; Also resets modelines of buffers A/B, since they may be clobbered by | |
1098 | ;; anothe invocations of Ediff. | |
1099 | (defun ediff-refresh-mode-lines () | |
1100 | (let (buf-A-state-diff buf-B-state-diff buf-C-state-diff buf-C-state-merge) | |
1101 | ||
1102 | (if (ediff-valid-difference-p) | |
1103 | (setq | |
1104 | buf-C-state-diff (ediff-get-state-of-diff ediff-current-difference 'C) | |
1105 | buf-C-state-merge (ediff-get-state-of-merge ediff-current-difference) | |
1106 | buf-A-state-diff (ediff-get-state-of-diff ediff-current-difference 'A) | |
1107 | buf-B-state-diff (ediff-get-state-of-diff ediff-current-difference 'B) | |
1108 | buf-A-state-diff (if buf-A-state-diff | |
1109 | (format "[%s] " buf-A-state-diff) | |
1110 | "") | |
1111 | buf-B-state-diff (if buf-B-state-diff | |
1112 | (format "[%s] " buf-B-state-diff) | |
1113 | "") | |
1114 | buf-C-state-diff (if (and (ediff-buffer-live-p ediff-buffer-C) | |
1115 | (or buf-C-state-diff buf-C-state-merge)) | |
6853a937 | 1116 | (format "[%s%s%s] " |
475f9031 KH |
1117 | (or buf-C-state-diff "") |
1118 | (if buf-C-state-merge | |
1119 | (concat " " buf-C-state-merge) | |
6853a937 MK |
1120 | "") |
1121 | (if (ediff-get-state-of-ancestor | |
1122 | ediff-current-difference) | |
1123 | " AncestorEmpty" | |
1124 | "") | |
1125 | ) | |
475f9031 KH |
1126 | "")) |
1127 | (setq buf-A-state-diff "" | |
1128 | buf-B-state-diff "" | |
1129 | buf-C-state-diff "")) | |
1130 | ||
1131 | ;; control buffer format | |
1132 | (setq mode-line-format | |
ddc90f39 MK |
1133 | (if (ediff-narrow-control-frame-p) |
1134 | (list " " mode-line-buffer-identification) | |
1135 | (list "-- " mode-line-buffer-identification " Quick Help"))) | |
475f9031 KH |
1136 | ;; control buffer id |
1137 | (setq mode-line-buffer-identification | |
1138 | (if (ediff-narrow-control-frame-p) | |
1139 | (ediff-make-narrow-control-buffer-id 'skip-name) | |
1140 | (ediff-make-wide-control-buffer-id))) | |
1141 | ;; Force mode-line redisplay | |
1142 | (force-mode-line-update) | |
1143 | ||
18b5607f | 1144 | (if (and (ediff-window-display-p) (frame-live-p ediff-control-frame)) |
475f9031 KH |
1145 | (ediff-refresh-control-frame)) |
1146 | ||
e756eb9f | 1147 | (ediff-with-current-buffer ediff-buffer-A |
475f9031 KH |
1148 | (setq ediff-diff-status buf-A-state-diff) |
1149 | (ediff-strip-mode-line-format) | |
1150 | (setq mode-line-format | |
1151 | (list " A: " 'ediff-diff-status mode-line-format)) | |
1152 | (force-mode-line-update)) | |
e756eb9f | 1153 | (ediff-with-current-buffer ediff-buffer-B |
475f9031 KH |
1154 | (setq ediff-diff-status buf-B-state-diff) |
1155 | (ediff-strip-mode-line-format) | |
1156 | (setq mode-line-format | |
1157 | (list " B: " 'ediff-diff-status mode-line-format)) | |
1158 | (force-mode-line-update)) | |
1159 | (if ediff-3way-job | |
e756eb9f | 1160 | (ediff-with-current-buffer ediff-buffer-C |
475f9031 KH |
1161 | (setq ediff-diff-status buf-C-state-diff) |
1162 | (ediff-strip-mode-line-format) | |
1163 | (setq mode-line-format | |
1164 | (list " C: " 'ediff-diff-status mode-line-format)) | |
1165 | (force-mode-line-update))) | |
6853a937 | 1166 | (if (ediff-buffer-live-p ediff-ancestor-buffer) |
e756eb9f | 1167 | (ediff-with-current-buffer ediff-ancestor-buffer |
6853a937 MK |
1168 | (ediff-strip-mode-line-format) |
1169 | ;; we keep the second dummy string in the mode line format of the | |
1170 | ;; ancestor, since for other buffers Ediff prepends 2 strings and | |
1171 | ;; ediff-strip-mode-line-format expects that. | |
1172 | (setq mode-line-format | |
1173 | (list " Ancestor: " | |
1174 | (cond ((not (stringp buf-C-state-merge)) | |
1175 | "") | |
1176 | ((string-match "prefer-A" buf-C-state-merge) | |
1177 | "[=diff(B)] ") | |
1178 | ((string-match "prefer-B" buf-C-state-merge) | |
1179 | "[=diff(A)] ") | |
1180 | (t "")) | |
1181 | mode-line-format)))) | |
475f9031 KH |
1182 | )) |
1183 | ||
1184 | ||
1185 | (defun ediff-refresh-control-frame () | |
6853a937 | 1186 | (if ediff-emacs-p |
bbe6126c | 1187 | ;; set frame/icon titles for Emacs |
6853a937 MK |
1188 | (modify-frame-parameters |
1189 | ediff-control-frame | |
bbe6126c MK |
1190 | (list (cons 'title (ediff-make-base-title)) |
1191 | (cons 'icon-name (ediff-make-narrow-control-buffer-id)) | |
1192 | )) | |
1193 | ;; set frame/icon titles for XEmacs | |
1194 | (setq frame-title-format (ediff-make-base-title) | |
1195 | frame-icon-title-format (ediff-make-narrow-control-buffer-id)) | |
6853a937 MK |
1196 | ;; force an update of the frame title |
1197 | (modify-frame-parameters ediff-control-frame '(())))) | |
475f9031 KH |
1198 | |
1199 | ||
1200 | (defun ediff-make-narrow-control-buffer-id (&optional skip-name) | |
1201 | (concat | |
1202 | (if skip-name | |
1203 | " " | |
bbe6126c | 1204 | (ediff-make-base-title)) |
475f9031 KH |
1205 | (cond ((< ediff-current-difference 0) |
1206 | (format " _/%d" ediff-number-of-differences)) | |
1207 | ((>= ediff-current-difference ediff-number-of-differences) | |
1208 | (format " $/%d" ediff-number-of-differences)) | |
1209 | (t | |
1210 | (format " %d/%d" | |
1211 | (1+ ediff-current-difference) | |
1212 | ediff-number-of-differences))))) | |
bbe6126c MK |
1213 | |
1214 | (defun ediff-make-base-title () | |
1215 | (concat | |
1216 | (cdr (assoc 'name ediff-control-frame-parameters)) | |
1217 | ediff-control-buffer-suffix)) | |
475f9031 KH |
1218 | |
1219 | (defun ediff-make-wide-control-buffer-id () | |
1220 | (cond ((< ediff-current-difference 0) | |
1221 | (list (format "%%b At start of %d diffs" | |
1222 | ediff-number-of-differences))) | |
1223 | ((>= ediff-current-difference ediff-number-of-differences) | |
1224 | (list (format "%%b At end of %d diffs" | |
1225 | ediff-number-of-differences))) | |
1226 | (t | |
1227 | (list (format "%%b diff %d of %d" | |
1228 | (1+ ediff-current-difference) | |
1229 | ediff-number-of-differences))))) | |
1230 | ||
1231 | ||
1232 | ||
1233 | ;; If buff is not live, return nil | |
1234 | (defun ediff-get-visible-buffer-window (buff) | |
1235 | (if (ediff-buffer-live-p buff) | |
1236 | (if ediff-xemacs-p | |
1237 | (get-buffer-window buff t) | |
1238 | (get-buffer-window buff 'visible)))) | |
1239 | ||
475f9031 | 1240 | |
bbe6126c | 1241 | ;;; Functions to decide when to redraw windows |
475f9031 KH |
1242 | |
1243 | (defun ediff-keep-window-config (control-buf) | |
1244 | (and (eq control-buf (current-buffer)) | |
1245 | (/= (buffer-size) 0) | |
e756eb9f | 1246 | (ediff-with-current-buffer control-buf |
475f9031 KH |
1247 | (let ((ctl-wind ediff-control-window) |
1248 | (A-wind ediff-window-A) | |
1249 | (B-wind ediff-window-B) | |
1250 | (C-wind ediff-window-C)) | |
1251 | ||
1252 | (and | |
1253 | (ediff-window-visible-p A-wind) | |
1254 | (ediff-window-visible-p B-wind) | |
1255 | ;; if buffer C is defined then take it into account | |
1256 | (or (not ediff-3way-job) | |
1257 | (ediff-window-visible-p C-wind)) | |
1258 | (eq (window-buffer A-wind) ediff-buffer-A) | |
1259 | (eq (window-buffer B-wind) ediff-buffer-B) | |
1260 | (or (not ediff-3way-job) | |
1261 | (eq (window-buffer C-wind) ediff-buffer-C)) | |
1262 | (string= ediff-window-config-saved | |
18b5607f | 1263 | (format "%S%S%S%S%S%S%S" |
475f9031 | 1264 | ctl-wind A-wind B-wind C-wind |
18b5607f KH |
1265 | ediff-split-window-function |
1266 | (ediff-multiframe-setup-p) | |
1267 | ediff-wide-display-p))))))) | |
475f9031 KH |
1268 | |
1269 | ||
bbe6126c MK |
1270 | ;;; Local Variables: |
1271 | ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun) | |
e756eb9f MK |
1272 | ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1) |
1273 | ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body)) | |
bbe6126c MK |
1274 | ;;; End: |
1275 | ||
475f9031 | 1276 | ;;; ediff-wind.el ends here |