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