*** empty log message ***
[emacs.git] / lisp / ediff-init.el
blobdd69b52b022956ad0c1976f4d083076237ba3b8a
1 ;;; ediff-init.el --- Macros, variables, and defsubsts used by Ediff
3 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
4 ;; 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
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, or (at your option)
13 ;; 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; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
25 ;;; Commentary:
27 ;;; Code:
29 ;; Start compiler pacifier
30 (defvar ediff-metajob-name)
31 (defvar ediff-meta-buffer)
32 (defvar pm-color-alist)
33 (defvar ediff-grab-mouse)
34 (defvar ediff-mouse-pixel-position)
35 (defvar ediff-mouse-pixel-threshold)
36 (defvar ediff-whitespace)
37 (defvar ediff-multiframe)
38 (defvar ediff-use-toolbar-p)
39 (defvar mswindowsx-bitmap-file-path)
41 (and noninteractive
42 (eval-when-compile
43 (load "ange-ftp" 'noerror)))
44 ;; end pacifier
46 ;; This is used to avoid compilation warnings. When emacs/xemacs forms can
47 ;; generate compile time warnings, we use this macro.
48 ;; In this case, the macro will expand into the form that is appropriate to the
49 ;; compiler at hand.
50 ;; Suggested by rms.
51 (defmacro ediff-cond-compile-for-xemacs-or-emacs (xemacs-form emacs-form)
52 (if (featurep 'xemacs)
53 xemacs-form emacs-form))
55 (defvar ediff-force-faces nil
56 "If t, Ediff will think that it is running on a display that supports faces.
57 This is provided as a temporary relief for users of face-capable displays
58 that Ediff doesn't know about.")
60 ;; Are we running as a window application or on a TTY?
61 (defsubst ediff-device-type ()
62 (ediff-cond-compile-for-xemacs-or-emacs
63 (device-type (selected-device)) ; xemacs form
64 window-system ; emacs form
67 ;; in XEmacs: device-type is tty on tty and stream in batch.
68 (defun ediff-window-display-p ()
69 (and (ediff-device-type) (not (memq (ediff-device-type) '(tty pc stream)))))
71 ;; test if supports faces
72 (defun ediff-has-face-support-p ()
73 (cond ((ediff-window-display-p))
74 (ediff-force-faces)
75 ((ediff-color-display-p))
76 ((featurep 'emacs) (memq (ediff-device-type) '(pc)))
77 ((featurep 'xemacs) (memq (ediff-device-type) '(tty pc)))
80 ;; toolbar support for emacs hasn't been implemented in ediff
81 (defun ediff-has-toolbar-support-p ()
82 (ediff-cond-compile-for-xemacs-or-emacs
83 (and (featurep 'toolbar) (console-on-window-system-p)) ; xemacs form
84 nil ; emacs form
88 (defun ediff-has-gutter-support-p ()
89 (ediff-cond-compile-for-xemacs-or-emacs
90 (and (featurep 'gutter) (console-on-window-system-p)) ; xemacs form
91 nil ; emacs form
95 (defun ediff-use-toolbar-p ()
96 (and (ediff-has-toolbar-support-p) ;Can it do it ?
97 (boundp 'ediff-use-toolbar-p)
98 ediff-use-toolbar-p)) ;Does the user want it ?
100 ;; Defines VAR as an advertised local variable.
101 ;; Performs a defvar, then executes `make-variable-buffer-local' on
102 ;; the variable. Also sets the `permanent-local' property,
103 ;; so that `kill-all-local-variables' (called by major-mode setting
104 ;; commands) won't destroy Ediff control variables.
106 ;; Plagiarised from `emerge-defvar-local' for XEmacs.
107 (defmacro ediff-defvar-local (var value doc)
108 "Defines VAR as a local variable."
109 (declare (indent defun))
110 `(progn
111 (defvar ,var ,value ,doc)
112 (make-variable-buffer-local ',var)
113 (put ',var 'permanent-local t)))
117 ;; Variables that control each Ediff session---local to the control buffer.
119 ;; Mode variables
120 ;; The buffer in which the A variant is stored.
121 (ediff-defvar-local ediff-buffer-A nil "")
122 ;; The buffer in which the B variant is stored.
123 (ediff-defvar-local ediff-buffer-B nil "")
124 ;; The buffer in which the C variant is stored or where the merge buffer lives.
125 (ediff-defvar-local ediff-buffer-C nil "")
126 ;; Ancestor buffer
127 (ediff-defvar-local ediff-ancestor-buffer nil "")
128 ;; The Ediff control buffer
129 (ediff-defvar-local ediff-control-buffer nil "")
131 (ediff-defvar-local ediff-temp-indirect-buffer nil
132 "If t, the buffer is a temporary indirect buffer.
133 It needs to be killed when we quit the session.")
136 ;; Association between buff-type and ediff-buffer-*
137 (defconst ediff-buffer-alist
138 '((?A . ediff-buffer-A)
139 (?B . ediff-buffer-B)
140 (?C . ediff-buffer-C)))
142 ;;; Macros
143 (defmacro ediff-odd-p (arg)
144 `(eq (logand ,arg 1) 1))
146 (defmacro ediff-buffer-live-p (buf)
147 `(and ,buf (get-buffer ,buf) (buffer-name (get-buffer ,buf))))
149 (defmacro ediff-get-buffer (arg)
150 `(cond ((eq ,arg 'A) ediff-buffer-A)
151 ((eq ,arg 'B) ediff-buffer-B)
152 ((eq ,arg 'C) ediff-buffer-C)
153 ((eq ,arg 'Ancestor) ediff-ancestor-buffer)
156 (defmacro ediff-get-value-according-to-buffer-type (buf-type list)
157 `(cond ((eq ,buf-type 'A) (nth 0 ,list))
158 ((eq ,buf-type 'B) (nth 1 ,list))
159 ((eq ,buf-type 'C) (nth 2 ,list))
162 (defmacro ediff-char-to-buftype (arg)
163 `(cond ((memq ,arg '(?a ?A)) 'A)
164 ((memq ,arg '(?b ?B)) 'B)
165 ((memq ,arg '(?c ?C)) 'C)
169 ;; A-list is supposed to be of the form (A . symb) (B . symb)...)
170 ;; where the first part of any association is a buffer type and the second is
171 ;; an appropriate symbol. Given buffer-type, this function returns the
172 ;; symbol. This is used to avoid using `intern'
173 (defsubst ediff-get-symbol-from-alist (buf-type alist)
174 (cdr (assoc buf-type alist)))
176 (defconst ediff-difference-vector-alist
177 '((A . ediff-difference-vector-A)
178 (B . ediff-difference-vector-B)
179 (C . ediff-difference-vector-C)
180 (Ancestor . ediff-difference-vector-Ancestor)))
182 (defmacro ediff-get-difference (n buf-type)
183 `(aref
184 (symbol-value
185 (ediff-get-symbol-from-alist
186 ,buf-type ediff-difference-vector-alist))
187 ,n))
189 ;; Tell if it has been previously determined that the region has
190 ;; no diffs other than the white space and newlines
191 ;; The argument, N, is the diff region number used by Ediff to index the
192 ;; diff vector. It is 1 less than the number seen by the user.
193 ;; Returns:
194 ;; t if the diffs are whitespace in all buffers
195 ;; 'A (in 3-buf comparison only) if there are only whitespace
196 ;; diffs in bufs B and C
197 ;; 'B (in 3-buf comparison only) if there are only whitespace
198 ;; diffs in bufs A and C
199 ;; 'C (in 3-buf comparison only) if there are only whitespace
200 ;; diffs in bufs A and B
202 ;; A Difference Vector has the form:
203 ;; [diff diff diff ...]
204 ;; where each diff has the form:
205 ;; [overlay fine-diff-vector no-fine-diffs-flag state-of-difference]
206 ;; fine-diff-vector is a vector [fine-diff fine-diff fine-diff ...]
207 ;; no-fine-diffs-flag says if there are fine differences.
208 ;; state-of-difference is A, B, C, or nil, indicating which buffer is
209 ;; different from the other two (used only in 3-way jobs).
210 (defmacro ediff-no-fine-diffs-p (n)
211 `(aref (ediff-get-difference ,n 'A) 2))
213 (defmacro ediff-get-diff-overlay-from-diff-record (diff-rec)
214 `(aref ,diff-rec 0))
216 (defmacro ediff-get-diff-overlay (n buf-type)
217 `(ediff-get-diff-overlay-from-diff-record
218 (ediff-get-difference ,n ,buf-type)))
220 (defmacro ediff-get-fine-diff-vector-from-diff-record (diff-rec)
221 `(aref ,diff-rec 1))
223 (defmacro ediff-set-fine-diff-vector (n buf-type fine-vec)
224 `(aset (ediff-get-difference ,n ,buf-type) 1 ,fine-vec))
226 (defmacro ediff-get-state-of-diff (n buf-type)
227 `(if (ediff-buffer-live-p ediff-buffer-C)
228 (aref (ediff-get-difference ,n ,buf-type) 3)))
229 (defmacro ediff-set-state-of-diff (n buf-type val)
230 `(aset (ediff-get-difference ,n ,buf-type) 3 ,val))
232 (defmacro ediff-get-state-of-merge (n)
233 `(if ediff-state-of-merge
234 (aref (aref ediff-state-of-merge ,n) 0)))
235 (defmacro ediff-set-state-of-merge (n val)
236 `(if ediff-state-of-merge
237 (aset (aref ediff-state-of-merge ,n) 0 ,val)))
239 (defmacro ediff-get-state-of-ancestor (n)
240 `(if ediff-state-of-merge
241 (aref (aref ediff-state-of-merge ,n) 1)))
243 ;; if flag is t, puts a mark on diff region saying that
244 ;; the differences are in white space only. If flag is nil,
245 ;; the region is marked as essential (i.e., differences are
246 ;; not just in the white space and newlines.)
247 (defmacro ediff-mark-diff-as-space-only (n flag)
248 `(aset (ediff-get-difference ,n 'A) 2 ,flag))
250 (defmacro ediff-get-fine-diff-vector (n buf-type)
251 `(ediff-get-fine-diff-vector-from-diff-record
252 (ediff-get-difference ,n ,buf-type)))
254 ;; Macro to switch to BUFFER, evaluate BODY, returns to original buffer.
255 ;; Doesn't save the point and mark.
256 ;; This is `with-current-buffer' with the added test for live buffers."
257 (defmacro ediff-with-current-buffer (buffer &rest body)
258 "Evaluates BODY in BUFFER."
259 (declare (indent 1) (debug (form body)))
260 `(if (ediff-buffer-live-p ,buffer)
261 (save-current-buffer
262 (set-buffer ,buffer)
263 ,@body)
264 (or (eq this-command 'ediff-quit)
265 (error ediff-KILLED-VITAL-BUFFER))
269 (defsubst ediff-multiframe-setup-p ()
270 (and (ediff-window-display-p) ediff-multiframe))
272 (defmacro ediff-narrow-control-frame-p ()
273 `(and (ediff-multiframe-setup-p)
274 (equal ediff-help-message ediff-brief-message-string)))
276 (defmacro ediff-3way-comparison-job ()
277 `(memq
278 ediff-job-name
279 '(ediff-files3 ediff-buffers3)))
280 (ediff-defvar-local ediff-3way-comparison-job nil "")
282 (defmacro ediff-merge-job ()
283 `(memq
284 ediff-job-name
285 '(ediff-merge-files
286 ediff-merge-buffers
287 ediff-merge-files-with-ancestor
288 ediff-merge-buffers-with-ancestor
289 ediff-merge-revisions
290 ediff-merge-revisions-with-ancestor)))
291 (ediff-defvar-local ediff-merge-job nil "")
293 (defmacro ediff-patch-job ()
294 `(eq ediff-job-name 'epatch))
296 (defmacro ediff-merge-with-ancestor-job ()
297 `(memq
298 ediff-job-name
299 '(ediff-merge-files-with-ancestor
300 ediff-merge-buffers-with-ancestor
301 ediff-merge-revisions-with-ancestor)))
302 (ediff-defvar-local ediff-merge-with-ancestor-job nil "")
304 (defmacro ediff-3way-job ()
305 `(or ediff-3way-comparison-job ediff-merge-job))
306 (ediff-defvar-local ediff-3way-job nil "")
308 ;; A diff3 job is like a 3way job, but ediff-merge doesn't require the use
309 ;; of diff3.
310 (defmacro ediff-diff3-job ()
311 `(or ediff-3way-comparison-job
312 ediff-merge-with-ancestor-job))
313 (ediff-defvar-local ediff-diff3-job nil "")
315 (defmacro ediff-windows-job ()
316 `(memq ediff-job-name '(ediff-windows-wordwise ediff-windows-linewise)))
317 (ediff-defvar-local ediff-windows-job nil "")
319 (defmacro ediff-word-mode-job ()
320 `(memq ediff-job-name '(ediff-windows-wordwise ediff-regions-wordwise)))
321 (ediff-defvar-local ediff-word-mode-job nil "")
323 (defmacro ediff-narrow-job ()
324 `(memq ediff-job-name '(ediff-windows-wordwise
325 ediff-regions-wordwise
326 ediff-windows-linewise
327 ediff-regions-linewise)))
328 (ediff-defvar-local ediff-narrow-job nil "")
330 ;; Note: ediff-merge-directory-revisions-with-ancestor is not treated as an
331 ;; ancestor metajob, since it behaves differently.
332 (defsubst ediff-ancestor-metajob (&optional metajob)
333 (memq (or metajob ediff-metajob-name)
334 '(ediff-merge-directories-with-ancestor
335 ediff-merge-filegroups-with-ancestor)))
336 (defsubst ediff-revision-metajob (&optional metajob)
337 (memq (or metajob ediff-metajob-name)
338 '(ediff-directory-revisions
339 ediff-merge-directory-revisions
340 ediff-merge-directory-revisions-with-ancestor)))
341 (defsubst ediff-patch-metajob (&optional metajob)
342 (memq (or metajob ediff-metajob-name)
343 '(ediff-multifile-patch)))
344 ;; metajob involving only one group of files, such as multipatch or directory
345 ;; revision
346 (defsubst ediff-one-filegroup-metajob (&optional metajob)
347 (or (ediff-revision-metajob metajob)
348 (ediff-patch-metajob metajob)
349 ;; add more here
351 ;; jobs suitable for the operation of collecting diffs into a multifile patch
352 (defsubst ediff-collect-diffs-metajob (&optional metajob)
353 (memq (or metajob ediff-metajob-name)
354 '(ediff-directories
355 ediff-merge-directories
356 ediff-merge-directories-with-ancestor
357 ediff-directory-revisions
358 ediff-merge-directory-revisions
359 ediff-merge-directory-revisions-with-ancestor
360 ;; add more here
362 (defsubst ediff-merge-metajob (&optional metajob)
363 (memq (or metajob ediff-metajob-name)
364 '(ediff-merge-directories
365 ediff-merge-directories-with-ancestor
366 ediff-merge-directory-revisions
367 ediff-merge-directory-revisions-with-ancestor
368 ediff-merge-filegroups-with-ancestor
369 ;; add more here
372 (defsubst ediff-metajob3 (&optional metajob)
373 (memq (or metajob ediff-metajob-name)
374 '(ediff-merge-directories-with-ancestor
375 ediff-merge-filegroups-with-ancestor
376 ediff-directories3
377 ediff-filegroups3)))
378 (defsubst ediff-comparison-metajob3 (&optional metajob)
379 (memq (or metajob ediff-metajob-name)
380 '(ediff-directories3 ediff-filegroups3)))
382 ;; with no argument, checks if we are in ediff-control-buffer
383 ;; with argument, checks if we are in ediff-meta-buffer
384 (defun ediff-in-control-buffer-p (&optional meta-buf-p)
385 (and (boundp 'ediff-control-buffer)
386 (eq (if meta-buf-p ediff-meta-buffer ediff-control-buffer)
387 (current-buffer))))
389 (defsubst ediff-barf-if-not-control-buffer (&optional meta-buf-p)
390 (or (ediff-in-control-buffer-p meta-buf-p)
391 (error "%S: This command runs in Ediff Control Buffer only!"
392 this-command)))
394 (defgroup ediff-highlighting nil
395 "Hilighting of difference regions in Ediff."
396 :prefix "ediff-"
397 :group 'ediff)
399 (defgroup ediff-merge nil
400 "Merging utilities."
401 :prefix "ediff-"
402 :group 'ediff)
404 (defgroup ediff-hook nil
405 "Hooks run by Ediff."
406 :prefix "ediff-"
407 :group 'ediff)
409 ;; Hook variables
411 (defcustom ediff-before-setup-hook nil
412 "*Hooks to run before Ediff begins to set up windows and buffers.
413 This hook can be used to save the previous window config, which can be restored
414 on ediff-quit or ediff-suspend."
415 :type 'hook
416 :group 'ediff-hook)
417 (defcustom ediff-before-setup-windows-hook nil
418 "*Hooks to run before Ediff sets its window configuration.
419 This hook is run every time when Ediff arranges its windows.
420 This happens each time Ediff detects that the windows were messed up by the
421 user."
422 :type 'hook
423 :group 'ediff-hook)
424 (defcustom ediff-after-setup-windows-hook nil
425 "*Hooks to run after Ediff sets its window configuration.
426 This can be used to set up control window or icon in a desired place."
427 :type 'hook
428 :group 'ediff-hook)
429 (defcustom ediff-before-setup-control-frame-hook nil
430 "*Hooks run before setting up the frame to display Ediff Control Panel.
431 Can be used to change control frame parameters to position it where it
432 is desirable."
433 :type 'hook
434 :group 'ediff-hook)
435 (defcustom ediff-after-setup-control-frame-hook nil
436 "*Hooks run after setting up the frame to display Ediff Control Panel.
437 Can be used to move the frame where it is desired."
438 :type 'hook
439 :group 'ediff-hook)
440 (defcustom ediff-startup-hook nil
441 "*Hooks to run in the control buffer after Ediff has been set up and is ready for the job."
442 :type 'hook
443 :group 'ediff-hook)
444 (defcustom ediff-select-hook nil
445 "*Hooks to run after a difference has been selected."
446 :type 'hook
447 :group 'ediff-hook)
448 (defcustom ediff-unselect-hook nil
449 "*Hooks to run after a difference has been unselected."
450 :type 'hook
451 :group 'ediff-hook)
452 (defcustom ediff-prepare-buffer-hook nil
453 "*Hooks run after buffers A, B, and C are set up.
454 For each buffer, the hooks are run with that buffer made current."
455 :type 'hook
456 :group 'ediff-hook)
457 (defcustom ediff-load-hook nil
458 "*Hook run after Ediff is loaded. Can be used to change defaults."
459 :type 'hook
460 :group 'ediff-hook)
462 (defcustom ediff-mode-hook nil
463 "*Hook run just after ediff-mode is set up in the control buffer.
464 This is done before any windows or frames are created. One can use it to
465 set local variables that determine how the display looks like."
466 :type 'hook
467 :group 'ediff-hook)
468 (defcustom ediff-keymap-setup-hook nil
469 "*Hook run just after the default bindings in Ediff keymap are set up."
470 :type 'hook
471 :group 'ediff-hook)
473 (defcustom ediff-display-help-hook nil
474 "*Hooks run after preparing the help message."
475 :type 'hook
476 :group 'ediff-hook)
478 (defcustom ediff-suspend-hook nil
479 "*Hooks to run in the Ediff control buffer when Ediff is suspended."
480 :type 'hook
481 :group 'ediff-hook)
482 (defcustom ediff-quit-hook nil
483 "*Hooks to run in the Ediff control buffer after finishing Ediff."
484 :type 'hook
485 :group 'ediff-hook)
486 (defcustom ediff-cleanup-hook nil
487 "*Hooks to run on exiting Ediff but before killing the control and variant buffers."
488 :type 'hook
489 :group 'ediff-hook)
491 ;; Error messages
492 (defconst ediff-KILLED-VITAL-BUFFER
493 "You have killed a vital Ediff buffer---you must leave Ediff now!")
494 (defconst ediff-NO-DIFFERENCES
495 "Sorry, comparison of identical variants is not what I am made for...")
496 (defconst ediff-BAD-DIFF-NUMBER
497 ;; %S stands for this-command, %d - diff number, %d - max diff
498 "%S: Bad diff region number, %d. Valid numbers are 1 to %d")
499 (defconst ediff-BAD-INFO (format "
500 *** The Info file for Ediff, a part of the standard distribution
501 *** of %sEmacs, does not seem to be properly installed.
503 *** Please contact your system administrator. "
504 (if (featurep 'xemacs) "X" "")))
506 ;; Selective browsing
508 (ediff-defvar-local ediff-skip-diff-region-function 'ediff-show-all-diffs
509 "Function that determines the next/previous diff region to show.
510 Should return t for regions to be ignored and nil otherwise.
511 This function gets a region number as an argument. The region number
512 is the one used internally by Ediff. It is 1 less than the number seen
513 by the user.")
515 (ediff-defvar-local ediff-hide-regexp-matches-function
516 'ediff-hide-regexp-matches
517 "Function to use in determining which regions to hide.
518 See the documentation string of `ediff-hide-regexp-matches' for details.")
519 (ediff-defvar-local ediff-focus-on-regexp-matches-function
520 'ediff-focus-on-regexp-matches
521 "Function to use in determining which regions to focus on.
522 See the documentation string of `ediff-focus-on-regexp-matches' for details.")
524 ;; Regexp that determines buf A regions to focus on when skipping to diff
525 (ediff-defvar-local ediff-regexp-focus-A "" "")
526 ;; Regexp that determines buf B regions to focus on when skipping to diff
527 (ediff-defvar-local ediff-regexp-focus-B "" "")
528 ;; Regexp that determines buf C regions to focus on when skipping to diff
529 (ediff-defvar-local ediff-regexp-focus-C "" "")
530 ;; connective that determines whether to focus regions that match both or
531 ;; one of the regexps
532 (ediff-defvar-local ediff-focus-regexp-connective 'and "")
534 ;; Regexp that determines buf A regions to ignore when skipping to diff
535 (ediff-defvar-local ediff-regexp-hide-A "" "")
536 ;; Regexp that determines buf B regions to ignore when skipping to diff
537 (ediff-defvar-local ediff-regexp-hide-B "" "")
538 ;; Regexp that determines buf C regions to ignore when skipping to diff
539 (ediff-defvar-local ediff-regexp-hide-C "" "")
540 ;; connective that determines whether to hide regions that match both or
541 ;; one of the regexps
542 (ediff-defvar-local ediff-hide-regexp-connective 'and "")
545 ;;; Copying difference regions between buffers.
547 ;; A list of killed diffs.
548 ;; A diff is saved here if it is replaced by a diff
549 ;; from another buffer. This alist has the form:
550 ;; \((num (buff-object . diff) (buff-object . diff) (buff-object . diff)) ...),
551 ;; where some buffer-objects may be missing.
552 (ediff-defvar-local ediff-killed-diffs-alist nil "")
554 ;; Syntax table to use in ediff-forward-word-function
555 ;; This is chosen by a heuristic. The important thing is for all buffers to
556 ;; have the same syntax table. Which is not too important.
557 (ediff-defvar-local ediff-syntax-table nil "")
560 ;; Highlighting
561 (defcustom ediff-before-flag-bol (if (featurep 'xemacs) (make-glyph "->>") "->>")
562 "*Flag placed before a highlighted block of differences, if block starts at beginning of a line."
563 :type 'string
564 :tag "Region before-flag at beginning of line"
565 :group 'ediff)
567 (defcustom ediff-after-flag-eol (if (featurep 'xemacs) (make-glyph "<<-") "<<-")
568 "*Flag placed after a highlighted block of differences, if block ends at end of a line."
569 :type 'string
570 :tag "Region after-flag at end of line"
571 :group 'ediff)
573 (defcustom ediff-before-flag-mol (if (featurep 'xemacs) (make-glyph "->>") "->>")
574 "*Flag placed before a highlighted block of differences, if block starts in mid-line."
575 :type 'string
576 :tag "Region before-flag in the middle of line"
577 :group 'ediff)
578 (defcustom ediff-after-flag-mol (if (featurep 'xemacs) (make-glyph "<<-") "<<-")
579 "*Flag placed after a highlighted block of differences, if block ends in mid-line."
580 :type 'string
581 :tag "Region after-flag in the middle of line"
582 :group 'ediff)
585 (ediff-defvar-local ediff-use-faces t "")
586 (defcustom ediff-use-faces t
587 "If t, differences are highlighted using faces, if device supports faces.
588 If nil, differences are highlighted using ASCII flags, ediff-before-flag
589 and ediff-after-flag. On a non-window system, differences are always
590 highlighted using ASCII flags."
591 :type 'boolean
592 :group 'ediff-highlighting)
594 ;; this indicates that diff regions are word-size, so fine diffs are
595 ;; permanently nixed; used in ediff-windows-wordwise and ediff-regions-wordwise
596 (ediff-defvar-local ediff-word-mode nil "")
597 ;; Name of the job (ediff-files, ediff-windows, etc.)
598 (ediff-defvar-local ediff-job-name nil "")
600 ;; Narrowing and ediff-region/windows support
601 ;; This is a list (overlay-A overlay-B overlay-C)
602 ;; If set, Ediff compares only those parts of buffers A/B/C that lie within
603 ;; the bounds of these overlays.
604 (ediff-defvar-local ediff-narrow-bounds nil "")
606 ;; List (overlay-A overlay-B overlay-C), where each overlay spans the
607 ;; entire corresponding buffer.
608 (ediff-defvar-local ediff-wide-bounds nil "")
610 ;; Current visibility boundaries in buffers A, B, and C.
611 ;; This is also a list of overlays. When the user toggles narrow/widen,
612 ;; this list changes from ediff-wide-bounds to ediff-narrow-bounds.
613 ;; and back.
614 (ediff-defvar-local ediff-visible-bounds nil "")
616 (ediff-defvar-local ediff-start-narrowed t
617 "Non-nil means start narrowed, if doing ediff-windows-* or ediff-regions-*")
618 (ediff-defvar-local ediff-quit-widened t
619 "*Non-nil means: when finished, Ediff widens buffers A/B.
620 Actually, Ediff restores the scope of visibility that existed at startup.")
622 (defcustom ediff-keep-variants t
623 "*nil means prompt to remove unmodified buffers A/B/C at session end.
624 Supplying a prefix argument to the quit command `q' temporarily reverses the
625 meaning of this variable."
626 :type 'boolean
627 :group 'ediff)
629 (ediff-defvar-local ediff-highlight-all-diffs t "")
630 (defcustom ediff-highlight-all-diffs t
631 "If nil, only the selected differences are highlighted.
632 Otherwise, all difference regions are highlighted, but the selected region is
633 shown in brighter colors."
634 :type 'boolean
635 :group 'ediff-highlighting)
638 ;; The suffix of the control buffer name.
639 (ediff-defvar-local ediff-control-buffer-suffix nil "")
640 ;; Same as ediff-control-buffer-suffix, but without <,>.
641 ;; It's a number rather than string.
642 (ediff-defvar-local ediff-control-buffer-number nil "")
645 ;; The original values of ediff-protected-variables for buffer A
646 (ediff-defvar-local ediff-buffer-values-orig-A nil "")
647 ;; The original values of ediff-protected-variables for buffer B
648 (ediff-defvar-local ediff-buffer-values-orig-B nil "")
649 ;; The original values of ediff-protected-variables for buffer C
650 (ediff-defvar-local ediff-buffer-values-orig-C nil "")
651 ;; The original values of ediff-protected-variables for buffer Ancestor
652 (ediff-defvar-local ediff-buffer-values-orig-Ancestor nil "")
654 ;; association between buff-type and ediff-buffer-values-orig-*
655 (defconst ediff-buffer-values-orig-alist
656 '((A . ediff-buffer-values-orig-A)
657 (B . ediff-buffer-values-orig-B)
658 (C . ediff-buffer-values-orig-C)
659 (Ancestor . ediff-buffer-values-orig-Ancestor)))
661 ;; Buffer-local variables to be saved then restored during Ediff sessions
662 (defconst ediff-protected-variables '(
663 ;;buffer-read-only
664 mode-line-format))
666 ;; Vector of differences between the variants. Each difference is
667 ;; represented by a vector of two overlays plus a vector of fine diffs,
668 ;; plus a no-fine-diffs flag. The first overlay spans the
669 ;; difference region in the A buffer and the second overlays the diff in
670 ;; the B buffer. If a difference section is empty, the corresponding
671 ;; overlay's endpoints coincide.
673 ;; The precise form of a Difference Vector for one buffer is:
674 ;; [diff diff diff ...]
675 ;; where each diff has the form:
676 ;; [diff-overlay fine-diff-vector no-fine-diffs-flag state-of-diff]
677 ;; fine-diff-vector is a vector [fine-diff-overlay fine-diff-overlay ...]
678 ;; no-fine-diffs-flag says if there are fine differences.
679 ;; state-of-difference is A, B, C, or nil, indicating which buffer is
680 ;; different from the other two (used only in 3-way jobs.
681 (ediff-defvar-local ediff-difference-vector-A nil "")
682 (ediff-defvar-local ediff-difference-vector-B nil "")
683 (ediff-defvar-local ediff-difference-vector-C nil "")
684 (ediff-defvar-local ediff-difference-vector-Ancestor nil "")
685 ;; A-list of diff vector types associated with buffer types
686 (defconst ediff-difference-vector-alist
687 '((A . ediff-difference-vector-A)
688 (B . ediff-difference-vector-B)
689 (C . ediff-difference-vector-C)
690 (Ancestor . ediff-difference-vector-Ancestor)))
692 ;; [ status status status ...]
693 ;; Each status: [state-of-merge state-of-ancestor]
694 ;; state-of-merge is default-A, default-B, prefer-A, or prefer-B. It
695 ;; indicates the way a diff region was created in buffer C.
696 ;; state-of-ancestor says if the corresponding region in ancestor buffer is
697 ;; empty.
698 (ediff-defvar-local ediff-state-of-merge nil "")
700 ;; The difference that is currently selected.
701 (ediff-defvar-local ediff-current-difference -1 "")
702 ;; Number of differences found.
703 (ediff-defvar-local ediff-number-of-differences nil "")
705 ;; Buffer containing the output of diff, which is used by Ediff to step
706 ;; through files.
707 (ediff-defvar-local ediff-diff-buffer nil "")
708 ;; Like ediff-diff-buffer, but contains context diff. It is not used by
709 ;; Ediff, but it is saved in a file, if user requests so.
710 (ediff-defvar-local ediff-custom-diff-buffer nil "")
711 ;; Buffer used for diff-style fine differences between regions.
712 (ediff-defvar-local ediff-fine-diff-buffer nil "")
713 ;; Temporary buffer used for computing fine differences.
714 (defconst ediff-tmp-buffer " *ediff-tmp*" "")
715 ;; Buffer used for messages
716 (defconst ediff-msg-buffer " *ediff-message*" "")
717 ;; Buffer containing the output of diff when diff returns errors.
718 (ediff-defvar-local ediff-error-buffer nil "")
719 ;; Buffer to display debug info
720 (ediff-defvar-local ediff-debug-buffer "*ediff-debug*" "")
722 ;; List of ediff control panels associated with each buffer A/B/C/Ancestor.
723 ;; Not used any more, but may be needed in the future.
724 (ediff-defvar-local ediff-this-buffer-ediff-sessions nil "")
726 ;; to be deleted in due time
727 ;; List of difference overlays disturbed by working with the current diff.
728 (defvar ediff-disturbed-overlays nil "")
730 ;; Priority of non-selected overlays.
731 (defvar ediff-shadow-overlay-priority 100 "")
733 (defcustom ediff-version-control-package 'vc
734 "Version control package used.
735 Currently, Ediff supports vc.el, rcs.el, pcl-cvs.el, and generic-sc.el. The
736 standard Emacs interface to RCS, CVS, SCCS, etc., is vc.el. However, some
737 people find the other two packages more convenient. Set this variable to the
738 appropriate symbol: `rcs', `pcl-cvs', or `generic-sc' if you so desire."
739 :type 'symbol
740 :group 'ediff)
742 (defcustom ediff-coding-system-for-read 'raw-text
743 "*The coding system for read to use when running the diff program as a subprocess.
744 In most cases, the default will do. However, under certain circumstances in
745 Windows NT/98/95 you might need to use something like 'raw-text-dos here.
746 So, if the output that your diff program sends to Emacs contains extra ^M's,
747 you might need to experiment here, if the default or 'raw-text-dos doesn't
748 work."
749 :type 'symbol
750 :group 'ediff)
752 (defcustom ediff-coding-system-for-write 'no-conversion
753 "*The coding system for write to use when writing out difference regions
754 to temp files when Ediff needs to find fine differences."
755 :type 'symbol
756 :group 'ediff)
759 (ediff-cond-compile-for-xemacs-or-emacs
760 (progn ; xemacs
761 (defalias 'ediff-read-event 'next-command-event)
762 (defalias 'ediff-overlayp 'extentp)
763 (defalias 'ediff-make-overlay 'make-extent)
764 (defalias 'ediff-delete-overlay 'delete-extent))
765 (progn ; emacs
766 (defalias 'ediff-read-event 'read-event)
767 (defalias 'ediff-overlayp 'overlayp)
768 (defalias 'ediff-make-overlay 'make-overlay)
769 (defalias 'ediff-delete-overlay 'delete-overlay))
772 ;; Check the current version against the major and minor version numbers
773 ;; using op: cur-vers op major.minor If emacs-major-version or
774 ;; emacs-minor-version are not defined, we assume that the current version
775 ;; is hopelessly outdated. We assume that emacs-major-version and
776 ;; emacs-minor-version are defined. Otherwise, for Emacs/XEmacs 19, if the
777 ;; current minor version is < 10 (xemacs) or < 23 (emacs) the return value
778 ;; will be nil (when op is =, >, or >=) and t (when op is <, <=), which may be
779 ;; incorrect. However, this gives correct result in our cases, since we are
780 ;; testing for sufficiently high Emacs versions.
781 (defun ediff-check-version (op major minor &optional type-of-emacs)
782 (if (and (boundp 'emacs-major-version) (boundp 'emacs-minor-version))
783 (and (cond ((eq type-of-emacs 'xemacs) (featurep 'xemacs))
784 ((eq type-of-emacs 'emacs) (featurep 'emacs))
785 (t t))
786 (cond ((eq op '=) (and (= emacs-minor-version minor)
787 (= emacs-major-version major)))
788 ((memq op '(> >= < <=))
789 (and (or (funcall op emacs-major-version major)
790 (= emacs-major-version major))
791 (if (= emacs-major-version major)
792 (funcall op emacs-minor-version minor)
793 t)))
795 (error "%S: Invalid op in ediff-check-version" op))))
796 (cond ((memq op '(= > >=)) nil)
797 ((memq op '(< <=)) t))))
800 (defun ediff-color-display-p ()
801 (condition-case nil
802 (ediff-cond-compile-for-xemacs-or-emacs
803 (eq (device-class (selected-device)) 'color) ; xemacs form
804 (if (fboundp 'display-color-p) ; emacs form
805 (display-color-p)
806 (x-display-color-p))
808 (error nil)))
811 ;; A var local to each control panel buffer. Indicates highlighting style
812 ;; in effect for this buffer: `face', `ascii',
813 ;; `off' -- turned off \(on a dumb terminal only\).
814 (ediff-defvar-local ediff-highlighting-style
815 (if (and (ediff-has-face-support-p) ediff-use-faces) 'face 'ascii)
819 (if (ediff-has-face-support-p)
820 (ediff-cond-compile-for-xemacs-or-emacs
821 (progn ; xemacs
822 (defalias 'ediff-valid-color-p 'valid-color-name-p)
823 (defalias 'ediff-get-face 'get-face))
824 (progn ; emacs
825 (defalias 'ediff-valid-color-p (if (fboundp 'color-defined-p)
826 'color-defined-p
827 'x-color-defined-p))
828 (defalias 'ediff-get-face 'internal-get-face))
831 (if (ediff-window-display-p)
832 (ediff-cond-compile-for-xemacs-or-emacs
833 (progn ; xemacs
834 (defalias 'ediff-display-pixel-width 'device-pixel-width)
835 (defalias 'ediff-display-pixel-height 'device-pixel-height))
836 (progn ; emacs
837 (defalias 'ediff-display-pixel-width
838 (if (fboundp 'display-pixel-width)
839 'display-pixel-width
840 'x-display-pixel-width))
841 (defalias 'ediff-display-pixel-height
842 (if (fboundp 'display-pixel-height)
843 'display-pixel-height
844 'x-display-pixel-height)))
847 ;; A-list of current-diff-overlay symbols associated with buf types
848 (defconst ediff-current-diff-overlay-alist
849 '((A . ediff-current-diff-overlay-A)
850 (B . ediff-current-diff-overlay-B)
851 (C . ediff-current-diff-overlay-C)
852 (Ancestor . ediff-current-diff-overlay-Ancestor)))
854 ;; A-list of current-diff-face-* symbols associated with buf types
855 (defconst ediff-current-diff-face-alist
856 '((A . ediff-current-diff-A)
857 (B . ediff-current-diff-B)
858 (C . ediff-current-diff-C)
859 (Ancestor . ediff-current-diff-Ancestor)))
862 (defun ediff-set-overlay-face (extent face)
863 (ediff-overlay-put extent 'face face)
864 (ediff-overlay-put extent 'help-echo 'ediff-region-help-echo))
866 (defun ediff-region-help-echo (extent-or-window &optional overlay point)
867 (unless overlay
868 (setq overlay extent-or-window))
869 (let ((is-current (ediff-overlay-get overlay 'ediff))
870 (face (ediff-overlay-get overlay 'face))
871 (diff-num (ediff-overlay-get overlay 'ediff-diff-num))
872 face-help)
874 ;; This happens only for refinement overlays
875 (if (stringp face)
876 (setq face (intern face)))
877 (setq face-help (and face (get face 'ediff-help-echo)))
879 (cond ((and is-current diff-num) ; current diff region
880 (format "Difference region %S -- current" (1+ diff-num)))
881 (face-help) ; refinement of current diff region
882 (diff-num ; non-current
883 (format "Difference region %S -- non-current" (1+ diff-num)))
884 (t "")) ; none
888 (defun ediff-set-face-pixmap (face pixmap)
889 "Set face pixmap on a monochrome display."
890 (if (and (ediff-window-display-p) (not (ediff-color-display-p)))
891 (condition-case nil
892 (set-face-background-pixmap face pixmap)
893 (error
894 (message "Pixmap not found for %S: %s" (face-name face) pixmap)
895 (sit-for 1)))))
897 (defun ediff-hide-face (face)
898 (if (and (ediff-has-face-support-p)
899 (boundp 'add-to-list)
900 (boundp 'facemenu-unlisted-faces))
901 (add-to-list 'facemenu-unlisted-faces face)))
905 (defface ediff-current-diff-A
906 (if (featurep 'emacs)
907 '((((class color) (min-colors 16))
908 (:foreground "firebrick" :background "pale green"))
909 (((class color))
910 (:foreground "blue3" :background "yellow3"))
911 (t (:inverse-video t)))
912 '((((type tty)) (:foreground "blue3" :background "yellow3"))
913 (((class color)) (:foreground "firebrick" :background "pale green"))
914 (t (:inverse-video t))))
915 "Face for highlighting the selected difference in buffer A."
916 :group 'ediff-highlighting)
917 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
918 ;; this variable is set to nil, then again to the appropriate face.
919 (defvar ediff-current-diff-face-A 'ediff-current-diff-A
920 "Face for highlighting the selected difference in buffer A.
921 DO NOT CHANGE this variable. Instead, use the customization
922 widget to customize the actual face object `ediff-current-diff-A'
923 this variable represents.")
924 (ediff-hide-face ediff-current-diff-face-A)
925 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
926 ;; This means that some user customization may be trashed.
927 (if (and (featurep 'xemacs)
928 (ediff-has-face-support-p)
929 (not (ediff-color-display-p)))
930 (copy-face 'modeline ediff-current-diff-face-A))
934 (defface ediff-current-diff-B
935 (if (featurep 'emacs)
936 '((((class color) (min-colors 16))
937 (:foreground "DarkOrchid" :background "Yellow"))
938 (((class color))
939 (:foreground "magenta3" :background "yellow3"
940 :weight bold))
941 (t (:inverse-video t)))
942 '((((type tty)) (:foreground "magenta3" :background "yellow3"
943 :weight bold))
944 (((class color)) (:foreground "DarkOrchid" :background "Yellow"))
945 (t (:inverse-video t))))
946 "Face for highlighting the selected difference in buffer B."
947 :group 'ediff-highlighting)
948 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
949 ;; this variable is set to nil, then again to the appropriate face.
950 (defvar ediff-current-diff-face-B 'ediff-current-diff-B
951 "Face for highlighting the selected difference in buffer B.
952 this variable. Instead, use the customization
953 widget to customize the actual face `ediff-current-diff-B'
954 this variable represents.")
955 (ediff-hide-face ediff-current-diff-face-B)
956 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
957 ;; This means that some user customization may be trashed.
958 (if (and (featurep 'xemacs)
959 (ediff-has-face-support-p)
960 (not (ediff-color-display-p)))
961 (copy-face 'modeline ediff-current-diff-face-B))
964 (defface ediff-current-diff-C
965 (if (featurep 'emacs)
966 '((((class color) (min-colors 16))
967 (:foreground "Navy" :background "Pink"))
968 (((class color))
969 (:foreground "cyan3" :background "yellow3" :weight bold))
970 (t (:inverse-video t)))
971 '((((type tty)) (:foreground "cyan3" :background "yellow3" :weight bold))
972 (((class color)) (:foreground "Navy" :background "Pink"))
973 (t (:inverse-video t))))
974 "Face for highlighting the selected difference in buffer C."
975 :group 'ediff-highlighting)
976 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
977 ;; this variable is set to nil, then again to the appropriate face.
978 (defvar ediff-current-diff-face-C 'ediff-current-diff-C
979 "Face for highlighting the selected difference in buffer C.
980 DO NOT CHANGE this variable. Instead, use the customization
981 widget to customize the actual face object `ediff-current-diff-C'
982 this variable represents.")
983 (ediff-hide-face ediff-current-diff-face-C)
984 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
985 ;; This means that some user customization may be trashed.
986 (if (and (featurep 'xemacs)
987 (ediff-has-face-support-p)
988 (not (ediff-color-display-p)))
989 (copy-face 'modeline ediff-current-diff-face-C))
992 (defface ediff-current-diff-Ancestor
993 (if (featurep 'emacs)
994 '((((class color) (min-colors 16))
995 (:foreground "Black" :background "VioletRed"))
996 (((class color))
997 (:foreground "black" :background "magenta3"))
998 (t (:inverse-video t)))
999 '((((type tty)) (:foreground "black" :background "magenta3"))
1000 (((class color)) (:foreground "Black" :background "VioletRed"))
1001 (t (:inverse-video t))))
1002 "Face for highlighting the selected difference in buffer Ancestor."
1003 :group 'ediff-highlighting)
1004 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1005 ;; this variable is set to nil, then again to the appropriate face.
1006 (defvar ediff-current-diff-face-Ancestor 'ediff-current-diff-Ancestor
1007 "Face for highlighting the selected difference in buffer Ancestor.
1008 DO NOT CHANGE this variable. Instead, use the customization
1009 widget to customize the actual face object `ediff-current-diff-Ancestor'
1010 this variable represents.")
1011 (ediff-hide-face ediff-current-diff-face-Ancestor)
1012 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
1013 ;; This means that some user customization may be trashed.
1014 (if (and (featurep 'xemacs)
1015 (ediff-has-face-support-p)
1016 (not (ediff-color-display-p)))
1017 (copy-face 'modeline ediff-current-diff-face-Ancestor))
1020 (defface ediff-fine-diff-A
1021 (if (featurep 'emacs)
1022 '((((class color) (min-colors 16))
1023 (:foreground "Navy" :background "sky blue"))
1024 (((class color))
1025 (:foreground "white" :background "sky blue" :weight bold))
1026 (t (:underline t :stipple "gray3")))
1027 '((((type tty)) (:foreground "white" :background "sky blue" :weight bold))
1028 (((class color)) (:foreground "Navy" :background "sky blue"))
1029 (t (:underline t :stipple "gray3"))))
1030 "Face for highlighting the refinement of the selected diff in buffer A."
1031 :group 'ediff-highlighting)
1032 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1033 ;; this variable is set to nil, then again to the appropriate face.
1034 (defvar ediff-fine-diff-face-A 'ediff-fine-diff-A
1035 "Face for highlighting the fine differences in buffer A.
1036 DO NOT CHANGE this variable. Instead, use the customization
1037 widget to customize the actual face object `ediff-fine-diff-A'
1038 this variable represents.")
1039 (ediff-hide-face ediff-fine-diff-face-A)
1041 (defface ediff-fine-diff-B
1042 (if (featurep 'emacs)
1043 '((((class color) (min-colors 16))
1044 (:foreground "Black" :background "cyan"))
1045 (((class color))
1046 (:foreground "magenta3" :background "cyan3"))
1047 (t (:underline t :stipple "gray3")))
1048 '((((type tty)) (:foreground "magenta3" :background "cyan3"))
1049 (((class color)) (:foreground "Black" :background "cyan"))
1050 (t (:underline t :stipple "gray3"))))
1051 "Face for highlighting the refinement of the selected diff in buffer B."
1052 :group 'ediff-highlighting)
1053 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1054 ;; this variable is set to nil, then again to the appropriate face.
1055 (defvar ediff-fine-diff-face-B 'ediff-fine-diff-B
1056 "Face for highlighting the fine differences in buffer B.
1057 DO NOT CHANGE this variable. Instead, use the customization
1058 widget to customize the actual face object `ediff-fine-diff-B'
1059 this variable represents.")
1060 (ediff-hide-face ediff-fine-diff-face-B)
1062 (defface ediff-fine-diff-C
1063 (if (featurep 'emacs)
1064 '((((type pc))
1065 (:foreground "white" :background "Turquoise"))
1066 (((class color) (min-colors 16))
1067 (:foreground "Black" :background "Turquoise"))
1068 (((class color))
1069 (:foreground "yellow3" :background "Turquoise"
1070 :weight bold))
1071 (t (:underline t :stipple "gray3")))
1072 '((((type tty)) (:foreground "yellow3" :background "Turquoise"
1073 :weight bold))
1074 (((type pc)) (:foreground "white" :background "Turquoise"))
1075 (((class color)) (:foreground "Black" :background "Turquoise"))
1076 (t (:underline t :stipple "gray3"))))
1077 "Face for highlighting the refinement of the selected diff in buffer C."
1078 :group 'ediff-highlighting)
1079 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1080 ;; this variable is set to nil, then again to the appropriate face.
1081 (defvar ediff-fine-diff-face-C 'ediff-fine-diff-C
1082 "Face for highlighting the fine differences in buffer C.
1083 DO NOT CHANGE this variable. Instead, use the customization
1084 widget to customize the actual face object `ediff-fine-diff-C'
1085 this variable represents.")
1086 (ediff-hide-face ediff-fine-diff-face-C)
1088 (defface ediff-fine-diff-Ancestor
1089 (if (featurep 'emacs)
1090 '((((class color) (min-colors 16))
1091 (:foreground "Black" :background "Green"))
1092 (((class color))
1093 (:foreground "red3" :background "green"))
1094 (t (:underline t :stipple "gray3")))
1095 '((((type tty)) (:foreground "red3" :background "green"))
1096 (((class color)) (:foreground "Black" :background "Green"))
1097 (t (:underline t :stipple "gray3"))))
1098 "Face for highlighting the refinement of the selected diff in the ancestor buffer.
1099 At present, this face is not used and no fine differences are computed for the
1100 ancestor buffer."
1101 :group 'ediff-highlighting)
1102 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1103 ;; this variable is set to nil, then again to the appropriate face.
1104 (defvar ediff-fine-diff-face-Ancestor 'ediff-fine-diff-Ancestor
1105 "Face for highlighting the fine differences in buffer Ancestor.
1106 DO NOT CHANGE this variable. Instead, use the customization
1107 widget to customize the actual face object `ediff-fine-diff-Ancestor'
1108 this variable represents.")
1109 (ediff-hide-face ediff-fine-diff-face-Ancestor)
1111 ;; Some installs don't have stipple or Stipple. So, try them in turn.
1112 (defvar stipple-pixmap
1113 (cond ((not (ediff-has-face-support-p)) nil)
1114 ((and (boundp 'x-bitmap-file-path)
1115 (locate-library "stipple" t x-bitmap-file-path)) "stipple")
1116 ((and (boundp 'mswindowsx-bitmap-file-path)
1117 (locate-library "stipple" t mswindowsx-bitmap-file-path)) "stipple")
1118 (t "Stipple")))
1120 (defface ediff-even-diff-A
1121 (if (featurep 'emacs)
1122 `((((type pc))
1123 (:foreground "green3" :background "light grey"))
1124 (((class color) (min-colors 16))
1125 (:foreground "Black" :background "light grey"))
1126 (((class color))
1127 (:foreground "red3" :background "light grey"
1128 :weight bold))
1129 (t (:italic t :stipple ,stipple-pixmap)))
1130 `((((type tty)) (:foreground "red3" :background "light grey"
1131 :weight bold))
1132 (((type pc)) (:foreground "green3" :background "light grey"))
1133 (((class color)) (:foreground "Black" :background "light grey"))
1134 (t (:italic t :stipple ,stipple-pixmap))))
1135 "Face for highlighting even-numbered non-current differences in buffer A."
1136 :group 'ediff-highlighting)
1137 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1138 ;; this variable is set to nil, then again to the appropriate face.
1139 (defvar ediff-even-diff-face-A 'ediff-even-diff-A
1140 "Face for highlighting even-numbered non-current differences in buffer A.
1141 DO NOT CHANGE this variable. Instead, use the customization
1142 widget to customize the actual face object `ediff-even-diff-A'
1143 this variable represents.")
1144 (ediff-hide-face ediff-even-diff-face-A)
1146 (defface ediff-even-diff-B
1147 (if (featurep 'emacs)
1148 `((((class color) (min-colors 16))
1149 (:foreground "White" :background "Grey"))
1150 (((class color))
1151 (:foreground "blue3" :background "Grey" :weight bold))
1152 (t (:italic t :stipple ,stipple-pixmap)))
1153 `((((type tty)) (:foreground "blue3" :background "Grey" :weight bold))
1154 (((class color)) (:foreground "White" :background "Grey"))
1155 (t (:italic t :stipple ,stipple-pixmap))))
1156 "Face for highlighting even-numbered non-current differences in buffer B."
1157 :group 'ediff-highlighting)
1158 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1159 ;; this variable is set to nil, then again to the appropriate face.
1160 (defvar ediff-even-diff-face-B 'ediff-even-diff-B
1161 "Face for highlighting even-numbered non-current differences in buffer B.
1162 DO NOT CHANGE this variable. Instead, use the customization
1163 widget to customize the actual face object `ediff-even-diff-B'
1164 this variable represents.")
1165 (ediff-hide-face ediff-even-diff-face-B)
1167 (defface ediff-even-diff-C
1168 (if (featurep 'emacs)
1169 `((((type pc))
1170 (:foreground "yellow3" :background "light grey"))
1171 (((class color) (min-colors 16))
1172 (:foreground "Black" :background "light grey"))
1173 (((class color))
1174 (:foreground "yellow3" :background "light grey"
1175 :weight bold))
1176 (t (:italic t :stipple ,stipple-pixmap)))
1177 `((((type tty)) (:foreground "yellow3" :background "light grey"
1178 :weight bold))
1179 (((type pc)) (:foreground "yellow3" :background "light grey"))
1180 (((class color)) (:foreground "Black" :background "light grey"))
1181 (t (:italic t :stipple ,stipple-pixmap))))
1182 "Face for highlighting even-numbered non-current differences in buffer C."
1183 :group 'ediff-highlighting)
1184 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1185 ;; this variable is set to nil, then again to the appropriate face.
1186 (defvar ediff-even-diff-face-C 'ediff-even-diff-C
1187 "Face for highlighting even-numbered non-current differences in buffer C.
1188 DO NOT CHANGE this variable. Instead, use the customization
1189 widget to customize the actual face object `ediff-even-diff-C'
1190 this variable represents.")
1191 (ediff-hide-face ediff-even-diff-face-C)
1193 (defface ediff-even-diff-Ancestor
1194 (if (featurep 'emacs)
1195 `((((type pc))
1196 (:foreground "cyan3" :background "light grey"))
1197 (((class color) (min-colors 16))
1198 (:foreground "White" :background "Grey"))
1199 (((class color))
1200 (:foreground "cyan3" :background "light grey"
1201 :weight bold))
1202 (t (:italic t :stipple ,stipple-pixmap)))
1203 `((((type tty)) (:foreground "cyan3" :background "light grey"
1204 :weight bold))
1205 (((type pc)) (:foreground "cyan3" :background "light grey"))
1206 (((class color)) (:foreground "White" :background "Grey"))
1207 (t (:italic t :stipple ,stipple-pixmap))))
1208 "Face for highlighting even-numbered non-current differences in the ancestor buffer."
1209 :group 'ediff-highlighting)
1210 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1211 ;; this variable is set to nil, then again to the appropriate face.
1212 (defvar ediff-even-diff-face-Ancestor 'ediff-even-diff-Ancestor
1213 "Face for highlighting even-numbered non-current differences in buffer Ancestor.
1214 DO NOT CHANGE this variable. Instead, use the customization
1215 widget to customize the actual face object `ediff-even-diff-Ancestor'
1216 this variable represents.")
1217 (ediff-hide-face ediff-even-diff-face-Ancestor)
1219 ;; Association between buffer types and even-diff-face symbols
1220 (defconst ediff-even-diff-face-alist
1221 '((A . ediff-even-diff-A)
1222 (B . ediff-even-diff-B)
1223 (C . ediff-even-diff-C)
1224 (Ancestor . ediff-even-diff-Ancestor)))
1226 (defface ediff-odd-diff-A
1227 (if (featurep 'emacs)
1228 '((((type pc))
1229 (:foreground "green3" :background "gray40"))
1230 (((class color) (min-colors 16))
1231 (:foreground "White" :background "Grey"))
1232 (((class color))
1233 (:foreground "red3" :background "black" :weight bold))
1234 (t (:italic t :stipple "gray1")))
1235 '((((type tty)) (:foreground "red3" :background "black" :weight bold))
1236 (((type pc)) (:foreground "green3" :background "gray40"))
1237 (((class color)) (:foreground "White" :background "Grey"))
1238 (t (:italic t :stipple "gray1"))))
1239 "Face for highlighting odd-numbered non-current differences in buffer A."
1240 :group 'ediff-highlighting)
1241 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1242 ;; this variable is set to nil, then again to the appropriate face.
1243 (defvar ediff-odd-diff-face-A 'ediff-odd-diff-A
1244 "Face for highlighting odd-numbered non-current differences in buffer A.
1245 DO NOT CHANGE this variable. Instead, use the customization
1246 widget to customize the actual face object `ediff-odd-diff-A'
1247 this variable represents.")
1248 (ediff-hide-face ediff-odd-diff-face-A)
1251 (defface ediff-odd-diff-B
1252 (if (featurep 'emacs)
1253 '((((type pc))
1254 (:foreground "White" :background "gray40"))
1255 (((class color) (min-colors 16))
1256 (:foreground "Black" :background "light grey"))
1257 (((class color))
1258 (:foreground "cyan3" :background "black" :weight bold))
1259 (t (:italic t :stipple "gray1")))
1260 '((((type tty)) (:foreground "cyan3" :background "black" :weight bold))
1261 (((type pc)) (:foreground "White" :background "gray40"))
1262 (((class color)) (:foreground "Black" :background "light grey"))
1263 (t (:italic t :stipple "gray1"))))
1264 "Face for highlighting odd-numbered non-current differences in buffer B."
1265 :group 'ediff-highlighting)
1266 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1267 ;; this variable is set to nil, then again to the appropriate face.
1268 (defvar ediff-odd-diff-face-B 'ediff-odd-diff-B
1269 "Face for highlighting odd-numbered non-current differences in buffer B.
1270 DO NOT CHANGE this variable. Instead, use the customization
1271 widget to customize the actual face object `ediff-odd-diff-B'
1272 this variable represents.")
1273 (ediff-hide-face ediff-odd-diff-face-B)
1275 (defface ediff-odd-diff-C
1276 (if (featurep 'emacs)
1277 '((((type pc))
1278 (:foreground "yellow3" :background "gray40"))
1279 (((class color) (min-colors 16))
1280 (:foreground "White" :background "Grey"))
1281 (((class color))
1282 (:foreground "yellow3" :background "black" :weight bold))
1283 (t (:italic t :stipple "gray1")))
1284 '((((type tty)) (:foreground "yellow3" :background "black" :weight bold))
1285 (((type pc)) (:foreground "yellow3" :background "gray40"))
1286 (((class color)) (:foreground "White" :background "Grey"))
1287 (t (:italic t :stipple "gray1"))))
1288 "Face for highlighting odd-numbered non-current differences in buffer C."
1289 :group 'ediff-highlighting)
1290 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1291 ;; this variable is set to nil, then again to the appropriate face.
1292 (defvar ediff-odd-diff-face-C 'ediff-odd-diff-C
1293 "Face for highlighting odd-numbered non-current differences in buffer C.
1294 DO NOT CHANGE this variable. Instead, use the customization
1295 widget to customize the actual face object `ediff-odd-diff-C'
1296 this variable represents.")
1297 (ediff-hide-face ediff-odd-diff-face-C)
1299 (defface ediff-odd-diff-Ancestor
1300 (if (featurep 'emacs)
1301 '((((class color) (min-colors 16))
1302 (:foreground "cyan3" :background "gray40"))
1303 (((class color))
1304 (:foreground "green3" :background "black" :weight bold))
1305 (t (:italic t :stipple "gray1")))
1306 '((((type tty)) (:foreground "green3" :background "black" :weight bold))
1307 (((class color)) (:foreground "cyan3" :background "gray40"))
1308 (t (:italic t :stipple "gray1"))))
1309 "Face for highlighting odd-numbered non-current differences in the ancestor buffer."
1310 :group 'ediff-highlighting)
1311 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1312 ;; this variable is set to nil, then again to the appropriate face.
1313 (defvar ediff-odd-diff-face-Ancestor 'ediff-odd-diff-Ancestor
1314 "Face for highlighting odd-numbered non-current differences in buffer Ancestor.
1315 DO NOT CHANGE this variable. Instead, use the customization
1316 widget to customize the actual face object `ediff-odd-diff-Ancestor'
1317 this variable represents.")
1318 (ediff-hide-face ediff-odd-diff-face-Ancestor)
1320 ;; Association between buffer types and odd-diff-face symbols
1321 (defconst ediff-odd-diff-face-alist
1322 '((A . ediff-odd-diff-A)
1323 (B . ediff-odd-diff-B)
1324 (C . ediff-odd-diff-C)
1325 (Ancestor . ediff-odd-diff-Ancestor)))
1327 ;; A-list of fine-diff face symbols associated with buffer types
1328 (defconst ediff-fine-diff-face-alist
1329 '((A . ediff-fine-diff-A)
1330 (B . ediff-fine-diff-B)
1331 (C . ediff-fine-diff-C)
1332 (Ancestor . ediff-fine-diff-Ancestor)))
1334 ;; Help echo
1335 (put ediff-fine-diff-face-A 'ediff-help-echo
1336 "A `refinement' of the current difference region")
1337 (put ediff-fine-diff-face-B 'ediff-help-echo
1338 "A `refinement' of the current difference region")
1339 (put ediff-fine-diff-face-C 'ediff-help-echo
1340 "A `refinement' of the current difference region")
1341 (put ediff-fine-diff-face-Ancestor 'ediff-help-echo
1342 "A `refinement' of the current difference region")
1344 (add-hook 'ediff-quit-hook 'ediff-cleanup-mess)
1345 (add-hook 'ediff-suspend-hook 'ediff-default-suspend-function)
1348 ;;; Overlays
1350 (ediff-defvar-local ediff-current-diff-overlay-A nil
1351 "Overlay for the current difference region in buffer A.")
1352 (ediff-defvar-local ediff-current-diff-overlay-B nil
1353 "Overlay for the current difference region in buffer B.")
1354 (ediff-defvar-local ediff-current-diff-overlay-C nil
1355 "Overlay for the current difference region in buffer C.")
1356 (ediff-defvar-local ediff-current-diff-overlay-Ancestor nil
1357 "Overlay for the current difference region in the ancestor buffer.")
1359 ;; Compute priority of a current ediff overlay.
1360 (defun ediff-highest-priority (start end buffer)
1361 (let ((pos (max 1 (1- start)))
1362 ovr-list)
1363 (ediff-cond-compile-for-xemacs-or-emacs
1364 (1+ ediff-shadow-overlay-priority) ; xemacs form
1365 ;; emacs form
1366 (ediff-with-current-buffer buffer
1367 (while (< pos (min (point-max) (1+ end)))
1368 (setq ovr-list (append (overlays-at pos) ovr-list))
1369 (setq pos (next-overlay-change pos)))
1370 (+ 1 ediff-shadow-overlay-priority
1371 (apply 'max
1372 (cons
1374 (mapcar
1375 (lambda (ovr)
1376 (if (and ovr
1377 ;; exclude ediff overlays from priority
1378 ;; calculation, or else priority will keep
1379 ;; increasing
1380 (null (ediff-overlay-get ovr 'ediff))
1381 (null (ediff-overlay-get ovr 'ediff-diff-num)))
1382 ;; use the overlay priority or 0
1383 (or (ediff-overlay-get ovr 'priority) 0)
1385 ovr-list)
1388 ) ; ediff-cond-compile-for-xemacs-or-emacs
1392 (defvar ediff-toggle-read-only-function nil
1393 "*Specifies the function to be used to toggle read-only.
1394 If nil, Ediff tries to deduce the function from the binding of C-x C-q.
1395 Normally, this is the `toggle-read-only' function, but, if version
1396 control is used, it could be `vc-toggle-read-only' or `rcs-toggle-read-only'.")
1398 (defcustom ediff-make-buffers-readonly-at-startup nil
1399 "*Make all variant buffers read-only when Ediff starts up.
1400 This property can be toggled interactively."
1401 :type 'boolean
1402 :group 'ediff)
1405 ;;; Misc
1407 ;; if nil, this silences some messages
1408 (defvar ediff-verbose-p t)
1410 (defcustom ediff-autostore-merges 'group-jobs-only
1411 "*Save the results of merge jobs automatically.
1412 With value nil, don't save automatically. With value t, always
1413 save. Anything else means save automatically only if the merge
1414 job is part of a group of jobs, such as `ediff-merge-directory'
1415 or `ediff-merge-directory-revisions'."
1416 :type '(choice (const nil) (const t) (const group-jobs-only))
1417 :group 'ediff-merge)
1418 (make-variable-buffer-local 'ediff-autostore-merges)
1420 ;; file where the result of the merge is to be saved. used internally
1421 (ediff-defvar-local ediff-merge-store-file nil "")
1423 (defcustom ediff-merge-filename-prefix "merge_"
1424 "*Prefix to be attached to saved merge buffers."
1425 :type 'string
1426 :group 'ediff-merge)
1428 (defcustom ediff-no-emacs-help-in-control-buffer nil
1429 "*Non-nil means C-h should not invoke Emacs help in control buffer.
1430 Instead, C-h would jump to previous difference."
1431 :type 'boolean
1432 :group 'ediff)
1434 ;; This is the same as temporary-file-directory from Emacs 20.3.
1435 ;; Copied over here because XEmacs doesn't have this variable.
1436 (defcustom ediff-temp-file-prefix
1437 (file-name-as-directory
1438 (cond ((boundp 'temporary-file-directory) temporary-file-directory)
1439 ((fboundp 'temp-directory) (temp-directory))
1440 (t "/tmp/")))
1441 ;;; (file-name-as-directory
1442 ;;; (cond ((memq system-type '(ms-dos windows-nt))
1443 ;;; (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
1444 ;;; ((memq system-type '(vax-vms axp-vms))
1445 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
1446 ;;; (t
1447 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))
1448 "*Prefix to put on Ediff temporary file names.
1449 Do not start with `~/' or `~USERNAME/'."
1450 :type 'string
1451 :group 'ediff)
1453 (defcustom ediff-temp-file-mode 384 ; u=rw only
1454 "*Mode for Ediff temporary files."
1455 :type 'integer
1456 :group 'ediff)
1458 ;; Metacharacters that have to be protected from the shell when executing
1459 ;; a diff/diff3 command.
1460 (defcustom ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
1461 "Regexp that matches characters that must be quoted with `\\' in shell command line.
1462 This default should work without changes."
1463 :type 'string
1464 :group 'ediff)
1466 ;; needed to simulate frame-char-width in XEmacs.
1467 (defvar ediff-H-glyph (if (featurep 'xemacs) (make-glyph "H")))
1470 ;; Temporary file used for refining difference regions in buffer A.
1471 (ediff-defvar-local ediff-temp-file-A nil "")
1472 ;; Temporary file used for refining difference regions in buffer B.
1473 (ediff-defvar-local ediff-temp-file-B nil "")
1474 ;; Temporary file used for refining difference regions in buffer C.
1475 (ediff-defvar-local ediff-temp-file-C nil "")
1478 (defun ediff-file-remote-p (file-name)
1479 (file-remote-p file-name))
1481 ;; File for which we can get attributes, such as size or date
1482 (defun ediff-listable-file (file-name)
1483 (let ((handler (find-file-name-handler file-name 'file-local-copy)))
1484 (or (null handler) (eq handler 'dired-handler-fn))))
1487 (defsubst ediff-frame-unsplittable-p (frame)
1488 (cdr (assq 'unsplittable (frame-parameters frame))))
1490 (defsubst ediff-get-next-window (wind prev-wind)
1491 (cond ((window-live-p wind) wind)
1492 (prev-wind (next-window wind))
1493 (t (selected-window))
1497 (defsubst ediff-kill-buffer-carefully (buf)
1498 "Kill buffer BUF if it exists."
1499 (if (ediff-buffer-live-p buf)
1500 (kill-buffer (get-buffer buf))))
1502 (defsubst ediff-background-face (buf-type dif-num)
1503 ;; The value of dif-num is always 1- the one that user sees.
1504 ;; This is why even face is used when dif-num is odd.
1505 (ediff-get-symbol-from-alist
1506 buf-type (if (ediff-odd-p dif-num)
1507 ediff-even-diff-face-alist
1508 ediff-odd-diff-face-alist)
1512 ;; activate faces on diff regions in buffer
1513 (defun ediff-paint-background-regions-in-one-buffer (buf-type unhighlight)
1514 (let ((diff-vector
1515 (eval (ediff-get-symbol-from-alist
1516 buf-type ediff-difference-vector-alist)))
1517 overl diff-num)
1518 (mapcar (lambda (rec)
1519 (setq overl (ediff-get-diff-overlay-from-diff-record rec)
1520 diff-num (ediff-overlay-get overl 'ediff-diff-num))
1521 (if (ediff-overlay-buffer overl)
1522 ;; only if overlay is alive
1523 (ediff-set-overlay-face
1524 overl
1525 (if (not unhighlight)
1526 (ediff-background-face buf-type diff-num))))
1528 diff-vector)))
1531 ;; activate faces on diff regions in all buffers
1532 (defun ediff-paint-background-regions (&optional unhighlight)
1533 (ediff-paint-background-regions-in-one-buffer
1534 'A unhighlight)
1535 (ediff-paint-background-regions-in-one-buffer
1536 'B unhighlight)
1537 (ediff-paint-background-regions-in-one-buffer
1538 'C unhighlight)
1539 (ediff-paint-background-regions-in-one-buffer
1540 'Ancestor unhighlight))
1543 ;; arg is a record for a given diff in a difference vector
1544 ;; this record is itself a vector
1545 (defsubst ediff-clear-fine-diff-vector (diff-record)
1546 (if diff-record
1547 (mapcar 'ediff-delete-overlay
1548 (ediff-get-fine-diff-vector-from-diff-record diff-record))))
1550 (defsubst ediff-clear-fine-differences-in-one-buffer (n buf-type)
1551 (ediff-clear-fine-diff-vector (ediff-get-difference n buf-type))
1552 (ediff-set-fine-diff-vector n buf-type nil))
1554 (defsubst ediff-clear-fine-differences (n)
1555 (ediff-clear-fine-differences-in-one-buffer n 'A)
1556 (ediff-clear-fine-differences-in-one-buffer n 'B)
1557 (if ediff-3way-job
1558 (ediff-clear-fine-differences-in-one-buffer n 'C)))
1561 (defsubst ediff-mouse-event-p (event)
1562 (ediff-cond-compile-for-xemacs-or-emacs
1563 (button-event-p event) ; xemacs form
1564 (string-match "mouse" (format "%S" (event-basic-type event))) ; emacs form
1568 (defsubst ediff-key-press-event-p (event)
1569 (ediff-cond-compile-for-xemacs-or-emacs
1570 (key-press-event-p event) ; xemacs form
1571 (or (char-or-string-p event) (symbolp event)) ; emacs form
1574 (defun ediff-event-point (event)
1575 (cond ((ediff-mouse-event-p event)
1576 (ediff-cond-compile-for-xemacs-or-emacs
1577 (event-point event) ; xemacs form
1578 (posn-point (event-start event)) ; emacs form
1581 ((ediff-key-press-event-p event)
1582 (point))
1583 (t (error nil))))
1585 (defun ediff-event-buffer (event)
1586 (cond ((ediff-mouse-event-p event)
1587 (ediff-cond-compile-for-xemacs-or-emacs
1588 (event-buffer event) ; xemacs form
1589 (window-buffer (posn-window (event-start event))) ; emacs form
1592 ((ediff-key-press-event-p event)
1593 (current-buffer))
1594 (t (error nil))))
1596 (defun ediff-event-key (event-or-key)
1597 (ediff-cond-compile-for-xemacs-or-emacs
1598 (if (eventp event-or-key) (event-key event-or-key) event-or-key) ; xemacs
1599 event-or-key ; emacs form
1603 (defsubst ediff-frame-iconified-p (frame)
1604 (if (and (ediff-window-display-p) (frame-live-p frame))
1605 (ediff-cond-compile-for-xemacs-or-emacs
1606 (frame-iconified-p frame) ; xemacs form
1607 (eq (frame-visible-p frame) 'icon) ; emacs form
1611 (defsubst ediff-window-visible-p (wind)
1612 ;; under TTY, window-live-p also means window is visible
1613 (and (window-live-p wind)
1614 (or (not (ediff-window-display-p))
1615 (frame-visible-p (window-frame wind)))))
1618 (defsubst ediff-frame-char-width (frame)
1619 (ediff-cond-compile-for-xemacs-or-emacs
1620 (/ (frame-pixel-width frame) (frame-width frame)) ; xemacs
1621 (frame-char-width frame) ; emacs
1624 (defun ediff-reset-mouse (&optional frame do-not-grab-mouse)
1625 (or frame (setq frame (selected-frame)))
1626 (if (ediff-window-display-p)
1627 (let ((frame-or-wind frame))
1628 (if (featurep 'xemacs)
1629 (setq frame-or-wind (frame-selected-window frame)))
1630 (or do-not-grab-mouse
1631 ;; don't set mouse if the user said to never do this
1632 (not ediff-grab-mouse)
1633 ;; Don't grab on quit, if the user doesn't want to.
1634 ;; If ediff-grab-mouse = t, then mouse won't be grabbed for
1635 ;; sessions that are not part of a group (this is done in
1636 ;; ediff-recenter). The condition below affects only terminating
1637 ;; sessions in session groups (in which case mouse is warped into
1638 ;; a meta buffer).
1639 (and (eq ediff-grab-mouse 'maybe)
1640 (memq this-command '(ediff-quit ediff-update-diffs)))
1641 (set-mouse-position frame-or-wind 1 0))
1644 (defsubst ediff-spy-after-mouse ()
1645 (setq ediff-mouse-pixel-position (mouse-pixel-position)))
1647 ;; It is not easy to find out when the user grabs the mouse, since emacs and
1648 ;; xemacs behave differently when mouse is not in any frame. Also, this is
1649 ;; sensitive to when the user grabbed mouse. Not used for now.
1650 (defun ediff-user-grabbed-mouse ()
1651 (if ediff-mouse-pixel-position
1652 (cond ((not (eq (car ediff-mouse-pixel-position)
1653 (car (mouse-pixel-position)))))
1654 ((and (car (cdr ediff-mouse-pixel-position))
1655 (car (cdr (mouse-pixel-position)))
1656 (cdr (cdr ediff-mouse-pixel-position))
1657 (cdr (cdr (mouse-pixel-position))))
1658 (not (and (< (abs (- (car (cdr ediff-mouse-pixel-position))
1659 (car (cdr (mouse-pixel-position)))))
1660 ediff-mouse-pixel-threshold)
1661 (< (abs (- (cdr (cdr ediff-mouse-pixel-position))
1662 (cdr (cdr (mouse-pixel-position)))))
1663 ediff-mouse-pixel-threshold))))
1664 (t nil))))
1666 (defsubst ediff-frame-char-height (frame)
1667 (ediff-cond-compile-for-xemacs-or-emacs
1668 (glyph-height ediff-H-glyph (frame-selected-window frame)) ; xemacs case
1669 (frame-char-height frame) ; emacs case
1673 ;; Some overlay functions
1675 (defsubst ediff-overlay-start (overl)
1676 (if (ediff-overlayp overl)
1677 (ediff-cond-compile-for-xemacs-or-emacs
1678 (extent-start-position overl) ; xemacs form
1679 (overlay-start overl) ; emacs form
1683 (defsubst ediff-overlay-end (overl)
1684 (if (ediff-overlayp overl)
1685 (ediff-cond-compile-for-xemacs-or-emacs
1686 (extent-end-position overl) ; xemacs form
1687 (overlay-end overl) ; emacs form
1691 (defsubst ediff-empty-overlay-p (overl)
1692 (= (ediff-overlay-start overl) (ediff-overlay-end overl)))
1694 ;; like overlay-buffer in Emacs. In XEmacs, returns nil if the extent is
1695 ;; dead. Otherwise, works like extent-buffer
1696 (defun ediff-overlay-buffer (overl)
1697 (ediff-cond-compile-for-xemacs-or-emacs
1698 (and (extent-live-p overl) (extent-object overl)) ; xemacs form
1699 (overlay-buffer overl) ; emacs form
1702 ;; like overlay-get in Emacs. In XEmacs, returns nil if the extent is
1703 ;; dead. Otherwise, like extent-property
1704 (defun ediff-overlay-get (overl property)
1705 (ediff-cond-compile-for-xemacs-or-emacs
1706 (and (extent-live-p overl) (extent-property overl property)) ; xemacs form
1707 (overlay-get overl property) ; emacs form
1711 ;; These two functions are here because XEmacs refuses to
1712 ;; handle overlays whose buffers were deleted.
1713 (defun ediff-move-overlay (overlay beg end &optional buffer)
1714 "Calls `move-overlay' in Emacs and `set-extent-endpoints' in Lemacs.
1715 Checks if overlay's buffer exists before actually doing the move."
1716 (let ((buf (and overlay (ediff-overlay-buffer overlay))))
1717 (if (ediff-buffer-live-p buf)
1718 (ediff-cond-compile-for-xemacs-or-emacs
1719 (set-extent-endpoints overlay beg end) ; xemacs form
1720 (move-overlay overlay beg end buffer) ; emacs form
1722 ;; buffer's dead
1723 (if overlay
1724 (ediff-delete-overlay overlay)))))
1726 (defun ediff-overlay-put (overlay prop value)
1727 "Calls `overlay-put' or `set-extent-property' depending on Emacs version.
1728 Checks if overlay's buffer exists."
1729 (if (ediff-buffer-live-p (ediff-overlay-buffer overlay))
1730 (ediff-cond-compile-for-xemacs-or-emacs
1731 (set-extent-property overlay prop value) ; xemacs form
1732 (overlay-put overlay prop value) ; emacs form
1734 (ediff-delete-overlay overlay)))
1736 ;; temporarily uses DIR to abbreviate file name
1737 ;; if DIR is nil, use default-directory
1738 (defun ediff-abbreviate-file-name (file &optional dir)
1739 (cond ((stringp dir)
1740 (let ((directory-abbrev-alist (list (cons dir ""))))
1741 (abbreviate-file-name file)))
1743 (ediff-cond-compile-for-xemacs-or-emacs
1744 ;; XEmacs requires addl argument
1745 (abbreviate-file-name file t) ; xemacs form
1746 (abbreviate-file-name file)) ; emacs form
1750 ;; Takes a directory and returns the parent directory.
1751 ;; does nothing to `/'. If the ARG is a regular file,
1752 ;; strip the file AND the last dir.
1753 (defun ediff-strip-last-dir (dir)
1754 (if (not (stringp dir)) (setq dir default-directory))
1755 (setq dir (expand-file-name dir))
1756 (or (file-directory-p dir) (setq dir (file-name-directory dir)))
1757 (let* ((pos (1- (length dir)))
1758 (last-char (aref dir pos)))
1759 (if (and (> pos 0) (= last-char ?/))
1760 (setq dir (substring dir 0 pos)))
1761 (ediff-abbreviate-file-name (file-name-directory dir))))
1763 (defun ediff-truncate-string-left (str newlen)
1764 ;; leave space for ... on the left
1765 (let ((len (length str))
1766 substr)
1767 (if (<= len newlen)
1769 (setq newlen (max 0 (- newlen 3)))
1770 (setq substr (substring str (max 0 (- len 1 newlen))))
1771 (concat "..." substr))))
1773 (defsubst ediff-nonempty-string-p (string)
1774 (and (stringp string) (not (string= string ""))))
1776 (unless (fboundp 'subst-char-in-string)
1777 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1778 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1779 Unless optional argument INPLACE is non-nil, return a new string."
1780 (let ((i (length string))
1781 (newstr (if inplace string (copy-sequence string))))
1782 (while (> i 0)
1783 (setq i (1- i))
1784 (if (eq (aref newstr i) fromchar)
1785 (aset newstr i tochar)))
1786 newstr)))
1788 (defun ediff-abbrev-jobname (jobname)
1789 (cond ((eq jobname 'ediff-directories)
1790 "Compare two directories")
1791 ((eq jobname 'ediff-files)
1792 "Compare two files")
1793 ((eq jobname 'ediff-buffers)
1794 "Compare two buffers")
1795 ((eq jobname 'ediff-directories3)
1796 "Compare three directories")
1797 ((eq jobname 'ediff-files3)
1798 "Compare three files")
1799 ((eq jobname 'ediff-buffers3)
1800 "Compare three buffers")
1801 ((eq jobname 'ediff-revision)
1802 "Compare file with a version")
1803 ((eq jobname 'ediff-directory-revisions)
1804 "Compare dir files with versions")
1805 ((eq jobname 'ediff-merge-directory-revisions)
1806 "Merge dir files with versions")
1807 ((eq jobname 'ediff-merge-directory-revisions-with-ancestor)
1808 "Merge dir versions via ancestors")
1810 (capitalize
1811 (subst-char-in-string ?- ?\s (substring (symbol-name jobname) 6))))
1815 ;; If ediff modified mode line, strip the modification
1816 (defsubst ediff-strip-mode-line-format ()
1817 (if (member (car mode-line-format) '(" A: " " B: " " C: " " Ancestor: "))
1818 (setq mode-line-format (nth 2 mode-line-format))))
1820 ;; Verify that we have a difference selected.
1821 (defsubst ediff-valid-difference-p (&optional n)
1822 (or n (setq n ediff-current-difference))
1823 (and (>= n 0) (< n ediff-number-of-differences)))
1825 (defsubst ediff-show-all-diffs (n)
1826 "Don't skip difference regions."
1827 nil)
1829 (defsubst Xor (a b)
1830 (or (and a (not b)) (and (not a) b)))
1832 (defsubst ediff-message-if-verbose (string &rest args)
1833 (if ediff-verbose-p
1834 (apply 'message string args)))
1836 (defun ediff-file-attributes (filename attr-number)
1837 (if (ediff-listable-file filename)
1838 (nth attr-number (file-attributes filename))
1842 (defsubst ediff-file-size (filename)
1843 (ediff-file-attributes filename 7))
1844 (defsubst ediff-file-modtime (filename)
1845 (ediff-file-attributes filename 5))
1848 (defun ediff-convert-standard-filename (fname)
1849 (if (fboundp 'convert-standard-filename)
1850 (convert-standard-filename fname)
1851 fname))
1854 (if (fboundp 'with-syntax-table)
1855 (defalias 'ediff-with-syntax-table 'with-syntax-table)
1856 ;; stolen from subr.el in emacs 21
1857 (defmacro ediff-with-syntax-table (table &rest body)
1858 (let ((old-table (make-symbol "table"))
1859 (old-buffer (make-symbol "buffer")))
1860 `(let ((,old-table (syntax-table))
1861 (,old-buffer (current-buffer)))
1862 (unwind-protect
1863 (progn
1864 (set-syntax-table (copy-syntax-table ,table))
1865 ,@body)
1866 (save-current-buffer
1867 (set-buffer ,old-buffer)
1868 (set-syntax-table ,old-table)))))))
1871 (provide 'ediff-init)
1875 ;; Local Variables:
1876 ;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1877 ;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1878 ;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1879 ;; End:
1881 ;; arch-tag: fa31d384-1e70-4d4b-82a7-3e96307c46f5
1882 ;;; ediff-init.el ends here