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