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