Some fixes to follow coding conventions.
[emacs.git] / lisp / ediff-init.el
blob4594445a89fffc68bb23e830bc62871df9d5f964
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 ;;; Commentary:
26 ;;; Code:
28 ;; Start compiler pacifier
29 (defvar ediff-metajob-name)
30 (defvar ediff-meta-buffer)
31 (defvar pm-color-alist)
32 (defvar ediff-grab-mouse)
33 (defvar ediff-mouse-pixel-position)
34 (defvar ediff-mouse-pixel-threshold)
35 (defvar ediff-whitespace)
36 (defvar ediff-multiframe)
37 (defvar ediff-use-toolbar-p)
39 (and noninteractive
40 (eval-when-compile
41 (load "ange-ftp" 'noerror)))
42 ;; end pacifier
44 ;; Is it XEmacs?
45 (defconst ediff-xemacs-p (string-match "XEmacs" emacs-version))
46 ;; Is it Emacs?
47 (defconst ediff-emacs-p (not ediff-xemacs-p))
49 (defvar ediff-force-faces nil
50 "If t, Ediff will think that it is running on a display that supports faces.
51 This is provided as a temporary relief for users of face-capable displays
52 that Ediff doesn't know about.")
54 ;; Are we running as a window application or on a TTY?
55 (defsubst ediff-device-type ()
56 (if ediff-emacs-p
57 window-system
58 (device-type (selected-device))))
60 ;; in XEmacs: device-type is tty on tty and stream in batch.
61 (defun ediff-window-display-p ()
62 (and (ediff-device-type) (not (memq (ediff-device-type) '(tty pc stream)))))
64 ;; test if supports faces
65 (defun ediff-has-face-support-p ()
66 (cond ((ediff-window-display-p))
67 (ediff-force-faces)
68 ((ediff-color-display-p))
69 (ediff-emacs-p (memq (ediff-device-type) '(pc)))
70 (ediff-xemacs-p (memq (ediff-device-type) '(tty pc)))))
72 (defun ediff-has-toolbar-support-p ()
73 (and ediff-xemacs-p
74 (featurep 'toolbar)
75 (console-on-window-system-p)))
77 (defun ediff-use-toolbar-p ()
78 (and (ediff-has-toolbar-support-p) ;Can it do it ?
79 (boundp 'ediff-use-toolbar-p)
80 ediff-use-toolbar-p)) ;Does the user want it ?
82 ;; Defines SYMBOL as an advertised local variable.
83 ;; Performs a defvar, then executes `make-variable-buffer-local' on
84 ;; the variable. Also sets the `permanent-local' property,
85 ;; so that `kill-all-local-variables' (called by major-mode setting
86 ;; commands) won't destroy Ediff control variables.
88 ;; Plagiarised from `emerge-defvar-local' for XEmacs.
89 (defmacro ediff-defvar-local (var value doc)
90 `(progn
91 (defvar ,var ,value ,doc)
92 (make-variable-buffer-local ',var)
93 (put ',var 'permanent-local t)))
97 ;; Variables that control each Ediff session---local to the control buffer.
99 ;; Mode variables
100 ;; The buffer in which the A variant is stored.
101 (ediff-defvar-local ediff-buffer-A nil "")
102 ;; The buffer in which the B variant is stored.
103 (ediff-defvar-local ediff-buffer-B nil "")
104 ;; The buffer in which the C variant is stored or where the merge buffer lives.
105 (ediff-defvar-local ediff-buffer-C nil "")
106 ;; Ancestor buffer
107 (ediff-defvar-local ediff-ancestor-buffer nil "")
108 ;; The Ediff control buffer
109 (ediff-defvar-local ediff-control-buffer nil "")
112 ;; Association between buff-type and ediff-buffer-*
113 (defconst ediff-buffer-alist
114 '((?A . ediff-buffer-A)
115 (?B . ediff-buffer-B)
116 (?C . ediff-buffer-C)))
118 ;;; Macros
119 (defmacro ediff-odd-p (arg)
120 `(eq (logand ,arg 1) 1))
122 (defmacro ediff-buffer-live-p (buf)
123 `(and ,buf (get-buffer ,buf) (buffer-name (get-buffer ,buf))))
125 (defmacro ediff-get-buffer (arg)
126 `(cond ((eq ,arg 'A) ediff-buffer-A)
127 ((eq ,arg 'B) ediff-buffer-B)
128 ((eq ,arg 'C) ediff-buffer-C)
129 ((eq ,arg 'Ancestor) ediff-ancestor-buffer)
132 (defmacro ediff-get-value-according-to-buffer-type (buf-type list)
133 `(cond ((eq ,buf-type 'A) (nth 0 ,list))
134 ((eq ,buf-type 'B) (nth 1 ,list))
135 ((eq ,buf-type 'C) (nth 2 ,list))
138 (defmacro ediff-char-to-buftype (arg)
139 `(cond ((memq ,arg '(?a ?A)) 'A)
140 ((memq ,arg '(?b ?B)) 'B)
141 ((memq ,arg '(?c ?C)) 'C)
145 ;; A-list is supposed to be of the form (A . symb) (B . symb)...)
146 ;; where the first part of any association is a buffer type and the second is
147 ;; an appropriate symbol. Given buffer-type, this function returns the
148 ;; symbol. This is used to avoid using `intern'
149 (defsubst ediff-get-symbol-from-alist (buf-type alist)
150 (cdr (assoc buf-type alist)))
152 (defconst ediff-difference-vector-alist
153 '((A . ediff-difference-vector-A)
154 (B . ediff-difference-vector-B)
155 (C . ediff-difference-vector-C)
156 (Ancestor . ediff-difference-vector-Ancestor)))
158 (defmacro ediff-get-difference (n buf-type)
159 `(aref
160 (symbol-value
161 (ediff-get-symbol-from-alist
162 ,buf-type ediff-difference-vector-alist))
163 ,n))
165 ;; Tell if it has been previously determined that the region has
166 ;; no diffs other than the white space and newlines
167 ;; The argument, N, is the diff region number used by Ediff to index the
168 ;; diff vector. It is 1 less than the number seen by the user.
169 ;; Returns:
170 ;; t if the diffs are whitespace in all buffers
171 ;; 'A (in 3-buf comparison only) if there are only whitespace
172 ;; diffs in bufs B and C
173 ;; 'B (in 3-buf comparison only) if there are only whitespace
174 ;; diffs in bufs A and C
175 ;; 'C (in 3-buf comparison only) if there are only whitespace
176 ;; diffs in bufs A and B
178 ;; A Difference Vector has the form:
179 ;; [diff diff diff ...]
180 ;; where each diff has the form:
181 ;; [overlay fine-diff-vector no-fine-diffs-flag state-of-difference]
182 ;; fine-diff-vector is a vector [fine-diff fine-diff fine-diff ...]
183 ;; no-fine-diffs-flag says if there are fine differences.
184 ;; state-of-difference is A, B, C, or nil, indicating which buffer is
185 ;; different from the other two (used only in 3-way jobs).
186 (defmacro ediff-no-fine-diffs-p (n)
187 `(aref (ediff-get-difference ,n 'A) 2))
189 (defmacro ediff-get-diff-overlay-from-diff-record (diff-rec)
190 `(aref ,diff-rec 0))
192 (defmacro ediff-get-diff-overlay (n buf-type)
193 `(ediff-get-diff-overlay-from-diff-record
194 (ediff-get-difference ,n ,buf-type)))
196 (defmacro ediff-get-fine-diff-vector-from-diff-record (diff-rec)
197 `(aref ,diff-rec 1))
199 (defmacro ediff-set-fine-diff-vector (n buf-type fine-vec)
200 `(aset (ediff-get-difference ,n ,buf-type) 1 ,fine-vec))
202 (defmacro ediff-get-state-of-diff (n buf-type)
203 `(if (ediff-buffer-live-p ediff-buffer-C)
204 (aref (ediff-get-difference ,n ,buf-type) 3)))
205 (defmacro ediff-set-state-of-diff (n buf-type val)
206 `(aset (ediff-get-difference ,n ,buf-type) 3 ,val))
208 (defmacro ediff-get-state-of-merge (n)
209 `(if ediff-state-of-merge
210 (aref (aref ediff-state-of-merge ,n) 0)))
211 (defmacro ediff-set-state-of-merge (n val)
212 `(if ediff-state-of-merge
213 (aset (aref ediff-state-of-merge ,n) 0 ,val)))
215 (defmacro ediff-get-state-of-ancestor (n)
216 `(if ediff-state-of-merge
217 (aref (aref ediff-state-of-merge ,n) 1)))
219 ;; if flag is t, puts a mark on diff region saying that
220 ;; the differences are in white space only. If flag is nil,
221 ;; the region is marked as essential (i.e., differences are
222 ;; not just in the white space and newlines.)
223 (defmacro ediff-mark-diff-as-space-only (n flag)
224 `(aset (ediff-get-difference ,n 'A) 2 ,flag))
226 (defmacro ediff-get-fine-diff-vector (n buf-type)
227 `(ediff-get-fine-diff-vector-from-diff-record
228 (ediff-get-difference ,n ,buf-type)))
230 ;; Macro to switch to BUFFER, evaluate BODY, returns to original buffer.
231 ;; Doesn't save the point and mark.
232 ;; This is `with-current-buffer' with the added test for live buffers."
233 (defmacro ediff-with-current-buffer (buffer &rest body)
234 `(if (ediff-buffer-live-p ,buffer)
235 (save-current-buffer
236 (set-buffer ,buffer)
237 ,@body)
238 (or (eq this-command 'ediff-quit)
239 (error ediff-KILLED-VITAL-BUFFER))
243 (defsubst ediff-multiframe-setup-p ()
244 (and (ediff-window-display-p) ediff-multiframe))
246 (defmacro ediff-narrow-control-frame-p ()
247 `(and (ediff-multiframe-setup-p)
248 (equal ediff-help-message ediff-brief-message-string)))
250 (defmacro ediff-3way-comparison-job ()
251 `(memq
252 ediff-job-name
253 '(ediff-files3 ediff-buffers3)))
254 (ediff-defvar-local ediff-3way-comparison-job nil "")
256 (defmacro ediff-merge-job ()
257 `(memq
258 ediff-job-name
259 '(ediff-merge-files
260 ediff-merge-buffers
261 ediff-merge-files-with-ancestor
262 ediff-merge-buffers-with-ancestor
263 ediff-merge-revisions
264 ediff-merge-revisions-with-ancestor)))
265 (ediff-defvar-local ediff-merge-job nil "")
267 (defmacro ediff-merge-with-ancestor-job ()
268 `(memq
269 ediff-job-name
270 '(ediff-merge-files-with-ancestor
271 ediff-merge-buffers-with-ancestor
272 ediff-merge-revisions-with-ancestor)))
273 (ediff-defvar-local ediff-merge-with-ancestor-job nil "")
275 (defmacro ediff-3way-job ()
276 `(or ediff-3way-comparison-job ediff-merge-job))
277 (ediff-defvar-local ediff-3way-job nil "")
279 ;; A diff3 job is like a 3way job, but ediff-merge doesn't require the use
280 ;; of diff3.
281 (defmacro ediff-diff3-job ()
282 `(or ediff-3way-comparison-job
283 ediff-merge-with-ancestor-job))
284 (ediff-defvar-local ediff-diff3-job nil "")
286 (defmacro ediff-windows-job ()
287 `(memq ediff-job-name '(ediff-windows-wordwise ediff-windows-linewise)))
288 (ediff-defvar-local ediff-windows-job nil "")
290 (defmacro ediff-word-mode-job ()
291 `(memq ediff-job-name '(ediff-windows-wordwise ediff-regions-wordwise)))
292 (ediff-defvar-local ediff-word-mode-job nil "")
294 (defmacro ediff-narrow-job ()
295 `(memq ediff-job-name '(ediff-windows-wordwise
296 ediff-regions-wordwise
297 ediff-windows-linewise
298 ediff-regions-linewise)))
299 (ediff-defvar-local ediff-narrow-job nil "")
301 ;; Note: ediff-merge-directory-revisions-with-ancestor is not treated as an
302 ;; ancestor metajob, since it behaves differently.
303 (defsubst ediff-ancestor-metajob (&optional metajob)
304 (memq (or metajob ediff-metajob-name)
305 '(ediff-merge-directories-with-ancestor
306 ediff-merge-filegroups-with-ancestor)))
307 (defsubst ediff-revision-metajob (&optional metajob)
308 (memq (or metajob ediff-metajob-name)
309 '(ediff-directory-revisions
310 ediff-merge-directory-revisions
311 ediff-merge-directory-revisions-with-ancestor)))
312 (defsubst ediff-patch-metajob (&optional metajob)
313 (memq (or metajob ediff-metajob-name)
314 '(ediff-multifile-patch)))
315 ;; metajob involving only one group of files, such as multipatch or directory
316 ;; revision
317 (defsubst ediff-one-filegroup-metajob (&optional metajob)
318 (or (ediff-revision-metajob metajob)
319 (ediff-patch-metajob metajob)
320 ;; add more here
322 (defsubst ediff-collect-diffs-metajob (&optional metajob)
323 (memq (or metajob ediff-metajob-name)
324 '(ediff-directories
325 ediff-directory-revisions
326 ediff-merge-directories
327 ediff-merge-directories-with-ancestor
328 ediff-merge-directory-revisions
329 ediff-merge-directory-revisions-with-ancestor
330 ;; add more here
332 (defsubst ediff-merge-metajob (&optional metajob)
333 (memq (or metajob ediff-metajob-name)
334 '(ediff-merge-directories
335 ediff-merge-directories-with-ancestor
336 ediff-merge-directory-revisions
337 ediff-merge-directory-revisions-with-ancestor
338 ediff-merge-filegroups-with-ancestor
339 ;; add more here
342 (defsubst ediff-metajob3 (&optional metajob)
343 (memq (or metajob ediff-metajob-name)
344 '(ediff-merge-directories-with-ancestor
345 ediff-merge-filegroups-with-ancestor
346 ediff-directories3
347 ediff-filegroups3)))
348 (defsubst ediff-comparison-metajob3 (&optional metajob)
349 (memq (or metajob ediff-metajob-name)
350 '(ediff-directories3 ediff-filegroups3)))
352 ;; with no argument, checks if we are in ediff-control-buffer
353 ;; with argument, checks if we are in ediff-meta-buffer
354 (defun ediff-in-control-buffer-p (&optional meta-buf-p)
355 (and (boundp 'ediff-control-buffer)
356 (eq (if meta-buf-p ediff-meta-buffer ediff-control-buffer)
357 (current-buffer))))
359 (defsubst ediff-barf-if-not-control-buffer (&optional meta-buf-p)
360 (or (ediff-in-control-buffer-p meta-buf-p)
361 (error "%S: This command runs in Ediff Control Buffer only!"
362 this-command)))
364 (defgroup ediff-highlighting nil
365 "Hilighting of difference regions in Ediff"
366 :prefix "ediff-"
367 :group 'ediff)
369 (defgroup ediff-merge nil
370 "Merging utilities"
371 :prefix "ediff-"
372 :group 'ediff)
374 (defgroup ediff-hook nil
375 "Hooks run by Ediff"
376 :prefix "ediff-"
377 :group 'ediff)
379 ;; Hook variables
381 (defcustom ediff-before-setup-hook nil
382 "*Hooks to run before Ediff begins to set up windows and buffers.
383 This hook can be used to save the previous window config, which can be restored
384 on ediff-quit or ediff-suspend."
385 :type 'hook
386 :group 'ediff-hook)
387 (defcustom ediff-before-setup-windows-hook nil
388 "*Hooks to run before Ediff sets its window configuration.
389 This hook is run every time when Ediff arranges its windows.
390 This happens each time Ediff detects that the windows were messed up by the
391 user."
392 :type 'hook
393 :group 'ediff-hook)
394 (defcustom ediff-after-setup-windows-hook nil
395 "*Hooks to run after Ediff sets its window configuration.
396 This can be used to set up control window or icon in a desired place."
397 :type 'hook
398 :group 'ediff-hook)
399 (defcustom ediff-before-setup-control-frame-hook nil
400 "*Hooks run before setting up the frame to display Ediff Control Panel.
401 Can be used to change control frame parameters to position it where it
402 is desirable."
403 :type 'hook
404 :group 'ediff-hook)
405 (defcustom ediff-after-setup-control-frame-hook nil
406 "*Hooks run after setting up the frame to display Ediff Control Panel.
407 Can be used to move the frame where it is desired."
408 :type 'hook
409 :group 'ediff-hook)
410 (defcustom ediff-startup-hook nil
411 "*Hooks to run in the control buffer after Ediff has been set up and is ready for the job."
412 :type 'hook
413 :group 'ediff-hook)
414 (defcustom ediff-select-hook nil
415 "*Hooks to run after a difference has been selected."
416 :type 'hook
417 :group 'ediff-hook)
418 (defcustom ediff-unselect-hook nil
419 "*Hooks to run after a difference has been unselected."
420 :type 'hook
421 :group 'ediff-hook)
422 (defcustom ediff-prepare-buffer-hook nil
423 "*Hooks run after buffers A, B, and C are set up.
424 For each buffer, the hooks are run with that buffer made current."
425 :type 'hook
426 :group 'ediff-hook)
427 (defcustom ediff-load-hook nil
428 "*Hook run after Ediff is loaded. Can be used to change defaults."
429 :type 'hook
430 :group 'ediff-hook)
432 (defcustom ediff-mode-hook nil
433 "*Hook run just after ediff-mode is set up in the control buffer.
434 This is done before any windows or frames are created. One can use it to
435 set local variables that determine how the display looks like."
436 :type 'hook
437 :group 'ediff-hook)
438 (defcustom ediff-keymap-setup-hook nil
439 "*Hook run just after the default bindings in Ediff keymap are set up."
440 :type 'hook
441 :group 'ediff-hook)
443 (defcustom ediff-display-help-hook nil
444 "*Hooks run after preparing the help message."
445 :type 'hook
446 :group 'ediff-hook)
448 (defcustom ediff-suspend-hook nil
449 "*Hooks to run in the Ediff control buffer when Ediff is suspended."
450 :type 'hook
451 :group 'ediff-hook)
452 (defcustom ediff-quit-hook nil
453 "*Hooks to run in the Ediff control buffer after finishing Ediff."
454 :type 'hook
455 :group 'ediff-hook)
456 (defcustom ediff-cleanup-hook nil
457 "*Hooks to run on exiting Ediff but before killing the control and variant buffers."
458 :type 'hook
459 :group 'ediff-hook)
461 ;; Error messages
462 (defconst ediff-KILLED-VITAL-BUFFER
463 "You have killed a vital Ediff buffer---you must leave Ediff now!")
464 (defconst ediff-NO-DIFFERENCES
465 "Sorry, comparison of identical variants is not what I am made for...")
466 (defconst ediff-BAD-DIFF-NUMBER
467 ;; %S stands for this-command, %d - diff number, %d - max diff
468 "%S: Bad diff region number, %d. Valid numbers are 1 to %d")
469 (defconst ediff-BAD-INFO (format "
470 *** The Info file for Ediff, a part of the standard distribution
471 *** of %sEmacs, does not seem to be properly installed.
473 *** Please contact your system administrator. "
474 (if ediff-xemacs-p "X" "")))
476 ;; Selective browsing
478 (ediff-defvar-local ediff-skip-diff-region-function 'ediff-show-all-diffs
479 "Function that determines the next/previous diff region to show.
480 Should return t for regions to be ignored and nil otherwise.
481 This function gets a region number as an argument. The region number
482 is the one used internally by Ediff. It is 1 less than the number seen
483 by the user.")
485 (ediff-defvar-local ediff-hide-regexp-matches-function
486 'ediff-hide-regexp-matches
487 "Function to use in determining which regions to hide.
488 See the documentation string of `ediff-hide-regexp-matches' for details.")
489 (ediff-defvar-local ediff-focus-on-regexp-matches-function
490 'ediff-focus-on-regexp-matches
491 "Function to use in determining which regions to focus on.
492 See the documentation string of `ediff-focus-on-regexp-matches' for details.")
494 ;; Regexp that determines buf A regions to focus on when skipping to diff
495 (ediff-defvar-local ediff-regexp-focus-A "" "")
496 ;; Regexp that determines buf B regions to focus on when skipping to diff
497 (ediff-defvar-local ediff-regexp-focus-B "" "")
498 ;; Regexp that determines buf C regions to focus on when skipping to diff
499 (ediff-defvar-local ediff-regexp-focus-C "" "")
500 ;; connective that determines whether to focus regions that match both or
501 ;; one of the regexps
502 (ediff-defvar-local ediff-focus-regexp-connective 'and "")
504 ;; Regexp that determines buf A regions to ignore when skipping to diff
505 (ediff-defvar-local ediff-regexp-hide-A "" "")
506 ;; Regexp that determines buf B regions to ignore when skipping to diff
507 (ediff-defvar-local ediff-regexp-hide-B "" "")
508 ;; Regexp that determines buf C regions to ignore when skipping to diff
509 (ediff-defvar-local ediff-regexp-hide-C "" "")
510 ;; connective that determines whether to hide regions that match both or
511 ;; one of the regexps
512 (ediff-defvar-local ediff-hide-regexp-connective 'and "")
515 ;;; Copying difference regions between buffers.
517 ;; A list of killed diffs.
518 ;; A diff is saved here if it is replaced by a diff
519 ;; from another buffer. This alist has the form:
520 ;; \((num (buff-object . diff) (buff-object . diff) (buff-object . diff)) ...),
521 ;; where some buffer-objects may be missing.
522 (ediff-defvar-local ediff-killed-diffs-alist nil "")
524 ;; Syntax table to use in ediff-forward-word-function
525 ;; This is chosen by a heuristic. The important thing is for all buffers to
526 ;; have the same syntax table. Which is not too important.
527 (ediff-defvar-local ediff-syntax-table nil "")
530 ;; Highlighting
531 (defcustom ediff-before-flag-bol (if ediff-xemacs-p (make-glyph "->>") "->>")
532 "*Flag placed before a highlighted block of differences, if block starts at beginning of a line."
533 :type 'string
534 :tag "Region before-flag at beginning of line"
535 :group 'ediff)
537 (defcustom ediff-after-flag-eol (if ediff-xemacs-p (make-glyph "<<-") "<<-")
538 "*Flag placed after a highlighted block of differences, if block ends at end of a line."
539 :type 'string
540 :tag "Region after-flag at end of line"
541 :group 'ediff)
543 (defcustom ediff-before-flag-mol (if ediff-xemacs-p (make-glyph "->>") "->>")
544 "*Flag placed before a highlighted block of differences, if block starts in mid-line."
545 :type 'string
546 :tag "Region before-flag in the middle of line"
547 :group 'ediff)
548 (defcustom ediff-after-flag-mol (if ediff-xemacs-p (make-glyph "<<-") "<<-")
549 "*Flag placed after a highlighted block of differences, if block ends in mid-line."
550 :type 'string
551 :tag "Region after-flag in the middle of line"
552 :group 'ediff)
555 (ediff-defvar-local ediff-use-faces t "")
556 (defcustom ediff-use-faces t
557 "If t, differences are highlighted using faces, if device supports faces.
558 If nil, differences are highlighted using ASCII flags, ediff-before-flag
559 and ediff-after-flag. On a non-window system, differences are always
560 highlighted using ASCII flags."
561 :type 'boolean
562 :group 'ediff-highlighting)
564 ;; this indicates that diff regions are word-size, so fine diffs are
565 ;; permanently nixed; used in ediff-windows-wordwise and ediff-regions-wordwise
566 (ediff-defvar-local ediff-word-mode nil "")
567 ;; Name of the job (ediff-files, ediff-windows, etc.)
568 (ediff-defvar-local ediff-job-name nil "")
570 ;; Narrowing and ediff-region/windows support
571 ;; This is a list (overlay-A overlay-B overlay-C)
572 ;; If set, Ediff compares only those parts of buffers A/B/C that lie within
573 ;; the bounds of these overlays.
574 (ediff-defvar-local ediff-narrow-bounds nil "")
576 ;; List (overlay-A overlay-B overlay-C), where each overlay spans the
577 ;; entire corresponding buffer.
578 (ediff-defvar-local ediff-wide-bounds nil "")
580 ;; Current visibility boundaries in buffers A, B, and C.
581 ;; This is also a list of overlays. When the user toggles narrow/widen,
582 ;; this list changes from ediff-wide-bounds to ediff-narrow-bounds.
583 ;; and back.
584 (ediff-defvar-local ediff-visible-bounds nil "")
586 (ediff-defvar-local ediff-start-narrowed t
587 "Non-nil means start narrowed, if doing ediff-windows-* or ediff-regions-*")
588 (ediff-defvar-local ediff-quit-widened t
589 "*Non-nil means: when finished, Ediff widens buffers A/B.
590 Actually, Ediff restores the scope of visibility that existed at startup.")
592 (defcustom ediff-keep-variants t
593 "*Nil means that non-modified variant buffers should be removed at the end of the session after some interrogation.
594 Supplying a prefix argument to the quit command `q' temporarily reverses the
595 meaning of this variable."
596 :type 'boolean
597 :group 'ediff)
599 (ediff-defvar-local ediff-highlight-all-diffs t "")
600 (defcustom ediff-highlight-all-diffs t
601 "If nil, only the selected differences are highlighted.
602 Otherwise, all difference regions are highlighted, but the selected region is
603 shown in brighter colors."
604 :type 'boolean
605 :group 'ediff-highlighting)
607 ;; A var local to each control panel buffer. Indicates highlighting style
608 ;; in effect for this buffer: `face', `ascii', nil -- temporarily
609 ;; unhighlighted, `off' -- turned off \(on a dumb terminal only\).
610 (ediff-defvar-local ediff-highlighting-style nil "")
613 ;; The suffix of the control buffer name.
614 (ediff-defvar-local ediff-control-buffer-suffix nil "")
615 ;; Same as ediff-control-buffer-suffix, but without <,>.
616 ;; It's a number rather than string.
617 (ediff-defvar-local ediff-control-buffer-number nil "")
620 ;; The original values of ediff-protected-variables for buffer A
621 (ediff-defvar-local ediff-buffer-values-orig-A nil "")
622 ;; The original values of ediff-protected-variables for buffer B
623 (ediff-defvar-local ediff-buffer-values-orig-B nil "")
624 ;; The original values of ediff-protected-variables for buffer C
625 (ediff-defvar-local ediff-buffer-values-orig-C nil "")
626 ;; The original values of ediff-protected-variables for buffer Ancestor
627 (ediff-defvar-local ediff-buffer-values-orig-Ancestor nil "")
629 ;; association between buff-type and ediff-buffer-values-orig-*
630 (defconst ediff-buffer-values-orig-alist
631 '((A . ediff-buffer-values-orig-A)
632 (B . ediff-buffer-values-orig-B)
633 (C . ediff-buffer-values-orig-C)
634 (Ancestor . ediff-buffer-values-orig-Ancestor)))
636 ;; Buffer-local variables to be saved then restored during Ediff sessions
637 (defconst ediff-protected-variables '(
638 ;;buffer-read-only
639 mode-line-format))
641 ;; Vector of differences between the variants. Each difference is
642 ;; represented by a vector of two overlays plus a vector of fine diffs,
643 ;; plus a no-fine-diffs flag. The first overlay spans the
644 ;; difference region in the A buffer and the second overlays the diff in
645 ;; the B buffer. If a difference section is empty, the corresponding
646 ;; overlay's endpoints coincide.
648 ;; The precise form of a Difference Vector for one buffer is:
649 ;; [diff diff diff ...]
650 ;; where each diff has the form:
651 ;; [diff-overlay fine-diff-vector no-fine-diffs-flag state-of-diff]
652 ;; fine-diff-vector is a vector [fine-diff-overlay fine-diff-overlay ...]
653 ;; no-fine-diffs-flag says if there are fine differences.
654 ;; state-of-difference is A, B, C, or nil, indicating which buffer is
655 ;; different from the other two (used only in 3-way jobs.
656 (ediff-defvar-local ediff-difference-vector-A nil "")
657 (ediff-defvar-local ediff-difference-vector-B nil "")
658 (ediff-defvar-local ediff-difference-vector-C nil "")
659 (ediff-defvar-local ediff-difference-vector-Ancestor nil "")
660 ;; A-list of diff vector types associated with buffer types
661 (defconst ediff-difference-vector-alist
662 '((A . ediff-difference-vector-A)
663 (B . ediff-difference-vector-B)
664 (C . ediff-difference-vector-C)
665 (Ancestor . ediff-difference-vector-Ancestor)))
667 ;; [ status status status ...]
668 ;; Each status: [state-of-merge state-of-ancestor]
669 ;; state-of-merge is default-A, default-B, prefer-A, or prefer-B. It
670 ;; indicates the way a diff region was created in buffer C.
671 ;; state-of-ancestor says if the corresponding region in ancestor buffer is
672 ;; empty.
673 (ediff-defvar-local ediff-state-of-merge nil "")
675 ;; The difference that is currently selected.
676 (ediff-defvar-local ediff-current-difference -1 "")
677 ;; Number of differences found.
678 (ediff-defvar-local ediff-number-of-differences nil "")
680 ;; Buffer containing the output of diff, which is used by Ediff to step
681 ;; through files.
682 (ediff-defvar-local ediff-diff-buffer nil "")
683 ;; Like ediff-diff-buffer, but contains context diff. It is not used by
684 ;; Ediff, but it is saved in a file, if user requests so.
685 (ediff-defvar-local ediff-custom-diff-buffer nil "")
686 ;; Buffer used for diff-style fine differences between regions.
687 (ediff-defvar-local ediff-fine-diff-buffer nil "")
688 ;; Temporary buffer used for computing fine differences.
689 (defconst ediff-tmp-buffer " *ediff-tmp*" "")
690 ;; Buffer used for messages
691 (defconst ediff-msg-buffer " *ediff-message*" "")
692 ;; Buffer containing the output of diff when diff returns errors.
693 (ediff-defvar-local ediff-error-buffer nil "")
694 ;; Buffer to display debug info
695 (ediff-defvar-local ediff-debug-buffer "*ediff-debug*" "")
697 ;; List of ediff control panels associated with each buffer A/B/C/Ancestor.
698 ;; Not used any more, but may be needed in the future.
699 (ediff-defvar-local ediff-this-buffer-ediff-sessions nil "")
701 ;; to be deleted in due time
702 ;; List of difference overlays disturbed by working with the current diff.
703 (defvar ediff-disturbed-overlays nil "")
705 ;; Priority of non-selected overlays.
706 (defvar ediff-shadow-overlay-priority 100 "")
708 (defcustom ediff-version-control-package 'vc
709 "Version control package used.
710 Currently, Ediff supports vc.el, rcs.el, pcl-cvs.el, and generic-sc.el. The
711 standard Emacs interface to RCS, CVS, SCCS, etc., is vc.el. However, some
712 people find the other two packages more convenient. Set this variable to the
713 appropriate symbol: `rcs', `pcl-cvs', or `generic-sc' if you so desire."
714 :type 'symbol
715 :group 'ediff)
718 (if ediff-xemacs-p
719 (progn
720 (fset 'ediff-read-event (symbol-function 'next-command-event))
721 (fset 'ediff-overlayp (symbol-function 'extentp))
722 (fset 'ediff-make-overlay (symbol-function 'make-extent))
723 (fset 'ediff-delete-overlay (symbol-function 'delete-extent)))
724 (fset 'ediff-read-event (symbol-function 'read-event))
725 (fset 'ediff-overlayp (symbol-function 'overlayp))
726 (fset 'ediff-make-overlay (symbol-function 'make-overlay))
727 (fset 'ediff-delete-overlay (symbol-function 'delete-overlay)))
729 ;; Check the current version against the major and minor version numbers
730 ;; using op: cur-vers op major.minor If emacs-major-version or
731 ;; emacs-minor-version are not defined, we assume that the current version
732 ;; is hopelessly outdated. We assume that emacs-major-version and
733 ;; emacs-minor-version are defined. Otherwise, for Emacs/XEmacs 19, if the
734 ;; current minor version is < 10 (xemacs) or < 23 (emacs) the return value
735 ;; will be nil (when op is =, >, or >=) and t (when op is <, <=), which may be
736 ;; incorrect. However, this gives correct result in our cases, since we are
737 ;; testing for sufficiently high Emacs versions.
738 (defun ediff-check-version (op major minor &optional type-of-emacs)
739 (if (and (boundp 'emacs-major-version) (boundp 'emacs-minor-version))
740 (and (cond ((eq type-of-emacs 'xemacs) ediff-xemacs-p)
741 ((eq type-of-emacs 'emacs) ediff-emacs-p)
742 (t t))
743 (cond ((eq op '=) (and (= emacs-minor-version minor)
744 (= emacs-major-version major)))
745 ((memq op '(> >= < <=))
746 (and (or (funcall op emacs-major-version major)
747 (= emacs-major-version major))
748 (if (= emacs-major-version major)
749 (funcall op emacs-minor-version minor)
750 t)))
752 (error "%S: Invalid op in ediff-check-version" op))))
753 (cond ((memq op '(= > >=)) nil)
754 ((memq op '(< <=)) t))))
757 (defun ediff-color-display-p ()
758 (condition-case nil
759 (if ediff-emacs-p
760 (if (fboundp 'display-color-p)
761 (display-color-p)
762 (x-display-color-p))
763 (eq (device-class (selected-device)) 'color))
764 (error
765 nil)))
768 (if (ediff-has-face-support-p)
769 (if ediff-xemacs-p
770 (progn
771 (fset 'ediff-valid-color-p (symbol-function 'valid-color-name-p))
772 (fset 'ediff-get-face (symbol-function 'get-face)))
773 (fset 'ediff-valid-color-p (symbol-function
774 (if (fboundp 'color-defined-p)
775 'color-defined-p
776 'x-color-defined-p)))
777 (fset 'ediff-get-face (symbol-function 'internal-get-face))))
779 (if (ediff-window-display-p)
780 (if ediff-xemacs-p
781 (progn
782 (fset 'ediff-display-pixel-width
783 (symbol-function 'device-pixel-width))
784 (fset 'ediff-display-pixel-height
785 (symbol-function 'device-pixel-height)))
786 (fset 'ediff-display-pixel-width (symbol-function
787 (if (fboundp 'display-pixel-width)
788 'display-pixel-width
789 'x-display-pixel-width)))
790 (fset 'ediff-display-pixel-height (symbol-function
791 (if (fboundp 'display-pixel-height)
792 'display-pixel-height
793 'x-display-pixel-height)))))
795 ;; A-list of current-diff-overlay symbols associated with buf types
796 (defconst ediff-current-diff-overlay-alist
797 '((A . ediff-current-diff-overlay-A)
798 (B . ediff-current-diff-overlay-B)
799 (C . ediff-current-diff-overlay-C)
800 (Ancestor . ediff-current-diff-overlay-Ancestor)))
802 ;; A-list of current-diff-face-* symbols associated with buf types
803 (defconst ediff-current-diff-face-alist
804 '((A . ediff-current-diff-face-A)
805 (B . ediff-current-diff-face-B)
806 (C . ediff-current-diff-face-C)
807 (Ancestor . ediff-current-diff-face-Ancestor)))
810 (defun ediff-make-current-diff-overlay (type)
811 (if (ediff-has-face-support-p)
812 (let ((overlay (ediff-get-symbol-from-alist
813 type ediff-current-diff-overlay-alist))
814 (buffer (ediff-get-buffer type))
815 (face (face-name
816 (symbol-value
817 (ediff-get-symbol-from-alist
818 type ediff-current-diff-face-alist)))))
819 (set overlay
820 (ediff-make-bullet-proof-overlay (point-max) (point-max) buffer))
821 (ediff-set-overlay-face (symbol-value overlay) face)
822 (ediff-overlay-put (symbol-value overlay) 'ediff ediff-control-buffer))
825 (defun ediff-set-overlay-face (extent face)
826 (ediff-overlay-put extent 'face face)
827 (ediff-overlay-put extent 'help-echo 'ediff-region-help-echo))
829 (defun ediff-region-help-echo (extent-or-window &optional overlay point)
830 (unless overlay
831 (setq overlay extent-or-window))
832 (let ((is-current (ediff-overlay-get overlay 'ediff))
833 (face (ediff-overlay-get overlay 'face))
834 (diff-num (ediff-overlay-get overlay 'ediff-diff-num))
835 face-help)
837 ;; This happens only for refinement overlays
838 (if (stringp face)
839 (setq face (intern face)))
840 (setq face-help (and face (get face 'ediff-help-echo)))
842 (cond ((and is-current diff-num) ; current diff region
843 (format "Difference region %S -- current" (1+ diff-num)))
844 (face-help) ; refinement of current diff region
845 (diff-num ; non-current
846 (format "Difference region %S -- non-current" (1+ diff-num)))
847 (t "")) ; none
851 (defun ediff-set-face-pixmap (face pixmap)
852 "Set face pixmap on a monochrome display."
853 (if (and (ediff-window-display-p) (not (ediff-color-display-p)))
854 (condition-case nil
855 (set-face-background-pixmap face pixmap)
856 (error
857 (message "Pixmap not found for %S: %s" (face-name face) pixmap)
858 (sit-for 1)))))
860 (defun ediff-hide-face (face)
861 (if (and (ediff-has-face-support-p) ediff-emacs-p)
862 (add-to-list 'facemenu-unlisted-faces face)))
866 (defface ediff-current-diff-face-A
867 '((((class color)) (:foreground "firebrick" :background "pale green"))
868 (t (:inverse-video t)))
869 "Face for highlighting the selected difference in buffer A."
870 :group 'ediff-highlighting)
871 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
872 ;; this variable is set to nil, then again to the appropriate face.
873 (defvar ediff-current-diff-face-A 'ediff-current-diff-face-A
874 "Face for highlighting the selected difference in buffer A.
875 DO NOT CHANGE this variable. Instead, use the customization
876 widget to customize the actual face object `ediff-current-diff-face-A'
877 this variable represents.")
878 (ediff-hide-face 'ediff-current-diff-face-A)
879 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
880 ;; This means that some user customization may be trashed.
881 (if (and ediff-xemacs-p
882 (ediff-has-face-support-p)
883 (not (ediff-color-display-p)))
884 (copy-face 'modeline 'ediff-current-diff-face-A))
888 (defface ediff-current-diff-face-B
889 '((((class color)) (:foreground "DarkOrchid" :background "Yellow"))
890 (t (:inverse-video t)))
891 "Face for highlighting the selected difference in buffer B."
892 :group 'ediff-highlighting)
893 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
894 ;; this variable is set to nil, then again to the appropriate face.
895 (defvar ediff-current-diff-face-B 'ediff-current-diff-face-B
896 "Face for highlighting the selected difference in buffer B.
897 this variable. Instead, use the customization
898 widget to customize the actual face `ediff-current-diff-face-B'
899 this variable represents.")
900 (ediff-hide-face 'ediff-current-diff-face-B)
901 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
902 ;; This means that some user customization may be trashed.
903 (if (and ediff-xemacs-p
904 (ediff-has-face-support-p)
905 (not (ediff-color-display-p)))
906 (copy-face 'modeline 'ediff-current-diff-face-B))
909 (defface ediff-current-diff-face-C
910 '((((class color)) (:foreground "Navy" :background "Pink"))
911 (t (:inverse-video t)))
912 "Face for highlighting the selected difference in buffer C."
913 :group 'ediff-highlighting)
914 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
915 ;; this variable is set to nil, then again to the appropriate face.
916 (defvar ediff-current-diff-face-C 'ediff-current-diff-face-C
917 "Face for highlighting the selected difference in buffer C.
918 DO NOT CHANGE this variable. Instead, use the customization
919 widget to customize the actual face object `ediff-current-diff-face-C'
920 this variable represents.")
921 (ediff-hide-face 'ediff-current-diff-face-C)
922 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
923 ;; This means that some user customization may be trashed.
924 (if (and ediff-xemacs-p
925 (ediff-has-face-support-p)
926 (not (ediff-color-display-p)))
927 (copy-face 'modeline 'ediff-current-diff-face-C))
930 (defface ediff-current-diff-face-Ancestor
931 '((((class color)) (:foreground "Black" :background "VioletRed"))
932 (t (:inverse-video t)))
933 "Face for highlighting the selected difference in buffer Ancestor."
934 :group 'ediff-highlighting)
935 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
936 ;; this variable is set to nil, then again to the appropriate face.
937 (defvar ediff-current-diff-face-Ancestor 'ediff-current-diff-face-Ancestor
938 "Face for highlighting the selected difference in buffer Ancestor.
939 DO NOT CHANGE this variable. Instead, use the customization
940 widget to customize the actual face object `ediff-current-diff-face-Ancestor'
941 this variable represents.")
942 (ediff-hide-face 'ediff-current-diff-face-Ancestor)
943 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
944 ;; This means that some user customization may be trashed.
945 (if (and ediff-xemacs-p
946 (ediff-has-face-support-p)
947 (not (ediff-color-display-p)))
948 (copy-face 'modeline 'ediff-current-diff-face-Ancestor))
951 (defface ediff-fine-diff-face-A
952 '((((class color)) (:foreground "Navy" :background "sky blue"))
953 (t (:underline t :stipple "gray3")))
954 "Face for highlighting the refinement of the selected diff in buffer A."
955 :group 'ediff-highlighting)
956 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
957 ;; this variable is set to nil, then again to the appropriate face.
958 (defvar ediff-fine-diff-face-A 'ediff-fine-diff-face-A
959 "Face for highlighting the fine differences in buffer A.
960 DO NOT CHANGE this variable. Instead, use the customization
961 widget to customize the actual face object `ediff-fine-diff-face-A'
962 this variable represents.")
963 (ediff-hide-face 'ediff-fine-diff-face-A)
965 (defface ediff-fine-diff-face-B
966 '((((class color)) (:foreground "Black" :background "cyan"))
967 (t (:underline t :stipple "gray3")))
968 "Face for highlighting the refinement of the selected diff in buffer B."
969 :group 'ediff-highlighting)
970 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
971 ;; this variable is set to nil, then again to the appropriate face.
972 (defvar ediff-fine-diff-face-B 'ediff-fine-diff-face-B
973 "Face for highlighting the fine differences in buffer B.
974 DO NOT CHANGE this variable. Instead, use the customization
975 widget to customize the actual face object `ediff-fine-diff-face-B'
976 this variable represents.")
977 (ediff-hide-face 'ediff-fine-diff-face-B)
979 (defface ediff-fine-diff-face-C
980 '((((class color)) (:foreground "Black" :background "Turquoise"))
981 (t (:underline t :stipple "gray3")))
982 "Face for highlighting the refinement of the selected diff in buffer C."
983 :group 'ediff-highlighting)
984 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
985 ;; this variable is set to nil, then again to the appropriate face.
986 (defvar ediff-fine-diff-face-C 'ediff-fine-diff-face-C
987 "Face for highlighting the fine differences in buffer C.
988 DO NOT CHANGE this variable. Instead, use the customization
989 widget to customize the actual face object `ediff-fine-diff-face-C'
990 this variable represents.")
991 (ediff-hide-face 'ediff-fine-diff-face-C)
993 (defface ediff-fine-diff-face-Ancestor
994 '((((class color)) (:foreground "Black" :background "Green"))
995 (t (:underline t :stipple "gray3")))
996 "Face for highlighting the refinement of the selected diff in the ancestor buffer.
997 At present, this face is not used and no fine differences are computed for the
998 ancestor buffer."
999 :group 'ediff-highlighting)
1000 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1001 ;; this variable is set to nil, then again to the appropriate face.
1002 (defvar ediff-fine-diff-face-Ancestor 'ediff-fine-diff-face-Ancestor
1003 "Face for highlighting the fine differences in buffer Ancestor.
1004 DO NOT CHANGE this variable. Instead, use the customization
1005 widget to customize the actual face object `ediff-fine-diff-face-Ancestor'
1006 this variable represents.")
1007 (ediff-hide-face 'ediff-fine-diff-face-Ancestor)
1009 ;; Some installs don't have stipple or Stipple. So, try them in turn.
1010 (defvar stipple-pixmap
1011 (cond ((not (ediff-has-face-support-p)) nil)
1012 ((and (boundp 'x-bitmap-file-path)
1013 (locate-library "stipple" t x-bitmap-file-path)) "stipple")
1014 ((and (boundp 'mswindowsx-bitmap-file-path)
1015 (locate-library "stipple" t mswindowsx-bitmap-file-path)) "stipple")
1016 (t "Stipple")))
1018 (defface ediff-even-diff-face-A
1019 `((((class color)) (:foreground "Black" :background "light grey"))
1020 (t (:italic t :stipple ,stipple-pixmap)))
1021 "Face for highlighting even-numbered non-current differences in buffer A."
1022 :group 'ediff-highlighting)
1023 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1024 ;; this variable is set to nil, then again to the appropriate face.
1025 (defvar ediff-even-diff-face-A 'ediff-even-diff-face-A
1026 "Face for highlighting even-numbered non-current differences in buffer A.
1027 DO NOT CHANGE this variable. Instead, use the customization
1028 widget to customize the actual face object `ediff-even-diff-face-A'
1029 this variable represents.")
1030 (ediff-hide-face 'ediff-even-diff-face-A)
1032 (defface ediff-even-diff-face-B
1033 `((((class color)) (:foreground "White" :background "Grey"))
1034 (t (:italic t :stipple ,stipple-pixmap)))
1035 "Face for highlighting even-numbered non-current differences in buffer B."
1036 :group 'ediff-highlighting)
1037 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1038 ;; this variable is set to nil, then again to the appropriate face.
1039 (defvar ediff-even-diff-face-B 'ediff-even-diff-face-B
1040 "Face for highlighting even-numbered non-current differences in buffer B.
1041 DO NOT CHANGE this variable. Instead, use the customization
1042 widget to customize the actual face object `ediff-even-diff-face-B'
1043 this variable represents.")
1044 (ediff-hide-face 'ediff-even-diff-face-B)
1046 (defface ediff-even-diff-face-C
1047 `((((class color)) (:foreground "Black" :background "light grey"))
1048 (t (:italic t :stipple ,stipple-pixmap)))
1049 "Face for highlighting even-numbered non-current differences in buffer C."
1050 :group 'ediff-highlighting)
1051 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1052 ;; this variable is set to nil, then again to the appropriate face.
1053 (defvar ediff-even-diff-face-C 'ediff-even-diff-face-C
1054 "Face for highlighting even-numbered non-current differences in buffer C.
1055 DO NOT CHANGE this variable. Instead, use the customization
1056 widget to customize the actual face object `ediff-even-diff-face-C'
1057 this variable represents.")
1058 (ediff-hide-face 'ediff-even-diff-face-C)
1060 (defface ediff-even-diff-face-Ancestor
1061 `((((class color)) (:foreground "White" :background "Grey"))
1062 (t (:italic t :stipple ,stipple-pixmap)))
1063 "Face for highlighting even-numbered non-current differences in the ancestor buffer."
1064 :group 'ediff-highlighting)
1065 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1066 ;; this variable is set to nil, then again to the appropriate face.
1067 (defvar ediff-even-diff-face-Ancestor 'ediff-even-diff-face-Ancestor
1068 "Face for highlighting even-numbered non-current differences in buffer Ancestor.
1069 DO NOT CHANGE this variable. Instead, use the customization
1070 widget to customize the actual face object `ediff-even-diff-face-Ancestor'
1071 this variable represents.")
1072 (ediff-hide-face 'ediff-even-diff-face-Ancestor)
1074 ;; Association between buffer types and even-diff-face symbols
1075 (defconst ediff-even-diff-face-alist
1076 '((A . ediff-even-diff-face-A)
1077 (B . ediff-even-diff-face-B)
1078 (C . ediff-even-diff-face-C)
1079 (Ancestor . ediff-even-diff-face-Ancestor)))
1081 (defface ediff-odd-diff-face-A
1082 '((((class color)) (:foreground "White" :background "Grey"))
1083 (t (:italic t :stipple "gray1")))
1084 "Face for highlighting odd-numbered non-current differences in buffer A."
1085 :group 'ediff-highlighting)
1086 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1087 ;; this variable is set to nil, then again to the appropriate face.
1088 (defvar ediff-odd-diff-face-A 'ediff-odd-diff-face-A
1089 "Face for highlighting odd-numbered non-current differences in buffer A.
1090 DO NOT CHANGE this variable. Instead, use the customization
1091 widget to customize the actual face object `ediff-odd-diff-face-A'
1092 this variable represents.")
1093 (ediff-hide-face 'ediff-odd-diff-face-A)
1096 (defface ediff-odd-diff-face-B
1097 '((((class color)) (:foreground "Black" :background "light grey"))
1098 (t (:italic t :stipple "gray1")))
1099 "Face for highlighting odd-numbered non-current differences in buffer B."
1100 :group 'ediff-highlighting)
1101 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1102 ;; this variable is set to nil, then again to the appropriate face.
1103 (defvar ediff-odd-diff-face-B 'ediff-odd-diff-face-B
1104 "Face for highlighting odd-numbered non-current differences in buffer B.
1105 DO NOT CHANGE this variable. Instead, use the customization
1106 widget to customize the actual face object `ediff-odd-diff-face-B'
1107 this variable represents.")
1108 (ediff-hide-face 'ediff-odd-diff-face-B)
1110 (defface ediff-odd-diff-face-C
1111 '((((class color)) (:foreground "White" :background "Grey"))
1112 (t (:italic t :stipple "gray1")))
1113 "Face for highlighting odd-numbered non-current differences in buffer C."
1114 :group 'ediff-highlighting)
1115 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1116 ;; this variable is set to nil, then again to the appropriate face.
1117 (defvar ediff-odd-diff-face-C 'ediff-odd-diff-face-C
1118 "Face for highlighting odd-numbered non-current differences in buffer C.
1119 DO NOT CHANGE this variable. Instead, use the customization
1120 widget to customize the actual face object `ediff-odd-diff-face-C'
1121 this variable represents.")
1122 (ediff-hide-face 'ediff-odd-diff-face-C)
1124 (defface ediff-odd-diff-face-Ancestor
1125 '((((class color)) (:foreground "Black" :background "light grey"))
1126 (t (:italic t :stipple "gray1")))
1127 "Face for highlighting odd-numbered non-current differences in the ancestor buffer."
1128 :group 'ediff-highlighting)
1129 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1130 ;; this variable is set to nil, then again to the appropriate face.
1131 (defvar ediff-odd-diff-face-Ancestor 'ediff-odd-diff-face-Ancestor
1132 "Face for highlighting odd-numbered non-current differences in buffer Ancestor.
1133 DO NOT CHANGE this variable. Instead, use the customization
1134 widget to customize the actual face object `ediff-odd-diff-face-Ancestor'
1135 this variable represents.")
1136 (ediff-hide-face 'ediff-odd-diff-face-Ancestor)
1138 ;; Association between buffer types and odd-diff-face symbols
1139 (defconst ediff-odd-diff-face-alist
1140 '((A . ediff-odd-diff-face-A)
1141 (B . ediff-odd-diff-face-B)
1142 (C . ediff-odd-diff-face-C)
1143 (Ancestor . ediff-odd-diff-face-Ancestor)))
1145 ;; A-list of fine-diff face symbols associated with buffer types
1146 (defconst ediff-fine-diff-face-alist
1147 '((A . ediff-fine-diff-face-A)
1148 (B . ediff-fine-diff-face-B)
1149 (C . ediff-fine-diff-face-C)
1150 (Ancestor . ediff-fine-diff-face-Ancestor)))
1152 ;; Help echo
1153 (put 'ediff-fine-diff-face-A 'ediff-help-echo
1154 "A `refinement' of the current difference region")
1155 (put 'ediff-fine-diff-face-B 'ediff-help-echo
1156 "A `refinement' of the current difference region")
1157 (put 'ediff-fine-diff-face-C 'ediff-help-echo
1158 "A `refinement' of the current difference region")
1159 (put 'ediff-fine-diff-face-Ancestor 'ediff-help-echo
1160 "A `refinement' of the current difference region")
1162 (add-hook 'ediff-quit-hook 'ediff-cleanup-mess)
1163 (add-hook 'ediff-suspend-hook 'ediff-default-suspend-function)
1166 ;;; Overlays
1168 (ediff-defvar-local ediff-current-diff-overlay-A nil
1169 "Overlay for the current difference region in buffer A.")
1170 (ediff-defvar-local ediff-current-diff-overlay-B nil
1171 "Overlay for the current difference region in buffer B.")
1172 (ediff-defvar-local ediff-current-diff-overlay-C nil
1173 "Overlay for the current difference region in buffer C.")
1174 (ediff-defvar-local ediff-current-diff-overlay-Ancestor nil
1175 "Overlay for the current difference region in the ancestor buffer.")
1177 ;; Compute priority of ediff overlay.
1178 (defun ediff-highest-priority (start end buffer)
1179 (let ((pos (max 1 (1- start)))
1180 ovr-list)
1181 (if ediff-xemacs-p
1182 (1+ ediff-shadow-overlay-priority)
1183 (ediff-with-current-buffer buffer
1184 (while (< pos (min (point-max) (1+ end)))
1185 (setq ovr-list (append (overlays-at pos) ovr-list))
1186 (setq pos (next-overlay-change pos)))
1187 (1+ (apply '+
1188 (mapcar (lambda (ovr)
1189 (if ovr
1190 (or (ediff-overlay-get ovr 'priority) 0)
1192 ovr-list)
1194 ))))
1197 (defvar ediff-toggle-read-only-function nil
1198 "*Specifies the function to be used to toggle read-only.
1199 If nil, Ediff tries to deduce the function from the binding of C-x C-q.
1200 Normally, this is the `toggle-read-only' function, but, if version
1201 control is used, it could be `vc-toggle-read-only' or `rcs-toggle-read-only'.")
1203 (defcustom ediff-make-buffers-readonly-at-startup nil
1204 "*Make all variant buffers read-only when Ediff starts up.
1205 This property can be toggled interactively."
1206 :type 'boolean
1207 :group 'ediff)
1210 ;;; Misc
1212 ;; if nil, this silences some messages
1213 (defconst ediff-verbose-p t)
1215 (defcustom ediff-autostore-merges 'group-jobs-only
1216 "*Save the results of merge jobs automatically.
1217 Nil means don't save automatically. t means always save. Anything but nil or t
1218 means save automatically only if the merge job is part of a group of jobs, such
1219 as `ediff-merge-directory' or `ediff-merge-directory-revisions'."
1220 :type '(choice (const nil) (const t) (const group-jobs-only))
1221 :group 'ediff-merge)
1222 (make-variable-buffer-local 'ediff-autostore-merges)
1224 ;; file where the result of the merge is to be saved. used internally
1225 (ediff-defvar-local ediff-merge-store-file nil "")
1227 (defcustom ediff-merge-filename-prefix "merge_"
1228 "*Prefix to be attached to saved merge buffers."
1229 :type 'string
1230 :group 'ediff-merge)
1232 (defcustom ediff-no-emacs-help-in-control-buffer nil
1233 "*Non-nil means C-h should not invoke Emacs help in control buffer.
1234 Instead, C-h would jump to previous difference."
1235 :type 'boolean
1236 :group 'ediff)
1238 ;; This is the same as temporary-file-directory from Emacs 20.3.
1239 ;; Copied over here because XEmacs doesn't have this variable.
1240 (defcustom ediff-temp-file-prefix
1241 (file-name-as-directory
1242 (cond ((boundp 'temporary-file-directory) temporary-file-directory)
1243 ((fboundp 'temp-directory) (temp-directory))
1244 (t "/tmp/")))
1245 ;;; (file-name-as-directory
1246 ;;; (cond ((memq system-type '(ms-dos windows-nt))
1247 ;;; (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
1248 ;;; ((memq system-type '(vax-vms axp-vms))
1249 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
1250 ;;; (t
1251 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))
1252 "*Prefix to put on Ediff temporary file names.
1253 Do not start with `~/' or `~USERNAME/'."
1254 :type 'string
1255 :group 'ediff)
1257 (defcustom ediff-temp-file-mode 384 ; u=rw only
1258 "*Mode for Ediff temporary files."
1259 :type 'integer
1260 :group 'ediff)
1262 ;; Metacharacters that have to be protected from the shell when executing
1263 ;; a diff/diff3 command.
1264 (defcustom ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
1265 "Regexp that matches characters that must be quoted with `\\' in shell command line.
1266 This default should work without changes."
1267 :type 'string
1268 :group 'ediff)
1270 ;; needed to simulate frame-char-width in XEmacs.
1271 (defvar ediff-H-glyph (if ediff-xemacs-p (make-glyph "H")))
1274 ;; Temporary file used for refining difference regions in buffer A.
1275 (ediff-defvar-local ediff-temp-file-A nil "")
1276 ;; Temporary file used for refining difference regions in buffer B.
1277 (ediff-defvar-local ediff-temp-file-B nil "")
1278 ;; Temporary file used for refining difference regions in buffer C.
1279 (ediff-defvar-local ediff-temp-file-C nil "")
1282 ;;; In-line functions
1284 (or (fboundp 'ediff-file-remote-p) ; user supplied his own function: use it
1285 (defun ediff-file-remote-p (file-name)
1286 (find-file-name-handler file-name 'file-local-copy)))
1287 ;;; (or (and (featurep 'efs-auto) (efs-ftp-path file-name))
1288 ;;; (and (featurep 'tramp) (tramp-tramp-file-p file-name))
1289 ;;; (and (fboundp 'file-remote-p) (file-remote-p file-name))
1290 ;;; ;; Can happen only in Emacs, since XEmacs has file-remote-p
1291 ;;; (and (require 'ange-ftp) (ange-ftp-ftp-name file-name)))))
1294 (defsubst ediff-frame-unsplittable-p (frame)
1295 (cdr (assq 'unsplittable (frame-parameters frame))))
1297 (defsubst ediff-get-next-window (wind prev-wind)
1298 (or (window-live-p wind)
1299 (setq wind (if prev-wind
1300 (next-window wind)
1301 (selected-window)))))
1304 (defsubst ediff-kill-buffer-carefully (buf)
1305 "Kill buffer BUF if it exists."
1306 (if (ediff-buffer-live-p buf)
1307 (kill-buffer (get-buffer buf))))
1309 (defsubst ediff-background-face (buf-type dif-num)
1310 ;; The value of dif-num is always 1- the one that user sees.
1311 ;; This is why even face is used when dif-num is odd.
1312 (ediff-get-symbol-from-alist
1313 buf-type (if (ediff-odd-p dif-num)
1314 ediff-even-diff-face-alist
1315 ediff-odd-diff-face-alist)
1319 ;; activate faces on diff regions in buffer
1320 (defun ediff-paint-background-regions-in-one-buffer (buf-type unhighlight)
1321 (let ((diff-vector
1322 (eval (ediff-get-symbol-from-alist
1323 buf-type ediff-difference-vector-alist)))
1324 overl diff-num)
1325 (mapcar (lambda (rec)
1326 (setq overl (ediff-get-diff-overlay-from-diff-record rec)
1327 diff-num (ediff-overlay-get overl 'ediff-diff-num))
1328 (if (ediff-overlay-buffer overl)
1329 ;; only if overlay is alive
1330 (ediff-set-overlay-face
1331 overl
1332 (if (not unhighlight)
1333 (ediff-background-face buf-type diff-num))))
1335 diff-vector)))
1338 ;; activate faces on diff regions in all buffers
1339 (defun ediff-paint-background-regions (&optional unhighlight)
1340 (ediff-paint-background-regions-in-one-buffer
1341 'A unhighlight)
1342 (ediff-paint-background-regions-in-one-buffer
1343 'B unhighlight)
1344 (ediff-paint-background-regions-in-one-buffer
1345 'C unhighlight)
1346 (ediff-paint-background-regions-in-one-buffer
1347 'Ancestor unhighlight))
1349 (defun ediff-highlight-diff-in-one-buffer (n buf-type)
1350 (if (ediff-buffer-live-p (ediff-get-buffer buf-type))
1351 (let* ((buff (ediff-get-buffer buf-type))
1352 (last (ediff-with-current-buffer buff (point-max)))
1353 (begin (ediff-get-diff-posn buf-type 'beg n))
1354 (end (ediff-get-diff-posn buf-type 'end n))
1355 (xtra (if (equal begin end) 1 0))
1356 (end-hilit (min last (+ end xtra)))
1357 (current-diff-overlay
1358 (symbol-value
1359 (ediff-get-symbol-from-alist
1360 buf-type ediff-current-diff-overlay-alist))))
1362 (if ediff-xemacs-p
1363 (ediff-move-overlay current-diff-overlay begin end-hilit)
1364 (ediff-move-overlay current-diff-overlay begin end-hilit buff))
1365 (ediff-overlay-put current-diff-overlay 'priority
1366 (ediff-highest-priority begin end-hilit buff))
1367 (ediff-overlay-put current-diff-overlay 'ediff-diff-num n)
1369 ;; unhighlight the background overlay for diff n so it won't
1370 ;; interfere with the current diff overlay
1371 (ediff-set-overlay-face (ediff-get-diff-overlay n buf-type) nil)
1375 (defun ediff-unhighlight-diff-in-one-buffer (buf-type)
1376 (if (ediff-buffer-live-p (ediff-get-buffer buf-type))
1377 (let ((current-diff-overlay
1378 (symbol-value
1379 (ediff-get-symbol-from-alist
1380 buf-type ediff-current-diff-overlay-alist)))
1381 (overlay
1382 (ediff-get-diff-overlay ediff-current-difference buf-type))
1385 (ediff-move-overlay current-diff-overlay 1 1)
1387 ;; rehighlight the overlay in the background of the
1388 ;; current difference region
1389 (ediff-set-overlay-face
1390 overlay
1391 (if (and (ediff-has-face-support-p)
1392 ediff-use-faces ediff-highlight-all-diffs)
1393 (ediff-background-face buf-type ediff-current-difference)))
1396 (defun ediff-unhighlight-diffs-totally-in-one-buffer (buf-type)
1397 (ediff-unselect-and-select-difference -1)
1398 (if (and (ediff-has-face-support-p) ediff-use-faces)
1399 (let* ((inhibit-quit t)
1400 (current-diff-overlay-var
1401 (ediff-get-symbol-from-alist
1402 buf-type ediff-current-diff-overlay-alist))
1403 (current-diff-overlay (symbol-value current-diff-overlay-var)))
1404 (ediff-paint-background-regions 'unhighlight)
1405 (if (ediff-overlayp current-diff-overlay)
1406 (ediff-delete-overlay current-diff-overlay))
1407 (set current-diff-overlay-var nil)
1411 (defsubst ediff-highlight-diff (n)
1412 "Put face on diff N. Invoked for X displays only."
1413 (ediff-highlight-diff-in-one-buffer n 'A)
1414 (ediff-highlight-diff-in-one-buffer n 'B)
1415 (ediff-highlight-diff-in-one-buffer n 'C)
1416 (ediff-highlight-diff-in-one-buffer n 'Ancestor)
1420 (defsubst ediff-unhighlight-diff ()
1421 "Remove overlays from buffers A, B, and C."
1422 (ediff-unhighlight-diff-in-one-buffer 'A)
1423 (ediff-unhighlight-diff-in-one-buffer 'B)
1424 (ediff-unhighlight-diff-in-one-buffer 'C)
1425 (ediff-unhighlight-diff-in-one-buffer 'Ancestor)
1428 ;; delete highlighting overlays, restore faces to their original form
1429 (defsubst ediff-unhighlight-diffs-totally ()
1430 (ediff-unhighlight-diffs-totally-in-one-buffer 'A)
1431 (ediff-unhighlight-diffs-totally-in-one-buffer 'B)
1432 (ediff-unhighlight-diffs-totally-in-one-buffer 'C)
1433 (ediff-unhighlight-diffs-totally-in-one-buffer 'Ancestor)
1437 ;; arg is a record for a given diff in a difference vector
1438 ;; this record is itself a vector
1439 (defsubst ediff-clear-fine-diff-vector (diff-record)
1440 (if diff-record
1441 (mapcar 'ediff-delete-overlay
1442 (ediff-get-fine-diff-vector-from-diff-record diff-record))))
1444 (defsubst ediff-clear-fine-differences-in-one-buffer (n buf-type)
1445 (ediff-clear-fine-diff-vector (ediff-get-difference n buf-type))
1446 (ediff-set-fine-diff-vector n buf-type nil))
1448 (defsubst ediff-clear-fine-differences (n)
1449 (ediff-clear-fine-differences-in-one-buffer n 'A)
1450 (ediff-clear-fine-differences-in-one-buffer n 'B)
1451 (if ediff-3way-job
1452 (ediff-clear-fine-differences-in-one-buffer n 'C)))
1455 (defsubst ediff-convert-fine-diffs-to-overlays (diff-list region-num)
1456 (ediff-set-fine-overlays-in-one-buffer 'A diff-list region-num)
1457 (ediff-set-fine-overlays-in-one-buffer 'B diff-list region-num)
1458 (if ediff-3way-job
1459 (ediff-set-fine-overlays-in-one-buffer 'C diff-list region-num)
1462 (defsubst ediff-mouse-event-p (event)
1463 (if ediff-xemacs-p
1464 (button-event-p event)
1465 (string-match "mouse" (format "%S" (event-basic-type event)))
1469 (defsubst ediff-key-press-event-p (event)
1470 (if ediff-xemacs-p
1471 (key-press-event-p event)
1472 (or (char-or-string-p event) (symbolp event))))
1474 (defun ediff-event-point (event)
1475 (cond ((ediff-mouse-event-p event)
1476 (if ediff-xemacs-p
1477 (event-point event)
1478 (posn-point (event-start event))))
1479 ((ediff-key-press-event-p event)
1480 (point))
1481 (t (error))))
1483 (defun ediff-event-buffer (event)
1484 (cond ((ediff-mouse-event-p event)
1485 (if ediff-xemacs-p
1486 (event-buffer event)
1487 (window-buffer (posn-window (event-start event)))))
1488 ((ediff-key-press-event-p event)
1489 (current-buffer))
1490 (t (error))))
1493 (defsubst ediff-frame-iconified-p (frame)
1494 (if (and (ediff-window-display-p) (frame-live-p frame))
1495 (if ediff-xemacs-p
1496 (frame-iconified-p frame)
1497 (eq (frame-visible-p frame) 'icon))))
1499 (defsubst ediff-window-visible-p (wind)
1500 ;; under TTY, window-live-p also means window is visible
1501 (and (window-live-p wind)
1502 (or (not (ediff-window-display-p))
1503 (frame-visible-p (window-frame wind)))))
1506 (defsubst ediff-frame-char-width (frame)
1507 (if ediff-xemacs-p
1508 (/ (frame-pixel-width frame) (frame-width frame))
1509 (frame-char-width frame)))
1511 (defun ediff-reset-mouse (&optional frame do-not-grab-mouse)
1512 (or frame (setq frame (selected-frame)))
1513 (if (ediff-window-display-p)
1514 (let ((frame-or-wind frame))
1515 (if ediff-xemacs-p
1516 (setq frame-or-wind (frame-selected-window frame)))
1517 (or do-not-grab-mouse
1518 ;; don't set mouse if the user said to never do this
1519 (not ediff-grab-mouse)
1520 ;; Don't grab on quit, if the user doesn't want to.
1521 ;; If ediff-grab-mouse = t, then mouse won't be grabbed for
1522 ;; sessions that are not part of a group (this is done in
1523 ;; ediff-recenter). The condition below affects only terminating
1524 ;; sessions in session groups (in which case mouse is warped into
1525 ;; a meta buffer).
1526 (and (eq ediff-grab-mouse 'maybe)
1527 (memq this-command '(ediff-quit ediff-update-diffs)))
1528 (set-mouse-position frame-or-wind 1 0))
1531 (defsubst ediff-spy-after-mouse ()
1532 (setq ediff-mouse-pixel-position (mouse-pixel-position)))
1534 ;; It is not easy to find out when the user grabs the mouse, since emacs and
1535 ;; xemacs behave differently when mouse is not in any frame. Also, this is
1536 ;; sensitive to when the user grabbed mouse. Not used for now.
1537 (defun ediff-user-grabbed-mouse ()
1538 (if ediff-mouse-pixel-position
1539 (cond ((not (eq (car ediff-mouse-pixel-position)
1540 (car (mouse-pixel-position)))))
1541 ((and (car (cdr ediff-mouse-pixel-position))
1542 (car (cdr (mouse-pixel-position)))
1543 (cdr (cdr ediff-mouse-pixel-position))
1544 (cdr (cdr (mouse-pixel-position))))
1545 (not (and (< (abs (- (car (cdr ediff-mouse-pixel-position))
1546 (car (cdr (mouse-pixel-position)))))
1547 ediff-mouse-pixel-threshold)
1548 (< (abs (- (cdr (cdr ediff-mouse-pixel-position))
1549 (cdr (cdr (mouse-pixel-position)))))
1550 ediff-mouse-pixel-threshold))))
1551 (t nil))))
1553 (defsubst ediff-frame-char-height (frame)
1554 (if ediff-xemacs-p
1555 (glyph-height ediff-H-glyph (selected-window frame))
1556 (frame-char-height frame)))
1558 ;; Some overlay functions
1560 (defsubst ediff-overlay-start (overl)
1561 (if (ediff-overlayp overl)
1562 (if ediff-emacs-p
1563 (overlay-start overl)
1564 (extent-start-position overl))))
1566 (defsubst ediff-overlay-end (overl)
1567 (if (ediff-overlayp overl)
1568 (if ediff-emacs-p
1569 (overlay-end overl)
1570 (extent-end-position overl))))
1572 (defsubst ediff-empty-overlay-p (overl)
1573 (= (ediff-overlay-start overl) (ediff-overlay-end overl)))
1575 ;; like overlay-buffer in Emacs. In XEmacs, returns nil if the extent is
1576 ;; dead. Otherwise, works like extent-buffer
1577 (defun ediff-overlay-buffer (overl)
1578 (if ediff-emacs-p
1579 (overlay-buffer overl)
1580 (and (extent-live-p overl) (extent-object overl))))
1582 ;; like overlay-get in Emacs. In XEmacs, returns nil if the extent is
1583 ;; dead. Otherwise, like extent-property
1584 (defun ediff-overlay-get (overl property)
1585 (if ediff-emacs-p
1586 (overlay-get overl property)
1587 (and (extent-live-p overl) (extent-property overl property))))
1590 ;; These two functions are here because XEmacs refuses to
1591 ;; handle overlays whose buffers were deleted.
1592 (defun ediff-move-overlay (overlay beg end &optional buffer)
1593 "Calls `move-overlay' in Emacs and `set-extent-endpoints' in Lemacs.
1594 Checks if overlay's buffer exists before actually doing the move."
1595 (let ((buf (and overlay (ediff-overlay-buffer overlay))))
1596 (if (ediff-buffer-live-p buf)
1597 (if ediff-xemacs-p
1598 (set-extent-endpoints overlay beg end)
1599 (move-overlay overlay beg end buffer))
1600 ;; buffer's dead
1601 (if overlay
1602 (ediff-delete-overlay overlay)))))
1604 (defun ediff-overlay-put (overlay prop value)
1605 "Calls `overlay-put' or `set-extent-property' depending on Emacs version.
1606 Checks if overlay's buffer exists."
1607 (if (ediff-buffer-live-p (ediff-overlay-buffer overlay))
1608 (if ediff-xemacs-p
1609 (set-extent-property overlay prop value)
1610 (overlay-put overlay prop value))
1611 (ediff-delete-overlay overlay)))
1613 ;; Some diff region tests
1615 ;; t if diff region is empty.
1616 ;; In case of buffer C, t also if it is not a 3way
1617 ;; comparison job (merging jobs return t as well).
1618 (defun ediff-empty-diff-region-p (n buf-type)
1619 (if (eq buf-type 'C)
1620 (or (not ediff-3way-comparison-job)
1621 (= (ediff-get-diff-posn 'C 'beg n)
1622 (ediff-get-diff-posn 'C 'end n)))
1623 (= (ediff-get-diff-posn buf-type 'beg n)
1624 (ediff-get-diff-posn buf-type 'end n))))
1626 ;; Test if diff region is white space only.
1627 ;; If 2-way job and buf-type = C, then returns t.
1628 (defun ediff-whitespace-diff-region-p (n buf-type)
1629 (or (and (eq buf-type 'C) (not ediff-3way-job))
1630 (ediff-empty-diff-region-p n buf-type)
1631 (let ((beg (ediff-get-diff-posn buf-type 'beg n))
1632 (end (ediff-get-diff-posn buf-type 'end n)))
1633 (ediff-with-current-buffer (ediff-get-buffer buf-type)
1634 (save-excursion
1635 (goto-char beg)
1636 (skip-chars-forward ediff-whitespace)
1637 (>= (point) end))))))
1639 ;; temporarily uses DIR to abbreviate file name
1640 ;; if DIR is nil, use default-directory
1641 (defun ediff-abbreviate-file-name (file &optional dir)
1642 (cond ((stringp dir)
1643 (let ((directory-abbrev-alist (list (cons dir ""))))
1644 (abbreviate-file-name file)))
1645 (ediff-emacs-p (abbreviate-file-name file))
1646 (t ; XEmacs requires addl argument
1647 (abbreviate-file-name file t))))
1649 ;; Takes a directory and returns the parent directory.
1650 ;; does nothing to `/'. If the ARG is a regular file,
1651 ;; strip the file AND the last dir.
1652 (defun ediff-strip-last-dir (dir)
1653 (if (not (stringp dir)) (setq dir default-directory))
1654 (setq dir (expand-file-name dir))
1655 (or (file-directory-p dir) (setq dir (file-name-directory dir)))
1656 (let* ((pos (1- (length dir)))
1657 (last-char (aref dir pos)))
1658 (if (and (> pos 0) (= last-char ?/))
1659 (setq dir (substring dir 0 pos)))
1660 (ediff-abbreviate-file-name (file-name-directory dir))))
1662 (defun ediff-truncate-string-left (str newlen)
1663 ;; leave space for ... on the left
1664 (let ((len (length str))
1665 substr)
1666 (if (<= len newlen)
1668 (setq newlen (max 0 (- newlen 3)))
1669 (setq substr (substring str (max 0 (- len 1 newlen))))
1670 (concat "..." substr))))
1672 (defsubst ediff-nonempty-string-p (string)
1673 (and (stringp string) (not (string= string ""))))
1675 (unless (fboundp 'subst-char-in-string)
1676 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1677 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1678 Unless optional argument INPLACE is non-nil, return a new string."
1679 (let ((i (length string))
1680 (newstr (if inplace string (copy-sequence string))))
1681 (while (> i 0)
1682 (setq i (1- i))
1683 (if (eq (aref newstr i) fromchar)
1684 (aset newstr i tochar)))
1685 newstr)))
1687 (defun ediff-abbrev-jobname (jobname)
1688 (cond ((eq jobname 'ediff-directories)
1689 "Compare two directories")
1690 ((eq jobname 'ediff-files)
1691 "Compare two files")
1692 ((eq jobname 'ediff-buffers)
1693 "Compare two buffers")
1694 ((eq jobname 'ediff-directories3)
1695 "Compare three directories")
1696 ((eq jobname 'ediff-files3)
1697 "Compare three files")
1698 ((eq jobname 'ediff-buffers3)
1699 "Compare three buffers")
1700 ((eq jobname 'ediff-revision)
1701 "Compare file with a version")
1702 ((eq jobname 'ediff-directory-revisions)
1703 "Compare dir files with versions")
1704 ((eq jobname 'ediff-merge-directory-revisions)
1705 "Merge dir files with versions")
1706 ((eq jobname 'ediff-merge-directory-revisions-with-ancestor)
1707 "Merge dir versions via ancestors")
1709 (capitalize
1710 (subst-char-in-string ?- ?\ (substring (symbol-name jobname) 6))))
1714 (defsubst ediff-get-region-contents (n buf-type ctrl-buf &optional start end)
1715 (ediff-with-current-buffer
1716 (ediff-with-current-buffer ctrl-buf (ediff-get-buffer buf-type))
1717 (buffer-substring
1718 (or start (ediff-get-diff-posn buf-type 'beg n ctrl-buf))
1719 (or end (ediff-get-diff-posn buf-type 'end n ctrl-buf)))))
1721 ;; If ediff modified mode line, strip the modification
1722 (defsubst ediff-strip-mode-line-format ()
1723 (if (member (car mode-line-format) '(" A: " " B: " " C: " " Ancestor: "))
1724 (setq mode-line-format (nth 2 mode-line-format))))
1726 ;; Verify that we have a difference selected.
1727 (defsubst ediff-valid-difference-p (&optional n)
1728 (or n (setq n ediff-current-difference))
1729 (and (>= n 0) (< n ediff-number-of-differences)))
1731 (defsubst ediff-show-all-diffs (n)
1732 "Don't skip difference regions."
1733 nil)
1735 (defsubst Xor (a b)
1736 (or (and a (not b)) (and (not a) b)))
1738 (defsubst ediff-message-if-verbose (string &rest args)
1739 (if ediff-verbose-p
1740 (apply 'message string args)))
1742 (defun ediff-file-attributes (filename attr-number)
1743 (if (ediff-file-remote-p filename)
1745 (nth attr-number (file-attributes filename))))
1747 (defsubst ediff-file-size (filename)
1748 (ediff-file-attributes filename 7))
1749 (defsubst ediff-file-modtime (filename)
1750 (ediff-file-attributes filename 5))
1753 (defun ediff-convert-standard-filename (fname)
1754 (if (fboundp 'convert-standard-filename)
1755 (convert-standard-filename fname)
1756 fname))
1759 (if (fboundp 'with-syntax-table)
1760 (fset 'ediff-with-syntax-table 'with-syntax-table)
1761 ;; stolen from subr.el in emacs 21
1762 (defmacro ediff-with-syntax-table (table &rest body)
1763 (let ((old-table (make-symbol "table"))
1764 (old-buffer (make-symbol "buffer")))
1765 `(let ((,old-table (syntax-table))
1766 (,old-buffer (current-buffer)))
1767 (unwind-protect
1768 (progn
1769 (set-syntax-table (copy-syntax-table ,table))
1770 ,@body)
1771 (save-current-buffer
1772 (set-buffer ,old-buffer)
1773 (set-syntax-table ,old-table)))))))
1777 ;;; Local Variables:
1778 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1779 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1780 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1781 ;;; End:
1783 (provide 'ediff-init)
1785 ;;; ediff-init.el ends here