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