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