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