1 ;;; ediff-wind.el --- window manipulation utilities
2 ;;; Copyright (C) 1994 Free Software Foundation, Inc.
4 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 (defvar ediff-window-setup-function (if (not window-system)
27 'ediff-setup-windows-plain
28 'ediff-setup-windows-multiframe)
29 "*Function called to set up windows.
30 Ediff provides a choice of two functions: ediff-setup-windows-plain, for
31 doing everything in one frame, and ediff-setup-windows-multiframe,
32 which sets the control panel in a separate frame. Also, if the latter
33 function detects that one of the buffers A/B is seen in some other frame,
34 it will try to keep that buffer in that frame.
36 If you don't like the two functions provided---write your own one.
38 1. It should leave the control buffer current and the control window
40 2. It should set ediff-window-A, ediff-window-B, ediff-window-C,
41 and ediff-control-window to contain window objects that display
42 the corresponding buffers.
43 3. It should accept the following arguments:
44 buffer-A, buffer-B, buffer-C, control-buffer
45 Buffer C may not be used in jobs that compare only two buffers.
46 If you plan to do something fancy, take a close look at how the two
47 provided functions are written.")
49 ;; indicates if we are in a multiframe setup
50 (ediff-defvar-local ediff-multiframe nil "")
52 ;; Share of the frame occupied by the merge window (buffer C)
53 (ediff-defvar-local ediff-merge-window-share 0.45 "")
55 ;; The control window.
56 (ediff-defvar-local ediff-control-window nil "")
57 ;; Official window for buffer A
58 (ediff-defvar-local ediff-window-A nil "")
59 ;; Official window for buffer B
60 (ediff-defvar-local ediff-window-B nil "")
61 ;; Official window for buffer C
62 (ediff-defvar-local ediff-window-C nil "")
63 ;; Ediff's window configuration.
64 ;; Used to minimize the need to rearrange windows.
65 (ediff-defvar-local ediff-window-config-saved "" "")
68 (defvar ediff-split-window-function 'split-window-vertically
69 "*The function used to split the main window between buffer-A and buffer-B.
70 You can set it to a horizontal split instead of the default vertical split
71 by setting this variable to `split-window-horizontally'.
72 You can also have your own function to do fancy splits.
73 This variable has no effect when buffer-A/B are shown in different frames.
74 In this case, Ediff will use those frames to display these buffers.")
76 (defvar ediff-merge-split-window-function 'split-window-horizontally
77 "*The function used to split the main window between buffer-A and buffer-B.
78 You can set it to a vertical split instead of the default horizontal split
79 by setting this variable to `split-window-vertically'.
80 You can also have your own function to do fancy splits.
81 This variable has no effect when buffer-A/B/C are shown in different frames.
82 In this case, Ediff will use those frames to display these buffers.")
84 (defconst ediff-control-frame-parameters
90 '(vertical-scroll-bars . nil) ; FSF only
91 '(scrollbar-width . 0) ; XEmacs only
92 '(menu-bar-lines . 0) ; FSF only
93 ;; don't lower and auto-raise
96 ;; this blocks queries from window manager as to where to put
97 ;; ediff's control frame. we put the frame outside the display,
98 ;; so the initial frame won't jump all over the screen
99 (cons 'top (if (fboundp 'x-display-pixel-height)
100 (1+ (x-display-pixel-height))
102 (cons 'left (if (fboundp 'x-display-pixel-width)
103 (1+ (x-display-pixel-width))
106 "Frame parameters for displaying Ediff Control Panel.
107 Do not specify width and height here. These are computed automatically.")
109 (defvar ediff-control-frame-position-function 'ediff-make-frame-position
110 "Function to call to determine the desired location for the control panel.
111 Expects three parameters: the control buffer, the desired width and height
112 of the control frame. It returns an association list
113 of the form \(\(top . <position>\) \(left . <position>\)\)")
115 (defvar ediff-control-frame-upward-shift (if ediff-xemacs-p 36 4)
116 "*The upward shift of control frame from the top of buffer A's frame.
118 This is used by the default control frame positioning function,
119 `ediff-make-frame-position'. This variable is provided for easy
120 customization of the default.")
122 (defvar ediff-narrow-control-frame-leftward-shift (if ediff-xemacs-p 7 3)
123 "*The leftward shift of control frame from the right edge of buf A's frame.
124 Measured in characters.
125 This is used by the default control frame positioning function,
126 `ediff-make-frame-position' to adjust the position of the control frame
127 when it shows the short menu. This variable is provided for easy
128 customization of the default.")
130 (defvar ediff-wide-control-frame-rightward-shift 7
131 "*The rightward shift of control frame from the left edge of buf A's frame.
132 Measured in characters.
133 This is used by the default control frame positioning function,
134 `ediff-make-frame-position' to adjust the position of the control frame
135 when it shows the full menu. This variable is provided for easy
136 customization of the default.")
139 ;; Wide frame display
141 ;; t means Ediff is using wide display
142 (ediff-defvar-local ediff-wide-display-p nil "")
143 ;; keeps frame config for toggling wide display
144 (ediff-defvar-local ediff-wide-display-orig-parameters nil
145 "Frame parameters to be restored when the user wants to toggle the wide
147 (ediff-defvar-local ediff-wide-display-frame nil
148 "Frame to be used for wide display.")
149 (ediff-defvar-local ediff-make-wide-display-function 'ediff-make-wide-display
150 "The value is a function that is called to create a wide display.
151 The function is called without arguments. It should resize the frame in
152 which buffers A, B, and C are to be displayed, and it should save the old
153 frame parameters in `ediff-wide-display-orig-parameters'.
154 The variable `ediff-wide-display-frame' should be set to contain
155 the frame used for the wide display.")
157 ;; Frame used for the control panel in a windowing system.
158 (ediff-defvar-local ediff-control-frame nil "")
160 (defvar ediff-prefer-iconified-control-frame nil
161 "*If t, keep control panel iconified when help message is off.
162 This has effect only on a windowing system.
163 If t, hiting `?' to toggle control panel off iconifies it.
165 This is only useful in Emacs and only for certain kinds of window managers,
166 such as TWM and its derivatives, since the window manager must permit
167 keyboard input to go into icons. XEmacs completely ignores keyboard input
168 into icons, regardless of the window manager.")
172 (defun ediff-get-window-by-clicking (wind prev-wind wind-number)
175 "Select windows by clicking. Please click on Window %d " wind-number)
176 (while (not (ediff-mouse-event-p (setq event (ediff-read-event))))
177 (if (sit-for 1) ; if sequence of events, wait till the final word
179 (message "Please click on Window %d " wind-number))
180 (ediff-read-event) ; discard event
181 (setq wind (if ediff-xemacs-p
183 (posn-window (event-start event))))
187 ;; Select the lowest window on the frame.
188 (defun ediff-select-lowest-window ()
189 (let* ((lowest-window (selected-window))
190 (bottom-edge (car (cdr (cdr (cdr (window-edges))))))
191 ;;(last-window (previous-window))
192 (last-window (save-excursion
193 (other-window -1) (selected-window)))
196 (let* ((this-window (next-window))
197 (next-bottom-edge (car (cdr (cdr (cdr
198 (window-edges this-window)))))))
199 (if (< bottom-edge next-bottom-edge)
201 (setq bottom-edge next-bottom-edge)
202 (setq lowest-window this-window)))
204 (select-window this-window)
205 (if (eq last-window this-window)
207 (select-window lowest-window)
208 (setq window-search nil)))))))
212 ;;; Common window setup routines
214 ;; Set up the window configuration. If POS is given, set the points to
215 ;; the beginnings of the buffers.
216 ;; When 3way comparison is added, this will have to choose the appropriate
217 ;; setup function based on ediff-job-name
218 (defun ediff-setup-windows (buffer-A buffer-B buffer-C control-buffer)
219 ;; Make sure we are not in the minibuffer window when we try to delete
220 ;; all other windows.
221 (run-hooks 'ediff-before-setup-windows-hooks)
222 (if (eq (selected-window) (minibuffer-window))
225 ;; when support for buf C is added, the actual window setup function will
226 ;; depend on ediff-job-name
227 (or (ediff-keep-window-config control-buffer)
229 (ediff-eval-in-buffer control-buffer ediff-window-setup-function)
230 buffer-A buffer-B buffer-C control-buffer))
231 (run-hooks 'ediff-after-setup-windows-hooks))
233 ;; Just set up 3 windows.
234 ;; Usually used without windowing systems
235 ;; With windowing, we want to use dedicated frames.
236 (defun ediff-setup-windows-plain (buffer-A buffer-B buffer-C control-buffer)
237 (ediff-eval-in-buffer control-buffer
238 (setq ediff-multiframe nil))
240 (ediff-setup-windows-plain-merge
241 buffer-A buffer-B buffer-C control-buffer)
242 (ediff-setup-windows-plain-compare
243 buffer-A buffer-B buffer-C control-buffer)))
245 (defun ediff-setup-windows-plain-merge (buf-A buf-B buf-C control-buffer)
246 ;; skip dedicated and unsplittable frames
247 (ediff-eval-in-buffer control-buffer
248 (if (and window-system (ediff-frame-live-p ediff-control-frame))
251 (ediff-delete-frame ediff-control-frame)
252 (setq ediff-control-frame nil))))
253 (ediff-skip-unsuitable-frames)
254 (let ((window-min-height 1)
255 split-window-function
256 merge-window-share merge-window-lines
257 wind-A wind-B wind-C)
258 (ediff-eval-in-buffer control-buffer
259 (setq merge-window-share ediff-merge-window-share
260 ;; this lets us have local versions of ediff-split-window-function
261 split-window-function ediff-split-window-function))
262 (delete-other-windows)
263 (split-window-vertically)
264 (ediff-select-lowest-window)
265 (ediff-setup-control-buffer control-buffer)
267 ;; go to the upper window and split it betw A, B, and possibly C
269 (setq merge-window-lines
270 (max 2 (round (* (window-height) merge-window-share))))
271 (switch-to-buffer buf-A)
272 (setq wind-A (selected-window))
274 ;; XEmacs seems to have a lot of trouble with display
275 ;; It won't set things right unless we tell it to sit still
276 (if ediff-xemacs-p (sit-for 0))
278 (split-window-vertically (max 2 (- (window-height) merge-window-lines)))
279 (if (eq (selected-window) wind-A)
281 (setq wind-C (selected-window))
282 (switch-to-buffer buf-C)
284 (select-window wind-A)
285 (funcall split-window-function)
287 (if (eq (selected-window) wind-A)
289 (switch-to-buffer buf-B)
290 (setq wind-B (selected-window))
292 (ediff-eval-in-buffer control-buffer
293 (setq ediff-window-A wind-A
294 ediff-window-B wind-B
295 ediff-window-C wind-C))
297 (ediff-select-lowest-window)
298 (ediff-setup-control-buffer control-buffer)
302 ;; This function handles all comparison jobs, including 3way jobs
303 (defun ediff-setup-windows-plain-compare (buf-A buf-B buf-C control-buffer)
304 ;; skip dedicated and unsplittable frames
305 (ediff-eval-in-buffer control-buffer
306 (if (and window-system (ediff-frame-live-p ediff-control-frame))
309 (ediff-delete-frame ediff-control-frame)
310 (setq ediff-control-frame nil))))
311 (ediff-skip-unsuitable-frames)
312 (let ((window-min-height 1)
313 split-window-function wind-width-or-height
315 job wind-A-start wind-B-start wind-A wind-B wind-C)
316 (ediff-eval-in-buffer control-buffer
317 (setq wind-A-start (ediff-overlay-start
318 (ediff-get-value-according-to-buffer-type
319 'A ediff-narrow-bounds))
320 wind-B-start (ediff-overlay-start
321 (ediff-get-value-according-to-buffer-type
322 'B ediff-narrow-bounds))
324 ;; this lets us have local versions of ediff-split-window-function
325 split-window-function ediff-split-window-function
326 three-way-comparison ediff-3way-comparison-job))
327 (delete-other-windows)
328 (split-window-vertically)
329 (ediff-select-lowest-window)
330 (ediff-setup-control-buffer control-buffer)
332 ;; go to the upper window and split it betw A, B, and possibly C
334 (switch-to-buffer buf-A)
335 (setq wind-A (selected-window))
336 (if three-way-comparison
337 (setq wind-width-or-height
338 (/ (if (eq split-window-function 'split-window-vertically)
339 (window-height wind-A)
340 (window-width wind-A))
343 ;; XEmacs seems to have a lot of trouble with display
344 ;; It won't set things right unless we tell it to sit still
345 (if ediff-xemacs-p (sit-for 0))
347 (funcall split-window-function wind-width-or-height)
349 (if (eq (selected-window) wind-A)
351 (switch-to-buffer buf-B)
352 (setq wind-B (selected-window))
354 (if three-way-comparison
356 (funcall split-window-function) ; equally
357 (if (eq (selected-window) wind-B)
359 (switch-to-buffer buf-C)
360 (setq wind-C (selected-window))))
362 (ediff-eval-in-buffer control-buffer
363 (setq ediff-window-A wind-A
364 ediff-window-B wind-B
365 ediff-window-C wind-C))
367 ;; It is unlikely that we will want to implement 3way window comparison.
368 ;; So, only buffers A and B are used here.
369 (if (eq job 'ediff-windows)
371 (set-window-start wind-A wind-A-start)
372 (set-window-start wind-B wind-B-start)))
374 (ediff-select-lowest-window)
375 (ediff-setup-control-buffer control-buffer)
379 ;; dispatch the appropriate window setup function
380 (defun ediff-setup-windows-multiframe (buf-A buf-B buf-C control-buf)
381 (ediff-eval-in-buffer control-buf
382 (setq ediff-multiframe t))
384 (ediff-setup-windows-multiframe-merge buf-A buf-B buf-C control-buf)
385 (ediff-setup-windows-multiframe-compare buf-A buf-B buf-C control-buf)))
387 (defun ediff-setup-windows-multiframe-merge (buf-A buf-B buf-C control-buf)
389 ;;; If A and B are in the same frame but C's frame is different--- use one
390 ;;; frame for A and B and use a separate frame for C.
391 ;;; If C's frame is non-existent, then: if the first suitable
392 ;;; non-dedicated frame is different from A&B's, then use it for C.
393 ;;; Otherwise, put A,B, and C in one frame.
394 ;;; If buffers A, B, C are is separate frames, use them to display these
397 ;; Skip dedicated or iconified frames. Unsplittable frames are taken
399 (ediff-skip-unsuitable-frames 'ok-unsplittable)
401 (let* ((window-min-height 1)
402 (wind-A (ediff-get-visible-buffer-window buf-A))
403 (wind-B (ediff-get-visible-buffer-window buf-B))
404 (wind-C (ediff-get-visible-buffer-window buf-C))
405 (frame-A (if wind-A (ediff-window-frame wind-A)))
406 (frame-B (if wind-B (ediff-window-frame wind-B)))
407 (frame-C (if wind-C (ediff-window-frame wind-C)))
408 ;; on wide display, do things in one frame
410 (ediff-eval-in-buffer control-buf ediff-wide-display-p))
411 ;; this lets us have local versions of ediff-split-window-function
412 (split-window-function
413 (ediff-eval-in-buffer control-buf ediff-split-window-function))
414 (orig-wind (selected-window))
415 (orig-frame (ediff-selected-frame))
416 (use-same-frame (or force-one-frame
417 (eq frame-A (or frame-C orig-frame))
418 (eq frame-B (or frame-C orig-frame))
419 (not (ediff-frame-live-p frame-A))
420 (not (ediff-frame-live-p frame-B))
422 (use-same-frame-for-AB (and (not use-same-frame)
423 (eq frame-A frame-B)))
424 (merge-window-share (ediff-eval-in-buffer control-buf
425 ediff-merge-window-share))
427 designated-minibuffer-frame
428 done-A done-B done-C)
431 (if (and (window-live-p wind-A)
432 (null use-same-frame)
433 (null use-same-frame-for-AB))
435 (select-window wind-A)
436 (delete-other-windows)
437 (switch-to-buffer buf-A)
438 (setq wind-A (selected-window))
442 (if (and (window-live-p wind-B) (null use-same-frame)) ; buf B on its own
444 (select-window wind-B)
445 (delete-other-windows)
446 (switch-to-buffer buf-B)
447 (setq wind-B (selected-window))
451 (if (and (window-live-p wind-C) (null use-same-frame)) ; buf C on its own
453 (select-window wind-C)
454 (delete-other-windows)
455 (switch-to-buffer buf-C)
456 (setq wind-C (selected-window))
459 (if use-same-frame-for-AB
461 (ediff-select-frame frame-A)
462 (switch-to-buffer buf-A)
463 (delete-other-windows)
464 (setq wind-A (selected-window))
466 (funcall split-window-function)
467 (if (eq (selected-window) wind-A)
469 (switch-to-buffer buf-B)
470 (setq wind-B (selected-window))
476 (let ((curr-frame (ediff-selected-frame))
477 (window-min-height 1))
478 ;; avoid dedicated and non-splittable windows
479 (ediff-skip-unsuitable-frames)
480 (or (eq curr-frame (ediff-selected-frame))
484 orig-wind (selected-window)))
486 ;; set the right frame
487 (cond (wind-A (select-window wind-A))
488 (wind-B (select-window wind-B))
489 (wind-C (select-window wind-C))
490 (t (select-window orig-wind)))
491 (delete-other-windows)
492 (setq merge-window-lines
493 (max 2 (round (* (window-height) merge-window-share))))
494 (switch-to-buffer buf-A)
495 (setq wind-A (selected-window))
497 ;; XEmacs seems to have a lot of trouble with display
498 ;; It won't set things right unless we tell it to catch breath
499 (if ediff-xemacs-p (sit-for 0))
501 (split-window-vertically
502 (max 2 (- (window-height) merge-window-lines)))
503 (if (eq (selected-window) wind-A)
505 (setq wind-C (selected-window))
506 (switch-to-buffer buf-C)
508 (select-window wind-A)
510 (funcall split-window-function)
511 (if (eq (selected-window) wind-A)
513 (switch-to-buffer buf-B)
514 (setq wind-B (selected-window))
521 (or done-A ; Buf A to be set in its own frame
522 (progn ; It was not set up yet as it wasn't visible
523 (select-window orig-wind)
524 (delete-other-windows)
525 (switch-to-buffer buf-A)
526 (setq wind-A (selected-window))
528 (or done-B ; Buf B to be set in its own frame
529 (progn ; It was not set up yet as it wasn't visible
530 (select-window orig-wind)
531 (delete-other-windows)
532 (switch-to-buffer buf-B)
533 (setq wind-B (selected-window))
536 (or done-C ; Buf C to be set in its own frame.
537 (progn ; It was not set up yet as it wasn't visible
538 (select-window orig-wind)
539 (delete-other-windows)
540 (switch-to-buffer buf-C)
541 (setq wind-C (selected-window))
544 (ediff-eval-in-buffer control-buf
545 (setq ediff-window-A wind-A
546 ediff-window-B wind-B
547 ediff-window-C wind-C)
549 (setq frame-A (ediff-window-frame ediff-window-A)
550 designated-minibuffer-frame (ediff-window-frame
551 (minibuffer-window frame-A)))
554 (if (not (eq designated-minibuffer-frame default-minibuffer-frame))
556 (setq default-minibuffer-frame designated-minibuffer-frame)
557 (if (ediff-frame-live-p ediff-control-frame)
558 (ediff-delete-frame ediff-control-frame)))
562 (ediff-setup-control-frame control-buf)
566 ;; Window setup for all comparison jobs, including 3way comparisons
567 (defun ediff-setup-windows-multiframe-compare (buf-A buf-B buf-C control-buf)
569 ;;; If a buffer is seen in a frame, use that frame for that buffer.
570 ;;; If it is not seen, use the current frame.
571 ;;; If both buffers are not seen, they share the current frame. If one
572 ;;; of the buffers is not seen, it is placed in the current frame (where
573 ;;; ediff started). If that frame is displaying the other buffer, it is
574 ;;; shared between the two buffers.
575 ;;; However, if we decide to put both buffers in one frame
576 ;;; and the selected frame isn't splittable, we create a new frame and
577 ;;; put both buffers there, event if one of this buffers is visible in
580 ;; Skip dedicated or iconified frames.
581 ;; Unsplittable frames are taken care of later.
582 (ediff-skip-unsuitable-frames 'ok-unsplittable)
584 (let* ((window-min-height 1)
585 (wind-A (ediff-get-visible-buffer-window buf-A))
586 (wind-B (ediff-get-visible-buffer-window buf-B))
587 (wind-C (ediff-get-visible-buffer-window buf-C))
588 (frame-A (if wind-A (ediff-window-frame wind-A)))
589 (frame-B (if wind-B (ediff-window-frame wind-B)))
590 (frame-C (if wind-C (ediff-window-frame wind-C)))
591 (ctl-frame-exists-p (ediff-eval-in-buffer control-buf
592 (ediff-frame-live-p ediff-control-frame)))
593 ;; on wide display, do things in one frame
595 (ediff-eval-in-buffer control-buf ediff-wide-display-p))
596 ;; this lets us have local versions of ediff-split-window-function
597 (split-window-function
598 (ediff-eval-in-buffer control-buf ediff-split-window-function))
599 (three-way-comparison
600 (ediff-eval-in-buffer control-buf ediff-3way-comparison-job))
601 (orig-wind (selected-window))
602 (use-same-frame (or force-one-frame
604 (if three-way-comparison
605 (or (eq frame-A frame-C)
607 (not (ediff-frame-live-p frame-A))
608 (not (ediff-frame-live-p frame-B))
609 (not (ediff-frame-live-p frame-C))))
610 (and (not (ediff-frame-live-p frame-B))
611 (or ctl-frame-exists-p
612 (eq frame-A (ediff-selected-frame))))
613 (and (not (ediff-frame-live-p frame-A))
614 (or ctl-frame-exists-p
615 (eq frame-B (ediff-selected-frame))))))
616 wind-A-start wind-B-start job-name
617 designated-minibuffer-frame
618 done-A done-B done-C)
620 (ediff-eval-in-buffer control-buf
621 (setq wind-A-start (ediff-overlay-start
622 (ediff-get-value-according-to-buffer-type
623 'A ediff-narrow-bounds))
624 wind-B-start (ediff-overlay-start
625 (ediff-get-value-according-to-buffer-type
626 'B ediff-narrow-bounds))
627 job-name ediff-job-name))
629 (if (and (window-live-p wind-A) (null use-same-frame)) ; buf-A on its own
631 (select-window wind-A)
632 (delete-other-windows)
633 (switch-to-buffer buf-A)
634 (setq wind-A (selected-window))
637 (if (and (window-live-p wind-B) (null use-same-frame)) ; buf B on its own
639 (select-window wind-B)
640 (delete-other-windows)
641 (switch-to-buffer buf-B)
642 (setq wind-B (selected-window))
645 (if (and (window-live-p wind-C) (null use-same-frame)) ; buf C on its own
647 (select-window wind-C)
648 (delete-other-windows)
649 (switch-to-buffer buf-C)
650 (setq wind-C (selected-window))
654 (let ((curr-frame (ediff-selected-frame))
655 ;; this affects 3way setups only
656 wind-width-or-height)
657 ;; avoid dedicated and non-splittable windows
658 (ediff-skip-unsuitable-frames)
659 (or (eq curr-frame (ediff-selected-frame))
663 orig-wind (selected-window)))
665 ;; set the right frame
666 (cond (wind-A (select-window wind-A))
667 (wind-B (select-window wind-B))
668 (wind-C (select-window wind-C))
669 (t (select-window orig-wind)))
670 (delete-other-windows)
671 (switch-to-buffer buf-A)
672 (setq wind-A (selected-window))
674 ;; XEmacs seems to have a lot of trouble with display
675 ;; It won't set things right unless we tell it to catch breath
676 (if ediff-xemacs-p (sit-for 0))
678 (if three-way-comparison
679 (setq wind-width-or-height
681 (if (eq split-window-function 'split-window-vertically)
682 (window-height wind-A)
683 (window-width wind-A))
686 (funcall split-window-function wind-width-or-height)
687 (if (eq (selected-window) wind-A)
689 (switch-to-buffer buf-B)
690 (setq wind-B (selected-window))
692 (if three-way-comparison
694 (funcall split-window-function) ; equally
695 (if (memq (selected-window) (list wind-A wind-B))
697 (switch-to-buffer buf-C)
698 (setq wind-C (selected-window))))
704 (or done-A ; Buf A to be set in its own frame
705 (progn ; It was not set up yet as it wasn't visible
706 (select-window orig-wind)
707 (delete-other-windows)
708 (switch-to-buffer buf-A)
709 (setq wind-A (selected-window))
711 (or done-B ; Buf B to be set in its own frame
712 (progn ; It was not set up yet as it wasn't visible
713 (select-window orig-wind)
714 (delete-other-windows)
715 (switch-to-buffer buf-B)
716 (setq wind-B (selected-window))
719 (if three-way-comparison
720 (or done-C ; Buf C to be set in its own frame
721 (progn ; It was not set up yet as it wasn't visible
722 (select-window orig-wind)
723 (delete-other-windows)
724 (switch-to-buffer buf-C)
725 (setq wind-C (selected-window))
728 (ediff-eval-in-buffer control-buf
729 (setq ediff-window-A wind-A
730 ediff-window-B wind-B
731 ediff-window-C wind-C)
733 (setq frame-A (ediff-window-frame ediff-window-A)
734 designated-minibuffer-frame (ediff-window-frame
735 (minibuffer-window frame-A)))
738 (if (not (eq designated-minibuffer-frame default-minibuffer-frame))
740 (setq default-minibuffer-frame designated-minibuffer-frame)
741 (if (ediff-frame-live-p ediff-control-frame)
742 (ediff-delete-frame ediff-control-frame)))
746 ;; It is unlikely that we'll implement ediff-windows that would compare
747 ;; 3 windows at once. So, we don't use buffer C here.
748 (if (eq job-name 'ediff-windows)
750 (set-window-start wind-A wind-A-start)
751 (set-window-start wind-B wind-B-start)))
753 (ediff-setup-control-frame control-buf)
756 ;; skip unsplittable and dedicated windows
757 ;; create a new splittable frame if none is found
758 (defun ediff-skip-unsuitable-frames (&optional ok-unsplittable)
761 (while (and (not (eq (selected-window) last-window))
763 (window-dedicated-p (selected-window))
764 (ediff-frame-iconified-p (ediff-selected-frame))
767 (ediff-frame-unsplittable-p (ediff-selected-frame)))))
768 ;; remember where started
769 (or last-window (setq last-window (selected-window)))
772 (if (eq (selected-window) last-window)
773 ;; fed up, no appropriate frame
776 (ediff-select-frame (ediff-make-frame '((unsplittable)))))))))
778 ;; Prepare or refresh control frame
779 (defun ediff-setup-control-frame (ctl-buffer)
780 (let ((window-min-height 1)
781 ctl-frame-iconified-p dont-iconify-ctl-frame deiconify-ctl-frame
782 ctl-frame old-ctl-frame lines
783 fheight fwidth adjusted-parameters)
785 (ediff-eval-in-buffer ctl-buffer
786 (run-hooks 'ediff-before-setup-control-frame-hooks))
788 (setq old-ctl-frame (ediff-eval-in-buffer ctl-buffer ediff-control-frame))
789 (if (ediff-frame-live-p old-ctl-frame)
790 (setq ctl-frame old-ctl-frame)
792 ;; frame should be made while ctl-buff is current, so that
793 ;; the local default-minibuffer-frame will be consulted and
794 ;; that ediff-control-frame-parameters will have the right value.
795 (ediff-eval-in-buffer ctl-buffer
796 (setq ctl-frame (ediff-make-frame
797 ediff-control-frame-parameters)))
798 (ediff-eval-in-buffer ctl-buffer (setq ediff-control-frame ctl-frame)))
800 (setq ctl-frame-iconified-p (ediff-frame-iconified-p ctl-frame))
801 (ediff-select-frame ctl-frame)
802 (if (window-dedicated-p (selected-window))
804 (delete-other-windows)
805 (switch-to-buffer ctl-buffer))
807 ;; must be before ediff-setup-control-buffer
809 ;; just a precaution--we should be in ctl-buffer already
810 (ediff-eval-in-buffer ctl-buffer
811 (make-local-variable 'screen-title-format)
812 (make-local-variable 'screen-icon-title-format)))
814 (ediff-setup-control-buffer ctl-buffer)
815 (setq dont-iconify-ctl-frame
816 (not (string= ediff-help-message ediff-brief-help-message)))
817 (setq deiconify-ctl-frame
818 (and (eq this-command 'ediff-toggle-help)
819 dont-iconify-ctl-frame))
821 ;; 1 more line for the modeline
822 (setq lines (if ediff-xemacs-p
823 (+ 2 (count-lines (point-min) (point-max)))
824 (1+ (count-lines (point-min) (point-max))))
826 fwidth (+ (ediff-help-message-line-length) 2)
827 adjusted-parameters (append (list
829 (cons 'height fheight))
831 ediff-control-frame-position-function
832 ctl-buffer fwidth fheight)))
834 ;; In XEmacs, buffer menubar needs to be killed before frame parameters
835 ;; are changed XEmacs needs to redisplay, as it has trouble setting
836 ;; height correctly otherwise.
837 (if (and ediff-xemacs-p (ediff-frame-has-menubar))
838 (progn (set-buffer-menubar nil)(sit-for 0)))
840 ;; Under OS/2 (emx) we have to call modify frame parameters twice, in
841 ;; order to make sure that at least once we do it for non-iconified
842 ;; frame. If appears that in the OS/2 port of Emacs, one can't modify
843 ;; frame parameters of iconified frames.
844 (if (eq system-type 'emx)
845 (ediff-modify-frame-parameters ctl-frame adjusted-parameters))
847 (goto-char (point-min))
849 (cond ((and ediff-prefer-iconified-control-frame
850 (not ctl-frame-iconified-p)
851 (not dont-iconify-ctl-frame))
852 (ediff-iconify-frame ctl-frame))
853 ((or deiconify-ctl-frame
854 (not ctl-frame-iconified-p))
855 (ediff-raise-frame ctl-frame)))
857 ;; This works around a bug in 19.25 and earlier. There, if frame gets
858 ;; iconified, the current buffer changes to that of the frame that
859 ;; becomes exposed as a result of this iconification.
860 ;; So, we make sure the current buffer doesn't change.
861 (ediff-select-frame ctl-frame)
862 (ediff-refresh-control-frame)
864 (ediff-modify-frame-parameters ctl-frame adjusted-parameters)
867 (set-window-buffer-dedicated (selected-window) ctl-buffer)
868 (set-window-dedicated-p (selected-window) t))
870 (or ediff-xemacs-p (sit-for 0 200)) ; emacs has trouble here, needs time
871 (or (ediff-frame-iconified-p ctl-frame)
872 (set-mouse-position ctl-frame 1 0))
873 (if (ediff-check-version '< 19 11 'xemacs) (sit-for 0))
874 (or ediff-xemacs-p (unfocus-frame))
877 (ediff-eval-in-buffer ctl-buffer
878 (make-local-variable 'select-screen-hook)
879 (add-hook 'select-screen-hook 'ediff-xemacs-select-screen-hook)
882 (ediff-eval-in-buffer ctl-buffer
883 (run-hooks 'ediff-after-setup-control-frame-hooks))
888 ;; finds a good place to clip control frame
889 (defun ediff-make-frame-position (ctl-buffer ctl-frame-width ctl-frame-height)
890 (ediff-eval-in-buffer ctl-buffer
891 (let* ((frame-A (ediff-window-frame ediff-window-A))
892 (frame-A-parameters (ediff-frame-parameters frame-A))
893 (frame-A-top (cdr (assoc 'top frame-A-parameters)))
894 (frame-A-left (cdr (assoc 'left frame-A-parameters)))
895 (frame-A-width (ediff-frame-width frame-A))
896 (ctl-frame ediff-control-frame)
897 horizontal-adjustment upward-adjustment
900 ;; Multiple control frames are clipped based on the value of
901 ;; ediff-control-buffer-number. This is done in order not to obscure
902 ;; other active control panels.
903 (setq horizontal-adjustment (* 2 ediff-control-buffer-number)
904 upward-adjustment (* -14 ediff-control-buffer-number))
906 (setq ctl-frame-top (- frame-A-top
908 ediff-control-frame-upward-shift))
910 (cons 'top (if (> ctl-frame-top 0) ctl-frame-top 1))
911 (cons 'left (+ frame-A-left
912 (if ediff-prefer-long-help-message
913 (* (ediff-frame-char-width ctl-frame)
914 (+ ediff-wide-control-frame-rightward-shift
915 horizontal-adjustment))
917 (ediff-frame-char-width frame-A))
918 (* (ediff-frame-char-width ctl-frame)
920 ediff-narrow-control-frame-leftward-shift
921 horizontal-adjustment))))))))))
923 (defun ediff-xemacs-select-screen-hook ()
924 (if (equal (ediff-selected-frame) ediff-control-frame)
925 (ediff-raise-frame ediff-control-frame)))
927 (defun ediff-make-wide-display ()
928 "Construct an alist of parameters for the wide display.
929 Saves the old frame parameters in `ediff-wide-display-orig-parameters'.
930 The frame to be resized is kept in `ediff-wide-display-frame'.
931 This function modifies only the left margin and the width of the display.
932 It assumes that it is called from within the control buffer."
933 (if (not (fboundp 'x-display-pixel-width))
935 "Can't determine display width. Please upgrade your version of Emacs"))
936 (let* ((frame-A (ediff-window-frame ediff-window-A))
937 (frame-A-params (ediff-frame-parameters frame-A))
938 (cw (ediff-frame-char-width frame-A))
939 (wd (- (/ (x-display-pixel-width) cw) 5)))
940 (setq ediff-wide-display-orig-parameters
941 (list (cons 'left (max 0 (cdr (assoc 'left frame-A-params))))
942 (cons 'width (cdr (assoc 'width frame-A-params))))
943 ediff-wide-display-frame frame-A)
944 (ediff-modify-frame-parameters frame-A (list (cons 'left cw)
949 ;; Revise the mode line to display which difference we have selected
950 ;; Also resets modelines of buffers A/B, since they may be clobbered by
951 ;; anothe invocations of Ediff.
952 (defun ediff-refresh-mode-lines ()
953 (let (buf-A-state-diff buf-B-state-diff buf-C-state-diff buf-C-state-merge)
955 (if (ediff-valid-difference-p)
957 buf-C-state-diff (ediff-get-state-of-diff ediff-current-difference 'C)
958 buf-C-state-merge (ediff-get-state-of-merge ediff-current-difference)
959 buf-A-state-diff (ediff-get-state-of-diff ediff-current-difference 'A)
960 buf-B-state-diff (ediff-get-state-of-diff ediff-current-difference 'B)
961 buf-A-state-diff (if buf-A-state-diff
962 (format "[%s] " buf-A-state-diff)
964 buf-B-state-diff (if buf-B-state-diff
965 (format "[%s] " buf-B-state-diff)
967 buf-C-state-diff (if (and (ediff-buffer-live-p ediff-buffer-C)
968 (or buf-C-state-diff buf-C-state-merge))
970 (or buf-C-state-diff "")
971 (if buf-C-state-merge
972 (concat " " buf-C-state-merge)
975 (setq buf-A-state-diff ""
977 buf-C-state-diff ""))
979 ;; control buffer format
980 (setq mode-line-format
981 (list (if (ediff-narrow-control-frame-p) " " "-- ")
982 mode-line-buffer-identification
985 (setq mode-line-buffer-identification
986 (if (ediff-narrow-control-frame-p)
987 (ediff-make-narrow-control-buffer-id 'skip-name)
988 (ediff-make-wide-control-buffer-id)))
989 ;; Force mode-line redisplay
990 (force-mode-line-update)
992 (if (and window-system (ediff-frame-live-p ediff-control-frame))
993 (ediff-refresh-control-frame))
995 (ediff-eval-in-buffer ediff-buffer-A
996 (setq ediff-diff-status buf-A-state-diff)
997 (ediff-strip-mode-line-format)
998 (setq mode-line-format
999 (list " A: " 'ediff-diff-status mode-line-format))
1000 (force-mode-line-update))
1001 (ediff-eval-in-buffer ediff-buffer-B
1002 (setq ediff-diff-status buf-B-state-diff)
1003 (ediff-strip-mode-line-format)
1004 (setq mode-line-format
1005 (list " B: " 'ediff-diff-status mode-line-format))
1006 (force-mode-line-update))
1008 (ediff-eval-in-buffer ediff-buffer-C
1009 (setq ediff-diff-status buf-C-state-diff)
1010 (ediff-strip-mode-line-format)
1011 (setq mode-line-format
1012 (list " C: " 'ediff-diff-status mode-line-format))
1013 (force-mode-line-update)))
1017 (defun ediff-refresh-control-frame ()
1020 (setq screen-title-format (ediff-make-narrow-control-buffer-id)
1021 screen-icon-title-format (ediff-make-narrow-control-buffer-id))
1022 ;; this forces update of the screen title
1023 (ediff-modify-frame-parameters ediff-control-frame '(())))
1024 (ediff-modify-frame-parameters
1026 (list (cons 'name (ediff-make-narrow-control-buffer-id))))
1030 (defun ediff-make-narrow-control-buffer-id (&optional skip-name)
1035 (cdr (assoc 'name ediff-control-frame-parameters))
1036 ediff-control-buffer-suffix))
1037 (cond ((< ediff-current-difference 0)
1038 (format " _/%d" ediff-number-of-differences))
1039 ((>= ediff-current-difference ediff-number-of-differences)
1040 (format " $/%d" ediff-number-of-differences))
1043 (1+ ediff-current-difference)
1044 ediff-number-of-differences)))))
1046 (defun ediff-make-wide-control-buffer-id ()
1047 (cond ((< ediff-current-difference 0)
1048 (list (format "%%b At start of %d diffs"
1049 ediff-number-of-differences)))
1050 ((>= ediff-current-difference ediff-number-of-differences)
1051 (list (format "%%b At end of %d diffs"
1052 ediff-number-of-differences)))
1054 (list (format "%%b diff %d of %d"
1055 (1+ ediff-current-difference)
1056 ediff-number-of-differences)))))
1060 ;; If buff is not live, return nil
1061 (defun ediff-get-visible-buffer-window (buff)
1062 (if (ediff-buffer-live-p buff)
1064 (get-buffer-window buff t)
1065 (get-buffer-window buff 'visible))))
1067 ;;; Functions to decide when to redraw windows
1070 (defun ediff-keep-window-config (control-buf)
1071 (and (eq control-buf (current-buffer))
1072 (/= (buffer-size) 0)
1073 (ediff-eval-in-buffer control-buf
1074 (let ((ctl-wind ediff-control-window)
1075 (A-wind ediff-window-A)
1076 (B-wind ediff-window-B)
1077 (C-wind ediff-window-C))
1080 (ediff-window-visible-p A-wind)
1081 (ediff-window-visible-p B-wind)
1082 ;; if buffer C is defined then take it into account
1083 (or (not ediff-3way-job)
1084 (ediff-window-visible-p C-wind))
1085 (eq (window-buffer A-wind) ediff-buffer-A)
1086 (eq (window-buffer B-wind) ediff-buffer-B)
1087 (or (not ediff-3way-job)
1088 (eq (window-buffer C-wind) ediff-buffer-C))
1089 (string= ediff-window-config-saved
1090 (format "%S%S%S%S%S"
1091 ctl-wind A-wind B-wind C-wind
1092 ediff-split-window-function)))))))
1095 (provide 'ediff-wind)
1098 ;;; ediff-wind.el ends here