Add arch tagline
[emacs.git] / lisp / ediff-init.el
blobd37096f9e89d4c7c93ee5dd867833d24d0e28597
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 2, 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 ;; Is it XEmacs?
47 (defconst ediff-xemacs-p (featurep 'xemacs))
48 ;; Is it Emacs?
49 (defconst ediff-emacs-p (not ediff-xemacs-p))
51 ;; This is used to avoid compilation warnings. When emacs/xemacs forms can
52 ;; generate compile time warnings, we use this macro.
53 ;; In this case, the macro will expand into the form that is appropriate to the
54 ;; compiler at hand.
55 ;; Suggested by rms.
56 (defmacro ediff-cond-compile-for-xemacs-or-emacs (xemacs-form emacs-form)
57 (if (featurep 'xemacs)
58 xemacs-form emacs-form))
60 (defvar ediff-force-faces nil
61 "If t, Ediff will think that it is running on a display that supports faces.
62 This is provided as a temporary relief for users of face-capable displays
63 that Ediff doesn't know about.")
65 ;; Are we running as a window application or on a TTY?
66 (defsubst ediff-device-type ()
67 (ediff-cond-compile-for-xemacs-or-emacs
68 (device-type (selected-device)) ; xemacs form
69 window-system ; emacs form
72 ;; in XEmacs: device-type is tty on tty and stream in batch.
73 (defun ediff-window-display-p ()
74 (and (ediff-device-type) (not (memq (ediff-device-type) '(tty pc stream)))))
76 ;; test if supports faces
77 (defun ediff-has-face-support-p ()
78 (cond ((ediff-window-display-p))
79 (ediff-force-faces)
80 ((ediff-color-display-p))
81 (ediff-emacs-p (memq (ediff-device-type) '(pc)))
82 (ediff-xemacs-p (memq (ediff-device-type) '(tty pc)))
85 ;; toolbar support for emacs hasn't been implemented in ediff
86 (defun ediff-has-toolbar-support-p ()
87 (ediff-cond-compile-for-xemacs-or-emacs
88 (and (featurep 'toolbar) (console-on-window-system-p)) ; xemacs form
89 nil ; emacs form
93 (defun ediff-has-gutter-support-p ()
94 (ediff-cond-compile-for-xemacs-or-emacs
95 (and (featurep 'gutter) (console-on-window-system-p)) ; xemacs form
96 nil ; emacs form
100 (defun ediff-use-toolbar-p ()
101 (and (ediff-has-toolbar-support-p) ;Can it do it ?
102 (boundp 'ediff-use-toolbar-p)
103 ediff-use-toolbar-p)) ;Does the user want it ?
105 ;; Defines SYMBOL as an advertised local variable.
106 ;; Performs a defvar, then executes `make-variable-buffer-local' on
107 ;; the variable. Also sets the `permanent-local' property,
108 ;; so that `kill-all-local-variables' (called by major-mode setting
109 ;; commands) won't destroy Ediff control variables.
111 ;; Plagiarised from `emerge-defvar-local' for XEmacs.
112 (defmacro ediff-defvar-local (var value doc)
113 (declare (indent defun))
114 `(progn
115 (defvar ,var ,value ,doc)
116 (make-variable-buffer-local ',var)
117 (put ',var 'permanent-local t)))
121 ;; Variables that control each Ediff session---local to the control buffer.
123 ;; Mode variables
124 ;; The buffer in which the A variant is stored.
125 (ediff-defvar-local ediff-buffer-A nil "")
126 ;; The buffer in which the B variant is stored.
127 (ediff-defvar-local ediff-buffer-B nil "")
128 ;; The buffer in which the C variant is stored or where the merge buffer lives.
129 (ediff-defvar-local ediff-buffer-C nil "")
130 ;; Ancestor buffer
131 (ediff-defvar-local ediff-ancestor-buffer nil "")
132 ;; The Ediff control buffer
133 (ediff-defvar-local ediff-control-buffer nil "")
135 (ediff-defvar-local ediff-temp-indirect-buffer nil
136 "If t, the buffer is a temporary indirect buffer.
137 It needs to be killed when we quit the session.")
140 ;; Association between buff-type and ediff-buffer-*
141 (defconst ediff-buffer-alist
142 '((?A . ediff-buffer-A)
143 (?B . ediff-buffer-B)
144 (?C . ediff-buffer-C)))
146 ;;; Macros
147 (defmacro ediff-odd-p (arg)
148 `(eq (logand ,arg 1) 1))
150 (defmacro ediff-buffer-live-p (buf)
151 `(and ,buf (get-buffer ,buf) (buffer-name (get-buffer ,buf))))
153 (defmacro ediff-get-buffer (arg)
154 `(cond ((eq ,arg 'A) ediff-buffer-A)
155 ((eq ,arg 'B) ediff-buffer-B)
156 ((eq ,arg 'C) ediff-buffer-C)
157 ((eq ,arg 'Ancestor) ediff-ancestor-buffer)
160 (defmacro ediff-get-value-according-to-buffer-type (buf-type list)
161 `(cond ((eq ,buf-type 'A) (nth 0 ,list))
162 ((eq ,buf-type 'B) (nth 1 ,list))
163 ((eq ,buf-type 'C) (nth 2 ,list))
166 (defmacro ediff-char-to-buftype (arg)
167 `(cond ((memq ,arg '(?a ?A)) 'A)
168 ((memq ,arg '(?b ?B)) 'B)
169 ((memq ,arg '(?c ?C)) 'C)
173 ;; A-list is supposed to be of the form (A . symb) (B . symb)...)
174 ;; where the first part of any association is a buffer type and the second is
175 ;; an appropriate symbol. Given buffer-type, this function returns the
176 ;; symbol. This is used to avoid using `intern'
177 (defsubst ediff-get-symbol-from-alist (buf-type alist)
178 (cdr (assoc buf-type alist)))
180 (defconst ediff-difference-vector-alist
181 '((A . ediff-difference-vector-A)
182 (B . ediff-difference-vector-B)
183 (C . ediff-difference-vector-C)
184 (Ancestor . ediff-difference-vector-Ancestor)))
186 (defmacro ediff-get-difference (n buf-type)
187 `(aref
188 (symbol-value
189 (ediff-get-symbol-from-alist
190 ,buf-type ediff-difference-vector-alist))
191 ,n))
193 ;; Tell if it has been previously determined that the region has
194 ;; no diffs other than the white space and newlines
195 ;; The argument, N, is the diff region number used by Ediff to index the
196 ;; diff vector. It is 1 less than the number seen by the user.
197 ;; Returns:
198 ;; t if the diffs are whitespace in all buffers
199 ;; 'A (in 3-buf comparison only) if there are only whitespace
200 ;; diffs in bufs B and C
201 ;; 'B (in 3-buf comparison only) if there are only whitespace
202 ;; diffs in bufs A and C
203 ;; 'C (in 3-buf comparison only) if there are only whitespace
204 ;; diffs in bufs A and B
206 ;; A Difference Vector has the form:
207 ;; [diff diff diff ...]
208 ;; where each diff has the form:
209 ;; [overlay fine-diff-vector no-fine-diffs-flag state-of-difference]
210 ;; fine-diff-vector is a vector [fine-diff fine-diff fine-diff ...]
211 ;; no-fine-diffs-flag says if there are fine differences.
212 ;; state-of-difference is A, B, C, or nil, indicating which buffer is
213 ;; different from the other two (used only in 3-way jobs).
214 (defmacro ediff-no-fine-diffs-p (n)
215 `(aref (ediff-get-difference ,n 'A) 2))
217 (defmacro ediff-get-diff-overlay-from-diff-record (diff-rec)
218 `(aref ,diff-rec 0))
220 (defmacro ediff-get-diff-overlay (n buf-type)
221 `(ediff-get-diff-overlay-from-diff-record
222 (ediff-get-difference ,n ,buf-type)))
224 (defmacro ediff-get-fine-diff-vector-from-diff-record (diff-rec)
225 `(aref ,diff-rec 1))
227 (defmacro ediff-set-fine-diff-vector (n buf-type fine-vec)
228 `(aset (ediff-get-difference ,n ,buf-type) 1 ,fine-vec))
230 (defmacro ediff-get-state-of-diff (n buf-type)
231 `(if (ediff-buffer-live-p ediff-buffer-C)
232 (aref (ediff-get-difference ,n ,buf-type) 3)))
233 (defmacro ediff-set-state-of-diff (n buf-type val)
234 `(aset (ediff-get-difference ,n ,buf-type) 3 ,val))
236 (defmacro ediff-get-state-of-merge (n)
237 `(if ediff-state-of-merge
238 (aref (aref ediff-state-of-merge ,n) 0)))
239 (defmacro ediff-set-state-of-merge (n val)
240 `(if ediff-state-of-merge
241 (aset (aref ediff-state-of-merge ,n) 0 ,val)))
243 (defmacro ediff-get-state-of-ancestor (n)
244 `(if ediff-state-of-merge
245 (aref (aref ediff-state-of-merge ,n) 1)))
247 ;; if flag is t, puts a mark on diff region saying that
248 ;; the differences are in white space only. If flag is nil,
249 ;; the region is marked as essential (i.e., differences are
250 ;; not just in the white space and newlines.)
251 (defmacro ediff-mark-diff-as-space-only (n flag)
252 `(aset (ediff-get-difference ,n 'A) 2 ,flag))
254 (defmacro ediff-get-fine-diff-vector (n buf-type)
255 `(ediff-get-fine-diff-vector-from-diff-record
256 (ediff-get-difference ,n ,buf-type)))
258 ;; Macro to switch to BUFFER, evaluate BODY, returns to original buffer.
259 ;; Doesn't save the point and mark.
260 ;; This is `with-current-buffer' with the added test for live buffers."
261 (defmacro ediff-with-current-buffer (buffer &rest body)
262 (declare (indent 1) (debug (form body)))
263 `(if (ediff-buffer-live-p ,buffer)
264 (save-current-buffer
265 (set-buffer ,buffer)
266 ,@body)
267 (or (eq this-command 'ediff-quit)
268 (error ediff-KILLED-VITAL-BUFFER))
272 (defsubst ediff-multiframe-setup-p ()
273 (and (ediff-window-display-p) ediff-multiframe))
275 (defmacro ediff-narrow-control-frame-p ()
276 `(and (ediff-multiframe-setup-p)
277 (equal ediff-help-message ediff-brief-message-string)))
279 (defmacro ediff-3way-comparison-job ()
280 `(memq
281 ediff-job-name
282 '(ediff-files3 ediff-buffers3)))
283 (ediff-defvar-local ediff-3way-comparison-job nil "")
285 (defmacro ediff-merge-job ()
286 `(memq
287 ediff-job-name
288 '(ediff-merge-files
289 ediff-merge-buffers
290 ediff-merge-files-with-ancestor
291 ediff-merge-buffers-with-ancestor
292 ediff-merge-revisions
293 ediff-merge-revisions-with-ancestor)))
294 (ediff-defvar-local ediff-merge-job nil "")
296 (defmacro ediff-patch-job ()
297 `(eq ediff-job-name 'epatch))
299 (defmacro ediff-merge-with-ancestor-job ()
300 `(memq
301 ediff-job-name
302 '(ediff-merge-files-with-ancestor
303 ediff-merge-buffers-with-ancestor
304 ediff-merge-revisions-with-ancestor)))
305 (ediff-defvar-local ediff-merge-with-ancestor-job nil "")
307 (defmacro ediff-3way-job ()
308 `(or ediff-3way-comparison-job ediff-merge-job))
309 (ediff-defvar-local ediff-3way-job nil "")
311 ;; A diff3 job is like a 3way job, but ediff-merge doesn't require the use
312 ;; of diff3.
313 (defmacro ediff-diff3-job ()
314 `(or ediff-3way-comparison-job
315 ediff-merge-with-ancestor-job))
316 (ediff-defvar-local ediff-diff3-job nil "")
318 (defmacro ediff-windows-job ()
319 `(memq ediff-job-name '(ediff-windows-wordwise ediff-windows-linewise)))
320 (ediff-defvar-local ediff-windows-job nil "")
322 (defmacro ediff-word-mode-job ()
323 `(memq ediff-job-name '(ediff-windows-wordwise ediff-regions-wordwise)))
324 (ediff-defvar-local ediff-word-mode-job nil "")
326 (defmacro ediff-narrow-job ()
327 `(memq ediff-job-name '(ediff-windows-wordwise
328 ediff-regions-wordwise
329 ediff-windows-linewise
330 ediff-regions-linewise)))
331 (ediff-defvar-local ediff-narrow-job nil "")
333 ;; Note: ediff-merge-directory-revisions-with-ancestor is not treated as an
334 ;; ancestor metajob, since it behaves differently.
335 (defsubst ediff-ancestor-metajob (&optional metajob)
336 (memq (or metajob ediff-metajob-name)
337 '(ediff-merge-directories-with-ancestor
338 ediff-merge-filegroups-with-ancestor)))
339 (defsubst ediff-revision-metajob (&optional metajob)
340 (memq (or metajob ediff-metajob-name)
341 '(ediff-directory-revisions
342 ediff-merge-directory-revisions
343 ediff-merge-directory-revisions-with-ancestor)))
344 (defsubst ediff-patch-metajob (&optional metajob)
345 (memq (or metajob ediff-metajob-name)
346 '(ediff-multifile-patch)))
347 ;; metajob involving only one group of files, such as multipatch or directory
348 ;; revision
349 (defsubst ediff-one-filegroup-metajob (&optional metajob)
350 (or (ediff-revision-metajob metajob)
351 (ediff-patch-metajob metajob)
352 ;; add more here
354 ;; jobs suitable for the operation of collecting diffs into a multifile patch
355 (defsubst ediff-collect-diffs-metajob (&optional metajob)
356 (memq (or metajob ediff-metajob-name)
357 '(ediff-directories
358 ediff-merge-directories
359 ediff-merge-directories-with-ancestor
360 ediff-directory-revisions
361 ediff-merge-directory-revisions
362 ediff-merge-directory-revisions-with-ancestor
363 ;; add more here
365 (defsubst ediff-merge-metajob (&optional metajob)
366 (memq (or metajob ediff-metajob-name)
367 '(ediff-merge-directories
368 ediff-merge-directories-with-ancestor
369 ediff-merge-directory-revisions
370 ediff-merge-directory-revisions-with-ancestor
371 ediff-merge-filegroups-with-ancestor
372 ;; add more here
375 (defsubst ediff-metajob3 (&optional metajob)
376 (memq (or metajob ediff-metajob-name)
377 '(ediff-merge-directories-with-ancestor
378 ediff-merge-filegroups-with-ancestor
379 ediff-directories3
380 ediff-filegroups3)))
381 (defsubst ediff-comparison-metajob3 (&optional metajob)
382 (memq (or metajob ediff-metajob-name)
383 '(ediff-directories3 ediff-filegroups3)))
385 ;; with no argument, checks if we are in ediff-control-buffer
386 ;; with argument, checks if we are in ediff-meta-buffer
387 (defun ediff-in-control-buffer-p (&optional meta-buf-p)
388 (and (boundp 'ediff-control-buffer)
389 (eq (if meta-buf-p ediff-meta-buffer ediff-control-buffer)
390 (current-buffer))))
392 (defsubst ediff-barf-if-not-control-buffer (&optional meta-buf-p)
393 (or (ediff-in-control-buffer-p meta-buf-p)
394 (error "%S: This command runs in Ediff Control Buffer only!"
395 this-command)))
397 (defgroup ediff-highlighting nil
398 "Hilighting of difference regions in Ediff."
399 :prefix "ediff-"
400 :group 'ediff)
402 (defgroup ediff-merge nil
403 "Merging utilities."
404 :prefix "ediff-"
405 :group 'ediff)
407 (defgroup ediff-hook nil
408 "Hooks run by Ediff."
409 :prefix "ediff-"
410 :group 'ediff)
412 ;; Hook variables
414 (defcustom ediff-before-setup-hook nil
415 "*Hooks to run before Ediff begins to set up windows and buffers.
416 This hook can be used to save the previous window config, which can be restored
417 on ediff-quit or ediff-suspend."
418 :type 'hook
419 :group 'ediff-hook)
420 (defcustom ediff-before-setup-windows-hook nil
421 "*Hooks to run before Ediff sets its window configuration.
422 This hook is run every time when Ediff arranges its windows.
423 This happens each time Ediff detects that the windows were messed up by the
424 user."
425 :type 'hook
426 :group 'ediff-hook)
427 (defcustom ediff-after-setup-windows-hook nil
428 "*Hooks to run after Ediff sets its window configuration.
429 This can be used to set up control window or icon in a desired place."
430 :type 'hook
431 :group 'ediff-hook)
432 (defcustom ediff-before-setup-control-frame-hook nil
433 "*Hooks run before setting up the frame to display Ediff Control Panel.
434 Can be used to change control frame parameters to position it where it
435 is desirable."
436 :type 'hook
437 :group 'ediff-hook)
438 (defcustom ediff-after-setup-control-frame-hook nil
439 "*Hooks run after setting up the frame to display Ediff Control Panel.
440 Can be used to move the frame where it is desired."
441 :type 'hook
442 :group 'ediff-hook)
443 (defcustom ediff-startup-hook nil
444 "*Hooks to run in the control buffer after Ediff has been set up and is ready for the job."
445 :type 'hook
446 :group 'ediff-hook)
447 (defcustom ediff-select-hook nil
448 "*Hooks to run after a difference has been selected."
449 :type 'hook
450 :group 'ediff-hook)
451 (defcustom ediff-unselect-hook nil
452 "*Hooks to run after a difference has been unselected."
453 :type 'hook
454 :group 'ediff-hook)
455 (defcustom ediff-prepare-buffer-hook nil
456 "*Hooks run after buffers A, B, and C are set up.
457 For each buffer, the hooks are run with that buffer made current."
458 :type 'hook
459 :group 'ediff-hook)
460 (defcustom ediff-load-hook nil
461 "*Hook run after Ediff is loaded. Can be used to change defaults."
462 :type 'hook
463 :group 'ediff-hook)
465 (defcustom ediff-mode-hook nil
466 "*Hook run just after ediff-mode is set up in the control buffer.
467 This is done before any windows or frames are created. One can use it to
468 set local variables that determine how the display looks like."
469 :type 'hook
470 :group 'ediff-hook)
471 (defcustom ediff-keymap-setup-hook nil
472 "*Hook run just after the default bindings in Ediff keymap are set up."
473 :type 'hook
474 :group 'ediff-hook)
476 (defcustom ediff-display-help-hook nil
477 "*Hooks run after preparing the help message."
478 :type 'hook
479 :group 'ediff-hook)
481 (defcustom ediff-suspend-hook nil
482 "*Hooks to run in the Ediff control buffer when Ediff is suspended."
483 :type 'hook
484 :group 'ediff-hook)
485 (defcustom ediff-quit-hook nil
486 "*Hooks to run in the Ediff control buffer after finishing Ediff."
487 :type 'hook
488 :group 'ediff-hook)
489 (defcustom ediff-cleanup-hook nil
490 "*Hooks to run on exiting Ediff but before killing the control and variant buffers."
491 :type 'hook
492 :group 'ediff-hook)
494 ;; Error messages
495 (defconst ediff-KILLED-VITAL-BUFFER
496 "You have killed a vital Ediff buffer---you must leave Ediff now!")
497 (defconst ediff-NO-DIFFERENCES
498 "Sorry, comparison of identical variants is not what I am made for...")
499 (defconst ediff-BAD-DIFF-NUMBER
500 ;; %S stands for this-command, %d - diff number, %d - max diff
501 "%S: Bad diff region number, %d. Valid numbers are 1 to %d")
502 (defconst ediff-BAD-INFO (format "
503 *** The Info file for Ediff, a part of the standard distribution
504 *** of %sEmacs, does not seem to be properly installed.
506 *** Please contact your system administrator. "
507 (if ediff-xemacs-p "X" "")))
509 ;; Selective browsing
511 (ediff-defvar-local ediff-skip-diff-region-function 'ediff-show-all-diffs
512 "Function that determines the next/previous diff region to show.
513 Should return t for regions to be ignored and nil otherwise.
514 This function gets a region number as an argument. The region number
515 is the one used internally by Ediff. It is 1 less than the number seen
516 by the user.")
518 (ediff-defvar-local ediff-hide-regexp-matches-function
519 'ediff-hide-regexp-matches
520 "Function to use in determining which regions to hide.
521 See the documentation string of `ediff-hide-regexp-matches' for details.")
522 (ediff-defvar-local ediff-focus-on-regexp-matches-function
523 'ediff-focus-on-regexp-matches
524 "Function to use in determining which regions to focus on.
525 See the documentation string of `ediff-focus-on-regexp-matches' for details.")
527 ;; Regexp that determines buf A regions to focus on when skipping to diff
528 (ediff-defvar-local ediff-regexp-focus-A "" "")
529 ;; Regexp that determines buf B regions to focus on when skipping to diff
530 (ediff-defvar-local ediff-regexp-focus-B "" "")
531 ;; Regexp that determines buf C regions to focus on when skipping to diff
532 (ediff-defvar-local ediff-regexp-focus-C "" "")
533 ;; connective that determines whether to focus regions that match both or
534 ;; one of the regexps
535 (ediff-defvar-local ediff-focus-regexp-connective 'and "")
537 ;; Regexp that determines buf A regions to ignore when skipping to diff
538 (ediff-defvar-local ediff-regexp-hide-A "" "")
539 ;; Regexp that determines buf B regions to ignore when skipping to diff
540 (ediff-defvar-local ediff-regexp-hide-B "" "")
541 ;; Regexp that determines buf C regions to ignore when skipping to diff
542 (ediff-defvar-local ediff-regexp-hide-C "" "")
543 ;; connective that determines whether to hide regions that match both or
544 ;; one of the regexps
545 (ediff-defvar-local ediff-hide-regexp-connective 'and "")
548 ;;; Copying difference regions between buffers.
550 ;; A list of killed diffs.
551 ;; A diff is saved here if it is replaced by a diff
552 ;; from another buffer. This alist has the form:
553 ;; \((num (buff-object . diff) (buff-object . diff) (buff-object . diff)) ...),
554 ;; where some buffer-objects may be missing.
555 (ediff-defvar-local ediff-killed-diffs-alist nil "")
557 ;; Syntax table to use in ediff-forward-word-function
558 ;; This is chosen by a heuristic. The important thing is for all buffers to
559 ;; have the same syntax table. Which is not too important.
560 (ediff-defvar-local ediff-syntax-table nil "")
563 ;; Highlighting
564 (defcustom ediff-before-flag-bol (if (featurep 'xemacs) (make-glyph "->>") "->>")
565 "*Flag placed before a highlighted block of differences, if block starts at beginning of a line."
566 :type 'string
567 :tag "Region before-flag at beginning of line"
568 :group 'ediff)
570 (defcustom ediff-after-flag-eol (if (featurep 'xemacs) (make-glyph "<<-") "<<-")
571 "*Flag placed after a highlighted block of differences, if block ends at end of a line."
572 :type 'string
573 :tag "Region after-flag at end of line"
574 :group 'ediff)
576 (defcustom ediff-before-flag-mol (if (featurep 'xemacs) (make-glyph "->>") "->>")
577 "*Flag placed before a highlighted block of differences, if block starts in mid-line."
578 :type 'string
579 :tag "Region before-flag in the middle of line"
580 :group 'ediff)
581 (defcustom ediff-after-flag-mol (if (featurep 'xemacs) (make-glyph "<<-") "<<-")
582 "*Flag placed after a highlighted block of differences, if block ends in mid-line."
583 :type 'string
584 :tag "Region after-flag in the middle of line"
585 :group 'ediff)
588 (ediff-defvar-local ediff-use-faces t "")
589 (defcustom ediff-use-faces t
590 "If t, differences are highlighted using faces, if device supports faces.
591 If nil, differences are highlighted using ASCII flags, ediff-before-flag
592 and ediff-after-flag. On a non-window system, differences are always
593 highlighted using ASCII flags."
594 :type 'boolean
595 :group 'ediff-highlighting)
597 ;; this indicates that diff regions are word-size, so fine diffs are
598 ;; permanently nixed; used in ediff-windows-wordwise and ediff-regions-wordwise
599 (ediff-defvar-local ediff-word-mode nil "")
600 ;; Name of the job (ediff-files, ediff-windows, etc.)
601 (ediff-defvar-local ediff-job-name nil "")
603 ;; Narrowing and ediff-region/windows support
604 ;; This is a list (overlay-A overlay-B overlay-C)
605 ;; If set, Ediff compares only those parts of buffers A/B/C that lie within
606 ;; the bounds of these overlays.
607 (ediff-defvar-local ediff-narrow-bounds nil "")
609 ;; List (overlay-A overlay-B overlay-C), where each overlay spans the
610 ;; entire corresponding buffer.
611 (ediff-defvar-local ediff-wide-bounds nil "")
613 ;; Current visibility boundaries in buffers A, B, and C.
614 ;; This is also a list of overlays. When the user toggles narrow/widen,
615 ;; this list changes from ediff-wide-bounds to ediff-narrow-bounds.
616 ;; and back.
617 (ediff-defvar-local ediff-visible-bounds nil "")
619 (ediff-defvar-local ediff-start-narrowed t
620 "Non-nil means start narrowed, if doing ediff-windows-* or ediff-regions-*")
621 (ediff-defvar-local ediff-quit-widened t
622 "*Non-nil means: when finished, Ediff widens buffers A/B.
623 Actually, Ediff restores the scope of visibility that existed at startup.")
625 (defcustom ediff-keep-variants t
626 "*nil means prompt to remove unmodified buffers A/B/C at session end.
627 Supplying a prefix argument to the quit command `q' temporarily reverses the
628 meaning of this variable."
629 :type 'boolean
630 :group 'ediff)
632 (ediff-defvar-local ediff-highlight-all-diffs t "")
633 (defcustom ediff-highlight-all-diffs t
634 "If nil, only the selected differences are highlighted.
635 Otherwise, all difference regions are highlighted, but the selected region is
636 shown in brighter colors."
637 :type 'boolean
638 :group 'ediff-highlighting)
641 ;; The suffix of the control buffer name.
642 (ediff-defvar-local ediff-control-buffer-suffix nil "")
643 ;; Same as ediff-control-buffer-suffix, but without <,>.
644 ;; It's a number rather than string.
645 (ediff-defvar-local ediff-control-buffer-number nil "")
648 ;; The original values of ediff-protected-variables for buffer A
649 (ediff-defvar-local ediff-buffer-values-orig-A nil "")
650 ;; The original values of ediff-protected-variables for buffer B
651 (ediff-defvar-local ediff-buffer-values-orig-B nil "")
652 ;; The original values of ediff-protected-variables for buffer C
653 (ediff-defvar-local ediff-buffer-values-orig-C nil "")
654 ;; The original values of ediff-protected-variables for buffer Ancestor
655 (ediff-defvar-local ediff-buffer-values-orig-Ancestor nil "")
657 ;; association between buff-type and ediff-buffer-values-orig-*
658 (defconst ediff-buffer-values-orig-alist
659 '((A . ediff-buffer-values-orig-A)
660 (B . ediff-buffer-values-orig-B)
661 (C . ediff-buffer-values-orig-C)
662 (Ancestor . ediff-buffer-values-orig-Ancestor)))
664 ;; Buffer-local variables to be saved then restored during Ediff sessions
665 (defconst ediff-protected-variables '(
666 ;;buffer-read-only
667 mode-line-format))
669 ;; Vector of differences between the variants. Each difference is
670 ;; represented by a vector of two overlays plus a vector of fine diffs,
671 ;; plus a no-fine-diffs flag. The first overlay spans the
672 ;; difference region in the A buffer and the second overlays the diff in
673 ;; the B buffer. If a difference section is empty, the corresponding
674 ;; overlay's endpoints coincide.
676 ;; The precise form of a Difference Vector for one buffer is:
677 ;; [diff diff diff ...]
678 ;; where each diff has the form:
679 ;; [diff-overlay fine-diff-vector no-fine-diffs-flag state-of-diff]
680 ;; fine-diff-vector is a vector [fine-diff-overlay fine-diff-overlay ...]
681 ;; no-fine-diffs-flag says if there are fine differences.
682 ;; state-of-difference is A, B, C, or nil, indicating which buffer is
683 ;; different from the other two (used only in 3-way jobs.
684 (ediff-defvar-local ediff-difference-vector-A nil "")
685 (ediff-defvar-local ediff-difference-vector-B nil "")
686 (ediff-defvar-local ediff-difference-vector-C nil "")
687 (ediff-defvar-local ediff-difference-vector-Ancestor nil "")
688 ;; A-list of diff vector types associated with buffer types
689 (defconst ediff-difference-vector-alist
690 '((A . ediff-difference-vector-A)
691 (B . ediff-difference-vector-B)
692 (C . ediff-difference-vector-C)
693 (Ancestor . ediff-difference-vector-Ancestor)))
695 ;; [ status status status ...]
696 ;; Each status: [state-of-merge state-of-ancestor]
697 ;; state-of-merge is default-A, default-B, prefer-A, or prefer-B. It
698 ;; indicates the way a diff region was created in buffer C.
699 ;; state-of-ancestor says if the corresponding region in ancestor buffer is
700 ;; empty.
701 (ediff-defvar-local ediff-state-of-merge nil "")
703 ;; The difference that is currently selected.
704 (ediff-defvar-local ediff-current-difference -1 "")
705 ;; Number of differences found.
706 (ediff-defvar-local ediff-number-of-differences nil "")
708 ;; Buffer containing the output of diff, which is used by Ediff to step
709 ;; through files.
710 (ediff-defvar-local ediff-diff-buffer nil "")
711 ;; Like ediff-diff-buffer, but contains context diff. It is not used by
712 ;; Ediff, but it is saved in a file, if user requests so.
713 (ediff-defvar-local ediff-custom-diff-buffer nil "")
714 ;; Buffer used for diff-style fine differences between regions.
715 (ediff-defvar-local ediff-fine-diff-buffer nil "")
716 ;; Temporary buffer used for computing fine differences.
717 (defconst ediff-tmp-buffer " *ediff-tmp*" "")
718 ;; Buffer used for messages
719 (defconst ediff-msg-buffer " *ediff-message*" "")
720 ;; Buffer containing the output of diff when diff returns errors.
721 (ediff-defvar-local ediff-error-buffer nil "")
722 ;; Buffer to display debug info
723 (ediff-defvar-local ediff-debug-buffer "*ediff-debug*" "")
725 ;; List of ediff control panels associated with each buffer A/B/C/Ancestor.
726 ;; Not used any more, but may be needed in the future.
727 (ediff-defvar-local ediff-this-buffer-ediff-sessions nil "")
729 ;; to be deleted in due time
730 ;; List of difference overlays disturbed by working with the current diff.
731 (defvar ediff-disturbed-overlays nil "")
733 ;; Priority of non-selected overlays.
734 (defvar ediff-shadow-overlay-priority 100 "")
736 (defcustom ediff-version-control-package 'vc
737 "Version control package used.
738 Currently, Ediff supports vc.el, rcs.el, pcl-cvs.el, and generic-sc.el. The
739 standard Emacs interface to RCS, CVS, SCCS, etc., is vc.el. However, some
740 people find the other two packages more convenient. Set this variable to the
741 appropriate symbol: `rcs', `pcl-cvs', or `generic-sc' if you so desire."
742 :type 'symbol
743 :group 'ediff)
745 (defcustom ediff-coding-system-for-read 'raw-text
746 "*The coding system for read to use when running the diff program as a subprocess.
747 In most cases, the default will do. However, under certain circumstances in
748 Windows NT/98/95 you might need to use something like 'raw-text-dos here.
749 So, if the output that your diff program sends to Emacs contains extra ^M's,
750 you might need to experiment here, if the default or 'raw-text-dos doesn't
751 work."
752 :type 'symbol
753 :group 'ediff)
755 (defcustom ediff-coding-system-for-write 'no-conversion
756 "*The coding system for write to use when writing out difference regions
757 to temp files when Ediff needs to find fine differences."
758 :type 'symbol
759 :group 'ediff)
762 (ediff-cond-compile-for-xemacs-or-emacs
763 (progn ; xemacs
764 (defalias 'ediff-read-event 'next-command-event)
765 (defalias 'ediff-overlayp 'extentp)
766 (defalias 'ediff-make-overlay 'make-extent)
767 (defalias 'ediff-delete-overlay 'delete-extent))
768 (progn ; emacs
769 (defalias 'ediff-read-event 'read-event)
770 (defalias 'ediff-overlayp 'overlayp)
771 (defalias 'ediff-make-overlay 'make-overlay)
772 (defalias 'ediff-delete-overlay 'delete-overlay))
775 ;; Check the current version against the major and minor version numbers
776 ;; using op: cur-vers op major.minor If emacs-major-version or
777 ;; emacs-minor-version are not defined, we assume that the current version
778 ;; is hopelessly outdated. We assume that emacs-major-version and
779 ;; emacs-minor-version are defined. Otherwise, for Emacs/XEmacs 19, if the
780 ;; current minor version is < 10 (xemacs) or < 23 (emacs) the return value
781 ;; will be nil (when op is =, >, or >=) and t (when op is <, <=), which may be
782 ;; incorrect. However, this gives correct result in our cases, since we are
783 ;; testing for sufficiently high Emacs versions.
784 (defun ediff-check-version (op major minor &optional type-of-emacs)
785 (if (and (boundp 'emacs-major-version) (boundp 'emacs-minor-version))
786 (and (cond ((eq type-of-emacs 'xemacs) ediff-xemacs-p)
787 ((eq type-of-emacs 'emacs) ediff-emacs-p)
788 (t t))
789 (cond ((eq op '=) (and (= emacs-minor-version minor)
790 (= emacs-major-version major)))
791 ((memq op '(> >= < <=))
792 (and (or (funcall op emacs-major-version major)
793 (= emacs-major-version major))
794 (if (= emacs-major-version major)
795 (funcall op emacs-minor-version minor)
796 t)))
798 (error "%S: Invalid op in ediff-check-version" op))))
799 (cond ((memq op '(= > >=)) nil)
800 ((memq op '(< <=)) t))))
803 (defun ediff-color-display-p ()
804 (condition-case nil
805 (ediff-cond-compile-for-xemacs-or-emacs
806 (eq (device-class (selected-device)) 'color) ; xemacs form
807 (if (fboundp 'display-color-p) ; emacs form
808 (display-color-p)
809 (x-display-color-p))
811 (error nil)))
814 ;; A var local to each control panel buffer. Indicates highlighting style
815 ;; in effect for this buffer: `face', `ascii',
816 ;; `off' -- turned off \(on a dumb terminal only\).
817 (ediff-defvar-local ediff-highlighting-style
818 (if (and (ediff-has-face-support-p) ediff-use-faces) 'face 'ascii)
822 (if (ediff-has-face-support-p)
823 (ediff-cond-compile-for-xemacs-or-emacs
824 (progn ; xemacs
825 (defalias 'ediff-valid-color-p 'valid-color-name-p)
826 (defalias 'ediff-get-face 'get-face))
827 (progn ; emacs
828 (defalias 'ediff-valid-color-p (if (fboundp 'color-defined-p)
829 'color-defined-p
830 'x-color-defined-p))
831 (defalias 'ediff-get-face 'internal-get-face))
834 (if (ediff-window-display-p)
835 (ediff-cond-compile-for-xemacs-or-emacs
836 (progn ; xemacs
837 (defalias 'ediff-display-pixel-width 'device-pixel-width)
838 (defalias 'ediff-display-pixel-height 'device-pixel-height))
839 (progn ; emacs
840 (defalias 'ediff-display-pixel-width
841 (if (fboundp 'display-pixel-width)
842 'display-pixel-width
843 'x-display-pixel-width))
844 (defalias 'ediff-display-pixel-height
845 (if (fboundp 'display-pixel-height)
846 'display-pixel-height
847 'x-display-pixel-height)))
850 ;; A-list of current-diff-overlay symbols associated with buf types
851 (defconst ediff-current-diff-overlay-alist
852 '((A . ediff-current-diff-overlay-A)
853 (B . ediff-current-diff-overlay-B)
854 (C . ediff-current-diff-overlay-C)
855 (Ancestor . ediff-current-diff-overlay-Ancestor)))
857 ;; A-list of current-diff-face-* symbols associated with buf types
858 (defconst ediff-current-diff-face-alist
859 '((A . ediff-current-diff-A)
860 (B . ediff-current-diff-B)
861 (C . ediff-current-diff-C)
862 (Ancestor . ediff-current-diff-Ancestor)))
865 (defun ediff-set-overlay-face (extent face)
866 (ediff-overlay-put extent 'face face)
867 (ediff-overlay-put extent 'help-echo 'ediff-region-help-echo))
869 (defun ediff-region-help-echo (extent-or-window &optional overlay point)
870 (unless overlay
871 (setq overlay extent-or-window))
872 (let ((is-current (ediff-overlay-get overlay 'ediff))
873 (face (ediff-overlay-get overlay 'face))
874 (diff-num (ediff-overlay-get overlay 'ediff-diff-num))
875 face-help)
877 ;; This happens only for refinement overlays
878 (if (stringp face)
879 (setq face (intern face)))
880 (setq face-help (and face (get face 'ediff-help-echo)))
882 (cond ((and is-current diff-num) ; current diff region
883 (format "Difference region %S -- current" (1+ diff-num)))
884 (face-help) ; refinement of current diff region
885 (diff-num ; non-current
886 (format "Difference region %S -- non-current" (1+ diff-num)))
887 (t "")) ; none
891 (defun ediff-set-face-pixmap (face pixmap)
892 "Set face pixmap on a monochrome display."
893 (if (and (ediff-window-display-p) (not (ediff-color-display-p)))
894 (condition-case nil
895 (set-face-background-pixmap face pixmap)
896 (error
897 (message "Pixmap not found for %S: %s" (face-name face) pixmap)
898 (sit-for 1)))))
900 (defun ediff-hide-face (face)
901 (if (and (ediff-has-face-support-p)
902 (boundp 'add-to-list)
903 (boundp 'facemenu-unlisted-faces))
904 (add-to-list 'facemenu-unlisted-faces face)))
908 (defface ediff-current-diff-A
909 (if ediff-emacs-p
910 '((((class color) (min-colors 16))
911 (:foreground "firebrick" :background "pale green"))
912 (((class color))
913 (:foreground "blue3" :background "yellow3"))
914 (t (:inverse-video t)))
915 '((((type tty)) (:foreground "blue3" :background "yellow3"))
916 (((class color)) (:foreground "firebrick" :background "pale green"))
917 (t (:inverse-video t))))
918 "Face for highlighting the selected difference in buffer A."
919 :group 'ediff-highlighting)
920 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
921 ;; this variable is set to nil, then again to the appropriate face.
922 (defvar ediff-current-diff-face-A 'ediff-current-diff-A
923 "Face for highlighting the selected difference in buffer A.
924 DO NOT CHANGE this variable. Instead, use the customization
925 widget to customize the actual face object `ediff-current-diff-A'
926 this variable represents.")
927 (ediff-hide-face ediff-current-diff-face-A)
928 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
929 ;; This means that some user customization may be trashed.
930 (if (and ediff-xemacs-p
931 (ediff-has-face-support-p)
932 (not (ediff-color-display-p)))
933 (copy-face 'modeline ediff-current-diff-face-A))
937 (defface ediff-current-diff-B
938 (if ediff-emacs-p
939 '((((class color) (min-colors 16))
940 (:foreground "DarkOrchid" :background "Yellow"))
941 (((class color))
942 (:foreground "magenta3" :background "yellow3"
943 :weight bold))
944 (t (:inverse-video t)))
945 '((((type tty)) (:foreground "magenta3" :background "yellow3"
946 :weight bold))
947 (((class color)) (:foreground "DarkOrchid" :background "Yellow"))
948 (t (:inverse-video t))))
949 "Face for highlighting the selected difference in buffer B."
950 :group 'ediff-highlighting)
951 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
952 ;; this variable is set to nil, then again to the appropriate face.
953 (defvar ediff-current-diff-face-B 'ediff-current-diff-B
954 "Face for highlighting the selected difference in buffer B.
955 this variable. Instead, use the customization
956 widget to customize the actual face `ediff-current-diff-B'
957 this variable represents.")
958 (ediff-hide-face ediff-current-diff-face-B)
959 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
960 ;; This means that some user customization may be trashed.
961 (if (and ediff-xemacs-p
962 (ediff-has-face-support-p)
963 (not (ediff-color-display-p)))
964 (copy-face 'modeline ediff-current-diff-face-B))
967 (defface ediff-current-diff-C
968 (if ediff-emacs-p
969 '((((class color) (min-colors 16))
970 (:foreground "Navy" :background "Pink"))
971 (((class color))
972 (:foreground "cyan3" :background "yellow3" :weight bold))
973 (t (:inverse-video t)))
974 '((((type tty)) (:foreground "cyan3" :background "yellow3" :weight bold))
975 (((class color)) (:foreground "Navy" :background "Pink"))
976 (t (:inverse-video t))))
977 "Face for highlighting the selected difference in buffer C."
978 :group 'ediff-highlighting)
979 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
980 ;; this variable is set to nil, then again to the appropriate face.
981 (defvar ediff-current-diff-face-C 'ediff-current-diff-C
982 "Face for highlighting the selected difference in buffer C.
983 DO NOT CHANGE this variable. Instead, use the customization
984 widget to customize the actual face object `ediff-current-diff-C'
985 this variable represents.")
986 (ediff-hide-face ediff-current-diff-face-C)
987 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
988 ;; This means that some user customization may be trashed.
989 (if (and ediff-xemacs-p
990 (ediff-has-face-support-p)
991 (not (ediff-color-display-p)))
992 (copy-face 'modeline ediff-current-diff-face-C))
995 (defface ediff-current-diff-Ancestor
996 (if ediff-emacs-p
997 '((((class color) (min-colors 16))
998 (:foreground "Black" :background "VioletRed"))
999 (((class color))
1000 (:foreground "black" :background "magenta3"))
1001 (t (:inverse-video t)))
1002 '((((type tty)) (:foreground "black" :background "magenta3"))
1003 (((class color)) (:foreground "Black" :background "VioletRed"))
1004 (t (:inverse-video t))))
1005 "Face for highlighting the selected difference in buffer Ancestor."
1006 :group 'ediff-highlighting)
1007 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1008 ;; this variable is set to nil, then again to the appropriate face.
1009 (defvar ediff-current-diff-face-Ancestor 'ediff-current-diff-Ancestor
1010 "Face for highlighting the selected difference in buffer Ancestor.
1011 DO NOT CHANGE this variable. Instead, use the customization
1012 widget to customize the actual face object `ediff-current-diff-Ancestor'
1013 this variable represents.")
1014 (ediff-hide-face ediff-current-diff-face-Ancestor)
1015 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
1016 ;; This means that some user customization may be trashed.
1017 (if (and ediff-xemacs-p
1018 (ediff-has-face-support-p)
1019 (not (ediff-color-display-p)))
1020 (copy-face 'modeline ediff-current-diff-face-Ancestor))
1023 (defface ediff-fine-diff-A
1024 (if ediff-emacs-p
1025 '((((class color) (min-colors 16))
1026 (:foreground "Navy" :background "sky blue"))
1027 (((class color))
1028 (:foreground "white" :background "sky blue" :weight bold))
1029 (t (:underline t :stipple "gray3")))
1030 '((((type tty)) (:foreground "white" :background "sky blue" :weight bold))
1031 (((class color)) (:foreground "Navy" :background "sky blue"))
1032 (t (:underline t :stipple "gray3"))))
1033 "Face for highlighting the refinement of the selected diff in buffer A."
1034 :group 'ediff-highlighting)
1035 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1036 ;; this variable is set to nil, then again to the appropriate face.
1037 (defvar ediff-fine-diff-face-A 'ediff-fine-diff-A
1038 "Face for highlighting the fine differences in buffer A.
1039 DO NOT CHANGE this variable. Instead, use the customization
1040 widget to customize the actual face object `ediff-fine-diff-A'
1041 this variable represents.")
1042 (ediff-hide-face ediff-fine-diff-face-A)
1044 (defface ediff-fine-diff-B
1045 (if ediff-emacs-p
1046 '((((class color) (min-colors 16))
1047 (:foreground "Black" :background "cyan"))
1048 (((class color))
1049 (:foreground "magenta3" :background "cyan3"))
1050 (t (:underline t :stipple "gray3")))
1051 '((((type tty)) (:foreground "magenta3" :background "cyan3"))
1052 (((class color)) (:foreground "Black" :background "cyan"))
1053 (t (:underline t :stipple "gray3"))))
1054 "Face for highlighting the refinement of the selected diff in buffer B."
1055 :group 'ediff-highlighting)
1056 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1057 ;; this variable is set to nil, then again to the appropriate face.
1058 (defvar ediff-fine-diff-face-B 'ediff-fine-diff-B
1059 "Face for highlighting the fine differences in buffer B.
1060 DO NOT CHANGE this variable. Instead, use the customization
1061 widget to customize the actual face object `ediff-fine-diff-B'
1062 this variable represents.")
1063 (ediff-hide-face ediff-fine-diff-face-B)
1065 (defface ediff-fine-diff-C
1066 (if ediff-emacs-p
1067 '((((type pc))
1068 (:foreground "white" :background "Turquoise"))
1069 (((class color) (min-colors 16))
1070 (:foreground "Black" :background "Turquoise"))
1071 (((class color))
1072 (:foreground "yellow3" :background "Turquoise"
1073 :weight bold))
1074 (t (:underline t :stipple "gray3")))
1075 '((((type tty)) (:foreground "yellow3" :background "Turquoise"
1076 :weight bold))
1077 (((type pc)) (:foreground "white" :background "Turquoise"))
1078 (((class color)) (:foreground "Black" :background "Turquoise"))
1079 (t (:underline t :stipple "gray3"))))
1080 "Face for highlighting the refinement of the selected diff in buffer C."
1081 :group 'ediff-highlighting)
1082 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1083 ;; this variable is set to nil, then again to the appropriate face.
1084 (defvar ediff-fine-diff-face-C 'ediff-fine-diff-C
1085 "Face for highlighting the fine differences in buffer C.
1086 DO NOT CHANGE this variable. Instead, use the customization
1087 widget to customize the actual face object `ediff-fine-diff-C'
1088 this variable represents.")
1089 (ediff-hide-face ediff-fine-diff-face-C)
1091 (defface ediff-fine-diff-Ancestor
1092 (if ediff-emacs-p
1093 '((((class color) (min-colors 16))
1094 (:foreground "Black" :background "Green"))
1095 (((class color))
1096 (:foreground "red3" :background "green"))
1097 (t (:underline t :stipple "gray3")))
1098 '((((type tty)) (:foreground "red3" :background "green"))
1099 (((class color)) (:foreground "Black" :background "Green"))
1100 (t (:underline t :stipple "gray3"))))
1101 "Face for highlighting the refinement of the selected diff in the ancestor buffer.
1102 At present, this face is not used and no fine differences are computed for the
1103 ancestor buffer."
1104 :group 'ediff-highlighting)
1105 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1106 ;; this variable is set to nil, then again to the appropriate face.
1107 (defvar ediff-fine-diff-face-Ancestor 'ediff-fine-diff-Ancestor
1108 "Face for highlighting the fine differences in buffer Ancestor.
1109 DO NOT CHANGE this variable. Instead, use the customization
1110 widget to customize the actual face object `ediff-fine-diff-Ancestor'
1111 this variable represents.")
1112 (ediff-hide-face ediff-fine-diff-face-Ancestor)
1114 ;; Some installs don't have stipple or Stipple. So, try them in turn.
1115 (defvar stipple-pixmap
1116 (cond ((not (ediff-has-face-support-p)) nil)
1117 ((and (boundp 'x-bitmap-file-path)
1118 (locate-library "stipple" t x-bitmap-file-path)) "stipple")
1119 ((and (boundp 'mswindowsx-bitmap-file-path)
1120 (locate-library "stipple" t mswindowsx-bitmap-file-path)) "stipple")
1121 (t "Stipple")))
1123 (defface ediff-even-diff-A
1124 (if ediff-emacs-p
1125 `((((type pc))
1126 (:foreground "green3" :background "light grey"))
1127 (((class color) (min-colors 16))
1128 (:foreground "Black" :background "light grey"))
1129 (((class color))
1130 (:foreground "red3" :background "light grey"
1131 :weight bold))
1132 (t (:italic t :stipple ,stipple-pixmap)))
1133 `((((type tty)) (:foreground "red3" :background "light grey"
1134 :weight bold))
1135 (((type pc)) (:foreground "green3" :background "light grey"))
1136 (((class color)) (:foreground "Black" :background "light grey"))
1137 (t (:italic t :stipple ,stipple-pixmap))))
1138 "Face for highlighting even-numbered non-current differences in buffer A."
1139 :group 'ediff-highlighting)
1140 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1141 ;; this variable is set to nil, then again to the appropriate face.
1142 (defvar ediff-even-diff-face-A 'ediff-even-diff-A
1143 "Face for highlighting even-numbered non-current differences in buffer A.
1144 DO NOT CHANGE this variable. Instead, use the customization
1145 widget to customize the actual face object `ediff-even-diff-A'
1146 this variable represents.")
1147 (ediff-hide-face ediff-even-diff-face-A)
1149 (defface ediff-even-diff-B
1150 (if ediff-emacs-p
1151 `((((class color) (min-colors 16))
1152 (:foreground "White" :background "Grey"))
1153 (((class color))
1154 (:foreground "blue3" :background "Grey" :weight bold))
1155 (t (:italic t :stipple ,stipple-pixmap)))
1156 `((((type tty)) (:foreground "blue3" :background "Grey" :weight bold))
1157 (((class color)) (:foreground "White" :background "Grey"))
1158 (t (:italic t :stipple ,stipple-pixmap))))
1159 "Face for highlighting even-numbered non-current differences in buffer B."
1160 :group 'ediff-highlighting)
1161 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1162 ;; this variable is set to nil, then again to the appropriate face.
1163 (defvar ediff-even-diff-face-B 'ediff-even-diff-B
1164 "Face for highlighting even-numbered non-current differences in buffer B.
1165 DO NOT CHANGE this variable. Instead, use the customization
1166 widget to customize the actual face object `ediff-even-diff-B'
1167 this variable represents.")
1168 (ediff-hide-face ediff-even-diff-face-B)
1170 (defface ediff-even-diff-C
1171 (if ediff-emacs-p
1172 `((((type pc))
1173 (:foreground "yellow3" :background "light grey"))
1174 (((class color) (min-colors 16))
1175 (:foreground "Black" :background "light grey"))
1176 (((class color))
1177 (:foreground "yellow3" :background "light grey"
1178 :weight bold))
1179 (t (:italic t :stipple ,stipple-pixmap)))
1180 `((((type tty)) (:foreground "yellow3" :background "light grey"
1181 :weight bold))
1182 (((type pc)) (:foreground "yellow3" :background "light grey"))
1183 (((class color)) (:foreground "Black" :background "light grey"))
1184 (t (:italic t :stipple ,stipple-pixmap))))
1185 "Face for highlighting even-numbered non-current differences in buffer C."
1186 :group 'ediff-highlighting)
1187 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1188 ;; this variable is set to nil, then again to the appropriate face.
1189 (defvar ediff-even-diff-face-C 'ediff-even-diff-C
1190 "Face for highlighting even-numbered non-current differences in buffer C.
1191 DO NOT CHANGE this variable. Instead, use the customization
1192 widget to customize the actual face object `ediff-even-diff-C'
1193 this variable represents.")
1194 (ediff-hide-face ediff-even-diff-face-C)
1196 (defface ediff-even-diff-Ancestor
1197 (if ediff-emacs-p
1198 `((((type pc))
1199 (:foreground "cyan3" :background "light grey"))
1200 (((class color) (min-colors 16))
1201 (:foreground "White" :background "Grey"))
1202 (((class color))
1203 (:foreground "cyan3" :background "light grey"
1204 :weight bold))
1205 (t (:italic t :stipple ,stipple-pixmap)))
1206 `((((type tty)) (:foreground "cyan3" :background "light grey"
1207 :weight bold))
1208 (((type pc)) (:foreground "cyan3" :background "light grey"))
1209 (((class color)) (:foreground "White" :background "Grey"))
1210 (t (:italic t :stipple ,stipple-pixmap))))
1211 "Face for highlighting even-numbered non-current differences in the ancestor buffer."
1212 :group 'ediff-highlighting)
1213 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1214 ;; this variable is set to nil, then again to the appropriate face.
1215 (defvar ediff-even-diff-face-Ancestor 'ediff-even-diff-Ancestor
1216 "Face for highlighting even-numbered non-current differences in buffer Ancestor.
1217 DO NOT CHANGE this variable. Instead, use the customization
1218 widget to customize the actual face object `ediff-even-diff-Ancestor'
1219 this variable represents.")
1220 (ediff-hide-face ediff-even-diff-face-Ancestor)
1222 ;; Association between buffer types and even-diff-face symbols
1223 (defconst ediff-even-diff-face-alist
1224 '((A . ediff-even-diff-A)
1225 (B . ediff-even-diff-B)
1226 (C . ediff-even-diff-C)
1227 (Ancestor . ediff-even-diff-Ancestor)))
1229 (defface ediff-odd-diff-A
1230 (if ediff-emacs-p
1231 '((((type pc))
1232 (:foreground "green3" :background "gray40"))
1233 (((class color) (min-colors 16))
1234 (:foreground "White" :background "Grey"))
1235 (((class color))
1236 (:foreground "red3" :background "black" :weight bold))
1237 (t (:italic t :stipple "gray1")))
1238 '((((type tty)) (:foreground "red3" :background "black" :weight bold))
1239 (((type pc)) (:foreground "green3" :background "gray40"))
1240 (((class color)) (:foreground "White" :background "Grey"))
1241 (t (:italic t :stipple "gray1"))))
1242 "Face for highlighting odd-numbered non-current differences in buffer A."
1243 :group 'ediff-highlighting)
1244 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1245 ;; this variable is set to nil, then again to the appropriate face.
1246 (defvar ediff-odd-diff-face-A 'ediff-odd-diff-A
1247 "Face for highlighting odd-numbered non-current differences in buffer A.
1248 DO NOT CHANGE this variable. Instead, use the customization
1249 widget to customize the actual face object `ediff-odd-diff-A'
1250 this variable represents.")
1251 (ediff-hide-face ediff-odd-diff-face-A)
1254 (defface ediff-odd-diff-B
1255 (if ediff-emacs-p
1256 '((((type pc))
1257 (:foreground "White" :background "gray40"))
1258 (((class color) (min-colors 16))
1259 (:foreground "Black" :background "light grey"))
1260 (((class color))
1261 (:foreground "cyan3" :background "black" :weight bold))
1262 (t (:italic t :stipple "gray1")))
1263 '((((type tty)) (:foreground "cyan3" :background "black" :weight bold))
1264 (((type pc)) (:foreground "White" :background "gray40"))
1265 (((class color)) (:foreground "Black" :background "light grey"))
1266 (t (:italic t :stipple "gray1"))))
1267 "Face for highlighting odd-numbered non-current differences in buffer B."
1268 :group 'ediff-highlighting)
1269 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1270 ;; this variable is set to nil, then again to the appropriate face.
1271 (defvar ediff-odd-diff-face-B 'ediff-odd-diff-B
1272 "Face for highlighting odd-numbered non-current differences in buffer B.
1273 DO NOT CHANGE this variable. Instead, use the customization
1274 widget to customize the actual face object `ediff-odd-diff-B'
1275 this variable represents.")
1276 (ediff-hide-face ediff-odd-diff-face-B)
1278 (defface ediff-odd-diff-C
1279 (if ediff-emacs-p
1280 '((((type pc))
1281 (:foreground "yellow3" :background "gray40"))
1282 (((class color) (min-colors 16))
1283 (:foreground "White" :background "Grey"))
1284 (((class color))
1285 (:foreground "yellow3" :background "black" :weight bold))
1286 (t (:italic t :stipple "gray1")))
1287 '((((type tty)) (:foreground "yellow3" :background "black" :weight bold))
1288 (((type pc)) (:foreground "yellow3" :background "gray40"))
1289 (((class color)) (:foreground "White" :background "Grey"))
1290 (t (:italic t :stipple "gray1"))))
1291 "Face for highlighting odd-numbered non-current differences in buffer C."
1292 :group 'ediff-highlighting)
1293 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1294 ;; this variable is set to nil, then again to the appropriate face.
1295 (defvar ediff-odd-diff-face-C 'ediff-odd-diff-C
1296 "Face for highlighting odd-numbered non-current differences in buffer C.
1297 DO NOT CHANGE this variable. Instead, use the customization
1298 widget to customize the actual face object `ediff-odd-diff-C'
1299 this variable represents.")
1300 (ediff-hide-face ediff-odd-diff-face-C)
1302 (defface ediff-odd-diff-Ancestor
1303 (if ediff-emacs-p
1304 '((((class color) (min-colors 16))
1305 (:foreground "cyan3" :background "gray40"))
1306 (((class color))
1307 (:foreground "green3" :background "black" :weight bold))
1308 (t (:italic t :stipple "gray1")))
1309 '((((type tty)) (:foreground "green3" :background "black" :weight bold))
1310 (((class color)) (:foreground "cyan3" :background "gray40"))
1311 (t (:italic t :stipple "gray1"))))
1312 "Face for highlighting odd-numbered non-current differences in the ancestor buffer."
1313 :group 'ediff-highlighting)
1314 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1315 ;; this variable is set to nil, then again to the appropriate face.
1316 (defvar ediff-odd-diff-face-Ancestor 'ediff-odd-diff-Ancestor
1317 "Face for highlighting odd-numbered non-current differences in buffer Ancestor.
1318 DO NOT CHANGE this variable. Instead, use the customization
1319 widget to customize the actual face object `ediff-odd-diff-Ancestor'
1320 this variable represents.")
1321 (ediff-hide-face ediff-odd-diff-face-Ancestor)
1323 ;; Association between buffer types and odd-diff-face symbols
1324 (defconst ediff-odd-diff-face-alist
1325 '((A . ediff-odd-diff-A)
1326 (B . ediff-odd-diff-B)
1327 (C . ediff-odd-diff-C)
1328 (Ancestor . ediff-odd-diff-Ancestor)))
1330 ;; A-list of fine-diff face symbols associated with buffer types
1331 (defconst ediff-fine-diff-face-alist
1332 '((A . ediff-fine-diff-A)
1333 (B . ediff-fine-diff-B)
1334 (C . ediff-fine-diff-C)
1335 (Ancestor . ediff-fine-diff-Ancestor)))
1337 ;; Help echo
1338 (put ediff-fine-diff-face-A 'ediff-help-echo
1339 "A `refinement' of the current difference region")
1340 (put ediff-fine-diff-face-B 'ediff-help-echo
1341 "A `refinement' of the current difference region")
1342 (put ediff-fine-diff-face-C 'ediff-help-echo
1343 "A `refinement' of the current difference region")
1344 (put ediff-fine-diff-face-Ancestor 'ediff-help-echo
1345 "A `refinement' of the current difference region")
1347 (add-hook 'ediff-quit-hook 'ediff-cleanup-mess)
1348 (add-hook 'ediff-suspend-hook 'ediff-default-suspend-function)
1351 ;;; Overlays
1353 (ediff-defvar-local ediff-current-diff-overlay-A nil
1354 "Overlay for the current difference region in buffer A.")
1355 (ediff-defvar-local ediff-current-diff-overlay-B nil
1356 "Overlay for the current difference region in buffer B.")
1357 (ediff-defvar-local ediff-current-diff-overlay-C nil
1358 "Overlay for the current difference region in buffer C.")
1359 (ediff-defvar-local ediff-current-diff-overlay-Ancestor nil
1360 "Overlay for the current difference region in the ancestor buffer.")
1362 ;; Compute priority of a current ediff overlay.
1363 (defun ediff-highest-priority (start end buffer)
1364 (let ((pos (max 1 (1- start)))
1365 ovr-list)
1366 (ediff-cond-compile-for-xemacs-or-emacs
1367 (1+ ediff-shadow-overlay-priority) ; xemacs form
1368 ;; emacs form
1369 (ediff-with-current-buffer buffer
1370 (while (< pos (min (point-max) (1+ end)))
1371 (setq ovr-list (append (overlays-at pos) ovr-list))
1372 (setq pos (next-overlay-change pos)))
1373 (+ 1 ediff-shadow-overlay-priority
1374 (apply 'max
1375 (cons
1377 (mapcar
1378 (lambda (ovr)
1379 (if (and ovr
1380 ;; exclude ediff overlays from priority
1381 ;; calculation, or else priority will keep
1382 ;; increasing
1383 (null (ediff-overlay-get ovr 'ediff))
1384 (null (ediff-overlay-get ovr 'ediff-diff-num)))
1385 ;; use the overlay priority or 0
1386 (or (ediff-overlay-get ovr 'priority) 0)
1388 ovr-list)
1391 ) ; ediff-cond-compile-for-xemacs-or-emacs
1395 (defvar ediff-toggle-read-only-function nil
1396 "*Specifies the function to be used to toggle read-only.
1397 If nil, Ediff tries to deduce the function from the binding of C-x C-q.
1398 Normally, this is the `toggle-read-only' function, but, if version
1399 control is used, it could be `vc-toggle-read-only' or `rcs-toggle-read-only'.")
1401 (defcustom ediff-make-buffers-readonly-at-startup nil
1402 "*Make all variant buffers read-only when Ediff starts up.
1403 This property can be toggled interactively."
1404 :type 'boolean
1405 :group 'ediff)
1408 ;;; Misc
1410 ;; if nil, this silences some messages
1411 (defconst ediff-verbose-p t)
1413 (defcustom ediff-autostore-merges 'group-jobs-only
1414 "*Save the results of merge jobs automatically.
1415 With value nil, don't save automatically. With value t, always
1416 save. Anything else means save automatically only if the merge
1417 job is part of a group of jobs, such as `ediff-merge-directory'
1418 or `ediff-merge-directory-revisions'."
1419 :type '(choice (const nil) (const t) (const group-jobs-only))
1420 :group 'ediff-merge)
1421 (make-variable-buffer-local 'ediff-autostore-merges)
1423 ;; file where the result of the merge is to be saved. used internally
1424 (ediff-defvar-local ediff-merge-store-file nil "")
1426 (defcustom ediff-merge-filename-prefix "merge_"
1427 "*Prefix to be attached to saved merge buffers."
1428 :type 'string
1429 :group 'ediff-merge)
1431 (defcustom ediff-no-emacs-help-in-control-buffer nil
1432 "*Non-nil means C-h should not invoke Emacs help in control buffer.
1433 Instead, C-h would jump to previous difference."
1434 :type 'boolean
1435 :group 'ediff)
1437 ;; This is the same as temporary-file-directory from Emacs 20.3.
1438 ;; Copied over here because XEmacs doesn't have this variable.
1439 (defcustom ediff-temp-file-prefix
1440 (file-name-as-directory
1441 (cond ((boundp 'temporary-file-directory) temporary-file-directory)
1442 ((fboundp 'temp-directory) (temp-directory))
1443 (t "/tmp/")))
1444 ;;; (file-name-as-directory
1445 ;;; (cond ((memq system-type '(ms-dos windows-nt))
1446 ;;; (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
1447 ;;; ((memq system-type '(vax-vms axp-vms))
1448 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
1449 ;;; (t
1450 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))
1451 "*Prefix to put on Ediff temporary file names.
1452 Do not start with `~/' or `~USERNAME/'."
1453 :type 'string
1454 :group 'ediff)
1456 (defcustom ediff-temp-file-mode 384 ; u=rw only
1457 "*Mode for Ediff temporary files."
1458 :type 'integer
1459 :group 'ediff)
1461 ;; Metacharacters that have to be protected from the shell when executing
1462 ;; a diff/diff3 command.
1463 (defcustom ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
1464 "Regexp that matches characters that must be quoted with `\\' in shell command line.
1465 This default should work without changes."
1466 :type 'string
1467 :group 'ediff)
1469 ;; needed to simulate frame-char-width in XEmacs.
1470 (defvar ediff-H-glyph (if (featurep 'xemacs) (make-glyph "H")))
1473 ;; Temporary file used for refining difference regions in buffer A.
1474 (ediff-defvar-local ediff-temp-file-A nil "")
1475 ;; Temporary file used for refining difference regions in buffer B.
1476 (ediff-defvar-local ediff-temp-file-B nil "")
1477 ;; Temporary file used for refining difference regions in buffer C.
1478 (ediff-defvar-local ediff-temp-file-C nil "")
1481 (defun ediff-file-remote-p (file-name)
1482 (file-remote-p file-name))
1484 ;; File for which we can get attributes, such as size or date
1485 (defun ediff-listable-file (file-name)
1486 (let ((handler (find-file-name-handler file-name 'file-local-copy)))
1487 (or (null handler) (eq handler 'dired-handler-fn))))
1490 (defsubst ediff-frame-unsplittable-p (frame)
1491 (cdr (assq 'unsplittable (frame-parameters frame))))
1493 (defsubst ediff-get-next-window (wind prev-wind)
1494 (cond ((window-live-p wind) wind)
1495 (prev-wind (next-window wind))
1496 (t (selected-window))
1500 (defsubst ediff-kill-buffer-carefully (buf)
1501 "Kill buffer BUF if it exists."
1502 (if (ediff-buffer-live-p buf)
1503 (kill-buffer (get-buffer buf))))
1505 (defsubst ediff-background-face (buf-type dif-num)
1506 ;; The value of dif-num is always 1- the one that user sees.
1507 ;; This is why even face is used when dif-num is odd.
1508 (ediff-get-symbol-from-alist
1509 buf-type (if (ediff-odd-p dif-num)
1510 ediff-even-diff-face-alist
1511 ediff-odd-diff-face-alist)
1515 ;; activate faces on diff regions in buffer
1516 (defun ediff-paint-background-regions-in-one-buffer (buf-type unhighlight)
1517 (let ((diff-vector
1518 (eval (ediff-get-symbol-from-alist
1519 buf-type ediff-difference-vector-alist)))
1520 overl diff-num)
1521 (mapcar (lambda (rec)
1522 (setq overl (ediff-get-diff-overlay-from-diff-record rec)
1523 diff-num (ediff-overlay-get overl 'ediff-diff-num))
1524 (if (ediff-overlay-buffer overl)
1525 ;; only if overlay is alive
1526 (ediff-set-overlay-face
1527 overl
1528 (if (not unhighlight)
1529 (ediff-background-face buf-type diff-num))))
1531 diff-vector)))
1534 ;; activate faces on diff regions in all buffers
1535 (defun ediff-paint-background-regions (&optional unhighlight)
1536 (ediff-paint-background-regions-in-one-buffer
1537 'A unhighlight)
1538 (ediff-paint-background-regions-in-one-buffer
1539 'B unhighlight)
1540 (ediff-paint-background-regions-in-one-buffer
1541 'C unhighlight)
1542 (ediff-paint-background-regions-in-one-buffer
1543 'Ancestor unhighlight))
1546 ;; arg is a record for a given diff in a difference vector
1547 ;; this record is itself a vector
1548 (defsubst ediff-clear-fine-diff-vector (diff-record)
1549 (if diff-record
1550 (mapcar 'ediff-delete-overlay
1551 (ediff-get-fine-diff-vector-from-diff-record diff-record))))
1553 (defsubst ediff-clear-fine-differences-in-one-buffer (n buf-type)
1554 (ediff-clear-fine-diff-vector (ediff-get-difference n buf-type))
1555 (ediff-set-fine-diff-vector n buf-type nil))
1557 (defsubst ediff-clear-fine-differences (n)
1558 (ediff-clear-fine-differences-in-one-buffer n 'A)
1559 (ediff-clear-fine-differences-in-one-buffer n 'B)
1560 (if ediff-3way-job
1561 (ediff-clear-fine-differences-in-one-buffer n 'C)))
1564 (defsubst ediff-mouse-event-p (event)
1565 (ediff-cond-compile-for-xemacs-or-emacs
1566 (button-event-p event) ; xemacs form
1567 (string-match "mouse" (format "%S" (event-basic-type event))) ; emacs form
1571 (defsubst ediff-key-press-event-p (event)
1572 (ediff-cond-compile-for-xemacs-or-emacs
1573 (key-press-event-p event) ; xemacs form
1574 (or (char-or-string-p event) (symbolp event)) ; emacs form
1577 (defun ediff-event-point (event)
1578 (cond ((ediff-mouse-event-p event)
1579 (ediff-cond-compile-for-xemacs-or-emacs
1580 (event-point event) ; xemacs form
1581 (posn-point (event-start event)) ; emacs form
1584 ((ediff-key-press-event-p event)
1585 (point))
1586 (t (error nil))))
1588 (defun ediff-event-buffer (event)
1589 (cond ((ediff-mouse-event-p event)
1590 (ediff-cond-compile-for-xemacs-or-emacs
1591 (event-buffer event) ; xemacs form
1592 (window-buffer (posn-window (event-start event))) ; emacs form
1595 ((ediff-key-press-event-p event)
1596 (current-buffer))
1597 (t (error nil))))
1599 (defun ediff-event-key (event-or-key)
1600 (ediff-cond-compile-for-xemacs-or-emacs
1601 (if (eventp event-or-key) (event-key event-or-key) event-or-key) ; xemacs
1602 event-or-key ; emacs form
1606 (defsubst ediff-frame-iconified-p (frame)
1607 (if (and (ediff-window-display-p) (frame-live-p frame))
1608 (ediff-cond-compile-for-xemacs-or-emacs
1609 (frame-iconified-p frame) ; xemacs form
1610 (eq (frame-visible-p frame) 'icon) ; emacs form
1614 (defsubst ediff-window-visible-p (wind)
1615 ;; under TTY, window-live-p also means window is visible
1616 (and (window-live-p wind)
1617 (or (not (ediff-window-display-p))
1618 (frame-visible-p (window-frame wind)))))
1621 (defsubst ediff-frame-char-width (frame)
1622 (ediff-cond-compile-for-xemacs-or-emacs
1623 (/ (frame-pixel-width frame) (frame-width frame)) ; xemacs
1624 (frame-char-width frame) ; emacs
1627 (defun ediff-reset-mouse (&optional frame do-not-grab-mouse)
1628 (or frame (setq frame (selected-frame)))
1629 (if (ediff-window-display-p)
1630 (let ((frame-or-wind frame))
1631 (if ediff-xemacs-p
1632 (setq frame-or-wind (frame-selected-window frame)))
1633 (or do-not-grab-mouse
1634 ;; don't set mouse if the user said to never do this
1635 (not ediff-grab-mouse)
1636 ;; Don't grab on quit, if the user doesn't want to.
1637 ;; If ediff-grab-mouse = t, then mouse won't be grabbed for
1638 ;; sessions that are not part of a group (this is done in
1639 ;; ediff-recenter). The condition below affects only terminating
1640 ;; sessions in session groups (in which case mouse is warped into
1641 ;; a meta buffer).
1642 (and (eq ediff-grab-mouse 'maybe)
1643 (memq this-command '(ediff-quit ediff-update-diffs)))
1644 (set-mouse-position frame-or-wind 1 0))
1647 (defsubst ediff-spy-after-mouse ()
1648 (setq ediff-mouse-pixel-position (mouse-pixel-position)))
1650 ;; It is not easy to find out when the user grabs the mouse, since emacs and
1651 ;; xemacs behave differently when mouse is not in any frame. Also, this is
1652 ;; sensitive to when the user grabbed mouse. Not used for now.
1653 (defun ediff-user-grabbed-mouse ()
1654 (if ediff-mouse-pixel-position
1655 (cond ((not (eq (car ediff-mouse-pixel-position)
1656 (car (mouse-pixel-position)))))
1657 ((and (car (cdr ediff-mouse-pixel-position))
1658 (car (cdr (mouse-pixel-position)))
1659 (cdr (cdr ediff-mouse-pixel-position))
1660 (cdr (cdr (mouse-pixel-position))))
1661 (not (and (< (abs (- (car (cdr ediff-mouse-pixel-position))
1662 (car (cdr (mouse-pixel-position)))))
1663 ediff-mouse-pixel-threshold)
1664 (< (abs (- (cdr (cdr ediff-mouse-pixel-position))
1665 (cdr (cdr (mouse-pixel-position)))))
1666 ediff-mouse-pixel-threshold))))
1667 (t nil))))
1669 (defsubst ediff-frame-char-height (frame)
1670 (ediff-cond-compile-for-xemacs-or-emacs
1671 (glyph-height ediff-H-glyph (frame-selected-window frame)) ; xemacs case
1672 (frame-char-height frame) ; emacs case
1676 ;; Some overlay functions
1678 (defsubst ediff-overlay-start (overl)
1679 (if (ediff-overlayp overl)
1680 (ediff-cond-compile-for-xemacs-or-emacs
1681 (extent-start-position overl) ; xemacs form
1682 (overlay-start overl) ; emacs form
1686 (defsubst ediff-overlay-end (overl)
1687 (if (ediff-overlayp overl)
1688 (ediff-cond-compile-for-xemacs-or-emacs
1689 (extent-end-position overl) ; xemacs form
1690 (overlay-end overl) ; emacs form
1694 (defsubst ediff-empty-overlay-p (overl)
1695 (= (ediff-overlay-start overl) (ediff-overlay-end overl)))
1697 ;; like overlay-buffer in Emacs. In XEmacs, returns nil if the extent is
1698 ;; dead. Otherwise, works like extent-buffer
1699 (defun ediff-overlay-buffer (overl)
1700 (ediff-cond-compile-for-xemacs-or-emacs
1701 (and (extent-live-p overl) (extent-object overl)) ; xemacs form
1702 (overlay-buffer overl) ; emacs form
1705 ;; like overlay-get in Emacs. In XEmacs, returns nil if the extent is
1706 ;; dead. Otherwise, like extent-property
1707 (defun ediff-overlay-get (overl property)
1708 (ediff-cond-compile-for-xemacs-or-emacs
1709 (and (extent-live-p overl) (extent-property overl property)) ; xemacs form
1710 (overlay-get overl property) ; emacs form
1714 ;; These two functions are here because XEmacs refuses to
1715 ;; handle overlays whose buffers were deleted.
1716 (defun ediff-move-overlay (overlay beg end &optional buffer)
1717 "Calls `move-overlay' in Emacs and `set-extent-endpoints' in Lemacs.
1718 Checks if overlay's buffer exists before actually doing the move."
1719 (let ((buf (and overlay (ediff-overlay-buffer overlay))))
1720 (if (ediff-buffer-live-p buf)
1721 (ediff-cond-compile-for-xemacs-or-emacs
1722 (set-extent-endpoints overlay beg end) ; xemacs form
1723 (move-overlay overlay beg end buffer) ; emacs form
1725 ;; buffer's dead
1726 (if overlay
1727 (ediff-delete-overlay overlay)))))
1729 (defun ediff-overlay-put (overlay prop value)
1730 "Calls `overlay-put' or `set-extent-property' depending on Emacs version.
1731 Checks if overlay's buffer exists."
1732 (if (ediff-buffer-live-p (ediff-overlay-buffer overlay))
1733 (ediff-cond-compile-for-xemacs-or-emacs
1734 (set-extent-property overlay prop value) ; xemacs form
1735 (overlay-put overlay prop value) ; emacs form
1737 (ediff-delete-overlay overlay)))
1739 ;; temporarily uses DIR to abbreviate file name
1740 ;; if DIR is nil, use default-directory
1741 (defun ediff-abbreviate-file-name (file &optional dir)
1742 (cond ((stringp dir)
1743 (let ((directory-abbrev-alist (list (cons dir ""))))
1744 (abbreviate-file-name file)))
1746 (ediff-cond-compile-for-xemacs-or-emacs
1747 ;; XEmacs requires addl argument
1748 (abbreviate-file-name file t) ; xemacs form
1749 (abbreviate-file-name file)) ; emacs form
1753 ;; Takes a directory and returns the parent directory.
1754 ;; does nothing to `/'. If the ARG is a regular file,
1755 ;; strip the file AND the last dir.
1756 (defun ediff-strip-last-dir (dir)
1757 (if (not (stringp dir)) (setq dir default-directory))
1758 (setq dir (expand-file-name dir))
1759 (or (file-directory-p dir) (setq dir (file-name-directory dir)))
1760 (let* ((pos (1- (length dir)))
1761 (last-char (aref dir pos)))
1762 (if (and (> pos 0) (= last-char ?/))
1763 (setq dir (substring dir 0 pos)))
1764 (ediff-abbreviate-file-name (file-name-directory dir))))
1766 (defun ediff-truncate-string-left (str newlen)
1767 ;; leave space for ... on the left
1768 (let ((len (length str))
1769 substr)
1770 (if (<= len newlen)
1772 (setq newlen (max 0 (- newlen 3)))
1773 (setq substr (substring str (max 0 (- len 1 newlen))))
1774 (concat "..." substr))))
1776 (defsubst ediff-nonempty-string-p (string)
1777 (and (stringp string) (not (string= string ""))))
1779 (unless (fboundp 'subst-char-in-string)
1780 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1781 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1782 Unless optional argument INPLACE is non-nil, return a new string."
1783 (let ((i (length string))
1784 (newstr (if inplace string (copy-sequence string))))
1785 (while (> i 0)
1786 (setq i (1- i))
1787 (if (eq (aref newstr i) fromchar)
1788 (aset newstr i tochar)))
1789 newstr)))
1791 (defun ediff-abbrev-jobname (jobname)
1792 (cond ((eq jobname 'ediff-directories)
1793 "Compare two directories")
1794 ((eq jobname 'ediff-files)
1795 "Compare two files")
1796 ((eq jobname 'ediff-buffers)
1797 "Compare two buffers")
1798 ((eq jobname 'ediff-directories3)
1799 "Compare three directories")
1800 ((eq jobname 'ediff-files3)
1801 "Compare three files")
1802 ((eq jobname 'ediff-buffers3)
1803 "Compare three buffers")
1804 ((eq jobname 'ediff-revision)
1805 "Compare file with a version")
1806 ((eq jobname 'ediff-directory-revisions)
1807 "Compare dir files with versions")
1808 ((eq jobname 'ediff-merge-directory-revisions)
1809 "Merge dir files with versions")
1810 ((eq jobname 'ediff-merge-directory-revisions-with-ancestor)
1811 "Merge dir versions via ancestors")
1813 (capitalize
1814 (subst-char-in-string ?- ?\s (substring (symbol-name jobname) 6))))
1818 ;; If ediff modified mode line, strip the modification
1819 (defsubst ediff-strip-mode-line-format ()
1820 (if (member (car mode-line-format) '(" A: " " B: " " C: " " Ancestor: "))
1821 (setq mode-line-format (nth 2 mode-line-format))))
1823 ;; Verify that we have a difference selected.
1824 (defsubst ediff-valid-difference-p (&optional n)
1825 (or n (setq n ediff-current-difference))
1826 (and (>= n 0) (< n ediff-number-of-differences)))
1828 (defsubst ediff-show-all-diffs (n)
1829 "Don't skip difference regions."
1830 nil)
1832 (defsubst Xor (a b)
1833 (or (and a (not b)) (and (not a) b)))
1835 (defsubst ediff-message-if-verbose (string &rest args)
1836 (if ediff-verbose-p
1837 (apply 'message string args)))
1839 (defun ediff-file-attributes (filename attr-number)
1840 (if (ediff-listable-file filename)
1841 (nth attr-number (file-attributes filename))
1845 (defsubst ediff-file-size (filename)
1846 (ediff-file-attributes filename 7))
1847 (defsubst ediff-file-modtime (filename)
1848 (ediff-file-attributes filename 5))
1851 (defun ediff-convert-standard-filename (fname)
1852 (if (fboundp 'convert-standard-filename)
1853 (convert-standard-filename fname)
1854 fname))
1857 (if (fboundp 'with-syntax-table)
1858 (defalias 'ediff-with-syntax-table 'with-syntax-table)
1859 ;; stolen from subr.el in emacs 21
1860 (defmacro ediff-with-syntax-table (table &rest body)
1861 (let ((old-table (make-symbol "table"))
1862 (old-buffer (make-symbol "buffer")))
1863 `(let ((,old-table (syntax-table))
1864 (,old-buffer (current-buffer)))
1865 (unwind-protect
1866 (progn
1867 (set-syntax-table (copy-syntax-table ,table))
1868 ,@body)
1869 (save-current-buffer
1870 (set-buffer ,old-buffer)
1871 (set-syntax-table ,old-table)))))))
1874 (provide 'ediff-init)
1878 ;; Local Variables:
1879 ;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1880 ;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1881 ;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1882 ;; End:
1884 ;; arch-tag: fa31d384-1e70-4d4b-82a7-3e96307c46f5
1885 ;;; ediff-init.el ends here