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