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