* term/mac-win.el: Remove load for ls-lisp.
[bpt/emacs.git] / lisp / ediff-util.el
1 ;;; ediff-util.el --- the core commands and utilities of ediff
2
3 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
4
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
6
7 ;; This file is part of GNU Emacs.
8
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)
12 ;; any later version.
13
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.
18
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.
23
24 ;;; Code:
25
26 (provide 'ediff-util)
27
28 ;; Compiler pacifier
29 (defvar ediff-patch-diagnostics)
30 (defvar ediff-patchbufer)
31 (defvar ediff-use-toolbar-p)
32 (defvar ediff-toolbar-height)
33 (defvar ediff-toolbar)
34 (defvar ediff-toolbar-3way)
35 (defvar bottom-toolbar)
36 (defvar bottom-toolbar-visible-p)
37 (defvar bottom-toolbar-height)
38 (defvar mark-active)
39 (defvar ediff-emacs-p)
40
41 (eval-when-compile
42 (let ((load-path (cons (expand-file-name ".") load-path)))
43 (or (featurep 'ediff-init)
44 (load "ediff-init.el" nil nil 'nosuffix))
45 (or (featurep 'ediff-help)
46 (load "ediff-help.el" nil nil 'nosuffix))
47 (or (featurep 'ediff-mult)
48 (load "ediff-mult.el" nil nil 'nosuffix))
49 (or (featurep 'ediff-wind)
50 (load "ediff-wind.el" nil nil 'nosuffix))
51 (or (featurep 'ediff-diff)
52 (load "ediff-diff.el" nil nil 'nosuffix))
53 (or (featurep 'ediff-merg)
54 (load "ediff-merg.el" nil nil 'nosuffix))
55 (or (featurep 'ediff)
56 (load "ediff.el" nil nil 'nosuffix))
57 (or (featurep 'ediff-tbar)
58 ediff-emacs-p
59 (load "ediff-tbar.el" 'noerror nil 'nosuffix))
60 ))
61 ;; end pacifier
62
63
64 (require 'ediff-init)
65 (require 'ediff-help)
66 (require 'ediff-mult)
67 (require 'ediff-wind)
68 (require 'ediff-diff)
69 (require 'ediff-merg)
70
71 (if ediff-xemacs-p
72 (require 'ediff-tbar))
73
74 \f
75 ;;; Functions
76
77 (defun ediff-mode ()
78 "Ediff mode controls all operations in a single Ediff session.
79 This mode is entered through one of the following commands:
80 `ediff'
81 `ediff-files'
82 `ediff-buffers'
83 `ebuffers'
84 `ediff3'
85 `ediff-files3'
86 `ediff-buffers3'
87 `ebuffers3'
88 `ediff-merge'
89 `ediff-merge-files'
90 `ediff-merge-files-with-ancestor'
91 `ediff-merge-buffers'
92 `ediff-merge-buffers-with-ancestor'
93 `ediff-merge-revisions'
94 `ediff-merge-revisions-with-ancestor'
95 `ediff-windows-wordwise'
96 `ediff-windows-linewise'
97 `ediff-regions-wordwise'
98 `ediff-regions-linewise'
99 `epatch'
100 `ediff-patch-file'
101 `ediff-patch-buffer'
102 `epatch-buffer'
103 `erevision'
104 `ediff-revision'
105
106 Commands:
107 \\{ediff-mode-map}"
108 (kill-all-local-variables)
109 (setq major-mode 'ediff-mode)
110 (setq mode-name "Ediff")
111 (run-hooks 'ediff-mode-hook))
112
113
114 \f
115 ;;; Build keymaps
116
117 (ediff-defvar-local ediff-mode-map nil
118 "Local keymap used in Ediff mode.
119 This is local to each Ediff Control Panel, so they may vary from invocation
120 to invocation.")
121
122 ;; Set up the keymap in the control buffer
123 (defun ediff-set-keys ()
124 "Set up Ediff keymap, if necessary."
125 (if (null ediff-mode-map)
126 (ediff-setup-keymap))
127 (use-local-map ediff-mode-map))
128
129 ;; Reload Ediff keymap. For debugging only.
130 (defun ediff-reload-keymap ()
131 (interactive)
132 (setq ediff-mode-map nil)
133 (ediff-set-keys))
134
135
136 (defun ediff-setup-keymap ()
137 "Set up the keymap used in the control buffer of Ediff."
138 (setq ediff-mode-map (make-sparse-keymap))
139 (suppress-keymap ediff-mode-map)
140
141 (define-key ediff-mode-map
142 (if ediff-emacs-p [mouse-2] [button2]) 'ediff-help-for-quick-help)
143 (define-key ediff-mode-map "\C-m" 'ediff-help-for-quick-help)
144
145 (define-key ediff-mode-map "p" 'ediff-previous-difference)
146 (define-key ediff-mode-map "\C-?" 'ediff-previous-difference)
147 (define-key ediff-mode-map [delete] 'ediff-previous-difference)
148 (define-key ediff-mode-map "\C-h" (if ediff-no-emacs-help-in-control-buffer
149 'ediff-previous-difference nil))
150 ;; must come after C-h, or else C-h wipes out backspace's binding in XEmacs
151 (define-key ediff-mode-map [backspace] 'ediff-previous-difference)
152 (define-key ediff-mode-map "n" 'ediff-next-difference)
153 (define-key ediff-mode-map " " 'ediff-next-difference)
154 (define-key ediff-mode-map "j" 'ediff-jump-to-difference)
155 (define-key ediff-mode-map "g" nil)
156 (define-key ediff-mode-map "ga" 'ediff-jump-to-difference-at-point)
157 (define-key ediff-mode-map "gb" 'ediff-jump-to-difference-at-point)
158 (define-key ediff-mode-map "q" 'ediff-quit)
159 (define-key ediff-mode-map "D" 'ediff-show-diff-output)
160 (define-key ediff-mode-map "z" 'ediff-suspend)
161 (define-key ediff-mode-map "\C-l" 'ediff-recenter)
162 (define-key ediff-mode-map "|" 'ediff-toggle-split)
163 (define-key ediff-mode-map "h" 'ediff-toggle-hilit)
164 (or ediff-word-mode
165 (define-key ediff-mode-map "@" 'ediff-toggle-autorefine))
166 (if ediff-narrow-job
167 (define-key ediff-mode-map "%" 'ediff-toggle-narrow-region))
168 (define-key ediff-mode-map "~" 'ediff-swap-buffers)
169 (define-key ediff-mode-map "v" 'ediff-scroll-vertically)
170 (define-key ediff-mode-map "\C-v" 'ediff-scroll-vertically)
171 (define-key ediff-mode-map "^" 'ediff-scroll-vertically)
172 (define-key ediff-mode-map "\M-v" 'ediff-scroll-vertically)
173 (define-key ediff-mode-map "V" 'ediff-scroll-vertically)
174 (define-key ediff-mode-map "<" 'ediff-scroll-horizontally)
175 (define-key ediff-mode-map ">" 'ediff-scroll-horizontally)
176 (define-key ediff-mode-map "i" 'ediff-status-info)
177 (define-key ediff-mode-map "E" 'ediff-documentation)
178 (define-key ediff-mode-map "?" 'ediff-toggle-help)
179 (define-key ediff-mode-map "!" 'ediff-update-diffs)
180 (define-key ediff-mode-map "M" 'ediff-show-current-session-meta-buffer)
181 (define-key ediff-mode-map "R" 'ediff-show-registry)
182 (or ediff-word-mode
183 (define-key ediff-mode-map "*" 'ediff-make-or-kill-fine-diffs))
184 (define-key ediff-mode-map "a" nil)
185 (define-key ediff-mode-map "b" nil)
186 (define-key ediff-mode-map "r" nil)
187 (cond (ediff-merge-job
188 ;; Will barf if no ancestor
189 (define-key ediff-mode-map "/" 'ediff-show-ancestor)
190 ;; In merging, we allow only A->C and B->C copying.
191 (define-key ediff-mode-map "a" 'ediff-copy-A-to-C)
192 (define-key ediff-mode-map "b" 'ediff-copy-B-to-C)
193 (define-key ediff-mode-map "r" 'ediff-restore-diff-in-merge-buffer)
194 (define-key ediff-mode-map "s" 'ediff-shrink-window-C)
195 (define-key ediff-mode-map "+" 'ediff-combine-diffs)
196 (define-key ediff-mode-map "$" nil)
197 (define-key ediff-mode-map "$$" 'ediff-toggle-show-clashes-only)
198 (define-key ediff-mode-map "$*" 'ediff-toggle-skip-changed-regions)
199 (define-key ediff-mode-map "&" 'ediff-re-merge))
200 (ediff-3way-comparison-job
201 (define-key ediff-mode-map "ab" 'ediff-copy-A-to-B)
202 (define-key ediff-mode-map "ba" 'ediff-copy-B-to-A)
203 (define-key ediff-mode-map "ac" 'ediff-copy-A-to-C)
204 (define-key ediff-mode-map "bc" 'ediff-copy-B-to-C)
205 (define-key ediff-mode-map "c" nil)
206 (define-key ediff-mode-map "ca" 'ediff-copy-C-to-A)
207 (define-key ediff-mode-map "cb" 'ediff-copy-C-to-B)
208 (define-key ediff-mode-map "ra" 'ediff-restore-diff)
209 (define-key ediff-mode-map "rb" 'ediff-restore-diff)
210 (define-key ediff-mode-map "rc" 'ediff-restore-diff)
211 (define-key ediff-mode-map "C" 'ediff-toggle-read-only))
212 (t ; 2-way comparison
213 (define-key ediff-mode-map "a" 'ediff-copy-A-to-B)
214 (define-key ediff-mode-map "b" 'ediff-copy-B-to-A)
215 (define-key ediff-mode-map "ra" 'ediff-restore-diff)
216 (define-key ediff-mode-map "rb" 'ediff-restore-diff))
217 ) ; cond
218 (define-key ediff-mode-map "G" 'ediff-submit-report)
219 (define-key ediff-mode-map "#" nil)
220 (define-key ediff-mode-map "#h" 'ediff-toggle-regexp-match)
221 (define-key ediff-mode-map "#f" 'ediff-toggle-regexp-match)
222 (or ediff-word-mode
223 (define-key ediff-mode-map "##" 'ediff-toggle-skip-similar))
224 (define-key ediff-mode-map "o" nil)
225 (define-key ediff-mode-map "A" 'ediff-toggle-read-only)
226 (define-key ediff-mode-map "B" 'ediff-toggle-read-only)
227 (define-key ediff-mode-map "w" nil)
228 (define-key ediff-mode-map "wa" 'ediff-save-buffer)
229 (define-key ediff-mode-map "wb" 'ediff-save-buffer)
230 (define-key ediff-mode-map "wd" 'ediff-save-buffer)
231 (define-key ediff-mode-map "=" 'ediff-inferior-compare-regions)
232 (if (fboundp 'ediff-show-patch-diagnostics)
233 (define-key ediff-mode-map "P" 'ediff-show-patch-diagnostics))
234 (if ediff-3way-job
235 (progn
236 (define-key ediff-mode-map "wc" 'ediff-save-buffer)
237 (define-key ediff-mode-map "gc" 'ediff-jump-to-difference-at-point)
238 ))
239
240 (define-key ediff-mode-map "m" 'ediff-toggle-wide-display)
241
242 ;; Allow ediff-mode-map to be referenced indirectly
243 (fset 'ediff-mode-map ediff-mode-map)
244 (run-hooks 'ediff-keymap-setup-hook))
245
246
247 ;;; Setup functions
248
249 ;; Common startup entry for all Ediff functions It now returns control buffer
250 ;; so other functions can do post-processing SETUP-PARAMETERS is a list of the
251 ;; form ((param .val) (param . val)...) This serves a similar purpose to
252 ;; STARTUP-HOOKS, but these parameters are set in the new control buffer right
253 ;; after this buf is created and before any windows are set and such.
254 (defun ediff-setup (buffer-A file-A buffer-B file-B buffer-C file-C
255 startup-hooks setup-parameters
256 &optional merge-buffer-file)
257 (run-hooks 'ediff-before-setup-hook)
258 ;; ediff-convert-standard-filename puts file names in the form appropriate
259 ;; for the OS at hand.
260 (setq file-A (ediff-convert-standard-filename (expand-file-name file-A)))
261 (setq file-B (ediff-convert-standard-filename (expand-file-name file-B)))
262 (if (stringp file-C)
263 (setq file-C
264 (ediff-convert-standard-filename (expand-file-name file-C))))
265 (if (stringp merge-buffer-file)
266 (progn
267 (setq merge-buffer-file
268 (ediff-convert-standard-filename
269 (expand-file-name merge-buffer-file)))
270 ;; check the directory exists
271 (or (file-exists-p (file-name-directory merge-buffer-file))
272 (error "Directory %s given as place to save the merge doesn't exist."
273 (abbreviate-file-name
274 (file-name-directory merge-buffer-file))))
275 (if (and (file-exists-p merge-buffer-file)
276 (file-directory-p merge-buffer-file))
277 (error "The merge buffer file %s must not be a directory"
278 (abbreviate-file-name merge-buffer-file)))
279 ))
280 (let* ((control-buffer-name
281 (ediff-unique-buffer-name "*Ediff Control Panel" "*"))
282 (control-buffer (ediff-with-current-buffer buffer-A
283 (get-buffer-create control-buffer-name))))
284 (ediff-with-current-buffer control-buffer
285 (ediff-mode)
286
287 (make-local-variable 'ediff-use-long-help-message)
288 (make-local-variable 'ediff-prefer-iconified-control-frame)
289 (make-local-variable 'ediff-split-window-function)
290 (make-local-variable 'ediff-default-variant)
291 (make-local-variable 'ediff-merge-window-share)
292 (make-local-variable 'ediff-window-setup-function)
293 (make-local-variable 'ediff-keep-variants)
294
295 (make-local-hook 'ediff-after-quit-hook-internal)
296
297 ;; unwrap set up parameters passed as argument
298 (while setup-parameters
299 (set (car (car setup-parameters)) (cdr (car setup-parameters)))
300 (setq setup-parameters (cdr setup-parameters)))
301
302 ;; set variables classifying the current ediff job
303 ;; must come AFTER setup-parameters
304 (setq ediff-3way-comparison-job (ediff-3way-comparison-job)
305 ediff-merge-job (ediff-merge-job)
306 ediff-merge-with-ancestor-job (ediff-merge-with-ancestor-job)
307 ediff-3way-job (ediff-3way-job)
308 ediff-diff3-job (ediff-diff3-job)
309 ediff-narrow-job (ediff-narrow-job)
310 ediff-windows-job (ediff-windows-job)
311 ediff-word-mode-job (ediff-word-mode-job))
312
313 ;; Don't delete variants in case of ediff-buffer-* jobs without asking.
314 ;; This is because u may loose work---dangerous.
315 (if (string-match "buffer" (symbol-name ediff-job-name))
316 (setq ediff-keep-variants t))
317
318 (make-local-hook 'pre-command-hook)
319 (if (ediff-window-display-p)
320 (add-hook 'pre-command-hook 'ediff-spy-after-mouse nil t))
321 (setq ediff-mouse-pixel-position (mouse-pixel-position))
322
323 ;; adjust for merge jobs
324 (if ediff-merge-job
325 (let ((buf
326 ;; If default variant is `combined', the right stuff is
327 ;; inserted by ediff-do-merge
328 ;; Note: at some point, we tried to put ancestor buffer here
329 ;; (which is currently buffer C. This didn't work right
330 ;; because the merge buffer will contain lossage: diff regions
331 ;; in the ancestor, which correspond to revisions that agree
332 ;; in both buf A and B.
333 (cond ((eq ediff-default-variant 'default-B)
334 buffer-B)
335 (t buffer-A))))
336
337 (setq ediff-split-window-function
338 ediff-merge-split-window-function)
339
340 ;; remember the ancestor buffer, if any
341 (setq ediff-ancestor-buffer buffer-C)
342
343 (setq buffer-C
344 (get-buffer-create
345 (ediff-unique-buffer-name "*ediff-merge" "*")))
346 (save-excursion
347 (set-buffer buffer-C)
348 (insert-buffer buf)
349 (funcall (ediff-with-current-buffer buf major-mode))
350 (add-hook 'local-write-file-hooks 'ediff-set-merge-mode nil t)
351 )))
352 (setq buffer-read-only nil
353 ediff-buffer-A buffer-A
354 ediff-buffer-B buffer-B
355 ediff-buffer-C buffer-C
356 ediff-control-buffer control-buffer)
357
358 (setq ediff-control-buffer-suffix
359 (if (string-match "<[0-9]*>" control-buffer-name)
360 (substring control-buffer-name
361 (match-beginning 0) (match-end 0))
362 "")
363 ediff-control-buffer-number
364 (max
365 0
366 (1-
367 (string-to-number
368 (substring
369 ediff-control-buffer-suffix
370 (or
371 (string-match "[0-9]+" ediff-control-buffer-suffix)
372 0))))))
373
374 (setq ediff-error-buffer
375 (get-buffer-create (ediff-unique-buffer-name "*ediff-errors" "*")))
376
377 (ediff-with-current-buffer buffer-A (ediff-strip-mode-line-format))
378 (ediff-with-current-buffer buffer-B (ediff-strip-mode-line-format))
379 (if ediff-3way-job
380 (ediff-with-current-buffer buffer-C (ediff-strip-mode-line-format)))
381 (if (ediff-buffer-live-p ediff-ancestor-buffer)
382 (ediff-with-current-buffer ediff-ancestor-buffer
383 (ediff-strip-mode-line-format)))
384
385 (ediff-save-protected-variables) ; save variables to be restored on exit
386
387 ;; ediff-setup-diff-regions-function must be set after setup
388 ;; parameters are processed.
389 (setq ediff-setup-diff-regions-function
390 (if ediff-diff3-job
391 'ediff-setup-diff-regions3
392 'ediff-setup-diff-regions))
393
394 (setq ediff-wide-bounds
395 (list (ediff-make-bullet-proof-overlay
396 '(point-min) '(point-max) ediff-buffer-A)
397 (ediff-make-bullet-proof-overlay
398 '(point-min) '(point-max) ediff-buffer-B)
399 (ediff-make-bullet-proof-overlay
400 '(point-min) '(point-max) ediff-buffer-C)))
401
402 ;; This has effect only on ediff-windows/regions
403 ;; In all other cases, ediff-visible-region sets visibility bounds to
404 ;; ediff-wide-bounds, and ediff-narrow-bounds are ignored.
405 (if ediff-start-narrowed
406 (setq ediff-visible-bounds ediff-narrow-bounds)
407 (setq ediff-visible-bounds ediff-wide-bounds))
408
409 (ediff-set-keys) ; comes after parameter setup
410
411 ;; set up ediff-narrow-bounds, if not set
412 (or ediff-narrow-bounds
413 (setq ediff-narrow-bounds ediff-wide-bounds))
414
415 ;; All these must be inside ediff-with-current-buffer control-buffer,
416 ;; since these vars are local to control-buffer
417 ;; These won't run if there are errors in diff
418 (ediff-with-current-buffer ediff-buffer-A
419 (ediff-nuke-selective-display)
420 (run-hooks 'ediff-prepare-buffer-hook)
421 (if (ediff-with-current-buffer control-buffer ediff-merge-job)
422 (setq buffer-read-only t))
423 ;; add control-buffer to the list of sessions--no longer used, but may
424 ;; be used again in the future
425 (or (memq control-buffer ediff-this-buffer-ediff-sessions)
426 (setq ediff-this-buffer-ediff-sessions
427 (cons control-buffer ediff-this-buffer-ediff-sessions)))
428 (if ediff-make-buffers-readonly-at-startup
429 (setq buffer-read-only t))
430 )
431
432 (ediff-with-current-buffer ediff-buffer-B
433 (ediff-nuke-selective-display)
434 (run-hooks 'ediff-prepare-buffer-hook)
435 (if (ediff-with-current-buffer control-buffer ediff-merge-job)
436 (setq buffer-read-only t))
437 ;; add control-buffer to the list of sessions
438 (or (memq control-buffer ediff-this-buffer-ediff-sessions)
439 (setq ediff-this-buffer-ediff-sessions
440 (cons control-buffer ediff-this-buffer-ediff-sessions)))
441 (if ediff-make-buffers-readonly-at-startup
442 (setq buffer-read-only t))
443 )
444
445 (if ediff-3way-job
446 (ediff-with-current-buffer ediff-buffer-C
447 (ediff-nuke-selective-display)
448 (run-hooks 'ediff-prepare-buffer-hook)
449 ;; add control-buffer to the list of sessions
450 (or (memq control-buffer ediff-this-buffer-ediff-sessions)
451 (setq ediff-this-buffer-ediff-sessions
452 (cons control-buffer
453 ediff-this-buffer-ediff-sessions)))
454 (if ediff-make-buffers-readonly-at-startup
455 (setq buffer-read-only t))
456 ))
457
458 (if (ediff-buffer-live-p ediff-ancestor-buffer)
459 (ediff-with-current-buffer ediff-ancestor-buffer
460 (ediff-nuke-selective-display)
461 (setq buffer-read-only t)
462 (run-hooks 'ediff-prepare-buffer-hook)
463 (or (memq control-buffer ediff-this-buffer-ediff-sessions)
464 (setq ediff-this-buffer-ediff-sessions
465 (cons control-buffer
466 ediff-this-buffer-ediff-sessions)))
467 ))
468
469 ;; must come after setting up ediff-narrow-bounds AND after
470 ;; nuking selective display
471 (funcall ediff-setup-diff-regions-function file-A file-B file-C)
472 (setq ediff-number-of-differences (length ediff-difference-vector-A))
473 (setq ediff-current-difference -1)
474
475 (ediff-make-current-diff-overlay 'A)
476 (ediff-make-current-diff-overlay 'B)
477 (if ediff-3way-job
478 (ediff-make-current-diff-overlay 'C))
479 (if ediff-merge-with-ancestor-job
480 (ediff-make-current-diff-overlay 'Ancestor))
481
482 (ediff-setup-windows buffer-A buffer-B buffer-C control-buffer)
483
484 (let ((shift-A (ediff-overlay-start
485 (ediff-get-value-according-to-buffer-type
486 'A ediff-narrow-bounds)))
487 (shift-B (ediff-overlay-start
488 (ediff-get-value-according-to-buffer-type
489 'B ediff-narrow-bounds)))
490 (shift-C (ediff-overlay-start
491 (ediff-get-value-according-to-buffer-type
492 'C ediff-narrow-bounds))))
493 ;; position point in buf A
494 (save-excursion
495 (select-window ediff-window-A)
496 (goto-char shift-A))
497 ;; position point in buf B
498 (save-excursion
499 (select-window ediff-window-B)
500 (goto-char shift-B))
501 (if ediff-3way-job
502 (save-excursion
503 (select-window ediff-window-C)
504 (goto-char shift-C)))
505 )
506
507 (select-window ediff-control-window)
508 (ediff-visible-region)
509
510 (run-hooks 'startup-hooks)
511 (ediff-arrange-autosave-in-merge-jobs merge-buffer-file)
512
513 (ediff-refresh-mode-lines)
514 (setq buffer-read-only t)
515 (setq ediff-session-registry
516 (cons control-buffer ediff-session-registry))
517 (ediff-update-registry)
518 (if (ediff-buffer-live-p ediff-meta-buffer)
519 (ediff-update-meta-buffer
520 ediff-meta-buffer nil ediff-meta-session-number))
521 (run-hooks 'ediff-startup-hook)
522 ) ; eval in control-buffer
523 control-buffer))
524
525
526 ;; This function assumes that we are in the window where control buffer is
527 ;; to reside.
528 (defun ediff-setup-control-buffer (ctl-buf)
529 "Set up window for control buffer."
530 (if (window-dedicated-p (selected-window))
531 (set-buffer ctl-buf) ; we are in control frame but just in case
532 (switch-to-buffer ctl-buf))
533 (let ((window-min-height 2))
534 (erase-buffer)
535 (ediff-set-help-message)
536 (insert ediff-help-message)
537 (shrink-window-if-larger-than-buffer)
538 (or (ediff-multiframe-setup-p)
539 (ediff-indent-help-message))
540 (ediff-set-help-overlays)
541
542 (set-buffer-modified-p nil)
543 (ediff-refresh-mode-lines)
544 (setq ediff-control-window (selected-window))
545 (setq ediff-window-config-saved
546 (format "%S%S%S%S%S%S%S"
547 ediff-control-window
548 ediff-window-A
549 ediff-window-B
550 ediff-window-C
551 ediff-split-window-function
552 (ediff-multiframe-setup-p)
553 ediff-wide-display-p))
554
555 ;; In multiframe, toolbar is set in ediff-setup-control-frame
556 (if (not (ediff-multiframe-setup-p))
557 (ediff-make-bottom-toolbar)) ; this checks if toolbar is requested
558 (goto-char (point-min))
559 (skip-chars-forward ediff-whitespace)))
560
561 ;; This executes in control buffer and sets auto-save, visited file name, etc,
562 ;; in the merge buffer
563 (defun ediff-arrange-autosave-in-merge-jobs (merge-buffer-file)
564 (if (not ediff-merge-job)
565 ()
566 (if (stringp merge-buffer-file)
567 (setq ediff-autostore-merges t
568 ediff-merge-store-file merge-buffer-file))
569 (if (stringp ediff-merge-store-file)
570 (progn
571 ;; save before leaving ctl buffer
572 (setq merge-buffer-file ediff-merge-store-file)
573 (ediff-with-current-buffer ediff-buffer-C
574 (set-visited-file-name merge-buffer-file))))
575 (ediff-with-current-buffer ediff-buffer-C
576 (setq buffer-offer-save t) ; ask before killing buffer
577 ;; make sure the contents is auto-saved
578 (auto-save-mode 1))
579 ))
580
581 \f
582 ;;; Commands for working with Ediff
583
584 (defun ediff-update-diffs ()
585 "Recompute difference regions in buffers A, B, and C.
586 Buffers are not synchronized with their respective files, so changes done
587 to these buffers are not saved at this point---the user can do this later,
588 if necessary."
589 (interactive)
590 (ediff-barf-if-not-control-buffer)
591 (if (and (ediff-buffer-live-p ediff-ancestor-buffer)
592 (not
593 (y-or-n-p
594 "Ancestor buffer will not be used. Recompute diffs anyway? ")))
595 (error "Recomputation of differences canceled"))
596
597 (let ((point-A (ediff-with-current-buffer ediff-buffer-A (point)))
598 ;;(point-B (ediff-with-current-buffer ediff-buffer-B (point)))
599 (tmp-buffer (get-buffer-create ediff-tmp-buffer))
600 (buf-A-file-name (buffer-file-name ediff-buffer-A))
601 (buf-B-file-name (buffer-file-name ediff-buffer-B))
602 ;; (null ediff-buffer-C) is no problem, as we later check if
603 ;; ediff-buffer-C is alive
604 (buf-C-file-name (buffer-file-name ediff-buffer-C))
605 (overl-A (ediff-get-value-according-to-buffer-type
606 'A ediff-narrow-bounds))
607 (overl-B (ediff-get-value-according-to-buffer-type
608 'B ediff-narrow-bounds))
609 (overl-C (ediff-get-value-according-to-buffer-type
610 'C ediff-narrow-bounds))
611 beg-A end-A beg-B end-B beg-C end-C
612 file-A file-B file-C)
613
614 (if (stringp buf-A-file-name)
615 (setq buf-A-file-name (file-name-nondirectory buf-A-file-name)))
616 (if (stringp buf-B-file-name)
617 (setq buf-B-file-name (file-name-nondirectory buf-B-file-name)))
618 (if (stringp buf-C-file-name)
619 (setq buf-C-file-name (file-name-nondirectory buf-C-file-name)))
620
621 (ediff-unselect-and-select-difference -1)
622
623 (setq beg-A (ediff-overlay-start overl-A)
624 beg-B (ediff-overlay-start overl-B)
625 beg-C (ediff-overlay-start overl-C)
626 end-A (ediff-overlay-end overl-A)
627 end-B (ediff-overlay-end overl-B)
628 end-C (ediff-overlay-end overl-C))
629
630 (if ediff-word-mode
631 (progn
632 (ediff-wordify beg-A end-A ediff-buffer-A tmp-buffer)
633 (setq file-A (ediff-make-temp-file tmp-buffer "regA"))
634 (ediff-wordify beg-B end-B ediff-buffer-B tmp-buffer)
635 (setq file-B (ediff-make-temp-file tmp-buffer "regB"))
636 (if ediff-3way-job
637 (progn
638 (ediff-wordify beg-C end-C ediff-buffer-C tmp-buffer)
639 (setq file-C (ediff-make-temp-file tmp-buffer "regC"))))
640 )
641 ;; not word-mode
642 (setq file-A (ediff-make-temp-file ediff-buffer-A buf-A-file-name))
643 (setq file-B (ediff-make-temp-file ediff-buffer-B buf-B-file-name))
644 (if ediff-3way-job
645 (setq file-C (ediff-make-temp-file ediff-buffer-C buf-C-file-name)))
646 )
647
648 (ediff-clear-diff-vector 'ediff-difference-vector-A 'fine-diffs-also)
649 (ediff-clear-diff-vector 'ediff-difference-vector-B 'fine-diffs-also)
650 (ediff-clear-diff-vector 'ediff-difference-vector-C 'fine-diffs-also)
651 (ediff-clear-diff-vector
652 'ediff-difference-vector-Ancestor 'fine-diffs-also)
653 ;; let them garbage collect. we can't use the ancestor after recomputing
654 ;; the diffs.
655 (setq ediff-difference-vector-Ancestor nil
656 ediff-ancestor-buffer nil
657 ediff-state-of-merge nil)
658
659 (setq ediff-killed-diffs-alist nil) ; invalidate saved killed diff regions
660
661 ;; In case of merge job, fool it into thinking that it is just doing
662 ;; comparison
663 (let ((ediff-setup-diff-regions-function ediff-setup-diff-regions-function)
664 (ediff-3way-comparison-job ediff-3way-comparison-job)
665 (ediff-merge-job ediff-merge-job)
666 (ediff-merge-with-ancestor-job ediff-merge-with-ancestor-job)
667 (ediff-job-name ediff-job-name))
668 (if ediff-merge-job
669 (setq ediff-setup-diff-regions-function 'ediff-setup-diff-regions3
670 ediff-3way-comparison-job t
671 ediff-merge-job nil
672 ediff-merge-with-ancestor-job nil
673 ediff-job-name 'ediff-files3))
674 (funcall ediff-setup-diff-regions-function file-A file-B file-C))
675
676 (setq ediff-number-of-differences (length ediff-difference-vector-A))
677 (delete-file file-A)
678 (delete-file file-B)
679 (if file-C
680 (delete-file file-C))
681
682 (if ediff-3way-job
683 (ediff-set-state-of-all-diffs-in-all-buffers ediff-control-buffer))
684
685 (ediff-jump-to-difference (ediff-diff-at-point 'A point-A))
686 (message "")
687 ))
688
689 ;; Not bound to any key---to dangerous. A user can do it if necessary.
690 (defun ediff-revert-buffers-then-recompute-diffs (noconfirm)
691 "Revert buffers A, B and C. Then rerun Ediff on file A and file B."
692 (interactive "P")
693 (ediff-barf-if-not-control-buffer)
694 (let ((bufA ediff-buffer-A)
695 (bufB ediff-buffer-B)
696 (bufC ediff-buffer-C)
697 (ctl-buf ediff-control-buffer)
698 (keep-variants ediff-keep-variants)
699 (ancestor-buf ediff-ancestor-buffer)
700 (ancestor-job ediff-merge-with-ancestor-job)
701 (merge ediff-merge-job)
702 (comparison ediff-3way-comparison-job))
703 (ediff-with-current-buffer bufA
704 (revert-buffer t noconfirm))
705 (ediff-with-current-buffer bufB
706 (revert-buffer t noconfirm))
707 ;; this should only be executed in a 3way comparison, not in merge
708 (if comparison
709 (ediff-with-current-buffer bufC
710 (revert-buffer t noconfirm)))
711 (if merge
712 (progn
713 (set-buffer ctl-buf)
714 ;; the argument says whether to reverse the meaning of
715 ;; ediff-keep-variants, i.e., ediff-really-quit runs here with
716 ;; variants kept.
717 (ediff-really-quit (not keep-variants))
718 (kill-buffer bufC)
719 (if ancestor-job
720 (ediff-merge-buffers-with-ancestor bufA bufB ancestor-buf)
721 (ediff-merge-buffers bufA bufB)))
722 (ediff-update-diffs))))
723
724
725 ;; optional NO-REHIGHLIGHT says to not rehighlight buffers
726 (defun ediff-recenter (&optional no-rehighlight)
727 "Bring the highlighted region of all buffers being compared into view.
728 Reestablish the default three-window display."
729 (interactive)
730 (ediff-barf-if-not-control-buffer)
731 (let (buffer-read-only)
732 (if (and (ediff-buffer-live-p ediff-buffer-A)
733 (ediff-buffer-live-p ediff-buffer-B)
734 (or (not ediff-3way-job)
735 (ediff-buffer-live-p ediff-buffer-C)))
736 (ediff-setup-windows
737 ediff-buffer-A ediff-buffer-B ediff-buffer-C ediff-control-buffer)
738 (or (eq this-command 'ediff-quit)
739 (message ediff-KILLED-VITAL-BUFFER
740 (beep 1)))
741 ))
742
743 ;; set visibility range appropriate to this invocation of Ediff.
744 (ediff-visible-region)
745 ;; raise
746 (if (and (ediff-window-display-p)
747 (symbolp this-command)
748 (symbolp last-command)
749 ;; Either one of the display-changing commands
750 (or (memq this-command
751 '(ediff-recenter
752 ediff-dir-action ediff-registry-action
753 ediff-patch-action
754 ediff-toggle-wide-display ediff-toggle-multiframe))
755 ;; Or one of the movement cmds and prev cmd was an Ediff cmd
756 ;; This avoids raising frames unnecessarily.
757 (and (memq this-command
758 '(ediff-next-difference
759 ediff-previous-difference
760 ediff-jump-to-difference
761 ediff-jump-to-difference-at-point))
762 (not (string-match "^ediff-" (symbol-name last-command)))
763 )))
764 (progn
765 (if (window-live-p ediff-window-A)
766 (raise-frame (window-frame ediff-window-A)))
767 (if (window-live-p ediff-window-B)
768 (raise-frame (window-frame ediff-window-B)))
769 (if (window-live-p ediff-window-C)
770 (raise-frame (window-frame ediff-window-C)))))
771 (if (and (ediff-window-display-p)
772 (frame-live-p ediff-control-frame)
773 (not ediff-use-long-help-message)
774 (not (ediff-frame-iconified-p ediff-control-frame)))
775 (raise-frame ediff-control-frame))
776
777 ;; Redisplay whatever buffers are showing, if there is a selected difference
778 (let ((control-frame ediff-control-frame)
779 (control-buf ediff-control-buffer))
780 (if (and (ediff-buffer-live-p ediff-buffer-A)
781 (ediff-buffer-live-p ediff-buffer-B)
782 (or (not ediff-3way-job)
783 (ediff-buffer-live-p ediff-buffer-C)))
784 (progn
785 (or no-rehighlight
786 (ediff-select-difference ediff-current-difference))
787
788 (ediff-recenter-one-window 'A)
789 (ediff-recenter-one-window 'B)
790 (if ediff-3way-job
791 (ediff-recenter-one-window 'C))
792
793 (ediff-with-current-buffer control-buf
794 (ediff-recenter-ancestor) ; check if ancestor is alive
795
796 (if (and (ediff-multiframe-setup-p)
797 (not ediff-use-long-help-message)
798 (not (ediff-frame-iconified-p ediff-control-frame)))
799 ;; never grab mouse on quit in this place
800 (ediff-reset-mouse
801 control-frame
802 (eq this-command 'ediff-quit))))
803 ))
804
805 (ediff-restore-highlighting)
806 (ediff-with-current-buffer control-buf (ediff-refresh-mode-lines))
807 ))
808
809 ;; this function returns to the window it was called from
810 ;; (which was the control window)
811 (defun ediff-recenter-one-window (buf-type)
812 (if (ediff-valid-difference-p)
813 ;; context must be saved before switching to windows A/B/C
814 (let* ((ctl-wind (selected-window))
815 (shift (ediff-overlay-start
816 (ediff-get-value-according-to-buffer-type
817 buf-type ediff-narrow-bounds)))
818 (job-name ediff-job-name)
819 (control-buf ediff-control-buffer)
820 (window-name (ediff-get-symbol-from-alist
821 buf-type ediff-window-alist))
822 (window (if (window-live-p (symbol-value window-name))
823 (symbol-value window-name))))
824
825 (if (and window ediff-windows-job)
826 (set-window-start window shift))
827 (if window
828 (progn
829 (select-window window)
830 (ediff-deactivate-mark)
831 (ediff-position-region
832 (ediff-get-diff-posn buf-type 'beg nil control-buf)
833 (ediff-get-diff-posn buf-type 'end nil control-buf)
834 (ediff-get-diff-posn buf-type 'beg nil control-buf)
835 job-name
836 )))
837 (select-window ctl-wind)
838 )))
839
840 (defun ediff-recenter-ancestor ()
841 ;; do half-hearted job by recentering the ancestor buffer, if it is alive and
842 ;; visible.
843 (if (and (ediff-buffer-live-p ediff-ancestor-buffer)
844 (ediff-valid-difference-p))
845 (let ((window (ediff-get-visible-buffer-window ediff-ancestor-buffer))
846 (ctl-wind (selected-window))
847 (job-name ediff-job-name)
848 (ctl-buf ediff-control-buffer))
849 (ediff-with-current-buffer ediff-ancestor-buffer
850 (goto-char (ediff-get-diff-posn 'Ancestor 'beg nil ctl-buf))
851 (if window
852 (progn
853 (select-window window)
854 (ediff-position-region
855 (ediff-get-diff-posn 'Ancestor 'beg nil ctl-buf)
856 (ediff-get-diff-posn 'Ancestor 'end nil ctl-buf)
857 (ediff-get-diff-posn 'Ancestor 'beg nil ctl-buf)
858 job-name))))
859 (select-window ctl-wind)
860 )))
861
862
863 ;; This will have to be refined for 3way jobs
864 (defun ediff-toggle-split ()
865 "Toggle vertical/horizontal window split.
866 Does nothing if file-A and file-B are in different frames."
867 (interactive)
868 (ediff-barf-if-not-control-buffer)
869 (let* ((wind-A (if (window-live-p ediff-window-A) ediff-window-A))
870 (wind-B (if (window-live-p ediff-window-B) ediff-window-B))
871 (wind-C (if (window-live-p ediff-window-C) ediff-window-C))
872 (frame-A (if wind-A (window-frame wind-A)))
873 (frame-B (if wind-B (window-frame wind-B)))
874 (frame-C (if wind-C (window-frame wind-C))))
875 (if (or (eq frame-A frame-B)
876 (not (frame-live-p frame-A))
877 (not (frame-live-p frame-B))
878 (if ediff-3way-comparison-job
879 (or (not (frame-live-p frame-C))
880 (eq frame-A frame-C) (eq frame-B frame-C))))
881 (setq ediff-split-window-function
882 (if (eq ediff-split-window-function 'split-window-vertically)
883 'split-window-horizontally
884 'split-window-vertically))
885 (message "Buffers being compared are in different frames"))
886 (ediff-recenter 'no-rehighlight)))
887
888 (defun ediff-toggle-hilit ()
889 "Switch between highlighting using ASCII flags and highlighting using faces.
890 On a dumb terminal, switches between ASCII highlighting and no highlighting."
891 (interactive)
892 (ediff-barf-if-not-control-buffer)
893 (if (not (ediff-has-face-support-p))
894 (if (eq ediff-highlighting-style 'ascii)
895 (progn
896 (message "ASCII highlighting flags removed")
897 (ediff-unselect-and-select-difference ediff-current-difference
898 'unselect-only)
899 (setq ediff-highlighting-style 'off))
900 (ediff-unselect-and-select-difference ediff-current-difference
901 'select-only))
902 (ediff-unselect-and-select-difference ediff-current-difference
903 'unselect-only)
904 ;; cycle through highlighting
905 (cond ((and ediff-use-faces ediff-highlight-all-diffs)
906 (message "Unhighlighting unselected difference regions")
907 (setq ediff-highlight-all-diffs nil))
908 (ediff-use-faces
909 (message "Highlighting with ASCII flags")
910 (setq ediff-use-faces nil))
911 (t
912 (message "Re-highlighting all difference regions")
913 (setq ediff-use-faces t
914 ediff-highlight-all-diffs t)))
915
916 (if (and ediff-use-faces ediff-highlight-all-diffs)
917 (ediff-paint-background-regions)
918 (ediff-paint-background-regions 'unhighlight))
919
920 (ediff-unselect-and-select-difference
921 ediff-current-difference 'select-only))
922 )
923
924
925 (defun ediff-toggle-autorefine ()
926 "Toggle auto-refine mode."
927 (interactive)
928 (ediff-barf-if-not-control-buffer)
929 (if ediff-word-mode
930 (error "No fine differences in this mode"))
931 (cond ((eq ediff-auto-refine 'nix)
932 (setq ediff-auto-refine 'on)
933 (ediff-make-fine-diffs ediff-current-difference 'noforce)
934 (message "Auto-refining is ON"))
935 ((eq ediff-auto-refine 'on)
936 (message "Auto-refining is OFF")
937 (setq ediff-auto-refine 'off))
938 (t ;; nix 'em
939 (ediff-set-fine-diff-properties ediff-current-difference 'default)
940 (message "Refinements are HIDDEN")
941 (setq ediff-auto-refine 'nix))
942 ))
943
944 (defun ediff-show-ancestor ()
945 "Show the ancestor buffer in a suitable window."
946 (interactive)
947 (ediff-recenter)
948 (or (ediff-buffer-live-p ediff-ancestor-buffer)
949 (if ediff-merge-with-ancestor-job
950 (error "Lost connection to ancestor buffer...sorry")
951 (error "Not merging with ancestor")))
952 (let (wind)
953 (cond ((setq wind (ediff-get-visible-buffer-window ediff-ancestor-buffer))
954 (raise-frame (window-frame wind)))
955 (t (set-window-buffer ediff-window-C ediff-ancestor-buffer)))))
956
957 (defun ediff-make-or-kill-fine-diffs (arg)
958 "Compute fine diffs. With negative prefix arg, kill fine diffs.
959 In both cases, operates on the current difference region."
960 (interactive "P")
961 (ediff-barf-if-not-control-buffer)
962 (cond ((eq arg '-)
963 (ediff-clear-fine-differences ediff-current-difference))
964 ((and (numberp arg) (< arg 0))
965 (ediff-clear-fine-differences ediff-current-difference))
966 (t (ediff-make-fine-diffs))))
967
968
969 (defun ediff-toggle-help ()
970 "Toggle short/long help message."
971 (interactive)
972 (ediff-barf-if-not-control-buffer)
973 (let (buffer-read-only)
974 (erase-buffer)
975 (setq ediff-use-long-help-message (not ediff-use-long-help-message))
976 (ediff-set-help-message))
977 ;; remember the icon status of the control frame when the user requested
978 ;; full control message
979 (if (and ediff-use-long-help-message (ediff-multiframe-setup-p))
980 (setq ediff-prefer-iconified-control-frame
981 (ediff-frame-iconified-p ediff-control-frame)))
982
983 (setq ediff-window-config-saved "") ; force redisplay
984 (ediff-recenter 'no-rehighlight))
985
986
987 ;; If BUF, this is the buffer to toggle, not current buffer.
988 (defun ediff-toggle-read-only (&optional buf)
989 "Toggle read-only in current buffer.
990 If buffer is under version control and locked, check it out first.
991 If optional argument BUF is specified, toggle read-only in that buffer instead
992 of the current buffer."
993 (interactive)
994 (ediff-barf-if-not-control-buffer)
995 (let ((ctl-buf (if (null buf) (current-buffer)))
996 (buf-type (ediff-char-to-buftype last-command-char)))
997 (or buf (ediff-recenter))
998 (or buf
999 (setq buf (ediff-get-buffer buf-type)))
1000
1001 (ediff-with-current-buffer buf ; eval in buf A/B/C
1002 (let* ((file (buffer-file-name buf))
1003 (file-writable (and file
1004 (file-exists-p file)
1005 (file-writable-p file)))
1006 (toggle-ro-cmd (cond (ediff-toggle-read-only-function)
1007 ((ediff-file-checked-out-p file)
1008 'toggle-read-only)
1009 (file-writable 'toggle-read-only)
1010 (t (key-binding "\C-x\C-q")))))
1011 ;; If the file is checked in, make sure we don't make buffer modifiable
1012 ;; without warning the user. The user can fool our checks by making the
1013 ;; buffer non-RO without checking the file out. We regard this as a
1014 ;; user problem.
1015 (if (and (ediff-file-checked-in-p file)
1016 ;; If ctl-buf is null, this means we called this
1017 ;; non-interactively, in which case don't ask questions
1018 ctl-buf)
1019 (cond ((not buffer-read-only)
1020 (setq toggle-ro-cmd 'toggle-read-only))
1021 ((and (or (beep 1) t) ; always beep
1022 (y-or-n-p
1023 (format
1024 "File %s is under version control. Check it out? "
1025 (ediff-abbreviate-file-name file))))
1026 ;; if we checked the file out, we should also change the
1027 ;; original state of buffer-read-only to nil. If we don't
1028 ;; do this, the mode line will show %%, since the file was
1029 ;; RO before ediff started, so the user will think the file
1030 ;; is checked in.
1031 (ediff-with-current-buffer ctl-buf
1032 (ediff-change-saved-variable
1033 'buffer-read-only nil buf-type)))
1034 (t
1035 (setq toggle-ro-cmd 'toggle-read-only)
1036 (beep 1) (beep 1)
1037 (message
1038 "Boy, this is risky! Don't modify this file...")
1039 (sit-for 3)))) ; let the user see the warning
1040 (if (and toggle-ro-cmd
1041 (string-match "toggle-read-only" (symbol-name toggle-ro-cmd)))
1042 (save-excursion
1043 (save-window-excursion
1044 (select-window (ediff-get-visible-buffer-window buf))
1045 (command-execute toggle-ro-cmd)))
1046 (error "Don't know how to toggle read-only in buffer %S" buf))
1047
1048 ;; Check if we made the current buffer updatable, but its file is RO.
1049 ;; Signal a warning in this case.
1050 (if (and file (not buffer-read-only)
1051 (eq this-command 'ediff-toggle-read-only)
1052 (file-exists-p file)
1053 (not (file-writable-p file)))
1054 (message "Warning: file %s is read-only"
1055 (ediff-abbreviate-file-name file) (beep 1)))
1056 ))))
1057
1058 ;; checkout if visited file is checked in
1059 (defun ediff-maybe-checkout (buf)
1060 (let ((file (expand-file-name (buffer-file-name buf)))
1061 (checkout-function (key-binding "\C-x\C-q")))
1062 (if (and (ediff-file-checked-in-p file)
1063 (or (beep 1) t)
1064 (y-or-n-p
1065 (format
1066 "File %s is under version control. Check it out? "
1067 (ediff-abbreviate-file-name file))))
1068 (ediff-with-current-buffer buf
1069 (command-execute checkout-function)))))
1070
1071
1072 ;; This is a simple-minded check for whether a file is under version control.
1073 ;; If file,v exists but file doesn't, this file is considered to be not checked
1074 ;; in and not checked out for the purpose of patching (since patch won't be
1075 ;; able to read such a file anyway).
1076 ;; FILE is a string representing file name
1077 ;;(defun ediff-file-under-version-control (file)
1078 ;; (let* ((filedir (file-name-directory file))
1079 ;; (file-nondir (file-name-nondirectory file))
1080 ;; (trial (concat file-nondir ",v"))
1081 ;; (full-trial (concat filedir trial))
1082 ;; (full-rcs-trial (concat filedir "RCS/" trial)))
1083 ;; (and (stringp file)
1084 ;; (file-exists-p file)
1085 ;; (or
1086 ;; (and
1087 ;; (file-exists-p full-trial)
1088 ;; ;; in FAT FS, `file,v' and `file' may turn out to be the same!
1089 ;; ;; don't be fooled by this!
1090 ;; (not (equal (file-attributes file)
1091 ;; (file-attributes full-trial))))
1092 ;; ;; check if a version is in RCS/ directory
1093 ;; (file-exists-p full-rcs-trial)))
1094 ;; ))
1095
1096
1097 (defsubst ediff-file-checked-out-p (file)
1098 (or (not (featurep 'vc-hooks))
1099 (and (vc-backend file)
1100 (or (memq (vc-state file) '(edited needs-merge))
1101 (stringp (vc-state file))))))
1102
1103 (defsubst ediff-file-checked-in-p (file)
1104 (and (featurep 'vc-hooks)
1105 ;; CVS files are considered not checked in
1106 (not (memq (vc-backend file) '(nil CVS)))
1107 (not (memq (vc-state file) '(edited needs-merge)))
1108 (not (stringp (vc-state file)))))
1109
1110 (defun ediff-file-compressed-p (file)
1111 (condition-case nil
1112 (require 'jka-compr)
1113 (error))
1114 (if (featurep 'jka-compr)
1115 (string-match (jka-compr-build-file-regexp) file)))
1116
1117
1118 (defun ediff-swap-buffers ()
1119 "Rotate the display of buffers A, B, and C."
1120 (interactive)
1121 (ediff-barf-if-not-control-buffer)
1122 (if (and (window-live-p ediff-window-A) (window-live-p ediff-window-B))
1123 (let ((buf ediff-buffer-A)
1124 (values ediff-buffer-values-orig-A)
1125 (diff-vec ediff-difference-vector-A)
1126 (hide-regexp ediff-regexp-hide-A)
1127 (focus-regexp ediff-regexp-focus-A)
1128 (wide-visibility-p (eq ediff-visible-bounds ediff-wide-bounds))
1129 (overlay (if (ediff-has-face-support-p)
1130 ediff-current-diff-overlay-A)))
1131 (if ediff-3way-comparison-job
1132 (progn
1133 (set-window-buffer ediff-window-A ediff-buffer-C)
1134 (set-window-buffer ediff-window-B ediff-buffer-A)
1135 (set-window-buffer ediff-window-C ediff-buffer-B)
1136 )
1137 (set-window-buffer ediff-window-A ediff-buffer-B)
1138 (set-window-buffer ediff-window-B ediff-buffer-A))
1139 ;; swap diff buffers
1140 (if ediff-3way-comparison-job
1141 (setq ediff-buffer-A ediff-buffer-C
1142 ediff-buffer-C ediff-buffer-B
1143 ediff-buffer-B buf)
1144 (setq ediff-buffer-A ediff-buffer-B
1145 ediff-buffer-B buf))
1146
1147 ;; swap saved buffer characteristics
1148 (if ediff-3way-comparison-job
1149 (setq ediff-buffer-values-orig-A ediff-buffer-values-orig-C
1150 ediff-buffer-values-orig-C ediff-buffer-values-orig-B
1151 ediff-buffer-values-orig-B values)
1152 (setq ediff-buffer-values-orig-A ediff-buffer-values-orig-B
1153 ediff-buffer-values-orig-B values))
1154
1155 ;; swap diff vectors
1156 (if ediff-3way-comparison-job
1157 (setq ediff-difference-vector-A ediff-difference-vector-C
1158 ediff-difference-vector-C ediff-difference-vector-B
1159 ediff-difference-vector-B diff-vec)
1160 (setq ediff-difference-vector-A ediff-difference-vector-B
1161 ediff-difference-vector-B diff-vec))
1162
1163 ;; swap hide/focus regexp
1164 (if ediff-3way-comparison-job
1165 (setq ediff-regexp-hide-A ediff-regexp-hide-C
1166 ediff-regexp-hide-C ediff-regexp-hide-B
1167 ediff-regexp-hide-B hide-regexp
1168 ediff-regexp-focus-A ediff-regexp-focus-C
1169 ediff-regexp-focus-C ediff-regexp-focus-B
1170 ediff-regexp-focus-B focus-regexp)
1171 (setq ediff-regexp-hide-A ediff-regexp-hide-B
1172 ediff-regexp-hide-B hide-regexp
1173 ediff-regexp-focus-A ediff-regexp-focus-B
1174 ediff-regexp-focus-B focus-regexp))
1175
1176 ;; The following is needed for XEmacs, since there one can't move
1177 ;; overlay to another buffer. In Emacs, this swap is redundant.
1178 (if (ediff-has-face-support-p)
1179 (if ediff-3way-comparison-job
1180 (setq ediff-current-diff-overlay-A ediff-current-diff-overlay-C
1181 ediff-current-diff-overlay-C ediff-current-diff-overlay-B
1182 ediff-current-diff-overlay-B overlay)
1183 (setq ediff-current-diff-overlay-A ediff-current-diff-overlay-B
1184 ediff-current-diff-overlay-B overlay)))
1185
1186 ;; swap wide bounds
1187 (setq ediff-wide-bounds
1188 (cond (ediff-3way-comparison-job
1189 (list (nth 2 ediff-wide-bounds)
1190 (nth 0 ediff-wide-bounds)
1191 (nth 1 ediff-wide-bounds)))
1192 (ediff-3way-job
1193 (list (nth 1 ediff-wide-bounds)
1194 (nth 0 ediff-wide-bounds)
1195 (nth 2 ediff-wide-bounds)))
1196 (t
1197 (list (nth 1 ediff-wide-bounds)
1198 (nth 0 ediff-wide-bounds)))))
1199 ;; swap narrow bounds
1200 (setq ediff-narrow-bounds
1201 (cond (ediff-3way-comparison-job
1202 (list (nth 2 ediff-narrow-bounds)
1203 (nth 0 ediff-narrow-bounds)
1204 (nth 1 ediff-narrow-bounds)))
1205 (ediff-3way-job
1206 (list (nth 1 ediff-narrow-bounds)
1207 (nth 0 ediff-narrow-bounds)
1208 (nth 2 ediff-narrow-bounds)))
1209 (t
1210 (list (nth 1 ediff-narrow-bounds)
1211 (nth 0 ediff-narrow-bounds)))))
1212 (if wide-visibility-p
1213 (setq ediff-visible-bounds ediff-wide-bounds)
1214 (setq ediff-visible-bounds ediff-narrow-bounds))
1215 ))
1216 (if ediff-3way-job
1217 (ediff-set-state-of-all-diffs-in-all-buffers ediff-control-buffer))
1218 (ediff-recenter 'no-rehighlight)
1219 )
1220
1221
1222 (defun ediff-toggle-wide-display ()
1223 "Toggle wide/regular display.
1224 This is especially useful when comparing buffers side-by-side."
1225 (interactive)
1226 (ediff-barf-if-not-control-buffer)
1227 (or (ediff-window-display-p)
1228 (error "%sEmacs is not running as a window application"
1229 (if ediff-emacs-p "" "X")))
1230 (ediff-recenter 'no-rehighlight) ; make sure buffs are displayed in windows
1231 (let ((ctl-buf ediff-control-buffer))
1232 (setq ediff-wide-display-p (not ediff-wide-display-p))
1233 (if (not ediff-wide-display-p)
1234 (ediff-with-current-buffer ctl-buf
1235 (modify-frame-parameters
1236 ediff-wide-display-frame ediff-wide-display-orig-parameters)
1237 ;;(sit-for (if ediff-xemacs-p 0.4 0))
1238 ;; restore control buf, since ctl window may have been deleted
1239 ;; during resizing
1240 (set-buffer ctl-buf)
1241 (setq ediff-wide-display-orig-parameters nil
1242 ediff-window-B nil) ; force update of window config
1243 (ediff-recenter 'no-rehighlight))
1244 (funcall ediff-make-wide-display-function)
1245 ;;(sit-for (if ediff-xemacs-p 0.4 0))
1246 (ediff-with-current-buffer ctl-buf
1247 (setq ediff-window-B nil) ; force update of window config
1248 (ediff-recenter 'no-rehighlight)))))
1249
1250 ;;;###autoload
1251 (defun ediff-toggle-multiframe ()
1252 "Switch from multiframe display to single-frame display and back.
1253 To change the default, set the variable `ediff-window-setup-function',
1254 which see."
1255 (interactive)
1256 (let (window-setup-func)
1257 (or (ediff-window-display-p)
1258 (error "%sEmacs is not running as a window application"
1259 (if ediff-emacs-p "" "X")))
1260
1261 (cond ((eq ediff-window-setup-function 'ediff-setup-windows-multiframe)
1262 (setq window-setup-func 'ediff-setup-windows-plain))
1263 ((eq ediff-window-setup-function 'ediff-setup-windows-plain)
1264 (if (ediff-in-control-buffer-p)
1265 (ediff-kill-bottom-toolbar))
1266 (setq window-setup-func 'ediff-setup-windows-multiframe)))
1267
1268 ;; change default
1269 (setq-default ediff-window-setup-function window-setup-func)
1270 ;; change in all active ediff sessions
1271 (mapcar (lambda(buf) (ediff-with-current-buffer buf
1272 (setq ediff-window-setup-function window-setup-func
1273 ediff-window-B nil)))
1274 ediff-session-registry)
1275 (if (ediff-in-control-buffer-p)
1276 (ediff-recenter 'no-rehighlight))))
1277
1278
1279 ;;;###autoload
1280 (defun ediff-toggle-use-toolbar ()
1281 "Enable or disable Ediff toolbar.
1282 Works only in versions of Emacs that support toolbars.
1283 To change the default, set the variable `ediff-use-toolbar-p', which see."
1284 (interactive)
1285 (if (featurep 'ediff-tbar)
1286 (progn
1287 (or (ediff-window-display-p)
1288 (error "%sEmacs is not running as a window application"
1289 (if ediff-emacs-p "" "X")))
1290 (if (ediff-use-toolbar-p)
1291 (ediff-kill-bottom-toolbar))
1292 ;; do this only after killing the toolbar
1293 (setq ediff-use-toolbar-p (not ediff-use-toolbar-p))
1294
1295 (mapcar (lambda(buf)
1296 (ediff-with-current-buffer buf
1297 ;; force redisplay
1298 (setq ediff-window-config-saved "")
1299 ))
1300 ediff-session-registry)
1301 (if (ediff-in-control-buffer-p)
1302 (ediff-recenter 'no-rehighlight)))))
1303
1304
1305 ;; if was using toolbar, kill it
1306 (defun ediff-kill-bottom-toolbar ()
1307 ;; Using ctl-buffer or ediff-control-window for LOCALE does not
1308 ;; work properly in XEmacs 19.14: we have to use
1309 ;;(selected-frame).
1310 ;; The problem with this is that any previous bottom-toolbar
1311 ;; will not re-appear after our cleanup here. Is there a way
1312 ;; to do "push" and "pop" toolbars ? --marcpa
1313 (if (ediff-use-toolbar-p)
1314 (progn
1315 (set-specifier bottom-toolbar (list (selected-frame) nil))
1316 (set-specifier bottom-toolbar-visible-p (list (selected-frame) nil)))))
1317
1318 ;; If wants to use toolbar, make it.
1319 ;; If not, zero the toolbar for XEmacs.
1320 ;; Do nothing for Emacs.
1321 (defun ediff-make-bottom-toolbar (&optional frame)
1322 (if (ediff-window-display-p)
1323 (progn
1324 (setq frame (or frame (selected-frame)))
1325 (cond ((ediff-use-toolbar-p) ; this checks for XEmacs
1326 (set-specifier
1327 bottom-toolbar
1328 (list frame (if (ediff-3way-comparison-job)
1329 ediff-toolbar-3way ediff-toolbar)))
1330 (set-specifier bottom-toolbar-visible-p (list frame t))
1331 (set-specifier bottom-toolbar-height
1332 (list frame ediff-toolbar-height)))
1333 ((ediff-has-toolbar-support-p)
1334 (set-specifier bottom-toolbar-height (list frame 0)))
1335 ))
1336 ))
1337
1338 ;; Merging
1339
1340 (defun ediff-toggle-show-clashes-only ()
1341 "Toggle the mode that shows only the merge regions where both variants differ from the ancestor."
1342 (interactive)
1343 (ediff-barf-if-not-control-buffer)
1344 (if (not ediff-merge-with-ancestor-job)
1345 (error "This command makes sense only when merging with an ancestor"))
1346 (setq ediff-show-clashes-only (not ediff-show-clashes-only))
1347 (if ediff-show-clashes-only
1348 (message "Focus on regions where both buffers differ from the ancestor")
1349 (message "Canceling focus on regions where changes clash")))
1350
1351 (defun ediff-toggle-skip-changed-regions ()
1352 "Toggle the mode that skips the merge regions that differ from the default."
1353 (interactive)
1354 (ediff-barf-if-not-control-buffer)
1355 (setq ediff-skip-merge-regions-that-differ-from-default
1356 (not ediff-skip-merge-regions-that-differ-from-default))
1357 (if ediff-skip-merge-regions-that-differ-from-default
1358 (message "Skipping regions that differ from default setting")
1359 (message "Showing regions that differ from default setting")))
1360
1361
1362
1363 ;; Widening/narrowing
1364
1365 (defun ediff-toggle-narrow-region ()
1366 "Toggle narrowing in buffers A, B, and C.
1367 Used in ediff-windows/regions only."
1368 (interactive)
1369 (if (eq ediff-buffer-A ediff-buffer-B)
1370 (error ediff-NO-DIFFERENCES))
1371 (if (eq ediff-visible-bounds ediff-wide-bounds)
1372 (setq ediff-visible-bounds ediff-narrow-bounds)
1373 (setq ediff-visible-bounds ediff-wide-bounds))
1374 (ediff-recenter 'no-rehighlight))
1375
1376 ;; Narrow bufs A/B/C to ediff-visible-bounds. If this is currently set to
1377 ;; ediff-wide-bounds, then this actually widens.
1378 ;; This function does nothing if job-name is not
1379 ;; ediff-regions-wordwise/linewise or ediff-windows-wordwise/linewise.
1380 ;; Does nothing if buffer-A = buffer-B since we can't narrow
1381 ;; to two different regions in one buffer.
1382 (defun ediff-visible-region ()
1383 (if (or (eq ediff-buffer-A ediff-buffer-B)
1384 (eq ediff-buffer-A ediff-buffer-C)
1385 (eq ediff-buffer-C ediff-buffer-B))
1386 ()
1387 ;; If ediff-*-regions/windows, ediff-visible-bounds is already set
1388 ;; Otherwise, always use full range.
1389 (if (not ediff-narrow-job)
1390 (setq ediff-visible-bounds ediff-wide-bounds))
1391 (let ((overl-A (ediff-get-value-according-to-buffer-type
1392 'A ediff-visible-bounds))
1393 (overl-B (ediff-get-value-according-to-buffer-type
1394 'B ediff-visible-bounds))
1395 (overl-C (ediff-get-value-according-to-buffer-type
1396 'C ediff-visible-bounds))
1397 )
1398 (ediff-with-current-buffer ediff-buffer-A
1399 (if (ediff-overlay-buffer overl-A)
1400 (narrow-to-region
1401 (ediff-overlay-start overl-A) (ediff-overlay-end overl-A))))
1402 (ediff-with-current-buffer ediff-buffer-B
1403 (if (ediff-overlay-buffer overl-B)
1404 (narrow-to-region
1405 (ediff-overlay-start overl-B) (ediff-overlay-end overl-B))))
1406
1407 (if (and ediff-3way-job (ediff-overlay-buffer overl-C))
1408 (ediff-with-current-buffer ediff-buffer-C
1409 (narrow-to-region
1410 (ediff-overlay-start overl-C) (ediff-overlay-end overl-C))))
1411 )))
1412
1413
1414 ;; Window scrolling operations
1415
1416 ;; Performs some operation on the two file windows (if they are showing).
1417 ;; Traps all errors on the operation in windows A/B/C.
1418 ;; Usually, errors come from scrolling off the
1419 ;; beginning or end of the buffer, and this gives error messages.
1420 (defun ediff-operate-on-windows (operation arg)
1421
1422 ;; make sure windows aren't dead
1423 (if (not (and (window-live-p ediff-window-A) (window-live-p ediff-window-B)))
1424 (ediff-recenter 'no-rehighlight))
1425 (if (not (and (ediff-buffer-live-p ediff-buffer-A)
1426 (ediff-buffer-live-p ediff-buffer-B)
1427 (or (not ediff-3way-job) ediff-buffer-C)
1428 ))
1429 (error ediff-KILLED-VITAL-BUFFER))
1430
1431 (let* ((wind (selected-window))
1432 (wind-A ediff-window-A)
1433 (wind-B ediff-window-B)
1434 (wind-C ediff-window-C)
1435 (coefA (ediff-get-region-size-coefficient 'A operation))
1436 (coefB (ediff-get-region-size-coefficient 'B operation))
1437 (three-way ediff-3way-job)
1438 (coefC (if three-way
1439 (ediff-get-region-size-coefficient 'C operation))))
1440
1441 (select-window wind-A)
1442 (condition-case nil
1443 (funcall operation (round (* coefA arg)))
1444 (error))
1445 (select-window wind-B)
1446 (condition-case nil
1447 (funcall operation (round (* coefB arg)))
1448 (error))
1449 (if three-way
1450 (progn
1451 (select-window wind-C)
1452 (condition-case nil
1453 (funcall operation (round (* coefC arg)))
1454 (error))))
1455 (select-window wind)))
1456
1457 (defun ediff-scroll-vertically (&optional arg)
1458 "Vertically scroll buffers A, B \(and C if appropriate\).
1459 With optional argument ARG, scroll ARG lines; otherwise scroll by nearly
1460 the one half of the height of window-A."
1461 (interactive "P")
1462 (ediff-barf-if-not-control-buffer)
1463
1464 ;; make sure windows aren't dead
1465 (if (not (and (window-live-p ediff-window-A) (window-live-p ediff-window-B)))
1466 (ediff-recenter 'no-rehighlight))
1467 (if (not (and (ediff-buffer-live-p ediff-buffer-A)
1468 (ediff-buffer-live-p ediff-buffer-B)
1469 (or (not ediff-3way-job)
1470 (ediff-buffer-live-p ediff-buffer-C))
1471 ))
1472 (error ediff-KILLED-VITAL-BUFFER))
1473
1474 (ediff-operate-on-windows
1475 (if (memq last-command-char '(?v ?\C-v))
1476 'scroll-up
1477 'scroll-down)
1478 ;; calculate argument to scroll-up/down
1479 ;; if there is an explicit argument
1480 (if (and arg (not (equal arg '-)))
1481 ;; use it
1482 (prefix-numeric-value arg)
1483 ;; if not, see if we can determine a default amount (the window height)
1484 (let (default-amount)
1485 (setq default-amount
1486 (- (/ (min (window-height ediff-window-A)
1487 (window-height ediff-window-B)
1488 (if ediff-3way-job
1489 (window-height ediff-window-C)
1490 500)) ; some large number
1491 2)
1492 1 next-screen-context-lines))
1493 ;; window found
1494 (if arg
1495 ;; C-u as argument means half of default amount
1496 (/ default-amount 2)
1497 ;; no argument means default amount
1498 default-amount)))))
1499
1500
1501 (defun ediff-scroll-horizontally (&optional arg)
1502 "Horizontally scroll buffers A, B \(and C if appropriate\).
1503 If an argument is given, that is how many columns are scrolled, else nearly
1504 the width of the A/B/C windows."
1505 (interactive "P")
1506 (ediff-barf-if-not-control-buffer)
1507
1508 ;; make sure windows aren't dead
1509 (if (not (and (window-live-p ediff-window-A) (window-live-p ediff-window-B)))
1510 (ediff-recenter 'no-rehighlight))
1511 (if (not (and (ediff-buffer-live-p ediff-buffer-A)
1512 (ediff-buffer-live-p ediff-buffer-B)
1513 (or (not ediff-3way-job)
1514 (ediff-buffer-live-p ediff-buffer-C))
1515 ))
1516 (error ediff-KILLED-VITAL-BUFFER))
1517
1518 (ediff-operate-on-windows
1519 (if (= last-command-char ?<)
1520 'scroll-left
1521 'scroll-right)
1522 ;; calculate argument to scroll-left/right
1523 ;; if there is an explicit argument
1524 (if (and arg (not (equal arg '-)))
1525 ;; use it
1526 (prefix-numeric-value arg)
1527 ;; if not, see if we can determine a default amount
1528 ;; (half the window width)
1529 (if (null ediff-control-window)
1530 ;; no control window, use nil
1531 nil
1532 (let ((default-amount
1533 (- (/ (min (window-width ediff-window-A)
1534 (window-width ediff-window-B)
1535 (if ediff-3way-comparison-job
1536 (window-width ediff-window-C)
1537 500) ; some large number
1538 )
1539 2)
1540 3)))
1541 ;; window found
1542 (if arg
1543 ;; C-u as argument means half of default amount
1544 (/ default-amount 2)
1545 ;; no argument means default amount
1546 default-amount))))))
1547
1548
1549 ;;BEG, END show the region to be positioned.
1550 ;;JOB-NAME holds ediff-job-name. The ediff-windows job positions regions
1551 ;;differently.
1552 (defun ediff-position-region (beg end pos job-name)
1553 (if (> end (point-max))
1554 (setq end (point-max)))
1555 (if ediff-windows-job
1556 (if (pos-visible-in-window-p end)
1557 () ; do nothing, wind is already positioned
1558 ;; at this point, windows are positioned at the beginning of the
1559 ;; file regions (not diff-regions) being compared.
1560 (save-excursion
1561 (move-to-window-line (- (window-height) 2))
1562 (let ((amount (+ 2 (count-lines (point) end))))
1563 (scroll-up amount))))
1564 (set-window-start (selected-window) beg)
1565 (if (pos-visible-in-window-p end)
1566 ;; Determine the number of lines that the region occupies
1567 (let ((lines 0)
1568 (prev-point 0))
1569 (while ( and (> end (progn
1570 (move-to-window-line lines)
1571 (point)))
1572 ;; `end' may be beyond the window bottom, so check
1573 ;; that we are making progress
1574 (< prev-point (point)))
1575 (setq prev-point (point))
1576 (setq lines (1+ lines)))
1577 ;; And position the beginning on the right line
1578 (goto-char beg)
1579 (recenter (/ (1+ (max (- (1- (window-height (selected-window)))
1580 lines)
1581 1)
1582 )
1583 2))))
1584 (goto-char pos)
1585 ))
1586
1587 ;; get number of lines from window start to region end
1588 (defun ediff-get-lines-to-region-end (buf-type &optional n ctl-buf)
1589 (or n (setq n ediff-current-difference))
1590 (or ctl-buf (setq ctl-buf ediff-control-buffer))
1591 (ediff-with-current-buffer ctl-buf
1592 (let* ((buf (ediff-get-buffer buf-type))
1593 (wind (eval (ediff-get-symbol-from-alist
1594 buf-type ediff-window-alist)))
1595 (beg (window-start wind))
1596 (end (ediff-get-diff-posn buf-type 'end))
1597 lines)
1598 (ediff-with-current-buffer buf
1599 (if (< beg end)
1600 (setq lines (count-lines beg end))
1601 (setq lines 0))
1602 lines
1603 ))))
1604
1605 ;; Calculate the number of lines from window end to the start of diff region
1606 (defun ediff-get-lines-to-region-start (buf-type &optional diff-num ctl-buf)
1607 (or diff-num (setq diff-num ediff-current-difference))
1608 (or ctl-buf (setq ctl-buf ediff-control-buffer))
1609 (ediff-with-current-buffer ctl-buf
1610 (let* ((buf (ediff-get-buffer buf-type))
1611 (wind (eval (ediff-get-symbol-from-alist
1612 buf-type ediff-window-alist)))
1613 (end (or (window-end wind) (window-end wind t)))
1614 (beg (ediff-get-diff-posn buf-type 'beg diff-num)))
1615 (ediff-with-current-buffer buf
1616 (if (< beg end)
1617 (count-lines (max beg (point-min)) (min end (point-max))) 0))
1618 )))
1619
1620
1621 ;; region size coefficient is a coefficient by which to adjust scrolling
1622 ;; up/down of the window displaying buffer of type BUFTYPE.
1623 ;; The purpose of this coefficient is to make the windows scroll in sync, so
1624 ;; that it won't happen that one diff region is scrolled off while the other is
1625 ;; still seen.
1626 ;;
1627 ;; If the difference region is invalid, the coefficient is 1
1628 (defun ediff-get-region-size-coefficient (buf-type op &optional n ctl-buf)
1629 (ediff-with-current-buffer (or ctl-buf ediff-control-buffer)
1630 (if (ediff-valid-difference-p n)
1631 (let* ((func (cond ((eq op 'scroll-down)
1632 'ediff-get-lines-to-region-start)
1633 ((eq op 'scroll-up)
1634 'ediff-get-lines-to-region-end)
1635 (t '(lambda (a b c) 0))))
1636 (max-lines (max (funcall func 'A n ctl-buf)
1637 (funcall func 'B n ctl-buf)
1638 (if (ediff-buffer-live-p ediff-buffer-C)
1639 (funcall func 'C n ctl-buf)
1640 0))))
1641 ;; this covers the horizontal coefficient as well:
1642 ;; if max-lines = 0 then coef = 1
1643 (if (> max-lines 0)
1644 (/ (+ (funcall func buf-type n ctl-buf) 0.0)
1645 (+ max-lines 0.0))
1646 1))
1647 1)))
1648
1649
1650 (defun ediff-next-difference (&optional arg)
1651 "Advance to the next difference.
1652 With a prefix argument, go forward that many differences."
1653 (interactive "p")
1654 (ediff-barf-if-not-control-buffer)
1655 (if (< ediff-current-difference ediff-number-of-differences)
1656 (let ((n (min ediff-number-of-differences
1657 (+ ediff-current-difference (or arg 1))))
1658 non-clash-skip skip-changed regexp-skip)
1659
1660 (ediff-visible-region)
1661 (or (>= n ediff-number-of-differences)
1662 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
1663 ;; this won't exec if regexp-skip is t
1664 (setq non-clash-skip (ediff-merge-region-is-non-clash n)
1665 skip-changed
1666 (ediff-skip-merge-region-if-changed-from-default-p n))
1667 (ediff-install-fine-diff-if-necessary n))
1668 ;; Skip loop
1669 (while (and (< n ediff-number-of-differences)
1670 (or
1671 ;; regexp skip
1672 regexp-skip
1673 ;; skip clashes, if necessary
1674 non-clash-skip
1675 ;; skip processed regions
1676 skip-changed
1677 ;; skip difference regions that differ in white space
1678 (and ediff-ignore-similar-regions
1679 (or (eq (ediff-no-fine-diffs-p n) t)
1680 (and (ediff-merge-job)
1681 (eq (ediff-no-fine-diffs-p n) 'C)))
1682 )))
1683 (setq n (1+ n))
1684 (if (= 0 (mod n 20))
1685 (message "Skipped over region %d and counting ..." n))
1686 (or (>= n ediff-number-of-differences)
1687 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
1688 ;; this won't exec if regexp-skip is t
1689 (setq non-clash-skip (ediff-merge-region-is-non-clash n)
1690 skip-changed
1691 (ediff-skip-merge-region-if-changed-from-default-p n))
1692 (ediff-install-fine-diff-if-necessary n))
1693 )
1694 (message "")
1695 (ediff-unselect-and-select-difference n)
1696 ) ; let
1697 (ediff-visible-region)
1698 (error "At end of the difference list")))
1699
1700 (defun ediff-previous-difference (&optional arg)
1701 "Go to the previous difference.
1702 With a prefix argument, go back that many differences."
1703 (interactive "p")
1704 (ediff-barf-if-not-control-buffer)
1705 (if (> ediff-current-difference -1)
1706 (let ((n (max -1 (- ediff-current-difference (or arg 1))))
1707 non-clash-skip skip-changed regexp-skip)
1708
1709 (ediff-visible-region)
1710 (or (< n 0)
1711 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
1712 ;; this won't exec if regexp-skip is t
1713 (setq non-clash-skip (ediff-merge-region-is-non-clash n)
1714 skip-changed
1715 (ediff-skip-merge-region-if-changed-from-default-p n))
1716 (ediff-install-fine-diff-if-necessary n))
1717 (while (and (> n -1)
1718 (or
1719 ;; regexp skip
1720 regexp-skip
1721 ;; skip clashes, if necessary
1722 non-clash-skip
1723 ;; skipp changed regions
1724 skip-changed
1725 ;; skip difference regions that differ in white space
1726 (and ediff-ignore-similar-regions
1727 (or (eq (ediff-no-fine-diffs-p n) t)
1728 (and (ediff-merge-job)
1729 (eq (ediff-no-fine-diffs-p n) 'C)))
1730 )))
1731 (if (= 0 (mod (1+ n) 20))
1732 (message "Skipped over region %d and counting ..." (1+ n)))
1733 (setq n (1- n))
1734 (or (< n 0)
1735 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
1736 ;; this won't exec if regexp-skip is t
1737 (setq non-clash-skip (ediff-merge-region-is-non-clash n)
1738 skip-changed
1739 (ediff-skip-merge-region-if-changed-from-default-p n))
1740 (ediff-install-fine-diff-if-necessary n))
1741 )
1742 (message "")
1743 (ediff-unselect-and-select-difference n)
1744 ) ; let
1745 (ediff-visible-region)
1746 (error "At beginning of the difference list")))
1747
1748 ;; The diff number is as perceived by the user (i.e., 1+ the internal
1749 ;; representation)
1750 (defun ediff-jump-to-difference (difference-number)
1751 "Go to the difference specified as a prefix argument.
1752 If the prefix is negative, count differences from the end."
1753 (interactive "p")
1754 (ediff-barf-if-not-control-buffer)
1755 (setq difference-number
1756 (cond ((< difference-number 0)
1757 (+ ediff-number-of-differences difference-number))
1758 ((> difference-number 0) (1- difference-number))
1759 (t -1)))
1760 ;; -1 is allowed by ediff-unselect-and-select-difference --- it is the
1761 ;; position before the first one.
1762 (if (and (>= difference-number -1)
1763 (<= difference-number ediff-number-of-differences))
1764 (ediff-unselect-and-select-difference difference-number)
1765 (error ediff-BAD-DIFF-NUMBER
1766 this-command (1+ difference-number) ediff-number-of-differences)))
1767
1768 (defun ediff-jump-to-difference-at-point (arg)
1769 "Go to difference closest to the point in buffer A, B, or C.
1770 The buffer depends on last command character \(a, b, or c\) that invoked this
1771 command. For instance, if the command was `ga' then the point value in buffer
1772 A is used.
1773 With a prefix argument, synchronize all files around the current point position
1774 in the specified buffer."
1775 (interactive "P")
1776 (ediff-barf-if-not-control-buffer)
1777 (let* ((buf-type (ediff-char-to-buftype last-command-char))
1778 (buffer (ediff-get-buffer buf-type))
1779 (pt (ediff-with-current-buffer buffer (point)))
1780 (diff-no (ediff-diff-at-point buf-type nil (if arg 'after)))
1781 (past-last-diff (< ediff-number-of-differences diff-no))
1782 (beg (if past-last-diff
1783 (ediff-with-current-buffer buffer (point-max))
1784 (ediff-get-diff-posn buf-type 'beg (1- diff-no))))
1785 ctl-wind wind-A wind-B wind-C
1786 shift)
1787 (if past-last-diff
1788 (ediff-jump-to-difference -1)
1789 (ediff-jump-to-difference diff-no))
1790 (setq ctl-wind (selected-window)
1791 wind-A ediff-window-A
1792 wind-B ediff-window-B
1793 wind-C ediff-window-C)
1794 (if arg
1795 (progn
1796 (ediff-with-current-buffer buffer
1797 (setq shift (- beg pt)))
1798 (select-window wind-A)
1799 (if past-last-diff (goto-char (point-max)))
1800 (condition-case nil
1801 (backward-char shift) ; noerror, if beginning of buffer
1802 (error))
1803 (recenter)
1804 (select-window wind-B)
1805 (if past-last-diff (goto-char (point-max)))
1806 (condition-case nil
1807 (backward-char shift) ; noerror, if beginning of buffer
1808 (error))
1809 (recenter)
1810 (if (window-live-p wind-C)
1811 (progn
1812 (select-window wind-C)
1813 (if past-last-diff (goto-char (point-max)))
1814 (condition-case nil
1815 (backward-char shift) ; noerror, if beginning of buffer
1816 (error))
1817 (recenter)
1818 ))
1819 (select-window ctl-wind)
1820 ))
1821 ))
1822
1823
1824 ;; find region most related to the current point position (or POS, if given)
1825 ;; returns diff number as seen by the user (i.e., 1+ the internal
1826 ;; representation)
1827 ;; The optional argument WHICH-DIFF can be `after' or `before'. If `after',
1828 ;; find the diff after the point. If `before', find the diff before the
1829 ;; point. If the point is inside a diff, return that diff.
1830 (defun ediff-diff-at-point (buf-type &optional pos which-diff)
1831 (let ((buffer (ediff-get-buffer buf-type))
1832 (ctl-buffer ediff-control-buffer)
1833 (max-dif-num (1- ediff-number-of-differences))
1834 (diff-no -1)
1835 (prev-beg 0)
1836 (prev-end 0)
1837 (beg 0)
1838 (end 0))
1839
1840 (ediff-with-current-buffer buffer
1841 (setq pos (or pos (point)))
1842 (while (and (or (< pos prev-beg) (> pos beg))
1843 (< diff-no max-dif-num))
1844 (setq diff-no (1+ diff-no))
1845 (setq prev-beg beg
1846 prev-end end)
1847 (setq beg (ediff-get-diff-posn buf-type 'beg diff-no ctl-buffer)
1848 end (ediff-get-diff-posn buf-type 'end diff-no ctl-buffer))
1849 )
1850
1851 ;; boost diff-no by 1, if past the last diff region
1852 (if (and (memq which-diff '(after before))
1853 (> pos beg) (= diff-no max-dif-num))
1854 (setq diff-no (1+ diff-no)))
1855
1856 (cond ((eq which-diff 'after) (1+ diff-no))
1857 ((eq which-diff 'before) diff-no)
1858 ((< (abs (count-lines pos (max 1 prev-end)))
1859 (abs (count-lines pos (max 1 beg))))
1860 diff-no) ; choose prev difference
1861 (t
1862 (1+ diff-no))) ; choose next difference
1863 )))
1864
1865 \f
1866 ;;; Copying diffs.
1867
1868 (defun ediff-diff-to-diff (arg &optional keys)
1869 "Copy buffer-X'th difference region to buffer Y \(X,Y are A, B, or C\).
1870 If numerical prefix argument, copy the difference specified in the arg.
1871 Otherwise, copy the difference given by `ediff-current-difference'.
1872 This command assumes it is bound to a 2-character key sequence, `ab', `ba',
1873 `ac', etc., which is used to determine the types of buffers to be used for
1874 copying difference regions. The first character in the sequence specifies
1875 the source buffer and the second specifies the target.
1876
1877 If the second optional argument, a 2-character string, is given, use it to
1878 determine the source and the target buffers instead of the command keys."
1879 (interactive "P")
1880 (ediff-barf-if-not-control-buffer)
1881 (or keys (setq keys (this-command-keys)))
1882 (if (eq arg '-) (setq arg -1)) ; translate neg arg to -1
1883 (if (numberp arg) (ediff-jump-to-difference arg))
1884
1885 (let* ((key1 (aref keys 0))
1886 (key2 (aref keys 1))
1887 (char1 (if (and ediff-xemacs-p (eventp key1)) (event-key key1) key1))
1888 (char2 (if (and ediff-xemacs-p (eventp key1)) (event-key key2) key2))
1889 ediff-verbose-p)
1890 (ediff-copy-diff ediff-current-difference
1891 (ediff-char-to-buftype char1)
1892 (ediff-char-to-buftype char2))
1893 ;; recenter with rehighlighting, but no messages
1894 (ediff-recenter)))
1895
1896 (defun ediff-copy-A-to-B (arg)
1897 "Copy ARGth difference region from buffer A to B.
1898 ARG is a prefix argument. If nil, copy the current difference region."
1899 (interactive "P")
1900 (ediff-diff-to-diff arg "ab"))
1901
1902 (defun ediff-copy-B-to-A (arg)
1903 "Copy ARGth difference region from buffer B to A.
1904 ARG is a prefix argument. If nil, copy the current difference region."
1905 (interactive "P")
1906 (ediff-diff-to-diff arg "ba"))
1907
1908 (defun ediff-copy-A-to-C (arg)
1909 "Copy ARGth difference region from buffer A to buffer C.
1910 ARG is a prefix argument. If nil, copy the current difference region."
1911 (interactive "P")
1912 (ediff-diff-to-diff arg "ac"))
1913
1914 (defun ediff-copy-B-to-C (arg)
1915 "Copy ARGth difference region from buffer B to buffer C.
1916 ARG is a prefix argument. If nil, copy the current difference region."
1917 (interactive "P")
1918 (ediff-diff-to-diff arg "bc"))
1919
1920 (defun ediff-copy-C-to-B (arg)
1921 "Copy ARGth difference region from buffer C to B.
1922 ARG is a prefix argument. If nil, copy the current difference region."
1923 (interactive "P")
1924 (ediff-diff-to-diff arg "cb"))
1925
1926 (defun ediff-copy-C-to-A (arg)
1927 "Copy ARGth difference region from buffer C to A.
1928 ARG is a prefix argument. If nil, copy the current difference region."
1929 (interactive "P")
1930 (ediff-diff-to-diff arg "ca"))
1931
1932
1933
1934 ;; Copy diff N from FROM-BUF-TYPE \(given as A, B or C\) to TO-BUF-TYPE.
1935 ;; If optional DO-NOT-SAVE is non-nil, do not save the old value of the
1936 ;; target diff. This is used in merging, when constructing the merged
1937 ;; version.
1938 (defun ediff-copy-diff (n from-buf-type to-buf-type
1939 &optional batch-invocation reg-to-copy)
1940 (let* ((to-buf (ediff-get-buffer to-buf-type))
1941 ;;(from-buf (if (not reg-to-copy) (ediff-get-buffer from-buf-type)))
1942 (ctrl-buf ediff-control-buffer)
1943 (saved-p t)
1944 (three-way ediff-3way-job)
1945 messg
1946 ediff-verbose-p
1947 reg-to-delete reg-to-delete-beg reg-to-delete-end)
1948
1949 (setq reg-to-delete-beg
1950 (ediff-get-diff-posn to-buf-type 'beg n ctrl-buf))
1951 (setq reg-to-delete-end
1952 (ediff-get-diff-posn to-buf-type 'end n ctrl-buf))
1953
1954 (if reg-to-copy
1955 (setq from-buf-type nil)
1956 (setq reg-to-copy (ediff-get-region-contents n from-buf-type ctrl-buf)))
1957
1958 (setq reg-to-delete (ediff-get-region-contents
1959 n to-buf-type ctrl-buf
1960 reg-to-delete-beg reg-to-delete-end))
1961
1962 (if (string= reg-to-delete reg-to-copy)
1963 (setq saved-p nil) ; don't copy identical buffers
1964 ;; seems ok to copy
1965 (if (or batch-invocation (ediff-test-save-region n to-buf-type))
1966 (condition-case conds
1967 (progn
1968 (ediff-with-current-buffer to-buf
1969 ;; to prevent flags from interfering if buffer is writable
1970 (let ((inhibit-read-only (null buffer-read-only)))
1971
1972 (goto-char reg-to-delete-end)
1973 (insert reg-to-copy)
1974
1975 (if (> reg-to-delete-end reg-to-delete-beg)
1976 (kill-region reg-to-delete-beg reg-to-delete-end))
1977 ))
1978 (or batch-invocation
1979 (setq
1980 messg
1981 (ediff-save-diff-region n to-buf-type reg-to-delete))))
1982 (error (message "ediff-copy-diff: %s %s"
1983 (car conds)
1984 (mapconcat 'prin1-to-string (cdr conds) " "))
1985 (beep 1)
1986 (sit-for 2) ; let the user see the error msg
1987 (setq saved-p nil)
1988 )))
1989 )
1990
1991 ;; adjust state of difference in case 3-way and diff was copied ok
1992 (if (and saved-p three-way)
1993 (ediff-set-state-of-diff-in-all-buffers n ctrl-buf))
1994
1995 (if batch-invocation
1996 (ediff-clear-fine-differences n)
1997 ;; If diff3 job, we should recompute fine diffs so we clear them
1998 ;; before reinserting flags (and thus before ediff-recenter).
1999 (if (and saved-p three-way)
2000 (ediff-clear-fine-differences n))
2001
2002 (ediff-refresh-mode-lines)
2003
2004 ;; For diff2 jobs, don't recompute fine diffs, since we know there
2005 ;; aren't any. So we clear diffs after ediff-recenter.
2006 (if (and saved-p (not three-way))
2007 (ediff-clear-fine-differences n))
2008 ;; Make sure that the message about saving and how to restore is seen
2009 ;; by the user
2010 (message messg))
2011 ))
2012
2013 ;; Save Nth diff of buffer BUF-TYPE \(A, B, or C\).
2014 ;; That is to say, the Nth diff on the `ediff-killed-diffs-alist'. REG
2015 ;; is the region to save. It is redundant here, but is passed anyway, for
2016 ;; convenience.
2017 (defun ediff-save-diff-region (n buf-type reg)
2018 (let* ((n-th-diff-saved (assoc n ediff-killed-diffs-alist))
2019 (buf (ediff-get-buffer buf-type))
2020 (this-buf-n-th-diff-saved (assoc buf (cdr n-th-diff-saved))))
2021
2022 (if this-buf-n-th-diff-saved
2023 ;; either nothing saved for n-th diff and buffer or we OK'ed
2024 ;; overriding
2025 (setcdr this-buf-n-th-diff-saved reg)
2026 (if n-th-diff-saved ;; n-th diff saved, but for another buffer
2027 (nconc n-th-diff-saved (list (cons buf reg)))
2028 (setq ediff-killed-diffs-alist ;; create record for n-th diff
2029 (cons (list n (cons buf reg))
2030 ediff-killed-diffs-alist))))
2031 (message "Saving old diff region #%d of buffer %S. To recover, type `r%s'"
2032 (1+ n) buf-type
2033 (if ediff-merge-job
2034 "" (downcase (symbol-name buf-type))))
2035 ))
2036
2037 ;; Test if saving Nth difference region of buffer BUF-TYPE is possible.
2038 (defun ediff-test-save-region (n buf-type)
2039 (let* ((n-th-diff-saved (assoc n ediff-killed-diffs-alist))
2040 (buf (ediff-get-buffer buf-type))
2041 (this-buf-n-th-diff-saved (assoc buf (cdr n-th-diff-saved))))
2042
2043 (if this-buf-n-th-diff-saved
2044 (if (yes-or-no-p
2045 (format
2046 "You've previously copied diff region %d to buffer %S. Confirm "
2047 (1+ n) buf-type))
2048 t
2049 (error "Quit"))
2050 t)))
2051
2052 (defun ediff-pop-diff (n buf-type)
2053 "Pop last killed Nth diff region from buffer BUF-TYPE."
2054 (let* ((n-th-record (assoc n ediff-killed-diffs-alist))
2055 (buf (ediff-get-buffer buf-type))
2056 (saved-rec (assoc buf (cdr n-th-record)))
2057 (three-way ediff-3way-job)
2058 (ctl-buf ediff-control-buffer)
2059 ediff-verbose-p
2060 saved-diff reg-beg reg-end recovered)
2061
2062 (if (cdr saved-rec)
2063 (setq saved-diff (cdr saved-rec))
2064 (if (> ediff-number-of-differences 0)
2065 (error "Nothing saved for diff %d in buffer %S" (1+ n) buf-type)
2066 (error ediff-NO-DIFFERENCES)))
2067
2068 (setq reg-beg (ediff-get-diff-posn buf-type 'beg n ediff-control-buffer))
2069 (setq reg-end (ediff-get-diff-posn buf-type 'end n ediff-control-buffer))
2070
2071 (condition-case conds
2072 (ediff-with-current-buffer buf
2073 (let ((inhibit-read-only (null buffer-read-only)))
2074
2075 (goto-char reg-end)
2076 (insert saved-diff)
2077
2078 (if (> reg-end reg-beg)
2079 (kill-region reg-beg reg-end))
2080
2081 (setq recovered t)
2082 ))
2083 (error (message "ediff-pop-diff: %s %s"
2084 (car conds)
2085 (mapconcat 'prin1-to-string (cdr conds) " "))
2086 (beep 1)))
2087
2088 ;; Clearing fine diffs is necessary for
2089 ;; ediff-unselect-and-select-difference to properly recompute them. We
2090 ;; can't rely on ediff-copy-diff to clear this vector, as the user might
2091 ;; have modified diff regions after copying and, thus, may have recomputed
2092 ;; fine diffs.
2093 (if recovered
2094 (ediff-clear-fine-differences n))
2095
2096 ;; adjust state of difference
2097 (if (and three-way recovered)
2098 (ediff-set-state-of-diff-in-all-buffers n ctl-buf))
2099
2100 (ediff-refresh-mode-lines)
2101
2102 (if recovered
2103 (progn
2104 (setq n-th-record (delq saved-rec n-th-record))
2105 (message "Diff region %d in buffer %S restored" (1+ n) buf-type)
2106 ))
2107 ))
2108
2109 (defun ediff-restore-diff (arg &optional key)
2110 "Restore ARGth diff from `ediff-killed-diffs-alist'.
2111 ARG is a prefix argument. If ARG is nil, restore the current-difference.
2112 If the second optional argument, a character, is given, use it to
2113 determine the target buffer instead of last-command-char"
2114 (interactive "P")
2115 (ediff-barf-if-not-control-buffer)
2116 (if (numberp arg)
2117 (ediff-jump-to-difference arg))
2118 (ediff-pop-diff ediff-current-difference
2119 (ediff-char-to-buftype (or key last-command-char)))
2120 ;; recenter with rehighlighting, but no messages
2121 (let (ediff-verbose-p)
2122 (ediff-recenter)))
2123
2124 (defun ediff-restore-diff-in-merge-buffer (arg)
2125 "Restore ARGth diff in the merge buffer.
2126 ARG is a prefix argument. If nil, restore the current diff."
2127 (interactive "P")
2128 (ediff-restore-diff arg ?c))
2129
2130
2131 (defun ediff-toggle-regexp-match ()
2132 "Toggle between focusing and hiding of difference regions that match
2133 a regular expression typed in by the user."
2134 (interactive)
2135 (ediff-barf-if-not-control-buffer)
2136 (let ((regexp-A "")
2137 (regexp-B "")
2138 (regexp-C "")
2139 msg-connective alt-msg-connective alt-connective)
2140 (cond
2141 ((or (and (eq ediff-skip-diff-region-function
2142 ediff-focus-on-regexp-matches-function)
2143 (eq last-command-char ?f))
2144 (and (eq ediff-skip-diff-region-function
2145 ediff-hide-regexp-matches-function)
2146 (eq last-command-char ?h)))
2147 (message "Selective browsing by regexp turned off")
2148 (setq ediff-skip-diff-region-function 'ediff-show-all-diffs))
2149 ((eq last-command-char ?h)
2150 (setq ediff-skip-diff-region-function ediff-hide-regexp-matches-function
2151 regexp-A
2152 (read-string
2153 (format
2154 "Ignore A-regions matching this regexp (default \"%s\"): "
2155 ediff-regexp-hide-A))
2156 regexp-B
2157 (read-string
2158 (format
2159 "Ignore B-regions matching this regexp (default \"%s\"): "
2160 ediff-regexp-hide-B)))
2161 (if ediff-3way-comparison-job
2162 (setq regexp-C
2163 (read-string
2164 (format
2165 "Ignore C-regions matching this regexp (default \"%s\"): "
2166 ediff-regexp-hide-C))))
2167 (if (eq ediff-hide-regexp-connective 'and)
2168 (setq msg-connective "BOTH"
2169 alt-msg-connective "ONE OF"
2170 alt-connective 'or)
2171 (setq msg-connective "ONE OF"
2172 alt-msg-connective "BOTH"
2173 alt-connective 'and))
2174 (if (y-or-n-p
2175 (format
2176 "Ignore regions that match %s regexps, OK? "
2177 msg-connective alt-msg-connective))
2178 (message "Will ignore regions that match %s regexps" msg-connective)
2179 (setq ediff-hide-regexp-connective alt-connective)
2180 (message "Will ignore regions that match %s regexps"
2181 alt-msg-connective))
2182
2183 (or (string= regexp-A "") (setq ediff-regexp-hide-A regexp-A))
2184 (or (string= regexp-B "") (setq ediff-regexp-hide-B regexp-B))
2185 (or (string= regexp-C "") (setq ediff-regexp-hide-C regexp-C)))
2186
2187 ((eq last-command-char ?f)
2188 (setq ediff-skip-diff-region-function
2189 ediff-focus-on-regexp-matches-function
2190 regexp-A
2191 (read-string
2192 (format
2193 "Focus on A-regions matching this regexp (default \"%s\"): "
2194 ediff-regexp-focus-A))
2195 regexp-B
2196 (read-string
2197 (format
2198 "Focus on B-regions matching this regexp (default \"%s\"): "
2199 ediff-regexp-focus-B)))
2200 (if ediff-3way-comparison-job
2201 (setq regexp-C
2202 (read-string
2203 (format
2204 "Focus on C-regions matching this regexp (default \"%s\"): "
2205 ediff-regexp-focus-C))))
2206 (if (eq ediff-focus-regexp-connective 'and)
2207 (setq msg-connective "BOTH"
2208 alt-msg-connective "ONE OF"
2209 alt-connective 'or)
2210 (setq msg-connective "ONE OF"
2211 alt-msg-connective "BOTH"
2212 alt-connective 'and))
2213 (if (y-or-n-p
2214 (format
2215 "Focus on regions that match %s regexps, OK? "
2216 msg-connective alt-msg-connective))
2217 (message "Will focus on regions that match %s regexps"
2218 msg-connective)
2219 (setq ediff-focus-regexp-connective alt-connective)
2220 (message "Will focus on regions that match %s regexps"
2221 alt-msg-connective))
2222
2223 (or (string= regexp-A "") (setq ediff-regexp-focus-A regexp-A))
2224 (or (string= regexp-B "") (setq ediff-regexp-focus-B regexp-B))
2225 (or (string= regexp-C "") (setq ediff-regexp-focus-C regexp-C))))))
2226
2227 (defun ediff-toggle-skip-similar ()
2228 (interactive)
2229 (ediff-barf-if-not-control-buffer)
2230 (if (not (eq ediff-auto-refine 'on))
2231 (error
2232 "Can't skip over whitespace regions: first turn auto-refining on"))
2233 (setq ediff-ignore-similar-regions (not ediff-ignore-similar-regions))
2234 (if ediff-ignore-similar-regions
2235 (message
2236 "Skipping regions that differ only in white space & line breaks")
2237 (message "Skipping over white-space differences turned off")))
2238
2239 (defun ediff-focus-on-regexp-matches (n)
2240 "Focus on diffs that match regexp `ediff-regexp-focus-A/B'.
2241 Regions to be ignored according to this function are those where
2242 buf A region doesn't match `ediff-regexp-focus-A' and buf B region
2243 doesn't match `ediff-regexp-focus-B'.
2244 This function returns nil if the region number N (specified as
2245 an argument) is not to be ignored and t if region N is to be ignored.
2246
2247 N is a region number used by Ediff internally. It is 1 less
2248 the number seen by the user."
2249 (if (ediff-valid-difference-p n)
2250 (let* ((ctl-buf ediff-control-buffer)
2251 (regex-A ediff-regexp-focus-A)
2252 (regex-B ediff-regexp-focus-B)
2253 (regex-C ediff-regexp-focus-C)
2254 (reg-A-match (ediff-with-current-buffer ediff-buffer-A
2255 (save-restriction
2256 (narrow-to-region
2257 (ediff-get-diff-posn 'A 'beg n ctl-buf)
2258 (ediff-get-diff-posn 'A 'end n ctl-buf))
2259 (goto-char (point-min))
2260 (re-search-forward regex-A nil t))))
2261 (reg-B-match (ediff-with-current-buffer ediff-buffer-B
2262 (save-restriction
2263 (narrow-to-region
2264 (ediff-get-diff-posn 'B 'beg n ctl-buf)
2265 (ediff-get-diff-posn 'B 'end n ctl-buf))
2266 (re-search-forward regex-B nil t))))
2267 (reg-C-match (if ediff-3way-comparison-job
2268 (ediff-with-current-buffer ediff-buffer-C
2269 (save-restriction
2270 (narrow-to-region
2271 (ediff-get-diff-posn 'C 'beg n ctl-buf)
2272 (ediff-get-diff-posn 'C 'end n ctl-buf))
2273 (re-search-forward regex-C nil t))))))
2274 (not (eval (if ediff-3way-comparison-job
2275 (list ediff-focus-regexp-connective
2276 reg-A-match reg-B-match reg-C-match)
2277 (list ediff-focus-regexp-connective
2278 reg-A-match reg-B-match))))
2279 )))
2280
2281 (defun ediff-hide-regexp-matches (n)
2282 "Hide diffs that match regexp `ediff-regexp-hide-A/B/C'.
2283 Regions to be ignored are those where buf A region matches
2284 `ediff-regexp-hide-A' and buf B region matches `ediff-regexp-hide-B'.
2285 This function returns nil if the region number N (specified as
2286 an argument) is not to be ignored and t if region N is to be ignored.
2287
2288 N is a region number used by Ediff internally. It is 1 less
2289 the number seen by the user."
2290 (if (ediff-valid-difference-p n)
2291 (let* ((ctl-buf ediff-control-buffer)
2292 (regex-A ediff-regexp-hide-A)
2293 (regex-B ediff-regexp-hide-B)
2294 (regex-C ediff-regexp-hide-C)
2295 (reg-A-match (ediff-with-current-buffer ediff-buffer-A
2296 (save-restriction
2297 (narrow-to-region
2298 (ediff-get-diff-posn 'A 'beg n ctl-buf)
2299 (ediff-get-diff-posn 'A 'end n ctl-buf))
2300 (goto-char (point-min))
2301 (re-search-forward regex-A nil t))))
2302 (reg-B-match (ediff-with-current-buffer ediff-buffer-B
2303 (save-restriction
2304 (narrow-to-region
2305 (ediff-get-diff-posn 'B 'beg n ctl-buf)
2306 (ediff-get-diff-posn 'B 'end n ctl-buf))
2307 (goto-char (point-min))
2308 (re-search-forward regex-B nil t))))
2309 (reg-C-match (if ediff-3way-comparison-job
2310 (ediff-with-current-buffer ediff-buffer-C
2311 (save-restriction
2312 (narrow-to-region
2313 (ediff-get-diff-posn 'C 'beg n ctl-buf)
2314 (ediff-get-diff-posn 'C 'end n ctl-buf))
2315 (goto-char (point-min))
2316 (re-search-forward regex-C nil t))))))
2317 (eval (if ediff-3way-comparison-job
2318 (list ediff-hide-regexp-connective
2319 reg-A-match reg-B-match reg-C-match)
2320 (list ediff-hide-regexp-connective reg-A-match reg-B-match)))
2321 )))
2322
2323
2324 \f
2325 ;;; Quitting, suspending, etc.
2326
2327 (defun ediff-quit (reverse-default-keep-variants)
2328 "Finish an Ediff session and exit Ediff.
2329 Unselects the selected difference, if any, restores the read-only and modified
2330 flags of the compared file buffers, kills Ediff buffers for this session
2331 \(but not buffers A, B, C\).
2332
2333 If `ediff-keep-variants' is nil, the user will be asked whether the buffers
2334 containing the variants should be removed \(if they haven't been modified\).
2335 If it is t, they will be preserved unconditionally. A prefix argument,
2336 temporarily reverses the meaning of this variable."
2337 (interactive "P")
2338 (ediff-barf-if-not-control-buffer)
2339 (let ((ctl-buf (current-buffer)))
2340 (if (y-or-n-p (format "Quit this Ediff session%s? "
2341 (if (ediff-buffer-live-p ediff-meta-buffer)
2342 " & show containing session group" "")))
2343 (progn
2344 (message "")
2345 (set-buffer ctl-buf)
2346 (ediff-really-quit reverse-default-keep-variants))
2347 (message ""))))
2348
2349
2350 ;; Perform the quit operations.
2351 (defun ediff-really-quit (reverse-default-keep-variants)
2352 (ediff-unhighlight-diffs-totally)
2353 (ediff-clear-diff-vector 'ediff-difference-vector-A 'fine-diffs-also)
2354 (ediff-clear-diff-vector 'ediff-difference-vector-B 'fine-diffs-also)
2355 (ediff-clear-diff-vector 'ediff-difference-vector-C 'fine-diffs-also)
2356 (ediff-clear-diff-vector 'ediff-difference-vector-Ancestor 'fine-diffs-also)
2357
2358 (ediff-delete-temp-files)
2359
2360 ;; Restore visibility range. This affects only ediff-*-regions/windows.
2361 ;; Since for other job names ediff-visible-region sets
2362 ;; ediff-visible-bounds to ediff-wide-bounds, the settings below are
2363 ;; ignored for such jobs.
2364 (if ediff-quit-widened
2365 (setq ediff-visible-bounds ediff-wide-bounds)
2366 (setq ediff-visible-bounds ediff-narrow-bounds))
2367
2368 ;; Apply selective display to narrow or widen
2369 (ediff-visible-region)
2370 (mapcar (lambda (overl)
2371 (if (ediff-overlayp overl)
2372 (ediff-delete-overlay overl)))
2373 ediff-wide-bounds)
2374 (mapcar (lambda (overl)
2375 (if (ediff-overlayp overl)
2376 (ediff-delete-overlay overl)))
2377 ediff-narrow-bounds)
2378
2379 ;; restore buffer mode line id's in buffer-A/B/C
2380 (let ((control-buffer ediff-control-buffer)
2381 (meta-buffer ediff-meta-buffer)
2382 (after-quit-hook-internal ediff-after-quit-hook-internal)
2383 (session-number ediff-meta-session-number)
2384 ;; suitable working frame
2385 (warp-frame (if (and (ediff-window-display-p) (eq ediff-grab-mouse t))
2386 (cond ((window-live-p ediff-window-A)
2387 (window-frame ediff-window-A))
2388 ((window-live-p ediff-window-B)
2389 (window-frame ediff-window-B))
2390 (t (next-frame))))))
2391 (condition-case nil
2392 (ediff-with-current-buffer ediff-buffer-A
2393 (setq ediff-this-buffer-ediff-sessions
2394 (delq control-buffer ediff-this-buffer-ediff-sessions))
2395 (kill-local-variable 'mode-line-buffer-identification)
2396 (kill-local-variable 'mode-line-format)
2397 )
2398 (error))
2399
2400 (condition-case nil
2401 (ediff-with-current-buffer ediff-buffer-B
2402 (setq ediff-this-buffer-ediff-sessions
2403 (delq control-buffer ediff-this-buffer-ediff-sessions))
2404 (kill-local-variable 'mode-line-buffer-identification)
2405 (kill-local-variable 'mode-line-format)
2406 )
2407 (error))
2408
2409 (condition-case nil
2410 (ediff-with-current-buffer ediff-buffer-C
2411 (setq ediff-this-buffer-ediff-sessions
2412 (delq control-buffer ediff-this-buffer-ediff-sessions))
2413 (kill-local-variable 'mode-line-buffer-identification)
2414 (kill-local-variable 'mode-line-format)
2415 )
2416 (error))
2417
2418 (condition-case nil
2419 (ediff-with-current-buffer ediff-ancestor-buffer
2420 (setq ediff-this-buffer-ediff-sessions
2421 (delq control-buffer ediff-this-buffer-ediff-sessions))
2422 (kill-local-variable 'mode-line-buffer-identification)
2423 (kill-local-variable 'mode-line-format)
2424 )
2425 (error))
2426
2427 (setq ediff-session-registry
2428 (delq ediff-control-buffer ediff-session-registry))
2429 (ediff-update-registry)
2430 ;; restore state of buffers to what it was before ediff
2431 (ediff-restore-protected-variables)
2432
2433 ;; If the user interrupts (canceling saving the merge buffer), continue
2434 ;; normally.
2435 (condition-case nil
2436 (if (ediff-merge-job)
2437 (run-hooks 'ediff-quit-merge-hook))
2438 (quit))
2439
2440 (run-hooks 'ediff-cleanup-hook)
2441
2442 ;; now kill buffers A/B/C, if requested
2443 (let ((ediff-keep-variants ediff-keep-variants))
2444 (if reverse-default-keep-variants
2445 (setq ediff-keep-variants (not ediff-keep-variants)))
2446 (or ediff-keep-variants (ediff-janitor 'ask)))
2447
2448 ;; one hook here is ediff-cleanup-mess, which kills the control buffer and
2449 ;; other auxiliary buffers. we made it into a hook to let the users do their
2450 ;; own cleanup, if needed.
2451 (run-hooks 'ediff-quit-hook)
2452 (ediff-update-meta-buffer meta-buffer nil session-number)
2453
2454 ;; warp mouse into a working window
2455 (setq warp-frame ; if mouse is over a reasonable frame, use it
2456 (cond ((ediff-good-frame-under-mouse))
2457 (t warp-frame)))
2458 (if (and (ediff-window-display-p) (frame-live-p warp-frame) ediff-grab-mouse)
2459 (set-mouse-position (if ediff-emacs-p
2460 warp-frame
2461 (frame-selected-window warp-frame))
2462 2 1))
2463
2464 (run-hooks 'after-quit-hook-internal)
2465 ))
2466
2467 ;; Returns frame under mouse, if this frame is not a minibuffer
2468 ;; frame. Otherwise: nil
2469 (defun ediff-good-frame-under-mouse ()
2470 (let ((frame-or-win (car (mouse-position)))
2471 (buf-name "")
2472 frame obj-ok)
2473 (setq obj-ok
2474 (if ediff-emacs-p
2475 (frame-live-p frame-or-win)
2476 (window-live-p frame-or-win)))
2477 (if obj-ok
2478 (setq frame (if ediff-emacs-p frame-or-win (window-frame frame-or-win))
2479 buf-name
2480 (buffer-name (window-buffer (frame-selected-window frame)))))
2481 (if (string-match "Minibuf" buf-name)
2482 nil
2483 frame)))
2484
2485
2486 (defun ediff-delete-temp-files ()
2487 (if (and (stringp ediff-temp-file-A) (file-exists-p ediff-temp-file-A))
2488 (delete-file ediff-temp-file-A))
2489 (if (and (stringp ediff-temp-file-B) (file-exists-p ediff-temp-file-B))
2490 (delete-file ediff-temp-file-B))
2491 (if (and (stringp ediff-temp-file-C) (file-exists-p ediff-temp-file-C))
2492 (delete-file ediff-temp-file-C)))
2493
2494
2495 ;; Kill control buffer, other auxiliary Ediff buffers.
2496 ;; Leave one of the frames split between buffers A/B/C
2497 (defun ediff-cleanup-mess ()
2498 (let* ((buff-A ediff-buffer-A)
2499 (buff-B ediff-buffer-B)
2500 (buff-C ediff-buffer-C)
2501 (ctl-buf ediff-control-buffer)
2502 (ctl-frame ediff-control-frame)
2503 (three-way-job ediff-3way-job)
2504 (main-frame (cond ((window-live-p ediff-window-A)
2505 (window-frame ediff-window-A))
2506 ((window-live-p ediff-window-B)
2507 (window-frame ediff-window-B)))))
2508
2509 (ediff-kill-buffer-carefully ediff-diff-buffer)
2510 (ediff-kill-buffer-carefully ediff-custom-diff-buffer)
2511 (ediff-kill-buffer-carefully ediff-fine-diff-buffer)
2512 (ediff-kill-buffer-carefully ediff-tmp-buffer)
2513 (ediff-kill-buffer-carefully ediff-error-buffer)
2514 (ediff-kill-buffer-carefully ediff-msg-buffer)
2515 (ediff-kill-buffer-carefully ediff-debug-buffer)
2516 (if (boundp 'ediff-patch-diagnostics)
2517 (ediff-kill-buffer-carefully ediff-patch-diagnostics))
2518
2519 (if (and (ediff-window-display-p) (frame-live-p ctl-frame))
2520 (delete-frame ctl-frame))
2521 ;; Hide bottom toolbar. --marcpa
2522 (if (not (ediff-multiframe-setup-p))
2523 (ediff-kill-bottom-toolbar))
2524
2525 (ediff-kill-buffer-carefully ctl-buf)
2526
2527 (if (frame-live-p main-frame)
2528 (progn
2529 (select-frame main-frame)
2530 (delete-other-windows)))
2531
2532 ;; display only if not visible
2533 (condition-case nil
2534 (or (ediff-get-visible-buffer-window buff-B)
2535 (switch-to-buffer buff-B))
2536 (error))
2537 (condition-case nil
2538 (or (ediff-get-visible-buffer-window buff-A)
2539 (progn
2540 (if (ediff-get-visible-buffer-window buff-B)
2541 (funcall ediff-split-window-function))
2542 (switch-to-buffer buff-A)))
2543 (error))
2544 (if three-way-job
2545 (condition-case nil
2546 (or (ediff-get-visible-buffer-window buff-C)
2547 (progn
2548 (if (or (ediff-get-visible-buffer-window buff-A)
2549 (ediff-get-visible-buffer-window buff-B))
2550 (funcall ediff-split-window-function))
2551 (switch-to-buffer buff-C)
2552 (balance-windows)))
2553 (error)))
2554 (message "")
2555 ))
2556
2557 (defun ediff-janitor (&optional ask)
2558 "Kill buffers A, B, and, possibly, C, if these buffers aren't modified.
2559 In merge jobs, buffer C is never deleted.
2560 However, the side effect of cleaning up may be that you cannot compare the same
2561 buffer in two separate Ediff sessions: quitting one of them will delete this
2562 buffer in another session as well."
2563 (or (not (ediff-buffer-live-p ediff-buffer-A))
2564 (buffer-modified-p ediff-buffer-A)
2565 (and ask
2566 (not (y-or-n-p (format "Kill buffer A [%s]? "
2567 (buffer-name ediff-buffer-A)))))
2568 (ediff-kill-buffer-carefully ediff-buffer-A))
2569 (or (not (ediff-buffer-live-p ediff-buffer-B))
2570 (buffer-modified-p ediff-buffer-B)
2571 (and ask
2572 (not (y-or-n-p (format "Kill buffer B [%s]? "
2573 (buffer-name ediff-buffer-B)))))
2574 (ediff-kill-buffer-carefully ediff-buffer-B))
2575 (if ediff-merge-job ; don't del buf C if merging--del ancestor buf instead
2576 (or (not (ediff-buffer-live-p ediff-ancestor-buffer))
2577 (buffer-modified-p ediff-ancestor-buffer)
2578 (and ask
2579 (not (y-or-n-p (format "Kill the ancestor buffer [%s]? "
2580 (buffer-name ediff-ancestor-buffer)))))
2581 (ediff-kill-buffer-carefully ediff-ancestor-buffer))
2582 (or (not (ediff-buffer-live-p ediff-buffer-C))
2583 (buffer-modified-p ediff-buffer-C)
2584 (and ask (not (y-or-n-p (format "Kill buffer C [%s]? "
2585 (buffer-name ediff-buffer-C)))))
2586 (ediff-kill-buffer-carefully ediff-buffer-C))))
2587
2588 (defun ediff-maybe-save-and-delete-merge (&optional save-and-continue)
2589 "Default hook to run on quitting a merge job.
2590 This can also be used to save merge buffer in the middle of an Ediff session.
2591
2592 If the optional SAVE-AND-CONTINUE argument is non-nil, save merge buffer and
2593 continue. Otherwise:
2594 If `ediff-autostore-merges' is nil, this does nothing.
2595 If it is t, it saves the merge buffer in the file `ediff-merge-store-file'
2596 or asks the user, if the latter is nil. It then asks the user whether to
2597 delete the merge buffer.
2598 If `ediff-autostore-merges' is neither nil nor t, the merge buffer is saved
2599 only if this merge job is part of a group, i.e., was invoked from within
2600 `ediff-merge-directories', `ediff-merge-directory-revisions', and such."
2601 (let ((merge-store-file ediff-merge-store-file)
2602 (ediff-autostore-merges ; fake ediff-autostore-merges, if necessary
2603 (if save-and-continue t ediff-autostore-merges)))
2604 (if ediff-autostore-merges
2605 (cond ((stringp ediff-merge-store-file)
2606 ;; store, ask to delete
2607 (ediff-write-merge-buffer-and-maybe-kill
2608 ediff-buffer-C merge-store-file 'show-file save-and-continue))
2609 ((eq ediff-autostore-merges t)
2610 ;; ask for file name
2611 (setq merge-store-file
2612 (read-file-name "Save the merge buffer in file: "))
2613 (ediff-write-merge-buffer-and-maybe-kill
2614 ediff-buffer-C merge-store-file nil save-and-continue))
2615 ((and (ediff-buffer-live-p ediff-meta-buffer)
2616 (ediff-with-current-buffer ediff-meta-buffer
2617 (ediff-merge-metajob)))
2618 ;; The parent metajob passed nil as the autostore file.
2619 nil)))
2620 ))
2621
2622 ;; write merge buffer. If the optional argument save-and-continue is non-nil,
2623 ;; then don't kill the merge buffer
2624 (defun ediff-write-merge-buffer-and-maybe-kill (buf file
2625 &optional
2626 show-file save-and-continue)
2627 (ediff-with-current-buffer buf
2628 (if (or (not (file-exists-p file))
2629 (y-or-n-p (format "File %s exists, overwrite? " file)))
2630 (progn
2631 (write-region (point-min) (point-max) file)
2632 (if show-file
2633 (progn
2634 (message "Merge buffer saved in: %s" file)
2635 (set-buffer-modified-p nil)
2636 (sit-for 3)))
2637 (if (and
2638 (not save-and-continue)
2639 (y-or-n-p "Merge buffer saved. Now kill the buffer? "))
2640 (ediff-kill-buffer-carefully buf))))))
2641
2642 ;; The default way of suspending Ediff.
2643 ;; Buries Ediff buffers, kills all windows.
2644 (defun ediff-default-suspend-function ()
2645 (let* ((buf-A ediff-buffer-A)
2646 (buf-B ediff-buffer-B)
2647 (buf-C ediff-buffer-C)
2648 (buf-A-wind (ediff-get-visible-buffer-window buf-A))
2649 (buf-B-wind (ediff-get-visible-buffer-window buf-B))
2650 (buf-C-wind (ediff-get-visible-buffer-window buf-C))
2651 (buf-patch (if (boundp 'ediff-patchbufer) ediff-patchbufer nil))
2652 (buf-patch-diag (if (boundp 'ediff-patch-diagnostics)
2653 ediff-patch-diagnostics nil))
2654 (buf-err ediff-error-buffer)
2655 (buf-diff ediff-diff-buffer)
2656 (buf-custom-diff ediff-custom-diff-buffer)
2657 (buf-fine-diff ediff-fine-diff-buffer))
2658
2659 ;; hide the control panel
2660 (if (and (ediff-window-display-p) (frame-live-p ediff-control-frame))
2661 (iconify-frame ediff-control-frame)
2662 (bury-buffer))
2663 (if buf-err (bury-buffer buf-err))
2664 (if buf-diff (bury-buffer buf-diff))
2665 (if buf-custom-diff (bury-buffer buf-custom-diff))
2666 (if buf-fine-diff (bury-buffer buf-fine-diff))
2667 (if buf-patch (bury-buffer buf-patch))
2668 (if buf-patch-diag (bury-buffer buf-patch-diag))
2669 (if (window-live-p buf-A-wind)
2670 (progn
2671 (select-window buf-A-wind)
2672 (delete-other-windows)
2673 (bury-buffer))
2674 (if (ediff-buffer-live-p buf-A)
2675 (progn
2676 (set-buffer buf-A)
2677 (bury-buffer))))
2678 (if (window-live-p buf-B-wind)
2679 (progn
2680 (select-window buf-B-wind)
2681 (delete-other-windows)
2682 (bury-buffer))
2683 (if (ediff-buffer-live-p buf-B)
2684 (progn
2685 (set-buffer buf-B)
2686 (bury-buffer))))
2687 (if (window-live-p buf-C-wind)
2688 (progn
2689 (select-window buf-C-wind)
2690 (delete-other-windows)
2691 (bury-buffer))
2692 (if (ediff-buffer-live-p buf-C)
2693 (progn
2694 (set-buffer buf-C)
2695 (bury-buffer))))
2696 ))
2697
2698
2699 (defun ediff-suspend ()
2700 "Suspend Ediff.
2701 To resume, switch to the appropriate `Ediff Control Panel'
2702 buffer and then type \\[ediff-recenter]. Ediff will automatically set
2703 up an appropriate window config."
2704 (interactive)
2705 (ediff-barf-if-not-control-buffer)
2706 (run-hooks 'ediff-suspend-hook)
2707 (message
2708 "To resume, type M-x eregistry and select the desired Ediff session"))
2709
2710
2711 (defun ediff-status-info ()
2712 "Show the names of the buffers or files being operated on by Ediff.
2713 Hit \\[ediff-recenter] to reset the windows afterward."
2714 (interactive)
2715 (ediff-barf-if-not-control-buffer)
2716 (save-excursion
2717 (ediff-skip-unsuitable-frames))
2718 (with-output-to-temp-buffer ediff-msg-buffer
2719 (ediff-with-current-buffer standard-output
2720 (fundamental-mode))
2721 (raise-frame (selected-frame))
2722 (princ (ediff-version))
2723 (princ "\n\n")
2724 (ediff-with-current-buffer ediff-buffer-A
2725 (if buffer-file-name
2726 (princ
2727 (format "File A = %S\n" buffer-file-name))
2728 (princ
2729 (format "Buffer A = %S\n" (buffer-name)))))
2730 (ediff-with-current-buffer ediff-buffer-B
2731 (if buffer-file-name
2732 (princ
2733 (format "File B = %S\n" buffer-file-name))
2734 (princ
2735 (format "Buffer B = %S\n" (buffer-name)))))
2736 (if ediff-3way-job
2737 (ediff-with-current-buffer ediff-buffer-C
2738 (if buffer-file-name
2739 (princ
2740 (format "File C = %S\n" buffer-file-name))
2741 (princ
2742 (format "Buffer C = %S\n" (buffer-name))))))
2743 (princ (format "Customized diff output %s\n"
2744 (if (ediff-buffer-live-p ediff-custom-diff-buffer)
2745 (concat "\tin buffer "
2746 (buffer-name ediff-custom-diff-buffer))
2747 " is not available")))
2748 (princ (format "Plain diff output %s\n"
2749 (if (ediff-buffer-live-p ediff-diff-buffer)
2750 (concat "\tin buffer "
2751 (buffer-name ediff-diff-buffer))
2752 " is not available")))
2753
2754 (let* ((A-line (ediff-with-current-buffer ediff-buffer-A
2755 (1+ (count-lines (point-min) (point)))))
2756 (B-line (ediff-with-current-buffer ediff-buffer-B
2757 (1+ (count-lines (point-min) (point)))))
2758 C-line)
2759 (princ (format "\Buffer A's point is on line %d\n" A-line))
2760 (princ (format "Buffer B's point is on line %d\n" B-line))
2761 (if ediff-3way-job
2762 (progn
2763 (setq C-line (ediff-with-current-buffer ediff-buffer-C
2764 (1+ (count-lines (point-min) (point)))))
2765 (princ (format "Buffer C's point is on line %d\n" C-line)))))
2766
2767 (princ (format "\nCurrent difference number = %S\n"
2768 (cond ((< ediff-current-difference 0) 'start)
2769 ((>= ediff-current-difference
2770 ediff-number-of-differences) 'end)
2771 (t (1+ ediff-current-difference)))))
2772
2773 (princ
2774 (format "\n%s regions that differ in white space & line breaks only"
2775 (if ediff-ignore-similar-regions
2776 "Ignoring" "Showing")))
2777 (if (and ediff-merge-job ediff-show-clashes-only)
2778 (princ
2779 "\nFocusing on regions where both buffers differ from the ancestor"))
2780 (if (and ediff-skip-merge-regions-that-differ-from-default ediff-merge-job)
2781 (princ
2782 "\nSkipping merge regions that differ from default setting"))
2783
2784 (cond ((eq ediff-skip-diff-region-function 'ediff-show-all-diffs)
2785 (princ "\nSelective browsing by regexp is off\n"))
2786 ((eq ediff-skip-diff-region-function
2787 ediff-hide-regexp-matches-function)
2788 (princ
2789 "\nIgnoring regions that match")
2790 (princ
2791 (format
2792 "\n\t regexp `%s' in buffer A %S\n\t regexp `%s' in buffer B\n"
2793 ediff-regexp-hide-A ediff-hide-regexp-connective
2794 ediff-regexp-hide-B)))
2795 ((eq ediff-skip-diff-region-function
2796 ediff-focus-on-regexp-matches-function)
2797 (princ
2798 "\nFocusing on regions that match")
2799 (princ
2800 (format
2801 "\n\t regexp `%s' in buffer A %S\n\t regexp `%s' in buffer B\n"
2802 ediff-regexp-focus-A ediff-focus-regexp-connective
2803 ediff-regexp-focus-B)))
2804 (t (princ "\nSelective browsing via a user-defined method.\n")))
2805
2806 (princ
2807 (format "\nBugs/suggestions: type `%s' while in Ediff Control Panel."
2808 (substitute-command-keys "\\[ediff-submit-report]")))
2809 ) ; with output
2810 (if (frame-live-p ediff-control-frame)
2811 (ediff-reset-mouse ediff-control-frame))
2812 (if (window-live-p ediff-control-window)
2813 (select-window ediff-control-window)))
2814
2815
2816
2817 \f
2818 ;;; Support routines
2819
2820 ;; Select a difference by placing the ASCII flags around the appropriate
2821 ;; group of lines in the A, B buffers
2822 ;; This may have to be modified for buffer C, when it will be supported.
2823 (defun ediff-select-difference (n)
2824 (if (and (ediff-buffer-live-p ediff-buffer-A)
2825 (ediff-buffer-live-p ediff-buffer-B)
2826 (ediff-valid-difference-p n))
2827 (progn
2828 (if (and (ediff-has-face-support-p) ediff-use-faces)
2829 (progn
2830 (ediff-highlight-diff n)
2831 (setq ediff-highlighting-style 'face))
2832 (setq ediff-highlighting-style 'ascii)
2833 (ediff-place-flags-in-buffer
2834 'A ediff-buffer-A ediff-control-buffer n)
2835 (ediff-place-flags-in-buffer
2836 'B ediff-buffer-B ediff-control-buffer n)
2837 (if ediff-3way-job
2838 (ediff-place-flags-in-buffer
2839 'C ediff-buffer-C ediff-control-buffer n))
2840 (if (ediff-buffer-live-p ediff-ancestor-buffer)
2841 (ediff-place-flags-in-buffer
2842 'Ancestor ediff-ancestor-buffer
2843 ediff-control-buffer n))
2844 )
2845
2846 (ediff-install-fine-diff-if-necessary n)
2847 (run-hooks 'ediff-select-hook))))
2848
2849
2850 ;; Unselect a difference by removing the ASCII flags in the buffers.
2851 ;; This may have to be modified for buffer C, when it will be supported.
2852 (defun ediff-unselect-difference (n)
2853 (if (ediff-valid-difference-p n)
2854 (progn
2855 (cond ((and (ediff-has-face-support-p) ediff-use-faces)
2856 (ediff-unhighlight-diff))
2857 ((eq ediff-highlighting-style 'ascii)
2858 (ediff-remove-flags-from-buffer
2859 ediff-buffer-A
2860 (ediff-get-diff-overlay n 'A))
2861 (ediff-remove-flags-from-buffer
2862 ediff-buffer-B
2863 (ediff-get-diff-overlay n 'B))
2864 (if ediff-3way-job
2865 (ediff-remove-flags-from-buffer
2866 ediff-buffer-C
2867 (ediff-get-diff-overlay n 'C)))
2868 (if (ediff-buffer-live-p ediff-ancestor-buffer)
2869 (ediff-remove-flags-from-buffer
2870 ediff-ancestor-buffer
2871 (ediff-get-diff-overlay n 'Ancestor)))
2872 ))
2873 (setq ediff-highlighting-style nil)
2874
2875 ;; unhighlight fine diffs
2876 (ediff-set-fine-diff-properties ediff-current-difference 'default)
2877 (run-hooks 'ediff-unselect-hook))))
2878
2879
2880 ;; Unselects prev diff and selects a new one, if FLAG has value other than
2881 ;; 'select-only or 'unselect-only. If FLAG is 'select-only, the
2882 ;; next difference is selected, but the current selection is not
2883 ;; unselected. If FLAG is 'unselect-only then the current selection is
2884 ;; unselected, but the next one is not selected. If NO-RECENTER is non-nil,
2885 ;; don't recenter buffers after selecting/unselecting.
2886 (defun ediff-unselect-and-select-difference (n &optional flag no-recenter)
2887 (let ((ediff-current-difference n))
2888 (or no-recenter
2889 (ediff-recenter 'no-rehighlight)))
2890
2891 (let ((control-buf ediff-control-buffer))
2892 (unwind-protect
2893 (progn
2894 (or (eq flag 'select-only)
2895 (ediff-unselect-difference ediff-current-difference))
2896
2897 (or (eq flag 'unselect-only)
2898 (ediff-select-difference n))
2899 (setq ediff-current-difference n)
2900 ) ; end protected section
2901
2902 (ediff-with-current-buffer control-buf (ediff-refresh-mode-lines))
2903 )))
2904
2905
2906 ;; This is adapted from a similar function in `emerge.el'.
2907 ;; PROMPT should not have a trailing ': ', so that it can be modified
2908 ;; according to context.
2909 ;; If DEFAULT-FILE is set, it should be used as the default value.
2910 ;; If DEFAULT-DIR is non-nil, use it as the default directory.
2911 ;; Otherwise, use the value of Emacs' variable `default-directory.'
2912 (defun ediff-read-file-name (prompt default-dir default-file)
2913 ;; hack default-dir if it is not set
2914 (setq default-dir
2915 (file-name-as-directory
2916 (ediff-abbreviate-file-name
2917 (expand-file-name (or default-dir
2918 (and default-file
2919 (file-name-directory default-file))
2920 default-directory)))))
2921
2922 ;; strip the directory from default-file
2923 (if default-file
2924 (setq default-file (file-name-nondirectory default-file)))
2925 (if (string= default-file "")
2926 (setq default-file nil))
2927
2928 (let (f)
2929 (setq f (expand-file-name
2930 (read-file-name
2931 (format "%s%s "
2932 prompt
2933 (cond (default-file
2934 (concat " (default " default-file "):"))
2935 (t (concat " (default " default-dir "):"))))
2936 default-dir
2937 (or default-file default-dir)
2938 t ; must match, no-confirm
2939 (if default-file (file-name-directory default-file))
2940 )
2941 default-dir
2942 ))
2943 ;; If user enters a directory name, expand the default file in that
2944 ;; directory. This allows the user to enter a directory name for the
2945 ;; B-file and diff against the default-file in that directory instead
2946 ;; of a DIRED listing!
2947 (if (and (file-directory-p f) default-file)
2948 (setq f (expand-file-name
2949 (file-name-nondirectory default-file) f)))
2950 f))
2951
2952 ;; If PREFIX is given, then it is used as a prefix for the temp file
2953 ;; name. Otherwise, `ediff' is used. If FILE is given, use this
2954 ;; file and don't create a new one.
2955 ;; In MS-DOS, make sure the prefix isn't too long, or else
2956 ;; `make-temp-name' isn't guaranteed to return a unique filename.
2957 ;; Also, save buffer from START to END in the file.
2958 ;; START defaults to (point-min), END to (point-max)
2959 (defun ediff-make-temp-file (buff &optional prefix given-file start end)
2960 (let* ((p (ediff-convert-standard-filename (or prefix "ediff")))
2961 (short-p p)
2962 (coding-system-for-write 'no-conversion)
2963 f short-f)
2964 (if (and (fboundp 'msdos-long-file-names)
2965 (not (msdos-long-file-names))
2966 (> (length p) 2))
2967 (setq short-p (substring p 0 2)))
2968
2969 (setq f (concat ediff-temp-file-prefix p)
2970 short-f (concat ediff-temp-file-prefix short-p)
2971 f (cond (given-file)
2972 ((find-file-name-handler f 'find-file-noselect)
2973 ;; to thwart file handlers in write-region, e.g., if file
2974 ;; name ends with .Z or .gz
2975 ;; This is needed so that patches produced by ediff will
2976 ;; have more meaningful names
2977 (ediff-make-empty-tmp-file short-f))
2978 (prefix
2979 ;; Prefix is most often the same as the file name for the
2980 ;; variant. Here we are trying to use the original file
2981 ;; name but in the temp directory.
2982 (ediff-make-empty-tmp-file f 'keep-name))
2983 (t
2984 ;; If don't care about name, add some random stuff
2985 ;; to proposed file name.
2986 (ediff-make-empty-tmp-file short-f))))
2987
2988 ;; create the file
2989 (ediff-with-current-buffer buff
2990 (write-region (if start start (point-min))
2991 (if end end (point-max))
2992 f
2993 nil ; don't append---erase
2994 'no-message)
2995 (set-file-modes f ediff-temp-file-mode)
2996 (expand-file-name f))))
2997
2998 ;; Create a temporary file.
2999 ;; The returned file name (created by appending some random characters at the
3000 ;; end of PROPOSED-NAME is guaranteed to point to a newly created empty file.
3001 ;; This is a replacement for make-temp-name, which eliminates a security hole.
3002 ;; If KEEP-PROPOSED-NAME isn't nil, try to keep PROPOSED-NAME, unless such file
3003 ;; already exists.
3004 ;; It is a modified version of make-temp-file in emacs 20.5
3005 (defun ediff-make-empty-tmp-file (proposed-name &optional keep-proposed-name)
3006 (let ((file proposed-name))
3007 (while (condition-case ()
3008 (progn
3009 (if (or (file-exists-p file) (not keep-proposed-name))
3010 (setq file (make-temp-name proposed-name)))
3011 (write-region "" nil file nil 'silent nil 'excl)
3012 nil)
3013 (file-already-exists t))
3014 ;; the file was somehow created by someone else between
3015 ;; `make-temp-name' and `write-region', let's try again.
3016 nil)
3017 file))
3018
3019
3020 ;; Quote metacharacters (using \) when executing diff in Unix, but not in
3021 ;; EMX OS/2
3022 ;;(defun ediff-protect-metachars (str)
3023 ;; (or (memq system-type '(emx vax-vms axp-vms))
3024 ;; (let ((limit 0))
3025 ;; (while (string-match ediff-metachars str limit)
3026 ;; (setq str (concat (substring str 0 (match-beginning 0))
3027 ;; "\\"
3028 ;; (substring str (match-beginning 0))))
3029 ;; (setq limit (1+ (match-end 0))))))
3030 ;; str)
3031
3032 ;; Make sure the current buffer (for a file) has the same contents as the
3033 ;; file on disk, and attempt to remedy the situation if not.
3034 ;; Signal an error if we can't make them the same, or the user doesn't want
3035 ;; to do what is necessary to make them the same.
3036 ;; Also, Ediff always offers to revert obsolete buffers, whether they
3037 ;; are modified or not.
3038 (defun ediff-verify-file-buffer (&optional file-magic)
3039 ;; First check if the file has been modified since the buffer visited it.
3040 (if (verify-visited-file-modtime (current-buffer))
3041 (if (buffer-modified-p)
3042 ;; If buffer is not obsolete and is modified, offer to save
3043 (if (yes-or-no-p
3044 (format "Buffer out of sync with visited file. Save file %s? "
3045 buffer-file-name))
3046 (condition-case nil
3047 (save-buffer)
3048 (error
3049 (beep)
3050 (message "Couldn't save %s" buffer-file-name)))
3051 (error "Buffer is out of sync for file %s" buffer-file-name))
3052 ;; If buffer is not obsolete and is not modified, do nothing
3053 nil)
3054 ;; If buffer is obsolete, offer to revert
3055 (if (yes-or-no-p
3056 (format "Buffer is out of sync with visited file. REVERT file %s? "
3057 buffer-file-name))
3058 (progn
3059 (if file-magic
3060 (erase-buffer))
3061 (revert-buffer t t))
3062 (error "Buffer out of sync for file %s" buffer-file-name))))
3063
3064
3065 (defun ediff-filename-magic-p (file)
3066 (or (ediff-file-compressed-p file)
3067 (ediff-file-remote-p file)))
3068
3069
3070 (defun ediff-save-buffer (arg)
3071 "Safe way of saving buffers A, B, C, and the diff output.
3072 `wa' saves buffer A, `wb' saves buffer B, `wc' saves buffer C,
3073 and `wd' saves the diff output.
3074
3075 With prefix argument, `wd' saves plain diff output.
3076 Without an argument, it saves customized diff argument, if available
3077 \(and plain output, if customized output was not generated\)."
3078 (interactive "P")
3079 (ediff-barf-if-not-control-buffer)
3080 (ediff-compute-custom-diffs-maybe)
3081 (ediff-with-current-buffer
3082 (cond ((memq last-command-char '(?a ?b ?c))
3083 (ediff-get-buffer
3084 (ediff-char-to-buftype last-command-char)))
3085 ((eq last-command-char ?d)
3086 (message "Saving diff output ...")
3087 (sit-for 1) ; let the user see the message
3088 (cond ((and arg (ediff-buffer-live-p ediff-diff-buffer))
3089 ediff-diff-buffer)
3090 ((ediff-buffer-live-p ediff-custom-diff-buffer)
3091 ediff-custom-diff-buffer)
3092 ((ediff-buffer-live-p ediff-diff-buffer)
3093 ediff-diff-buffer)
3094 (t (error "Output from `diff' not found"))))
3095 )
3096 (save-buffer)))
3097
3098 (defun ediff-compute-custom-diffs-maybe ()
3099 (let ((buf-A-file-name (buffer-file-name ediff-buffer-A))
3100 (buf-B-file-name (buffer-file-name ediff-buffer-B))
3101 file-A file-B)
3102 (if (stringp buf-A-file-name)
3103 (setq buf-A-file-name (file-name-nondirectory buf-A-file-name)))
3104 (if (stringp buf-B-file-name)
3105 (setq buf-B-file-name (file-name-nondirectory buf-B-file-name)))
3106 (setq file-A (ediff-make-temp-file ediff-buffer-A buf-A-file-name)
3107 file-B (ediff-make-temp-file ediff-buffer-B buf-B-file-name))
3108
3109 (or (ediff-buffer-live-p ediff-custom-diff-buffer)
3110 (setq ediff-custom-diff-buffer
3111 (get-buffer-create
3112 (ediff-unique-buffer-name "*ediff-custom-diff" "*"))))
3113 (ediff-exec-process
3114 ediff-custom-diff-program ediff-custom-diff-buffer 'synchronize
3115 ediff-custom-diff-options file-A file-B)
3116 (delete-file file-A)
3117 (delete-file file-B)
3118 ))
3119
3120 (defun ediff-show-diff-output (arg)
3121 (interactive "P")
3122 (ediff-barf-if-not-control-buffer)
3123 (ediff-compute-custom-diffs-maybe)
3124 (save-excursion
3125 (ediff-skip-unsuitable-frames ' ok-unsplittable))
3126 (let ((buf (cond ((and arg (ediff-buffer-live-p ediff-diff-buffer))
3127 ediff-diff-buffer)
3128 ((ediff-buffer-live-p ediff-custom-diff-buffer)
3129 ediff-custom-diff-buffer)
3130 ((ediff-buffer-live-p ediff-diff-buffer)
3131 ediff-diff-buffer)
3132 (t
3133 (beep)
3134 (message "Output from `diff' not found")
3135 nil))))
3136 (if buf
3137 (progn
3138 (ediff-with-current-buffer buf
3139 (goto-char (point-min)))
3140 (switch-to-buffer buf)
3141 (raise-frame (selected-frame)))))
3142 (if (frame-live-p ediff-control-frame)
3143 (ediff-reset-mouse ediff-control-frame))
3144 (if (window-live-p ediff-control-window)
3145 (select-window ediff-control-window)))
3146
3147
3148 (defun ediff-inferior-compare-regions ()
3149 "Compare regions in an active Ediff session.
3150 Like ediff-regions-linewise but is called from under an active Ediff session on
3151 the files that belong to that session.
3152
3153 After quitting the session invoked via this function, type C-l to the parent
3154 Ediff Control Panel to restore highlighting."
3155 (interactive)
3156 (let ((answer "")
3157 (possibilities (list ?A ?B ?C))
3158 (zmacs-regions t)
3159 (ctl-buf (current-buffer))
3160 quit-now
3161 begA begB endA endB bufA bufB)
3162
3163 (cond ((ediff-merge-job)
3164 (setq bufB ediff-buffer-C)
3165 (while (cond ((eq answer ?A)
3166 (setq bufA ediff-buffer-A
3167 possibilities '(?B))
3168 nil)
3169 ((eq answer ?B)
3170 (setq bufA ediff-buffer-B
3171 possibilities '(?A))
3172 nil)
3173 ((equal answer ""))
3174 (t (beep 1)
3175 (message "Valid values are A or B")
3176 (sit-for 2)
3177 t))
3178 (let ((cursor-in-echo-area t))
3179 (message "Which buffer to compare to the merge buffer (A/B)? ")
3180 (setq answer (capitalize (read-char-exclusive))))))
3181
3182 ((ediff-3way-comparison-job)
3183 (while (cond ((memq answer possibilities)
3184 (setq possibilities (delq answer possibilities))
3185 (setq bufA
3186 (eval
3187 (ediff-get-symbol-from-alist
3188 answer ediff-buffer-alist)))
3189 nil)
3190 ((equal answer ""))
3191 (t (beep 1)
3192 (message
3193 "Valid values are %s"
3194 (mapconcat 'char-to-string possibilities " or "))
3195 (sit-for 2)
3196 t))
3197 (let ((cursor-in-echo-area t))
3198 (message "Enter the 1st buffer you want to compare (%s): "
3199 (mapconcat 'char-to-string possibilities "/"))
3200 (setq answer (capitalize (read-char-exclusive)))))
3201 (setq answer "") ; silence error msg
3202 (while (cond ((memq answer possibilities)
3203 (setq possibilities (delq answer possibilities))
3204 (setq bufB
3205 (eval
3206 (ediff-get-symbol-from-alist
3207 answer ediff-buffer-alist)))
3208 nil)
3209 ((equal answer ""))
3210 (t (beep 1)
3211 (message
3212 "Valid values are %s"
3213 (mapconcat 'char-to-string possibilities " or "))
3214 (sit-for 2)
3215 t))
3216 (let ((cursor-in-echo-area t))
3217 (message "Enter the 2nd buffer you want to compare (%s): "
3218 (mapconcat 'char-to-string possibilities "/"))
3219 (setq answer (capitalize (read-char-exclusive))))))
3220 (t ; 2way comparison
3221 (setq bufA ediff-buffer-A
3222 bufB ediff-buffer-B
3223 possibilities nil)))
3224
3225 (ediff-with-current-buffer bufA
3226 (or (mark t)
3227 (error "You forgot to specify a region in buffer %s" (buffer-name)))
3228 (setq begA (region-beginning)
3229 endA (region-end))
3230 (goto-char begA)
3231 (beginning-of-line)
3232 (setq begA (point))
3233 (goto-char endA)
3234 (end-of-line)
3235 (or (eobp) (forward-char)) ; include the newline char
3236 (setq endA (point)))
3237 (ediff-with-current-buffer bufB
3238 (or (mark t)
3239 (error "You forgot to specify a region in buffer %s" (buffer-name)))
3240 (setq begB (region-beginning)
3241 endB (region-end))
3242 (goto-char begB)
3243 (beginning-of-line)
3244 (setq begB (point))
3245 (goto-char endB)
3246 (end-of-line)
3247 (or (eobp) (forward-char)) ; include the newline char
3248 (setq endB (point)))
3249
3250 (ediff-unselect-and-select-difference
3251 ediff-current-difference 'unselect-only)
3252 (ediff-paint-background-regions 'unhighlight)
3253
3254 (ediff-with-current-buffer bufA
3255 (goto-char begA)
3256 (set-mark endA)
3257 (narrow-to-region begA endA)
3258 ;; (ediff-activate-mark)
3259 )
3260 ;; (sit-for 0)
3261 (ediff-with-current-buffer bufB
3262 (goto-char begB)
3263 (set-mark endB)
3264 (narrow-to-region begB endB)
3265 ;; (ediff-activate-mark)
3266 )
3267 ;; (sit-for 0)
3268
3269 ;; At this point, possibilities contains either the window char A/B/C
3270 ;; that was not selected, or it is nil. We delete the window that is not
3271 ;; selected.
3272 (if possibilities
3273 (ediff-with-current-buffer ctl-buf
3274 (let* ((wind-to-delete (eval
3275 (ediff-get-symbol-from-alist
3276 (car possibilities)
3277 ediff-window-alist)))
3278 (frame (window-frame wind-to-delete)))
3279 (delete-window wind-to-delete)
3280 (select-frame frame)
3281 (balance-windows))))
3282 (or (y-or-n-p
3283 "Please check regions selected for comparison. Continue? ")
3284 (setq quit-now t))
3285
3286 (ediff-with-current-buffer bufA
3287 (widen))
3288 (ediff-with-current-buffer bufB
3289 (widen))
3290 (if quit-now
3291 (ediff-with-current-buffer ctl-buf
3292 (ediff-recenter)
3293 (sit-for 0)
3294 (error "All right. Make up your mind and come back...")))
3295
3296 (ediff-regions-internal
3297 bufA begA endA bufB begB endB
3298 nil ; setup-hook
3299 'ediff-regions-linewise ; job name
3300 nil ; no word mode
3301 ;; setup param to pass to ediff-setup
3302 (list (cons 'ediff-split-window-function ediff-split-window-function)))
3303 ))
3304
3305
3306
3307 (defun ediff-remove-flags-from-buffer (buffer overlay)
3308 (ediff-with-current-buffer buffer
3309 (let ((inhibit-read-only t))
3310 (if ediff-xemacs-p
3311 (ediff-overlay-put overlay 'begin-glyph nil)
3312 (ediff-overlay-put overlay 'before-string nil))
3313
3314 (if ediff-xemacs-p
3315 (ediff-overlay-put overlay 'end-glyph nil)
3316 (ediff-overlay-put overlay 'after-string nil))
3317 )))
3318
3319
3320
3321 (defun ediff-place-flags-in-buffer (buf-type buffer ctl-buffer diff)
3322 (ediff-with-current-buffer buffer
3323 (ediff-place-flags-in-buffer1 buf-type ctl-buffer diff)))
3324
3325
3326 (defun ediff-place-flags-in-buffer1 (buf-type ctl-buffer diff-no)
3327 (let* ((curr-overl (ediff-with-current-buffer ctl-buffer
3328 (ediff-get-diff-overlay diff-no buf-type)))
3329 (before (ediff-get-diff-posn buf-type 'beg diff-no ctl-buffer))
3330 after beg-of-line flag)
3331
3332 ;; insert flag before the difference
3333 (goto-char before)
3334 (setq beg-of-line (bolp))
3335
3336 (setq flag (ediff-with-current-buffer ctl-buffer
3337 (if (eq ediff-highlighting-style 'ascii)
3338 (if beg-of-line
3339 ediff-before-flag-bol ediff-before-flag-mol))))
3340
3341 ;; insert the flag itself
3342 (if ediff-xemacs-p
3343 (ediff-overlay-put curr-overl 'begin-glyph flag)
3344 (ediff-overlay-put curr-overl 'before-string flag))
3345
3346 ;; insert the flag after the difference
3347 ;; `after' must be set here, after the before-flag was inserted
3348 (setq after (ediff-get-diff-posn buf-type 'end diff-no ctl-buffer))
3349 (goto-char after)
3350 (setq beg-of-line (bolp))
3351
3352 (setq flag (ediff-with-current-buffer ctl-buffer
3353 (if (eq ediff-highlighting-style 'ascii)
3354 (if beg-of-line
3355 ediff-after-flag-eol ediff-after-flag-mol))))
3356
3357 ;; insert the flag itself
3358 (if ediff-xemacs-p
3359 (ediff-overlay-put curr-overl 'end-glyph flag)
3360 (ediff-overlay-put curr-overl 'after-string flag))
3361 ))
3362
3363
3364 ;; Returns positions of difference sectors in the BUF-TYPE buffer.
3365 ;; BUF-TYPE should be a symbol -- `A', `B', or `C'.
3366 ;; POS is either `beg' or `end'--it specifies whether you want the position at
3367 ;; the beginning of a difference or at the end.
3368 ;;
3369 ;; The optional argument N says which difference (default:
3370 ;; `ediff-current-difference'). N is the internal difference number (1- what
3371 ;; the user sees). The optional argument CONTROL-BUF says
3372 ;; which control buffer is in effect in case it is not the current
3373 ;; buffer.
3374 (defun ediff-get-diff-posn (buf-type pos &optional n control-buf)
3375 (let (diff-overlay)
3376 (or control-buf
3377 (setq control-buf (current-buffer)))
3378
3379 (ediff-with-current-buffer control-buf
3380 (or n (setq n ediff-current-difference))
3381 (if (or (< n 0) (>= n ediff-number-of-differences))
3382 (if (> ediff-number-of-differences 0)
3383 (error ediff-BAD-DIFF-NUMBER
3384 this-command (1+ n) ediff-number-of-differences)
3385 (error ediff-NO-DIFFERENCES)))
3386 (setq diff-overlay (ediff-get-diff-overlay n buf-type)))
3387 (if (not (ediff-buffer-live-p (ediff-overlay-buffer diff-overlay)))
3388 (error ediff-KILLED-VITAL-BUFFER))
3389 (if (eq pos 'beg)
3390 (ediff-overlay-start diff-overlay)
3391 (ediff-overlay-end diff-overlay))
3392 ))
3393
3394
3395 ;; Restore highlighting to what it should be according to ediff-use-faces,
3396 ;; ediff-highlighting-style, and ediff-highlight-all-diffs variables.
3397 (defun ediff-restore-highlighting (&optional ctl-buf)
3398 (ediff-with-current-buffer (or ctl-buf (current-buffer))
3399 (if (and (ediff-has-face-support-p)
3400 ediff-use-faces
3401 ediff-highlight-all-diffs)
3402 (ediff-paint-background-regions))
3403 (ediff-select-difference ediff-current-difference)))
3404
3405
3406
3407 ;; null out difference overlays so they won't slow down future
3408 ;; editing operations
3409 ;; VEC is either a difference vector or a fine-diff vector
3410 (defun ediff-clear-diff-vector (vec-var &optional fine-diffs-also)
3411 (if (vectorp (symbol-value vec-var))
3412 (mapcar (lambda (elt)
3413 (ediff-delete-overlay
3414 (ediff-get-diff-overlay-from-diff-record elt))
3415 (if fine-diffs-also
3416 (ediff-clear-fine-diff-vector elt))
3417 )
3418 (symbol-value vec-var)))
3419 ;; allow them to be garbage collected
3420 (set vec-var nil))
3421
3422
3423 \f
3424 ;;; Misc
3425
3426 ;; In Emacs, this just makes overlay. In the future, when Emacs will start
3427 ;; supporting sticky overlays, this function will make a sticky overlay.
3428 ;; BEG and END are expressions telling where overlay starts.
3429 ;; If they are numbers or buffers, then all is well. Otherwise, they must
3430 ;; be expressions to be evaluated in buffer BUF in order to get the overlay
3431 ;; bounds.
3432 ;; If BUFF is not a live buffer, then return nil; otherwise, return the
3433 ;; newly created overlay.
3434 (defun ediff-make-bullet-proof-overlay (beg end buff)
3435 (if (ediff-buffer-live-p buff)
3436 (let (overl)
3437 (ediff-with-current-buffer buff
3438 (or (number-or-marker-p beg)
3439 (setq beg (eval beg)))
3440 (or (number-or-marker-p end)
3441 (setq end (eval end)))
3442 (setq overl
3443 (if ediff-xemacs-p
3444 (make-extent beg end buff)
3445 ;; advance front and rear of the overlay
3446 (make-overlay beg end buff nil 'rear-advance)))
3447
3448 ;; never detach
3449 (ediff-overlay-put
3450 overl (if ediff-emacs-p 'evaporate 'detachable) nil)
3451 ;; make vip-minibuffer-overlay open-ended
3452 ;; In emacs, it is made open ended at creation time
3453 (if ediff-xemacs-p
3454 (progn
3455 (ediff-overlay-put overl 'start-open nil)
3456 (ediff-overlay-put overl 'end-open nil)))
3457 (ediff-overlay-put overl 'ediff-diff-num 0)
3458 overl))))
3459
3460
3461 ;; Like other-buffer, but prefers visible buffers and ignores temporary or
3462 ;; other insignificant buffers (those beginning with "^[ *]").
3463 ;; Gets one arg--buffer name or a list of buffer names (it won't return
3464 ;; these buffers).
3465 ;; EXCL-BUFF-LIST is an exclusion list.
3466 (defun ediff-other-buffer (excl-buff-lst)
3467 (or (listp excl-buff-lst) (setq excl-buff-lst (list excl-buff-lst)))
3468 (let* ((all-buffers (nconc (ediff-get-selected-buffers) (buffer-list)))
3469 ;; we compute this the second time because we need to do memq on it
3470 ;; later, and nconc above will break it. Either this or use slow
3471 ;; append instead of nconc
3472 (selected-buffers (ediff-get-selected-buffers))
3473 (prefered-buffer (car all-buffers))
3474 visible-dired-buffers
3475 (excl-buff-name-list
3476 (mapcar
3477 (lambda (b) (cond ((stringp b) b)
3478 ((bufferp b) (buffer-name b))))
3479 excl-buff-lst))
3480 ;; if at least one buffer on the exclusion list is dired, then force
3481 ;; all others to be dired. This is because this means that the user
3482 ;; has already chosen a dired buffer before
3483 (use-dired-major-mode
3484 (cond ((null (ediff-buffer-live-p (car excl-buff-lst))) 'unknown)
3485 ((eq (ediff-with-current-buffer (car excl-buff-lst) major-mode)
3486 'dired-mode)
3487 'yes)
3488 (t 'no)))
3489 ;; significant-buffers must be visible and not belong
3490 ;; to the exclusion list `buff-list'
3491 ;; We also exclude temporary buffers, but keep mail and gnus buffers
3492 ;; Furthermore, we exclude dired buffers, unless they are the only
3493 ;; ones visible (and there are at least two of them).
3494 ;; Also, any visible window not on the exclusion list that is first in
3495 ;; the buffer list is chosen regardless. (This is because the user
3496 ;; clicked on it or did something to distinguish it).
3497 (significant-buffers
3498 (mapcar
3499 (lambda (x)
3500 (cond ((member (buffer-name x) excl-buff-name-list) nil)
3501 ((memq x selected-buffers) x)
3502 ((not (ediff-get-visible-buffer-window x)) nil)
3503 ((eq x prefered-buffer) x)
3504 ;; if prev selected buffer is dired, look only at
3505 ;; dired.
3506 ((eq use-dired-major-mode 'yes)
3507 (if (eq (ediff-with-current-buffer x major-mode)
3508 'dired-mode)
3509 x nil))
3510 ((eq (ediff-with-current-buffer x major-mode)
3511 'dired-mode)
3512 (if (null use-dired-major-mode)
3513 ;; don't know if we must enforce dired.
3514 ;; Remember this buffer in case
3515 ;; dired buffs are the only ones visible.
3516 (setq visible-dired-buffers
3517 (cons x visible-dired-buffers)))
3518 ;; skip, if dired is not forced
3519 nil)
3520 ((memq (ediff-with-current-buffer x major-mode)
3521 '(rmail-mode
3522 vm-mode
3523 gnus-article-mode
3524 mh-show-mode))
3525 x)
3526 ((string-match "^[ *]" (buffer-name x)) nil)
3527 ((string= "*scratch*" (buffer-name x)) nil)
3528 (t x)))
3529 all-buffers))
3530 (clean-significant-buffers (delq nil significant-buffers))
3531 less-significant-buffers)
3532
3533 (if (and (null clean-significant-buffers)
3534 (> (length visible-dired-buffers) 0))
3535 (setq clean-significant-buffers visible-dired-buffers))
3536
3537 (cond (clean-significant-buffers (car clean-significant-buffers))
3538 ;; try also buffers that are not displayed in windows
3539 ((setq less-significant-buffers
3540 (delq nil
3541 (mapcar
3542 (lambda (x)
3543 (cond ((member (buffer-name x) excl-buff-name-list)
3544 nil)
3545 ((eq use-dired-major-mode 'yes)
3546 (if (eq (ediff-with-current-buffer
3547 x major-mode)
3548 'dired-mode)
3549 x nil))
3550 ((eq (ediff-with-current-buffer x major-mode)
3551 'dired-mode)
3552 nil)
3553 ((string-match "^[ *]" (buffer-name x)) nil)
3554 ((string= "*scratch*" (buffer-name x)) nil)
3555 (t x)))
3556 all-buffers)))
3557 (car less-significant-buffers))
3558 (t "*scratch*"))
3559 ))
3560
3561
3562 ;; If current buffer is a Buffer-menu buffer, then take the selected buffers
3563 ;; and append the buffer at the cursor to the end.
3564 ;; This list would be the preferred list.
3565 (defun ediff-get-selected-buffers ()
3566 (if (eq major-mode 'Buffer-menu-mode)
3567 (let ((lis (condition-case nil
3568 (list (Buffer-menu-buffer t))
3569 (error))
3570 ))
3571 (save-excursion
3572 (goto-char (point-max))
3573 (while (search-backward "\n>" nil t)
3574 (forward-char 1)
3575 (setq lis (cons (Buffer-menu-buffer t) lis)))
3576 lis))
3577 ))
3578
3579 ;; Construct a unique buffer name.
3580 ;; The first one tried is prefixsuffix, then prefix<2>suffix,
3581 ;; prefix<3>suffix, etc.
3582 (defun ediff-unique-buffer-name (prefix suffix)
3583 (if (null (get-buffer (concat prefix suffix)))
3584 (concat prefix suffix)
3585 (let ((n 2))
3586 (while (get-buffer (format "%s<%d>%s" prefix n suffix))
3587 (setq n (1+ n)))
3588 (format "%s<%d>%s" prefix n suffix))))
3589
3590
3591 (defun ediff-submit-report ()
3592 "Submit bug report on Ediff."
3593 (interactive)
3594 (ediff-barf-if-not-control-buffer)
3595 (let ((reporter-prompt-for-summary-p t)
3596 (ctl-buf ediff-control-buffer)
3597 (ediff-device-type (ediff-device-type))
3598 varlist salutation buffer-name)
3599 (setq varlist '(ediff-diff-program ediff-diff-options
3600 ediff-patch-program ediff-patch-options
3601 ediff-shell
3602 ediff-use-faces
3603 ediff-auto-refine ediff-highlighting-style
3604 ediff-buffer-A ediff-buffer-B ediff-control-buffer
3605 ediff-forward-word-function
3606 ediff-control-frame
3607 ediff-control-frame-parameters
3608 ediff-control-frame-position-function
3609 ediff-prefer-iconified-control-frame
3610 ediff-window-setup-function
3611 ediff-split-window-function
3612 ediff-job-name
3613 ediff-word-mode
3614 buffer-name
3615 ediff-device-type
3616 ))
3617 (setq salutation "
3618 Congratulations! You may have unearthed a bug in Ediff!
3619
3620 Please make a concise and accurate summary of what happened
3621 and mail it to the address above.
3622 -----------------------------------------------------------
3623 ")
3624
3625 (ediff-skip-unsuitable-frames)
3626 (ediff-reset-mouse)
3627
3628 (switch-to-buffer ediff-msg-buffer)
3629 (erase-buffer)
3630 (delete-other-windows)
3631 (insert "
3632 Please read this first:
3633 ----------------------
3634
3635 Some ``bugs'' may actually be no bugs at all. For instance, if you are
3636 reporting that certain difference regions are not matched as you think they
3637 should, this is most likely due to the way Unix diff program decides what
3638 constitutes a difference region. Ediff is an Emacs interface to diff, and
3639 it has nothing to do with those decisions---it only takes the output from
3640 diff and presents it in a way that is better suited for human browsing and
3641 manipulation.
3642
3643 If Emacs happens to dump core, this is NOT an Ediff problem---it is
3644 an Emacs bug. Report this to Emacs maintainers.
3645
3646 Another popular topic for reports is compilation messages. Because Ediff
3647 interfaces to several other packages and runs under Emacs and XEmacs,
3648 byte-compilation may produce output like this:
3649
3650 While compiling toplevel forms in file ediff.el:
3651 ** reference to free variable pm-color-alist
3652 ........................
3653 While compiling the end of the data:
3654 ** The following functions are not known to be defined:
3655 ediff-valid-color-p, ediff-set-face,
3656 ........................
3657
3658 These are NOT errors, but inevitable warnings, which ought to be ignored.
3659
3660 Please do not report those and similar things. However, comments and
3661 suggestions are always welcome.
3662
3663 Mail anyway? (y or n) ")
3664
3665 (if (y-or-n-p "Mail anyway? ")
3666 (progn
3667 (if (ediff-buffer-live-p ctl-buf)
3668 (set-buffer ctl-buf))
3669 (setq buffer-name (buffer-name))
3670 (require 'reporter)
3671 (reporter-submit-bug-report "kifer@cs.sunysb.edu"
3672 (ediff-version)
3673 varlist
3674 nil
3675 'delete-other-windows
3676 salutation))
3677 (bury-buffer)
3678 (beep 1)(message "Bug report aborted")
3679 (if (ediff-buffer-live-p ctl-buf)
3680 (ediff-with-current-buffer ctl-buf
3681 (ediff-recenter 'no-rehighlight))))
3682 ))
3683
3684
3685 (defun ediff-deactivate-mark ()
3686 (if ediff-xemacs-p
3687 (zmacs-deactivate-region)
3688 (deactivate-mark)))
3689 (defun ediff-activate-mark ()
3690 (if ediff-emacs-p
3691 (setq mark-active t)
3692 (zmacs-activate-region)))
3693
3694 (cond ((fboundp 'nuke-selective-display)
3695 ;; XEmacs 19.12 has nuke-selective-display
3696 (fset 'ediff-nuke-selective-display 'nuke-selective-display))
3697 (t
3698 (defun ediff-nuke-selective-display ()
3699 (save-excursion
3700 (save-restriction
3701 (widen)
3702 (goto-char (point-min))
3703 (let ((mod-p (buffer-modified-p))
3704 buffer-read-only end)
3705 (and (eq t selective-display)
3706 (while (search-forward "\^M" nil t)
3707 (end-of-line)
3708 (setq end (point))
3709 (beginning-of-line)
3710 (while (search-forward "\^M" end t)
3711 (delete-char -1)
3712 (insert "\^J"))))
3713 (set-buffer-modified-p mod-p)
3714 (setq selective-display nil)))))
3715 ))
3716
3717
3718 ;; The next two are modified versions from emerge.el.
3719 ;; VARS must be a list of symbols
3720 ;; ediff-save-variables returns an association list: ((var . val) ...)
3721 (defsubst ediff-save-variables (vars)
3722 (mapcar (lambda (v) (cons v (symbol-value v)))
3723 vars))
3724 ;; VARS is a list of variable symbols.
3725 (defun ediff-restore-variables (vars assoc-list)
3726 (while vars
3727 (set (car vars) (cdr (assoc (car vars) assoc-list)))
3728 (setq vars (cdr vars))))
3729
3730 (defun ediff-change-saved-variable (var value buf-type)
3731 (let* ((assoc-list
3732 (symbol-value (ediff-get-symbol-from-alist
3733 buf-type
3734 ediff-buffer-values-orig-alist)))
3735 (assoc-elt (assoc var assoc-list)))
3736 (if assoc-elt
3737 (setcdr assoc-elt value))))
3738
3739
3740 ;; must execute in control buf
3741 (defun ediff-save-protected-variables ()
3742 (setq ediff-buffer-values-orig-A
3743 (ediff-with-current-buffer ediff-buffer-A
3744 (ediff-save-variables ediff-protected-variables)))
3745 (setq ediff-buffer-values-orig-B
3746 (ediff-with-current-buffer ediff-buffer-B
3747 (ediff-save-variables ediff-protected-variables)))
3748 (if ediff-3way-comparison-job
3749 (setq ediff-buffer-values-orig-C
3750 (ediff-with-current-buffer ediff-buffer-C
3751 (ediff-save-variables ediff-protected-variables))))
3752 (if (ediff-buffer-live-p ediff-ancestor-buffer)
3753 (setq ediff-buffer-values-orig-Ancestor
3754 (ediff-with-current-buffer ediff-ancestor-buffer
3755 (ediff-save-variables ediff-protected-variables)))))
3756
3757 ;; must execute in control buf
3758 (defun ediff-restore-protected-variables ()
3759 (let ((values-A ediff-buffer-values-orig-A)
3760 (values-B ediff-buffer-values-orig-B)
3761 (values-C ediff-buffer-values-orig-C)
3762 (values-Ancestor ediff-buffer-values-orig-Ancestor))
3763 (ediff-with-current-buffer ediff-buffer-A
3764 (ediff-restore-variables ediff-protected-variables values-A))
3765 (ediff-with-current-buffer ediff-buffer-B
3766 (ediff-restore-variables ediff-protected-variables values-B))
3767 (if ediff-3way-comparison-job
3768 (ediff-with-current-buffer ediff-buffer-C
3769 (ediff-restore-variables ediff-protected-variables values-C)))
3770 (if (ediff-buffer-live-p ediff-ancestor-buffer)
3771 (ediff-with-current-buffer ediff-ancestor-buffer
3772 (ediff-restore-variables ediff-protected-variables values-Ancestor)))
3773 ))
3774
3775 ;; save BUFFER in FILE. used in hooks.
3776 (defun ediff-save-buffer-in-file (buffer file)
3777 (ediff-with-current-buffer buffer
3778 (write-file file)))
3779
3780
3781 ;;; Debug
3782
3783 (ediff-defvar-local ediff-command-begin-time '(0 0 0) "")
3784
3785 ;; calculate time used by command
3786 (defun ediff-calc-command-time ()
3787 (let ((end (current-time))
3788 micro sec)
3789 (setq micro
3790 (if (>= (nth 2 end) (nth 2 ediff-command-begin-time))
3791 (- (nth 2 end) (nth 2 ediff-command-begin-time))
3792 (+ (nth 2 end) (- 1000000 (nth 2 ediff-command-begin-time)))))
3793 (setq sec (- (nth 1 end) (nth 1 ediff-command-begin-time)))
3794 (or (equal ediff-command-begin-time '(0 0 0))
3795 (message "Elapsed time: %d second(s) + %d microsecond(s)" sec micro))))
3796
3797 (defsubst ediff-save-time ()
3798 (setq ediff-command-begin-time (current-time)))
3799
3800 (defun ediff-profile ()
3801 "Toggle profiling Ediff commands."
3802 (interactive)
3803 (ediff-barf-if-not-control-buffer)
3804 (make-local-hook 'post-command-hook)
3805 (let ((pre-hook 'pre-command-hook)
3806 (post-hook 'post-command-hook))
3807 (if (not (equal ediff-command-begin-time '(0 0 0)))
3808 (progn (remove-hook pre-hook 'ediff-save-time)
3809 (remove-hook post-hook 'ediff-calc-command-time)
3810 (setq ediff-command-begin-time '(0 0 0))
3811 (message "Ediff profiling disabled"))
3812 (add-hook pre-hook 'ediff-save-time t t)
3813 (add-hook post-hook 'ediff-calc-command-time nil t)
3814 (message "Ediff profiling enabled"))))
3815
3816 (defun ediff-print-diff-vector (diff-vector-var)
3817 (princ (format "\n*** %S ***\n" diff-vector-var))
3818 (mapcar (lambda (overl-vec)
3819 (princ
3820 (format
3821 "Diff %d: \tOverlay: %S
3822 \t\tFine diffs: %s
3823 \t\tNo-fine-diff-flag: %S
3824 \t\tState-of-diff:\t %S
3825 \t\tState-of-merge:\t %S
3826 "
3827 (1+ (ediff-overlay-get (aref overl-vec 0) 'ediff-diff-num))
3828 (aref overl-vec 0)
3829 ;; fine-diff-vector
3830 (if (= (length (aref overl-vec 1)) 0)
3831 "none\n"
3832 (mapconcat 'prin1-to-string
3833 (aref overl-vec 1) "\n\t\t\t "))
3834 (aref overl-vec 2) ; no fine diff flag
3835 (aref overl-vec 3) ; state-of-diff
3836 (aref overl-vec 4) ; state-of-merge
3837 )))
3838 (eval diff-vector-var)))
3839
3840
3841
3842 (defun ediff-debug-info ()
3843 (interactive)
3844 (ediff-barf-if-not-control-buffer)
3845 (with-output-to-temp-buffer ediff-debug-buffer
3846 (ediff-with-current-buffer standard-output
3847 (fundamental-mode))
3848 (princ (format "\nCtl buffer: %S\n" ediff-control-buffer))
3849 (ediff-print-diff-vector (intern "ediff-difference-vector-A"))
3850 (ediff-print-diff-vector (intern "ediff-difference-vector-B"))
3851 (ediff-print-diff-vector (intern "ediff-difference-vector-C"))
3852 (ediff-print-diff-vector (intern "ediff-difference-vector-Ancestor"))
3853 ))
3854
3855
3856 ;;; General utilities
3857
3858 ;; this uses comparison-func to decide who is a member
3859 (defun ediff-member (elt lis comparison-func)
3860 (while (and lis (not (funcall comparison-func (car lis) elt)))
3861 (setq lis (cdr lis)))
3862 lis)
3863
3864 ;; this uses comparison-func to decide who is a member, and this determines how
3865 ;; intersection looks like
3866 (defun ediff-intersection (lis1 lis2 comparison-func)
3867 (let ((result (list 'a)))
3868 (while lis1
3869 (if (ediff-member (car lis1) lis2 comparison-func)
3870 (nconc result (list (car lis1))))
3871 (setq lis1 (cdr lis1)))
3872 (cdr result)))
3873
3874
3875 ;; eliminates duplicates using comparison-func
3876 (defun ediff-union (lis1 lis2 comparison-func)
3877 (let ((result (list 'a)))
3878 (while lis1
3879 (or (ediff-member (car lis1) (cdr result) comparison-func)
3880 (nconc result (list (car lis1))))
3881 (setq lis1 (cdr lis1)))
3882 (while lis2
3883 (or (ediff-member (car lis2) (cdr result) comparison-func)
3884 (nconc result (list (car lis2))))
3885 (setq lis2 (cdr lis2)))
3886 (cdr result)))
3887
3888 ;; eliminates duplicates using comparison-func
3889 (defun ediff-set-difference (lis1 lis2 comparison-func)
3890 (let ((result (list 'a)))
3891 (while lis1
3892 (or (ediff-member (car lis1) (cdr result) comparison-func)
3893 (ediff-member (car lis1) lis2 comparison-func)
3894 (nconc result (list (car lis1))))
3895 (setq lis1 (cdr lis1)))
3896 (cdr result)))
3897
3898 (if (fboundp 'copy-sequence)
3899 (defalias 'ediff-copy-list 'copy-sequence)
3900 (defun ediff-copy-list (list)
3901 (if (consp list)
3902 ;;;(let ((res nil))
3903 ;;; (while (consp list) (push (pop list) res))
3904 ;;; (prog1 (nreverse res) (setcdr res list)))
3905 (let (res elt)
3906 (while (consp list)
3907 (setq elt (car list)
3908 res (cons elt res)
3909 list (cdr list)))
3910 (nreverse res))
3911 (car list))))
3912
3913
3914 ;; don't report error if version control package wasn't found
3915 ;;(ediff-load-version-control 'silent)
3916
3917 (run-hooks 'ediff-load-hook)
3918
3919
3920 ;;; Local Variables:
3921 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
3922 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
3923 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
3924 ;;; End:
3925
3926 ;;; ediff-util.el ends here