Weed out redundant uses of `function'
[emacs.git] / lisp / ediff-init.el
blob08490c4c16ceb885b735f33cf2b917a663744da3
1 ;;; ediff-init.el --- Macros, variables, and defsubsts used by Ediff
3 ;; Copyright (C) 1994, 1995, 1996, 1997 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-emacs-p (memq (ediff-device-type) '(pc)))
67 (ediff-xemacs-p (memq (ediff-device-type) '(tty pc)))))
69 (defun ediff-has-toolbar-support-p ()
70 (and ediff-xemacs-p
71 (featurep 'toolbar)
72 (console-on-window-system-p)))
74 (defun ediff-use-toolbar-p ()
75 (and (ediff-has-toolbar-support-p) ;Can it do it ?
76 (boundp 'ediff-use-toolbar-p)
77 ediff-use-toolbar-p)) ;Does the user want it ?
79 ;; Defines SYMBOL as an advertised local variable.
80 ;; Performs a defvar, then executes `make-variable-buffer-local' on
81 ;; the variable. Also sets the `permanent-local' property,
82 ;; so that `kill-all-local-variables' (called by major-mode setting
83 ;; commands) won't destroy Ediff control variables.
84 ;;
85 ;; Plagiarised from `emerge-defvar-local' for XEmacs.
86 (defmacro ediff-defvar-local (var value doc)
87 `(progn
88 (defvar ,var ,value ,doc)
89 (make-variable-buffer-local ',var)
90 (put ',var 'permanent-local t)))
94 ;; Variables that control each Ediff session---local to the control buffer.
96 ;; Mode variables
97 ;; The buffer in which the A variant is stored.
98 (ediff-defvar-local ediff-buffer-A nil "")
99 ;; The buffer in which the B variant is stored.
100 (ediff-defvar-local ediff-buffer-B nil "")
101 ;; The buffer in which the C variant is stored or where the merge buffer lives.
102 (ediff-defvar-local ediff-buffer-C nil "")
103 ;; Ancestor buffer
104 (ediff-defvar-local ediff-ancestor-buffer nil "")
105 ;; The Ediff control buffer
106 (ediff-defvar-local ediff-control-buffer nil "")
109 ;; Association between buff-type and ediff-buffer-*
110 (defconst ediff-buffer-alist
111 '((?A . ediff-buffer-A)
112 (?B . ediff-buffer-B)
113 (?C . ediff-buffer-C)))
115 ;;; Macros
116 (defmacro ediff-odd-p (arg)
117 `(eq (logand ,arg 1) 1))
119 (defmacro ediff-buffer-live-p (buf)
120 `(and ,buf (get-buffer ,buf) (buffer-name (get-buffer ,buf))))
122 (defmacro ediff-get-buffer (arg)
123 `(cond ((eq ,arg 'A) ediff-buffer-A)
124 ((eq ,arg 'B) ediff-buffer-B)
125 ((eq ,arg 'C) ediff-buffer-C)
126 ((eq ,arg 'Ancestor) ediff-ancestor-buffer)
129 (defmacro ediff-get-value-according-to-buffer-type (buf-type list)
130 `(cond ((eq ,buf-type 'A) (nth 0 ,list))
131 ((eq ,buf-type 'B) (nth 1 ,list))
132 ((eq ,buf-type 'C) (nth 2 ,list))
135 (defmacro ediff-char-to-buftype (arg)
136 `(cond ((memq ,arg '(?a ?A)) 'A)
137 ((memq ,arg '(?b ?B)) 'B)
138 ((memq ,arg '(?c ?C)) 'C)
142 ;; A-list is supposed to be of the form (A . symb) (B . symb)...)
143 ;; where the first part of any association is a buffer type and the second is
144 ;; an appropriate symbol. Given buffer-type, this function returns the
145 ;; symbol. This is used to avoid using `intern'
146 (defsubst ediff-get-symbol-from-alist (buf-type alist)
147 (cdr (assoc buf-type alist)))
149 (defconst ediff-difference-vector-alist
150 '((A . ediff-difference-vector-A)
151 (B . ediff-difference-vector-B)
152 (C . ediff-difference-vector-C)
153 (Ancestor . ediff-difference-vector-Ancestor)))
155 (defmacro ediff-get-difference (n buf-type)
156 `(aref
157 (symbol-value
158 (ediff-get-symbol-from-alist
159 ,buf-type ediff-difference-vector-alist))
160 ,n))
162 ;; Tell if it has been previously determined that the region has
163 ;; no diffs other than the white space and newlines
164 ;; The argument, N, is the diff region number used by Ediff to index the
165 ;; diff vector. It is 1 less than the number seen by the user.
166 ;; Returns:
167 ;; t if the diffs are whitespace in all buffers
168 ;; 'A (in 3-buf comparison only) if there are only whitespace
169 ;; diffs in bufs B and C
170 ;; 'B (in 3-buf comparison only) if there are only whitespace
171 ;; diffs in bufs A and C
172 ;; 'C (in 3-buf comparison only) if there are only whitespace
173 ;; diffs in bufs A and B
175 ;; A Difference Vector has the form:
176 ;; [diff diff diff ...]
177 ;; where each diff has the form:
178 ;; [overlay fine-diff-vector no-fine-diffs-flag state-of-difference]
179 ;; fine-diff-vector is a vector [fine-diff fine-diff fine-diff ...]
180 ;; no-fine-diffs-flag says if there are fine differences.
181 ;; state-of-difference is A, B, C, or nil, indicating which buffer is
182 ;; different from the other two (used only in 3-way jobs).
183 (defmacro ediff-no-fine-diffs-p (n)
184 `(aref (ediff-get-difference ,n 'A) 2))
186 (defmacro ediff-get-diff-overlay-from-diff-record (diff-rec)
187 `(aref ,diff-rec 0))
189 (defmacro ediff-get-diff-overlay (n buf-type)
190 `(ediff-get-diff-overlay-from-diff-record
191 (ediff-get-difference ,n ,buf-type)))
193 (defmacro ediff-get-fine-diff-vector-from-diff-record (diff-rec)
194 `(aref ,diff-rec 1))
196 (defmacro ediff-set-fine-diff-vector (n buf-type fine-vec)
197 `(aset (ediff-get-difference ,n ,buf-type) 1 ,fine-vec))
199 (defmacro ediff-get-state-of-diff (n buf-type)
200 `(if (ediff-buffer-live-p ediff-buffer-C)
201 (aref (ediff-get-difference ,n ,buf-type) 3)))
202 (defmacro ediff-set-state-of-diff (n buf-type val)
203 `(aset (ediff-get-difference ,n ,buf-type) 3 ,val))
205 (defmacro ediff-get-state-of-merge (n)
206 `(if ediff-state-of-merge
207 (aref (aref ediff-state-of-merge ,n) 0)))
208 (defmacro ediff-set-state-of-merge (n val)
209 `(if ediff-state-of-merge
210 (aset (aref ediff-state-of-merge ,n) 0 ,val)))
212 (defmacro ediff-get-state-of-ancestor (n)
213 `(if ediff-state-of-merge
214 (aref (aref ediff-state-of-merge ,n) 1)))
216 ;; if flag is t, puts a mark on diff region saying that
217 ;; the differences are in white space only. If flag is nil,
218 ;; the region is marked as essential (i.e., differences are
219 ;; not just in the white space and newlines.)
220 (defmacro ediff-mark-diff-as-space-only (n flag)
221 `(aset (ediff-get-difference ,n 'A) 2 ,flag))
223 (defmacro ediff-get-fine-diff-vector (n buf-type)
224 `(ediff-get-fine-diff-vector-from-diff-record
225 (ediff-get-difference ,n ,buf-type)))
227 ;; Macro to switch to BUFFER, evaluate BODY, returns to original buffer.
228 ;; Doesn't save the point and mark.
229 ;; This is `with-current-buffer' with the added test for live buffers."
230 (defmacro ediff-with-current-buffer (buffer &rest body)
231 `(if (ediff-buffer-live-p ,buffer)
232 (save-current-buffer
233 (set-buffer ,buffer)
234 ,@body)
235 (or (eq this-command 'ediff-quit)
236 (error ediff-KILLED-VITAL-BUFFER))
240 (defsubst ediff-multiframe-setup-p ()
241 (and (ediff-window-display-p) ediff-multiframe))
243 (defmacro ediff-narrow-control-frame-p ()
244 `(and (ediff-multiframe-setup-p)
245 (equal ediff-help-message ediff-brief-message-string)))
247 (defmacro ediff-3way-comparison-job ()
248 `(memq
249 ediff-job-name
250 '(ediff-files3 ediff-buffers3)))
251 (ediff-defvar-local ediff-3way-comparison-job nil "")
253 (defmacro ediff-merge-job ()
254 `(memq
255 ediff-job-name
256 '(ediff-merge-files
257 ediff-merge-buffers
258 ediff-merge-files-with-ancestor
259 ediff-merge-buffers-with-ancestor
260 ediff-merge-revisions
261 ediff-merge-revisions-with-ancestor)))
262 (ediff-defvar-local ediff-merge-job nil "")
264 (defmacro ediff-merge-with-ancestor-job ()
265 `(memq
266 ediff-job-name
267 '(ediff-merge-files-with-ancestor
268 ediff-merge-buffers-with-ancestor
269 ediff-merge-revisions-with-ancestor)))
270 (ediff-defvar-local ediff-merge-with-ancestor-job nil "")
272 (defmacro ediff-3way-job ()
273 `(or ediff-3way-comparison-job ediff-merge-job))
274 (ediff-defvar-local ediff-3way-job nil "")
276 ;; A diff3 job is like a 3way job, but ediff-merge doesn't require the use
277 ;; of diff3.
278 (defmacro ediff-diff3-job ()
279 `(or ediff-3way-comparison-job
280 ediff-merge-with-ancestor-job))
281 (ediff-defvar-local ediff-diff3-job nil "")
283 (defmacro ediff-windows-job ()
284 `(memq ediff-job-name '(ediff-windows-wordwise ediff-windows-linewise)))
285 (ediff-defvar-local ediff-windows-job nil "")
287 (defmacro ediff-word-mode-job ()
288 `(memq ediff-job-name '(ediff-windows-wordwise ediff-regions-wordwise)))
289 (ediff-defvar-local ediff-word-mode-job nil "")
291 (defmacro ediff-narrow-job ()
292 `(memq ediff-job-name '(ediff-windows-wordwise
293 ediff-regions-wordwise
294 ediff-windows-linewise
295 ediff-regions-linewise)))
296 (ediff-defvar-local ediff-narrow-job nil "")
298 ;; Note: ediff-merge-directory-revisions-with-ancestor is not treated as an
299 ;; ancestor metajob, since it behaves differently.
300 (defsubst ediff-ancestor-metajob (&optional metajob)
301 (memq (or metajob ediff-metajob-name)
302 '(ediff-merge-directories-with-ancestor
303 ediff-merge-filegroups-with-ancestor)))
304 (defsubst ediff-revision-metajob (&optional metajob)
305 (memq (or metajob ediff-metajob-name)
306 '(ediff-directory-revisions
307 ediff-merge-directory-revisions
308 ediff-merge-directory-revisions-with-ancestor)))
309 (defsubst ediff-patch-metajob (&optional metajob)
310 (memq (or metajob ediff-metajob-name)
311 '(ediff-multifile-patch)))
312 ;; metajob involving only one group of files, such as multipatch or directory
313 ;; revision
314 (defsubst ediff-one-filegroup-metajob (&optional metajob)
315 (or (ediff-revision-metajob metajob)
316 (ediff-patch-metajob metajob)
317 ;; add more here
319 (defsubst ediff-collect-diffs-metajob (&optional metajob)
320 (memq (or metajob ediff-metajob-name)
321 '(ediff-directories
322 ediff-directory-revisions
323 ediff-merge-directories
324 ediff-merge-directories-with-ancestor
325 ediff-merge-directory-revisions
326 ediff-merge-directory-revisions-with-ancestor
327 ;; add more here
329 (defsubst ediff-merge-metajob (&optional metajob)
330 (memq (or metajob ediff-metajob-name)
331 '(ediff-merge-directories
332 ediff-merge-directories-with-ancestor
333 ediff-merge-directory-revisions
334 ediff-merge-directory-revisions-with-ancestor
335 ediff-merge-filegroups-with-ancestor
336 ;; add more here
339 (defsubst ediff-metajob3 (&optional metajob)
340 (memq (or metajob ediff-metajob-name)
341 '(ediff-merge-directories-with-ancestor
342 ediff-merge-filegroups-with-ancestor
343 ediff-directories3
344 ediff-filegroups3)))
345 (defsubst ediff-comparison-metajob3 (&optional metajob)
346 (memq (or metajob ediff-metajob-name)
347 '(ediff-directories3 ediff-filegroups3)))
349 ;; with no argument, checks if we are in ediff-control-buffer
350 ;; with argument, checks if we are in ediff-meta-buffer
351 (defun ediff-in-control-buffer-p (&optional meta-buf-p)
352 (and (boundp 'ediff-control-buffer)
353 (eq (if meta-buf-p ediff-meta-buffer ediff-control-buffer)
354 (current-buffer))))
356 (defsubst ediff-barf-if-not-control-buffer (&optional meta-buf-p)
357 (or (ediff-in-control-buffer-p meta-buf-p)
358 (error "%S: This command runs in Ediff Control Buffer only!"
359 this-command)))
361 (defgroup ediff-highlighting nil
362 "Hilighting of difference regions in Ediff"
363 :prefix "ediff-"
364 :group 'ediff)
366 (defgroup ediff-merge nil
367 "Merging utilities"
368 :prefix "ediff-"
369 :group 'ediff)
371 (defgroup ediff-hook nil
372 "Hooks called by Ediff"
373 :prefix "ediff-"
374 :group 'ediff)
376 ;; Hook variables
378 (defcustom ediff-before-setup-windows-hook nil
379 "*Hooks to run before Ediff sets its window configuration.
380 This can be used to save the previous window config, which can be restored
381 on ediff-quit or ediff-suspend."
382 :type 'hook
383 :group 'ediff-hook)
384 (defcustom ediff-after-setup-windows-hook nil
385 "*Hooks to run after Ediff sets its window configuration.
386 This can be used to set up control window or icon in a desired place."
387 :type 'hook
388 :group 'ediff-hook)
389 (defcustom ediff-before-setup-control-frame-hook nil
390 "*Hooks run before setting up the frame to display Ediff Control Panel.
391 Can be used to change control frame parameters to position it where it
392 is desirable."
393 :type 'hook
394 :group 'ediff-hook)
395 (defcustom ediff-after-setup-control-frame-hook nil
396 "*Hooks run after setting up the frame to display Ediff Control Panel.
397 Can be used to move the frame where it is desired."
398 :type 'hook
399 :group 'ediff-hook)
400 (defcustom ediff-startup-hook nil
401 "*Hooks to run in the control buffer after Ediff has been set up."
402 :type 'hook
403 :group 'ediff-hook)
404 (defcustom ediff-select-hook nil
405 "*Hooks to run after a difference has been selected."
406 :type 'hook
407 :group 'ediff-hook)
408 (defcustom ediff-unselect-hook nil
409 "*Hooks to run after a difference has been unselected."
410 :type 'hook
411 :group 'ediff-hook)
412 (defcustom ediff-prepare-buffer-hook nil
413 "*Hooks called after buffers A, B, and C are set up."
414 :type 'hook
415 :group 'ediff-hook)
416 (defcustom ediff-load-hook nil
417 "*Hook run after Ediff is loaded. Can be used to change defaults."
418 :type 'hook
419 :group 'ediff-hook)
421 (defcustom ediff-mode-hook nil
422 "*Hook run just after ediff-mode is set up in the control buffer.
423 This is done before any windows or frames are created. One can use it to
424 set local variables that determine how the display looks like."
425 :type 'hook
426 :group 'ediff-hook)
427 (defcustom ediff-keymap-setup-hook nil
428 "*Hook run just after the default bindings in Ediff keymap are set up."
429 :type 'hook
430 :group 'ediff-hook)
432 (defcustom ediff-display-help-hook nil
433 "*Hooks run after preparing the help message."
434 :type 'hook
435 :group 'ediff-hook)
437 (defcustom ediff-suspend-hook (list 'ediff-default-suspend-function)
438 "*Hooks to run in the Ediff control buffer when Ediff is suspended."
439 :type 'hook
440 :group 'ediff-hook)
441 (defcustom ediff-quit-hook (list 'ediff-cleanup-mess)
442 "*Hooks to run in the Ediff control buffer after finishing Ediff."
443 :type 'hook
444 :group 'ediff-hook)
445 (defcustom ediff-cleanup-hook nil
446 "*Hooks to run on exiting Ediff but before killing the control and variant buffers."
447 :type 'hook
448 :group 'ediff-hook)
450 ;; Error messages
451 (defconst ediff-KILLED-VITAL-BUFFER
452 "You have killed a vital Ediff buffer---you must leave Ediff now!")
453 (defconst ediff-NO-DIFFERENCES
454 "Sorry, comparison of identical variants is not what I am made for...")
455 (defconst ediff-BAD-DIFF-NUMBER
456 ;; %S stands for this-command, %d - diff number, %d - max diff
457 "%S: Bad diff region number, %d. Valid numbers are 1 to %d")
458 (defconst ediff-BAD-INFO (format "
459 *** The Info file for Ediff, a part of the standard distribution
460 *** of %sEmacs, does not seem to be properly installed.
461 ***
462 *** Please contact your system administrator. "
463 (if ediff-xemacs-p "X" "")))
465 ;; Selective browsing
467 (ediff-defvar-local ediff-skip-diff-region-function 'ediff-show-all-diffs
468 "Function that determines the next/previous diff region to show.
469 Should return t for regions to be ignored and nil otherwise.
470 This function gets a region number as an argument. The region number
471 is the one used internally by Ediff. It is 1 less than the number seen
472 by the user.")
474 (ediff-defvar-local ediff-hide-regexp-matches-function
475 'ediff-hide-regexp-matches
476 "Function to use in determining which regions to hide.
477 See the documentation string of `ediff-hide-regexp-matches' for details.")
478 (ediff-defvar-local ediff-focus-on-regexp-matches-function
479 'ediff-focus-on-regexp-matches
480 "Function to use in determining which regions to focus on.
481 See the documentation string of `ediff-focus-on-regexp-matches' for details.")
483 ;; Regexp that determines buf A regions to focus on when skipping to diff
484 (ediff-defvar-local ediff-regexp-focus-A "" "")
485 ;; Regexp that determines buf B regions to focus on when skipping to diff
486 (ediff-defvar-local ediff-regexp-focus-B "" "")
487 ;; Regexp that determines buf C regions to focus on when skipping to diff
488 (ediff-defvar-local ediff-regexp-focus-C "" "")
489 ;; connective that determines whether to focus regions that match both or
490 ;; one of the regexps
491 (ediff-defvar-local ediff-focus-regexp-connective 'and "")
493 ;; Regexp that determines buf A regions to ignore when skipping to diff
494 (ediff-defvar-local ediff-regexp-hide-A "" "")
495 ;; Regexp that determines buf B regions to ignore when skipping to diff
496 (ediff-defvar-local ediff-regexp-hide-B "" "")
497 ;; Regexp that determines buf C regions to ignore when skipping to diff
498 (ediff-defvar-local ediff-regexp-hide-C "" "")
499 ;; connective that determines whether to hide regions that match both or
500 ;; one of the regexps
501 (ediff-defvar-local ediff-hide-regexp-connective 'and "")
504 ;;; Copying difference regions between buffers.
506 ;; A list of killed diffs.
507 ;; A diff is saved here if it is replaced by a diff
508 ;; from another buffer. This alist has the form:
509 ;; \((num (buff-object . diff) (buff-object . diff) (buff-object . diff)) ...),
510 ;; where some buffer-objects may be missing.
511 (ediff-defvar-local ediff-killed-diffs-alist nil "")
514 ;; Highlighting
515 (defcustom ediff-before-flag-bol (if ediff-xemacs-p (make-glyph "->>") "->>")
516 "*Flag placed before a highlighted block of differences, if block starts at beginning of a line."
517 :type 'string
518 :tag "Region before-flag at beginning of line"
519 :group 'ediff)
521 (defcustom ediff-after-flag-eol (if ediff-xemacs-p (make-glyph "<<-") "<<-")
522 "*Flag placed after a highlighted block of differences, if block ends at end of a line."
523 :type 'string
524 :tag "Region after-flag at end of line"
525 :group 'ediff)
527 (defcustom ediff-before-flag-mol (if ediff-xemacs-p (make-glyph "->>") "->>")
528 "*Flag placed before a highlighted block of differences, if block starts in mid-line."
529 :type 'string
530 :tag "Region before-flag in the middle of line"
531 :group 'ediff)
532 (defcustom ediff-after-flag-mol (if ediff-xemacs-p (make-glyph "<<-") "<<-")
533 "*Flag placed after a highlighted block of differences, if block ends in mid-line."
534 :type 'string
535 :tag "Region after-flag in the middle of line"
536 :group 'ediff)
539 (ediff-defvar-local ediff-use-faces t "")
540 (defcustom ediff-use-faces t
541 "If t, differences are highlighted using faces, if device supports faces.
542 If nil, differences are highlighted using ASCII flags, ediff-before-flag
543 and ediff-after-flag. On a non-window system, differences are always
544 highlighted using ASCII flags."
545 :type 'boolean
546 :group 'ediff-highlighting)
548 ;; this indicates that diff regions are word-size, so fine diffs are
549 ;; permanently nixed; used in ediff-windows-wordwise and ediff-regions-wordwise
550 (ediff-defvar-local ediff-word-mode nil "")
551 ;; Name of the job (ediff-files, ediff-windows, etc.)
552 (ediff-defvar-local ediff-job-name nil "")
554 ;; Narrowing and ediff-region/windows support
555 ;; This is a list (overlay-A overlay-B overlay-C)
556 ;; If set, Ediff compares only those parts of buffers A/B/C that lie within
557 ;; the bounds of these overlays.
558 (ediff-defvar-local ediff-narrow-bounds nil "")
560 ;; List (overlay-A overlay-B overlay-C), where each overlay spans the
561 ;; entire corresponding buffer.
562 (ediff-defvar-local ediff-wide-bounds nil "")
564 ;; Current visibility boundaries in buffers A, B, and C.
565 ;; This is also a list of overlays. When the user toggles narrow/widen,
566 ;; this list changes from ediff-wide-bounds to ediff-narrow-bounds.
567 ;; and back.
568 (ediff-defvar-local ediff-visible-bounds nil "")
570 (ediff-defvar-local ediff-start-narrowed t
571 "Non-nil means start narrowed, if doing ediff-windows-* or ediff-regions-*")
572 (ediff-defvar-local ediff-quit-widened t
573 "*Non-nil means: when finished, Ediff widens buffers A/B.
574 Actually, Ediff restores the scope of visibility that existed at startup.")
576 (defcustom ediff-keep-variants t
577 "*Nil means that non-modified variant buffers should be removed at the end of the session after some interrogation.
578 Supplying a prefix argument to the quit command `q' temporarily reverses the
579 meaning of this variable."
580 :type 'boolean
581 :group 'ediff)
583 (ediff-defvar-local ediff-highlight-all-diffs t "")
584 (defcustom ediff-highlight-all-diffs t
585 "If nil, only the selected differences are highlighted.
586 Otherwise, all difference regions are highlighted, but the selected region is
587 shown in brighter colors."
588 :type 'boolean
589 :group 'ediff-highlighting)
591 ;; A var local to each control panel buffer. Indicates highlighting style
592 ;; in effect for this buffer: `face', `ascii', nil -- temporarily
593 ;; unhighlighted, `off' -- turned off \(on a dumb terminal only\).
594 (ediff-defvar-local ediff-highlighting-style nil "")
597 ;; The suffix of the control buffer name.
598 (ediff-defvar-local ediff-control-buffer-suffix nil "")
599 ;; Same as ediff-control-buffer-suffix, but without <,>.
600 ;; It's a number rather than string.
601 (ediff-defvar-local ediff-control-buffer-number nil "")
604 ;; The original values of ediff-protected-variables for buffer A
605 (ediff-defvar-local ediff-buffer-values-orig-A nil "")
606 ;; The original values of ediff-protected-variables for buffer B
607 (ediff-defvar-local ediff-buffer-values-orig-B nil "")
608 ;; The original values of ediff-protected-variables for buffer C
609 (ediff-defvar-local ediff-buffer-values-orig-C nil "")
610 ;; The original values of ediff-protected-variables for buffer Ancestor
611 (ediff-defvar-local ediff-buffer-values-orig-Ancestor nil "")
613 ;; association between buff-type and ediff-buffer-values-orig-*
614 (defconst ediff-buffer-values-orig-alist
615 '((A . ediff-buffer-values-orig-A)
616 (B . ediff-buffer-values-orig-B)
617 (C . ediff-buffer-values-orig-C)
618 (Ancestor . ediff-buffer-values-orig-Ancestor)))
620 ;; Buffer-local variables to be saved then restored during Ediff sessions
621 (defconst ediff-protected-variables '(
622 ;;buffer-read-only
623 mode-line-format))
625 ;; Vector of differences between the variants. Each difference is
626 ;; represented by a vector of two overlays plus a vector of fine diffs,
627 ;; plus a no-fine-diffs flag. The first overlay spans the
628 ;; difference region in the A buffer and the second overlays the diff in
629 ;; the B buffer. If a difference section is empty, the corresponding
630 ;; overlay's endpoints coincide.
632 ;; The precise form of a Difference Vector for one buffer is:
633 ;; [diff diff diff ...]
634 ;; where each diff has the form:
635 ;; [diff-overlay fine-diff-vector no-fine-diffs-flag state-of-diff]
636 ;; fine-diff-vector is a vector [fine-diff-overlay fine-diff-overlay ...]
637 ;; no-fine-diffs-flag says if there are fine differences.
638 ;; state-of-difference is A, B, C, or nil, indicating which buffer is
639 ;; different from the other two (used only in 3-way jobs.
640 (ediff-defvar-local ediff-difference-vector-A nil "")
641 (ediff-defvar-local ediff-difference-vector-B nil "")
642 (ediff-defvar-local ediff-difference-vector-C nil "")
643 (ediff-defvar-local ediff-difference-vector-Ancestor nil "")
644 ;; A-list of diff vector types associated with buffer types
645 (defconst ediff-difference-vector-alist
646 '((A . ediff-difference-vector-A)
647 (B . ediff-difference-vector-B)
648 (C . ediff-difference-vector-C)
649 (Ancestor . ediff-difference-vector-Ancestor)))
651 ;; [ status status status ...]
652 ;; Each status: [state-of-merge state-of-ancestor]
653 ;; state-of-merge is default-A, default-B, prefer-A, or prefer-B. It
654 ;; indicates the way a diff region was created in buffer C.
655 ;; state-of-ancestor says if the corresponding region in ancestor buffer is
656 ;; empty.
657 (ediff-defvar-local ediff-state-of-merge nil "")
659 ;; The difference that is currently selected.
660 (ediff-defvar-local ediff-current-difference -1 "")
661 ;; Number of differences found.
662 (ediff-defvar-local ediff-number-of-differences nil "")
664 ;; Buffer containing the output of diff, which is used by Ediff to step
665 ;; through files.
666 (ediff-defvar-local ediff-diff-buffer nil "")
667 ;; Like ediff-diff-buffer, but contains context diff. It is not used by
668 ;; Ediff, but it is saved in a file, if user requests so.
669 (ediff-defvar-local ediff-custom-diff-buffer nil "")
670 ;; Buffer used for diff-style fine differences between regions.
671 (ediff-defvar-local ediff-fine-diff-buffer nil "")
672 ;; Temporary buffer used for computing fine differences.
673 (defconst ediff-tmp-buffer " *ediff-tmp*" "")
674 ;; Buffer used for messages
675 (defconst ediff-msg-buffer " *ediff-message*" "")
676 ;; Buffer containing the output of diff when diff returns errors.
677 (ediff-defvar-local ediff-error-buffer nil "")
678 ;; Buffer to display debug info
679 (ediff-defvar-local ediff-debug-buffer "*ediff-debug*" "")
681 ;; List of ediff control panels associated with each buffer A/B/C/Ancestor.
682 ;; Not used any more, but may be needed in the future.
683 (ediff-defvar-local ediff-this-buffer-ediff-sessions nil "")
685 ;; to be deleted in due time
686 ;; List of difference overlays disturbed by working with the current diff.
687 (defvar ediff-disturbed-overlays nil "")
689 ;; Priority of non-selected overlays.
690 (defvar ediff-shadow-overlay-priority 100 "")
692 (defcustom ediff-version-control-package 'vc
693 "Version control package used.
694 Currently, Ediff supports vc.el, rcs.el, pcl-cvs.el, and generic-sc.el. The
695 standard Emacs interface to RCS, CVS, SCCS, etc., is vc.el. However, some
696 people find the other two packages more convenient. Set this variable to the
697 appropriate symbol: `rcs', `pcl-cvs', or `generic-sc' if you so desire."
698 :type 'symbol
699 :group 'ediff)
702 (if ediff-xemacs-p
703 (progn
704 (fset 'ediff-read-event (symbol-function 'next-command-event))
705 (fset 'ediff-overlayp (symbol-function 'extentp))
706 (fset 'ediff-make-overlay (symbol-function 'make-extent))
707 (fset 'ediff-delete-overlay (symbol-function 'delete-extent)))
708 (fset 'ediff-read-event (symbol-function 'read-event))
709 (fset 'ediff-overlayp (symbol-function 'overlayp))
710 (fset 'ediff-make-overlay (symbol-function 'make-overlay))
711 (fset 'ediff-delete-overlay (symbol-function 'delete-overlay)))
713 ;; Check the current version against the major and minor version numbers
714 ;; using op: cur-vers op major.minor If emacs-major-version or
715 ;; emacs-minor-version are not defined, we assume that the current version
716 ;; is hopelessly outdated. We assume that emacs-major-version and
717 ;; emacs-minor-version are defined. Otherwise, for Emacs/XEmacs 19, if the
718 ;; current minor version is < 10 (xemacs) or < 23 (emacs) the return value
719 ;; will be nil (when op is =, >, or >=) and t (when op is <, <=), which may be
720 ;; incorrect. However, this gives correct result in our cases, since we are
721 ;; testing for sufficiently high Emacs versions.
722 (defun ediff-check-version (op major minor &optional type-of-emacs)
723 (if (and (boundp 'emacs-major-version) (boundp 'emacs-minor-version))
724 (and (cond ((eq type-of-emacs 'xemacs) ediff-xemacs-p)
725 ((eq type-of-emacs 'emacs) ediff-emacs-p)
726 (t t))
727 (cond ((eq op '=) (and (= emacs-minor-version minor)
728 (= emacs-major-version major)))
729 ((memq op '(> >= < <=))
730 (and (or (funcall op emacs-major-version major)
731 (= emacs-major-version major))
732 (if (= emacs-major-version major)
733 (funcall op emacs-minor-version minor)
734 t)))
736 (error "%S: Invalid op in ediff-check-version" op))))
737 (cond ((memq op '(= > >=)) nil)
738 ((memq op '(< <=)) t))))
742 ;; A fix for NeXT Step
743 ;; Should probably be eliminated in later versions.
744 (if (and (ediff-window-display-p) (eq (ediff-device-type) 'ns))
745 (progn
746 (fset 'x-display-color-p (symbol-function 'ns-display-color-p))
747 (fset 'x-color-defined-p (symbol-function 'ns-color-defined-p))
748 (fset 'x-display-pixel-height (symbol-function 'ns-display-pixel-height))
749 (fset 'x-display-pixel-width (symbol-function 'ns-display-pixel-width))
753 (defsubst ediff-color-display-p ()
754 (if ediff-emacs-p
755 (x-display-color-p)
756 (eq (device-class (selected-device)) 'color)))
759 (if (ediff-has-face-support-p)
760 (if ediff-xemacs-p
761 (progn
762 (fset 'ediff-valid-color-p (symbol-function 'valid-color-name-p))
763 (fset 'ediff-get-face (symbol-function 'get-face)))
764 ;; Temporary fix for OS/2 port of Emacs
765 ;; pm-win.el in PM-Emacs should be fixed.
766 (if (eq (ediff-device-type) 'pm)
767 (fset 'ediff-valid-color-p
768 (lambda (color) (assoc color pm-color-alist)))
769 (fset 'ediff-valid-color-p (symbol-function 'x-color-defined-p)))
770 (fset 'ediff-get-face (symbol-function 'internal-get-face))))
772 (if (ediff-window-display-p)
773 (if ediff-xemacs-p
774 (progn
775 (fset 'ediff-display-pixel-width
776 (symbol-function 'device-pixel-width))
777 (fset 'ediff-display-pixel-height
778 (symbol-function 'device-pixel-height)))
779 (fset 'ediff-display-pixel-width
780 (symbol-function 'x-display-pixel-width))
781 (fset 'ediff-display-pixel-height
782 (symbol-function 'x-display-pixel-height))))
784 ;; A-list of current-diff-overlay symbols asssociated with buf types
785 (defconst ediff-current-diff-overlay-alist
786 '((A . ediff-current-diff-overlay-A)
787 (B . ediff-current-diff-overlay-B)
788 (C . ediff-current-diff-overlay-C)
789 (Ancestor . ediff-current-diff-overlay-Ancestor)))
791 ;; A-list of current-diff-face-* symbols asssociated with buf types
792 (defconst ediff-current-diff-face-alist
793 '((A . ediff-current-diff-face-A)
794 (B . ediff-current-diff-face-B)
795 (C . ediff-current-diff-face-C)
796 (Ancestor . ediff-current-diff-face-Ancestor)))
799 (defun ediff-make-current-diff-overlay (type)
800 (if (ediff-has-face-support-p)
801 (let ((overlay (ediff-get-symbol-from-alist
802 type ediff-current-diff-overlay-alist))
803 (buffer (ediff-get-buffer type))
804 (face (face-name
805 (symbol-value
806 (ediff-get-symbol-from-alist
807 type ediff-current-diff-face-alist)))))
808 (set overlay
809 (ediff-make-bullet-proof-overlay (point-max) (point-max) buffer))
810 (ediff-set-overlay-face (symbol-value overlay) face)
811 (ediff-overlay-put (symbol-value overlay) 'ediff ediff-control-buffer))
814 (defun ediff-set-overlay-face (extent face)
815 (ediff-overlay-put extent 'face face)
816 (ediff-overlay-put extent 'help-echo 'ediff-region-help-echo))
818 ;; This does nothing in Emacs, since overlays there have no help-echo property
819 (defun ediff-region-help-echo (extent)
820 (let ((is-current (ediff-overlay-get extent 'ediff))
821 (face (ediff-overlay-get extent 'face))
822 (diff-num (ediff-overlay-get extent 'ediff-diff-num))
823 face-help)
825 ;; This happens only for refinement overlays
826 (setq face-help (and face (get face 'ediff-help-echo)))
828 (cond ((and is-current diff-num) ; current diff region
829 (format "Difference region %S -- current" (1+ diff-num)))
830 (face-help) ; refinement of current diff region
831 (diff-num ; non-current
832 (format "Difference region %S -- non-current" (1+ diff-num)))
833 (t "")) ; none
837 (defun ediff-set-face-pixmap (face pixmap)
838 "Set face pixmap on a monochrome display."
839 (if (and (ediff-window-display-p) (not (ediff-color-display-p)))
840 (condition-case nil
841 (set-face-background-pixmap face pixmap)
842 (error
843 (message "Pixmap not found for %S: %s" (face-name face) pixmap)
844 (sit-for 1)))))
846 (defun ediff-hide-face (face)
847 (if (and (ediff-has-face-support-p) ediff-emacs-p)
848 (add-to-list 'facemenu-unlisted-faces face)))
852 (defface ediff-current-diff-face-A
853 '((((class color)) (:foreground "firebrick" :background "pale green"))
854 (t (:inverse-video t)))
855 "Face for highlighting the selected difference in buffer A."
856 :group 'ediff-highlighting)
857 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
858 ;; this variable is set to nil, then again to the appropriate face.
859 (defvar ediff-current-diff-face-A 'ediff-current-diff-face-A
860 "Face for highlighting the selected difference in buffer A.
861 DO NOT CHANGE this variable. Instead, use the customization
862 widget to customize the actual face object `ediff-current-diff-face-A'
863 this variable represents.")
864 (ediff-hide-face 'ediff-current-diff-face-A)
865 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
866 ;; This means that some user customization may be trashed.
867 (if (and ediff-xemacs-p
868 (ediff-has-face-support-p)
869 (not (ediff-color-display-p)))
870 (copy-face 'modeline 'ediff-current-diff-face-A))
874 (defface ediff-current-diff-face-B
875 '((((class color)) (:foreground "DarkOrchid" :background "Yellow"))
876 (t (:inverse-video t)))
877 "Face for highlighting the selected difference in buffer B."
878 :group 'ediff-highlighting)
879 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
880 ;; this variable is set to nil, then again to the appropriate face.
881 (defvar ediff-current-diff-face-B 'ediff-current-diff-face-B
882 "Face for highlighting the selected difference in buffer B.
883 this variable. Instead, use the customization
884 widget to customize the actual face `ediff-current-diff-face-B'
885 this variable represents.")
886 (ediff-hide-face 'ediff-current-diff-face-B)
887 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
888 ;; This means that some user customization may be trashed.
889 (if (and ediff-xemacs-p
890 (ediff-has-face-support-p)
891 (not (ediff-color-display-p)))
892 (copy-face 'modeline 'ediff-current-diff-face-B))
895 (defface ediff-current-diff-face-C
896 '((((class color)) (:foreground "Navy" :background "Pink"))
897 (t (:inverse-video t)))
898 "Face for highlighting the selected difference in buffer C."
899 :group 'ediff-highlighting)
900 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
901 ;; this variable is set to nil, then again to the appropriate face.
902 (defvar ediff-current-diff-face-C 'ediff-current-diff-face-C
903 "Face for highlighting the selected difference in buffer C.
904 DO NOT CHANGE this variable. Instead, use the customization
905 widget to customize the actual face object `ediff-current-diff-face-C'
906 this variable represents.")
907 (ediff-hide-face 'ediff-current-diff-face-C)
908 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
909 ;; This means that some user customization may be trashed.
910 (if (and ediff-xemacs-p
911 (ediff-has-face-support-p)
912 (not (ediff-color-display-p)))
913 (copy-face 'modeline 'ediff-current-diff-face-C))
916 (defface ediff-current-diff-face-Ancestor
917 '((((class color)) (:foreground "Black" :background "VioletRed"))
918 (t (:inverse-video t)))
919 "Face for highlighting the selected difference in buffer Ancestor."
920 :group 'ediff-highlighting)
921 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
922 ;; this variable is set to nil, then again to the appropriate face.
923 (defvar ediff-current-diff-face-Ancestor 'ediff-current-diff-face-Ancestor
924 "Face for highlighting the selected difference in buffer Ancestor.
925 DO NOT CHANGE this variable. Instead, use the customization
926 widget to customize the actual face object `ediff-current-diff-face-Ancestor'
927 this variable represents.")
928 (ediff-hide-face 'ediff-current-diff-face-Ancestor)
929 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
930 ;; This means that some user customization may be trashed.
931 (if (and ediff-xemacs-p
932 (ediff-has-face-support-p)
933 (not (ediff-color-display-p)))
934 (copy-face 'modeline 'ediff-current-diff-face-Ancestor))
937 (defface ediff-fine-diff-face-A
938 '((((class color)) (:foreground "Navy" :background "sky blue"))
939 (t (:underline t :stipple "gray3")))
940 "Face for highlighting the refinement of the selected diff in buffer A."
941 :group 'ediff-highlighting)
942 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
943 ;; this variable is set to nil, then again to the appropriate face.
944 (defvar ediff-fine-diff-face-A 'ediff-fine-diff-face-A
945 "Face for highlighting the fine differences in buffer A.
946 DO NOT CHANGE this variable. Instead, use the customization
947 widget to customize the actual face object `ediff-fine-diff-face-A'
948 this variable represents.")
949 (ediff-hide-face 'ediff-fine-diff-face-A)
951 (defface ediff-fine-diff-face-B
952 '((((class color)) (:foreground "Black" :background "cyan"))
953 (t (:underline t :stipple "gray3")))
954 "Face for highlighting the refinement of the selected diff in buffer B."
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-B 'ediff-fine-diff-face-B
959 "Face for highlighting the fine differences in buffer B.
960 DO NOT CHANGE this variable. Instead, use the customization
961 widget to customize the actual face object `ediff-fine-diff-face-B'
962 this variable represents.")
963 (ediff-hide-face 'ediff-fine-diff-face-B)
965 (defface ediff-fine-diff-face-C
966 '((((class color)) (:foreground "Black" :background "Turquoise"))
967 (t (:underline t :stipple "gray3")))
968 "Face for highlighting the refinement of the selected diff in buffer C."
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-C 'ediff-fine-diff-face-C
973 "Face for highlighting the fine differences in buffer C.
974 DO NOT CHANGE this variable. Instead, use the customization
975 widget to customize the actual face object `ediff-fine-diff-face-C'
976 this variable represents.")
977 (ediff-hide-face 'ediff-fine-diff-face-C)
979 (defface ediff-fine-diff-face-Ancestor
980 '((((class color)) (:foreground "Black" :background "Green"))
981 (t (:underline t :stipple "gray3")))
982 "Face for highlighting the refinement of the selected diff in the ancestor buffer.
983 At present, this face is not used and no fine differences are computed for the
984 ancestor buffer."
985 :group 'ediff-highlighting)
986 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
987 ;; this variable is set to nil, then again to the appropriate face.
988 (defvar ediff-fine-diff-face-Ancestor 'ediff-fine-diff-face-Ancestor
989 "Face for highlighting the fine differences in buffer Ancestor.
990 DO NOT CHANGE this variable. Instead, use the customization
991 widget to customize the actual face object `ediff-fine-diff-face-Ancestor'
992 this variable represents.")
993 (ediff-hide-face 'ediff-fine-diff-face-Ancestor)
995 ;; Some installs don't have stipple or Stipple. So, try them in turn.
996 (defvar stipple-pixmap
997 (cond ((not (ediff-has-face-support-p)) nil)
998 ((and (boundp 'x-bitmap-file-path)
999 (locate-library "stipple" t x-bitmap-file-path)) "stipple")
1000 ((and (boundp 'mswindowsx-bitmap-file-path)
1001 (locate-library "stipple" t mswindowsx-bitmap-file-path)) "stipple")
1002 (t "Stipple")))
1004 (defface ediff-even-diff-face-A
1005 `((((class color)) (:foreground "Black" :background "light grey"))
1006 (t (:italic t :stipple ,stipple-pixmap)))
1007 "Face for highlighting even-numbered non-current differences in buffer A."
1008 :group 'ediff-highlighting)
1009 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1010 ;; this variable is set to nil, then again to the appropriate face.
1011 (defvar ediff-even-diff-face-A 'ediff-even-diff-face-A
1012 "Face for highlighting even-numbered non-current differences in buffer A.
1013 DO NOT CHANGE this variable. Instead, use the customization
1014 widget to customize the actual face object `ediff-even-diff-face-A'
1015 this variable represents.")
1016 (ediff-hide-face 'ediff-even-diff-face-A)
1018 (defface ediff-even-diff-face-B
1019 `((((class color)) (:foreground "White" :background "Grey"))
1020 (t (:italic t :stipple ,stipple-pixmap)))
1021 "Face for highlighting even-numbered non-current differences in buffer B."
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-B 'ediff-even-diff-face-B
1026 "Face for highlighting even-numbered non-current differences in buffer B.
1027 DO NOT CHANGE this variable. Instead, use the customization
1028 widget to customize the actual face object `ediff-even-diff-face-B'
1029 this variable represents.")
1030 (ediff-hide-face 'ediff-even-diff-face-B)
1032 (defface ediff-even-diff-face-C
1033 `((((class color)) (:foreground "Black" :background "light grey"))
1034 (t (:italic t :stipple ,stipple-pixmap)))
1035 "Face for highlighting even-numbered non-current differences in buffer C."
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-C 'ediff-even-diff-face-C
1040 "Face for highlighting even-numbered non-current differences in buffer C.
1041 DO NOT CHANGE this variable. Instead, use the customization
1042 widget to customize the actual face object `ediff-even-diff-face-C'
1043 this variable represents.")
1044 (ediff-hide-face 'ediff-even-diff-face-C)
1046 (defface ediff-even-diff-face-Ancestor
1047 `((((class color)) (:foreground "White" :background "Grey"))
1048 (t (:italic t :stipple ,stipple-pixmap)))
1049 "Face for highlighting even-numbered non-current differences in the ancestor buffer."
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-Ancestor 'ediff-even-diff-face-Ancestor
1054 "Face for highlighting even-numbered non-current differences in buffer Ancestor.
1055 DO NOT CHANGE this variable. Instead, use the customization
1056 widget to customize the actual face object `ediff-even-diff-face-Ancestor'
1057 this variable represents.")
1058 (ediff-hide-face 'ediff-even-diff-face-Ancestor)
1060 ;; Association between buffer types and even-diff-face symbols
1061 (defconst ediff-even-diff-face-alist
1062 '((A . ediff-even-diff-face-A)
1063 (B . ediff-even-diff-face-B)
1064 (C . ediff-even-diff-face-C)
1065 (Ancestor . ediff-even-diff-face-Ancestor)))
1067 (defface ediff-odd-diff-face-A
1068 '((((class color)) (:foreground "White" :background "Grey"))
1069 (t (:italic t :stipple "gray1")))
1070 "Face for highlighting odd-numbered non-current differences in buffer A."
1071 :group 'ediff-highlighting)
1072 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1073 ;; this variable is set to nil, then again to the appropriate face.
1074 (defvar ediff-odd-diff-face-A 'ediff-odd-diff-face-A
1075 "Face for highlighting odd-numbered non-current differences in buffer A.
1076 DO NOT CHANGE this variable. Instead, use the customization
1077 widget to customize the actual face object `ediff-odd-diff-face-A'
1078 this variable represents.")
1079 (ediff-hide-face 'ediff-odd-diff-face-A)
1082 (defface ediff-odd-diff-face-B
1083 '((((class color)) (:foreground "Black" :background "light grey"))
1084 (t (:italic t :stipple "gray1")))
1085 "Face for highlighting odd-numbered non-current differences in buffer B."
1086 :group 'ediff-highlighting)
1087 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1088 ;; this variable is set to nil, then again to the appropriate face.
1089 (defvar ediff-odd-diff-face-B 'ediff-odd-diff-face-B
1090 "Face for highlighting odd-numbered non-current differences in buffer B.
1091 DO NOT CHANGE this variable. Instead, use the customization
1092 widget to customize the actual face object `ediff-odd-diff-face-B'
1093 this variable represents.")
1094 (ediff-hide-face 'ediff-odd-diff-face-B)
1096 (defface ediff-odd-diff-face-C
1097 '((((class color)) (:foreground "White" :background "Grey"))
1098 (t (:italic t :stipple "gray1")))
1099 "Face for highlighting odd-numbered non-current differences in buffer C."
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-C 'ediff-odd-diff-face-C
1104 "Face for highlighting odd-numbered non-current differences in buffer C.
1105 DO NOT CHANGE this variable. Instead, use the customization
1106 widget to customize the actual face object `ediff-odd-diff-face-C'
1107 this variable represents.")
1108 (ediff-hide-face 'ediff-odd-diff-face-C)
1110 (defface ediff-odd-diff-face-Ancestor
1111 '((((class color)) (:foreground "Black" :background "light grey"))
1112 (t (:italic t :stipple "gray1")))
1113 "Face for highlighting odd-numbered non-current differences in the ancestor buffer."
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-Ancestor 'ediff-odd-diff-face-Ancestor
1118 "Face for highlighting odd-numbered non-current differences in buffer Ancestor.
1119 DO NOT CHANGE this variable. Instead, use the customization
1120 widget to customize the actual face object `ediff-odd-diff-face-Ancestor'
1121 this variable represents.")
1122 (ediff-hide-face 'ediff-odd-diff-face-Ancestor)
1124 ;; Association between buffer types and odd-diff-face symbols
1125 (defconst ediff-odd-diff-face-alist
1126 '((A . ediff-odd-diff-face-A)
1127 (B . ediff-odd-diff-face-B)
1128 (C . ediff-odd-diff-face-C)
1129 (Ancestor . ediff-odd-diff-face-Ancestor)))
1131 ;; A-list of fine-diff face symbols associated with buffer types
1132 (defconst ediff-fine-diff-face-alist
1133 '((A . ediff-fine-diff-face-A)
1134 (B . ediff-fine-diff-face-B)
1135 (C . ediff-fine-diff-face-C)
1136 (Ancestor . ediff-fine-diff-face-Ancestor)))
1138 ;; Help echo
1139 (put 'ediff-fine-diff-face-A 'ediff-help-echo
1140 "A `refinement' of the current difference region")
1141 (put 'ediff-fine-diff-face-B 'ediff-help-echo
1142 "A `refinement' of the current difference region")
1143 (put 'ediff-fine-diff-face-C 'ediff-help-echo
1144 "A `refinement' of the current difference region")
1145 (put 'ediff-fine-diff-face-Ancestor 'ediff-help-echo
1146 "A `refinement' of the current difference region")
1149 ;;; Overlays
1151 (ediff-defvar-local ediff-current-diff-overlay-A nil
1152 "Overlay for the current difference region in buffer A.")
1153 (ediff-defvar-local ediff-current-diff-overlay-B nil
1154 "Overlay for the current difference region in buffer B.")
1155 (ediff-defvar-local ediff-current-diff-overlay-C nil
1156 "Overlay for the current difference region in buffer C.")
1157 (ediff-defvar-local ediff-current-diff-overlay-Ancestor nil
1158 "Overlay for the current difference region in the ancestor buffer.")
1160 ;; Compute priority of ediff overlay.
1161 (defun ediff-highest-priority (start end buffer)
1162 (let ((pos (max 1 (1- start)))
1163 ovr-list)
1164 (if ediff-xemacs-p
1165 (1+ ediff-shadow-overlay-priority)
1166 (ediff-with-current-buffer buffer
1167 (while (< pos (min (point-max) (1+ end)))
1168 (setq ovr-list (append (overlays-at pos) ovr-list))
1169 (setq pos (next-overlay-change pos)))
1170 (1+ (apply '+
1171 (mapcar (lambda (ovr)
1172 (if ovr
1173 (or (ediff-overlay-get ovr 'priority) 0)
1175 ovr-list)
1177 ))))
1180 (defvar ediff-toggle-read-only-function nil
1181 "*Specifies the function to be used to toggle read-only.
1182 If nil, Ediff tries to deduce the function from the binding of C-x C-q.
1183 Normally, this is the `toggle-read-only' function, but, if version
1184 control is used, it could be `vc-toggle-read-only' or `rcs-toggle-read-only'.")
1186 (defcustom ediff-make-buffers-readonly-at-startup nil
1187 "*Make all variant buffers read-only when Ediff starts up.
1188 This property can be toggled interactively."
1189 :type 'boolean
1190 :group 'ediff)
1193 ;;; Misc
1195 ;; if nil, this silences some messages
1196 (defconst ediff-verbose-p t)
1198 (defcustom ediff-autostore-merges 'group-jobs-only
1199 "*Save the results of merge jobs automatically.
1200 Nil means don't save automatically. t means always save. Anything but nil or t
1201 means save automatically only if the merge job is part of a group of jobs, such
1202 as `ediff-merge-directory' or `ediff-merge-directory-revisions'."
1203 :type '(choice (const nil) (const t) (const group-jobs-only))
1204 :group 'ediff-merge)
1205 (make-variable-buffer-local 'ediff-autostore-merges)
1207 ;; file where the result of the merge is to be saved. used internally
1208 (ediff-defvar-local ediff-merge-store-file nil "")
1210 (defcustom ediff-no-emacs-help-in-control-buffer nil
1211 "*Non-nil means C-h should not invoke Emacs help in control buffer.
1212 Instead, C-h would jump to previous difference."
1213 :type 'boolean
1214 :group 'ediff)
1216 ;; This is the same as temporary-file-directory from Emacs 20.3.
1217 ;; Copied over here because XEmacs doesn't have this variable.
1218 (defcustom ediff-temp-file-prefix
1219 (file-name-as-directory
1220 (cond ((boundp 'temporary-file-directory) temporary-file-directory)
1221 ((fboundp 'temp-directory) (temp-directory))
1222 (t "/tmp/")))
1223 ;;; (file-name-as-directory
1224 ;;; (cond ((memq system-type '(ms-dos windows-nt))
1225 ;;; (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
1226 ;;; ((memq system-type '(vax-vms axp-vms))
1227 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
1228 ;;; (t
1229 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))
1230 "*Prefix to put on Ediff temporary file names.
1231 Do not start with `~/' or `~USERNAME/'."
1232 :type 'string
1233 :group 'ediff)
1235 (defcustom ediff-temp-file-mode 384 ; u=rw only
1236 "*Mode for Ediff temporary files."
1237 :type 'integer
1238 :group 'ediff)
1240 ;; Metacharacters that have to be protected from the shell when executing
1241 ;; a diff/diff3 command.
1242 (defcustom ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
1243 "Regexp that matches characters that must be quoted with `\\' in shell command line.
1244 This default should work without changes."
1245 :type 'string
1246 :group 'ediff)
1248 ;; needed to simulate frame-char-width in XEmacs.
1249 (defvar ediff-H-glyph (if ediff-xemacs-p (make-glyph "H")))
1252 ;; Temporary file used for refining difference regions in buffer A.
1253 (ediff-defvar-local ediff-temp-file-A nil "")
1254 ;; Temporary file used for refining difference regions in buffer B.
1255 (ediff-defvar-local ediff-temp-file-B nil "")
1256 ;; Temporary file used for refining difference regions in buffer C.
1257 (ediff-defvar-local ediff-temp-file-C nil "")
1260 ;;; In-line functions
1262 (or (fboundp 'ediff-file-remote-p) ; user supplied his own function: use it
1263 (defun ediff-file-remote-p (file-name)
1264 (car (cond ((featurep 'efs-auto) (efs-ftp-path file-name))
1265 ((fboundp 'file-remote-p) (file-remote-p file-name))
1266 (t (require 'ange-ftp)
1267 ;; Can happen only in Emacs, since XEmacs has file-remote-p
1268 (ange-ftp-ftp-name file-name))))))
1271 (defsubst ediff-frame-unsplittable-p (frame)
1272 (cdr (assq 'unsplittable (frame-parameters frame))))
1274 (defsubst ediff-get-next-window (wind prev-wind)
1275 (or (window-live-p wind)
1276 (setq wind (if prev-wind
1277 (next-window wind)
1278 (selected-window)))))
1281 (defsubst ediff-kill-buffer-carefully (buf)
1282 "Kill buffer BUF if it exists."
1283 (if (ediff-buffer-live-p buf)
1284 (kill-buffer (get-buffer buf))))
1286 (defsubst ediff-background-face (buf-type dif-num)
1287 ;; The value of dif-num is always 1- the one that user sees.
1288 ;; This is why even face is used when dif-num is odd.
1289 (ediff-get-symbol-from-alist
1290 buf-type (if (ediff-odd-p dif-num)
1291 ediff-even-diff-face-alist
1292 ediff-odd-diff-face-alist)
1296 ;; activate faces on diff regions in buffer
1297 (defun ediff-paint-background-regions-in-one-buffer (buf-type unhighlight)
1298 (let ((diff-vector
1299 (eval (ediff-get-symbol-from-alist
1300 buf-type ediff-difference-vector-alist)))
1301 overl diff-num)
1302 (mapcar (lambda (rec)
1303 (setq overl (ediff-get-diff-overlay-from-diff-record rec)
1304 diff-num (ediff-overlay-get overl 'ediff-diff-num))
1305 (if (ediff-overlay-buffer overl)
1306 ;; only if overlay is alive
1307 (ediff-set-overlay-face
1308 overl
1309 (if (not unhighlight)
1310 (ediff-background-face buf-type diff-num))))
1312 diff-vector)))
1315 ;; activate faces on diff regions in all buffers
1316 (defun ediff-paint-background-regions (&optional unhighlight)
1317 (ediff-paint-background-regions-in-one-buffer
1318 'A unhighlight)
1319 (ediff-paint-background-regions-in-one-buffer
1320 'B unhighlight)
1321 (ediff-paint-background-regions-in-one-buffer
1322 'C unhighlight)
1323 (ediff-paint-background-regions-in-one-buffer
1324 'Ancestor unhighlight))
1326 (defun ediff-highlight-diff-in-one-buffer (n buf-type)
1327 (if (ediff-buffer-live-p (ediff-get-buffer buf-type))
1328 (let* ((buff (ediff-get-buffer buf-type))
1329 (last (ediff-with-current-buffer buff (point-max)))
1330 (begin (ediff-get-diff-posn buf-type 'beg n))
1331 (end (ediff-get-diff-posn buf-type 'end n))
1332 (xtra (if (equal begin end) 1 0))
1333 (end-hilit (min last (+ end xtra)))
1334 (current-diff-overlay
1335 (symbol-value
1336 (ediff-get-symbol-from-alist
1337 buf-type ediff-current-diff-overlay-alist))))
1339 (if ediff-xemacs-p
1340 (ediff-move-overlay current-diff-overlay begin end-hilit)
1341 (ediff-move-overlay current-diff-overlay begin end-hilit buff))
1342 (ediff-overlay-put current-diff-overlay 'priority
1343 (ediff-highest-priority begin end-hilit buff))
1344 (ediff-overlay-put current-diff-overlay 'ediff-diff-num n)
1346 ;; unhighlight the background overlay for diff n so it won't
1347 ;; interfere with the current diff overlay
1348 (ediff-set-overlay-face (ediff-get-diff-overlay n buf-type) nil)
1352 (defun ediff-unhighlight-diff-in-one-buffer (buf-type)
1353 (if (ediff-buffer-live-p (ediff-get-buffer buf-type))
1354 (let ((current-diff-overlay
1355 (symbol-value
1356 (ediff-get-symbol-from-alist
1357 buf-type ediff-current-diff-overlay-alist)))
1358 (overlay
1359 (ediff-get-diff-overlay ediff-current-difference buf-type))
1362 (ediff-move-overlay current-diff-overlay 1 1)
1364 ;; rehighlight the overlay in the background of the
1365 ;; current difference region
1366 (ediff-set-overlay-face
1367 overlay
1368 (if (and (ediff-has-face-support-p)
1369 ediff-use-faces ediff-highlight-all-diffs)
1370 (ediff-background-face buf-type ediff-current-difference)))
1373 (defun ediff-unhighlight-diffs-totally-in-one-buffer (buf-type)
1374 (ediff-unselect-and-select-difference -1)
1375 (if (and (ediff-has-face-support-p) ediff-use-faces)
1376 (let* ((inhibit-quit t)
1377 (current-diff-overlay-var
1378 (ediff-get-symbol-from-alist
1379 buf-type ediff-current-diff-overlay-alist))
1380 (current-diff-overlay (symbol-value current-diff-overlay-var)))
1381 (ediff-paint-background-regions 'unhighlight)
1382 (if (ediff-overlayp current-diff-overlay)
1383 (ediff-delete-overlay current-diff-overlay))
1384 (set current-diff-overlay-var nil)
1388 (defsubst ediff-highlight-diff (n)
1389 "Put face on diff N. Invoked for X displays only."
1390 (ediff-highlight-diff-in-one-buffer n 'A)
1391 (ediff-highlight-diff-in-one-buffer n 'B)
1392 (ediff-highlight-diff-in-one-buffer n 'C)
1393 (ediff-highlight-diff-in-one-buffer n 'Ancestor)
1397 (defsubst ediff-unhighlight-diff ()
1398 "Remove overlays from buffers A, B, and C."
1399 (ediff-unhighlight-diff-in-one-buffer 'A)
1400 (ediff-unhighlight-diff-in-one-buffer 'B)
1401 (ediff-unhighlight-diff-in-one-buffer 'C)
1402 (ediff-unhighlight-diff-in-one-buffer 'Ancestor)
1405 ;; delete highlighting overlays, restore faces to their original form
1406 (defsubst ediff-unhighlight-diffs-totally ()
1407 (ediff-unhighlight-diffs-totally-in-one-buffer 'A)
1408 (ediff-unhighlight-diffs-totally-in-one-buffer 'B)
1409 (ediff-unhighlight-diffs-totally-in-one-buffer 'C)
1410 (ediff-unhighlight-diffs-totally-in-one-buffer 'Ancestor)
1414 ;; arg is a record for a given diff in a difference vector
1415 ;; this record is itself a vector
1416 (defsubst ediff-clear-fine-diff-vector (diff-record)
1417 (if diff-record
1418 (mapcar 'ediff-delete-overlay
1419 (ediff-get-fine-diff-vector-from-diff-record diff-record))))
1421 (defsubst ediff-clear-fine-differences-in-one-buffer (n buf-type)
1422 (ediff-clear-fine-diff-vector (ediff-get-difference n buf-type))
1423 (ediff-set-fine-diff-vector n buf-type nil))
1425 (defsubst ediff-clear-fine-differences (n)
1426 (ediff-clear-fine-differences-in-one-buffer n 'A)
1427 (ediff-clear-fine-differences-in-one-buffer n 'B)
1428 (if ediff-3way-job
1429 (ediff-clear-fine-differences-in-one-buffer n 'C)))
1432 (defsubst ediff-convert-fine-diffs-to-overlays (diff-list region-num)
1433 (ediff-set-fine-overlays-in-one-buffer 'A diff-list region-num)
1434 (ediff-set-fine-overlays-in-one-buffer 'B diff-list region-num)
1435 (if ediff-3way-job
1436 (ediff-set-fine-overlays-in-one-buffer 'C diff-list region-num)
1439 (defsubst ediff-mouse-event-p (event)
1440 (if ediff-xemacs-p
1441 (button-event-p event)
1442 (string-match "mouse" (format "%S" (event-basic-type event)))
1446 (defsubst ediff-key-press-event-p (event)
1447 (if ediff-xemacs-p
1448 (key-press-event-p event)
1449 (or (char-or-string-p event) (symbolp event))))
1451 (defun ediff-event-point (event)
1452 (cond ((ediff-mouse-event-p event)
1453 (if ediff-xemacs-p
1454 (event-point event)
1455 (posn-point (event-start event))))
1456 ((ediff-key-press-event-p event)
1457 (point))
1458 (t (error))))
1460 (defun ediff-event-buffer (event)
1461 (cond ((ediff-mouse-event-p event)
1462 (if ediff-xemacs-p
1463 (event-buffer event)
1464 (window-buffer (posn-window (event-start event)))))
1465 ((ediff-key-press-event-p event)
1466 (current-buffer))
1467 (t (error))))
1470 (defsubst ediff-frame-iconified-p (frame)
1471 (if (and (ediff-window-display-p) (frame-live-p frame))
1472 (if ediff-xemacs-p
1473 (frame-iconified-p frame)
1474 (eq (frame-visible-p frame) 'icon))))
1476 (defsubst ediff-window-visible-p (wind)
1477 ;; under TTY, window-live-p also means window is visible
1478 (and (window-live-p wind)
1479 (or (not (ediff-window-display-p))
1480 (frame-visible-p (window-frame wind)))))
1483 (defsubst ediff-frame-char-width (frame)
1484 (if ediff-xemacs-p
1485 (/ (frame-pixel-width frame) (frame-width frame))
1486 (frame-char-width frame)))
1488 (defun ediff-reset-mouse (&optional frame do-not-grab-mouse)
1489 (or frame (setq frame (selected-frame)))
1490 (if (ediff-window-display-p)
1491 (let ((frame-or-wind frame))
1492 (if ediff-xemacs-p
1493 (setq frame-or-wind (frame-selected-window frame)))
1494 (or do-not-grab-mouse
1495 ;; don't set mouse if the user said to never do this
1496 (not ediff-grab-mouse)
1497 ;; Don't grab on quit, if the user doesn't want to.
1498 ;; If ediff-grab-mouse = t, then mouse won't be grabbed for
1499 ;; sessions that are not part of a group (this is done in
1500 ;; ediff-recenter). The condition below affects only terminating
1501 ;; sessions in session groups (in which case mouse is warped into
1502 ;; a meta buffer).
1503 (and (eq ediff-grab-mouse 'maybe)
1504 (memq this-command '(ediff-quit ediff-update-diffs)))
1505 (set-mouse-position frame-or-wind 1 0))
1508 (defsubst ediff-spy-after-mouse ()
1509 (setq ediff-mouse-pixel-position (mouse-pixel-position)))
1511 ;; It is not easy to find out when the user grabs the mouse, since emacs and
1512 ;; xemacs behave differently when mouse is not in any frame. Also, this is
1513 ;; sensitive to when the user grabbed mouse. Not used for now.
1514 (defun ediff-user-grabbed-mouse ()
1515 (if ediff-mouse-pixel-position
1516 (cond ((not (eq (car ediff-mouse-pixel-position)
1517 (car (mouse-pixel-position)))))
1518 ((and (car (cdr ediff-mouse-pixel-position))
1519 (car (cdr (mouse-pixel-position)))
1520 (cdr (cdr ediff-mouse-pixel-position))
1521 (cdr (cdr (mouse-pixel-position))))
1522 (not (and (< (abs (- (car (cdr ediff-mouse-pixel-position))
1523 (car (cdr (mouse-pixel-position)))))
1524 ediff-mouse-pixel-threshold)
1525 (< (abs (- (cdr (cdr ediff-mouse-pixel-position))
1526 (cdr (cdr (mouse-pixel-position)))))
1527 ediff-mouse-pixel-threshold))))
1528 (t nil))))
1530 (defsubst ediff-frame-char-height (frame)
1531 (if ediff-xemacs-p
1532 (glyph-height ediff-H-glyph (selected-window frame))
1533 (frame-char-height frame)))
1535 ;; Some overlay functions
1537 (defsubst ediff-overlay-start (overl)
1538 (if (ediff-overlayp overl)
1539 (if ediff-emacs-p
1540 (overlay-start overl)
1541 (extent-start-position overl))))
1543 (defsubst ediff-overlay-end (overl)
1544 (if (ediff-overlayp overl)
1545 (if ediff-emacs-p
1546 (overlay-end overl)
1547 (extent-end-position overl))))
1549 (defsubst ediff-empty-overlay-p (overl)
1550 (= (ediff-overlay-start overl) (ediff-overlay-end overl)))
1552 ;; like overlay-buffer in Emacs. In XEmacs, returns nil if the extent is
1553 ;; dead. Otherwise, works like extent-buffer
1554 (defun ediff-overlay-buffer (overl)
1555 (if ediff-emacs-p
1556 (overlay-buffer overl)
1557 (and (extent-live-p overl) (extent-object overl))))
1559 ;; like overlay-get in Emacs. In XEmacs, returns nil if the extent is
1560 ;; dead. Otherwise, like extent-property
1561 (defun ediff-overlay-get (overl property)
1562 (if ediff-emacs-p
1563 (overlay-get overl property)
1564 (and (extent-live-p overl) (extent-property overl property))))
1567 ;; These two functions are here because XEmacs refuses to
1568 ;; handle overlays whose buffers were deleted.
1569 (defun ediff-move-overlay (overlay beg end &optional buffer)
1570 "Calls `move-overlay' in Emacs and `set-extent-endpoints' in Lemacs.
1571 Checks if overlay's buffer exists before actually doing the move."
1572 (let ((buf (and overlay (ediff-overlay-buffer overlay))))
1573 (if (ediff-buffer-live-p buf)
1574 (if ediff-xemacs-p
1575 (set-extent-endpoints overlay beg end)
1576 (move-overlay overlay beg end buffer))
1577 ;; buffer's dead
1578 (if overlay
1579 (ediff-delete-overlay overlay)))))
1581 (defun ediff-overlay-put (overlay prop value)
1582 "Calls `overlay-put' or `set-extent-property' depending on Emacs version.
1583 Checks if overlay's buffer exists."
1584 (if (ediff-buffer-live-p (ediff-overlay-buffer overlay))
1585 (if ediff-xemacs-p
1586 (set-extent-property overlay prop value)
1587 (overlay-put overlay prop value))
1588 (ediff-delete-overlay overlay)))
1590 ;; Some diff region tests
1592 ;; t if diff region is empty.
1593 ;; In case of buffer C, t also if it is not a 3way
1594 ;; comparison job (merging jobs return t as well).
1595 (defun ediff-empty-diff-region-p (n buf-type)
1596 (if (eq buf-type 'C)
1597 (or (not ediff-3way-comparison-job)
1598 (= (ediff-get-diff-posn 'C 'beg n)
1599 (ediff-get-diff-posn 'C 'end n)))
1600 (= (ediff-get-diff-posn buf-type 'beg n)
1601 (ediff-get-diff-posn buf-type 'end n))))
1603 ;; Test if diff region is white space only.
1604 ;; If 2-way job and buf-type = C, then returns t.
1605 (defun ediff-whitespace-diff-region-p (n buf-type)
1606 (or (and (eq buf-type 'C) (not ediff-3way-job))
1607 (ediff-empty-diff-region-p n buf-type)
1608 (let ((beg (ediff-get-diff-posn buf-type 'beg n))
1609 (end (ediff-get-diff-posn buf-type 'end n)))
1610 (ediff-with-current-buffer (ediff-get-buffer buf-type)
1611 (save-excursion
1612 (goto-char beg)
1613 (skip-chars-forward ediff-whitespace)
1614 (>= (point) end))))))
1616 ;; temporarily uses DIR to abbreviate file name
1617 ;; if DIR is nil, use default-directory
1618 (defun ediff-abbreviate-file-name (file &optional dir)
1619 (cond ((stringp dir)
1620 (let ((directory-abbrev-alist (list (cons dir ""))))
1621 (abbreviate-file-name file)))
1622 (ediff-emacs-p (abbreviate-file-name file))
1623 (t ; XEmacs requires addl argument
1624 (abbreviate-file-name file t))))
1626 ;; Takes a directory and returns the parent directory.
1627 ;; does nothing to `/'. If the ARG is a regular file,
1628 ;; strip the file AND the last dir.
1629 (defun ediff-strip-last-dir (dir)
1630 (if (not (stringp dir)) (setq dir default-directory))
1631 (setq dir (expand-file-name dir))
1632 (or (file-directory-p dir) (setq dir (file-name-directory dir)))
1633 (let* ((pos (1- (length dir)))
1634 (last-char (aref dir pos)))
1635 (if (and (> pos 0) (= last-char ?/))
1636 (setq dir (substring dir 0 pos)))
1637 (ediff-abbreviate-file-name (file-name-directory dir))))
1639 (defun ediff-truncate-string-left (str newlen)
1640 ;; leave space for ... on the left
1641 (let ((len (length str))
1642 substr)
1643 (if (<= len newlen)
1645 (setq newlen (max 0 (- newlen 3)))
1646 (setq substr (substring str (max 0 (- len 1 newlen))))
1647 (concat "..." substr))))
1649 (defsubst ediff-nonempty-string-p (string)
1650 (and (stringp string) (not (string= string ""))))
1652 (defun ediff-abbrev-jobname (jobname)
1653 (cond ((eq jobname 'ediff-directories)
1654 "Compare two directories")
1655 ((eq jobname 'ediff-files)
1656 "Compare two files")
1657 ((eq jobname 'ediff-buffers)
1658 "Compare two buffers")
1659 ((eq jobname 'ediff-directories3)
1660 "Compare three directories")
1661 ((eq jobname 'ediff-files3)
1662 "Compare three files")
1663 ((eq jobname 'ediff-buffers3)
1664 "Compare three buffers")
1665 ((eq jobname 'ediff-revision)
1666 "Compare file with a version")
1667 ((eq jobname 'ediff-directory-revisions)
1668 "Compare dir files with versions")
1669 ((eq jobname 'ediff-merge-directory-revisions)
1670 "Merge dir files with versions")
1671 ((eq jobname 'ediff-merge-directory-revisions-with-ancestor)
1672 "Merge dir versions via ancestors")
1674 (let* ((str (substring (symbol-name jobname) 6))
1675 (len (length str))
1676 (pos 0))
1677 (while (< pos len)
1678 (if (= pos 0)
1679 (aset str pos (upcase (aref str pos))))
1680 (if (= (aref str pos) ?-)
1681 (aset str pos ?\ ))
1682 (setq pos (1+ pos)))
1683 str))))
1687 (defsubst ediff-get-region-contents (n buf-type ctrl-buf &optional start end)
1688 (ediff-with-current-buffer
1689 (ediff-with-current-buffer ctrl-buf (ediff-get-buffer buf-type))
1690 (buffer-substring
1691 (or start (ediff-get-diff-posn buf-type 'beg n ctrl-buf))
1692 (or end (ediff-get-diff-posn buf-type 'end n ctrl-buf)))))
1694 ;; If ediff modified mode line, strip the modification
1695 (defsubst ediff-strip-mode-line-format ()
1696 (if (member (car mode-line-format) '(" A: " " B: " " C: " " Ancestor: "))
1697 (setq mode-line-format (nth 2 mode-line-format))))
1699 ;; Verify that we have a difference selected.
1700 (defsubst ediff-valid-difference-p (&optional n)
1701 (or n (setq n ediff-current-difference))
1702 (and (>= n 0) (< n ediff-number-of-differences)))
1704 (defsubst ediff-show-all-diffs (n)
1705 "Don't skip difference regions."
1706 nil)
1708 (defsubst Xor (a b)
1709 (or (and a (not b)) (and (not a) b)))
1711 (defsubst ediff-message-if-verbose (string &rest args)
1712 (if ediff-verbose-p
1713 (apply 'message string args)))
1715 (defun ediff-file-attributes (filename attr-number)
1716 (if (ediff-file-remote-p filename)
1718 (nth attr-number (file-attributes filename))))
1720 (defsubst ediff-file-size (filename)
1721 (ediff-file-attributes filename 7))
1722 (defsubst ediff-file-modtime (filename)
1723 (ediff-file-attributes filename 5))
1726 (defun ediff-convert-standard-filename (fname)
1727 (if (fboundp 'convert-standard-filename)
1728 (convert-standard-filename fname)
1729 fname))
1732 ;;; Local Variables:
1733 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1734 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1735 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1736 ;;; End:
1738 (provide 'ediff-init)
1741 ;;; ediff-init.el ends here