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