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