1 ;;; ediff-util.el --- the core commands and utilities of ediff
3 ;; Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 01 Free Software Foundation, Inc.
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
31 (defvar ediff-patch-diagnostics
)
32 (defvar ediff-patchbufer
)
33 (defvar ediff-use-toolbar-p
)
34 (defvar ediff-toolbar-height
)
35 (defvar ediff-toolbar
)
36 (defvar ediff-toolbar-3way
)
37 (defvar bottom-toolbar
)
38 (defvar bottom-toolbar-visible-p
)
39 (defvar bottom-toolbar-height
)
41 (defvar ediff-emacs-p
)
44 (let ((load-path (cons (expand-file-name ".") load-path
)))
45 (or (featurep 'ediff-init
)
46 (load "ediff-init.el" nil nil
'nosuffix
))
47 (or (featurep 'ediff-help
)
48 (load "ediff-help.el" nil nil
'nosuffix
))
49 (or (featurep 'ediff-mult
)
50 (load "ediff-mult.el" nil nil
'nosuffix
))
51 (or (featurep 'ediff-wind
)
52 (load "ediff-wind.el" nil nil
'nosuffix
))
53 (or (featurep 'ediff-diff
)
54 (load "ediff-diff.el" nil nil
'nosuffix
))
55 (or (featurep 'ediff-merg
)
56 (load "ediff-merg.el" nil nil
'nosuffix
))
58 (load "ediff.el" nil nil
'nosuffix
))
59 (or (featurep 'ediff-tbar
)
61 (load "ediff-tbar.el" 'noerror nil
'nosuffix
))
74 (require 'ediff-tbar
))
80 "Ediff mode controls all operations in a single Ediff session.
81 This mode is entered through one of the following commands:
92 `ediff-merge-files-with-ancestor'
94 `ediff-merge-buffers-with-ancestor'
95 `ediff-merge-revisions'
96 `ediff-merge-revisions-with-ancestor'
97 `ediff-windows-wordwise'
98 `ediff-windows-linewise'
99 `ediff-regions-wordwise'
100 `ediff-regions-linewise'
110 (kill-all-local-variables)
111 (setq major-mode
'ediff-mode
)
112 (setq mode-name
"Ediff")
113 (run-hooks 'ediff-mode-hook
))
119 (ediff-defvar-local ediff-mode-map nil
120 "Local keymap used in Ediff mode.
121 This is local to each Ediff Control Panel, so they may vary from invocation
124 ;; Set up the keymap in the control buffer
125 (defun ediff-set-keys ()
126 "Set up Ediff keymap, if necessary."
127 (if (null ediff-mode-map
)
128 (ediff-setup-keymap))
129 (use-local-map ediff-mode-map
))
131 ;; Reload Ediff keymap. For debugging only.
132 (defun ediff-reload-keymap ()
134 (setq ediff-mode-map nil
)
138 (defun ediff-setup-keymap ()
139 "Set up the keymap used in the control buffer of Ediff."
140 (setq ediff-mode-map
(make-sparse-keymap))
141 (suppress-keymap ediff-mode-map
)
143 (define-key ediff-mode-map
144 (if ediff-emacs-p
[mouse-2
] [button2]) 'ediff-help-for-quick-help)
145 (define-key ediff-mode-map "\C-m" 'ediff-help-for-quick-help)
147 (define-key ediff-mode-map "p" 'ediff-previous-difference)
148 (define-key ediff-mode-map "\C-?" 'ediff-previous-difference)
149 (define-key ediff-mode-map [delete] 'ediff-previous-difference)
150 (define-key ediff-mode-map "\C-h" (if ediff-no-emacs-help-in-control-buffer
151 'ediff-previous-difference nil))
152 ;; must come after C-h, or else C-h wipes out backspace's binding in XEmacs
153 (define-key ediff-mode-map [backspace] 'ediff-previous-difference)
154 (define-key ediff-mode-map "n" 'ediff-next-difference)
155 (define-key ediff-mode-map " " 'ediff-next-difference)
156 (define-key ediff-mode-map "j" 'ediff-jump-to-difference)
157 (define-key ediff-mode-map "g" nil)
158 (define-key ediff-mode-map "ga" 'ediff-jump-to-difference-at-point)
159 (define-key ediff-mode-map "gb" 'ediff-jump-to-difference-at-point)
160 (define-key ediff-mode-map "q" 'ediff-quit)
161 (define-key ediff-mode-map "D" 'ediff-show-diff-output)
162 (define-key ediff-mode-map "z" 'ediff-suspend)
163 (define-key ediff-mode-map "\C-l" 'ediff-recenter)
164 (define-key ediff-mode-map "|" 'ediff-toggle-split)
165 (define-key ediff-mode-map "h" 'ediff-toggle-hilit)
167 (define-key ediff-mode-map "@" 'ediff-toggle-autorefine))
169 (define-key ediff-mode-map "%" 'ediff-toggle-narrow-region))
170 (define-key ediff-mode-map "~" 'ediff-swap-buffers)
171 (define-key ediff-mode-map "v" 'ediff-scroll-vertically)
172 (define-key ediff-mode-map "\C-v" 'ediff-scroll-vertically)
173 (define-key ediff-mode-map "^" 'ediff-scroll-vertically)
174 (define-key ediff-mode-map "\M-v" 'ediff-scroll-vertically)
175 (define-key ediff-mode-map "V" 'ediff-scroll-vertically)
176 (define-key ediff-mode-map "<" 'ediff-scroll-horizontally)
177 (define-key ediff-mode-map ">" 'ediff-scroll-horizontally)
178 (define-key ediff-mode-map "i" 'ediff-status-info)
179 (define-key ediff-mode-map "E" 'ediff-documentation)
180 (define-key ediff-mode-map "?" 'ediff-toggle-help)
181 (define-key ediff-mode-map "!" 'ediff-update-diffs)
182 (define-key ediff-mode-map "M" 'ediff-show-current-session-meta-buffer)
183 (define-key ediff-mode-map "R" 'ediff-show-registry)
185 (define-key ediff-mode-map "*" 'ediff-make-or-kill-fine-diffs))
186 (define-key ediff-mode-map "a" nil)
187 (define-key ediff-mode-map "b" nil)
188 (define-key ediff-mode-map "r" nil)
189 (cond (ediff-merge-job
190 ;; Will barf if no ancestor
191 (define-key ediff-mode-map "/" 'ediff-show-ancestor)
192 ;; In merging, we allow only A->C and B->C copying.
193 (define-key ediff-mode-map "a" 'ediff-copy-A-to-C)
194 (define-key ediff-mode-map "b" 'ediff-copy-B-to-C)
195 (define-key ediff-mode-map "r" 'ediff-restore-diff-in-merge-buffer)
196 (define-key ediff-mode-map "s" 'ediff-shrink-window-C)
197 (define-key ediff-mode-map "+" 'ediff-combine-diffs)
198 (define-key ediff-mode-map "$" nil)
199 (define-key ediff-mode-map "$$" 'ediff-toggle-show-clashes-only)
200 (define-key ediff-mode-map "$*" 'ediff-toggle-skip-changed-regions)
201 (define-key ediff-mode-map "&" 'ediff-re-merge))
202 (ediff-3way-comparison-job
203 (define-key ediff-mode-map "ab" 'ediff-copy-A-to-B)
204 (define-key ediff-mode-map "ba" 'ediff-copy-B-to-A)
205 (define-key ediff-mode-map "ac" 'ediff-copy-A-to-C)
206 (define-key ediff-mode-map "bc" 'ediff-copy-B-to-C)
207 (define-key ediff-mode-map "c" nil)
208 (define-key ediff-mode-map "ca" 'ediff-copy-C-to-A)
209 (define-key ediff-mode-map "cb" 'ediff-copy-C-to-B)
210 (define-key ediff-mode-map "ra" 'ediff-restore-diff)
211 (define-key ediff-mode-map "rb" 'ediff-restore-diff)
212 (define-key ediff-mode-map "rc" 'ediff-restore-diff)
213 (define-key ediff-mode-map "C" 'ediff-toggle-read-only))
214 (t ; 2-way comparison
215 (define-key ediff-mode-map "a" 'ediff-copy-A-to-B)
216 (define-key ediff-mode-map "b" 'ediff-copy-B-to-A)
217 (define-key ediff-mode-map "ra" 'ediff-restore-diff)
218 (define-key ediff-mode-map "rb" 'ediff-restore-diff))
220 (define-key ediff-mode-map "G" 'ediff-submit-report)
221 (define-key ediff-mode-map "#" nil)
222 (define-key ediff-mode-map "#h" 'ediff-toggle-regexp-match)
223 (define-key ediff-mode-map "#f" 'ediff-toggle-regexp-match)
225 (define-key ediff-mode-map "##" 'ediff-toggle-skip-similar))
226 (define-key ediff-mode-map "o" nil)
227 (define-key ediff-mode-map "A" 'ediff-toggle-read-only)
228 (define-key ediff-mode-map "B" 'ediff-toggle-read-only)
229 (define-key ediff-mode-map "w" nil)
230 (define-key ediff-mode-map "wa" 'ediff-save-buffer)
231 (define-key ediff-mode-map "wb" 'ediff-save-buffer)
232 (define-key ediff-mode-map "wd" 'ediff-save-buffer)
233 (define-key ediff-mode-map "=" 'ediff-inferior-compare-regions)
234 (if (fboundp 'ediff-show-patch-diagnostics)
235 (define-key ediff-mode-map "P" 'ediff-show-patch-diagnostics))
238 (define-key ediff-mode-map "wc" 'ediff-save-buffer)
239 (define-key ediff-mode-map "gc" 'ediff-jump-to-difference-at-point)
242 (define-key ediff-mode-map "m" 'ediff-toggle-wide-display)
244 ;; Allow ediff-mode-map to be referenced indirectly
245 (fset 'ediff-mode-map ediff-mode-map)
246 (run-hooks 'ediff-keymap-setup-hook))
251 ;; Common startup entry for all Ediff functions It now returns control buffer
252 ;; so other functions can do post-processing SETUP-PARAMETERS is a list of the
253 ;; form ((param .val) (param . val)...) This serves a similar purpose to
254 ;; STARTUP-HOOKS, but these parameters are set in the new control buffer right
255 ;; after this buf is created and before any windows are set and such.
256 (defun ediff-setup (buffer-A file-A buffer-B file-B buffer-C file-C
257 startup-hooks setup-parameters
258 &optional merge-buffer-file)
259 (run-hooks 'ediff-before-setup-hook)
260 ;; ediff-convert-standard-filename puts file names in the form appropriate
261 ;; for the OS at hand.
262 (setq file-A (ediff-convert-standard-filename (expand-file-name file-A)))
263 (setq file-B (ediff-convert-standard-filename (expand-file-name file-B)))
266 (ediff-convert-standard-filename (expand-file-name file-C))))
267 (if (stringp merge-buffer-file)
269 (setq merge-buffer-file
270 (ediff-convert-standard-filename
271 (expand-file-name merge-buffer-file)))
272 ;; check the directory exists
273 (or (file-exists-p (file-name-directory merge-buffer-file))
274 (error "Directory %s given as place to save the merge doesn't exist"
275 (abbreviate-file-name
276 (file-name-directory merge-buffer-file))))
277 (if (and (file-exists-p merge-buffer-file)
278 (file-directory-p merge-buffer-file))
279 (error "The merge buffer file %s must not be a directory"
280 (abbreviate-file-name merge-buffer-file)))
282 (let* ((control-buffer-name
283 (ediff-unique-buffer-name "*Ediff Control Panel" "*"))
284 (control-buffer (ediff-with-current-buffer buffer-A
285 (get-buffer-create control-buffer-name))))
286 (ediff-with-current-buffer control-buffer
289 (make-local-variable 'ediff-use-long-help-message)
290 (make-local-variable 'ediff-prefer-iconified-control-frame)
291 (make-local-variable 'ediff-split-window-function)
292 (make-local-variable 'ediff-default-variant)
293 (make-local-variable 'ediff-merge-window-share)
294 (make-local-variable 'ediff-window-setup-function)
295 (make-local-variable 'ediff-keep-variants)
297 (make-local-hook 'ediff-after-quit-hook-internal)
299 ;; unwrap set up parameters passed as argument
300 (while setup-parameters
301 (set (car (car setup-parameters)) (cdr (car setup-parameters)))
302 (setq setup-parameters (cdr setup-parameters)))
304 ;; set variables classifying the current ediff job
305 ;; must come AFTER setup-parameters
306 (setq ediff-3way-comparison-job (ediff-3way-comparison-job)
307 ediff-merge-job (ediff-merge-job)
308 ediff-merge-with-ancestor-job (ediff-merge-with-ancestor-job)
309 ediff-3way-job (ediff-3way-job)
310 ediff-diff3-job (ediff-diff3-job)
311 ediff-narrow-job (ediff-narrow-job)
312 ediff-windows-job (ediff-windows-job)
313 ediff-word-mode-job (ediff-word-mode-job))
315 ;; Don't delete variants in case of ediff-buffer-* jobs without asking.
316 ;; This is because u may loose work---dangerous.
317 (if (string-match "buffer" (symbol-name ediff-job-name))
318 (setq ediff-keep-variants t))
320 (make-local-hook 'pre-command-hook)
321 (if (ediff-window-display-p)
322 (add-hook 'pre-command-hook 'ediff-spy-after-mouse nil t))
323 (setq ediff-mouse-pixel-position (mouse-pixel-position))
325 ;; adjust for merge jobs
328 ;; If default variant is `combined', the right stuff is
329 ;; inserted by ediff-do-merge
330 ;; Note: at some point, we tried to put ancestor buffer here
331 ;; (which is currently buffer C. This didn't work right
332 ;; because the merge buffer will contain lossage: diff regions
333 ;; in the ancestor, which correspond to revisions that agree
334 ;; in both buf A and B.
335 (cond ((eq ediff-default-variant 'default-B)
339 (setq ediff-split-window-function
340 ediff-merge-split-window-function)
342 ;; remember the ancestor buffer, if any
343 (setq ediff-ancestor-buffer buffer-C)
347 (ediff-unique-buffer-name "*ediff-merge" "*")))
349 (set-buffer buffer-C)
351 (funcall (ediff-with-current-buffer buf major-mode))
352 (add-hook 'local-write-file-hooks 'ediff-set-merge-mode nil t)
354 (setq buffer-read-only nil
355 ediff-buffer-A buffer-A
356 ediff-buffer-B buffer-B
357 ediff-buffer-C buffer-C
358 ediff-control-buffer control-buffer)
360 (ediff-choose-syntax-table)
362 (setq ediff-control-buffer-suffix
363 (if (string-match "<[0-9]*>" control-buffer-name)
364 (substring control-buffer-name
365 (match-beginning 0) (match-end 0))
367 ediff-control-buffer-number
373 ediff-control-buffer-suffix
375 (string-match "[0-9]+" ediff-control-buffer-suffix)
378 (setq ediff-error-buffer
379 (get-buffer-create (ediff-unique-buffer-name "*ediff-errors" "*")))
381 (ediff-with-current-buffer buffer-A (ediff-strip-mode-line-format))
382 (ediff-with-current-buffer buffer-B (ediff-strip-mode-line-format))
384 (ediff-with-current-buffer buffer-C (ediff-strip-mode-line-format)))
385 (if (ediff-buffer-live-p ediff-ancestor-buffer)
386 (ediff-with-current-buffer ediff-ancestor-buffer
387 (ediff-strip-mode-line-format)))
389 (ediff-save-protected-variables) ; save variables to be restored on exit
391 ;; ediff-setup-diff-regions-function must be set after setup
392 ;; parameters are processed.
393 (setq ediff-setup-diff-regions-function
395 'ediff-setup-diff-regions3
396 'ediff-setup-diff-regions))
398 (setq ediff-wide-bounds
399 (list (ediff-make-bullet-proof-overlay
400 '(point-min) '(point-max) ediff-buffer-A)
401 (ediff-make-bullet-proof-overlay
402 '(point-min) '(point-max) ediff-buffer-B)
403 (ediff-make-bullet-proof-overlay
404 '(point-min) '(point-max) ediff-buffer-C)))
406 ;; This has effect only on ediff-windows/regions
407 ;; In all other cases, ediff-visible-region sets visibility bounds to
408 ;; ediff-wide-bounds, and ediff-narrow-bounds are ignored.
409 (if ediff-start-narrowed
410 (setq ediff-visible-bounds ediff-narrow-bounds)
411 (setq ediff-visible-bounds ediff-wide-bounds))
413 (ediff-set-keys) ; comes after parameter setup
415 ;; set up ediff-narrow-bounds, if not set
416 (or ediff-narrow-bounds
417 (setq ediff-narrow-bounds ediff-wide-bounds))
419 ;; All these must be inside ediff-with-current-buffer control-buffer,
420 ;; since these vars are local to control-buffer
421 ;; These won't run if there are errors in diff
422 (ediff-with-current-buffer ediff-buffer-A
423 (ediff-nuke-selective-display)
424 (run-hooks 'ediff-prepare-buffer-hook)
425 (if (ediff-with-current-buffer control-buffer ediff-merge-job)
426 (setq buffer-read-only t))
427 ;; add control-buffer to the list of sessions--no longer used, but may
428 ;; be used again in the future
429 (or (memq control-buffer ediff-this-buffer-ediff-sessions)
430 (setq ediff-this-buffer-ediff-sessions
431 (cons control-buffer ediff-this-buffer-ediff-sessions)))
432 (if ediff-make-buffers-readonly-at-startup
433 (setq buffer-read-only t))
436 (ediff-with-current-buffer ediff-buffer-B
437 (ediff-nuke-selective-display)
438 (run-hooks 'ediff-prepare-buffer-hook)
439 (if (ediff-with-current-buffer control-buffer ediff-merge-job)
440 (setq buffer-read-only t))
441 ;; add control-buffer to the list of sessions
442 (or (memq control-buffer ediff-this-buffer-ediff-sessions)
443 (setq ediff-this-buffer-ediff-sessions
444 (cons control-buffer ediff-this-buffer-ediff-sessions)))
445 (if ediff-make-buffers-readonly-at-startup
446 (setq buffer-read-only t))
450 (ediff-with-current-buffer ediff-buffer-C
451 (ediff-nuke-selective-display)
452 (run-hooks 'ediff-prepare-buffer-hook)
453 ;; add control-buffer to the list of sessions
454 (or (memq control-buffer ediff-this-buffer-ediff-sessions)
455 (setq ediff-this-buffer-ediff-sessions
457 ediff-this-buffer-ediff-sessions)))
458 (if ediff-make-buffers-readonly-at-startup
459 (setq buffer-read-only t))
462 (if (ediff-buffer-live-p ediff-ancestor-buffer)
463 (ediff-with-current-buffer ediff-ancestor-buffer
464 (ediff-nuke-selective-display)
465 (setq buffer-read-only t)
466 (run-hooks 'ediff-prepare-buffer-hook)
467 (or (memq control-buffer ediff-this-buffer-ediff-sessions)
468 (setq ediff-this-buffer-ediff-sessions
470 ediff-this-buffer-ediff-sessions)))
473 ;; must come after setting up ediff-narrow-bounds AND after
474 ;; nuking selective display
475 (funcall ediff-setup-diff-regions-function file-A file-B file-C)
476 (setq ediff-number-of-differences (length ediff-difference-vector-A))
477 (setq ediff-current-difference -1)
479 (ediff-make-current-diff-overlay 'A)
480 (ediff-make-current-diff-overlay 'B)
482 (ediff-make-current-diff-overlay 'C))
483 (if ediff-merge-with-ancestor-job
484 (ediff-make-current-diff-overlay 'Ancestor))
486 (ediff-setup-windows buffer-A buffer-B buffer-C control-buffer)
488 (let ((shift-A (ediff-overlay-start
489 (ediff-get-value-according-to-buffer-type
490 'A ediff-narrow-bounds)))
491 (shift-B (ediff-overlay-start
492 (ediff-get-value-according-to-buffer-type
493 'B ediff-narrow-bounds)))
494 (shift-C (ediff-overlay-start
495 (ediff-get-value-according-to-buffer-type
496 'C ediff-narrow-bounds))))
497 ;; position point in buf A
499 (select-window ediff-window-A)
501 ;; position point in buf B
503 (select-window ediff-window-B)
507 (select-window ediff-window-C)
508 (goto-char shift-C)))
511 (select-window ediff-control-window)
512 (ediff-visible-region)
514 (run-hooks 'startup-hooks)
515 (ediff-arrange-autosave-in-merge-jobs merge-buffer-file)
517 (ediff-refresh-mode-lines)
518 (setq buffer-read-only t)
519 (setq ediff-session-registry
520 (cons control-buffer ediff-session-registry))
521 (ediff-update-registry)
522 (if (ediff-buffer-live-p ediff-meta-buffer)
523 (ediff-update-meta-buffer
524 ediff-meta-buffer nil ediff-meta-session-number))
525 (run-hooks 'ediff-startup-hook)
526 ) ; eval in control-buffer
530 ;; This function assumes that we are in the window where control buffer is
532 (defun ediff-setup-control-buffer (ctl-buf)
533 "Set up window for control buffer."
534 (if (window-dedicated-p (selected-window))
535 (set-buffer ctl-buf) ; we are in control frame but just in case
536 (switch-to-buffer ctl-buf))
537 (let ((window-min-height 2))
539 (ediff-set-help-message)
540 (insert ediff-help-message)
541 (shrink-window-if-larger-than-buffer)
542 (or (ediff-multiframe-setup-p)
543 (ediff-indent-help-message))
544 (ediff-set-help-overlays)
546 (set-buffer-modified-p nil)
547 (ediff-refresh-mode-lines)
548 (setq ediff-control-window (selected-window))
549 (setq ediff-window-config-saved
550 (format "%S%S%S%S%S%S%S"
555 ediff-split-window-function
556 (ediff-multiframe-setup-p)
557 ediff-wide-display-p))
559 ;; In multiframe, toolbar is set in ediff-setup-control-frame
560 (if (not (ediff-multiframe-setup-p))
561 (ediff-make-bottom-toolbar)) ; this checks if toolbar is requested
562 (goto-char (point-min))
563 (skip-chars-forward ediff-whitespace)))
565 ;; This executes in control buffer and sets auto-save, visited file name, etc,
566 ;; in the merge buffer
567 (defun ediff-arrange-autosave-in-merge-jobs (merge-buffer-file)
568 (if (not ediff-merge-job)
570 (if (stringp merge-buffer-file)
571 (setq ediff-autostore-merges t
572 ediff-merge-store-file merge-buffer-file))
573 (if (stringp ediff-merge-store-file)
575 ;; save before leaving ctl buffer
576 (setq merge-buffer-file ediff-merge-store-file)
577 (ediff-with-current-buffer ediff-buffer-C
578 (set-visited-file-name merge-buffer-file))))
579 (ediff-with-current-buffer ediff-buffer-C
580 (setq buffer-offer-save t) ; ask before killing buffer
581 ;; make sure the contents is auto-saved
586 ;;; Commands for working with Ediff
588 (defun ediff-update-diffs ()
589 "Recompute difference regions in buffers A, B, and C.
590 Buffers are not synchronized with their respective files, so changes done
591 to these buffers are not saved at this point---the user can do this later,
594 (ediff-barf-if-not-control-buffer)
595 (if (and (ediff-buffer-live-p ediff-ancestor-buffer)
598 "Ancestor buffer will not be used. Recompute diffs anyway? ")))
599 (error "Recomputation of differences canceled"))
601 (let ((point-A (ediff-with-current-buffer ediff-buffer-A (point)))
602 ;;(point-B (ediff-with-current-buffer ediff-buffer-B (point)))
603 (tmp-buffer (get-buffer-create ediff-tmp-buffer))
604 (buf-A-file-name (buffer-file-name ediff-buffer-A))
605 (buf-B-file-name (buffer-file-name ediff-buffer-B))
606 ;; (null ediff-buffer-C) is no problem, as we later check if
607 ;; ediff-buffer-C is alive
608 (buf-C-file-name (buffer-file-name ediff-buffer-C))
609 (overl-A (ediff-get-value-according-to-buffer-type
610 'A ediff-narrow-bounds))
611 (overl-B (ediff-get-value-according-to-buffer-type
612 'B ediff-narrow-bounds))
613 (overl-C (ediff-get-value-according-to-buffer-type
614 'C ediff-narrow-bounds))
615 beg-A end-A beg-B end-B beg-C end-C
616 file-A file-B file-C)
618 (if (stringp buf-A-file-name)
619 (setq buf-A-file-name (file-name-nondirectory buf-A-file-name)))
620 (if (stringp buf-B-file-name)
621 (setq buf-B-file-name (file-name-nondirectory buf-B-file-name)))
622 (if (stringp buf-C-file-name)
623 (setq buf-C-file-name (file-name-nondirectory buf-C-file-name)))
625 (ediff-unselect-and-select-difference -1)
627 (setq beg-A (ediff-overlay-start overl-A)
628 beg-B (ediff-overlay-start overl-B)
629 beg-C (ediff-overlay-start overl-C)
630 end-A (ediff-overlay-end overl-A)
631 end-B (ediff-overlay-end overl-B)
632 end-C (ediff-overlay-end overl-C))
636 (ediff-wordify beg-A end-A ediff-buffer-A tmp-buffer)
637 (setq file-A (ediff-make-temp-file tmp-buffer "regA"))
638 (ediff-wordify beg-B end-B ediff-buffer-B tmp-buffer)
639 (setq file-B (ediff-make-temp-file tmp-buffer "regB"))
642 (ediff-wordify beg-C end-C ediff-buffer-C tmp-buffer)
643 (setq file-C (ediff-make-temp-file tmp-buffer "regC"))))
646 (setq file-A (ediff-make-temp-file ediff-buffer-A buf-A-file-name))
647 (setq file-B (ediff-make-temp-file ediff-buffer-B buf-B-file-name))
649 (setq file-C (ediff-make-temp-file ediff-buffer-C buf-C-file-name)))
652 (ediff-clear-diff-vector 'ediff-difference-vector-A 'fine-diffs-also)
653 (ediff-clear-diff-vector 'ediff-difference-vector-B 'fine-diffs-also)
654 (ediff-clear-diff-vector 'ediff-difference-vector-C 'fine-diffs-also)
655 (ediff-clear-diff-vector
656 'ediff-difference-vector-Ancestor 'fine-diffs-also)
657 ;; let them garbage collect. we can't use the ancestor after recomputing
659 (setq ediff-difference-vector-Ancestor nil
660 ediff-ancestor-buffer nil
661 ediff-state-of-merge nil)
663 (setq ediff-killed-diffs-alist nil) ; invalidate saved killed diff regions
665 ;; In case of merge job, fool it into thinking that it is just doing
667 (let ((ediff-setup-diff-regions-function ediff-setup-diff-regions-function)
668 (ediff-3way-comparison-job ediff-3way-comparison-job)
669 (ediff-merge-job ediff-merge-job)
670 (ediff-merge-with-ancestor-job ediff-merge-with-ancestor-job)
671 (ediff-job-name ediff-job-name))
673 (setq ediff-setup-diff-regions-function 'ediff-setup-diff-regions3
674 ediff-3way-comparison-job t
676 ediff-merge-with-ancestor-job nil
677 ediff-job-name 'ediff-files3))
678 (funcall ediff-setup-diff-regions-function file-A file-B file-C))
680 (setq ediff-number-of-differences (length ediff-difference-vector-A))
684 (delete-file file-C))
687 (ediff-set-state-of-all-diffs-in-all-buffers ediff-control-buffer))
689 (ediff-jump-to-difference (ediff-diff-at-point 'A point-A))
693 ;; Not bound to any key---to dangerous. A user can do it if necessary.
694 (defun ediff-revert-buffers-then-recompute-diffs (noconfirm)
695 "Revert buffers A, B and C. Then rerun Ediff on file A and file B."
697 (ediff-barf-if-not-control-buffer)
698 (let ((bufA ediff-buffer-A)
699 (bufB ediff-buffer-B)
700 (bufC ediff-buffer-C)
701 (ctl-buf ediff-control-buffer)
702 (keep-variants ediff-keep-variants)
703 (ancestor-buf ediff-ancestor-buffer)
704 (ancestor-job ediff-merge-with-ancestor-job)
705 (merge ediff-merge-job)
706 (comparison ediff-3way-comparison-job))
707 (ediff-with-current-buffer bufA
708 (revert-buffer t noconfirm))
709 (ediff-with-current-buffer bufB
710 (revert-buffer t noconfirm))
711 ;; this should only be executed in a 3way comparison, not in merge
713 (ediff-with-current-buffer bufC
714 (revert-buffer t noconfirm)))
718 ;; the argument says whether to reverse the meaning of
719 ;; ediff-keep-variants, i.e., ediff-really-quit runs here with
721 (ediff-really-quit (not keep-variants))
724 (ediff-merge-buffers-with-ancestor bufA bufB ancestor-buf)
725 (ediff-merge-buffers bufA bufB)))
726 (ediff-update-diffs))))
729 ;; optional NO-REHIGHLIGHT says to not rehighlight buffers
730 (defun ediff-recenter (&optional no-rehighlight)
731 "Bring the highlighted region of all buffers being compared into view.
732 Reestablish the default three-window display."
734 (ediff-barf-if-not-control-buffer)
735 (let (buffer-read-only)
736 (if (and (ediff-buffer-live-p ediff-buffer-A)
737 (ediff-buffer-live-p ediff-buffer-B)
738 (or (not ediff-3way-job)
739 (ediff-buffer-live-p ediff-buffer-C)))
741 ediff-buffer-A ediff-buffer-B ediff-buffer-C ediff-control-buffer)
742 (or (eq this-command 'ediff-quit)
743 (message ediff-KILLED-VITAL-BUFFER
747 ;; set visibility range appropriate to this invocation of Ediff.
748 (ediff-visible-region)
750 (if (and (ediff-window-display-p)
751 (symbolp this-command)
752 (symbolp last-command)
753 ;; Either one of the display-changing commands
754 (or (memq this-command
756 ediff-dir-action ediff-registry-action
758 ediff-toggle-wide-display ediff-toggle-multiframe))
759 ;; Or one of the movement cmds and prev cmd was an Ediff cmd
760 ;; This avoids raising frames unnecessarily.
761 (and (memq this-command
762 '(ediff-next-difference
763 ediff-previous-difference
764 ediff-jump-to-difference
765 ediff-jump-to-difference-at-point))
766 (not (string-match "^ediff-" (symbol-name last-command)))
769 (if (window-live-p ediff-window-A)
770 (raise-frame (window-frame ediff-window-A)))
771 (if (window-live-p ediff-window-B)
772 (raise-frame (window-frame ediff-window-B)))
773 (if (window-live-p ediff-window-C)
774 (raise-frame (window-frame ediff-window-C)))))
775 (if (and (ediff-window-display-p)
776 (frame-live-p ediff-control-frame)
777 (not ediff-use-long-help-message)
778 (not (ediff-frame-iconified-p ediff-control-frame)))
779 (raise-frame ediff-control-frame))
781 ;; Redisplay whatever buffers are showing, if there is a selected difference
782 (let ((control-frame ediff-control-frame)
783 (control-buf ediff-control-buffer))
784 (if (and (ediff-buffer-live-p ediff-buffer-A)
785 (ediff-buffer-live-p ediff-buffer-B)
786 (or (not ediff-3way-job)
787 (ediff-buffer-live-p ediff-buffer-C)))
790 (ediff-select-difference ediff-current-difference))
792 (ediff-recenter-one-window 'A)
793 (ediff-recenter-one-window 'B)
795 (ediff-recenter-one-window 'C))
797 (ediff-with-current-buffer control-buf
798 (ediff-recenter-ancestor) ; check if ancestor is alive
800 (if (and (ediff-multiframe-setup-p)
801 (not ediff-use-long-help-message)
802 (not (ediff-frame-iconified-p ediff-control-frame)))
803 ;; never grab mouse on quit in this place
806 (eq this-command 'ediff-quit))))
809 (ediff-restore-highlighting)
810 (ediff-with-current-buffer control-buf (ediff-refresh-mode-lines))
813 ;; this function returns to the window it was called from
814 ;; (which was the control window)
815 (defun ediff-recenter-one-window (buf-type)
816 (if (ediff-valid-difference-p)
817 ;; context must be saved before switching to windows A/B/C
818 (let* ((ctl-wind (selected-window))
819 (shift (ediff-overlay-start
820 (ediff-get-value-according-to-buffer-type
821 buf-type ediff-narrow-bounds)))
822 (job-name ediff-job-name)
823 (control-buf ediff-control-buffer)
824 (window-name (ediff-get-symbol-from-alist
825 buf-type ediff-window-alist))
826 (window (if (window-live-p (symbol-value window-name))
827 (symbol-value window-name))))
829 (if (and window ediff-windows-job)
830 (set-window-start window shift))
833 (select-window window)
834 (ediff-deactivate-mark)
835 (ediff-position-region
836 (ediff-get-diff-posn buf-type 'beg nil control-buf)
837 (ediff-get-diff-posn buf-type 'end nil control-buf)
838 (ediff-get-diff-posn buf-type 'beg nil control-buf)
841 (select-window ctl-wind)
844 (defun ediff-recenter-ancestor ()
845 ;; do half-hearted job by recentering the ancestor buffer, if it is alive and
847 (if (and (ediff-buffer-live-p ediff-ancestor-buffer)
848 (ediff-valid-difference-p))
849 (let ((window (ediff-get-visible-buffer-window ediff-ancestor-buffer))
850 (ctl-wind (selected-window))
851 (job-name ediff-job-name)
852 (ctl-buf ediff-control-buffer))
853 (ediff-with-current-buffer ediff-ancestor-buffer
854 (goto-char (ediff-get-diff-posn 'Ancestor 'beg nil ctl-buf))
857 (select-window window)
858 (ediff-position-region
859 (ediff-get-diff-posn 'Ancestor 'beg nil ctl-buf)
860 (ediff-get-diff-posn 'Ancestor 'end nil ctl-buf)
861 (ediff-get-diff-posn 'Ancestor 'beg nil ctl-buf)
863 (select-window ctl-wind)
867 ;; This will have to be refined for 3way jobs
868 (defun ediff-toggle-split ()
869 "Toggle vertical/horizontal window split.
870 Does nothing if file-A and file-B are in different frames."
872 (ediff-barf-if-not-control-buffer)
873 (let* ((wind-A (if (window-live-p ediff-window-A) ediff-window-A))
874 (wind-B (if (window-live-p ediff-window-B) ediff-window-B))
875 (wind-C (if (window-live-p ediff-window-C) ediff-window-C))
876 (frame-A (if wind-A (window-frame wind-A)))
877 (frame-B (if wind-B (window-frame wind-B)))
878 (frame-C (if wind-C (window-frame wind-C))))
879 (if (or (eq frame-A frame-B)
880 (not (frame-live-p frame-A))
881 (not (frame-live-p frame-B))
882 (if ediff-3way-comparison-job
883 (or (not (frame-live-p frame-C))
884 (eq frame-A frame-C) (eq frame-B frame-C))))
885 (setq ediff-split-window-function
886 (if (eq ediff-split-window-function 'split-window-vertically)
887 'split-window-horizontally
888 'split-window-vertically))
889 (message "Buffers being compared are in different frames"))
890 (ediff-recenter 'no-rehighlight)))
892 (defun ediff-toggle-hilit ()
893 "Switch between highlighting using ASCII flags and highlighting using faces.
894 On a dumb terminal, switches between ASCII highlighting and no highlighting."
896 (ediff-barf-if-not-control-buffer)
897 (if (not (ediff-has-face-support-p))
898 (if (eq ediff-highlighting-style 'ascii)
900 (message "ASCII highlighting flags removed")
901 (ediff-unselect-and-select-difference ediff-current-difference
903 (setq ediff-highlighting-style 'off))
904 (ediff-unselect-and-select-difference ediff-current-difference
906 (ediff-unselect-and-select-difference ediff-current-difference
908 ;; cycle through highlighting
909 (cond ((and ediff-use-faces ediff-highlight-all-diffs)
910 (message "Unhighlighting unselected difference regions")
911 (setq ediff-highlight-all-diffs nil))
913 (message "Highlighting with ASCII flags")
914 (setq ediff-use-faces nil))
916 (message "Re-highlighting all difference regions")
917 (setq ediff-use-faces t
918 ediff-highlight-all-diffs t)))
920 (if (and ediff-use-faces ediff-highlight-all-diffs)
921 (ediff-paint-background-regions)
922 (ediff-paint-background-regions 'unhighlight))
924 (ediff-unselect-and-select-difference
925 ediff-current-difference 'select-only))
929 (defun ediff-toggle-autorefine ()
930 "Toggle auto-refine mode."
932 (ediff-barf-if-not-control-buffer)
934 (error "No fine differences in this mode"))
935 (cond ((eq ediff-auto-refine 'nix)
936 (setq ediff-auto-refine 'on)
937 (ediff-make-fine-diffs ediff-current-difference 'noforce)
938 (message "Auto-refining is ON"))
939 ((eq ediff-auto-refine 'on)
940 (message "Auto-refining is OFF")
941 (setq ediff-auto-refine 'off))
943 (ediff-set-fine-diff-properties ediff-current-difference 'default)
944 (message "Refinements are HIDDEN")
945 (setq ediff-auto-refine 'nix))
948 (defun ediff-show-ancestor ()
949 "Show the ancestor buffer in a suitable window."
952 (or (ediff-buffer-live-p ediff-ancestor-buffer)
953 (if ediff-merge-with-ancestor-job
954 (error "Lost connection to ancestor buffer...sorry")
955 (error "Not merging with ancestor")))
957 (cond ((setq wind (ediff-get-visible-buffer-window ediff-ancestor-buffer))
958 (raise-frame (window-frame wind)))
959 (t (set-window-buffer ediff-window-C ediff-ancestor-buffer)))))
961 (defun ediff-make-or-kill-fine-diffs (arg)
962 "Compute fine diffs. With negative prefix arg, kill fine diffs.
963 In both cases, operates on the current difference region."
965 (ediff-barf-if-not-control-buffer)
967 (ediff-clear-fine-differences ediff-current-difference))
968 ((and (numberp arg) (< arg 0))
969 (ediff-clear-fine-differences ediff-current-difference))
970 (t (ediff-make-fine-diffs))))
973 (defun ediff-toggle-help ()
974 "Toggle short/long help message."
976 (ediff-barf-if-not-control-buffer)
977 (let (buffer-read-only)
979 (setq ediff-use-long-help-message (not ediff-use-long-help-message))
980 (ediff-set-help-message))
981 ;; remember the icon status of the control frame when the user requested
982 ;; full control message
983 (if (and ediff-use-long-help-message (ediff-multiframe-setup-p))
984 (setq ediff-prefer-iconified-control-frame
985 (ediff-frame-iconified-p ediff-control-frame)))
987 (setq ediff-window-config-saved "") ; force redisplay
988 (ediff-recenter 'no-rehighlight))
991 ;; If BUF, this is the buffer to toggle, not current buffer.
992 (defun ediff-toggle-read-only (&optional buf)
993 "Toggle read-only in current buffer.
994 If buffer is under version control and locked, check it out first.
995 If optional argument BUF is specified, toggle read-only in that buffer instead
996 of the current buffer."
998 (ediff-barf-if-not-control-buffer)
999 (let ((ctl-buf (if (null buf) (current-buffer)))
1000 (buf-type (ediff-char-to-buftype last-command-char)))
1001 (or buf (ediff-recenter))
1003 (setq buf (ediff-get-buffer buf-type)))
1005 (ediff-with-current-buffer buf ; eval in buf A/B/C
1006 (let* ((file (buffer-file-name buf))
1007 (file-writable (and file
1008 (file-exists-p file)
1009 (file-writable-p file)))
1010 (toggle-ro-cmd (cond (ediff-toggle-read-only-function)
1011 ((ediff-file-checked-out-p file)
1013 (file-writable 'toggle-read-only)
1014 (t (key-binding "\C-x\C-q")))))
1015 ;; If the file is checked in, make sure we don't make buffer modifiable
1016 ;; without warning the user. The user can fool our checks by making the
1017 ;; buffer non-RO without checking the file out. We regard this as a
1019 (if (and (ediff-file-checked-in-p file)
1020 ;; If ctl-buf is null, this means we called this
1021 ;; non-interactively, in which case don't ask questions
1023 (cond ((not buffer-read-only)
1024 (setq toggle-ro-cmd 'toggle-read-only))
1025 ((and (or (beep 1) t) ; always beep
1028 "File %s is under version control. Check it out? "
1029 (ediff-abbreviate-file-name file))))
1030 ;; if we checked the file out, we should also change the
1031 ;; original state of buffer-read-only to nil. If we don't
1032 ;; do this, the mode line will show %%, since the file was
1033 ;; RO before ediff started, so the user will think the file
1035 (ediff-with-current-buffer ctl-buf
1036 (ediff-change-saved-variable
1037 'buffer-read-only nil buf-type)))
1039 (setq toggle-ro-cmd 'toggle-read-only)
1042 "Boy, this is risky! Don't modify this file...")
1043 (sit-for 3)))) ; let the user see the warning
1044 (if (and toggle-ro-cmd
1045 (string-match "toggle-read-only" (symbol-name toggle-ro-cmd)))
1047 (save-window-excursion
1048 (select-window (ediff-get-visible-buffer-window buf))
1049 (command-execute toggle-ro-cmd)))
1050 (error "Don't know how to toggle read-only in buffer %S" buf))
1052 ;; Check if we made the current buffer updatable, but its file is RO.
1053 ;; Signal a warning in this case.
1054 (if (and file (not buffer-read-only)
1055 (eq this-command 'ediff-toggle-read-only)
1056 (file-exists-p file)
1057 (not (file-writable-p file)))
1058 (message "Warning: file %s is read-only"
1059 (ediff-abbreviate-file-name file) (beep 1)))
1062 ;; checkout if visited file is checked in
1063 (defun ediff-maybe-checkout (buf)
1064 (let ((file (expand-file-name (buffer-file-name buf)))
1065 (checkout-function (key-binding "\C-x\C-q")))
1066 (if (and (ediff-file-checked-in-p file)
1070 "File %s is under version control. Check it out? "
1071 (ediff-abbreviate-file-name file))))
1072 (ediff-with-current-buffer buf
1073 (command-execute checkout-function)))))
1076 ;; This is a simple-minded check for whether a file is under version control.
1077 ;; If file,v exists but file doesn't, this file is considered to be not checked
1078 ;; in and not checked out for the purpose of patching (since patch won't be
1079 ;; able to read such a file anyway).
1080 ;; FILE is a string representing file name
1081 ;;(defun ediff-file-under-version-control (file)
1082 ;; (let* ((filedir (file-name-directory file))
1083 ;; (file-nondir (file-name-nondirectory file))
1084 ;; (trial (concat file-nondir ",v"))
1085 ;; (full-trial (concat filedir trial))
1086 ;; (full-rcs-trial (concat filedir "RCS/" trial)))
1087 ;; (and (stringp file)
1088 ;; (file-exists-p file)
1091 ;; (file-exists-p full-trial)
1092 ;; ;; in FAT FS, `file,v' and `file' may turn out to be the same!
1093 ;; ;; don't be fooled by this!
1094 ;; (not (equal (file-attributes file)
1095 ;; (file-attributes full-trial))))
1096 ;; ;; check if a version is in RCS/ directory
1097 ;; (file-exists-p full-rcs-trial)))
1101 (defsubst ediff-file-checked-out-p (file)
1102 (or (not (featurep 'vc-hooks))
1103 (and (vc-backend file)
1104 (or (memq (vc-state file) '(edited needs-merge))
1105 (stringp (vc-state file))))))
1107 (defsubst ediff-file-checked-in-p (file)
1108 (and (featurep 'vc-hooks)
1109 ;; CVS files are considered not checked in
1110 (not (memq (vc-backend file) '(nil CVS)))
1111 (not (memq (vc-state file) '(edited needs-merge)))
1112 (not (stringp (vc-state file)))))
1114 (defun ediff-file-compressed-p (file)
1116 (require 'jka-compr)
1118 (if (featurep 'jka-compr)
1119 (string-match (jka-compr-build-file-regexp) file)))
1122 (defun ediff-swap-buffers ()
1123 "Rotate the display of buffers A, B, and C."
1125 (ediff-barf-if-not-control-buffer)
1126 (if (and (window-live-p ediff-window-A) (window-live-p ediff-window-B))
1127 (let ((buf ediff-buffer-A)
1128 (values ediff-buffer-values-orig-A)
1129 (diff-vec ediff-difference-vector-A)
1130 (hide-regexp ediff-regexp-hide-A)
1131 (focus-regexp ediff-regexp-focus-A)
1132 (wide-visibility-p (eq ediff-visible-bounds ediff-wide-bounds))
1133 (overlay (if (ediff-has-face-support-p)
1134 ediff-current-diff-overlay-A)))
1135 (if ediff-3way-comparison-job
1137 (set-window-buffer ediff-window-A ediff-buffer-C)
1138 (set-window-buffer ediff-window-B ediff-buffer-A)
1139 (set-window-buffer ediff-window-C ediff-buffer-B)
1141 (set-window-buffer ediff-window-A ediff-buffer-B)
1142 (set-window-buffer ediff-window-B ediff-buffer-A))
1143 ;; swap diff buffers
1144 (if ediff-3way-comparison-job
1145 (setq ediff-buffer-A ediff-buffer-C
1146 ediff-buffer-C ediff-buffer-B
1148 (setq ediff-buffer-A ediff-buffer-B
1149 ediff-buffer-B buf))
1151 ;; swap saved buffer characteristics
1152 (if ediff-3way-comparison-job
1153 (setq ediff-buffer-values-orig-A ediff-buffer-values-orig-C
1154 ediff-buffer-values-orig-C ediff-buffer-values-orig-B
1155 ediff-buffer-values-orig-B values)
1156 (setq ediff-buffer-values-orig-A ediff-buffer-values-orig-B
1157 ediff-buffer-values-orig-B values))
1159 ;; swap diff vectors
1160 (if ediff-3way-comparison-job
1161 (setq ediff-difference-vector-A ediff-difference-vector-C
1162 ediff-difference-vector-C ediff-difference-vector-B
1163 ediff-difference-vector-B diff-vec)
1164 (setq ediff-difference-vector-A ediff-difference-vector-B
1165 ediff-difference-vector-B diff-vec))
1167 ;; swap hide/focus regexp
1168 (if ediff-3way-comparison-job
1169 (setq ediff-regexp-hide-A ediff-regexp-hide-C
1170 ediff-regexp-hide-C ediff-regexp-hide-B
1171 ediff-regexp-hide-B hide-regexp
1172 ediff-regexp-focus-A ediff-regexp-focus-C
1173 ediff-regexp-focus-C ediff-regexp-focus-B
1174 ediff-regexp-focus-B focus-regexp)
1175 (setq ediff-regexp-hide-A ediff-regexp-hide-B
1176 ediff-regexp-hide-B hide-regexp
1177 ediff-regexp-focus-A ediff-regexp-focus-B
1178 ediff-regexp-focus-B focus-regexp))
1180 ;; The following is needed for XEmacs, since there one can't move
1181 ;; overlay to another buffer. In Emacs, this swap is redundant.
1182 (if (ediff-has-face-support-p)
1183 (if ediff-3way-comparison-job
1184 (setq ediff-current-diff-overlay-A ediff-current-diff-overlay-C
1185 ediff-current-diff-overlay-C ediff-current-diff-overlay-B
1186 ediff-current-diff-overlay-B overlay)
1187 (setq ediff-current-diff-overlay-A ediff-current-diff-overlay-B
1188 ediff-current-diff-overlay-B overlay)))
1191 (setq ediff-wide-bounds
1192 (cond (ediff-3way-comparison-job
1193 (list (nth 2 ediff-wide-bounds)
1194 (nth 0 ediff-wide-bounds)
1195 (nth 1 ediff-wide-bounds)))
1197 (list (nth 1 ediff-wide-bounds)
1198 (nth 0 ediff-wide-bounds)
1199 (nth 2 ediff-wide-bounds)))
1201 (list (nth 1 ediff-wide-bounds)
1202 (nth 0 ediff-wide-bounds)))))
1203 ;; swap narrow bounds
1204 (setq ediff-narrow-bounds
1205 (cond (ediff-3way-comparison-job
1206 (list (nth 2 ediff-narrow-bounds)
1207 (nth 0 ediff-narrow-bounds)
1208 (nth 1 ediff-narrow-bounds)))
1210 (list (nth 1 ediff-narrow-bounds)
1211 (nth 0 ediff-narrow-bounds)
1212 (nth 2 ediff-narrow-bounds)))
1214 (list (nth 1 ediff-narrow-bounds)
1215 (nth 0 ediff-narrow-bounds)))))
1216 (if wide-visibility-p
1217 (setq ediff-visible-bounds ediff-wide-bounds)
1218 (setq ediff-visible-bounds ediff-narrow-bounds))
1221 (ediff-set-state-of-all-diffs-in-all-buffers ediff-control-buffer))
1222 (ediff-recenter 'no-rehighlight)
1226 (defun ediff-toggle-wide-display ()
1227 "Toggle wide/regular display.
1228 This is especially useful when comparing buffers side-by-side."
1230 (ediff-barf-if-not-control-buffer)
1231 (or (ediff-window-display-p)
1232 (error "%sEmacs is not running as a window application"
1233 (if ediff-emacs-p "" "X")))
1234 (ediff-recenter 'no-rehighlight) ; make sure buffs are displayed in windows
1235 (let ((ctl-buf ediff-control-buffer))
1236 (setq ediff-wide-display-p (not ediff-wide-display-p))
1237 (if (not ediff-wide-display-p)
1238 (ediff-with-current-buffer ctl-buf
1239 (modify-frame-parameters
1240 ediff-wide-display-frame ediff-wide-display-orig-parameters)
1241 ;;(sit-for (if ediff-xemacs-p 0.4 0))
1242 ;; restore control buf, since ctl window may have been deleted
1244 (set-buffer ctl-buf)
1245 (setq ediff-wide-display-orig-parameters nil
1246 ediff-window-B nil) ; force update of window config
1247 (ediff-recenter 'no-rehighlight))
1248 (funcall ediff-make-wide-display-function)
1249 ;;(sit-for (if ediff-xemacs-p 0.4 0))
1250 (ediff-with-current-buffer ctl-buf
1251 (setq ediff-window-B nil) ; force update of window config
1252 (ediff-recenter 'no-rehighlight)))))
1255 (defun ediff-toggle-multiframe ()
1256 "Switch from multiframe display to single-frame display and back.
1257 To change the default, set the variable `ediff-window-setup-function',
1260 (let (window-setup-func)
1261 (or (ediff-window-display-p)
1262 (error "%sEmacs is not running as a window application"
1263 (if ediff-emacs-p "" "X")))
1265 (cond ((eq ediff-window-setup-function 'ediff-setup-windows-multiframe)
1266 (setq window-setup-func 'ediff-setup-windows-plain))
1267 ((eq ediff-window-setup-function 'ediff-setup-windows-plain)
1268 (if (ediff-in-control-buffer-p)
1269 (ediff-kill-bottom-toolbar))
1270 (setq window-setup-func 'ediff-setup-windows-multiframe)))
1273 (setq-default ediff-window-setup-function window-setup-func)
1274 ;; change in all active ediff sessions
1275 (mapcar (lambda(buf) (ediff-with-current-buffer buf
1276 (setq ediff-window-setup-function window-setup-func
1277 ediff-window-B nil)))
1278 ediff-session-registry)
1279 (if (ediff-in-control-buffer-p)
1280 (ediff-recenter 'no-rehighlight))))
1284 (defun ediff-toggle-use-toolbar ()
1285 "Enable or disable Ediff toolbar.
1286 Works only in versions of Emacs that support toolbars.
1287 To change the default, set the variable `ediff-use-toolbar-p', which see."
1289 (if (featurep 'ediff-tbar)
1291 (or (ediff-window-display-p)
1292 (error "%sEmacs is not running as a window application"
1293 (if ediff-emacs-p "" "X")))
1294 (if (ediff-use-toolbar-p)
1295 (ediff-kill-bottom-toolbar))
1296 ;; do this only after killing the toolbar
1297 (setq ediff-use-toolbar-p (not ediff-use-toolbar-p))
1299 (mapcar (lambda(buf)
1300 (ediff-with-current-buffer buf
1302 (setq ediff-window-config-saved "")
1304 ediff-session-registry)
1305 (if (ediff-in-control-buffer-p)
1306 (ediff-recenter 'no-rehighlight)))))
1309 ;; if was using toolbar, kill it
1310 (defun ediff-kill-bottom-toolbar ()
1311 ;; Using ctl-buffer or ediff-control-window for LOCALE does not
1312 ;; work properly in XEmacs 19.14: we have to use
1314 ;; The problem with this is that any previous bottom-toolbar
1315 ;; will not re-appear after our cleanup here. Is there a way
1316 ;; to do "push" and "pop" toolbars ? --marcpa
1317 (if (ediff-use-toolbar-p)
1319 (set-specifier bottom-toolbar (list (selected-frame) nil))
1320 (set-specifier bottom-toolbar-visible-p (list (selected-frame) nil)))))
1322 ;; If wants to use toolbar, make it.
1323 ;; If not, zero the toolbar for XEmacs.
1324 ;; Do nothing for Emacs.
1325 (defun ediff-make-bottom-toolbar (&optional frame)
1326 (if (ediff-window-display-p)
1328 (setq frame (or frame (selected-frame)))
1329 (cond ((ediff-use-toolbar-p) ; this checks for XEmacs
1332 (list frame (if (ediff-3way-comparison-job)
1333 ediff-toolbar-3way ediff-toolbar)))
1334 (set-specifier bottom-toolbar-visible-p (list frame t))
1335 (set-specifier bottom-toolbar-height
1336 (list frame ediff-toolbar-height)))
1337 ((ediff-has-toolbar-support-p)
1338 (set-specifier bottom-toolbar-height (list frame 0)))
1344 (defun ediff-toggle-show-clashes-only ()
1345 "Toggle the mode that shows only the merge regions where both variants differ from the ancestor."
1347 (ediff-barf-if-not-control-buffer)
1348 (if (not ediff-merge-with-ancestor-job)
1349 (error "This command makes sense only when merging with an ancestor"))
1350 (setq ediff-show-clashes-only (not ediff-show-clashes-only))
1351 (if ediff-show-clashes-only
1352 (message "Focus on regions where both buffers differ from the ancestor")
1353 (message "Canceling focus on regions where changes clash")))
1355 (defun ediff-toggle-skip-changed-regions ()
1356 "Toggle the mode that skips the merge regions that differ from the default."
1358 (ediff-barf-if-not-control-buffer)
1359 (setq ediff-skip-merge-regions-that-differ-from-default
1360 (not ediff-skip-merge-regions-that-differ-from-default))
1361 (if ediff-skip-merge-regions-that-differ-from-default
1362 (message "Skipping regions that differ from default setting")
1363 (message "Showing regions that differ from default setting")))
1367 ;; Widening/narrowing
1369 (defun ediff-toggle-narrow-region ()
1370 "Toggle narrowing in buffers A, B, and C.
1371 Used in ediff-windows/regions only."
1373 (if (eq ediff-buffer-A ediff-buffer-B)
1374 (error ediff-NO-DIFFERENCES))
1375 (if (eq ediff-visible-bounds ediff-wide-bounds)
1376 (setq ediff-visible-bounds ediff-narrow-bounds)
1377 (setq ediff-visible-bounds ediff-wide-bounds))
1378 (ediff-recenter 'no-rehighlight))
1380 ;; Narrow bufs A/B/C to ediff-visible-bounds. If this is currently set to
1381 ;; ediff-wide-bounds, then this actually widens.
1382 ;; This function does nothing if job-name is not
1383 ;; ediff-regions-wordwise/linewise or ediff-windows-wordwise/linewise.
1384 ;; Does nothing if buffer-A = buffer-B since we can't narrow
1385 ;; to two different regions in one buffer.
1386 (defun ediff-visible-region ()
1387 (if (or (eq ediff-buffer-A ediff-buffer-B)
1388 (eq ediff-buffer-A ediff-buffer-C)
1389 (eq ediff-buffer-C ediff-buffer-B))
1391 ;; If ediff-*-regions/windows, ediff-visible-bounds is already set
1392 ;; Otherwise, always use full range.
1393 (if (not ediff-narrow-job)
1394 (setq ediff-visible-bounds ediff-wide-bounds))
1395 (let ((overl-A (ediff-get-value-according-to-buffer-type
1396 'A ediff-visible-bounds))
1397 (overl-B (ediff-get-value-according-to-buffer-type
1398 'B ediff-visible-bounds))
1399 (overl-C (ediff-get-value-according-to-buffer-type
1400 'C ediff-visible-bounds))
1402 (ediff-with-current-buffer ediff-buffer-A
1403 (if (ediff-overlay-buffer overl-A)
1405 (ediff-overlay-start overl-A) (ediff-overlay-end overl-A))))
1406 (ediff-with-current-buffer ediff-buffer-B
1407 (if (ediff-overlay-buffer overl-B)
1409 (ediff-overlay-start overl-B) (ediff-overlay-end overl-B))))
1411 (if (and ediff-3way-job (ediff-overlay-buffer overl-C))
1412 (ediff-with-current-buffer ediff-buffer-C
1414 (ediff-overlay-start overl-C) (ediff-overlay-end overl-C))))
1418 ;; Window scrolling operations
1420 ;; Performs some operation on the two file windows (if they are showing).
1421 ;; Traps all errors on the operation in windows A/B/C.
1422 ;; Usually, errors come from scrolling off the
1423 ;; beginning or end of the buffer, and this gives error messages.
1424 (defun ediff-operate-on-windows (operation arg)
1426 ;; make sure windows aren't dead
1427 (if (not (and (window-live-p ediff-window-A) (window-live-p ediff-window-B)))
1428 (ediff-recenter 'no-rehighlight))
1429 (if (not (and (ediff-buffer-live-p ediff-buffer-A)
1430 (ediff-buffer-live-p ediff-buffer-B)
1431 (or (not ediff-3way-job) ediff-buffer-C)
1433 (error ediff-KILLED-VITAL-BUFFER))
1435 (let* ((wind (selected-window))
1436 (wind-A ediff-window-A)
1437 (wind-B ediff-window-B)
1438 (wind-C ediff-window-C)
1439 (coefA (ediff-get-region-size-coefficient 'A operation))
1440 (coefB (ediff-get-region-size-coefficient 'B operation))
1441 (three-way ediff-3way-job)
1442 (coefC (if three-way
1443 (ediff-get-region-size-coefficient 'C operation))))
1445 (select-window wind-A)
1447 (funcall operation (round (* coefA arg)))
1449 (select-window wind-B)
1451 (funcall operation (round (* coefB arg)))
1455 (select-window wind-C)
1457 (funcall operation (round (* coefC arg)))
1459 (select-window wind)))
1461 (defun ediff-scroll-vertically (&optional arg)
1462 "Vertically scroll buffers A, B \(and C if appropriate\).
1463 With optional argument ARG, scroll ARG lines; otherwise scroll by nearly
1464 the one half of the height of window-A."
1466 (ediff-barf-if-not-control-buffer)
1468 ;; make sure windows aren't dead
1469 (if (not (and (window-live-p ediff-window-A) (window-live-p ediff-window-B)))
1470 (ediff-recenter 'no-rehighlight))
1471 (if (not (and (ediff-buffer-live-p ediff-buffer-A)
1472 (ediff-buffer-live-p ediff-buffer-B)
1473 (or (not ediff-3way-job)
1474 (ediff-buffer-live-p ediff-buffer-C))
1476 (error ediff-KILLED-VITAL-BUFFER))
1478 (ediff-operate-on-windows
1479 (if (memq last-command-char '(?v ?\C-v))
1482 ;; calculate argument to scroll-up/down
1483 ;; if there is an explicit argument
1484 (if (and arg (not (equal arg '-)))
1486 (prefix-numeric-value arg)
1487 ;; if not, see if we can determine a default amount (the window height)
1488 (let (default-amount)
1489 (setq default-amount
1490 (- (/ (min (window-height ediff-window-A)
1491 (window-height ediff-window-B)
1493 (window-height ediff-window-C)
1494 500)) ; some large number
1496 1 next-screen-context-lines))
1499 ;; C-u as argument means half of default amount
1500 (/ default-amount 2)
1501 ;; no argument means default amount
1505 (defun ediff-scroll-horizontally (&optional arg)
1506 "Horizontally scroll buffers A, B \(and C if appropriate\).
1507 If an argument is given, that is how many columns are scrolled, else nearly
1508 the width of the A/B/C windows."
1510 (ediff-barf-if-not-control-buffer)
1512 ;; make sure windows aren't dead
1513 (if (not (and (window-live-p ediff-window-A) (window-live-p ediff-window-B)))
1514 (ediff-recenter 'no-rehighlight))
1515 (if (not (and (ediff-buffer-live-p ediff-buffer-A)
1516 (ediff-buffer-live-p ediff-buffer-B)
1517 (or (not ediff-3way-job)
1518 (ediff-buffer-live-p ediff-buffer-C))
1520 (error ediff-KILLED-VITAL-BUFFER))
1522 (ediff-operate-on-windows
1523 ;; Arrange for scroll-left and scroll-right being called
1524 ;; interactively so that they set the window's min_hscroll.
1525 ;; Otherwise, automatic hscrolling will undo the effect of
1527 (if (= last-command-char ?<)
1529 (let ((prefix-arg arg))
1530 (call-interactively 'scroll-left)))
1532 (let ((prefix-arg arg))
1533 (call-interactively 'scroll-right))))
1534 ;; calculate argument to scroll-left/right
1535 ;; if there is an explicit argument
1536 (if (and arg (not (equal arg '-)))
1538 (prefix-numeric-value arg)
1539 ;; if not, see if we can determine a default amount
1540 ;; (half the window width)
1541 (if (null ediff-control-window)
1542 ;; no control window, use nil
1544 (let ((default-amount
1545 (- (/ (min (window-width ediff-window-A)
1546 (window-width ediff-window-B)
1547 (if ediff-3way-comparison-job
1548 (window-width ediff-window-C)
1549 500) ; some large number
1555 ;; C-u as argument means half of default amount
1556 (/ default-amount 2)
1557 ;; no argument means default amount
1558 default-amount))))))
1561 ;;BEG, END show the region to be positioned.
1562 ;;JOB-NAME holds ediff-job-name. The ediff-windows job positions regions
1564 (defun ediff-position-region (beg end pos job-name)
1565 (if (> end (point-max))
1566 (setq end (point-max)))
1567 (if ediff-windows-job
1568 (if (pos-visible-in-window-p end)
1569 () ; do nothing, wind is already positioned
1570 ;; at this point, windows are positioned at the beginning of the
1571 ;; file regions (not diff-regions) being compared.
1573 (move-to-window-line (- (window-height) 2))
1574 (let ((amount (+ 2 (count-lines (point) end))))
1575 (scroll-up amount))))
1576 (set-window-start (selected-window) beg)
1577 (if (pos-visible-in-window-p end)
1578 ;; Determine the number of lines that the region occupies
1581 (while ( and (> end (progn
1582 (move-to-window-line lines)
1584 ;; `end' may be beyond the window bottom, so check
1585 ;; that we are making progress
1586 (< prev-point (point)))
1587 (setq prev-point (point))
1588 (setq lines (1+ lines)))
1589 ;; And position the beginning on the right line
1591 (recenter (/ (1+ (max (- (1- (window-height (selected-window)))
1599 ;; get number of lines from window start to region end
1600 (defun ediff-get-lines-to-region-end (buf-type &optional n ctl-buf)
1601 (or n (setq n ediff-current-difference))
1602 (or ctl-buf (setq ctl-buf ediff-control-buffer))
1603 (ediff-with-current-buffer ctl-buf
1604 (let* ((buf (ediff-get-buffer buf-type))
1605 (wind (eval (ediff-get-symbol-from-alist
1606 buf-type ediff-window-alist)))
1607 (beg (window-start wind))
1608 (end (ediff-get-diff-posn buf-type 'end))
1610 (ediff-with-current-buffer buf
1612 (setq lines (count-lines beg end))
1617 ;; Calculate the number of lines from window end to the start of diff region
1618 (defun ediff-get-lines-to-region-start (buf-type &optional diff-num ctl-buf)
1619 (or diff-num (setq diff-num ediff-current-difference))
1620 (or ctl-buf (setq ctl-buf ediff-control-buffer))
1621 (ediff-with-current-buffer ctl-buf
1622 (let* ((buf (ediff-get-buffer buf-type))
1623 (wind (eval (ediff-get-symbol-from-alist
1624 buf-type ediff-window-alist)))
1625 (end (or (window-end wind) (window-end wind t)))
1626 (beg (ediff-get-diff-posn buf-type 'beg diff-num)))
1627 (ediff-with-current-buffer buf
1629 (count-lines (max beg (point-min)) (min end (point-max))) 0))
1633 ;; region size coefficient is a coefficient by which to adjust scrolling
1634 ;; up/down of the window displaying buffer of type BUFTYPE.
1635 ;; The purpose of this coefficient is to make the windows scroll in sync, so
1636 ;; that it won't happen that one diff region is scrolled off while the other is
1639 ;; If the difference region is invalid, the coefficient is 1
1640 (defun ediff-get-region-size-coefficient (buf-type op &optional n ctl-buf)
1641 (ediff-with-current-buffer (or ctl-buf ediff-control-buffer)
1642 (if (ediff-valid-difference-p n)
1643 (let* ((func (cond ((eq op 'scroll-down)
1644 'ediff-get-lines-to-region-start)
1646 'ediff-get-lines-to-region-end)
1647 (t '(lambda (a b c) 0))))
1648 (max-lines (max (funcall func 'A n ctl-buf)
1649 (funcall func 'B n ctl-buf)
1650 (if (ediff-buffer-live-p ediff-buffer-C)
1651 (funcall func 'C n ctl-buf)
1653 ;; this covers the horizontal coefficient as well:
1654 ;; if max-lines = 0 then coef = 1
1656 (/ (+ (funcall func buf-type n ctl-buf) 0.0)
1662 (defun ediff-next-difference (&optional arg)
1663 "Advance to the next difference.
1664 With a prefix argument, go forward that many differences."
1666 (ediff-barf-if-not-control-buffer)
1667 (if (< ediff-current-difference ediff-number-of-differences)
1668 (let ((n (min ediff-number-of-differences
1669 (+ ediff-current-difference (or arg 1))))
1670 non-clash-skip skip-changed regexp-skip)
1672 (ediff-visible-region)
1673 (or (>= n ediff-number-of-differences)
1674 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
1675 ;; this won't exec if regexp-skip is t
1676 (setq non-clash-skip (ediff-merge-region-is-non-clash n)
1678 (ediff-skip-merge-region-if-changed-from-default-p n))
1679 (ediff-install-fine-diff-if-necessary n))
1681 (while (and (< n ediff-number-of-differences)
1685 ;; skip clashes, if necessary
1687 ;; skip processed regions
1689 ;; skip difference regions that differ in white space
1690 (and ediff-ignore-similar-regions
1691 (or (eq (ediff-no-fine-diffs-p n) t)
1692 (and (ediff-merge-job)
1693 (eq (ediff-no-fine-diffs-p n) 'C)))
1696 (if (= 0 (mod n 20))
1697 (message "Skipped over region %d and counting ..." n))
1698 (or (>= n ediff-number-of-differences)
1699 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
1700 ;; this won't exec if regexp-skip is t
1701 (setq non-clash-skip (ediff-merge-region-is-non-clash n)
1703 (ediff-skip-merge-region-if-changed-from-default-p n))
1704 (ediff-install-fine-diff-if-necessary n))
1707 (ediff-unselect-and-select-difference n)
1709 (ediff-visible-region)
1710 (error "At end of the difference list")))
1712 (defun ediff-previous-difference (&optional arg)
1713 "Go to the previous difference.
1714 With a prefix argument, go back that many differences."
1716 (ediff-barf-if-not-control-buffer)
1717 (if (> ediff-current-difference -1)
1718 (let ((n (max -1 (- ediff-current-difference (or arg 1))))
1719 non-clash-skip skip-changed regexp-skip)
1721 (ediff-visible-region)
1723 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
1724 ;; this won't exec if regexp-skip is t
1725 (setq non-clash-skip (ediff-merge-region-is-non-clash n)
1727 (ediff-skip-merge-region-if-changed-from-default-p n))
1728 (ediff-install-fine-diff-if-necessary n))
1729 (while (and (> n -1)
1733 ;; skip clashes, if necessary
1735 ;; skipp changed regions
1737 ;; skip difference regions that differ in white space
1738 (and ediff-ignore-similar-regions
1739 (or (eq (ediff-no-fine-diffs-p n) t)
1740 (and (ediff-merge-job)
1741 (eq (ediff-no-fine-diffs-p n) 'C)))
1743 (if (= 0 (mod (1+ n) 20))
1744 (message "Skipped over region %d and counting ..." (1+ n)))
1747 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
1748 ;; this won't exec if regexp-skip is t
1749 (setq non-clash-skip (ediff-merge-region-is-non-clash n)
1751 (ediff-skip-merge-region-if-changed-from-default-p n))
1752 (ediff-install-fine-diff-if-necessary n))
1755 (ediff-unselect-and-select-difference n)
1757 (ediff-visible-region)
1758 (error "At beginning of the difference list")))
1760 ;; The diff number is as perceived by the user (i.e., 1+ the internal
1762 (defun ediff-jump-to-difference (difference-number)
1763 "Go to the difference specified as a prefix argument.
1764 If the prefix is negative, count differences from the end."
1766 (ediff-barf-if-not-control-buffer)
1767 (setq difference-number
1768 (cond ((< difference-number 0)
1769 (+ ediff-number-of-differences difference-number))
1770 ((> difference-number 0) (1- difference-number))
1772 ;; -1 is allowed by ediff-unselect-and-select-difference --- it is the
1773 ;; position before the first one.
1774 (if (and (>= difference-number -1)
1775 (<= difference-number ediff-number-of-differences))
1776 (ediff-unselect-and-select-difference difference-number)
1777 (error ediff-BAD-DIFF-NUMBER
1778 this-command (1+ difference-number) ediff-number-of-differences)))
1780 (defun ediff-jump-to-difference-at-point (arg)
1781 "Go to difference closest to the point in buffer A, B, or C.
1782 The buffer depends on last command character \(a, b, or c\) that invoked this
1783 command. For instance, if the command was `ga' then the point value in buffer
1785 With a prefix argument, synchronize all files around the current point position
1786 in the specified buffer."
1788 (ediff-barf-if-not-control-buffer)
1789 (let* ((buf-type (ediff-char-to-buftype last-command-char))
1790 (buffer (ediff-get-buffer buf-type))
1791 (pt (ediff-with-current-buffer buffer (point)))
1792 (diff-no (ediff-diff-at-point buf-type nil (if arg 'after)))
1793 (past-last-diff (< ediff-number-of-differences diff-no))
1794 (beg (if past-last-diff
1795 (ediff-with-current-buffer buffer (point-max))
1796 (ediff-get-diff-posn buf-type 'beg (1- diff-no))))
1797 ctl-wind wind-A wind-B wind-C
1800 (ediff-jump-to-difference -1)
1801 (ediff-jump-to-difference diff-no))
1802 (setq ctl-wind (selected-window)
1803 wind-A ediff-window-A
1804 wind-B ediff-window-B
1805 wind-C ediff-window-C)
1808 (ediff-with-current-buffer buffer
1809 (setq shift (- beg pt)))
1810 (select-window wind-A)
1811 (if past-last-diff (goto-char (point-max)))
1813 (backward-char shift) ; noerror, if beginning of buffer
1816 (select-window wind-B)
1817 (if past-last-diff (goto-char (point-max)))
1819 (backward-char shift) ; noerror, if beginning of buffer
1822 (if (window-live-p wind-C)
1824 (select-window wind-C)
1825 (if past-last-diff (goto-char (point-max)))
1827 (backward-char shift) ; noerror, if beginning of buffer
1831 (select-window ctl-wind)
1836 ;; find region most related to the current point position (or POS, if given)
1837 ;; returns diff number as seen by the user (i.e., 1+ the internal
1839 ;; The optional argument WHICH-DIFF can be `after' or `before'. If `after',
1840 ;; find the diff after the point. If `before', find the diff before the
1841 ;; point. If the point is inside a diff, return that diff.
1842 (defun ediff-diff-at-point (buf-type &optional pos which-diff)
1843 (let ((buffer (ediff-get-buffer buf-type))
1844 (ctl-buffer ediff-control-buffer)
1845 (max-dif-num (1- ediff-number-of-differences))
1852 (ediff-with-current-buffer buffer
1853 (setq pos (or pos (point)))
1854 (while (and (or (< pos prev-beg) (> pos beg))
1855 (< diff-no max-dif-num))
1856 (setq diff-no (1+ diff-no))
1859 (setq beg (ediff-get-diff-posn buf-type 'beg diff-no ctl-buffer)
1860 end (ediff-get-diff-posn buf-type 'end diff-no ctl-buffer))
1863 ;; boost diff-no by 1, if past the last diff region
1864 (if (and (memq which-diff '(after before))
1865 (> pos beg) (= diff-no max-dif-num))
1866 (setq diff-no (1+ diff-no)))
1868 (cond ((eq which-diff 'after) (1+ diff-no))
1869 ((eq which-diff 'before) diff-no)
1870 ((< (abs (count-lines pos (max 1 prev-end)))
1871 (abs (count-lines pos (max 1 beg))))
1872 diff-no) ; choose prev difference
1874 (1+ diff-no))) ; choose next difference
1880 (defun ediff-diff-to-diff (arg &optional keys)
1881 "Copy buffer-X'th difference region to buffer Y \(X,Y are A, B, or C\).
1882 If numerical prefix argument, copy the difference specified in the arg.
1883 Otherwise, copy the difference given by `ediff-current-difference'.
1884 This command assumes it is bound to a 2-character key sequence, `ab', `ba',
1885 `ac', etc., which is used to determine the types of buffers to be used for
1886 copying difference regions. The first character in the sequence specifies
1887 the source buffer and the second specifies the target.
1889 If the second optional argument, a 2-character string, is given, use it to
1890 determine the source and the target buffers instead of the command keys."
1892 (ediff-barf-if-not-control-buffer)
1893 (or keys (setq keys (this-command-keys)))
1894 (if (eq arg '-) (setq arg -1)) ; translate neg arg to -1
1895 (if (numberp arg) (ediff-jump-to-difference arg))
1897 (let* ((key1 (aref keys 0))
1898 (key2 (aref keys 1))
1899 (char1 (if (and ediff-xemacs-p (eventp key1)) (event-key key1) key1))
1900 (char2 (if (and ediff-xemacs-p (eventp key1)) (event-key key2) key2))
1902 (ediff-copy-diff ediff-current-difference
1903 (ediff-char-to-buftype char1)
1904 (ediff-char-to-buftype char2))
1905 ;; recenter with rehighlighting, but no messages
1908 (defun ediff-copy-A-to-B (arg)
1909 "Copy ARGth difference region from buffer A to B.
1910 ARG is a prefix argument. If nil, copy the current difference region."
1912 (ediff-diff-to-diff arg "ab"))
1914 (defun ediff-copy-B-to-A (arg)
1915 "Copy ARGth difference region from buffer B to A.
1916 ARG is a prefix argument. If nil, copy the current difference region."
1918 (ediff-diff-to-diff arg "ba"))
1920 (defun ediff-copy-A-to-C (arg)
1921 "Copy ARGth difference region from buffer A to buffer C.
1922 ARG is a prefix argument. If nil, copy the current difference region."
1924 (ediff-diff-to-diff arg "ac"))
1926 (defun ediff-copy-B-to-C (arg)
1927 "Copy ARGth difference region from buffer B to buffer C.
1928 ARG is a prefix argument. If nil, copy the current difference region."
1930 (ediff-diff-to-diff arg "bc"))
1932 (defun ediff-copy-C-to-B (arg)
1933 "Copy ARGth difference region from buffer C to B.
1934 ARG is a prefix argument. If nil, copy the current difference region."
1936 (ediff-diff-to-diff arg "cb"))
1938 (defun ediff-copy-C-to-A (arg)
1939 "Copy ARGth difference region from buffer C to A.
1940 ARG is a prefix argument. If nil, copy the current difference region."
1942 (ediff-diff-to-diff arg "ca"))
1946 ;; Copy diff N from FROM-BUF-TYPE \(given as A, B or C\) to TO-BUF-TYPE.
1947 ;; If optional DO-NOT-SAVE is non-nil, do not save the old value of the
1948 ;; target diff. This is used in merging, when constructing the merged
1950 (defun ediff-copy-diff (n from-buf-type to-buf-type
1951 &optional batch-invocation reg-to-copy)
1952 (let* ((to-buf (ediff-get-buffer to-buf-type))
1953 ;;(from-buf (if (not reg-to-copy) (ediff-get-buffer from-buf-type)))
1954 (ctrl-buf ediff-control-buffer)
1956 (three-way ediff-3way-job)
1959 reg-to-delete reg-to-delete-beg reg-to-delete-end)
1961 (setq reg-to-delete-beg
1962 (ediff-get-diff-posn to-buf-type 'beg n ctrl-buf))
1963 (setq reg-to-delete-end
1964 (ediff-get-diff-posn to-buf-type 'end n ctrl-buf))
1967 (setq from-buf-type nil)
1968 (setq reg-to-copy (ediff-get-region-contents n from-buf-type ctrl-buf)))
1970 (setq reg-to-delete (ediff-get-region-contents
1971 n to-buf-type ctrl-buf
1972 reg-to-delete-beg reg-to-delete-end))
1974 (if (string= reg-to-delete reg-to-copy)
1975 (setq saved-p nil) ; don't copy identical buffers
1977 (if (or batch-invocation (ediff-test-save-region n to-buf-type))
1978 (condition-case conds
1980 (ediff-with-current-buffer to-buf
1981 ;; to prevent flags from interfering if buffer is writable
1982 (let ((inhibit-read-only (null buffer-read-only)))
1984 (goto-char reg-to-delete-end)
1985 (insert reg-to-copy)
1987 (if (> reg-to-delete-end reg-to-delete-beg)
1988 (kill-region reg-to-delete-beg reg-to-delete-end))
1990 (or batch-invocation
1993 (ediff-save-diff-region n to-buf-type reg-to-delete))))
1994 (error (message "ediff-copy-diff: %s %s"
1996 (mapconcat 'prin1-to-string (cdr conds) " "))
1998 (sit-for 2) ; let the user see the error msg
2003 ;; adjust state of difference in case 3-way and diff was copied ok
2004 (if (and saved-p three-way)
2005 (ediff-set-state-of-diff-in-all-buffers n ctrl-buf))
2007 (if batch-invocation
2008 (ediff-clear-fine-differences n)
2009 ;; If diff3 job, we should recompute fine diffs so we clear them
2010 ;; before reinserting flags (and thus before ediff-recenter).
2011 (if (and saved-p three-way)
2012 (ediff-clear-fine-differences n))
2014 (ediff-refresh-mode-lines)
2016 ;; For diff2 jobs, don't recompute fine diffs, since we know there
2017 ;; aren't any. So we clear diffs after ediff-recenter.
2018 (if (and saved-p (not three-way))
2019 (ediff-clear-fine-differences n))
2020 ;; Make sure that the message about saving and how to restore is seen
2025 ;; Save Nth diff of buffer BUF-TYPE \(A, B, or C\).
2026 ;; That is to say, the Nth diff on the `ediff-killed-diffs-alist'. REG
2027 ;; is the region to save. It is redundant here, but is passed anyway, for
2029 (defun ediff-save-diff-region (n buf-type reg)
2030 (let* ((n-th-diff-saved (assoc n ediff-killed-diffs-alist))
2031 (buf (ediff-get-buffer buf-type))
2032 (this-buf-n-th-diff-saved (assoc buf (cdr n-th-diff-saved))))
2034 (if this-buf-n-th-diff-saved
2035 ;; either nothing saved for n-th diff and buffer or we OK'ed
2037 (setcdr this-buf-n-th-diff-saved reg)
2038 (if n-th-diff-saved ;; n-th diff saved, but for another buffer
2039 (nconc n-th-diff-saved (list (cons buf reg)))
2040 (setq ediff-killed-diffs-alist ;; create record for n-th diff
2041 (cons (list n (cons buf reg))
2042 ediff-killed-diffs-alist))))
2043 (message "Saving old diff region #%d of buffer %S. To recover, type `r%s'"
2046 "" (downcase (symbol-name buf-type))))
2049 ;; Test if saving Nth difference region of buffer BUF-TYPE is possible.
2050 (defun ediff-test-save-region (n buf-type)
2051 (let* ((n-th-diff-saved (assoc n ediff-killed-diffs-alist))
2052 (buf (ediff-get-buffer buf-type))
2053 (this-buf-n-th-diff-saved (assoc buf (cdr n-th-diff-saved))))
2055 (if this-buf-n-th-diff-saved
2058 "You've previously copied diff region %d to buffer %S. Confirm "
2064 (defun ediff-pop-diff (n buf-type)
2065 "Pop last killed Nth diff region from buffer BUF-TYPE."
2066 (let* ((n-th-record (assoc n ediff-killed-diffs-alist))
2067 (buf (ediff-get-buffer buf-type))
2068 (saved-rec (assoc buf (cdr n-th-record)))
2069 (three-way ediff-3way-job)
2070 (ctl-buf ediff-control-buffer)
2072 saved-diff reg-beg reg-end recovered)
2075 (setq saved-diff (cdr saved-rec))
2076 (if (> ediff-number-of-differences 0)
2077 (error "Nothing saved for diff %d in buffer %S" (1+ n) buf-type)
2078 (error ediff-NO-DIFFERENCES)))
2080 (setq reg-beg (ediff-get-diff-posn buf-type 'beg n ediff-control-buffer))
2081 (setq reg-end (ediff-get-diff-posn buf-type 'end n ediff-control-buffer))
2083 (condition-case conds
2084 (ediff-with-current-buffer buf
2085 (let ((inhibit-read-only (null buffer-read-only)))
2090 (if (> reg-end reg-beg)
2091 (kill-region reg-beg reg-end))
2095 (error (message "ediff-pop-diff: %s %s"
2097 (mapconcat 'prin1-to-string (cdr conds) " "))
2100 ;; Clearing fine diffs is necessary for
2101 ;; ediff-unselect-and-select-difference to properly recompute them. We
2102 ;; can't rely on ediff-copy-diff to clear this vector, as the user might
2103 ;; have modified diff regions after copying and, thus, may have recomputed
2106 (ediff-clear-fine-differences n))
2108 ;; adjust state of difference
2109 (if (and three-way recovered)
2110 (ediff-set-state-of-diff-in-all-buffers n ctl-buf))
2112 (ediff-refresh-mode-lines)
2116 (setq n-th-record (delq saved-rec n-th-record))
2117 (message "Diff region %d in buffer %S restored" (1+ n) buf-type)
2121 (defun ediff-restore-diff (arg &optional key)
2122 "Restore ARGth diff from `ediff-killed-diffs-alist'.
2123 ARG is a prefix argument. If ARG is nil, restore the current-difference.
2124 If the second optional argument, a character, is given, use it to
2125 determine the target buffer instead of last-command-char"
2127 (ediff-barf-if-not-control-buffer)
2129 (ediff-jump-to-difference arg))
2130 (ediff-pop-diff ediff-current-difference
2131 (ediff-char-to-buftype (or key last-command-char)))
2132 ;; recenter with rehighlighting, but no messages
2133 (let (ediff-verbose-p)
2136 (defun ediff-restore-diff-in-merge-buffer (arg)
2137 "Restore ARGth diff in the merge buffer.
2138 ARG is a prefix argument. If nil, restore the current diff."
2140 (ediff-restore-diff arg ?c))
2143 (defun ediff-toggle-regexp-match ()
2144 "Toggle between focusing and hiding of difference regions that match
2145 a regular expression typed in by the user."
2147 (ediff-barf-if-not-control-buffer)
2151 msg-connective alt-msg-connective alt-connective)
2153 ((or (and (eq ediff-skip-diff-region-function
2154 ediff-focus-on-regexp-matches-function)
2155 (eq last-command-char ?f))
2156 (and (eq ediff-skip-diff-region-function
2157 ediff-hide-regexp-matches-function)
2158 (eq last-command-char ?h)))
2159 (message "Selective browsing by regexp turned off")
2160 (setq ediff-skip-diff-region-function 'ediff-show-all-diffs))
2161 ((eq last-command-char ?h)
2162 (setq ediff-skip-diff-region-function ediff-hide-regexp-matches-function
2166 "Ignore A-regions matching this regexp (default \"%s\"): "
2167 ediff-regexp-hide-A))
2171 "Ignore B-regions matching this regexp (default \"%s\"): "
2172 ediff-regexp-hide-B)))
2173 (if ediff-3way-comparison-job
2177 "Ignore C-regions matching this regexp (default \"%s\"): "
2178 ediff-regexp-hide-C))))
2179 (if (eq ediff-hide-regexp-connective 'and)
2180 (setq msg-connective "BOTH"
2181 alt-msg-connective "ONE OF"
2183 (setq msg-connective "ONE OF"
2184 alt-msg-connective "BOTH"
2185 alt-connective 'and))
2188 "Ignore regions that match %s regexps, OK? "
2189 msg-connective alt-msg-connective))
2190 (message "Will ignore regions that match %s regexps" msg-connective)
2191 (setq ediff-hide-regexp-connective alt-connective)
2192 (message "Will ignore regions that match %s regexps"
2193 alt-msg-connective))
2195 (or (string= regexp-A "") (setq ediff-regexp-hide-A regexp-A))
2196 (or (string= regexp-B "") (setq ediff-regexp-hide-B regexp-B))
2197 (or (string= regexp-C "") (setq ediff-regexp-hide-C regexp-C)))
2199 ((eq last-command-char ?f)
2200 (setq ediff-skip-diff-region-function
2201 ediff-focus-on-regexp-matches-function
2205 "Focus on A-regions matching this regexp (default \"%s\"): "
2206 ediff-regexp-focus-A))
2210 "Focus on B-regions matching this regexp (default \"%s\"): "
2211 ediff-regexp-focus-B)))
2212 (if ediff-3way-comparison-job
2216 "Focus on C-regions matching this regexp (default \"%s\"): "
2217 ediff-regexp-focus-C))))
2218 (if (eq ediff-focus-regexp-connective 'and)
2219 (setq msg-connective "BOTH"
2220 alt-msg-connective "ONE OF"
2222 (setq msg-connective "ONE OF"
2223 alt-msg-connective "BOTH"
2224 alt-connective 'and))
2227 "Focus on regions that match %s regexps, OK? "
2228 msg-connective alt-msg-connective))
2229 (message "Will focus on regions that match %s regexps"
2231 (setq ediff-focus-regexp-connective alt-connective)
2232 (message "Will focus on regions that match %s regexps"
2233 alt-msg-connective))
2235 (or (string= regexp-A "") (setq ediff-regexp-focus-A regexp-A))
2236 (or (string= regexp-B "") (setq ediff-regexp-focus-B regexp-B))
2237 (or (string= regexp-C "") (setq ediff-regexp-focus-C regexp-C))))))
2239 (defun ediff-toggle-skip-similar ()
2241 (ediff-barf-if-not-control-buffer)
2242 (if (not (eq ediff-auto-refine 'on))
2244 "Can't skip over whitespace regions: first turn auto-refining on"))
2245 (setq ediff-ignore-similar-regions (not ediff-ignore-similar-regions))
2246 (if ediff-ignore-similar-regions
2248 "Skipping regions that differ only in white space & line breaks")
2249 (message "Skipping over white-space differences turned off")))
2251 (defun ediff-focus-on-regexp-matches (n)
2252 "Focus on diffs that match regexp `ediff-regexp-focus-A/B'.
2253 Regions to be ignored according to this function are those where
2254 buf A region doesn't match `ediff-regexp-focus-A' and buf B region
2255 doesn't match `ediff-regexp-focus-B'.
2256 This function returns nil if the region number N (specified as
2257 an argument) is not to be ignored and t if region N is to be ignored.
2259 N is a region number used by Ediff internally. It is 1 less
2260 the number seen by the user."
2261 (if (ediff-valid-difference-p n)
2262 (let* ((ctl-buf ediff-control-buffer)
2263 (regex-A ediff-regexp-focus-A)
2264 (regex-B ediff-regexp-focus-B)
2265 (regex-C ediff-regexp-focus-C)
2266 (reg-A-match (ediff-with-current-buffer ediff-buffer-A
2269 (ediff-get-diff-posn 'A 'beg n ctl-buf)
2270 (ediff-get-diff-posn 'A 'end n ctl-buf))
2271 (goto-char (point-min))
2272 (re-search-forward regex-A nil t))))
2273 (reg-B-match (ediff-with-current-buffer ediff-buffer-B
2276 (ediff-get-diff-posn 'B 'beg n ctl-buf)
2277 (ediff-get-diff-posn 'B 'end n ctl-buf))
2278 (re-search-forward regex-B nil t))))
2279 (reg-C-match (if ediff-3way-comparison-job
2280 (ediff-with-current-buffer ediff-buffer-C
2283 (ediff-get-diff-posn 'C 'beg n ctl-buf)
2284 (ediff-get-diff-posn 'C 'end n ctl-buf))
2285 (re-search-forward regex-C nil t))))))
2286 (not (eval (if ediff-3way-comparison-job
2287 (list ediff-focus-regexp-connective
2288 reg-A-match reg-B-match reg-C-match)
2289 (list ediff-focus-regexp-connective
2290 reg-A-match reg-B-match))))
2293 (defun ediff-hide-regexp-matches (n)
2294 "Hide diffs that match regexp `ediff-regexp-hide-A/B/C'.
2295 Regions to be ignored are those where buf A region matches
2296 `ediff-regexp-hide-A' and buf B region matches `ediff-regexp-hide-B'.
2297 This function returns nil if the region number N (specified as
2298 an argument) is not to be ignored and t if region N is to be ignored.
2300 N is a region number used by Ediff internally. It is 1 less
2301 the number seen by the user."
2302 (if (ediff-valid-difference-p n)
2303 (let* ((ctl-buf ediff-control-buffer)
2304 (regex-A ediff-regexp-hide-A)
2305 (regex-B ediff-regexp-hide-B)
2306 (regex-C ediff-regexp-hide-C)
2307 (reg-A-match (ediff-with-current-buffer ediff-buffer-A
2310 (ediff-get-diff-posn 'A 'beg n ctl-buf)
2311 (ediff-get-diff-posn 'A 'end n ctl-buf))
2312 (goto-char (point-min))
2313 (re-search-forward regex-A nil t))))
2314 (reg-B-match (ediff-with-current-buffer ediff-buffer-B
2317 (ediff-get-diff-posn 'B 'beg n ctl-buf)
2318 (ediff-get-diff-posn 'B 'end n ctl-buf))
2319 (goto-char (point-min))
2320 (re-search-forward regex-B nil t))))
2321 (reg-C-match (if ediff-3way-comparison-job
2322 (ediff-with-current-buffer ediff-buffer-C
2325 (ediff-get-diff-posn 'C 'beg n ctl-buf)
2326 (ediff-get-diff-posn 'C 'end n ctl-buf))
2327 (goto-char (point-min))
2328 (re-search-forward regex-C nil t))))))
2329 (eval (if ediff-3way-comparison-job
2330 (list ediff-hide-regexp-connective
2331 reg-A-match reg-B-match reg-C-match)
2332 (list ediff-hide-regexp-connective reg-A-match reg-B-match)))
2337 ;;; Quitting, suspending, etc.
2339 (defun ediff-quit (reverse-default-keep-variants)
2340 "Finish an Ediff session and exit Ediff.
2341 Unselects the selected difference, if any, restores the read-only and modified
2342 flags of the compared file buffers, kills Ediff buffers for this session
2343 \(but not buffers A, B, C\).
2345 If `ediff-keep-variants' is nil, the user will be asked whether the buffers
2346 containing the variants should be removed \(if they haven't been modified\).
2347 If it is t, they will be preserved unconditionally. A prefix argument,
2348 temporarily reverses the meaning of this variable."
2350 (ediff-barf-if-not-control-buffer)
2351 (let ((ctl-buf (current-buffer)))
2352 (if (y-or-n-p (format "Quit this Ediff session%s? "
2353 (if (ediff-buffer-live-p ediff-meta-buffer)
2354 " & show containing session group" "")))
2357 (set-buffer ctl-buf)
2358 (ediff-really-quit reverse-default-keep-variants))
2362 ;; Perform the quit operations.
2363 (defun ediff-really-quit (reverse-default-keep-variants)
2364 (ediff-unhighlight-diffs-totally)
2365 (ediff-clear-diff-vector 'ediff-difference-vector-A 'fine-diffs-also)
2366 (ediff-clear-diff-vector 'ediff-difference-vector-B 'fine-diffs-also)
2367 (ediff-clear-diff-vector 'ediff-difference-vector-C 'fine-diffs-also)
2368 (ediff-clear-diff-vector 'ediff-difference-vector-Ancestor 'fine-diffs-also)
2370 (ediff-delete-temp-files)
2372 ;; Restore visibility range. This affects only ediff-*-regions/windows.
2373 ;; Since for other job names ediff-visible-region sets
2374 ;; ediff-visible-bounds to ediff-wide-bounds, the settings below are
2375 ;; ignored for such jobs.
2376 (if ediff-quit-widened
2377 (setq ediff-visible-bounds ediff-wide-bounds)
2378 (setq ediff-visible-bounds ediff-narrow-bounds))
2380 ;; Apply selective display to narrow or widen
2381 (ediff-visible-region)
2382 (mapcar (lambda (overl)
2383 (if (ediff-overlayp overl)
2384 (ediff-delete-overlay overl)))
2386 (mapcar (lambda (overl)
2387 (if (ediff-overlayp overl)
2388 (ediff-delete-overlay overl)))
2389 ediff-narrow-bounds)
2391 ;; restore buffer mode line id's in buffer-A/B/C
2392 (let ((control-buffer ediff-control-buffer)
2393 (meta-buffer ediff-meta-buffer)
2394 (after-quit-hook-internal ediff-after-quit-hook-internal)
2395 (session-number ediff-meta-session-number)
2396 ;; suitable working frame
2397 (warp-frame (if (and (ediff-window-display-p) (eq ediff-grab-mouse t))
2398 (cond ((window-live-p ediff-window-A)
2399 (window-frame ediff-window-A))
2400 ((window-live-p ediff-window-B)
2401 (window-frame ediff-window-B))
2402 (t (next-frame))))))
2404 (ediff-with-current-buffer ediff-buffer-A
2405 (setq ediff-this-buffer-ediff-sessions
2406 (delq control-buffer ediff-this-buffer-ediff-sessions))
2407 (kill-local-variable 'mode-line-buffer-identification)
2408 (kill-local-variable 'mode-line-format)
2413 (ediff-with-current-buffer ediff-buffer-B
2414 (setq ediff-this-buffer-ediff-sessions
2415 (delq control-buffer ediff-this-buffer-ediff-sessions))
2416 (kill-local-variable 'mode-line-buffer-identification)
2417 (kill-local-variable 'mode-line-format)
2422 (ediff-with-current-buffer ediff-buffer-C
2423 (setq ediff-this-buffer-ediff-sessions
2424 (delq control-buffer ediff-this-buffer-ediff-sessions))
2425 (kill-local-variable 'mode-line-buffer-identification)
2426 (kill-local-variable 'mode-line-format)
2431 (ediff-with-current-buffer ediff-ancestor-buffer
2432 (setq ediff-this-buffer-ediff-sessions
2433 (delq control-buffer ediff-this-buffer-ediff-sessions))
2434 (kill-local-variable 'mode-line-buffer-identification)
2435 (kill-local-variable 'mode-line-format)
2439 (setq ediff-session-registry
2440 (delq ediff-control-buffer ediff-session-registry))
2441 (ediff-update-registry)
2442 ;; restore state of buffers to what it was before ediff
2443 (ediff-restore-protected-variables)
2445 ;; If the user interrupts (canceling saving the merge buffer), continue
2448 (if (ediff-merge-job)
2449 (run-hooks 'ediff-quit-merge-hook))
2452 (run-hooks 'ediff-cleanup-hook)
2454 ;; now kill buffers A/B/C, if requested
2455 (let ((ediff-keep-variants ediff-keep-variants))
2456 (if reverse-default-keep-variants
2457 (setq ediff-keep-variants (not ediff-keep-variants)))
2458 (or ediff-keep-variants (ediff-janitor 'ask)))
2460 ;; one hook here is ediff-cleanup-mess, which kills the control buffer and
2461 ;; other auxiliary buffers. we made it into a hook to let the users do their
2462 ;; own cleanup, if needed.
2463 (run-hooks 'ediff-quit-hook)
2464 (ediff-update-meta-buffer meta-buffer nil session-number)
2466 ;; warp mouse into a working window
2467 (setq warp-frame ; if mouse is over a reasonable frame, use it
2468 (cond ((ediff-good-frame-under-mouse))
2470 (if (and (ediff-window-display-p) (frame-live-p warp-frame) ediff-grab-mouse)
2471 (set-mouse-position (if ediff-emacs-p
2473 (frame-selected-window warp-frame))
2476 (run-hooks 'after-quit-hook-internal)
2479 ;; Returns frame under mouse, if this frame is not a minibuffer
2480 ;; frame. Otherwise: nil
2481 (defun ediff-good-frame-under-mouse ()
2482 (let ((frame-or-win (car (mouse-position)))
2487 (frame-live-p frame-or-win)
2488 (window-live-p frame-or-win)))
2490 (setq frame (if ediff-emacs-p frame-or-win (window-frame frame-or-win))
2492 (buffer-name (window-buffer (frame-selected-window frame)))))
2493 (if (string-match "Minibuf" buf-name)
2498 (defun ediff-delete-temp-files ()
2499 (if (and (stringp ediff-temp-file-A) (file-exists-p ediff-temp-file-A))
2500 (delete-file ediff-temp-file-A))
2501 (if (and (stringp ediff-temp-file-B) (file-exists-p ediff-temp-file-B))
2502 (delete-file ediff-temp-file-B))
2503 (if (and (stringp ediff-temp-file-C) (file-exists-p ediff-temp-file-C))
2504 (delete-file ediff-temp-file-C)))
2507 ;; Kill control buffer, other auxiliary Ediff buffers.
2508 ;; Leave one of the frames split between buffers A/B/C
2509 (defun ediff-cleanup-mess ()
2510 (let* ((buff-A ediff-buffer-A)
2511 (buff-B ediff-buffer-B)
2512 (buff-C ediff-buffer-C)
2513 (ctl-buf ediff-control-buffer)
2514 (ctl-frame ediff-control-frame)
2515 (three-way-job ediff-3way-job)
2516 (main-frame (cond ((window-live-p ediff-window-A)
2517 (window-frame ediff-window-A))
2518 ((window-live-p ediff-window-B)
2519 (window-frame ediff-window-B)))))
2521 (ediff-kill-buffer-carefully ediff-diff-buffer)
2522 (ediff-kill-buffer-carefully ediff-custom-diff-buffer)
2523 (ediff-kill-buffer-carefully ediff-fine-diff-buffer)
2524 (ediff-kill-buffer-carefully ediff-tmp-buffer)
2525 (ediff-kill-buffer-carefully ediff-error-buffer)
2526 (ediff-kill-buffer-carefully ediff-msg-buffer)
2527 (ediff-kill-buffer-carefully ediff-debug-buffer)
2528 (if (boundp 'ediff-patch-diagnostics)
2529 (ediff-kill-buffer-carefully ediff-patch-diagnostics))
2531 (if (and (ediff-window-display-p) (frame-live-p ctl-frame))
2532 (delete-frame ctl-frame))
2533 ;; Hide bottom toolbar. --marcpa
2534 (if (not (ediff-multiframe-setup-p))
2535 (ediff-kill-bottom-toolbar))
2537 (ediff-kill-buffer-carefully ctl-buf)
2539 (if (frame-live-p main-frame)
2541 (select-frame main-frame)
2542 (delete-other-windows)))
2544 ;; display only if not visible
2546 (or (ediff-get-visible-buffer-window buff-B)
2547 (switch-to-buffer buff-B))
2550 (or (ediff-get-visible-buffer-window buff-A)
2552 (if (ediff-get-visible-buffer-window buff-B)
2553 (funcall ediff-split-window-function))
2554 (switch-to-buffer buff-A)))
2558 (or (ediff-get-visible-buffer-window buff-C)
2560 (if (or (ediff-get-visible-buffer-window buff-A)
2561 (ediff-get-visible-buffer-window buff-B))
2562 (funcall ediff-split-window-function))
2563 (switch-to-buffer buff-C)
2569 (defun ediff-janitor (&optional ask)
2570 "Kill buffers A, B, and, possibly, C, if these buffers aren't modified.
2571 In merge jobs, buffer C is never deleted.
2572 However, the side effect of cleaning up may be that you cannot compare the same
2573 buffer in two separate Ediff sessions: quitting one of them will delete this
2574 buffer in another session as well."
2575 (or (not (ediff-buffer-live-p ediff-buffer-A))
2576 (buffer-modified-p ediff-buffer-A)
2578 (not (y-or-n-p (format "Kill buffer A [%s]? "
2579 (buffer-name ediff-buffer-A)))))
2580 (ediff-kill-buffer-carefully ediff-buffer-A))
2581 (or (not (ediff-buffer-live-p ediff-buffer-B))
2582 (buffer-modified-p ediff-buffer-B)
2584 (not (y-or-n-p (format "Kill buffer B [%s]? "
2585 (buffer-name ediff-buffer-B)))))
2586 (ediff-kill-buffer-carefully ediff-buffer-B))
2587 (if ediff-merge-job ; don't del buf C if merging--del ancestor buf instead
2588 (or (not (ediff-buffer-live-p ediff-ancestor-buffer))
2589 (buffer-modified-p ediff-ancestor-buffer)
2591 (not (y-or-n-p (format "Kill the ancestor buffer [%s]? "
2592 (buffer-name ediff-ancestor-buffer)))))
2593 (ediff-kill-buffer-carefully ediff-ancestor-buffer))
2594 (or (not (ediff-buffer-live-p ediff-buffer-C))
2595 (buffer-modified-p ediff-buffer-C)
2596 (and ask (not (y-or-n-p (format "Kill buffer C [%s]? "
2597 (buffer-name ediff-buffer-C)))))
2598 (ediff-kill-buffer-carefully ediff-buffer-C))))
2600 (defun ediff-maybe-save-and-delete-merge (&optional save-and-continue)
2601 "Default hook to run on quitting a merge job.
2602 This can also be used to save merge buffer in the middle of an Ediff session.
2604 If the optional SAVE-AND-CONTINUE argument is non-nil, save merge buffer and
2605 continue. Otherwise:
2606 If `ediff-autostore-merges' is nil, this does nothing.
2607 If it is t, it saves the merge buffer in the file `ediff-merge-store-file'
2608 or asks the user, if the latter is nil. It then asks the user whether to
2609 delete the merge buffer.
2610 If `ediff-autostore-merges' is neither nil nor t, the merge buffer is saved
2611 only if this merge job is part of a group, i.e., was invoked from within
2612 `ediff-merge-directories', `ediff-merge-directory-revisions', and such."
2613 (let ((merge-store-file ediff-merge-store-file)
2614 (ediff-autostore-merges ; fake ediff-autostore-merges, if necessary
2615 (if save-and-continue t ediff-autostore-merges)))
2616 (if ediff-autostore-merges
2617 (cond ((stringp ediff-merge-store-file)
2618 ;; store, ask to delete
2619 (ediff-write-merge-buffer-and-maybe-kill
2620 ediff-buffer-C merge-store-file 'show-file save-and-continue))
2621 ((eq ediff-autostore-merges t)
2622 ;; ask for file name
2623 (setq merge-store-file
2624 (read-file-name "Save the merge buffer in file: "))
2625 (ediff-write-merge-buffer-and-maybe-kill
2626 ediff-buffer-C merge-store-file nil save-and-continue))
2627 ((and (ediff-buffer-live-p ediff-meta-buffer)
2628 (ediff-with-current-buffer ediff-meta-buffer
2629 (ediff-merge-metajob)))
2630 ;; The parent metajob passed nil as the autostore file.
2634 ;; write merge buffer. If the optional argument save-and-continue is non-nil,
2635 ;; then don't kill the merge buffer
2636 (defun ediff-write-merge-buffer-and-maybe-kill (buf file
2638 show-file save-and-continue)
2639 (ediff-with-current-buffer buf
2640 (if (or (not (file-exists-p file))
2641 (y-or-n-p (format "File %s exists, overwrite? " file)))
2643 (write-region (point-min) (point-max) file)
2646 (message "Merge buffer saved in: %s" file)
2647 (set-buffer-modified-p nil)
2650 (not save-and-continue)
2651 (y-or-n-p "Merge buffer saved. Now kill the buffer? "))
2652 (ediff-kill-buffer-carefully buf))))))
2654 ;; The default way of suspending Ediff.
2655 ;; Buries Ediff buffers, kills all windows.
2656 (defun ediff-default-suspend-function ()
2657 (let* ((buf-A ediff-buffer-A)
2658 (buf-B ediff-buffer-B)
2659 (buf-C ediff-buffer-C)
2660 (buf-A-wind (ediff-get-visible-buffer-window buf-A))
2661 (buf-B-wind (ediff-get-visible-buffer-window buf-B))
2662 (buf-C-wind (ediff-get-visible-buffer-window buf-C))
2663 (buf-patch (if (boundp 'ediff-patchbufer) ediff-patchbufer nil))
2664 (buf-patch-diag (if (boundp 'ediff-patch-diagnostics)
2665 ediff-patch-diagnostics nil))
2666 (buf-err ediff-error-buffer)
2667 (buf-diff ediff-diff-buffer)
2668 (buf-custom-diff ediff-custom-diff-buffer)
2669 (buf-fine-diff ediff-fine-diff-buffer))
2671 ;; hide the control panel
2672 (if (and (ediff-window-display-p) (frame-live-p ediff-control-frame))
2673 (iconify-frame ediff-control-frame)
2675 (if buf-err (bury-buffer buf-err))
2676 (if buf-diff (bury-buffer buf-diff))
2677 (if buf-custom-diff (bury-buffer buf-custom-diff))
2678 (if buf-fine-diff (bury-buffer buf-fine-diff))
2679 (if buf-patch (bury-buffer buf-patch))
2680 (if buf-patch-diag (bury-buffer buf-patch-diag))
2681 (if (window-live-p buf-A-wind)
2683 (select-window buf-A-wind)
2684 (delete-other-windows)
2686 (if (ediff-buffer-live-p buf-A)
2690 (if (window-live-p buf-B-wind)
2692 (select-window buf-B-wind)
2693 (delete-other-windows)
2695 (if (ediff-buffer-live-p buf-B)
2699 (if (window-live-p buf-C-wind)
2701 (select-window buf-C-wind)
2702 (delete-other-windows)
2704 (if (ediff-buffer-live-p buf-C)
2711 (defun ediff-suspend ()
2713 To resume, switch to the appropriate `Ediff Control Panel'
2714 buffer and then type \\[ediff-recenter]. Ediff will automatically set
2715 up an appropriate window config."
2717 (ediff-barf-if-not-control-buffer)
2718 (run-hooks 'ediff-suspend-hook)
2720 "To resume, type M-x eregistry and select the desired Ediff session"))
2723 (defun ediff-status-info ()
2724 "Show the names of the buffers or files being operated on by Ediff.
2725 Hit \\[ediff-recenter] to reset the windows afterward."
2727 (ediff-barf-if-not-control-buffer)
2729 (ediff-skip-unsuitable-frames))
2730 (with-output-to-temp-buffer ediff-msg-buffer
2731 (ediff-with-current-buffer standard-output
2733 (raise-frame (selected-frame))
2734 (princ (ediff-version))
2736 (ediff-with-current-buffer ediff-buffer-A
2737 (if buffer-file-name
2739 (format "File A = %S\n" buffer-file-name))
2741 (format "Buffer A = %S\n" (buffer-name)))))
2742 (ediff-with-current-buffer ediff-buffer-B
2743 (if buffer-file-name
2745 (format "File B = %S\n" buffer-file-name))
2747 (format "Buffer B = %S\n" (buffer-name)))))
2749 (ediff-with-current-buffer ediff-buffer-C
2750 (if buffer-file-name
2752 (format "File C = %S\n" buffer-file-name))
2754 (format "Buffer C = %S\n" (buffer-name))))))
2755 (princ (format "Customized diff output %s\n"
2756 (if (ediff-buffer-live-p ediff-custom-diff-buffer)
2757 (concat "\tin buffer "
2758 (buffer-name ediff-custom-diff-buffer))
2759 " is not available")))
2760 (princ (format "Plain diff output %s\n"
2761 (if (ediff-buffer-live-p ediff-diff-buffer)
2762 (concat "\tin buffer "
2763 (buffer-name ediff-diff-buffer))
2764 " is not available")))
2766 (let* ((A-line (ediff-with-current-buffer ediff-buffer-A
2767 (1+ (count-lines (point-min) (point)))))
2768 (B-line (ediff-with-current-buffer ediff-buffer-B
2769 (1+ (count-lines (point-min) (point)))))
2771 (princ (format "\Buffer A's point is on line %d\n" A-line))
2772 (princ (format "Buffer B's point is on line %d\n" B-line))
2775 (setq C-line (ediff-with-current-buffer ediff-buffer-C
2776 (1+ (count-lines (point-min) (point)))))
2777 (princ (format "Buffer C's point is on line %d\n" C-line)))))
2779 (princ (format "\nCurrent difference number = %S\n"
2780 (cond ((< ediff-current-difference 0) 'start)
2781 ((>= ediff-current-difference
2782 ediff-number-of-differences) 'end)
2783 (t (1+ ediff-current-difference)))))
2786 (format "\n%s regions that differ in white space & line breaks only"
2787 (if ediff-ignore-similar-regions
2788 "Ignoring" "Showing")))
2789 (if (and ediff-merge-job ediff-show-clashes-only)
2791 "\nFocusing on regions where both buffers differ from the ancestor"))
2792 (if (and ediff-skip-merge-regions-that-differ-from-default ediff-merge-job)
2794 "\nSkipping merge regions that differ from default setting"))
2796 (cond ((eq ediff-skip-diff-region-function 'ediff-show-all-diffs)
2797 (princ "\nSelective browsing by regexp is off\n"))
2798 ((eq ediff-skip-diff-region-function
2799 ediff-hide-regexp-matches-function)
2801 "\nIgnoring regions that match")
2804 "\n\t regexp `%s' in buffer A %S\n\t regexp `%s' in buffer B\n"
2805 ediff-regexp-hide-A ediff-hide-regexp-connective
2806 ediff-regexp-hide-B)))
2807 ((eq ediff-skip-diff-region-function
2808 ediff-focus-on-regexp-matches-function)
2810 "\nFocusing on regions that match")
2813 "\n\t regexp `%s' in buffer A %S\n\t regexp `%s' in buffer B\n"
2814 ediff-regexp-focus-A ediff-focus-regexp-connective
2815 ediff-regexp-focus-B)))
2816 (t (princ "\nSelective browsing via a user-defined method.\n")))
2819 (format "\nBugs/suggestions: type `%s' while in Ediff Control Panel."
2820 (substitute-command-keys "\\[ediff-submit-report]")))
2822 (if (frame-live-p ediff-control-frame)
2823 (ediff-reset-mouse ediff-control-frame))
2824 (if (window-live-p ediff-control-window)
2825 (select-window ediff-control-window)))
2830 ;;; Support routines
2832 ;; Select a difference by placing the ASCII flags around the appropriate
2833 ;; group of lines in the A, B buffers
2834 ;; This may have to be modified for buffer C, when it will be supported.
2835 (defun ediff-select-difference (n)
2836 (if (and (ediff-buffer-live-p ediff-buffer-A)
2837 (ediff-buffer-live-p ediff-buffer-B)
2838 (ediff-valid-difference-p n))
2840 (if (and (ediff-has-face-support-p) ediff-use-faces)
2842 (ediff-highlight-diff n)
2843 (setq ediff-highlighting-style 'face))
2844 (setq ediff-highlighting-style 'ascii)
2845 (ediff-place-flags-in-buffer
2846 'A ediff-buffer-A ediff-control-buffer n)
2847 (ediff-place-flags-in-buffer
2848 'B ediff-buffer-B ediff-control-buffer n)
2850 (ediff-place-flags-in-buffer
2851 'C ediff-buffer-C ediff-control-buffer n))
2852 (if (ediff-buffer-live-p ediff-ancestor-buffer)
2853 (ediff-place-flags-in-buffer
2854 'Ancestor ediff-ancestor-buffer
2855 ediff-control-buffer n))
2858 (ediff-install-fine-diff-if-necessary n)
2859 (run-hooks 'ediff-select-hook))))
2862 ;; Unselect a difference by removing the ASCII flags in the buffers.
2863 ;; This may have to be modified for buffer C, when it will be supported.
2864 (defun ediff-unselect-difference (n)
2865 (if (ediff-valid-difference-p n)
2867 (cond ((and (ediff-has-face-support-p) ediff-use-faces)
2868 (ediff-unhighlight-diff))
2869 ((eq ediff-highlighting-style 'ascii)
2870 (ediff-remove-flags-from-buffer
2872 (ediff-get-diff-overlay n 'A))
2873 (ediff-remove-flags-from-buffer
2875 (ediff-get-diff-overlay n 'B))
2877 (ediff-remove-flags-from-buffer
2879 (ediff-get-diff-overlay n 'C)))
2880 (if (ediff-buffer-live-p ediff-ancestor-buffer)
2881 (ediff-remove-flags-from-buffer
2882 ediff-ancestor-buffer
2883 (ediff-get-diff-overlay n 'Ancestor)))
2885 (setq ediff-highlighting-style nil)
2887 ;; unhighlight fine diffs
2888 (ediff-set-fine-diff-properties ediff-current-difference 'default)
2889 (run-hooks 'ediff-unselect-hook))))
2892 ;; Unselects prev diff and selects a new one, if FLAG has value other than
2893 ;; 'select-only or 'unselect-only. If FLAG is 'select-only, the
2894 ;; next difference is selected, but the current selection is not
2895 ;; unselected. If FLAG is 'unselect-only then the current selection is
2896 ;; unselected, but the next one is not selected. If NO-RECENTER is non-nil,
2897 ;; don't recenter buffers after selecting/unselecting.
2898 (defun ediff-unselect-and-select-difference (n &optional flag no-recenter)
2899 (let ((ediff-current-difference n))
2901 (ediff-recenter 'no-rehighlight)))
2903 (let ((control-buf ediff-control-buffer))
2906 (or (eq flag 'select-only)
2907 (ediff-unselect-difference ediff-current-difference))
2909 (or (eq flag 'unselect-only)
2910 (ediff-select-difference n))
2911 (setq ediff-current-difference n)
2912 ) ; end protected section
2914 (ediff-with-current-buffer control-buf (ediff-refresh-mode-lines))
2918 ;; This is adapted from a similar function in `emerge.el'.
2919 ;; PROMPT should not have a trailing ': ', so that it can be modified
2920 ;; according to context.
2921 ;; If DEFAULT-FILE is set, it should be used as the default value.
2922 ;; If DEFAULT-DIR is non-nil, use it as the default directory.
2923 ;; Otherwise, use the value of Emacs' variable `default-directory.'
2924 (defun ediff-read-file-name (prompt default-dir default-file)
2925 ;; hack default-dir if it is not set
2927 (file-name-as-directory
2928 (ediff-abbreviate-file-name
2929 (expand-file-name (or default-dir
2931 (file-name-directory default-file))
2932 default-directory)))))
2934 ;; strip the directory from default-file
2936 (setq default-file (file-name-nondirectory default-file)))
2937 (if (string= default-file "")
2938 (setq default-file nil))
2941 (setq f (expand-file-name
2946 (concat " (default " default-file "):"))
2947 (t (concat " (default " default-dir "):"))))
2949 (or default-file default-dir)
2950 t ; must match, no-confirm
2951 (if default-file (file-name-directory default-file))
2955 ;; If user enters a directory name, expand the default file in that
2956 ;; directory. This allows the user to enter a directory name for the
2957 ;; B-file and diff against the default-file in that directory instead
2958 ;; of a DIRED listing!
2959 (if (and (file-directory-p f) default-file)
2960 (setq f (expand-file-name
2961 (file-name-nondirectory default-file) f)))
2964 ;; If PREFIX is given, then it is used as a prefix for the temp file
2965 ;; name. Otherwise, `ediff' is used. If FILE is given, use this
2966 ;; file and don't create a new one.
2967 ;; In MS-DOS, make sure the prefix isn't too long, or else
2968 ;; `make-temp-name' isn't guaranteed to return a unique filename.
2969 ;; Also, save buffer from START to END in the file.
2970 ;; START defaults to (point-min), END to (point-max)
2971 (defun ediff-make-temp-file (buff &optional prefix given-file start end)
2972 (let* ((p (ediff-convert-standard-filename (or prefix "ediff")))
2974 (coding-system-for-write 'no-conversion)
2976 (if (and (fboundp 'msdos-long-file-names)
2977 (not (msdos-long-file-names))
2979 (setq short-p (substring p 0 2)))
2981 (setq f (concat ediff-temp-file-prefix p)
2982 short-f (concat ediff-temp-file-prefix short-p)
2983 f (cond (given-file)
2984 ((find-file-name-handler f 'find-file-noselect)
2985 ;; to thwart file handlers in write-region, e.g., if file
2986 ;; name ends with .Z or .gz
2987 ;; This is needed so that patches produced by ediff will
2988 ;; have more meaningful names
2989 (ediff-make-empty-tmp-file short-f))
2991 ;; Prefix is most often the same as the file name for the
2992 ;; variant. Here we are trying to use the original file
2993 ;; name but in the temp directory.
2994 (ediff-make-empty-tmp-file f 'keep-name))
2996 ;; If don't care about name, add some random stuff
2997 ;; to proposed file name.
2998 (ediff-make-empty-tmp-file short-f))))
3001 (ediff-with-current-buffer buff
3002 (write-region (if start start (point-min))
3003 (if end end (point-max))
3005 nil ; don't append---erase
3007 (set-file-modes f ediff-temp-file-mode)
3008 (expand-file-name f))))
3010 ;; Create a temporary file.
3011 ;; The returned file name (created by appending some random characters at the
3012 ;; end of PROPOSED-NAME is guaranteed to point to a newly created empty file.
3013 ;; This is a replacement for make-temp-name, which eliminates a security hole.
3014 ;; If KEEP-PROPOSED-NAME isn't nil, try to keep PROPOSED-NAME, unless such file
3016 ;; It is a modified version of make-temp-file in emacs 20.5
3017 (defun ediff-make-empty-tmp-file (proposed-name &optional keep-proposed-name)
3018 (let ((file proposed-name))
3019 (while (condition-case ()
3021 (if (or (file-exists-p file) (not keep-proposed-name))
3022 (setq file (make-temp-name proposed-name)))
3023 (write-region "" nil file nil 'silent nil 'excl)
3025 (file-already-exists t))
3026 ;; the file was somehow created by someone else between
3027 ;; `make-temp-name' and `write-region', let's try again.
3032 ;; Quote metacharacters (using \) when executing diff in Unix, but not in
3034 ;;(defun ediff-protect-metachars (str)
3035 ;; (or (memq system-type '(emx vax-vms axp-vms))
3037 ;; (while (string-match ediff-metachars str limit)
3038 ;; (setq str (concat (substring str 0 (match-beginning 0))
3040 ;; (substring str (match-beginning 0))))
3041 ;; (setq limit (1+ (match-end 0))))))
3044 ;; Make sure the current buffer (for a file) has the same contents as the
3045 ;; file on disk, and attempt to remedy the situation if not.
3046 ;; Signal an error if we can't make them the same, or the user doesn't want
3047 ;; to do what is necessary to make them the same.
3048 ;; Also, Ediff always offers to revert obsolete buffers, whether they
3049 ;; are modified or not.
3050 (defun ediff-verify-file-buffer (&optional file-magic)
3051 ;; First check if the file has been modified since the buffer visited it.
3052 (if (verify-visited-file-modtime (current-buffer))
3053 (if (buffer-modified-p)
3054 ;; If buffer is not obsolete and is modified, offer to save
3056 (format "Buffer out of sync with visited file. Save file %s? "
3062 (message "Couldn't save %s" buffer-file-name)))
3063 (error "Buffer is out of sync for file %s" buffer-file-name))
3064 ;; If buffer is not obsolete and is not modified, do nothing
3066 ;; If buffer is obsolete, offer to revert
3068 (format "Buffer is out of sync with visited file. REVERT file %s? "
3073 (revert-buffer t t))
3074 (error "Buffer out of sync for file %s" buffer-file-name))))
3077 (defun ediff-filename-magic-p (file)
3078 (or (ediff-file-compressed-p file)
3079 (ediff-file-remote-p file)))
3082 (defun ediff-save-buffer (arg)
3083 "Safe way of saving buffers A, B, C, and the diff output.
3084 `wa' saves buffer A, `wb' saves buffer B, `wc' saves buffer C,
3085 and `wd' saves the diff output.
3087 With prefix argument, `wd' saves plain diff output.
3088 Without an argument, it saves customized diff argument, if available
3089 \(and plain output, if customized output was not generated\)."
3091 (ediff-barf-if-not-control-buffer)
3092 (ediff-compute-custom-diffs-maybe)
3093 (ediff-with-current-buffer
3094 (cond ((memq last-command-char '(?a ?b ?c))
3096 (ediff-char-to-buftype last-command-char)))
3097 ((eq last-command-char ?d)
3098 (message "Saving diff output ...")
3099 (sit-for 1) ; let the user see the message
3100 (cond ((and arg (ediff-buffer-live-p ediff-diff-buffer))
3102 ((ediff-buffer-live-p ediff-custom-diff-buffer)
3103 ediff-custom-diff-buffer)
3104 ((ediff-buffer-live-p ediff-diff-buffer)
3106 (t (error "Output from `diff' not found"))))
3110 (defun ediff-compute-custom-diffs-maybe ()
3111 (let ((buf-A-file-name (buffer-file-name ediff-buffer-A))
3112 (buf-B-file-name (buffer-file-name ediff-buffer-B))
3114 (if (stringp buf-A-file-name)
3115 (setq buf-A-file-name (file-name-nondirectory buf-A-file-name)))
3116 (if (stringp buf-B-file-name)
3117 (setq buf-B-file-name (file-name-nondirectory buf-B-file-name)))
3118 (setq file-A (ediff-make-temp-file ediff-buffer-A buf-A-file-name)
3119 file-B (ediff-make-temp-file ediff-buffer-B buf-B-file-name))
3121 (or (ediff-buffer-live-p ediff-custom-diff-buffer)
3122 (setq ediff-custom-diff-buffer
3124 (ediff-unique-buffer-name "*ediff-custom-diff" "*"))))
3126 ediff-custom-diff-program ediff-custom-diff-buffer 'synchronize
3127 ediff-custom-diff-options file-A file-B)
3128 ;; put the diff file in diff-mode, if it is available
3129 (if (fboundp 'diff-mode)
3130 (with-current-buffer ediff-custom-diff-buffer
3132 (delete-file file-A)
3133 (delete-file file-B)
3136 (defun ediff-show-diff-output (arg)
3138 (ediff-barf-if-not-control-buffer)
3139 (ediff-compute-custom-diffs-maybe)
3141 (ediff-skip-unsuitable-frames ' ok-unsplittable))
3142 (let ((buf (cond ((and arg (ediff-buffer-live-p ediff-diff-buffer))
3144 ((ediff-buffer-live-p ediff-custom-diff-buffer)
3145 ediff-custom-diff-buffer)
3146 ((ediff-buffer-live-p ediff-diff-buffer)
3150 (message "Output from `diff' not found")
3154 (ediff-with-current-buffer buf
3155 (goto-char (point-min)))
3156 (switch-to-buffer buf)
3157 (raise-frame (selected-frame)))))
3158 (if (frame-live-p ediff-control-frame)
3159 (ediff-reset-mouse ediff-control-frame))
3160 (if (window-live-p ediff-control-window)
3161 (select-window ediff-control-window)))
3164 (defun ediff-inferior-compare-regions ()
3165 "Compare regions in an active Ediff session.
3166 Like ediff-regions-linewise but is called from under an active Ediff session on
3167 the files that belong to that session.
3169 After quitting the session invoked via this function, type C-l to the parent
3170 Ediff Control Panel to restore highlighting."
3173 (possibilities (list ?A ?B ?C))
3175 (ctl-buf (current-buffer))
3177 begA begB endA endB bufA bufB)
3179 (cond ((ediff-merge-job)
3180 (setq bufB ediff-buffer-C)
3181 (while (cond ((eq answer ?A)
3182 (setq bufA ediff-buffer-A
3183 possibilities '(?B))
3186 (setq bufA ediff-buffer-B
3187 possibilities '(?A))
3191 (message "Valid values are A or B")
3194 (let ((cursor-in-echo-area t))
3195 (message "Which buffer to compare to the merge buffer (A/B)? ")
3196 (setq answer (capitalize (read-char-exclusive))))))
3198 ((ediff-3way-comparison-job)
3199 (while (cond ((memq answer possibilities)
3200 (setq possibilities (delq answer possibilities))
3203 (ediff-get-symbol-from-alist
3204 answer ediff-buffer-alist)))
3209 "Valid values are %s"
3210 (mapconcat 'char-to-string possibilities " or "))
3213 (let ((cursor-in-echo-area t))
3214 (message "Enter the 1st buffer you want to compare (%s): "
3215 (mapconcat 'char-to-string possibilities "/"))
3216 (setq answer (capitalize (read-char-exclusive)))))
3217 (setq answer "") ; silence error msg
3218 (while (cond ((memq answer possibilities)
3219 (setq possibilities (delq answer possibilities))
3222 (ediff-get-symbol-from-alist
3223 answer ediff-buffer-alist)))
3228 "Valid values are %s"
3229 (mapconcat 'char-to-string possibilities " or "))
3232 (let ((cursor-in-echo-area t))
3233 (message "Enter the 2nd buffer you want to compare (%s): "
3234 (mapconcat 'char-to-string possibilities "/"))
3235 (setq answer (capitalize (read-char-exclusive))))))
3236 (t ; 2way comparison
3237 (setq bufA ediff-buffer-A
3239 possibilities nil)))
3241 (ediff-with-current-buffer bufA
3243 (error "You forgot to specify a region in buffer %s" (buffer-name)))
3244 (setq begA (region-beginning)
3251 (or (eobp) (forward-char)) ; include the newline char
3252 (setq endA (point)))
3253 (ediff-with-current-buffer bufB
3255 (error "You forgot to specify a region in buffer %s" (buffer-name)))
3256 (setq begB (region-beginning)
3263 (or (eobp) (forward-char)) ; include the newline char
3264 (setq endB (point)))
3266 (ediff-unselect-and-select-difference
3267 ediff-current-difference 'unselect-only)
3268 (ediff-paint-background-regions 'unhighlight)
3270 (ediff-with-current-buffer bufA
3273 (narrow-to-region begA endA)
3274 ;; (ediff-activate-mark)
3277 (ediff-with-current-buffer bufB
3280 (narrow-to-region begB endB)
3281 ;; (ediff-activate-mark)
3285 ;; At this point, possibilities contains either the window char A/B/C
3286 ;; that was not selected, or it is nil. We delete the window that is not
3289 (ediff-with-current-buffer ctl-buf
3290 (let* ((wind-to-delete (eval
3291 (ediff-get-symbol-from-alist
3293 ediff-window-alist)))
3294 (frame (window-frame wind-to-delete)))
3295 (delete-window wind-to-delete)
3296 (select-frame frame)
3297 (balance-windows))))
3299 "Please check regions selected for comparison. Continue? ")
3302 (ediff-with-current-buffer bufA
3304 (ediff-with-current-buffer bufB
3307 (ediff-with-current-buffer ctl-buf
3310 (error "All right. Make up your mind and come back...")))
3312 (ediff-regions-internal
3313 bufA begA endA bufB begB endB
3315 'ediff-regions-linewise ; job name
3317 ;; setup param to pass to ediff-setup
3318 (list (cons 'ediff-split-window-function ediff-split-window-function)))
3323 (defun ediff-remove-flags-from-buffer (buffer overlay)
3324 (ediff-with-current-buffer buffer
3325 (let ((inhibit-read-only t))
3327 (ediff-overlay-put overlay 'begin-glyph nil)
3328 (ediff-overlay-put overlay 'before-string nil))
3331 (ediff-overlay-put overlay 'end-glyph nil)
3332 (ediff-overlay-put overlay 'after-string nil))
3337 (defun ediff-place-flags-in-buffer (buf-type buffer ctl-buffer diff)
3338 (ediff-with-current-buffer buffer
3339 (ediff-place-flags-in-buffer1 buf-type ctl-buffer diff)))
3342 (defun ediff-place-flags-in-buffer1 (buf-type ctl-buffer diff-no)
3343 (let* ((curr-overl (ediff-with-current-buffer ctl-buffer
3344 (ediff-get-diff-overlay diff-no buf-type)))
3345 (before (ediff-get-diff-posn buf-type 'beg diff-no ctl-buffer))
3346 after beg-of-line flag)
3348 ;; insert flag before the difference
3350 (setq beg-of-line (bolp))
3352 (setq flag (ediff-with-current-buffer ctl-buffer
3353 (if (eq ediff-highlighting-style 'ascii)
3355 ediff-before-flag-bol ediff-before-flag-mol))))
3357 ;; insert the flag itself
3359 (ediff-overlay-put curr-overl 'begin-glyph flag)
3360 (ediff-overlay-put curr-overl 'before-string flag))
3362 ;; insert the flag after the difference
3363 ;; `after' must be set here, after the before-flag was inserted
3364 (setq after (ediff-get-diff-posn buf-type 'end diff-no ctl-buffer))
3366 (setq beg-of-line (bolp))
3368 (setq flag (ediff-with-current-buffer ctl-buffer
3369 (if (eq ediff-highlighting-style 'ascii)
3371 ediff-after-flag-eol ediff-after-flag-mol))))
3373 ;; insert the flag itself
3375 (ediff-overlay-put curr-overl 'end-glyph flag)
3376 (ediff-overlay-put curr-overl 'after-string flag))
3380 ;; Returns positions of difference sectors in the BUF-TYPE buffer.
3381 ;; BUF-TYPE should be a symbol -- `A', `B', or `C'.
3382 ;; POS is either `beg' or `end'--it specifies whether you want the position at
3383 ;; the beginning of a difference or at the end.
3385 ;; The optional argument N says which difference (default:
3386 ;; `ediff-current-difference'). N is the internal difference number (1- what
3387 ;; the user sees). The optional argument CONTROL-BUF says
3388 ;; which control buffer is in effect in case it is not the current
3390 (defun ediff-get-diff-posn (buf-type pos &optional n control-buf)
3393 (setq control-buf (current-buffer)))
3395 (ediff-with-current-buffer control-buf
3396 (or n (setq n ediff-current-difference))
3397 (if (or (< n 0) (>= n ediff-number-of-differences))
3398 (if (> ediff-number-of-differences 0)
3399 (error ediff-BAD-DIFF-NUMBER
3400 this-command (1+ n) ediff-number-of-differences)
3401 (error ediff-NO-DIFFERENCES)))
3402 (setq diff-overlay (ediff-get-diff-overlay n buf-type)))
3403 (if (not (ediff-buffer-live-p (ediff-overlay-buffer diff-overlay)))
3404 (error ediff-KILLED-VITAL-BUFFER))
3406 (ediff-overlay-start diff-overlay)
3407 (ediff-overlay-end diff-overlay))
3411 ;; Restore highlighting to what it should be according to ediff-use-faces,
3412 ;; ediff-highlighting-style, and ediff-highlight-all-diffs variables.
3413 (defun ediff-restore-highlighting (&optional ctl-buf)
3414 (ediff-with-current-buffer (or ctl-buf (current-buffer))
3415 (if (and (ediff-has-face-support-p)
3417 ediff-highlight-all-diffs)
3418 (ediff-paint-background-regions))
3419 (ediff-select-difference ediff-current-difference)))
3423 ;; null out difference overlays so they won't slow down future
3424 ;; editing operations
3425 ;; VEC is either a difference vector or a fine-diff vector
3426 (defun ediff-clear-diff-vector (vec-var &optional fine-diffs-also)
3427 (if (vectorp (symbol-value vec-var))
3428 (mapcar (lambda (elt)
3429 (ediff-delete-overlay
3430 (ediff-get-diff-overlay-from-diff-record elt))
3432 (ediff-clear-fine-diff-vector elt))
3434 (symbol-value vec-var)))
3435 ;; allow them to be garbage collected
3442 ;; In Emacs, this just makes overlay. In the future, when Emacs will start
3443 ;; supporting sticky overlays, this function will make a sticky overlay.
3444 ;; BEG and END are expressions telling where overlay starts.
3445 ;; If they are numbers or buffers, then all is well. Otherwise, they must
3446 ;; be expressions to be evaluated in buffer BUF in order to get the overlay
3448 ;; If BUFF is not a live buffer, then return nil; otherwise, return the
3449 ;; newly created overlay.
3450 (defun ediff-make-bullet-proof-overlay (beg end buff)
3451 (if (ediff-buffer-live-p buff)
3453 (ediff-with-current-buffer buff
3454 (or (number-or-marker-p beg)
3455 (setq beg (eval beg)))
3456 (or (number-or-marker-p end)
3457 (setq end (eval end)))
3460 (make-extent beg end buff)
3461 ;; advance front and rear of the overlay
3462 (make-overlay beg end buff nil 'rear-advance)))
3466 overl (if ediff-emacs-p 'evaporate 'detachable) nil)
3467 ;; make vip-minibuffer-overlay open-ended
3468 ;; In emacs, it is made open ended at creation time
3471 (ediff-overlay-put overl 'start-open nil)
3472 (ediff-overlay-put overl 'end-open nil)))
3473 (ediff-overlay-put overl 'ediff-diff-num 0)
3477 ;; Like other-buffer, but prefers visible buffers and ignores temporary or
3478 ;; other insignificant buffers (those beginning with "^[ *]").
3479 ;; Gets one arg--buffer name or a list of buffer names (it won't return
3481 ;; EXCL-BUFF-LIST is an exclusion list.
3482 (defun ediff-other-buffer (excl-buff-lst)
3483 (or (listp excl-buff-lst) (setq excl-buff-lst (list excl-buff-lst)))
3484 (let* ((all-buffers (nconc (ediff-get-selected-buffers) (buffer-list)))
3485 ;; we compute this the second time because we need to do memq on it
3486 ;; later, and nconc above will break it. Either this or use slow
3487 ;; append instead of nconc
3488 (selected-buffers (ediff-get-selected-buffers))
3489 (prefered-buffer (car all-buffers))
3490 visible-dired-buffers
3491 (excl-buff-name-list
3493 (lambda (b) (cond ((stringp b) b)
3494 ((bufferp b) (buffer-name b))))
3496 ;; if at least one buffer on the exclusion list is dired, then force
3497 ;; all others to be dired. This is because this means that the user
3498 ;; has already chosen a dired buffer before
3499 (use-dired-major-mode
3500 (cond ((null (ediff-buffer-live-p (car excl-buff-lst))) 'unknown)
3501 ((eq (ediff-with-current-buffer (car excl-buff-lst) major-mode)
3505 ;; significant-buffers must be visible and not belong
3506 ;; to the exclusion list `buff-list'
3507 ;; We also exclude temporary buffers, but keep mail and gnus buffers
3508 ;; Furthermore, we exclude dired buffers, unless they are the only
3509 ;; ones visible (and there are at least two of them).
3510 ;; Also, any visible window not on the exclusion list that is first in
3511 ;; the buffer list is chosen regardless. (This is because the user
3512 ;; clicked on it or did something to distinguish it).
3513 (significant-buffers
3516 (cond ((member (buffer-name x) excl-buff-name-list) nil)
3517 ((memq x selected-buffers) x)
3518 ((not (ediff-get-visible-buffer-window x)) nil)
3519 ((eq x prefered-buffer) x)
3520 ;; if prev selected buffer is dired, look only at
3522 ((eq use-dired-major-mode 'yes)
3523 (if (eq (ediff-with-current-buffer x major-mode)
3526 ((eq (ediff-with-current-buffer x major-mode)
3528 (if (null use-dired-major-mode)
3529 ;; don't know if we must enforce dired.
3530 ;; Remember this buffer in case
3531 ;; dired buffs are the only ones visible.
3532 (setq visible-dired-buffers
3533 (cons x visible-dired-buffers)))
3534 ;; skip, if dired is not forced
3536 ((memq (ediff-with-current-buffer x major-mode)
3542 ((string-match "^[ *]" (buffer-name x)) nil)
3543 ((string= "*scratch*" (buffer-name x)) nil)
3546 (clean-significant-buffers (delq nil significant-buffers))
3547 less-significant-buffers)
3549 (if (and (null clean-significant-buffers)
3550 (> (length visible-dired-buffers) 0))
3551 (setq clean-significant-buffers visible-dired-buffers))
3553 (cond (clean-significant-buffers (car clean-significant-buffers))
3554 ;; try also buffers that are not displayed in windows
3555 ((setq less-significant-buffers
3559 (cond ((member (buffer-name x) excl-buff-name-list)
3561 ((eq use-dired-major-mode 'yes)
3562 (if (eq (ediff-with-current-buffer
3566 ((eq (ediff-with-current-buffer x major-mode)
3569 ((string-match "^[ *]" (buffer-name x)) nil)
3570 ((string= "*scratch*" (buffer-name x)) nil)
3573 (car less-significant-buffers))
3578 ;; If current buffer is a Buffer-menu buffer, then take the selected buffers
3579 ;; and append the buffer at the cursor to the end.
3580 ;; This list would be the preferred list.
3581 (defun ediff-get-selected-buffers ()
3582 (if (eq major-mode 'Buffer-menu-mode)
3583 (let ((lis (condition-case nil
3584 (list (Buffer-menu-buffer t))
3588 (goto-char (point-max))
3589 (while (search-backward "\n>" nil t)
3591 (setq lis (cons (Buffer-menu-buffer t) lis)))
3595 ;; Construct a unique buffer name.
3596 ;; The first one tried is prefixsuffix, then prefix<2>suffix,
3597 ;; prefix<3>suffix, etc.
3598 (defun ediff-unique-buffer-name (prefix suffix)
3599 (if (null (get-buffer (concat prefix suffix)))
3600 (concat prefix suffix)
3602 (while (get-buffer (format "%s<%d>%s" prefix n suffix))
3604 (format "%s<%d>%s" prefix n suffix))))
3607 (defun ediff-submit-report ()
3608 "Submit bug report on Ediff."
3610 (ediff-barf-if-not-control-buffer)
3611 (let ((reporter-prompt-for-summary-p t)
3612 (ctl-buf ediff-control-buffer)
3613 (ediff-device-type (ediff-device-type))
3614 varlist salutation buffer-name)
3615 (setq varlist '(ediff-diff-program ediff-diff-options
3616 ediff-patch-program ediff-patch-options
3619 ediff-auto-refine ediff-highlighting-style
3620 ediff-buffer-A ediff-buffer-B ediff-control-buffer
3621 ediff-forward-word-function
3623 ediff-control-frame-parameters
3624 ediff-control-frame-position-function
3625 ediff-prefer-iconified-control-frame
3626 ediff-window-setup-function
3627 ediff-split-window-function
3634 Congratulations! You may have unearthed a bug in Ediff!
3636 Please make a concise and accurate summary of what happened
3637 and mail it to the address above.
3638 -----------------------------------------------------------
3641 (ediff-skip-unsuitable-frames)
3644 (switch-to-buffer ediff-msg-buffer)
3646 (delete-other-windows)
3648 Please read this first:
3649 ----------------------
3651 Some ``bugs'' may actually be no bugs at all. For instance, if you are
3652 reporting that certain difference regions are not matched as you think they
3653 should, this is most likely due to the way Unix diff program decides what
3654 constitutes a difference region. Ediff is an Emacs interface to diff, and
3655 it has nothing to do with those decisions---it only takes the output from
3656 diff and presents it in a way that is better suited for human browsing and
3659 If Emacs happens to dump core, this is NOT an Ediff problem---it is
3660 an Emacs bug. Report this to Emacs maintainers.
3662 Another popular topic for reports is compilation messages. Because Ediff
3663 interfaces to several other packages and runs under Emacs and XEmacs,
3664 byte-compilation may produce output like this:
3666 While compiling toplevel forms in file ediff.el:
3667 ** reference to free variable pm-color-alist
3668 ........................
3669 While compiling the end of the data:
3670 ** The following functions are not known to be defined:
3671 ediff-valid-color-p, ediff-set-face,
3672 ........................
3674 These are NOT errors, but inevitable warnings, which ought to be ignored.
3676 Please do not report those and similar things. However, comments and
3677 suggestions are always welcome.
3679 Mail anyway? (y or n) ")
3681 (if (y-or-n-p "Mail anyway? ")
3683 (if (ediff-buffer-live-p ctl-buf)
3684 (set-buffer ctl-buf))
3685 (setq buffer-name (buffer-name))
3687 (reporter-submit-bug-report "kifer@cs.sunysb.edu"
3691 'delete-other-windows
3694 (beep 1)(message "Bug report aborted")
3695 (if (ediff-buffer-live-p ctl-buf)
3696 (ediff-with-current-buffer ctl-buf
3697 (ediff-recenter 'no-rehighlight))))
3701 ;; Find an appropriate syntax table for everyone to use
3702 ;; If buffer B is not fundamental or text mode, use its syntax table
3703 ;; Otherwise, use buffer B's.
3704 ;; The syntax mode is used in ediff-forward-word-function
3705 ;; The important thing is that every buffer should use the same syntax table
3706 ;; during the refinement operation
3707 (defun ediff-choose-syntax-table ()
3708 (setq ediff-syntax-table
3709 (ediff-with-current-buffer ediff-buffer-A
3710 (if (not (memq major-mode
3711 '(fundamental-mode text-mode indented-text-mode)))
3713 (if (not ediff-syntax-table)
3714 (setq ediff-syntax-table
3715 (ediff-with-current-buffer ediff-buffer-B
3720 (defun ediff-deactivate-mark ()
3722 (zmacs-deactivate-region)
3724 (defun ediff-activate-mark ()
3726 (setq mark-active t)
3727 (zmacs-activate-region)))
3729 (cond ((fboundp 'nuke-selective-display)
3730 ;; XEmacs 19.12 has nuke-selective-display
3731 (fset 'ediff-nuke-selective-display 'nuke-selective-display))
3733 (defun ediff-nuke-selective-display ()
3737 (goto-char (point-min))
3738 (let ((mod-p (buffer-modified-p))
3739 buffer-read-only end)
3740 (and (eq t selective-display)
3741 (while (search-forward "\^M" nil t)
3745 (while (search-forward "\^M" end t)
3748 (set-buffer-modified-p mod-p)
3749 (setq selective-display nil)))))
3753 ;; The next two are modified versions from emerge.el.
3754 ;; VARS must be a list of symbols
3755 ;; ediff-save-variables returns an association list: ((var . val) ...)
3756 (defsubst ediff-save-variables (vars)
3757 (mapcar (lambda (v) (cons v (symbol-value v)))
3759 ;; VARS is a list of variable symbols.
3760 (defun ediff-restore-variables (vars assoc-list)
3762 (set (car vars) (cdr (assoc (car vars) assoc-list)))
3763 (setq vars (cdr vars))))
3765 (defun ediff-change-saved-variable (var value buf-type)
3767 (symbol-value (ediff-get-symbol-from-alist
3769 ediff-buffer-values-orig-alist)))
3770 (assoc-elt (assoc var assoc-list)))
3772 (setcdr assoc-elt value))))
3775 ;; must execute in control buf
3776 (defun ediff-save-protected-variables ()
3777 (setq ediff-buffer-values-orig-A
3778 (ediff-with-current-buffer ediff-buffer-A
3779 (ediff-save-variables ediff-protected-variables)))
3780 (setq ediff-buffer-values-orig-B
3781 (ediff-with-current-buffer ediff-buffer-B
3782 (ediff-save-variables ediff-protected-variables)))
3783 (if ediff-3way-comparison-job
3784 (setq ediff-buffer-values-orig-C
3785 (ediff-with-current-buffer ediff-buffer-C
3786 (ediff-save-variables ediff-protected-variables))))
3787 (if (ediff-buffer-live-p ediff-ancestor-buffer)
3788 (setq ediff-buffer-values-orig-Ancestor
3789 (ediff-with-current-buffer ediff-ancestor-buffer
3790 (ediff-save-variables ediff-protected-variables)))))
3792 ;; must execute in control buf
3793 (defun ediff-restore-protected-variables ()
3794 (let ((values-A ediff-buffer-values-orig-A)
3795 (values-B ediff-buffer-values-orig-B)
3796 (values-C ediff-buffer-values-orig-C)
3797 (values-Ancestor ediff-buffer-values-orig-Ancestor))
3798 (ediff-with-current-buffer ediff-buffer-A
3799 (ediff-restore-variables ediff-protected-variables values-A))
3800 (ediff-with-current-buffer ediff-buffer-B
3801 (ediff-restore-variables ediff-protected-variables values-B))
3802 (if ediff-3way-comparison-job
3803 (ediff-with-current-buffer ediff-buffer-C
3804 (ediff-restore-variables ediff-protected-variables values-C)))
3805 (if (ediff-buffer-live-p ediff-ancestor-buffer)
3806 (ediff-with-current-buffer ediff-ancestor-buffer
3807 (ediff-restore-variables ediff-protected-variables values-Ancestor)))
3810 ;; save BUFFER in FILE. used in hooks.
3811 (defun ediff-save-buffer-in-file (buffer file)
3812 (ediff-with-current-buffer buffer
3818 (ediff-defvar-local ediff-command-begin-time '(0 0 0) "")
3820 ;; calculate time used by command
3821 (defun ediff-calc-command-time ()
3822 (let ((end (current-time))
3825 (if (>= (nth 2 end) (nth 2 ediff-command-begin-time))
3826 (- (nth 2 end) (nth 2 ediff-command-begin-time))
3827 (+ (nth 2 end) (- 1000000 (nth 2 ediff-command-begin-time)))))
3828 (setq sec (- (nth 1 end) (nth 1 ediff-command-begin-time)))
3829 (or (equal ediff-command-begin-time '(0 0 0))
3830 (message "Elapsed time: %d second(s) + %d microsecond(s)" sec micro))))
3832 (defsubst ediff-save-time ()
3833 (setq ediff-command-begin-time (current-time)))
3835 (defun ediff-profile ()
3836 "Toggle profiling Ediff commands."
3838 (ediff-barf-if-not-control-buffer)
3839 (make-local-hook 'post-command-hook)
3840 (let ((pre-hook 'pre-command-hook)
3841 (post-hook 'post-command-hook))
3842 (if (not (equal ediff-command-begin-time '(0 0 0)))
3843 (progn (remove-hook pre-hook 'ediff-save-time)
3844 (remove-hook post-hook 'ediff-calc-command-time)
3845 (setq ediff-command-begin-time '(0 0 0))
3846 (message "Ediff profiling disabled"))
3847 (add-hook pre-hook 'ediff-save-time t t)
3848 (add-hook post-hook 'ediff-calc-command-time nil t)
3849 (message "Ediff profiling enabled"))))
3851 (defun ediff-print-diff-vector (diff-vector-var)
3852 (princ (format "\n*** %S ***\n" diff-vector-var))
3853 (mapcar (lambda (overl-vec)
3856 "Diff %d: \tOverlay: %S
3858 \t\tNo-fine-diff-flag: %S
3859 \t\tState-of-diff:\t %S
3860 \t\tState-of-merge:\t %S
3862 (1+ (ediff-overlay-get (aref overl-vec 0) 'ediff-diff-num))
3865 (if (= (length (aref overl-vec 1)) 0)
3867 (mapconcat 'prin1-to-string
3868 (aref overl-vec 1) "\n\t\t\t "))
3869 (aref overl-vec 2) ; no fine diff flag
3870 (aref overl-vec 3) ; state-of-diff
3871 (aref overl-vec 4) ; state-of-merge
3873 (eval diff-vector-var)))
3877 (defun ediff-debug-info ()
3879 (ediff-barf-if-not-control-buffer)
3880 (with-output-to-temp-buffer ediff-debug-buffer
3881 (ediff-with-current-buffer standard-output
3883 (princ (format "\nCtl buffer: %S\n" ediff-control-buffer))
3884 (ediff-print-diff-vector (intern "ediff-difference-vector-A"))
3885 (ediff-print-diff-vector (intern "ediff-difference-vector-B"))
3886 (ediff-print-diff-vector (intern "ediff-difference-vector-C"))
3887 (ediff-print-diff-vector (intern "ediff-difference-vector-Ancestor"))
3891 ;;; General utilities
3893 ;; this uses comparison-func to decide who is a member
3894 (defun ediff-member (elt lis comparison-func)
3895 (while (and lis (not (funcall comparison-func (car lis) elt)))
3896 (setq lis (cdr lis)))
3899 ;; this uses comparison-func to decide who is a member, and this determines how
3900 ;; intersection looks like
3901 (defun ediff-intersection (lis1 lis2 comparison-func)
3902 (let ((result (list 'a)))
3904 (if (ediff-member (car lis1) lis2 comparison-func)
3905 (nconc result (list (car lis1))))
3906 (setq lis1 (cdr lis1)))
3910 ;; eliminates duplicates using comparison-func
3911 (defun ediff-union (lis1 lis2 comparison-func)
3912 (let ((result (list 'a)))
3914 (or (ediff-member (car lis1) (cdr result) comparison-func)
3915 (nconc result (list (car lis1))))
3916 (setq lis1 (cdr lis1)))
3918 (or (ediff-member (car lis2) (cdr result) comparison-func)
3919 (nconc result (list (car lis2))))
3920 (setq lis2 (cdr lis2)))
3923 ;; eliminates duplicates using comparison-func
3924 (defun ediff-set-difference (lis1 lis2 comparison-func)
3925 (let ((result (list 'a)))
3927 (or (ediff-member (car lis1) (cdr result) comparison-func)
3928 (ediff-member (car lis1) lis2 comparison-func)
3929 (nconc result (list (car lis1))))
3930 (setq lis1 (cdr lis1)))
3933 (if (fboundp 'copy-sequence)
3934 (defalias 'ediff-copy-list 'copy-sequence)
3935 (defun ediff-copy-list (list)
3938 ;;; (while (consp list) (push (pop list) res))
3939 ;;; (prog1 (nreverse res) (setcdr res list)))
3942 (setq elt (car list)
3949 ;; don't report error if version control package wasn't found
3950 ;;(ediff-load-version-control 'silent)
3952 (run-hooks 'ediff-load-hook)
3955 ;;; Local Variables:
3956 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
3957 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
3958 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
3961 ;;; ediff-util.el ends here