(dabbrev-ignored-buffer-regexps): Renamed from
[emacs.git] / lisp / ediff-init.el
blobbfa77a71fbab95efc97ce32b644dfe1c425dd14c
1 ;;; ediff-init.el --- Macros, variables, and defsubsts used by Ediff
3 ;; Copyright (C) 1994, 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
24 ;;; Code:
26 ;; Start compiler pacifier
27 (defvar ediff-metajob-name)
28 (defvar ediff-meta-buffer)
29 (defvar pm-color-alist)
30 (defvar ediff-grab-mouse)
31 (defvar ediff-mouse-pixel-position)
32 (defvar ediff-mouse-pixel-threshold)
33 (defvar ediff-whitespace)
34 (defvar ediff-multiframe)
35 (defvar ediff-use-toolbar-p)
37 (and noninteractive
38 (eval-when-compile
39 (load "ange-ftp" 'noerror)))
40 ;; end pacifier
42 ;; Is it XEmacs?
43 (defconst ediff-xemacs-p (string-match "XEmacs" emacs-version))
44 ;; Is it Emacs?
45 (defconst ediff-emacs-p (not ediff-xemacs-p))
47 (defvar ediff-force-faces nil
48 "If t, Ediff will think that it is running on a display that supports faces.
49 This is provided as a temporary relief for users of face-capable displays
50 that Ediff doesn't know about.")
52 ;; Are we running as a window application or on a TTY?
53 (defsubst ediff-device-type ()
54 (if ediff-emacs-p
55 window-system
56 (device-type (selected-device))))
58 ;; in XEmacs: device-type is tty on tty and stream in batch.
59 (defun ediff-window-display-p ()
60 (and (ediff-device-type) (not (memq (ediff-device-type) '(tty pc stream)))))
62 ;; test if supports faces
63 (defun ediff-has-face-support-p ()
64 (cond ((ediff-window-display-p))
65 (ediff-force-faces)
66 ((ediff-color-display-p))
67 (ediff-emacs-p (memq (ediff-device-type) '(pc)))
68 (ediff-xemacs-p (memq (ediff-device-type) '(tty pc)))))
70 (defun ediff-has-toolbar-support-p ()
71 (and ediff-xemacs-p
72 (featurep 'toolbar)
73 (console-on-window-system-p)))
75 (defun ediff-use-toolbar-p ()
76 (and (ediff-has-toolbar-support-p) ;Can it do it ?
77 (boundp 'ediff-use-toolbar-p)
78 ediff-use-toolbar-p)) ;Does the user want it ?
80 ;; Defines SYMBOL as an advertised local variable.
81 ;; Performs a defvar, then executes `make-variable-buffer-local' on
82 ;; the variable. Also sets the `permanent-local' property,
83 ;; so that `kill-all-local-variables' (called by major-mode setting
84 ;; commands) won't destroy Ediff control variables.
86 ;; Plagiarised from `emerge-defvar-local' for XEmacs.
87 (defmacro ediff-defvar-local (var value doc)
88 `(progn
89 (defvar ,var ,value ,doc)
90 (make-variable-buffer-local ',var)
91 (put ',var 'permanent-local t)))
95 ;; Variables that control each Ediff session---local to the control buffer.
97 ;; Mode variables
98 ;; The buffer in which the A variant is stored.
99 (ediff-defvar-local ediff-buffer-A nil "")
100 ;; The buffer in which the B variant is stored.
101 (ediff-defvar-local ediff-buffer-B nil "")
102 ;; The buffer in which the C variant is stored or where the merge buffer lives.
103 (ediff-defvar-local ediff-buffer-C nil "")
104 ;; Ancestor buffer
105 (ediff-defvar-local ediff-ancestor-buffer nil "")
106 ;; The Ediff control buffer
107 (ediff-defvar-local ediff-control-buffer nil "")
110 ;; Association between buff-type and ediff-buffer-*
111 (defconst ediff-buffer-alist
112 '((?A . ediff-buffer-A)
113 (?B . ediff-buffer-B)
114 (?C . ediff-buffer-C)))
116 ;;; Macros
117 (defmacro ediff-odd-p (arg)
118 `(eq (logand ,arg 1) 1))
120 (defmacro ediff-buffer-live-p (buf)
121 `(and ,buf (get-buffer ,buf) (buffer-name (get-buffer ,buf))))
123 (defmacro ediff-get-buffer (arg)
124 `(cond ((eq ,arg 'A) ediff-buffer-A)
125 ((eq ,arg 'B) ediff-buffer-B)
126 ((eq ,arg 'C) ediff-buffer-C)
127 ((eq ,arg 'Ancestor) ediff-ancestor-buffer)
130 (defmacro ediff-get-value-according-to-buffer-type (buf-type list)
131 `(cond ((eq ,buf-type 'A) (nth 0 ,list))
132 ((eq ,buf-type 'B) (nth 1 ,list))
133 ((eq ,buf-type 'C) (nth 2 ,list))
136 (defmacro ediff-char-to-buftype (arg)
137 `(cond ((memq ,arg '(?a ?A)) 'A)
138 ((memq ,arg '(?b ?B)) 'B)
139 ((memq ,arg '(?c ?C)) 'C)
143 ;; A-list is supposed to be of the form (A . symb) (B . symb)...)
144 ;; where the first part of any association is a buffer type and the second is
145 ;; an appropriate symbol. Given buffer-type, this function returns the
146 ;; symbol. This is used to avoid using `intern'
147 (defsubst ediff-get-symbol-from-alist (buf-type alist)
148 (cdr (assoc buf-type alist)))
150 (defconst ediff-difference-vector-alist
151 '((A . ediff-difference-vector-A)
152 (B . ediff-difference-vector-B)
153 (C . ediff-difference-vector-C)
154 (Ancestor . ediff-difference-vector-Ancestor)))
156 (defmacro ediff-get-difference (n buf-type)
157 `(aref
158 (symbol-value
159 (ediff-get-symbol-from-alist
160 ,buf-type ediff-difference-vector-alist))
161 ,n))
163 ;; Tell if it has been previously determined that the region has
164 ;; no diffs other than the white space and newlines
165 ;; The argument, N, is the diff region number used by Ediff to index the
166 ;; diff vector. It is 1 less than the number seen by the user.
167 ;; Returns:
168 ;; t if the diffs are whitespace in all buffers
169 ;; 'A (in 3-buf comparison only) if there are only whitespace
170 ;; diffs in bufs B and C
171 ;; 'B (in 3-buf comparison only) if there are only whitespace
172 ;; diffs in bufs A and C
173 ;; 'C (in 3-buf comparison only) if there are only whitespace
174 ;; diffs in bufs A and B
176 ;; A Difference Vector has the form:
177 ;; [diff diff diff ...]
178 ;; where each diff has the form:
179 ;; [overlay fine-diff-vector no-fine-diffs-flag state-of-difference]
180 ;; fine-diff-vector is a vector [fine-diff fine-diff fine-diff ...]
181 ;; no-fine-diffs-flag says if there are fine differences.
182 ;; state-of-difference is A, B, C, or nil, indicating which buffer is
183 ;; different from the other two (used only in 3-way jobs).
184 (defmacro ediff-no-fine-diffs-p (n)
185 `(aref (ediff-get-difference ,n 'A) 2))
187 (defmacro ediff-get-diff-overlay-from-diff-record (diff-rec)
188 `(aref ,diff-rec 0))
190 (defmacro ediff-get-diff-overlay (n buf-type)
191 `(ediff-get-diff-overlay-from-diff-record
192 (ediff-get-difference ,n ,buf-type)))
194 (defmacro ediff-get-fine-diff-vector-from-diff-record (diff-rec)
195 `(aref ,diff-rec 1))
197 (defmacro ediff-set-fine-diff-vector (n buf-type fine-vec)
198 `(aset (ediff-get-difference ,n ,buf-type) 1 ,fine-vec))
200 (defmacro ediff-get-state-of-diff (n buf-type)
201 `(if (ediff-buffer-live-p ediff-buffer-C)
202 (aref (ediff-get-difference ,n ,buf-type) 3)))
203 (defmacro ediff-set-state-of-diff (n buf-type val)
204 `(aset (ediff-get-difference ,n ,buf-type) 3 ,val))
206 (defmacro ediff-get-state-of-merge (n)
207 `(if ediff-state-of-merge
208 (aref (aref ediff-state-of-merge ,n) 0)))
209 (defmacro ediff-set-state-of-merge (n val)
210 `(if ediff-state-of-merge
211 (aset (aref ediff-state-of-merge ,n) 0 ,val)))
213 (defmacro ediff-get-state-of-ancestor (n)
214 `(if ediff-state-of-merge
215 (aref (aref ediff-state-of-merge ,n) 1)))
217 ;; if flag is t, puts a mark on diff region saying that
218 ;; the differences are in white space only. If flag is nil,
219 ;; the region is marked as essential (i.e., differences are
220 ;; not just in the white space and newlines.)
221 (defmacro ediff-mark-diff-as-space-only (n flag)
222 `(aset (ediff-get-difference ,n 'A) 2 ,flag))
224 (defmacro ediff-get-fine-diff-vector (n buf-type)
225 `(ediff-get-fine-diff-vector-from-diff-record
226 (ediff-get-difference ,n ,buf-type)))
228 ;; Macro to switch to BUFFER, evaluate BODY, returns to original buffer.
229 ;; Doesn't save the point and mark.
230 ;; This is `with-current-buffer' with the added test for live buffers."
231 (defmacro ediff-with-current-buffer (buffer &rest body)
232 `(if (ediff-buffer-live-p ,buffer)
233 (save-current-buffer
234 (set-buffer ,buffer)
235 ,@body)
236 (or (eq this-command 'ediff-quit)
237 (error ediff-KILLED-VITAL-BUFFER))
241 (defsubst ediff-multiframe-setup-p ()
242 (and (ediff-window-display-p) ediff-multiframe))
244 (defmacro ediff-narrow-control-frame-p ()
245 `(and (ediff-multiframe-setup-p)
246 (equal ediff-help-message ediff-brief-message-string)))
248 (defmacro ediff-3way-comparison-job ()
249 `(memq
250 ediff-job-name
251 '(ediff-files3 ediff-buffers3)))
252 (ediff-defvar-local ediff-3way-comparison-job nil "")
254 (defmacro ediff-merge-job ()
255 `(memq
256 ediff-job-name
257 '(ediff-merge-files
258 ediff-merge-buffers
259 ediff-merge-files-with-ancestor
260 ediff-merge-buffers-with-ancestor
261 ediff-merge-revisions
262 ediff-merge-revisions-with-ancestor)))
263 (ediff-defvar-local ediff-merge-job nil "")
265 (defmacro ediff-merge-with-ancestor-job ()
266 `(memq
267 ediff-job-name
268 '(ediff-merge-files-with-ancestor
269 ediff-merge-buffers-with-ancestor
270 ediff-merge-revisions-with-ancestor)))
271 (ediff-defvar-local ediff-merge-with-ancestor-job nil "")
273 (defmacro ediff-3way-job ()
274 `(or ediff-3way-comparison-job ediff-merge-job))
275 (ediff-defvar-local ediff-3way-job nil "")
277 ;; A diff3 job is like a 3way job, but ediff-merge doesn't require the use
278 ;; of diff3.
279 (defmacro ediff-diff3-job ()
280 `(or ediff-3way-comparison-job
281 ediff-merge-with-ancestor-job))
282 (ediff-defvar-local ediff-diff3-job nil "")
284 (defmacro ediff-windows-job ()
285 `(memq ediff-job-name '(ediff-windows-wordwise ediff-windows-linewise)))
286 (ediff-defvar-local ediff-windows-job nil "")
288 (defmacro ediff-word-mode-job ()
289 `(memq ediff-job-name '(ediff-windows-wordwise ediff-regions-wordwise)))
290 (ediff-defvar-local ediff-word-mode-job nil "")
292 (defmacro ediff-narrow-job ()
293 `(memq ediff-job-name '(ediff-windows-wordwise
294 ediff-regions-wordwise
295 ediff-windows-linewise
296 ediff-regions-linewise)))
297 (ediff-defvar-local ediff-narrow-job nil "")
299 ;; Note: ediff-merge-directory-revisions-with-ancestor is not treated as an
300 ;; ancestor metajob, since it behaves differently.
301 (defsubst ediff-ancestor-metajob (&optional metajob)
302 (memq (or metajob ediff-metajob-name)
303 '(ediff-merge-directories-with-ancestor
304 ediff-merge-filegroups-with-ancestor)))
305 (defsubst ediff-revision-metajob (&optional metajob)
306 (memq (or metajob ediff-metajob-name)
307 '(ediff-directory-revisions
308 ediff-merge-directory-revisions
309 ediff-merge-directory-revisions-with-ancestor)))
310 (defsubst ediff-patch-metajob (&optional metajob)
311 (memq (or metajob ediff-metajob-name)
312 '(ediff-multifile-patch)))
313 ;; metajob involving only one group of files, such as multipatch or directory
314 ;; revision
315 (defsubst ediff-one-filegroup-metajob (&optional metajob)
316 (or (ediff-revision-metajob metajob)
317 (ediff-patch-metajob metajob)
318 ;; add more here
320 (defsubst ediff-collect-diffs-metajob (&optional metajob)
321 (memq (or metajob ediff-metajob-name)
322 '(ediff-directories
323 ediff-directory-revisions
324 ediff-merge-directories
325 ediff-merge-directories-with-ancestor
326 ediff-merge-directory-revisions
327 ediff-merge-directory-revisions-with-ancestor
328 ;; add more here
330 (defsubst ediff-merge-metajob (&optional metajob)
331 (memq (or metajob ediff-metajob-name)
332 '(ediff-merge-directories
333 ediff-merge-directories-with-ancestor
334 ediff-merge-directory-revisions
335 ediff-merge-directory-revisions-with-ancestor
336 ediff-merge-filegroups-with-ancestor
337 ;; add more here
340 (defsubst ediff-metajob3 (&optional metajob)
341 (memq (or metajob ediff-metajob-name)
342 '(ediff-merge-directories-with-ancestor
343 ediff-merge-filegroups-with-ancestor
344 ediff-directories3
345 ediff-filegroups3)))
346 (defsubst ediff-comparison-metajob3 (&optional metajob)
347 (memq (or metajob ediff-metajob-name)
348 '(ediff-directories3 ediff-filegroups3)))
350 ;; with no argument, checks if we are in ediff-control-buffer
351 ;; with argument, checks if we are in ediff-meta-buffer
352 (defun ediff-in-control-buffer-p (&optional meta-buf-p)
353 (and (boundp 'ediff-control-buffer)
354 (eq (if meta-buf-p ediff-meta-buffer ediff-control-buffer)
355 (current-buffer))))
357 (defsubst ediff-barf-if-not-control-buffer (&optional meta-buf-p)
358 (or (ediff-in-control-buffer-p meta-buf-p)
359 (error "%S: This command runs in Ediff Control Buffer only!"
360 this-command)))
362 (defgroup ediff-highlighting nil
363 "Hilighting of difference regions in Ediff"
364 :prefix "ediff-"
365 :group 'ediff)
367 (defgroup ediff-merge nil
368 "Merging utilities"
369 :prefix "ediff-"
370 :group 'ediff)
372 (defgroup ediff-hook nil
373 "Hooks run by Ediff"
374 :prefix "ediff-"
375 :group 'ediff)
377 ;; Hook variables
379 (defcustom ediff-before-setup-hook nil
380 "*Hooks to run before Ediff begins to set up windows and buffers.
381 This hook can be used to save the previous window config, which can be restored
382 on ediff-quit or ediff-suspend."
383 :type 'hook
384 :version "21.1"
385 :group 'ediff-hook)
386 (defcustom ediff-before-setup-windows-hook nil
387 "*Hooks to run before Ediff sets its window configuration.
388 This hook is run every time when Ediff arranges its windows.
389 This happens each time Ediff detects that the windows were messed up by the
390 user."
391 :type 'hook
392 :group 'ediff-hook)
393 (defcustom ediff-after-setup-windows-hook nil
394 "*Hooks to run after Ediff sets its window configuration.
395 This can be used to set up control window or icon in a desired place."
396 :type 'hook
397 :group 'ediff-hook)
398 (defcustom ediff-before-setup-control-frame-hook nil
399 "*Hooks run before setting up the frame to display Ediff Control Panel.
400 Can be used to change control frame parameters to position it where it
401 is desirable."
402 :type 'hook
403 :group 'ediff-hook)
404 (defcustom ediff-after-setup-control-frame-hook nil
405 "*Hooks run after setting up the frame to display Ediff Control Panel.
406 Can be used to move the frame where it is desired."
407 :type 'hook
408 :group 'ediff-hook)
409 (defcustom ediff-startup-hook nil
410 "*Hooks to run in the control buffer after Ediff has been set up and is ready for the job."
411 :type 'hook
412 :group 'ediff-hook)
413 (defcustom ediff-select-hook nil
414 "*Hooks to run after a difference has been selected."
415 :type 'hook
416 :group 'ediff-hook)
417 (defcustom ediff-unselect-hook nil
418 "*Hooks to run after a difference has been unselected."
419 :type 'hook
420 :group 'ediff-hook)
421 (defcustom ediff-prepare-buffer-hook nil
422 "*Hooks run after buffers A, B, and C are set up.
423 For each buffer, the hooks are run with that buffer made current."
424 :type 'hook
425 :group 'ediff-hook)
426 (defcustom ediff-load-hook nil
427 "*Hook run after Ediff is loaded. Can be used to change defaults."
428 :type 'hook
429 :group 'ediff-hook)
431 (defcustom ediff-mode-hook nil
432 "*Hook run just after ediff-mode is set up in the control buffer.
433 This is done before any windows or frames are created. One can use it to
434 set local variables that determine how the display looks like."
435 :type 'hook
436 :group 'ediff-hook)
437 (defcustom ediff-keymap-setup-hook nil
438 "*Hook run just after the default bindings in Ediff keymap are set up."
439 :type 'hook
440 :group 'ediff-hook)
442 (defcustom ediff-display-help-hook nil
443 "*Hooks run after preparing the help message."
444 :type 'hook
445 :group 'ediff-hook)
447 (defcustom ediff-suspend-hook nil
448 "*Hooks to run in the Ediff control buffer when Ediff is suspended."
449 :type 'hook
450 :group 'ediff-hook)
451 (defcustom ediff-quit-hook nil
452 "*Hooks to run in the Ediff control buffer after finishing Ediff."
453 :type 'hook
454 :group 'ediff-hook)
455 (defcustom ediff-cleanup-hook nil
456 "*Hooks to run on exiting Ediff but before killing the control and variant buffers."
457 :type 'hook
458 :group 'ediff-hook)
460 ;; Error messages
461 (defconst ediff-KILLED-VITAL-BUFFER
462 "You have killed a vital Ediff buffer---you must leave Ediff now!")
463 (defconst ediff-NO-DIFFERENCES
464 "Sorry, comparison of identical variants is not what I am made for...")
465 (defconst ediff-BAD-DIFF-NUMBER
466 ;; %S stands for this-command, %d - diff number, %d - max diff
467 "%S: Bad diff region number, %d. Valid numbers are 1 to %d")
468 (defconst ediff-BAD-INFO (format "
469 *** The Info file for Ediff, a part of the standard distribution
470 *** of %sEmacs, does not seem to be properly installed.
472 *** Please contact your system administrator. "
473 (if ediff-xemacs-p "X" "")))
475 ;; Selective browsing
477 (ediff-defvar-local ediff-skip-diff-region-function 'ediff-show-all-diffs
478 "Function that determines the next/previous diff region to show.
479 Should return t for regions to be ignored and nil otherwise.
480 This function gets a region number as an argument. The region number
481 is the one used internally by Ediff. It is 1 less than the number seen
482 by the user.")
484 (ediff-defvar-local ediff-hide-regexp-matches-function
485 'ediff-hide-regexp-matches
486 "Function to use in determining which regions to hide.
487 See the documentation string of `ediff-hide-regexp-matches' for details.")
488 (ediff-defvar-local ediff-focus-on-regexp-matches-function
489 'ediff-focus-on-regexp-matches
490 "Function to use in determining which regions to focus on.
491 See the documentation string of `ediff-focus-on-regexp-matches' for details.")
493 ;; Regexp that determines buf A regions to focus on when skipping to diff
494 (ediff-defvar-local ediff-regexp-focus-A "" "")
495 ;; Regexp that determines buf B regions to focus on when skipping to diff
496 (ediff-defvar-local ediff-regexp-focus-B "" "")
497 ;; Regexp that determines buf C regions to focus on when skipping to diff
498 (ediff-defvar-local ediff-regexp-focus-C "" "")
499 ;; connective that determines whether to focus regions that match both or
500 ;; one of the regexps
501 (ediff-defvar-local ediff-focus-regexp-connective 'and "")
503 ;; Regexp that determines buf A regions to ignore when skipping to diff
504 (ediff-defvar-local ediff-regexp-hide-A "" "")
505 ;; Regexp that determines buf B regions to ignore when skipping to diff
506 (ediff-defvar-local ediff-regexp-hide-B "" "")
507 ;; Regexp that determines buf C regions to ignore when skipping to diff
508 (ediff-defvar-local ediff-regexp-hide-C "" "")
509 ;; connective that determines whether to hide regions that match both or
510 ;; one of the regexps
511 (ediff-defvar-local ediff-hide-regexp-connective 'and "")
514 ;;; Copying difference regions between buffers.
516 ;; A list of killed diffs.
517 ;; A diff is saved here if it is replaced by a diff
518 ;; from another buffer. This alist has the form:
519 ;; \((num (buff-object . diff) (buff-object . diff) (buff-object . diff)) ...),
520 ;; where some buffer-objects may be missing.
521 (ediff-defvar-local ediff-killed-diffs-alist nil "")
524 ;; Highlighting
525 (defcustom ediff-before-flag-bol (if ediff-xemacs-p (make-glyph "->>") "->>")
526 "*Flag placed before a highlighted block of differences, if block starts at beginning of a line."
527 :type 'string
528 :tag "Region before-flag at beginning of line"
529 :group 'ediff)
531 (defcustom ediff-after-flag-eol (if ediff-xemacs-p (make-glyph "<<-") "<<-")
532 "*Flag placed after a highlighted block of differences, if block ends at end of a line."
533 :type 'string
534 :tag "Region after-flag at end of line"
535 :group 'ediff)
537 (defcustom ediff-before-flag-mol (if ediff-xemacs-p (make-glyph "->>") "->>")
538 "*Flag placed before a highlighted block of differences, if block starts in mid-line."
539 :type 'string
540 :tag "Region before-flag in the middle of line"
541 :group 'ediff)
542 (defcustom ediff-after-flag-mol (if ediff-xemacs-p (make-glyph "<<-") "<<-")
543 "*Flag placed after a highlighted block of differences, if block ends in mid-line."
544 :type 'string
545 :tag "Region after-flag in the middle of line"
546 :group 'ediff)
549 (ediff-defvar-local ediff-use-faces t "")
550 (defcustom ediff-use-faces t
551 "If t, differences are highlighted using faces, if device supports faces.
552 If nil, differences are highlighted using ASCII flags, ediff-before-flag
553 and ediff-after-flag. On a non-window system, differences are always
554 highlighted using ASCII flags."
555 :type 'boolean
556 :group 'ediff-highlighting)
558 ;; this indicates that diff regions are word-size, so fine diffs are
559 ;; permanently nixed; used in ediff-windows-wordwise and ediff-regions-wordwise
560 (ediff-defvar-local ediff-word-mode nil "")
561 ;; Name of the job (ediff-files, ediff-windows, etc.)
562 (ediff-defvar-local ediff-job-name nil "")
564 ;; Narrowing and ediff-region/windows support
565 ;; This is a list (overlay-A overlay-B overlay-C)
566 ;; If set, Ediff compares only those parts of buffers A/B/C that lie within
567 ;; the bounds of these overlays.
568 (ediff-defvar-local ediff-narrow-bounds nil "")
570 ;; List (overlay-A overlay-B overlay-C), where each overlay spans the
571 ;; entire corresponding buffer.
572 (ediff-defvar-local ediff-wide-bounds nil "")
574 ;; Current visibility boundaries in buffers A, B, and C.
575 ;; This is also a list of overlays. When the user toggles narrow/widen,
576 ;; this list changes from ediff-wide-bounds to ediff-narrow-bounds.
577 ;; and back.
578 (ediff-defvar-local ediff-visible-bounds nil "")
580 (ediff-defvar-local ediff-start-narrowed t
581 "Non-nil means start narrowed, if doing ediff-windows-* or ediff-regions-*")
582 (ediff-defvar-local ediff-quit-widened t
583 "*Non-nil means: when finished, Ediff widens buffers A/B.
584 Actually, Ediff restores the scope of visibility that existed at startup.")
586 (defcustom ediff-keep-variants t
587 "*Nil means that non-modified variant buffers should be removed at the end of the session after some interrogation.
588 Supplying a prefix argument to the quit command `q' temporarily reverses the
589 meaning of this variable."
590 :type 'boolean
591 :group 'ediff)
593 (ediff-defvar-local ediff-highlight-all-diffs t "")
594 (defcustom ediff-highlight-all-diffs t
595 "If nil, only the selected differences are highlighted.
596 Otherwise, all difference regions are highlighted, but the selected region is
597 shown in brighter colors."
598 :type 'boolean
599 :group 'ediff-highlighting)
601 ;; A var local to each control panel buffer. Indicates highlighting style
602 ;; in effect for this buffer: `face', `ascii', nil -- temporarily
603 ;; unhighlighted, `off' -- turned off \(on a dumb terminal only\).
604 (ediff-defvar-local ediff-highlighting-style nil "")
607 ;; The suffix of the control buffer name.
608 (ediff-defvar-local ediff-control-buffer-suffix nil "")
609 ;; Same as ediff-control-buffer-suffix, but without <,>.
610 ;; It's a number rather than string.
611 (ediff-defvar-local ediff-control-buffer-number nil "")
614 ;; The original values of ediff-protected-variables for buffer A
615 (ediff-defvar-local ediff-buffer-values-orig-A nil "")
616 ;; The original values of ediff-protected-variables for buffer B
617 (ediff-defvar-local ediff-buffer-values-orig-B nil "")
618 ;; The original values of ediff-protected-variables for buffer C
619 (ediff-defvar-local ediff-buffer-values-orig-C nil "")
620 ;; The original values of ediff-protected-variables for buffer Ancestor
621 (ediff-defvar-local ediff-buffer-values-orig-Ancestor nil "")
623 ;; association between buff-type and ediff-buffer-values-orig-*
624 (defconst ediff-buffer-values-orig-alist
625 '((A . ediff-buffer-values-orig-A)
626 (B . ediff-buffer-values-orig-B)
627 (C . ediff-buffer-values-orig-C)
628 (Ancestor . ediff-buffer-values-orig-Ancestor)))
630 ;; Buffer-local variables to be saved then restored during Ediff sessions
631 (defconst ediff-protected-variables '(
632 ;;buffer-read-only
633 mode-line-format))
635 ;; Vector of differences between the variants. Each difference is
636 ;; represented by a vector of two overlays plus a vector of fine diffs,
637 ;; plus a no-fine-diffs flag. The first overlay spans the
638 ;; difference region in the A buffer and the second overlays the diff in
639 ;; the B buffer. If a difference section is empty, the corresponding
640 ;; overlay's endpoints coincide.
642 ;; The precise form of a Difference Vector for one buffer is:
643 ;; [diff diff diff ...]
644 ;; where each diff has the form:
645 ;; [diff-overlay fine-diff-vector no-fine-diffs-flag state-of-diff]
646 ;; fine-diff-vector is a vector [fine-diff-overlay fine-diff-overlay ...]
647 ;; no-fine-diffs-flag says if there are fine differences.
648 ;; state-of-difference is A, B, C, or nil, indicating which buffer is
649 ;; different from the other two (used only in 3-way jobs.
650 (ediff-defvar-local ediff-difference-vector-A nil "")
651 (ediff-defvar-local ediff-difference-vector-B nil "")
652 (ediff-defvar-local ediff-difference-vector-C nil "")
653 (ediff-defvar-local ediff-difference-vector-Ancestor nil "")
654 ;; A-list of diff vector types associated with buffer types
655 (defconst ediff-difference-vector-alist
656 '((A . ediff-difference-vector-A)
657 (B . ediff-difference-vector-B)
658 (C . ediff-difference-vector-C)
659 (Ancestor . ediff-difference-vector-Ancestor)))
661 ;; [ status status status ...]
662 ;; Each status: [state-of-merge state-of-ancestor]
663 ;; state-of-merge is default-A, default-B, prefer-A, or prefer-B. It
664 ;; indicates the way a diff region was created in buffer C.
665 ;; state-of-ancestor says if the corresponding region in ancestor buffer is
666 ;; empty.
667 (ediff-defvar-local ediff-state-of-merge nil "")
669 ;; The difference that is currently selected.
670 (ediff-defvar-local ediff-current-difference -1 "")
671 ;; Number of differences found.
672 (ediff-defvar-local ediff-number-of-differences nil "")
674 ;; Buffer containing the output of diff, which is used by Ediff to step
675 ;; through files.
676 (ediff-defvar-local ediff-diff-buffer nil "")
677 ;; Like ediff-diff-buffer, but contains context diff. It is not used by
678 ;; Ediff, but it is saved in a file, if user requests so.
679 (ediff-defvar-local ediff-custom-diff-buffer nil "")
680 ;; Buffer used for diff-style fine differences between regions.
681 (ediff-defvar-local ediff-fine-diff-buffer nil "")
682 ;; Temporary buffer used for computing fine differences.
683 (defconst ediff-tmp-buffer " *ediff-tmp*" "")
684 ;; Buffer used for messages
685 (defconst ediff-msg-buffer " *ediff-message*" "")
686 ;; Buffer containing the output of diff when diff returns errors.
687 (ediff-defvar-local ediff-error-buffer nil "")
688 ;; Buffer to display debug info
689 (ediff-defvar-local ediff-debug-buffer "*ediff-debug*" "")
691 ;; List of ediff control panels associated with each buffer A/B/C/Ancestor.
692 ;; Not used any more, but may be needed in the future.
693 (ediff-defvar-local ediff-this-buffer-ediff-sessions nil "")
695 ;; to be deleted in due time
696 ;; List of difference overlays disturbed by working with the current diff.
697 (defvar ediff-disturbed-overlays nil "")
699 ;; Priority of non-selected overlays.
700 (defvar ediff-shadow-overlay-priority 100 "")
702 (defcustom ediff-version-control-package 'vc
703 "Version control package used.
704 Currently, Ediff supports vc.el, rcs.el, pcl-cvs.el, and generic-sc.el. The
705 standard Emacs interface to RCS, CVS, SCCS, etc., is vc.el. However, some
706 people find the other two packages more convenient. Set this variable to the
707 appropriate symbol: `rcs', `pcl-cvs', or `generic-sc' if you so desire."
708 :type 'symbol
709 :group 'ediff)
712 (if ediff-xemacs-p
713 (progn
714 (fset 'ediff-read-event (symbol-function 'next-command-event))
715 (fset 'ediff-overlayp (symbol-function 'extentp))
716 (fset 'ediff-make-overlay (symbol-function 'make-extent))
717 (fset 'ediff-delete-overlay (symbol-function 'delete-extent)))
718 (fset 'ediff-read-event (symbol-function 'read-event))
719 (fset 'ediff-overlayp (symbol-function 'overlayp))
720 (fset 'ediff-make-overlay (symbol-function 'make-overlay))
721 (fset 'ediff-delete-overlay (symbol-function 'delete-overlay)))
723 ;; Check the current version against the major and minor version numbers
724 ;; using op: cur-vers op major.minor If emacs-major-version or
725 ;; emacs-minor-version are not defined, we assume that the current version
726 ;; is hopelessly outdated. We assume that emacs-major-version and
727 ;; emacs-minor-version are defined. Otherwise, for Emacs/XEmacs 19, if the
728 ;; current minor version is < 10 (xemacs) or < 23 (emacs) the return value
729 ;; will be nil (when op is =, >, or >=) and t (when op is <, <=), which may be
730 ;; incorrect. However, this gives correct result in our cases, since we are
731 ;; testing for sufficiently high Emacs versions.
732 (defun ediff-check-version (op major minor &optional type-of-emacs)
733 (if (and (boundp 'emacs-major-version) (boundp 'emacs-minor-version))
734 (and (cond ((eq type-of-emacs 'xemacs) ediff-xemacs-p)
735 ((eq type-of-emacs 'emacs) ediff-emacs-p)
736 (t t))
737 (cond ((eq op '=) (and (= emacs-minor-version minor)
738 (= emacs-major-version major)))
739 ((memq op '(> >= < <=))
740 (and (or (funcall op emacs-major-version major)
741 (= emacs-major-version major))
742 (if (= emacs-major-version major)
743 (funcall op emacs-minor-version minor)
744 t)))
746 (error "%S: Invalid op in ediff-check-version" op))))
747 (cond ((memq op '(= > >=)) nil)
748 ((memq op '(< <=)) t))))
751 (defun ediff-color-display-p ()
752 (condition-case nil
753 (if ediff-emacs-p
754 (if (fboundp 'display-color-p)
755 (display-color-p)
756 (x-display-color-p))
757 (eq (device-class (selected-device)) 'color))
758 (error
759 nil)))
762 (if (ediff-has-face-support-p)
763 (if ediff-xemacs-p
764 (progn
765 (fset 'ediff-valid-color-p (symbol-function 'valid-color-name-p))
766 (fset 'ediff-get-face (symbol-function 'get-face)))
767 (fset 'ediff-valid-color-p (symbol-function
768 (if (fboundp 'color-defined-p)
769 'color-defined-p
770 'x-color-defined-p)))
771 (fset 'ediff-get-face (symbol-function 'internal-get-face))))
773 (if (ediff-window-display-p)
774 (if ediff-xemacs-p
775 (progn
776 (fset 'ediff-display-pixel-width
777 (symbol-function 'device-pixel-width))
778 (fset 'ediff-display-pixel-height
779 (symbol-function 'device-pixel-height)))
780 (fset 'ediff-display-pixel-width (symbol-function
781 (if (fboundp 'display-pixel-width)
782 'display-pixel-width
783 'x-display-pixel-width)))
784 (fset 'ediff-display-pixel-height (symbol-function
785 (if (fboundp 'display-pixel-height)
786 'display-pixel-height
787 'x-display-pixel-height)))))
789 ;; A-list of current-diff-overlay symbols associated with buf types
790 (defconst ediff-current-diff-overlay-alist
791 '((A . ediff-current-diff-overlay-A)
792 (B . ediff-current-diff-overlay-B)
793 (C . ediff-current-diff-overlay-C)
794 (Ancestor . ediff-current-diff-overlay-Ancestor)))
796 ;; A-list of current-diff-face-* symbols associated with buf types
797 (defconst ediff-current-diff-face-alist
798 '((A . ediff-current-diff-face-A)
799 (B . ediff-current-diff-face-B)
800 (C . ediff-current-diff-face-C)
801 (Ancestor . ediff-current-diff-face-Ancestor)))
804 (defun ediff-make-current-diff-overlay (type)
805 (if (ediff-has-face-support-p)
806 (let ((overlay (ediff-get-symbol-from-alist
807 type ediff-current-diff-overlay-alist))
808 (buffer (ediff-get-buffer type))
809 (face (face-name
810 (symbol-value
811 (ediff-get-symbol-from-alist
812 type ediff-current-diff-face-alist)))))
813 (set overlay
814 (ediff-make-bullet-proof-overlay (point-max) (point-max) buffer))
815 (ediff-set-overlay-face (symbol-value overlay) face)
816 (ediff-overlay-put (symbol-value overlay) 'ediff ediff-control-buffer))
819 (defun ediff-set-overlay-face (extent face)
820 (ediff-overlay-put extent 'face face)
821 (ediff-overlay-put extent 'help-echo 'ediff-region-help-echo))
823 (defun ediff-region-help-echo (extent-or-window &optional overlay point)
824 (unless overlay
825 (setq overlay extent-or-window))
826 (let ((is-current (ediff-overlay-get overlay 'ediff))
827 (face (ediff-overlay-get overlay 'face))
828 (diff-num (ediff-overlay-get overlay 'ediff-diff-num))
829 face-help)
831 ;; This happens only for refinement overlays
832 (if (stringp face)
833 (setq face (intern face)))
834 (setq face-help (and face (get face 'ediff-help-echo)))
836 (cond ((and is-current diff-num) ; current diff region
837 (format "Difference region %S -- current" (1+ diff-num)))
838 (face-help) ; refinement of current diff region
839 (diff-num ; non-current
840 (format "Difference region %S -- non-current" (1+ diff-num)))
841 (t "")) ; none
845 (defun ediff-set-face-pixmap (face pixmap)
846 "Set face pixmap on a monochrome display."
847 (if (and (ediff-window-display-p) (not (ediff-color-display-p)))
848 (condition-case nil
849 (set-face-background-pixmap face pixmap)
850 (error
851 (message "Pixmap not found for %S: %s" (face-name face) pixmap)
852 (sit-for 1)))))
854 (defun ediff-hide-face (face)
855 (if (and (ediff-has-face-support-p) ediff-emacs-p)
856 (add-to-list 'facemenu-unlisted-faces face)))
860 (defface ediff-current-diff-face-A
861 '((((class color)) (:foreground "firebrick" :background "pale green"))
862 (t (:inverse-video t)))
863 "Face for highlighting the selected difference in buffer A."
864 :group 'ediff-highlighting)
865 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
866 ;; this variable is set to nil, then again to the appropriate face.
867 (defvar ediff-current-diff-face-A 'ediff-current-diff-face-A
868 "Face for highlighting the selected difference in buffer A.
869 DO NOT CHANGE this variable. Instead, use the customization
870 widget to customize the actual face object `ediff-current-diff-face-A'
871 this variable represents.")
872 (ediff-hide-face 'ediff-current-diff-face-A)
873 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
874 ;; This means that some user customization may be trashed.
875 (if (and ediff-xemacs-p
876 (ediff-has-face-support-p)
877 (not (ediff-color-display-p)))
878 (copy-face 'modeline 'ediff-current-diff-face-A))
882 (defface ediff-current-diff-face-B
883 '((((class color)) (:foreground "DarkOrchid" :background "Yellow"))
884 (t (:inverse-video t)))
885 "Face for highlighting the selected difference in buffer B."
886 :group 'ediff-highlighting)
887 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
888 ;; this variable is set to nil, then again to the appropriate face.
889 (defvar ediff-current-diff-face-B 'ediff-current-diff-face-B
890 "Face for highlighting the selected difference in buffer B.
891 this variable. Instead, use the customization
892 widget to customize the actual face `ediff-current-diff-face-B'
893 this variable represents.")
894 (ediff-hide-face 'ediff-current-diff-face-B)
895 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
896 ;; This means that some user customization may be trashed.
897 (if (and ediff-xemacs-p
898 (ediff-has-face-support-p)
899 (not (ediff-color-display-p)))
900 (copy-face 'modeline 'ediff-current-diff-face-B))
903 (defface ediff-current-diff-face-C
904 '((((class color)) (:foreground "Navy" :background "Pink"))
905 (t (:inverse-video t)))
906 "Face for highlighting the selected difference in buffer C."
907 :group 'ediff-highlighting)
908 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
909 ;; this variable is set to nil, then again to the appropriate face.
910 (defvar ediff-current-diff-face-C 'ediff-current-diff-face-C
911 "Face for highlighting the selected difference in buffer C.
912 DO NOT CHANGE this variable. Instead, use the customization
913 widget to customize the actual face object `ediff-current-diff-face-C'
914 this variable represents.")
915 (ediff-hide-face 'ediff-current-diff-face-C)
916 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
917 ;; This means that some user customization may be trashed.
918 (if (and ediff-xemacs-p
919 (ediff-has-face-support-p)
920 (not (ediff-color-display-p)))
921 (copy-face 'modeline 'ediff-current-diff-face-C))
924 (defface ediff-current-diff-face-Ancestor
925 '((((class color)) (:foreground "Black" :background "VioletRed"))
926 (t (:inverse-video t)))
927 "Face for highlighting the selected difference in buffer Ancestor."
928 :group 'ediff-highlighting)
929 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
930 ;; this variable is set to nil, then again to the appropriate face.
931 (defvar ediff-current-diff-face-Ancestor 'ediff-current-diff-face-Ancestor
932 "Face for highlighting the selected difference in buffer Ancestor.
933 DO NOT CHANGE this variable. Instead, use the customization
934 widget to customize the actual face object `ediff-current-diff-face-Ancestor'
935 this variable represents.")
936 (ediff-hide-face 'ediff-current-diff-face-Ancestor)
937 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
938 ;; This means that some user customization may be trashed.
939 (if (and ediff-xemacs-p
940 (ediff-has-face-support-p)
941 (not (ediff-color-display-p)))
942 (copy-face 'modeline 'ediff-current-diff-face-Ancestor))
945 (defface ediff-fine-diff-face-A
946 '((((class color)) (:foreground "Navy" :background "sky blue"))
947 (t (:underline t :stipple "gray3")))
948 "Face for highlighting the refinement of the selected diff in buffer A."
949 :group 'ediff-highlighting)
950 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
951 ;; this variable is set to nil, then again to the appropriate face.
952 (defvar ediff-fine-diff-face-A 'ediff-fine-diff-face-A
953 "Face for highlighting the fine differences in buffer A.
954 DO NOT CHANGE this variable. Instead, use the customization
955 widget to customize the actual face object `ediff-fine-diff-face-A'
956 this variable represents.")
957 (ediff-hide-face 'ediff-fine-diff-face-A)
959 (defface ediff-fine-diff-face-B
960 '((((class color)) (:foreground "Black" :background "cyan"))
961 (t (:underline t :stipple "gray3")))
962 "Face for highlighting the refinement of the selected diff in buffer B."
963 :group 'ediff-highlighting)
964 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
965 ;; this variable is set to nil, then again to the appropriate face.
966 (defvar ediff-fine-diff-face-B 'ediff-fine-diff-face-B
967 "Face for highlighting the fine differences in buffer B.
968 DO NOT CHANGE this variable. Instead, use the customization
969 widget to customize the actual face object `ediff-fine-diff-face-B'
970 this variable represents.")
971 (ediff-hide-face 'ediff-fine-diff-face-B)
973 (defface ediff-fine-diff-face-C
974 '((((class color)) (:foreground "Black" :background "Turquoise"))
975 (t (:underline t :stipple "gray3")))
976 "Face for highlighting the refinement of the selected diff in buffer C."
977 :group 'ediff-highlighting)
978 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
979 ;; this variable is set to nil, then again to the appropriate face.
980 (defvar ediff-fine-diff-face-C 'ediff-fine-diff-face-C
981 "Face for highlighting the fine differences in buffer C.
982 DO NOT CHANGE this variable. Instead, use the customization
983 widget to customize the actual face object `ediff-fine-diff-face-C'
984 this variable represents.")
985 (ediff-hide-face 'ediff-fine-diff-face-C)
987 (defface ediff-fine-diff-face-Ancestor
988 '((((class color)) (:foreground "Black" :background "Green"))
989 (t (:underline t :stipple "gray3")))
990 "Face for highlighting the refinement of the selected diff in the ancestor buffer.
991 At present, this face is not used and no fine differences are computed for the
992 ancestor buffer."
993 :group 'ediff-highlighting)
994 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
995 ;; this variable is set to nil, then again to the appropriate face.
996 (defvar ediff-fine-diff-face-Ancestor 'ediff-fine-diff-face-Ancestor
997 "Face for highlighting the fine differences in buffer Ancestor.
998 DO NOT CHANGE this variable. Instead, use the customization
999 widget to customize the actual face object `ediff-fine-diff-face-Ancestor'
1000 this variable represents.")
1001 (ediff-hide-face 'ediff-fine-diff-face-Ancestor)
1003 ;; Some installs don't have stipple or Stipple. So, try them in turn.
1004 (defvar stipple-pixmap
1005 (cond ((not (ediff-has-face-support-p)) nil)
1006 ((and (boundp 'x-bitmap-file-path)
1007 (locate-library "stipple" t x-bitmap-file-path)) "stipple")
1008 ((and (boundp 'mswindowsx-bitmap-file-path)
1009 (locate-library "stipple" t mswindowsx-bitmap-file-path)) "stipple")
1010 (t "Stipple")))
1012 (defface ediff-even-diff-face-A
1013 `((((class color)) (:foreground "Black" :background "light grey"))
1014 (t (:italic t :stipple ,stipple-pixmap)))
1015 "Face for highlighting even-numbered non-current differences in buffer A."
1016 :group 'ediff-highlighting)
1017 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1018 ;; this variable is set to nil, then again to the appropriate face.
1019 (defvar ediff-even-diff-face-A 'ediff-even-diff-face-A
1020 "Face for highlighting even-numbered non-current differences in buffer A.
1021 DO NOT CHANGE this variable. Instead, use the customization
1022 widget to customize the actual face object `ediff-even-diff-face-A'
1023 this variable represents.")
1024 (ediff-hide-face 'ediff-even-diff-face-A)
1026 (defface ediff-even-diff-face-B
1027 `((((class color)) (:foreground "White" :background "Grey"))
1028 (t (:italic t :stipple ,stipple-pixmap)))
1029 "Face for highlighting even-numbered non-current differences in buffer B."
1030 :group 'ediff-highlighting)
1031 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1032 ;; this variable is set to nil, then again to the appropriate face.
1033 (defvar ediff-even-diff-face-B 'ediff-even-diff-face-B
1034 "Face for highlighting even-numbered non-current differences in buffer B.
1035 DO NOT CHANGE this variable. Instead, use the customization
1036 widget to customize the actual face object `ediff-even-diff-face-B'
1037 this variable represents.")
1038 (ediff-hide-face 'ediff-even-diff-face-B)
1040 (defface ediff-even-diff-face-C
1041 `((((class color)) (:foreground "Black" :background "light grey"))
1042 (t (:italic t :stipple ,stipple-pixmap)))
1043 "Face for highlighting even-numbered non-current differences in buffer C."
1044 :group 'ediff-highlighting)
1045 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1046 ;; this variable is set to nil, then again to the appropriate face.
1047 (defvar ediff-even-diff-face-C 'ediff-even-diff-face-C
1048 "Face for highlighting even-numbered non-current differences in buffer C.
1049 DO NOT CHANGE this variable. Instead, use the customization
1050 widget to customize the actual face object `ediff-even-diff-face-C'
1051 this variable represents.")
1052 (ediff-hide-face 'ediff-even-diff-face-C)
1054 (defface ediff-even-diff-face-Ancestor
1055 `((((class color)) (:foreground "White" :background "Grey"))
1056 (t (:italic t :stipple ,stipple-pixmap)))
1057 "Face for highlighting even-numbered non-current differences in the ancestor buffer."
1058 :group 'ediff-highlighting)
1059 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1060 ;; this variable is set to nil, then again to the appropriate face.
1061 (defvar ediff-even-diff-face-Ancestor 'ediff-even-diff-face-Ancestor
1062 "Face for highlighting even-numbered non-current differences in buffer Ancestor.
1063 DO NOT CHANGE this variable. Instead, use the customization
1064 widget to customize the actual face object `ediff-even-diff-face-Ancestor'
1065 this variable represents.")
1066 (ediff-hide-face 'ediff-even-diff-face-Ancestor)
1068 ;; Association between buffer types and even-diff-face symbols
1069 (defconst ediff-even-diff-face-alist
1070 '((A . ediff-even-diff-face-A)
1071 (B . ediff-even-diff-face-B)
1072 (C . ediff-even-diff-face-C)
1073 (Ancestor . ediff-even-diff-face-Ancestor)))
1075 (defface ediff-odd-diff-face-A
1076 '((((class color)) (:foreground "White" :background "Grey"))
1077 (t (:italic t :stipple "gray1")))
1078 "Face for highlighting odd-numbered non-current differences in buffer A."
1079 :group 'ediff-highlighting)
1080 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1081 ;; this variable is set to nil, then again to the appropriate face.
1082 (defvar ediff-odd-diff-face-A 'ediff-odd-diff-face-A
1083 "Face for highlighting odd-numbered non-current differences in buffer A.
1084 DO NOT CHANGE this variable. Instead, use the customization
1085 widget to customize the actual face object `ediff-odd-diff-face-A'
1086 this variable represents.")
1087 (ediff-hide-face 'ediff-odd-diff-face-A)
1090 (defface ediff-odd-diff-face-B
1091 '((((class color)) (:foreground "Black" :background "light grey"))
1092 (t (:italic t :stipple "gray1")))
1093 "Face for highlighting odd-numbered non-current differences in buffer B."
1094 :group 'ediff-highlighting)
1095 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1096 ;; this variable is set to nil, then again to the appropriate face.
1097 (defvar ediff-odd-diff-face-B 'ediff-odd-diff-face-B
1098 "Face for highlighting odd-numbered non-current differences in buffer B.
1099 DO NOT CHANGE this variable. Instead, use the customization
1100 widget to customize the actual face object `ediff-odd-diff-face-B'
1101 this variable represents.")
1102 (ediff-hide-face 'ediff-odd-diff-face-B)
1104 (defface ediff-odd-diff-face-C
1105 '((((class color)) (:foreground "White" :background "Grey"))
1106 (t (:italic t :stipple "gray1")))
1107 "Face for highlighting odd-numbered non-current differences in buffer C."
1108 :group 'ediff-highlighting)
1109 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1110 ;; this variable is set to nil, then again to the appropriate face.
1111 (defvar ediff-odd-diff-face-C 'ediff-odd-diff-face-C
1112 "Face for highlighting odd-numbered non-current differences in buffer C.
1113 DO NOT CHANGE this variable. Instead, use the customization
1114 widget to customize the actual face object `ediff-odd-diff-face-C'
1115 this variable represents.")
1116 (ediff-hide-face 'ediff-odd-diff-face-C)
1118 (defface ediff-odd-diff-face-Ancestor
1119 '((((class color)) (:foreground "Black" :background "light grey"))
1120 (t (:italic t :stipple "gray1")))
1121 "Face for highlighting odd-numbered non-current differences in the ancestor buffer."
1122 :group 'ediff-highlighting)
1123 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1124 ;; this variable is set to nil, then again to the appropriate face.
1125 (defvar ediff-odd-diff-face-Ancestor 'ediff-odd-diff-face-Ancestor
1126 "Face for highlighting odd-numbered non-current differences in buffer Ancestor.
1127 DO NOT CHANGE this variable. Instead, use the customization
1128 widget to customize the actual face object `ediff-odd-diff-face-Ancestor'
1129 this variable represents.")
1130 (ediff-hide-face 'ediff-odd-diff-face-Ancestor)
1132 ;; Association between buffer types and odd-diff-face symbols
1133 (defconst ediff-odd-diff-face-alist
1134 '((A . ediff-odd-diff-face-A)
1135 (B . ediff-odd-diff-face-B)
1136 (C . ediff-odd-diff-face-C)
1137 (Ancestor . ediff-odd-diff-face-Ancestor)))
1139 ;; A-list of fine-diff face symbols associated with buffer types
1140 (defconst ediff-fine-diff-face-alist
1141 '((A . ediff-fine-diff-face-A)
1142 (B . ediff-fine-diff-face-B)
1143 (C . ediff-fine-diff-face-C)
1144 (Ancestor . ediff-fine-diff-face-Ancestor)))
1146 ;; Help echo
1147 (put 'ediff-fine-diff-face-A 'ediff-help-echo
1148 "A `refinement' of the current difference region")
1149 (put 'ediff-fine-diff-face-B 'ediff-help-echo
1150 "A `refinement' of the current difference region")
1151 (put 'ediff-fine-diff-face-C 'ediff-help-echo
1152 "A `refinement' of the current difference region")
1153 (put 'ediff-fine-diff-face-Ancestor 'ediff-help-echo
1154 "A `refinement' of the current difference region")
1156 (add-hook 'ediff-quit-hook 'ediff-cleanup-mess)
1157 (add-hook 'ediff-suspend-hook 'ediff-default-suspend-function)
1160 ;;; Overlays
1162 (ediff-defvar-local ediff-current-diff-overlay-A nil
1163 "Overlay for the current difference region in buffer A.")
1164 (ediff-defvar-local ediff-current-diff-overlay-B nil
1165 "Overlay for the current difference region in buffer B.")
1166 (ediff-defvar-local ediff-current-diff-overlay-C nil
1167 "Overlay for the current difference region in buffer C.")
1168 (ediff-defvar-local ediff-current-diff-overlay-Ancestor nil
1169 "Overlay for the current difference region in the ancestor buffer.")
1171 ;; Compute priority of ediff overlay.
1172 (defun ediff-highest-priority (start end buffer)
1173 (let ((pos (max 1 (1- start)))
1174 ovr-list)
1175 (if ediff-xemacs-p
1176 (1+ ediff-shadow-overlay-priority)
1177 (ediff-with-current-buffer buffer
1178 (while (< pos (min (point-max) (1+ end)))
1179 (setq ovr-list (append (overlays-at pos) ovr-list))
1180 (setq pos (next-overlay-change pos)))
1181 (1+ (apply '+
1182 (mapcar (lambda (ovr)
1183 (if ovr
1184 (or (ediff-overlay-get ovr 'priority) 0)
1186 ovr-list)
1188 ))))
1191 (defvar ediff-toggle-read-only-function nil
1192 "*Specifies the function to be used to toggle read-only.
1193 If nil, Ediff tries to deduce the function from the binding of C-x C-q.
1194 Normally, this is the `toggle-read-only' function, but, if version
1195 control is used, it could be `vc-toggle-read-only' or `rcs-toggle-read-only'.")
1197 (defcustom ediff-make-buffers-readonly-at-startup nil
1198 "*Make all variant buffers read-only when Ediff starts up.
1199 This property can be toggled interactively."
1200 :type 'boolean
1201 :group 'ediff)
1204 ;;; Misc
1206 ;; if nil, this silences some messages
1207 (defconst ediff-verbose-p t)
1209 (defcustom ediff-autostore-merges 'group-jobs-only
1210 "*Save the results of merge jobs automatically.
1211 Nil means don't save automatically. t means always save. Anything but nil or t
1212 means save automatically only if the merge job is part of a group of jobs, such
1213 as `ediff-merge-directory' or `ediff-merge-directory-revisions'."
1214 :type '(choice (const nil) (const t) (const group-jobs-only))
1215 :group 'ediff-merge)
1216 (make-variable-buffer-local 'ediff-autostore-merges)
1218 ;; file where the result of the merge is to be saved. used internally
1219 (ediff-defvar-local ediff-merge-store-file nil "")
1221 (defcustom ediff-merge-filename-prefix "merge_"
1222 "*Prefix to be attached to saved merge buffers."
1223 :type 'string
1224 :version "21.1"
1225 :group 'ediff-merge)
1227 (defcustom ediff-no-emacs-help-in-control-buffer nil
1228 "*Non-nil means C-h should not invoke Emacs help in control buffer.
1229 Instead, C-h would jump to previous difference."
1230 :type 'boolean
1231 :group 'ediff)
1233 ;; This is the same as temporary-file-directory from Emacs 20.3.
1234 ;; Copied over here because XEmacs doesn't have this variable.
1235 (defcustom ediff-temp-file-prefix
1236 (file-name-as-directory
1237 (cond ((boundp 'temporary-file-directory) temporary-file-directory)
1238 ((fboundp 'temp-directory) (temp-directory))
1239 (t "/tmp/")))
1240 ;;; (file-name-as-directory
1241 ;;; (cond ((memq system-type '(ms-dos windows-nt))
1242 ;;; (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
1243 ;;; ((memq system-type '(vax-vms axp-vms))
1244 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
1245 ;;; (t
1246 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))
1247 "*Prefix to put on Ediff temporary file names.
1248 Do not start with `~/' or `~USERNAME/'."
1249 :type 'string
1250 :group 'ediff)
1252 (defcustom ediff-temp-file-mode 384 ; u=rw only
1253 "*Mode for Ediff temporary files."
1254 :type 'integer
1255 :group 'ediff)
1257 ;; Metacharacters that have to be protected from the shell when executing
1258 ;; a diff/diff3 command.
1259 (defcustom ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
1260 "Regexp that matches characters that must be quoted with `\\' in shell command line.
1261 This default should work without changes."
1262 :type 'string
1263 :group 'ediff)
1265 ;; needed to simulate frame-char-width in XEmacs.
1266 (defvar ediff-H-glyph (if ediff-xemacs-p (make-glyph "H")))
1269 ;; Temporary file used for refining difference regions in buffer A.
1270 (ediff-defvar-local ediff-temp-file-A nil "")
1271 ;; Temporary file used for refining difference regions in buffer B.
1272 (ediff-defvar-local ediff-temp-file-B nil "")
1273 ;; Temporary file used for refining difference regions in buffer C.
1274 (ediff-defvar-local ediff-temp-file-C nil "")
1277 ;;; In-line functions
1279 (or (fboundp 'ediff-file-remote-p) ; user supplied his own function: use it
1280 (defun ediff-file-remote-p (file-name)
1281 (find-file-name-handler file-name 'file-local-copy)))
1282 ;;; (or (and (featurep 'efs-auto) (efs-ftp-path file-name))
1283 ;;; (and (featurep 'tramp) (tramp-tramp-file-p file-name))
1284 ;;; (and (fboundp 'file-remote-p) (file-remote-p file-name))
1285 ;;; ;; Can happen only in Emacs, since XEmacs has file-remote-p
1286 ;;; (and (require 'ange-ftp) (ange-ftp-ftp-name file-name)))))
1289 (defsubst ediff-frame-unsplittable-p (frame)
1290 (cdr (assq 'unsplittable (frame-parameters frame))))
1292 (defsubst ediff-get-next-window (wind prev-wind)
1293 (or (window-live-p wind)
1294 (setq wind (if prev-wind
1295 (next-window wind)
1296 (selected-window)))))
1299 (defsubst ediff-kill-buffer-carefully (buf)
1300 "Kill buffer BUF if it exists."
1301 (if (ediff-buffer-live-p buf)
1302 (kill-buffer (get-buffer buf))))
1304 (defsubst ediff-background-face (buf-type dif-num)
1305 ;; The value of dif-num is always 1- the one that user sees.
1306 ;; This is why even face is used when dif-num is odd.
1307 (ediff-get-symbol-from-alist
1308 buf-type (if (ediff-odd-p dif-num)
1309 ediff-even-diff-face-alist
1310 ediff-odd-diff-face-alist)
1314 ;; activate faces on diff regions in buffer
1315 (defun ediff-paint-background-regions-in-one-buffer (buf-type unhighlight)
1316 (let ((diff-vector
1317 (eval (ediff-get-symbol-from-alist
1318 buf-type ediff-difference-vector-alist)))
1319 overl diff-num)
1320 (mapcar (lambda (rec)
1321 (setq overl (ediff-get-diff-overlay-from-diff-record rec)
1322 diff-num (ediff-overlay-get overl 'ediff-diff-num))
1323 (if (ediff-overlay-buffer overl)
1324 ;; only if overlay is alive
1325 (ediff-set-overlay-face
1326 overl
1327 (if (not unhighlight)
1328 (ediff-background-face buf-type diff-num))))
1330 diff-vector)))
1333 ;; activate faces on diff regions in all buffers
1334 (defun ediff-paint-background-regions (&optional unhighlight)
1335 (ediff-paint-background-regions-in-one-buffer
1336 'A unhighlight)
1337 (ediff-paint-background-regions-in-one-buffer
1338 'B unhighlight)
1339 (ediff-paint-background-regions-in-one-buffer
1340 'C unhighlight)
1341 (ediff-paint-background-regions-in-one-buffer
1342 'Ancestor unhighlight))
1344 (defun ediff-highlight-diff-in-one-buffer (n buf-type)
1345 (if (ediff-buffer-live-p (ediff-get-buffer buf-type))
1346 (let* ((buff (ediff-get-buffer buf-type))
1347 (last (ediff-with-current-buffer buff (point-max)))
1348 (begin (ediff-get-diff-posn buf-type 'beg n))
1349 (end (ediff-get-diff-posn buf-type 'end n))
1350 (xtra (if (equal begin end) 1 0))
1351 (end-hilit (min last (+ end xtra)))
1352 (current-diff-overlay
1353 (symbol-value
1354 (ediff-get-symbol-from-alist
1355 buf-type ediff-current-diff-overlay-alist))))
1357 (if ediff-xemacs-p
1358 (ediff-move-overlay current-diff-overlay begin end-hilit)
1359 (ediff-move-overlay current-diff-overlay begin end-hilit buff))
1360 (ediff-overlay-put current-diff-overlay 'priority
1361 (ediff-highest-priority begin end-hilit buff))
1362 (ediff-overlay-put current-diff-overlay 'ediff-diff-num n)
1364 ;; unhighlight the background overlay for diff n so it won't
1365 ;; interfere with the current diff overlay
1366 (ediff-set-overlay-face (ediff-get-diff-overlay n buf-type) nil)
1370 (defun ediff-unhighlight-diff-in-one-buffer (buf-type)
1371 (if (ediff-buffer-live-p (ediff-get-buffer buf-type))
1372 (let ((current-diff-overlay
1373 (symbol-value
1374 (ediff-get-symbol-from-alist
1375 buf-type ediff-current-diff-overlay-alist)))
1376 (overlay
1377 (ediff-get-diff-overlay ediff-current-difference buf-type))
1380 (ediff-move-overlay current-diff-overlay 1 1)
1382 ;; rehighlight the overlay in the background of the
1383 ;; current difference region
1384 (ediff-set-overlay-face
1385 overlay
1386 (if (and (ediff-has-face-support-p)
1387 ediff-use-faces ediff-highlight-all-diffs)
1388 (ediff-background-face buf-type ediff-current-difference)))
1391 (defun ediff-unhighlight-diffs-totally-in-one-buffer (buf-type)
1392 (ediff-unselect-and-select-difference -1)
1393 (if (and (ediff-has-face-support-p) ediff-use-faces)
1394 (let* ((inhibit-quit t)
1395 (current-diff-overlay-var
1396 (ediff-get-symbol-from-alist
1397 buf-type ediff-current-diff-overlay-alist))
1398 (current-diff-overlay (symbol-value current-diff-overlay-var)))
1399 (ediff-paint-background-regions 'unhighlight)
1400 (if (ediff-overlayp current-diff-overlay)
1401 (ediff-delete-overlay current-diff-overlay))
1402 (set current-diff-overlay-var nil)
1406 (defsubst ediff-highlight-diff (n)
1407 "Put face on diff N. Invoked for X displays only."
1408 (ediff-highlight-diff-in-one-buffer n 'A)
1409 (ediff-highlight-diff-in-one-buffer n 'B)
1410 (ediff-highlight-diff-in-one-buffer n 'C)
1411 (ediff-highlight-diff-in-one-buffer n 'Ancestor)
1415 (defsubst ediff-unhighlight-diff ()
1416 "Remove overlays from buffers A, B, and C."
1417 (ediff-unhighlight-diff-in-one-buffer 'A)
1418 (ediff-unhighlight-diff-in-one-buffer 'B)
1419 (ediff-unhighlight-diff-in-one-buffer 'C)
1420 (ediff-unhighlight-diff-in-one-buffer 'Ancestor)
1423 ;; delete highlighting overlays, restore faces to their original form
1424 (defsubst ediff-unhighlight-diffs-totally ()
1425 (ediff-unhighlight-diffs-totally-in-one-buffer 'A)
1426 (ediff-unhighlight-diffs-totally-in-one-buffer 'B)
1427 (ediff-unhighlight-diffs-totally-in-one-buffer 'C)
1428 (ediff-unhighlight-diffs-totally-in-one-buffer 'Ancestor)
1432 ;; arg is a record for a given diff in a difference vector
1433 ;; this record is itself a vector
1434 (defsubst ediff-clear-fine-diff-vector (diff-record)
1435 (if diff-record
1436 (mapcar 'ediff-delete-overlay
1437 (ediff-get-fine-diff-vector-from-diff-record diff-record))))
1439 (defsubst ediff-clear-fine-differences-in-one-buffer (n buf-type)
1440 (ediff-clear-fine-diff-vector (ediff-get-difference n buf-type))
1441 (ediff-set-fine-diff-vector n buf-type nil))
1443 (defsubst ediff-clear-fine-differences (n)
1444 (ediff-clear-fine-differences-in-one-buffer n 'A)
1445 (ediff-clear-fine-differences-in-one-buffer n 'B)
1446 (if ediff-3way-job
1447 (ediff-clear-fine-differences-in-one-buffer n 'C)))
1450 (defsubst ediff-convert-fine-diffs-to-overlays (diff-list region-num)
1451 (ediff-set-fine-overlays-in-one-buffer 'A diff-list region-num)
1452 (ediff-set-fine-overlays-in-one-buffer 'B diff-list region-num)
1453 (if ediff-3way-job
1454 (ediff-set-fine-overlays-in-one-buffer 'C diff-list region-num)
1457 (defsubst ediff-mouse-event-p (event)
1458 (if ediff-xemacs-p
1459 (button-event-p event)
1460 (string-match "mouse" (format "%S" (event-basic-type event)))
1464 (defsubst ediff-key-press-event-p (event)
1465 (if ediff-xemacs-p
1466 (key-press-event-p event)
1467 (or (char-or-string-p event) (symbolp event))))
1469 (defun ediff-event-point (event)
1470 (cond ((ediff-mouse-event-p event)
1471 (if ediff-xemacs-p
1472 (event-point event)
1473 (posn-point (event-start event))))
1474 ((ediff-key-press-event-p event)
1475 (point))
1476 (t (error))))
1478 (defun ediff-event-buffer (event)
1479 (cond ((ediff-mouse-event-p event)
1480 (if ediff-xemacs-p
1481 (event-buffer event)
1482 (window-buffer (posn-window (event-start event)))))
1483 ((ediff-key-press-event-p event)
1484 (current-buffer))
1485 (t (error))))
1488 (defsubst ediff-frame-iconified-p (frame)
1489 (if (and (ediff-window-display-p) (frame-live-p frame))
1490 (if ediff-xemacs-p
1491 (frame-iconified-p frame)
1492 (eq (frame-visible-p frame) 'icon))))
1494 (defsubst ediff-window-visible-p (wind)
1495 ;; under TTY, window-live-p also means window is visible
1496 (and (window-live-p wind)
1497 (or (not (ediff-window-display-p))
1498 (frame-visible-p (window-frame wind)))))
1501 (defsubst ediff-frame-char-width (frame)
1502 (if ediff-xemacs-p
1503 (/ (frame-pixel-width frame) (frame-width frame))
1504 (frame-char-width frame)))
1506 (defun ediff-reset-mouse (&optional frame do-not-grab-mouse)
1507 (or frame (setq frame (selected-frame)))
1508 (if (ediff-window-display-p)
1509 (let ((frame-or-wind frame))
1510 (if ediff-xemacs-p
1511 (setq frame-or-wind (frame-selected-window frame)))
1512 (or do-not-grab-mouse
1513 ;; don't set mouse if the user said to never do this
1514 (not ediff-grab-mouse)
1515 ;; Don't grab on quit, if the user doesn't want to.
1516 ;; If ediff-grab-mouse = t, then mouse won't be grabbed for
1517 ;; sessions that are not part of a group (this is done in
1518 ;; ediff-recenter). The condition below affects only terminating
1519 ;; sessions in session groups (in which case mouse is warped into
1520 ;; a meta buffer).
1521 (and (eq ediff-grab-mouse 'maybe)
1522 (memq this-command '(ediff-quit ediff-update-diffs)))
1523 (set-mouse-position frame-or-wind 1 0))
1526 (defsubst ediff-spy-after-mouse ()
1527 (setq ediff-mouse-pixel-position (mouse-pixel-position)))
1529 ;; It is not easy to find out when the user grabs the mouse, since emacs and
1530 ;; xemacs behave differently when mouse is not in any frame. Also, this is
1531 ;; sensitive to when the user grabbed mouse. Not used for now.
1532 (defun ediff-user-grabbed-mouse ()
1533 (if ediff-mouse-pixel-position
1534 (cond ((not (eq (car ediff-mouse-pixel-position)
1535 (car (mouse-pixel-position)))))
1536 ((and (car (cdr ediff-mouse-pixel-position))
1537 (car (cdr (mouse-pixel-position)))
1538 (cdr (cdr ediff-mouse-pixel-position))
1539 (cdr (cdr (mouse-pixel-position))))
1540 (not (and (< (abs (- (car (cdr ediff-mouse-pixel-position))
1541 (car (cdr (mouse-pixel-position)))))
1542 ediff-mouse-pixel-threshold)
1543 (< (abs (- (cdr (cdr ediff-mouse-pixel-position))
1544 (cdr (cdr (mouse-pixel-position)))))
1545 ediff-mouse-pixel-threshold))))
1546 (t nil))))
1548 (defsubst ediff-frame-char-height (frame)
1549 (if ediff-xemacs-p
1550 (glyph-height ediff-H-glyph (selected-window frame))
1551 (frame-char-height frame)))
1553 ;; Some overlay functions
1555 (defsubst ediff-overlay-start (overl)
1556 (if (ediff-overlayp overl)
1557 (if ediff-emacs-p
1558 (overlay-start overl)
1559 (extent-start-position overl))))
1561 (defsubst ediff-overlay-end (overl)
1562 (if (ediff-overlayp overl)
1563 (if ediff-emacs-p
1564 (overlay-end overl)
1565 (extent-end-position overl))))
1567 (defsubst ediff-empty-overlay-p (overl)
1568 (= (ediff-overlay-start overl) (ediff-overlay-end overl)))
1570 ;; like overlay-buffer in Emacs. In XEmacs, returns nil if the extent is
1571 ;; dead. Otherwise, works like extent-buffer
1572 (defun ediff-overlay-buffer (overl)
1573 (if ediff-emacs-p
1574 (overlay-buffer overl)
1575 (and (extent-live-p overl) (extent-object overl))))
1577 ;; like overlay-get in Emacs. In XEmacs, returns nil if the extent is
1578 ;; dead. Otherwise, like extent-property
1579 (defun ediff-overlay-get (overl property)
1580 (if ediff-emacs-p
1581 (overlay-get overl property)
1582 (and (extent-live-p overl) (extent-property overl property))))
1585 ;; These two functions are here because XEmacs refuses to
1586 ;; handle overlays whose buffers were deleted.
1587 (defun ediff-move-overlay (overlay beg end &optional buffer)
1588 "Calls `move-overlay' in Emacs and `set-extent-endpoints' in Lemacs.
1589 Checks if overlay's buffer exists before actually doing the move."
1590 (let ((buf (and overlay (ediff-overlay-buffer overlay))))
1591 (if (ediff-buffer-live-p buf)
1592 (if ediff-xemacs-p
1593 (set-extent-endpoints overlay beg end)
1594 (move-overlay overlay beg end buffer))
1595 ;; buffer's dead
1596 (if overlay
1597 (ediff-delete-overlay overlay)))))
1599 (defun ediff-overlay-put (overlay prop value)
1600 "Calls `overlay-put' or `set-extent-property' depending on Emacs version.
1601 Checks if overlay's buffer exists."
1602 (if (ediff-buffer-live-p (ediff-overlay-buffer overlay))
1603 (if ediff-xemacs-p
1604 (set-extent-property overlay prop value)
1605 (overlay-put overlay prop value))
1606 (ediff-delete-overlay overlay)))
1608 ;; Some diff region tests
1610 ;; t if diff region is empty.
1611 ;; In case of buffer C, t also if it is not a 3way
1612 ;; comparison job (merging jobs return t as well).
1613 (defun ediff-empty-diff-region-p (n buf-type)
1614 (if (eq buf-type 'C)
1615 (or (not ediff-3way-comparison-job)
1616 (= (ediff-get-diff-posn 'C 'beg n)
1617 (ediff-get-diff-posn 'C 'end n)))
1618 (= (ediff-get-diff-posn buf-type 'beg n)
1619 (ediff-get-diff-posn buf-type 'end n))))
1621 ;; Test if diff region is white space only.
1622 ;; If 2-way job and buf-type = C, then returns t.
1623 (defun ediff-whitespace-diff-region-p (n buf-type)
1624 (or (and (eq buf-type 'C) (not ediff-3way-job))
1625 (ediff-empty-diff-region-p n buf-type)
1626 (let ((beg (ediff-get-diff-posn buf-type 'beg n))
1627 (end (ediff-get-diff-posn buf-type 'end n)))
1628 (ediff-with-current-buffer (ediff-get-buffer buf-type)
1629 (save-excursion
1630 (goto-char beg)
1631 (skip-chars-forward ediff-whitespace)
1632 (>= (point) end))))))
1634 ;; temporarily uses DIR to abbreviate file name
1635 ;; if DIR is nil, use default-directory
1636 (defun ediff-abbreviate-file-name (file &optional dir)
1637 (cond ((stringp dir)
1638 (let ((directory-abbrev-alist (list (cons dir ""))))
1639 (abbreviate-file-name file)))
1640 (ediff-emacs-p (abbreviate-file-name file))
1641 (t ; XEmacs requires addl argument
1642 (abbreviate-file-name file t))))
1644 ;; Takes a directory and returns the parent directory.
1645 ;; does nothing to `/'. If the ARG is a regular file,
1646 ;; strip the file AND the last dir.
1647 (defun ediff-strip-last-dir (dir)
1648 (if (not (stringp dir)) (setq dir default-directory))
1649 (setq dir (expand-file-name dir))
1650 (or (file-directory-p dir) (setq dir (file-name-directory dir)))
1651 (let* ((pos (1- (length dir)))
1652 (last-char (aref dir pos)))
1653 (if (and (> pos 0) (= last-char ?/))
1654 (setq dir (substring dir 0 pos)))
1655 (ediff-abbreviate-file-name (file-name-directory dir))))
1657 (defun ediff-truncate-string-left (str newlen)
1658 ;; leave space for ... on the left
1659 (let ((len (length str))
1660 substr)
1661 (if (<= len newlen)
1663 (setq newlen (max 0 (- newlen 3)))
1664 (setq substr (substring str (max 0 (- len 1 newlen))))
1665 (concat "..." substr))))
1667 (defsubst ediff-nonempty-string-p (string)
1668 (and (stringp string) (not (string= string ""))))
1670 (unless (fboundp 'subst-char-in-string)
1671 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1672 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1673 Unless optional argument INPLACE is non-nil, return a new string."
1674 (let ((i (length string))
1675 (newstr (if inplace string (copy-sequence string))))
1676 (while (> i 0)
1677 (setq i (1- i))
1678 (if (eq (aref newstr i) fromchar)
1679 (aset newstr i tochar)))
1680 newstr)))
1682 (defun ediff-abbrev-jobname (jobname)
1683 (cond ((eq jobname 'ediff-directories)
1684 "Compare two directories")
1685 ((eq jobname 'ediff-files)
1686 "Compare two files")
1687 ((eq jobname 'ediff-buffers)
1688 "Compare two buffers")
1689 ((eq jobname 'ediff-directories3)
1690 "Compare three directories")
1691 ((eq jobname 'ediff-files3)
1692 "Compare three files")
1693 ((eq jobname 'ediff-buffers3)
1694 "Compare three buffers")
1695 ((eq jobname 'ediff-revision)
1696 "Compare file with a version")
1697 ((eq jobname 'ediff-directory-revisions)
1698 "Compare dir files with versions")
1699 ((eq jobname 'ediff-merge-directory-revisions)
1700 "Merge dir files with versions")
1701 ((eq jobname 'ediff-merge-directory-revisions-with-ancestor)
1702 "Merge dir versions via ancestors")
1704 (capitalize
1705 (subst-char-in-string ?- ?\ (substring (symbol-name jobname) 6))))
1709 (defsubst ediff-get-region-contents (n buf-type ctrl-buf &optional start end)
1710 (ediff-with-current-buffer
1711 (ediff-with-current-buffer ctrl-buf (ediff-get-buffer buf-type))
1712 (buffer-substring
1713 (or start (ediff-get-diff-posn buf-type 'beg n ctrl-buf))
1714 (or end (ediff-get-diff-posn buf-type 'end n ctrl-buf)))))
1716 ;; If ediff modified mode line, strip the modification
1717 (defsubst ediff-strip-mode-line-format ()
1718 (if (member (car mode-line-format) '(" A: " " B: " " C: " " Ancestor: "))
1719 (setq mode-line-format (nth 2 mode-line-format))))
1721 ;; Verify that we have a difference selected.
1722 (defsubst ediff-valid-difference-p (&optional n)
1723 (or n (setq n ediff-current-difference))
1724 (and (>= n 0) (< n ediff-number-of-differences)))
1726 (defsubst ediff-show-all-diffs (n)
1727 "Don't skip difference regions."
1728 nil)
1730 (defsubst Xor (a b)
1731 (or (and a (not b)) (and (not a) b)))
1733 (defsubst ediff-message-if-verbose (string &rest args)
1734 (if ediff-verbose-p
1735 (apply 'message string args)))
1737 (defun ediff-file-attributes (filename attr-number)
1738 (if (ediff-file-remote-p filename)
1740 (nth attr-number (file-attributes filename))))
1742 (defsubst ediff-file-size (filename)
1743 (ediff-file-attributes filename 7))
1744 (defsubst ediff-file-modtime (filename)
1745 (ediff-file-attributes filename 5))
1748 (defun ediff-convert-standard-filename (fname)
1749 (if (fboundp 'convert-standard-filename)
1750 (convert-standard-filename fname)
1751 fname))
1754 ;;; Local Variables:
1755 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1756 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1757 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1758 ;;; End:
1760 (provide 'ediff-init)
1763 ;;; ediff-init.el ends here