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