Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / lisp / vc / ediff-init.el
blob06bbc47b61e8106962738b142c289d30afe400e6
1 ;;; ediff-init.el --- Macros, variables, and defsubsts used by Ediff
3 ;; Copyright (C) 1994-2014 Free Software Foundation, Inc.
5 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
6 ;; Package: ediff
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 ;; Start compiler pacifier
28 (defvar ediff-metajob-name)
29 (defvar ediff-meta-buffer)
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)
36 (defvar mswindowsx-bitmap-file-path)
37 ;; end pacifier
39 (defvar ediff-force-faces nil
40 "If t, Ediff will think that it is running on a display that supports faces.
41 This is provided as a temporary relief for users of face-capable displays
42 that Ediff doesn't know about.")
44 ;; Are we running as a window application or on a TTY?
45 (defsubst ediff-device-type ()
46 (if (featurep 'xemacs)
47 (device-type (selected-device))
48 window-system))
50 ;; in XEmacs: device-type is tty on tty and stream in batch.
51 (defun ediff-window-display-p ()
52 (and (ediff-device-type) (not (memq (ediff-device-type) '(tty pc stream)))))
54 ;; test if supports faces
55 (defun ediff-has-face-support-p ()
56 (cond ((ediff-window-display-p))
57 (ediff-force-faces)
58 ((ediff-color-display-p))
59 ((featurep 'emacs) (memq (ediff-device-type) '(pc)))
60 ((featurep 'xemacs) (memq (ediff-device-type) '(tty pc)))
63 ;; toolbar support for emacs hasn't been implemented in ediff
64 (defun ediff-has-toolbar-support-p ()
65 (if (featurep 'xemacs)
66 (if (featurep 'toolbar) (console-on-window-system-p))))
69 (defun ediff-has-gutter-support-p ()
70 (if (featurep 'xemacs)
71 (if (featurep 'gutter) (console-on-window-system-p))))
73 (defun ediff-use-toolbar-p ()
74 (and (ediff-has-toolbar-support-p) ;Can it do it ?
75 (boundp 'ediff-use-toolbar-p)
76 ediff-use-toolbar-p)) ;Does the user want it ?
78 ;; Defines VAR as an advertised local variable.
79 ;; Performs a defvar, then executes `make-variable-buffer-local' on
80 ;; the variable. Also sets the `permanent-local' property,
81 ;; so that `kill-all-local-variables' (called by major-mode setting
82 ;; commands) won't destroy Ediff control variables.
84 ;; Plagiarized from `emerge-defvar-local' for XEmacs.
85 (defmacro ediff-defvar-local (var value doc)
86 "Defines VAR as a local variable."
87 (declare (indent defun))
88 `(progn
89 (defvar ,var ,value ,doc)
90 (make-variable-buffer-local ',var)
91 (put ',var 'permanent-local t)))
95 ;; Variables that control each Ediff session---local to the control buffer.
97 ;; Mode variables
98 ;; The buffer in which the A variant is stored.
99 (ediff-defvar-local ediff-buffer-A nil "")
100 ;; The buffer in which the B variant is stored.
101 (ediff-defvar-local ediff-buffer-B nil "")
102 ;; The buffer in which the C variant is stored or where the merge buffer lives.
103 (ediff-defvar-local ediff-buffer-C nil "")
104 ;; Ancestor buffer
105 (ediff-defvar-local ediff-ancestor-buffer nil "")
106 ;; The Ediff control buffer
107 (ediff-defvar-local ediff-control-buffer nil "")
109 (ediff-defvar-local ediff-temp-indirect-buffer nil
110 "If t, the buffer is a temporary indirect buffer.
111 It needs to be killed when we quit the session.")
114 ;; Association between buff-type and ediff-buffer-*
115 (defconst ediff-buffer-alist
116 '((?A . ediff-buffer-A)
117 (?B . ediff-buffer-B)
118 (?C . ediff-buffer-C)))
120 ;;; Macros
121 (defmacro ediff-odd-p (arg)
122 `(eq (logand ,arg 1) 1))
124 (defmacro ediff-buffer-live-p (buf)
125 `(and ,buf (get-buffer ,buf) (buffer-name (get-buffer ,buf))))
127 (defmacro ediff-get-buffer (arg)
128 `(cond ((eq ,arg 'A) ediff-buffer-A)
129 ((eq ,arg 'B) ediff-buffer-B)
130 ((eq ,arg 'C) ediff-buffer-C)
131 ((eq ,arg 'Ancestor) ediff-ancestor-buffer)
134 (defmacro ediff-get-value-according-to-buffer-type (buf-type list)
135 `(cond ((eq ,buf-type 'A) (nth 0 ,list))
136 ((eq ,buf-type 'B) (nth 1 ,list))
137 ((eq ,buf-type 'C) (nth 2 ,list))
140 (defmacro ediff-char-to-buftype (arg)
141 `(cond ((memq ,arg '(?a ?A)) 'A)
142 ((memq ,arg '(?b ?B)) 'B)
143 ((memq ,arg '(?c ?C)) 'C)
147 ;; A-list is supposed to be of the form (A . symb) (B . symb)...)
148 ;; where the first part of any association is a buffer type and the second is
149 ;; an appropriate symbol. Given buffer-type, this function returns the
150 ;; symbol. This is used to avoid using `intern'
151 (defsubst ediff-get-symbol-from-alist (buf-type alist)
152 (cdr (assoc buf-type alist)))
154 (defconst ediff-difference-vector-alist
155 '((A . ediff-difference-vector-A)
156 (B . ediff-difference-vector-B)
157 (C . ediff-difference-vector-C)
158 (Ancestor . ediff-difference-vector-Ancestor)))
160 (defmacro ediff-get-difference (n buf-type)
161 `(aref
162 (symbol-value
163 (ediff-get-symbol-from-alist
164 ,buf-type ediff-difference-vector-alist))
165 ,n))
167 ;; Tell if it has been previously determined that the region has
168 ;; no diffs other than the white space and newlines
169 ;; The argument, N, is the diff region number used by Ediff to index the
170 ;; diff vector. It is 1 less than the number seen by the user.
171 ;; Returns:
172 ;; t if the diffs are whitespace in all buffers
173 ;; 'A (in 3-buf comparison only) if there are only whitespace
174 ;; diffs in bufs B and C
175 ;; 'B (in 3-buf comparison only) if there are only whitespace
176 ;; diffs in bufs A and C
177 ;; 'C (in 3-buf comparison only) if there are only whitespace
178 ;; diffs in bufs A and B
180 ;; A Difference Vector has the form:
181 ;; [diff diff diff ...]
182 ;; where each diff has the form:
183 ;; [overlay fine-diff-vector no-fine-diffs-flag state-of-difference]
184 ;; fine-diff-vector is a vector [fine-diff fine-diff fine-diff ...]
185 ;; no-fine-diffs-flag says if there are fine differences.
186 ;; state-of-difference is A, B, C, or nil, indicating which buffer is
187 ;; different from the other two (used only in 3-way jobs).
188 (defmacro ediff-no-fine-diffs-p (n)
189 `(aref (ediff-get-difference ,n 'A) 2))
191 (defmacro ediff-get-diff-overlay-from-diff-record (diff-rec)
192 `(aref ,diff-rec 0))
194 (defmacro ediff-get-diff-overlay (n buf-type)
195 `(ediff-get-diff-overlay-from-diff-record
196 (ediff-get-difference ,n ,buf-type)))
198 (defmacro ediff-get-fine-diff-vector-from-diff-record (diff-rec)
199 `(aref ,diff-rec 1))
201 (defmacro ediff-set-fine-diff-vector (n buf-type fine-vec)
202 `(aset (ediff-get-difference ,n ,buf-type) 1 ,fine-vec))
204 (defmacro ediff-get-state-of-diff (n buf-type)
205 `(if (ediff-buffer-live-p ediff-buffer-C)
206 (aref (ediff-get-difference ,n ,buf-type) 3)))
207 (defmacro ediff-set-state-of-diff (n buf-type val)
208 `(aset (ediff-get-difference ,n ,buf-type) 3 ,val))
210 (defmacro ediff-get-state-of-merge (n)
211 `(if ediff-state-of-merge
212 (aref (aref ediff-state-of-merge ,n) 0)))
213 (defmacro ediff-set-state-of-merge (n val)
214 `(if ediff-state-of-merge
215 (aset (aref ediff-state-of-merge ,n) 0 ,val)))
217 (defmacro ediff-get-state-of-ancestor (n)
218 `(if ediff-state-of-merge
219 (aref (aref ediff-state-of-merge ,n) 1)))
221 ;; if flag is t, puts a mark on diff region saying that
222 ;; the differences are in white space only. If flag is nil,
223 ;; the region is marked as essential (i.e., differences are
224 ;; not just in the white space and newlines.)
225 (defmacro ediff-mark-diff-as-space-only (n flag)
226 `(aset (ediff-get-difference ,n 'A) 2 ,flag))
228 (defmacro ediff-get-fine-diff-vector (n buf-type)
229 `(ediff-get-fine-diff-vector-from-diff-record
230 (ediff-get-difference ,n ,buf-type)))
232 ;; Macro to switch to BUFFER, evaluate BODY, returns to original buffer.
233 ;; Doesn't save the point and mark.
234 ;; This is `with-current-buffer' with the added test for live buffers."
235 (defmacro ediff-with-current-buffer (buffer &rest body)
236 "Evaluates BODY in BUFFER."
237 (declare (indent 1) (debug (form body)))
238 `(if (ediff-buffer-live-p ,buffer)
239 (save-current-buffer
240 (set-buffer ,buffer)
241 ,@body)
242 (or (eq this-command 'ediff-quit)
243 (error ediff-KILLED-VITAL-BUFFER))
247 (defsubst ediff-multiframe-setup-p ()
248 (and (ediff-window-display-p) ediff-multiframe))
250 (defmacro ediff-narrow-control-frame-p ()
251 `(and (ediff-multiframe-setup-p)
252 (equal ediff-help-message ediff-brief-message-string)))
254 (defmacro ediff-3way-comparison-job ()
255 `(memq
256 ediff-job-name
257 '(ediff-files3 ediff-buffers3)))
258 (ediff-defvar-local ediff-3way-comparison-job nil "")
260 (defmacro ediff-merge-job ()
261 `(memq
262 ediff-job-name
263 '(ediff-merge-files
264 ediff-merge-buffers
265 ediff-merge-files-with-ancestor
266 ediff-merge-buffers-with-ancestor
267 ediff-merge-revisions
268 ediff-merge-revisions-with-ancestor)))
269 (ediff-defvar-local ediff-merge-job nil "")
271 (defmacro ediff-patch-job ()
272 `(eq ediff-job-name 'epatch))
274 (defmacro ediff-merge-with-ancestor-job ()
275 `(memq
276 ediff-job-name
277 '(ediff-merge-files-with-ancestor
278 ediff-merge-buffers-with-ancestor
279 ediff-merge-revisions-with-ancestor)))
280 (ediff-defvar-local ediff-merge-with-ancestor-job nil "")
282 (defmacro ediff-3way-job ()
283 `(or ediff-3way-comparison-job ediff-merge-job))
284 (ediff-defvar-local ediff-3way-job nil "")
286 ;; A diff3 job is like a 3way job, but ediff-merge doesn't require the use
287 ;; of diff3.
288 (defmacro ediff-diff3-job ()
289 `(or ediff-3way-comparison-job
290 ediff-merge-with-ancestor-job))
291 (ediff-defvar-local ediff-diff3-job nil "")
293 (defmacro ediff-windows-job ()
294 `(memq ediff-job-name '(ediff-windows-wordwise ediff-windows-linewise)))
295 (ediff-defvar-local ediff-windows-job nil "")
297 (defmacro ediff-word-mode-job ()
298 `(memq ediff-job-name '(ediff-windows-wordwise ediff-regions-wordwise)))
299 (ediff-defvar-local ediff-word-mode-job nil "")
301 (defmacro ediff-narrow-job ()
302 `(memq ediff-job-name '(ediff-windows-wordwise
303 ediff-regions-wordwise
304 ediff-windows-linewise
305 ediff-regions-linewise)))
306 (ediff-defvar-local ediff-narrow-job nil "")
308 ;; Note: ediff-merge-directory-revisions-with-ancestor is not treated as an
309 ;; ancestor metajob, since it behaves differently.
310 (defsubst ediff-ancestor-metajob (&optional metajob)
311 (memq (or metajob ediff-metajob-name)
312 '(ediff-merge-directories-with-ancestor
313 ediff-merge-filegroups-with-ancestor)))
314 (defsubst ediff-revision-metajob (&optional metajob)
315 (memq (or metajob ediff-metajob-name)
316 '(ediff-directory-revisions
317 ediff-merge-directory-revisions
318 ediff-merge-directory-revisions-with-ancestor)))
319 (defsubst ediff-patch-metajob (&optional metajob)
320 (memq (or metajob ediff-metajob-name)
321 '(ediff-multifile-patch)))
322 ;; metajob involving only one group of files, such as multipatch or directory
323 ;; revision
324 (defsubst ediff-one-filegroup-metajob (&optional metajob)
325 (or (ediff-revision-metajob metajob)
326 (ediff-patch-metajob metajob)
327 ;; add more here
329 ;; jobs suitable for the operation of collecting diffs into a multifile patch
330 (defsubst ediff-collect-diffs-metajob (&optional metajob)
331 (memq (or metajob ediff-metajob-name)
332 '(ediff-directories
333 ediff-merge-directories
334 ediff-merge-directories-with-ancestor
335 ediff-directory-revisions
336 ediff-merge-directory-revisions
337 ediff-merge-directory-revisions-with-ancestor
338 ;; add more here
340 (defsubst ediff-merge-metajob (&optional metajob)
341 (memq (or metajob ediff-metajob-name)
342 '(ediff-merge-directories
343 ediff-merge-directories-with-ancestor
344 ediff-merge-directory-revisions
345 ediff-merge-directory-revisions-with-ancestor
346 ediff-merge-filegroups-with-ancestor
347 ;; add more here
350 (defsubst ediff-metajob3 (&optional metajob)
351 (memq (or metajob ediff-metajob-name)
352 '(ediff-merge-directories-with-ancestor
353 ediff-merge-filegroups-with-ancestor
354 ediff-directories3
355 ediff-filegroups3)))
356 (defsubst ediff-comparison-metajob3 (&optional metajob)
357 (memq (or metajob ediff-metajob-name)
358 '(ediff-directories3 ediff-filegroups3)))
360 ;; with no argument, checks if we are in ediff-control-buffer
361 ;; with argument, checks if we are in ediff-meta-buffer
362 (defun ediff-in-control-buffer-p (&optional meta-buf-p)
363 (and (boundp 'ediff-control-buffer)
364 (eq (if meta-buf-p ediff-meta-buffer ediff-control-buffer)
365 (current-buffer))))
367 (defsubst ediff-barf-if-not-control-buffer (&optional meta-buf-p)
368 (or (ediff-in-control-buffer-p meta-buf-p)
369 (error "%S: This command runs in Ediff Control Buffer only!"
370 this-command)))
372 (defgroup ediff-highlighting nil
373 "Highlighting of difference regions in Ediff."
374 :prefix "ediff-"
375 :group 'ediff)
377 (defgroup ediff-merge nil
378 "Merging utilities."
379 :prefix "ediff-"
380 :group 'ediff)
382 (defgroup ediff-hook nil
383 "Hooks run by Ediff."
384 :prefix "ediff-"
385 :group 'ediff)
387 ;; Hook variables
389 (defcustom ediff-before-setup-hook nil
390 "Hooks to run before Ediff begins to set up windows and buffers.
391 This hook can be used to save the previous window config, which can be restored
392 on ediff-quit or ediff-suspend."
393 :type 'hook
394 :group 'ediff-hook)
395 (defcustom ediff-before-setup-windows-hook nil
396 "Hooks to run before Ediff sets its window configuration.
397 This hook is run every time when Ediff arranges its windows.
398 This happens each time Ediff detects that the windows were messed up by the
399 user."
400 :type 'hook
401 :group 'ediff-hook)
402 (defcustom ediff-after-setup-windows-hook nil
403 "Hooks to run after Ediff sets its window configuration.
404 This can be used to set up control window or icon in a desired place."
405 :type 'hook
406 :group 'ediff-hook)
407 (defcustom ediff-before-setup-control-frame-hook nil
408 "Hooks run before setting up the frame to display Ediff Control Panel.
409 Can be used to change control frame parameters to position it where it
410 is desirable."
411 :type 'hook
412 :group 'ediff-hook)
413 (defcustom ediff-after-setup-control-frame-hook nil
414 "Hooks run after setting up the frame to display Ediff Control Panel.
415 Can be used to move the frame where it is desired."
416 :type 'hook
417 :group 'ediff-hook)
418 (defcustom ediff-startup-hook nil
419 "Hooks to run in the control buffer after Ediff has been set up and is ready for the job."
420 :type 'hook
421 :group 'ediff-hook)
422 (defcustom ediff-select-hook nil
423 "Hooks to run after a difference has been selected."
424 :type 'hook
425 :group 'ediff-hook)
426 (defcustom ediff-unselect-hook nil
427 "Hooks to run after a difference has been unselected."
428 :type 'hook
429 :group 'ediff-hook)
430 (defcustom ediff-prepare-buffer-hook nil
431 "Hooks run after buffers A, B, and C are set up.
432 For each buffer, the hooks are run with that buffer made current."
433 :type 'hook
434 :group 'ediff-hook)
435 (defcustom ediff-load-hook nil
436 "Hook run after Ediff is loaded. Can be used to change defaults."
437 :type 'hook
438 :group 'ediff-hook)
440 (defcustom ediff-mode-hook nil
441 "Hook run just after ediff-mode is set up in the control buffer.
442 This is done before any windows or frames are created. One can use it to
443 set local variables that determine how the display looks like."
444 :type 'hook
445 :group 'ediff-hook)
446 (defcustom ediff-keymap-setup-hook nil
447 "Hook run just after the default bindings in Ediff keymap are set up."
448 :type 'hook
449 :group 'ediff-hook)
451 (defcustom ediff-display-help-hook nil
452 "Hooks run after preparing the help message."
453 :type 'hook
454 :group 'ediff-hook)
456 (defcustom ediff-suspend-hook nil
457 "Hooks to run in the Ediff control buffer when Ediff is suspended."
458 :type 'hook
459 :group 'ediff-hook)
460 (defcustom ediff-quit-hook nil
461 "Hooks to run in the Ediff control buffer after finishing Ediff."
462 :type 'hook
463 :group 'ediff-hook)
464 (defcustom ediff-cleanup-hook nil
465 "Hooks to run on exiting Ediff but before killing the control and variant buffers."
466 :type 'hook
467 :group 'ediff-hook)
469 ;; Error messages
470 (defconst ediff-KILLED-VITAL-BUFFER
471 "You have killed a vital Ediff buffer---you must leave Ediff now!")
472 (defconst ediff-NO-DIFFERENCES
473 "Sorry, comparison of identical variants is not what I am made for...")
474 (defconst ediff-BAD-DIFF-NUMBER
475 ;; %S stands for this-command, %d - diff number, %d - max diff
476 "%S: Bad diff region number, %d. Valid numbers are 1 to %d")
477 (defconst ediff-BAD-INFO (format "
478 *** The Info file for Ediff, a part of the standard distribution
479 *** of %sEmacs, does not seem to be properly installed.
481 *** Please contact your system administrator. "
482 (if (featurep 'xemacs) "X" "")))
484 ;; Selective browsing
486 (ediff-defvar-local ediff-skip-diff-region-function 'ediff-show-all-diffs
487 "Function that determines the next/previous diff region to show.
488 Should return t for regions to be ignored and nil otherwise.
489 This function gets a region number as an argument. The region number
490 is the one used internally by Ediff. It is 1 less than the number seen
491 by the user.")
493 (ediff-defvar-local ediff-hide-regexp-matches-function
494 'ediff-hide-regexp-matches
495 "Function to use in determining which regions to hide.
496 See the documentation string of `ediff-hide-regexp-matches' for details.")
497 (ediff-defvar-local ediff-focus-on-regexp-matches-function
498 'ediff-focus-on-regexp-matches
499 "Function to use in determining which regions to focus on.
500 See the documentation string of `ediff-focus-on-regexp-matches' for details.")
502 ;; Regexp that determines buf A regions to focus on when skipping to diff
503 (ediff-defvar-local ediff-regexp-focus-A "" "")
504 ;; Regexp that determines buf B regions to focus on when skipping to diff
505 (ediff-defvar-local ediff-regexp-focus-B "" "")
506 ;; Regexp that determines buf C regions to focus on when skipping to diff
507 (ediff-defvar-local ediff-regexp-focus-C "" "")
508 ;; connective that determines whether to focus regions that match both or
509 ;; one of the regexps
510 (ediff-defvar-local ediff-focus-regexp-connective 'and "")
512 ;; Regexp that determines buf A regions to ignore when skipping to diff
513 (ediff-defvar-local ediff-regexp-hide-A "" "")
514 ;; Regexp that determines buf B regions to ignore when skipping to diff
515 (ediff-defvar-local ediff-regexp-hide-B "" "")
516 ;; Regexp that determines buf C regions to ignore when skipping to diff
517 (ediff-defvar-local ediff-regexp-hide-C "" "")
518 ;; connective that determines whether to hide regions that match both or
519 ;; one of the regexps
520 (ediff-defvar-local ediff-hide-regexp-connective 'and "")
523 ;;; Copying difference regions between buffers.
525 ;; A list of killed diffs.
526 ;; A diff is saved here if it is replaced by a diff
527 ;; from another buffer. This alist has the form:
528 ;; \((num (buff-object . diff) (buff-object . diff) (buff-object . diff)) ...),
529 ;; where some buffer-objects may be missing.
530 (ediff-defvar-local ediff-killed-diffs-alist nil "")
532 ;; Syntax table to use in ediff-forward-word-function
533 ;; This is chosen by a heuristic. The important thing is for all buffers to
534 ;; have the same syntax table. Which is not too important.
535 (ediff-defvar-local ediff-syntax-table nil "")
538 ;; Highlighting
539 (defcustom ediff-before-flag-bol (if (featurep 'xemacs) (make-glyph "->>") "->>")
540 "Flag placed before a highlighted block of differences, if block starts at beginning of a line."
541 :type 'string
542 :tag "Region before-flag at beginning of line"
543 :group 'ediff)
545 (defcustom ediff-after-flag-eol (if (featurep 'xemacs) (make-glyph "<<-") "<<-")
546 "Flag placed after a highlighted block of differences, if block ends at end of a line."
547 :type 'string
548 :tag "Region after-flag at end of line"
549 :group 'ediff)
551 (defcustom ediff-before-flag-mol (if (featurep 'xemacs) (make-glyph "->>") "->>")
552 "Flag placed before a highlighted block of differences, if block starts in mid-line."
553 :type 'string
554 :tag "Region before-flag in the middle of line"
555 :group 'ediff)
556 (defcustom ediff-after-flag-mol (if (featurep 'xemacs) (make-glyph "<<-") "<<-")
557 "Flag placed after a highlighted block of differences, if block ends in mid-line."
558 :type 'string
559 :tag "Region after-flag in the middle of line"
560 :group 'ediff)
563 (defcustom ediff-use-faces t
564 "If t, differences are highlighted using faces, if device supports faces.
565 If nil, differences are highlighted using ASCII flags, ediff-before-flag
566 and ediff-after-flag. On a non-window system, differences are always
567 highlighted using ASCII flags."
568 :type 'boolean
569 :group 'ediff-highlighting)
570 (ediff-defvar-local ediff-use-faces t "")
572 ;; this indicates that diff regions are word-size, so fine diffs are
573 ;; permanently nixed; used in ediff-windows-wordwise and ediff-regions-wordwise
574 (ediff-defvar-local ediff-word-mode nil "")
575 ;; Name of the job (ediff-files, ediff-windows, etc.)
576 (ediff-defvar-local ediff-job-name nil "")
578 ;; Narrowing and ediff-region/windows support
579 ;; This is a list (overlay-A overlay-B overlay-C)
580 ;; If set, Ediff compares only those parts of buffers A/B/C that lie within
581 ;; the bounds of these overlays.
582 (ediff-defvar-local ediff-narrow-bounds nil "")
584 ;; List (overlay-A overlay-B overlay-C), where each overlay spans the
585 ;; entire corresponding buffer.
586 (ediff-defvar-local ediff-wide-bounds nil "")
588 ;; Current visibility boundaries in buffers A, B, and C.
589 ;; This is also a list of overlays. When the user toggles narrow/widen,
590 ;; this list changes from ediff-wide-bounds to ediff-narrow-bounds.
591 ;; and back.
592 (ediff-defvar-local ediff-visible-bounds nil "")
594 (ediff-defvar-local ediff-start-narrowed t
595 "Non-nil means start narrowed, if doing ediff-windows-* or ediff-regions-*")
596 (ediff-defvar-local ediff-quit-widened t
597 "Non-nil means: when finished, Ediff widens buffers A/B.
598 Actually, Ediff restores the scope of visibility that existed at startup.")
600 (defcustom ediff-keep-variants t
601 "nil means prompt to remove unmodified buffers A/B/C at session end.
602 Supplying a prefix argument to the quit command `q' temporarily reverses the
603 meaning of this variable."
604 :type 'boolean
605 :group 'ediff)
607 (defcustom ediff-highlight-all-diffs t
608 "If nil, only the selected differences are highlighted.
609 Otherwise, all difference regions are highlighted, but the selected region is
610 shown in brighter colors."
611 :type 'boolean
612 :group 'ediff-highlighting)
613 (ediff-defvar-local ediff-highlight-all-diffs t "")
616 ;; The suffix of the control buffer name.
617 (ediff-defvar-local ediff-control-buffer-suffix nil "")
618 ;; Same as ediff-control-buffer-suffix, but without <,>.
619 ;; It's a number rather than string.
620 (ediff-defvar-local ediff-control-buffer-number nil "")
623 ;; The original values of ediff-protected-variables for buffer A
624 (ediff-defvar-local ediff-buffer-values-orig-A nil "")
625 ;; The original values of ediff-protected-variables for buffer B
626 (ediff-defvar-local ediff-buffer-values-orig-B nil "")
627 ;; The original values of ediff-protected-variables for buffer C
628 (ediff-defvar-local ediff-buffer-values-orig-C nil "")
629 ;; The original values of ediff-protected-variables for buffer Ancestor
630 (ediff-defvar-local ediff-buffer-values-orig-Ancestor nil "")
632 ;; association between buff-type and ediff-buffer-values-orig-*
633 (defconst ediff-buffer-values-orig-alist
634 '((A . ediff-buffer-values-orig-A)
635 (B . ediff-buffer-values-orig-B)
636 (C . ediff-buffer-values-orig-C)
637 (Ancestor . ediff-buffer-values-orig-Ancestor)))
639 ;; Buffer-local variables to be saved then restored during Ediff sessions
640 (defconst ediff-protected-variables '(
641 ;;buffer-read-only
642 mode-line-format))
644 ;; Vector of differences between the variants. Each difference is
645 ;; represented by a vector of two overlays plus a vector of fine diffs,
646 ;; plus a no-fine-diffs flag. The first overlay spans the
647 ;; difference region in the A buffer and the second overlays the diff in
648 ;; the B buffer. If a difference section is empty, the corresponding
649 ;; overlay's endpoints coincide.
651 ;; The precise form of a Difference Vector for one buffer is:
652 ;; [diff diff diff ...]
653 ;; where each diff has the form:
654 ;; [diff-overlay fine-diff-vector no-fine-diffs-flag state-of-diff]
655 ;; fine-diff-vector is a vector [fine-diff-overlay fine-diff-overlay ...]
656 ;; no-fine-diffs-flag says if there are fine differences.
657 ;; state-of-difference is A, B, C, or nil, indicating which buffer is
658 ;; different from the other two (used only in 3-way jobs.
659 (ediff-defvar-local ediff-difference-vector-A nil "")
660 (ediff-defvar-local ediff-difference-vector-B nil "")
661 (ediff-defvar-local ediff-difference-vector-C nil "")
662 (ediff-defvar-local ediff-difference-vector-Ancestor nil "")
663 ;; A-list of diff vector types associated with buffer types
664 (defconst ediff-difference-vector-alist
665 '((A . ediff-difference-vector-A)
666 (B . ediff-difference-vector-B)
667 (C . ediff-difference-vector-C)
668 (Ancestor . ediff-difference-vector-Ancestor)))
670 ;; [ status status status ...]
671 ;; Each status: [state-of-merge state-of-ancestor]
672 ;; state-of-merge is default-A, default-B, prefer-A, or prefer-B. It
673 ;; indicates the way a diff region was created in buffer C.
674 ;; state-of-ancestor says if the corresponding region in ancestor buffer is
675 ;; empty.
676 (ediff-defvar-local ediff-state-of-merge nil "")
678 ;; The difference that is currently selected.
679 (ediff-defvar-local ediff-current-difference -1 "")
680 ;; Number of differences found.
681 (ediff-defvar-local ediff-number-of-differences nil "")
683 ;; Buffer containing the output of diff, which is used by Ediff to step
684 ;; through files.
685 (ediff-defvar-local ediff-diff-buffer nil "")
686 ;; Like ediff-diff-buffer, but contains context diff. It is not used by
687 ;; Ediff, but it is saved in a file, if user requests so.
688 (ediff-defvar-local ediff-custom-diff-buffer nil "")
689 ;; Buffer used for diff-style fine differences between regions.
690 (ediff-defvar-local ediff-fine-diff-buffer nil "")
691 ;; Temporary buffer used for computing fine differences.
692 (defconst ediff-tmp-buffer " *ediff-tmp*" "")
693 ;; Buffer used for messages
694 (defconst ediff-msg-buffer " *ediff-message*" "")
695 ;; Buffer containing the output of diff when diff returns errors.
696 (ediff-defvar-local ediff-error-buffer nil "")
697 ;; Buffer to display debug info
698 (ediff-defvar-local ediff-debug-buffer "*ediff-debug*" "")
700 ;; List of ediff control panels associated with each buffer A/B/C/Ancestor.
701 ;; Not used any more, but may be needed in the future.
702 (ediff-defvar-local ediff-this-buffer-ediff-sessions nil "")
704 ;; to be deleted in due time
705 ;; List of difference overlays disturbed by working with the current diff.
706 (defvar ediff-disturbed-overlays nil "")
708 ;; Priority of non-selected overlays.
709 (defvar ediff-shadow-overlay-priority 100 "")
711 (defcustom ediff-version-control-package 'vc
712 "Version control package used.
713 Currently, Ediff supports vc.el, rcs.el, pcl-cvs.el, and generic-sc.el. The
714 standard Emacs interface to RCS, CVS, SCCS, etc., is vc.el. However, some
715 people find the other two packages more convenient. Set this variable to the
716 appropriate symbol: `rcs', `pcl-cvs', or `generic-sc' if you so desire."
717 :type 'symbol
718 :group 'ediff)
720 (defcustom ediff-coding-system-for-read 'raw-text
721 "The coding system for read to use when running the diff program as a subprocess.
722 In most cases, the default will do. However, under certain circumstances in
723 MS-Windows you might need to use something like 'raw-text-dos here.
724 So, if the output that your diff program sends to Emacs contains extra ^M's,
725 you might need to experiment here, if the default or 'raw-text-dos doesn't
726 work."
727 :type 'symbol
728 :group 'ediff)
730 (defcustom ediff-coding-system-for-write (if (featurep 'xemacs)
731 'escape-quoted
732 'emacs-internal)
733 "The coding system for write to use when writing out difference regions
734 to temp files in buffer jobs and when Ediff needs to find fine differences."
735 :type 'symbol
736 :group 'ediff)
739 (defalias 'ediff-read-event
740 (if (featurep 'xemacs) 'next-command-event 'read-event))
742 (defalias 'ediff-overlayp
743 (if (featurep 'xemacs) 'extentp 'overlayp))
745 (defalias 'ediff-make-overlay
746 (if (featurep 'xemacs) 'make-extent 'make-overlay))
748 (defalias 'ediff-delete-overlay
749 (if (featurep 'xemacs) 'delete-extent 'delete-overlay))
751 ;; Assumes that emacs-major-version and emacs-minor-version are defined.
752 (defun ediff-check-version (op major minor &optional type-of-emacs)
753 "Check the current version against MAJOR and MINOR version numbers.
754 The comparison uses operator OP, which may be any of: =, >, >=, <, <=.
755 TYPE-OF-EMACS is either 'xemacs or 'emacs."
756 (declare (obsolete version< "23.1"))
757 (and (cond ((eq type-of-emacs 'xemacs) (featurep 'xemacs))
758 ((eq type-of-emacs 'emacs) (featurep 'emacs))
759 (t))
760 (cond ((eq op '=) (and (= emacs-minor-version minor)
761 (= emacs-major-version major)))
762 ((memq op '(> >= < <=))
763 (and (or (funcall op emacs-major-version major)
764 (= emacs-major-version major))
765 (if (= emacs-major-version major)
766 (funcall op emacs-minor-version minor)
767 t)))
769 (error "%S: Invalid op in ediff-check-version" op)))))
771 (defun ediff-color-display-p ()
772 (condition-case nil
773 (if (featurep 'xemacs)
774 (eq (device-class (selected-device)) 'color) ; xemacs form
775 (display-color-p)) ; emacs form
776 (error nil)))
779 ;; A var local to each control panel buffer. Indicates highlighting style
780 ;; in effect for this buffer: `face', `ascii',
781 ;; `off' -- turned off \(on a dumb terminal only\).
782 (ediff-defvar-local ediff-highlighting-style
783 (if (and (ediff-has-face-support-p) ediff-use-faces) 'face 'ascii)
787 (if (featurep 'xemacs)
788 (progn
789 (defalias 'ediff-display-pixel-width 'device-pixel-width)
790 (defalias 'ediff-display-pixel-height 'device-pixel-height))
791 (defalias 'ediff-display-pixel-width 'display-pixel-width)
792 (defalias 'ediff-display-pixel-height 'display-pixel-height))
794 ;; A-list of current-diff-overlay symbols associated with buf types
795 (defconst ediff-current-diff-overlay-alist
796 '((A . ediff-current-diff-overlay-A)
797 (B . ediff-current-diff-overlay-B)
798 (C . ediff-current-diff-overlay-C)
799 (Ancestor . ediff-current-diff-overlay-Ancestor)))
801 ;; A-list of current-diff-face-* symbols associated with buf types
802 (defconst ediff-current-diff-face-alist
803 '((A . ediff-current-diff-A)
804 (B . ediff-current-diff-B)
805 (C . ediff-current-diff-C)
806 (Ancestor . ediff-current-diff-Ancestor)))
809 (defun ediff-set-overlay-face (extent face)
810 (ediff-overlay-put extent 'face face)
811 (ediff-overlay-put extent 'help-echo 'ediff-region-help-echo))
813 (defun ediff-region-help-echo (extent-or-window &optional overlay _point)
814 (unless overlay
815 (setq overlay extent-or-window))
816 (let ((is-current (ediff-overlay-get overlay 'ediff))
817 (face (ediff-overlay-get overlay 'face))
818 (diff-num (ediff-overlay-get overlay 'ediff-diff-num))
819 face-help)
821 ;; This happens only for refinement overlays
822 (if (stringp face)
823 (setq face (intern face)))
824 (setq face-help (and face (get face 'ediff-help-echo)))
826 (cond ((and is-current diff-num) ; current diff region
827 (format "Difference region %S -- current" (1+ diff-num)))
828 (face-help) ; refinement of current diff region
829 (diff-num ; non-current
830 (format "Difference region %S -- non-current" (1+ diff-num)))
831 (t "")) ; none
835 (defun ediff-set-face-pixmap (face pixmap)
836 "Set face pixmap on a monochrome display."
837 (if (and (ediff-window-display-p) (not (ediff-color-display-p)))
838 (condition-case nil
839 (set-face-background-pixmap face pixmap)
840 (error
841 (message "Pixmap not found for %S: %s" (face-name face) pixmap)
842 (sit-for 1)))))
844 (defun ediff-hide-face (face)
845 (if (and (ediff-has-face-support-p)
846 (boundp 'add-to-list)
847 (boundp 'facemenu-unlisted-faces))
848 (add-to-list 'facemenu-unlisted-faces face)))
852 (defface ediff-current-diff-A
853 (if (featurep 'emacs)
854 '((((class color) (min-colors 88) (background light))
855 :background "#ffdddd")
856 (((class color) (min-colors 88) (background dark))
857 :background "#553333")
858 (((class color) (min-colors 16))
859 (:foreground "firebrick" :background "pale green"))
860 (((class color))
861 (:foreground "blue3" :background "yellow3"))
862 (t (:inverse-video t)))
863 '((((type tty)) (:foreground "blue3" :background "yellow3"))
864 (((class color)) (:foreground "firebrick" :background "pale green"))
865 (t (:inverse-video t))))
866 "Face for highlighting the selected difference in buffer A."
867 :group 'ediff-highlighting)
868 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
869 ;; this variable is set to nil, then again to the appropriate face.
870 (defvar ediff-current-diff-face-A 'ediff-current-diff-A
871 "Face for highlighting the selected difference in buffer A.
872 DO NOT CHANGE this variable. Instead, use the customization
873 widget to customize the actual face object `ediff-current-diff-A'
874 this variable represents.")
875 (ediff-hide-face ediff-current-diff-face-A)
876 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
877 ;; This means that some user customization may be trashed.
878 (and (featurep 'xemacs)
879 (ediff-has-face-support-p)
880 (not (ediff-color-display-p))
881 (copy-face 'modeline ediff-current-diff-face-A))
885 (defface ediff-current-diff-B
886 (if (featurep 'emacs)
887 '((((class color) (min-colors 88) (background light))
888 :background "#ddffdd")
889 (((class color) (min-colors 88) (background dark))
890 :background "#335533")
891 (((class color) (min-colors 16))
892 (:foreground "DarkOrchid" :background "Yellow"))
893 (((class color))
894 (:foreground "magenta3" :background "yellow3"
895 :weight bold))
896 (t (:inverse-video t)))
897 '((((type tty)) (:foreground "magenta3" :background "yellow3"
898 :weight bold))
899 (((class color)) (:foreground "DarkOrchid" :background "Yellow"))
900 (t (:inverse-video t))))
901 "Face for highlighting the selected difference in buffer B."
902 :group 'ediff-highlighting)
903 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
904 ;; this variable is set to nil, then again to the appropriate face.
905 (defvar ediff-current-diff-face-B 'ediff-current-diff-B
906 "Face for highlighting the selected difference in buffer B.
907 this variable. Instead, use the customization
908 widget to customize the actual face `ediff-current-diff-B'
909 this variable represents.")
910 (ediff-hide-face ediff-current-diff-face-B)
911 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
912 ;; This means that some user customization may be trashed.
913 (and (featurep 'xemacs)
914 (ediff-has-face-support-p)
915 (not (ediff-color-display-p))
916 (copy-face 'modeline ediff-current-diff-face-B))
919 (defface ediff-current-diff-C
920 (if (featurep 'emacs)
921 '((((class color) (min-colors 88) (background light))
922 :background "#ffffaa")
923 (((class color) (min-colors 88) (background dark))
924 :background "#888833")
925 (((class color) (min-colors 16))
926 (:foreground "Navy" :background "Pink"))
927 (((class color))
928 (:foreground "cyan3" :background "yellow3" :weight bold))
929 (t (:inverse-video t)))
930 '((((type tty)) (:foreground "cyan3" :background "yellow3" :weight bold))
931 (((class color)) (:foreground "Navy" :background "Pink"))
932 (t (:inverse-video t))))
933 "Face for highlighting the selected difference in buffer C."
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-C 'ediff-current-diff-C
938 "Face for highlighting the selected difference in buffer C.
939 DO NOT CHANGE this variable. Instead, use the customization
940 widget to customize the actual face object `ediff-current-diff-C'
941 this variable represents.")
942 (ediff-hide-face ediff-current-diff-face-C)
943 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
944 ;; This means that some user customization may be trashed.
945 (and (featurep 'xemacs)
946 (ediff-has-face-support-p)
947 (not (ediff-color-display-p))
948 (copy-face 'modeline ediff-current-diff-face-C))
951 (defface ediff-current-diff-Ancestor
952 (if (featurep 'emacs)
953 '((((class color) (min-colors 16))
954 (:foreground "Black" :background "VioletRed"))
955 (((class color))
956 (:foreground "black" :background "magenta3"))
957 (t (:inverse-video t)))
958 '((((type tty)) (:foreground "black" :background "magenta3"))
959 (((class color)) (:foreground "Black" :background "VioletRed"))
960 (t (:inverse-video t))))
961 "Face for highlighting the selected difference in buffer Ancestor."
962 :group 'ediff-highlighting)
963 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
964 ;; this variable is set to nil, then again to the appropriate face.
965 (defvar ediff-current-diff-face-Ancestor 'ediff-current-diff-Ancestor
966 "Face for highlighting the selected difference in buffer Ancestor.
967 DO NOT CHANGE this variable. Instead, use the customization
968 widget to customize the actual face object `ediff-current-diff-Ancestor'
969 this variable represents.")
970 (ediff-hide-face ediff-current-diff-face-Ancestor)
971 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
972 ;; This means that some user customization may be trashed.
973 (and (featurep 'xemacs)
974 (ediff-has-face-support-p)
975 (not (ediff-color-display-p))
976 (copy-face 'modeline ediff-current-diff-face-Ancestor))
979 (defface ediff-fine-diff-A
980 (if (featurep 'emacs)
981 '((((class color) (min-colors 88) (background light))
982 :background "#ffbbbb")
983 (((class color) (min-colors 88) (background dark))
984 :background "#aa2222")
985 (((class color) (min-colors 16))
986 (:foreground "Navy" :background "sky blue"))
987 (((class color))
988 (:foreground "white" :background "sky blue" :weight bold))
989 (t (:underline t :stipple "gray3")))
990 '((((type tty)) (:foreground "white" :background "sky blue" :weight bold))
991 (((class color)) (:foreground "Navy" :background "sky blue"))
992 (t (:underline t :stipple "gray3"))))
993 "Face for highlighting the refinement of the selected diff in buffer A."
994 :group 'ediff-highlighting)
995 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
996 ;; this variable is set to nil, then again to the appropriate face.
997 (defvar ediff-fine-diff-face-A 'ediff-fine-diff-A
998 "Face for highlighting the fine differences in buffer A.
999 DO NOT CHANGE this variable. Instead, use the customization
1000 widget to customize the actual face object `ediff-fine-diff-A'
1001 this variable represents.")
1002 (ediff-hide-face ediff-fine-diff-face-A)
1004 (defface ediff-fine-diff-B
1005 (if (featurep 'emacs)
1006 '((((class color) (min-colors 88) (background light))
1007 :background "#aaffaa")
1008 (((class color) (min-colors 88) (background dark))
1009 :background "#22aa22")
1010 (((class color) (min-colors 16))
1011 (:foreground "Black" :background "cyan"))
1012 (((class color))
1013 (:foreground "magenta3" :background "cyan3"))
1014 (t (:underline t :stipple "gray3")))
1015 '((((type tty)) (:foreground "magenta3" :background "cyan3"))
1016 (((class color)) (:foreground "Black" :background "cyan"))
1017 (t (:underline t :stipple "gray3"))))
1018 "Face for highlighting the refinement of the selected diff in buffer B."
1019 :group 'ediff-highlighting)
1020 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1021 ;; this variable is set to nil, then again to the appropriate face.
1022 (defvar ediff-fine-diff-face-B 'ediff-fine-diff-B
1023 "Face for highlighting the fine differences in buffer B.
1024 DO NOT CHANGE this variable. Instead, use the customization
1025 widget to customize the actual face object `ediff-fine-diff-B'
1026 this variable represents.")
1027 (ediff-hide-face ediff-fine-diff-face-B)
1029 (defface ediff-fine-diff-C
1030 (if (featurep 'emacs)
1031 '((((class color) (min-colors 88) (background light))
1032 :background "#ffff55")
1033 (((class color) (min-colors 88) (background dark))
1034 :background "#aaaa22")
1035 (((type pc))
1036 (:foreground "white" :background "Turquoise"))
1037 (((class color) (min-colors 16))
1038 (:foreground "Black" :background "Turquoise"))
1039 (((class color))
1040 (:foreground "yellow3" :background "Turquoise"
1041 :weight bold))
1042 (t (:underline t :stipple "gray3")))
1043 '((((type tty)) (:foreground "yellow3" :background "Turquoise"
1044 :weight bold))
1045 (((type pc)) (:foreground "white" :background "Turquoise"))
1046 (((class color)) (:foreground "Black" :background "Turquoise"))
1047 (t (:underline t :stipple "gray3"))))
1048 "Face for highlighting the refinement of the selected diff in buffer C."
1049 :group 'ediff-highlighting)
1050 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1051 ;; this variable is set to nil, then again to the appropriate face.
1052 (defvar ediff-fine-diff-face-C 'ediff-fine-diff-C
1053 "Face for highlighting the fine differences in buffer C.
1054 DO NOT CHANGE this variable. Instead, use the customization
1055 widget to customize the actual face object `ediff-fine-diff-C'
1056 this variable represents.")
1057 (ediff-hide-face ediff-fine-diff-face-C)
1059 (defface ediff-fine-diff-Ancestor
1060 (if (featurep 'emacs)
1061 '((((class color) (min-colors 16))
1062 (:foreground "Black" :background "Green"))
1063 (((class color))
1064 (:foreground "red3" :background "green"))
1065 (t (:underline t :stipple "gray3")))
1066 '((((type tty)) (:foreground "red3" :background "green"))
1067 (((class color)) (:foreground "Black" :background "Green"))
1068 (t (:underline t :stipple "gray3"))))
1069 "Face for highlighting the refinement of the selected diff in the ancestor buffer.
1070 At present, this face is not used and no fine differences are computed for the
1071 ancestor buffer."
1072 :group 'ediff-highlighting)
1073 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1074 ;; this variable is set to nil, then again to the appropriate face.
1075 (defvar ediff-fine-diff-face-Ancestor 'ediff-fine-diff-Ancestor
1076 "Face for highlighting the fine differences in buffer Ancestor.
1077 DO NOT CHANGE this variable. Instead, use the customization
1078 widget to customize the actual face object `ediff-fine-diff-Ancestor'
1079 this variable represents.")
1080 (ediff-hide-face ediff-fine-diff-face-Ancestor)
1082 ;; Some installs don't have stipple or Stipple. So, try them in turn.
1083 (defvar stipple-pixmap
1084 (cond ((not (ediff-has-face-support-p)) nil)
1085 ((and (boundp 'x-bitmap-file-path)
1086 (locate-library "stipple" t x-bitmap-file-path)) "stipple")
1087 ((and (boundp 'mswindowsx-bitmap-file-path)
1088 (locate-library "stipple" t mswindowsx-bitmap-file-path)) "stipple")
1089 (t "Stipple")))
1091 (defface ediff-even-diff-A
1092 (if (featurep 'emacs)
1093 `((((type pc))
1094 (:foreground "green3" :background "light grey"))
1095 (((class color) (min-colors 16))
1096 (:foreground "Black" :background "light grey"))
1097 (((class color))
1098 (:foreground "red3" :background "light grey"
1099 :weight bold))
1100 (t (:italic t :stipple ,stipple-pixmap)))
1101 `((((type tty)) (:foreground "red3" :background "light grey"
1102 :weight bold))
1103 (((type pc)) (:foreground "green3" :background "light grey"))
1104 (((class color)) (:foreground "Black" :background "light grey"))
1105 (t (:italic t :stipple ,stipple-pixmap))))
1106 "Face for highlighting even-numbered non-current differences in buffer A."
1107 :group 'ediff-highlighting)
1108 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1109 ;; this variable is set to nil, then again to the appropriate face.
1110 (defvar ediff-even-diff-face-A 'ediff-even-diff-A
1111 "Face for highlighting even-numbered non-current differences in buffer A.
1112 DO NOT CHANGE this variable. Instead, use the customization
1113 widget to customize the actual face object `ediff-even-diff-A'
1114 this variable represents.")
1115 (ediff-hide-face ediff-even-diff-face-A)
1117 (defface ediff-even-diff-B
1118 (if (featurep 'emacs)
1119 `((((class color) (min-colors 16))
1120 (:foreground "White" :background "Grey"))
1121 (((class color))
1122 (:foreground "blue3" :background "Grey" :weight bold))
1123 (t (:italic t :stipple ,stipple-pixmap)))
1124 `((((type tty)) (:foreground "blue3" :background "Grey" :weight bold))
1125 (((class color)) (:foreground "White" :background "Grey"))
1126 (t (:italic t :stipple ,stipple-pixmap))))
1127 "Face for highlighting even-numbered non-current differences in buffer B."
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-even-diff-face-B 'ediff-even-diff-B
1132 "Face for highlighting even-numbered non-current differences in buffer B.
1133 DO NOT CHANGE this variable. Instead, use the customization
1134 widget to customize the actual face object `ediff-even-diff-B'
1135 this variable represents.")
1136 (ediff-hide-face ediff-even-diff-face-B)
1138 (defface ediff-even-diff-C
1139 (if (featurep 'emacs)
1140 `((((type pc))
1141 (:foreground "yellow3" :background "light grey"))
1142 (((class color) (min-colors 16))
1143 (:foreground "Black" :background "light grey"))
1144 (((class color))
1145 (:foreground "yellow3" :background "light grey"
1146 :weight bold))
1147 (t (:italic t :stipple ,stipple-pixmap)))
1148 `((((type tty)) (:foreground "yellow3" :background "light grey"
1149 :weight bold))
1150 (((type pc)) (:foreground "yellow3" :background "light grey"))
1151 (((class color)) (:foreground "Black" :background "light grey"))
1152 (t (:italic t :stipple ,stipple-pixmap))))
1153 "Face for highlighting even-numbered non-current differences in buffer C."
1154 :group 'ediff-highlighting)
1155 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1156 ;; this variable is set to nil, then again to the appropriate face.
1157 (defvar ediff-even-diff-face-C 'ediff-even-diff-C
1158 "Face for highlighting even-numbered non-current differences in buffer C.
1159 DO NOT CHANGE this variable. Instead, use the customization
1160 widget to customize the actual face object `ediff-even-diff-C'
1161 this variable represents.")
1162 (ediff-hide-face ediff-even-diff-face-C)
1164 (defface ediff-even-diff-Ancestor
1165 (if (featurep 'emacs)
1166 `((((type pc))
1167 (:foreground "cyan3" :background "light grey"))
1168 (((class color) (min-colors 16))
1169 (:foreground "White" :background "Grey"))
1170 (((class color))
1171 (:foreground "cyan3" :background "light grey"
1172 :weight bold))
1173 (t (:italic t :stipple ,stipple-pixmap)))
1174 `((((type tty)) (:foreground "cyan3" :background "light grey"
1175 :weight bold))
1176 (((type pc)) (:foreground "cyan3" :background "light grey"))
1177 (((class color)) (:foreground "White" :background "Grey"))
1178 (t (:italic t :stipple ,stipple-pixmap))))
1179 "Face for highlighting even-numbered non-current differences in the ancestor buffer."
1180 :group 'ediff-highlighting)
1181 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1182 ;; this variable is set to nil, then again to the appropriate face.
1183 (defvar ediff-even-diff-face-Ancestor 'ediff-even-diff-Ancestor
1184 "Face for highlighting even-numbered non-current differences in buffer Ancestor.
1185 DO NOT CHANGE this variable. Instead, use the customization
1186 widget to customize the actual face object `ediff-even-diff-Ancestor'
1187 this variable represents.")
1188 (ediff-hide-face ediff-even-diff-face-Ancestor)
1190 ;; Association between buffer types and even-diff-face symbols
1191 (defconst ediff-even-diff-face-alist
1192 '((A . ediff-even-diff-A)
1193 (B . ediff-even-diff-B)
1194 (C . ediff-even-diff-C)
1195 (Ancestor . ediff-even-diff-Ancestor)))
1197 (defface ediff-odd-diff-A
1198 (if (featurep 'emacs)
1199 '((((type pc))
1200 (:foreground "green3" :background "gray40"))
1201 (((class color) (min-colors 16))
1202 (:foreground "White" :background "Grey"))
1203 (((class color))
1204 (:foreground "red3" :background "black" :weight bold))
1205 (t (:italic t :stipple "gray1")))
1206 '((((type tty)) (:foreground "red3" :background "black" :weight bold))
1207 (((type pc)) (:foreground "green3" :background "gray40"))
1208 (((class color)) (:foreground "White" :background "Grey"))
1209 (t (:italic t :stipple "gray1"))))
1210 "Face for highlighting odd-numbered non-current differences in buffer A."
1211 :group 'ediff-highlighting)
1212 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1213 ;; this variable is set to nil, then again to the appropriate face.
1214 (defvar ediff-odd-diff-face-A 'ediff-odd-diff-A
1215 "Face for highlighting odd-numbered non-current differences in buffer A.
1216 DO NOT CHANGE this variable. Instead, use the customization
1217 widget to customize the actual face object `ediff-odd-diff-A'
1218 this variable represents.")
1219 (ediff-hide-face ediff-odd-diff-face-A)
1222 (defface ediff-odd-diff-B
1223 (if (featurep 'emacs)
1224 '((((type pc))
1225 (:foreground "White" :background "gray40"))
1226 (((class color) (min-colors 16))
1227 (:foreground "Black" :background "light grey"))
1228 (((class color))
1229 (:foreground "cyan3" :background "black" :weight bold))
1230 (t (:italic t :stipple "gray1")))
1231 '((((type tty)) (:foreground "cyan3" :background "black" :weight bold))
1232 (((type pc)) (:foreground "White" :background "gray40"))
1233 (((class color)) (:foreground "Black" :background "light grey"))
1234 (t (:italic t :stipple "gray1"))))
1235 "Face for highlighting odd-numbered non-current differences in buffer B."
1236 :group 'ediff-highlighting)
1237 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1238 ;; this variable is set to nil, then again to the appropriate face.
1239 (defvar ediff-odd-diff-face-B 'ediff-odd-diff-B
1240 "Face for highlighting odd-numbered non-current differences in buffer B.
1241 DO NOT CHANGE this variable. Instead, use the customization
1242 widget to customize the actual face object `ediff-odd-diff-B'
1243 this variable represents.")
1244 (ediff-hide-face ediff-odd-diff-face-B)
1246 (defface ediff-odd-diff-C
1247 (if (featurep 'emacs)
1248 '((((type pc))
1249 (:foreground "yellow3" :background "gray40"))
1250 (((class color) (min-colors 16))
1251 (:foreground "White" :background "Grey"))
1252 (((class color))
1253 (:foreground "yellow3" :background "black" :weight bold))
1254 (t (:italic t :stipple "gray1")))
1255 '((((type tty)) (:foreground "yellow3" :background "black" :weight bold))
1256 (((type pc)) (:foreground "yellow3" :background "gray40"))
1257 (((class color)) (:foreground "White" :background "Grey"))
1258 (t (:italic t :stipple "gray1"))))
1259 "Face for highlighting odd-numbered non-current differences in buffer C."
1260 :group 'ediff-highlighting)
1261 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1262 ;; this variable is set to nil, then again to the appropriate face.
1263 (defvar ediff-odd-diff-face-C 'ediff-odd-diff-C
1264 "Face for highlighting odd-numbered non-current differences in buffer C.
1265 DO NOT CHANGE this variable. Instead, use the customization
1266 widget to customize the actual face object `ediff-odd-diff-C'
1267 this variable represents.")
1268 (ediff-hide-face ediff-odd-diff-face-C)
1270 (defface ediff-odd-diff-Ancestor
1271 (if (featurep 'emacs)
1272 '((((class color) (min-colors 16))
1273 (:foreground "cyan3" :background "gray40"))
1274 (((class color))
1275 (:foreground "green3" :background "black" :weight bold))
1276 (t (:italic t :stipple "gray1")))
1277 '((((type tty)) (:foreground "green3" :background "black" :weight bold))
1278 (((class color)) (:foreground "cyan3" :background "gray40"))
1279 (t (:italic t :stipple "gray1"))))
1280 "Face for highlighting odd-numbered non-current differences in the ancestor buffer."
1281 :group 'ediff-highlighting)
1282 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1283 ;; this variable is set to nil, then again to the appropriate face.
1284 (defvar ediff-odd-diff-face-Ancestor 'ediff-odd-diff-Ancestor
1285 "Face for highlighting odd-numbered non-current differences in buffer Ancestor.
1286 DO NOT CHANGE this variable. Instead, use the customization
1287 widget to customize the actual face object `ediff-odd-diff-Ancestor'
1288 this variable represents.")
1289 (ediff-hide-face ediff-odd-diff-face-Ancestor)
1291 ;; Association between buffer types and odd-diff-face symbols
1292 (defconst ediff-odd-diff-face-alist
1293 '((A . ediff-odd-diff-A)
1294 (B . ediff-odd-diff-B)
1295 (C . ediff-odd-diff-C)
1296 (Ancestor . ediff-odd-diff-Ancestor)))
1298 ;; A-list of fine-diff face symbols associated with buffer types
1299 (defconst ediff-fine-diff-face-alist
1300 '((A . ediff-fine-diff-A)
1301 (B . ediff-fine-diff-B)
1302 (C . ediff-fine-diff-C)
1303 (Ancestor . ediff-fine-diff-Ancestor)))
1305 ;; Help echo
1306 (put ediff-fine-diff-face-A 'ediff-help-echo
1307 "A `refinement' of the current difference region")
1308 (put ediff-fine-diff-face-B 'ediff-help-echo
1309 "A `refinement' of the current difference region")
1310 (put ediff-fine-diff-face-C 'ediff-help-echo
1311 "A `refinement' of the current difference region")
1312 (put ediff-fine-diff-face-Ancestor 'ediff-help-echo
1313 "A `refinement' of the current difference region")
1315 (add-hook 'ediff-quit-hook 'ediff-cleanup-mess)
1316 (add-hook 'ediff-suspend-hook 'ediff-default-suspend-function)
1319 ;;; Overlays
1321 (ediff-defvar-local ediff-current-diff-overlay-A nil
1322 "Overlay for the current difference region in buffer A.")
1323 (ediff-defvar-local ediff-current-diff-overlay-B nil
1324 "Overlay for the current difference region in buffer B.")
1325 (ediff-defvar-local ediff-current-diff-overlay-C nil
1326 "Overlay for the current difference region in buffer C.")
1327 (ediff-defvar-local ediff-current-diff-overlay-Ancestor nil
1328 "Overlay for the current difference region in the ancestor buffer.")
1330 ;; Compute priority of a current ediff overlay.
1331 (defun ediff-highest-priority (start end buffer)
1332 (let ((pos (max 1 (1- start)))
1333 ovr-list)
1334 (if (featurep 'xemacs)
1335 (1+ ediff-shadow-overlay-priority)
1336 (ediff-with-current-buffer buffer
1337 (while (< pos (min (point-max) (1+ end)))
1338 (setq ovr-list (append (overlays-at pos) ovr-list))
1339 (setq pos (next-overlay-change pos)))
1340 (+ 1 ediff-shadow-overlay-priority
1341 (apply 'max
1342 (cons
1344 (mapcar
1345 (lambda (ovr)
1346 (if (and ovr
1347 ;; exclude ediff overlays from priority
1348 ;; calculation, or else priority will keep
1349 ;; increasing
1350 (null (ediff-overlay-get ovr 'ediff))
1351 (null (ediff-overlay-get ovr 'ediff-diff-num)))
1352 ;; use the overlay priority or 0
1353 (or (ediff-overlay-get ovr 'priority) 0)
1355 ovr-list))))))))
1358 (defvar ediff-toggle-read-only-function 'toggle-read-only
1359 "Function to be used to toggle read-only status of the buffer.
1360 If nil, Ediff tries using the command bound to C-x C-q.")
1362 (defcustom ediff-make-buffers-readonly-at-startup nil
1363 "Make all variant buffers read-only when Ediff starts up.
1364 This property can be toggled interactively."
1365 :type 'boolean
1366 :group 'ediff)
1369 ;;; Misc
1371 ;; if nil, this silences some messages
1372 (defvar ediff-verbose-p t)
1374 (defcustom ediff-autostore-merges 'group-jobs-only
1375 "Save the results of merge jobs automatically.
1376 With value nil, don't save automatically. With value t, always
1377 save. Anything else means save automatically only if the merge
1378 job is part of a group of jobs, such as `ediff-merge-directory'
1379 or `ediff-merge-directory-revisions'."
1380 :type '(choice (const nil) (const t) (const group-jobs-only))
1381 :group 'ediff-merge)
1382 (make-variable-buffer-local 'ediff-autostore-merges)
1384 ;; file where the result of the merge is to be saved. used internally
1385 (ediff-defvar-local ediff-merge-store-file nil "")
1387 (defcustom ediff-merge-filename-prefix "merge_"
1388 "Prefix to be attached to saved merge buffers."
1389 :type 'string
1390 :group 'ediff-merge)
1392 (defcustom ediff-no-emacs-help-in-control-buffer nil
1393 "Non-nil means C-h should not invoke Emacs help in control buffer.
1394 Instead, C-h would jump to previous difference."
1395 :type 'boolean
1396 :group 'ediff)
1398 ;; This is the same as temporary-file-directory from Emacs 20.3.
1399 ;; Copied over here because XEmacs doesn't have this variable.
1400 (defcustom ediff-temp-file-prefix
1401 (file-name-as-directory
1402 (cond ((boundp 'temporary-file-directory) temporary-file-directory)
1403 ((fboundp 'temp-directory) (temp-directory))
1404 (t "/tmp/")))
1405 ;;; (file-name-as-directory
1406 ;;; (cond ((memq system-type '(ms-dos windows-nt))
1407 ;;; (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
1408 ;;; (t
1409 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))
1410 "Prefix to put on Ediff temporary file names.
1411 Do not start with `~/' or `~USERNAME/'."
1412 :type 'string
1413 :group 'ediff)
1415 (defcustom ediff-temp-file-mode 384 ; u=rw only
1416 "Mode for Ediff temporary files."
1417 :type 'integer
1418 :group 'ediff)
1420 ;; Metacharacters that have to be protected from the shell when executing
1421 ;; a diff/diff3 command.
1422 (defcustom ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
1423 "Regexp that matches characters that must be quoted with `\\' in shell command line.
1424 This default should work without changes."
1425 :type 'string
1426 :group 'ediff)
1428 ;; needed to simulate frame-char-width in XEmacs.
1429 (defvar ediff-H-glyph (if (featurep 'xemacs) (make-glyph "H")))
1432 ;; Temporary file used for refining difference regions in buffer A.
1433 (ediff-defvar-local ediff-temp-file-A nil "")
1434 ;; Temporary file used for refining difference regions in buffer B.
1435 (ediff-defvar-local ediff-temp-file-B nil "")
1436 ;; Temporary file used for refining difference regions in buffer C.
1437 (ediff-defvar-local ediff-temp-file-C nil "")
1440 (defun ediff-file-remote-p (file-name)
1441 (file-remote-p file-name))
1443 ;; File for which we can get attributes, such as size or date
1444 (defun ediff-listable-file (file-name)
1445 (let ((handler (find-file-name-handler file-name 'file-local-copy)))
1446 (or (null handler) (eq handler 'dired-handler-fn))))
1449 (defsubst ediff-frame-unsplittable-p (frame)
1450 (cdr (assq 'unsplittable (frame-parameters frame))))
1452 (defsubst ediff-get-next-window (wind prev-wind)
1453 (cond ((window-live-p wind) wind)
1454 (prev-wind (next-window wind))
1455 (t (selected-window))
1459 (defsubst ediff-kill-buffer-carefully (buf)
1460 "Kill buffer BUF if it exists."
1461 (if (ediff-buffer-live-p buf)
1462 (kill-buffer (get-buffer buf))))
1464 (defsubst ediff-background-face (buf-type dif-num)
1465 ;; The value of dif-num is always 1- the one that user sees.
1466 ;; This is why even face is used when dif-num is odd.
1467 (ediff-get-symbol-from-alist
1468 buf-type (if (ediff-odd-p dif-num)
1469 ediff-even-diff-face-alist
1470 ediff-odd-diff-face-alist)
1474 ;; activate faces on diff regions in buffer
1475 (defun ediff-paint-background-regions-in-one-buffer (buf-type unhighlight)
1476 (let ((diff-vector
1477 (eval (ediff-get-symbol-from-alist
1478 buf-type ediff-difference-vector-alist)))
1479 overl diff-num)
1480 (mapcar (lambda (rec)
1481 (setq overl (ediff-get-diff-overlay-from-diff-record rec)
1482 diff-num (ediff-overlay-get overl 'ediff-diff-num))
1483 (if (ediff-overlay-buffer overl)
1484 ;; only if overlay is alive
1485 (ediff-set-overlay-face
1486 overl
1487 (if (not unhighlight)
1488 (ediff-background-face buf-type diff-num))))
1490 diff-vector)))
1493 ;; activate faces on diff regions in all buffers
1494 (defun ediff-paint-background-regions (&optional unhighlight)
1495 (ediff-paint-background-regions-in-one-buffer
1496 'A unhighlight)
1497 (ediff-paint-background-regions-in-one-buffer
1498 'B unhighlight)
1499 (ediff-paint-background-regions-in-one-buffer
1500 'C unhighlight)
1501 (ediff-paint-background-regions-in-one-buffer
1502 'Ancestor unhighlight))
1505 ;; arg is a record for a given diff in a difference vector
1506 ;; this record is itself a vector
1507 (defsubst ediff-clear-fine-diff-vector (diff-record)
1508 (if diff-record
1509 (mapc 'ediff-delete-overlay
1510 (ediff-get-fine-diff-vector-from-diff-record diff-record))))
1512 (defsubst ediff-clear-fine-differences-in-one-buffer (n buf-type)
1513 (ediff-clear-fine-diff-vector (ediff-get-difference n buf-type))
1514 (ediff-set-fine-diff-vector n buf-type nil))
1516 (defsubst ediff-clear-fine-differences (n)
1517 (ediff-clear-fine-differences-in-one-buffer n 'A)
1518 (ediff-clear-fine-differences-in-one-buffer n 'B)
1519 (if ediff-3way-job
1520 (ediff-clear-fine-differences-in-one-buffer n 'C)))
1523 (defsubst ediff-mouse-event-p (event)
1524 (if (featurep 'xemacs)
1525 (button-event-p event)
1526 (string-match "mouse" (format "%S" (event-basic-type event)))))
1529 (defsubst ediff-key-press-event-p (event)
1530 (if (featurep 'xemacs)
1531 (key-press-event-p event)
1532 (or (char-or-string-p event) (symbolp event))))
1534 (defun ediff-event-point (event)
1535 (cond ((ediff-mouse-event-p event)
1536 (if (featurep 'xemacs)
1537 (event-point event)
1538 (posn-point (event-start event))))
1539 ((ediff-key-press-event-p event)
1540 (point))
1541 (t (error "Error"))))
1543 (defun ediff-event-buffer (event)
1544 (cond ((ediff-mouse-event-p event)
1545 (if (featurep 'xemacs)
1546 (event-buffer event)
1547 (window-buffer (posn-window (event-start event)))))
1548 ((ediff-key-press-event-p event)
1549 (current-buffer))
1550 (t (error "Error"))))
1552 (defun ediff-event-key (event-or-key)
1553 (if (featurep 'xemacs)
1554 ;;(if (eventp event-or-key) (event-key event-or-key) event-or-key)
1555 (if (eventp event-or-key) (event-to-character event-or-key t t) event-or-key)
1556 event-or-key))
1558 (defun ediff-last-command-char ()
1559 (ediff-event-key last-command-event))
1562 (defsubst ediff-frame-iconified-p (frame)
1563 (and (ediff-window-display-p) (frame-live-p frame)
1564 (if (featurep 'xemacs)
1565 (frame-iconified-p frame)
1566 (eq (frame-visible-p frame) 'icon))))
1568 (defsubst ediff-window-visible-p (wind)
1569 ;; under TTY, window-live-p also means window is visible
1570 (and (window-live-p wind)
1571 (or (not (ediff-window-display-p))
1572 (frame-visible-p (window-frame wind)))))
1575 (defsubst ediff-frame-char-width (frame)
1576 (if (featurep 'xemacs)
1577 (/ (frame-pixel-width frame) (frame-width frame))
1578 (frame-char-width frame)))
1580 (defun ediff-reset-mouse (&optional frame do-not-grab-mouse)
1581 (or frame (setq frame (selected-frame)))
1582 (if (ediff-window-display-p)
1583 (let ((frame-or-wind frame))
1584 (if (featurep 'xemacs)
1585 (setq frame-or-wind (frame-selected-window frame)))
1586 (or do-not-grab-mouse
1587 ;; don't set mouse if the user said to never do this
1588 (not ediff-grab-mouse)
1589 ;; Don't grab on quit, if the user doesn't want to.
1590 ;; If ediff-grab-mouse = t, then mouse won't be grabbed for
1591 ;; sessions that are not part of a group (this is done in
1592 ;; ediff-recenter). The condition below affects only terminating
1593 ;; sessions in session groups (in which case mouse is warped into
1594 ;; a meta buffer).
1595 (and (eq ediff-grab-mouse 'maybe)
1596 (memq this-command '(ediff-quit ediff-update-diffs)))
1597 (set-mouse-position frame-or-wind 1 0))
1600 (defsubst ediff-spy-after-mouse ()
1601 (setq ediff-mouse-pixel-position (mouse-pixel-position)))
1603 ;; It is not easy to find out when the user grabs the mouse, since emacs and
1604 ;; xemacs behave differently when mouse is not in any frame. Also, this is
1605 ;; sensitive to when the user grabbed mouse. Not used for now.
1606 (defun ediff-user-grabbed-mouse ()
1607 (if ediff-mouse-pixel-position
1608 (cond ((not (eq (car ediff-mouse-pixel-position)
1609 (car (mouse-pixel-position)))))
1610 ((and (car (cdr ediff-mouse-pixel-position))
1611 (car (cdr (mouse-pixel-position)))
1612 (cdr (cdr ediff-mouse-pixel-position))
1613 (cdr (cdr (mouse-pixel-position))))
1614 (not (and (< (abs (- (car (cdr ediff-mouse-pixel-position))
1615 (car (cdr (mouse-pixel-position)))))
1616 ediff-mouse-pixel-threshold)
1617 (< (abs (- (cdr (cdr ediff-mouse-pixel-position))
1618 (cdr (cdr (mouse-pixel-position)))))
1619 ediff-mouse-pixel-threshold))))
1620 (t nil))))
1622 (defsubst ediff-frame-char-height (frame)
1623 (if (featurep 'xemacs)
1624 (glyph-height ediff-H-glyph (frame-selected-window frame))
1625 (frame-char-height frame)))
1627 ;; Some overlay functions
1629 (defsubst ediff-overlay-start (overl)
1630 (if (ediff-overlayp overl)
1631 (if (featurep 'xemacs)
1632 (extent-start-position overl)
1633 (overlay-start overl))))
1635 (defsubst ediff-overlay-end (overl)
1636 (if (ediff-overlayp overl)
1637 (if (featurep 'xemacs)
1638 (extent-end-position overl)
1639 (overlay-end overl))))
1641 (defsubst ediff-empty-overlay-p (overl)
1642 (= (ediff-overlay-start overl) (ediff-overlay-end overl)))
1644 ;; like overlay-buffer in Emacs. In XEmacs, returns nil if the extent is
1645 ;; dead. Otherwise, works like extent-buffer
1646 (defun ediff-overlay-buffer (overl)
1647 (if (featurep 'xemacs)
1648 (and (extent-live-p overl) (extent-object overl))
1649 (overlay-buffer overl)))
1651 ;; like overlay-get in Emacs. In XEmacs, returns nil if the extent is
1652 ;; dead. Otherwise, like extent-property
1653 (defun ediff-overlay-get (overl property)
1654 (if (featurep 'xemacs)
1655 (and (extent-live-p overl) (extent-property overl property))
1656 (overlay-get overl property)))
1659 ;; These two functions are here because XEmacs refuses to
1660 ;; handle overlays whose buffers were deleted.
1661 (defun ediff-move-overlay (overlay beg end &optional buffer)
1662 "Calls `move-overlay' in Emacs and `set-extent-endpoints' in Lemacs.
1663 Checks if overlay's buffer exists before actually doing the move."
1664 (let ((buf (and overlay (ediff-overlay-buffer overlay))))
1665 (if (ediff-buffer-live-p buf)
1666 (if (featurep 'xemacs)
1667 (set-extent-endpoints overlay beg end)
1668 (move-overlay overlay beg end buffer))
1669 ;; buffer's dead
1670 (if overlay
1671 (ediff-delete-overlay overlay)))))
1673 (defun ediff-overlay-put (overlay prop value)
1674 "Calls `overlay-put' or `set-extent-property' depending on Emacs version.
1675 Checks if overlay's buffer exists."
1676 (if (ediff-buffer-live-p (ediff-overlay-buffer overlay))
1677 (if (featurep 'xemacs)
1678 (set-extent-property overlay prop value)
1679 (overlay-put overlay prop value))
1680 (ediff-delete-overlay overlay)))
1682 ;; temporarily uses DIR to abbreviate file name
1683 ;; if DIR is nil, use default-directory
1684 (defun ediff-abbreviate-file-name (file &optional dir)
1685 (cond ((stringp dir)
1686 (let ((directory-abbrev-alist (list (cons dir ""))))
1687 (abbreviate-file-name file)))
1689 (if (featurep 'xemacs)
1690 ;; XEmacs requires addl argument
1691 (abbreviate-file-name file t)
1692 (abbreviate-file-name file)))))
1694 ;; Takes a directory and returns the parent directory.
1695 ;; does nothing to `/'. If the ARG is a regular file,
1696 ;; strip the file AND the last dir.
1697 (defun ediff-strip-last-dir (dir)
1698 (if (not (stringp dir)) (setq dir default-directory))
1699 (setq dir (expand-file-name dir))
1700 (or (file-directory-p dir) (setq dir (file-name-directory dir)))
1701 (let* ((pos (1- (length dir)))
1702 (last-char (aref dir pos)))
1703 (if (and (> pos 0) (= last-char ?/))
1704 (setq dir (substring dir 0 pos)))
1705 (ediff-abbreviate-file-name (file-name-directory dir))))
1707 (defun ediff-truncate-string-left (str newlen)
1708 ;; leave space for ... on the left
1709 (let ((len (length str))
1710 substr)
1711 (if (<= len newlen)
1713 (setq newlen (max 0 (- newlen 3)))
1714 (setq substr (substring str (max 0 (- len 1 newlen))))
1715 (concat "..." substr))))
1717 (defsubst ediff-nonempty-string-p (string)
1718 (and (stringp string) (not (string= string ""))))
1720 (unless (fboundp 'subst-char-in-string)
1721 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1722 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1723 Unless optional argument INPLACE is non-nil, return a new string."
1724 (let ((i (length string))
1725 (newstr (if inplace string (copy-sequence string))))
1726 (while (> i 0)
1727 (setq i (1- i))
1728 (if (eq (aref newstr i) fromchar)
1729 (aset newstr i tochar)))
1730 newstr)))
1732 (defun ediff-abbrev-jobname (jobname)
1733 (cond ((eq jobname 'ediff-directories)
1734 "Compare two directories")
1735 ((eq jobname 'ediff-files)
1736 "Compare two files")
1737 ((eq jobname 'ediff-buffers)
1738 "Compare two buffers")
1739 ((eq jobname 'ediff-directories3)
1740 "Compare three directories")
1741 ((eq jobname 'ediff-files3)
1742 "Compare three files")
1743 ((eq jobname 'ediff-buffers3)
1744 "Compare three buffers")
1745 ((eq jobname 'ediff-revision)
1746 "Compare file with a version")
1747 ((eq jobname 'ediff-directory-revisions)
1748 "Compare dir files with versions")
1749 ((eq jobname 'ediff-merge-directory-revisions)
1750 "Merge dir files with versions")
1751 ((eq jobname 'ediff-merge-directory-revisions-with-ancestor)
1752 "Merge dir versions via ancestors")
1754 (capitalize
1755 (subst-char-in-string ?- ?\s (substring (symbol-name jobname) 6))))
1759 ;; If ediff modified mode line, strip the modification
1760 (defsubst ediff-strip-mode-line-format ()
1761 (and (consp mode-line-format)
1762 (member (car mode-line-format)
1763 '(" A: " " B: " " C: " " Ancestor: "))
1764 (setq mode-line-format (nth 2 mode-line-format))))
1766 ;; Verify that we have a difference selected.
1767 (defsubst ediff-valid-difference-p (&optional n)
1768 (or n (setq n ediff-current-difference))
1769 (and (>= n 0) (< n ediff-number-of-differences)))
1771 (defsubst ediff-show-all-diffs (_n)
1772 "Don't skip difference regions."
1773 nil)
1775 (defsubst ediff-message-if-verbose (string &rest args)
1776 (if ediff-verbose-p
1777 (apply 'message string args)))
1779 (defun ediff-file-attributes (filename attr-number)
1780 (if (ediff-listable-file filename)
1781 (nth attr-number (file-attributes filename))
1785 (defsubst ediff-file-size (filename)
1786 (ediff-file-attributes filename 7))
1787 (defsubst ediff-file-modtime (filename)
1788 (ediff-file-attributes filename 5))
1791 (defun ediff-convert-standard-filename (fname)
1792 (if (fboundp 'convert-standard-filename)
1793 (convert-standard-filename fname)
1794 fname))
1796 (if (featurep 'emacs)
1797 (defalias 'ediff-with-syntax-table 'with-syntax-table)
1798 (if (fboundp 'with-syntax-table)
1799 (defalias 'ediff-with-syntax-table 'with-syntax-table)
1800 ;; stolen from subr.el in emacs 21
1801 (defmacro ediff-with-syntax-table (table &rest body)
1802 (let ((old-table (make-symbol "table"))
1803 (old-buffer (make-symbol "buffer")))
1804 `(let ((,old-table (syntax-table))
1805 (,old-buffer (current-buffer)))
1806 (unwind-protect
1807 (progn
1808 (set-syntax-table (copy-syntax-table ,table))
1809 ,@body)
1810 (save-current-buffer
1811 (set-buffer ,old-buffer)
1812 (set-syntax-table ,old-table))))))))
1815 (provide 'ediff-init)
1819 ;; Local Variables:
1820 ;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1821 ;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1822 ;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1823 ;; End:
1825 ;;; ediff-init.el ends here