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