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