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