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