ediff-init.el 67.8 KB
Newer Older
1
;;; ediff-init.el --- Macros, variables, and defsubsts used by Ediff
Erik Naggum's avatar
Erik Naggum committed
2

3
;; Copyright (C) 1994-2011 Free Software Foundation, Inc.
Karl Heuer's avatar
Karl Heuer committed
4

5
;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
6
;; Package: ediff
Karl Heuer's avatar
Karl Heuer committed
7 8 9

;; This file is part of GNU Emacs.

10
;; GNU Emacs is free software: you can redistribute it and/or modify
Karl Heuer's avatar
Karl Heuer committed
11
;; it under the terms of the GNU General Public License as published by
12 13
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
Karl Heuer's avatar
Karl Heuer committed
14 15 16 17 18 19 20

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
21
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
Karl Heuer's avatar
Karl Heuer committed
22

23 24
;;; Commentary:

Erik Naggum's avatar
Erik Naggum committed
25
;;; Code:
Karl Heuer's avatar
Karl Heuer committed
26

Michael Kifer's avatar
Michael Kifer committed
27 28 29 30 31 32 33 34
;; Start compiler pacifier
(defvar ediff-metajob-name)
(defvar ediff-meta-buffer)
(defvar ediff-grab-mouse)
(defvar ediff-mouse-pixel-position)
(defvar ediff-mouse-pixel-threshold)
(defvar ediff-whitespace)
(defvar ediff-multiframe)
Michael Kifer's avatar
Michael Kifer committed
35
(defvar ediff-use-toolbar-p)
36
(defvar mswindowsx-bitmap-file-path)
Michael Kifer's avatar
Michael Kifer committed
37 38 39 40 41 42 43
;; end pacifier

(defvar ediff-force-faces nil
  "If t, Ediff will think that it is running on a display that supports faces.
This is provided as a temporary relief for users of face-capable displays
that Ediff doesn't know about.")

44 45
;; Are we running as a window application or on a TTY?
(defsubst ediff-device-type ()
46 47 48
  (if (featurep 'xemacs)
      (device-type (selected-device))
    window-system))
Michael Kifer's avatar
Michael Kifer committed
49

50
;; in XEmacs: device-type is tty on tty and stream in batch.
Michael Kifer's avatar
Michael Kifer committed
51 52 53 54 55 56 57
(defun ediff-window-display-p ()
  (and (ediff-device-type) (not (memq (ediff-device-type) '(tty pc stream)))))

;; test if supports faces
(defun ediff-has-face-support-p ()
  (cond ((ediff-window-display-p))
	(ediff-force-faces)
58
	((ediff-color-display-p))
59 60
	((featurep 'emacs) (memq (ediff-device-type) '(pc)))
	((featurep 'xemacs) (memq (ediff-device-type) '(tty pc)))
61
	))
Michael Kifer's avatar
Michael Kifer committed
62

63
;; toolbar support for emacs hasn't been implemented in ediff
Michael Kifer's avatar
Michael Kifer committed
64
(defun ediff-has-toolbar-support-p ()
65 66
  (if (featurep 'xemacs)
      (if (featurep 'toolbar) (console-on-window-system-p))))
Michael Kifer's avatar
Michael Kifer committed
67

68 69

(defun ediff-has-gutter-support-p ()
70 71
  (if (featurep 'xemacs)
      (if (featurep 'gutter) (console-on-window-system-p))))
72

Michael Kifer's avatar
Michael Kifer committed
73 74 75 76 77
(defun ediff-use-toolbar-p ()
  (and (ediff-has-toolbar-support-p)	;Can it do it ?
       (boundp 'ediff-use-toolbar-p)
       ediff-use-toolbar-p))		;Does the user want it ?

78
;; Defines VAR as an advertised local variable.
Michael Kifer's avatar
Michael Kifer committed
79 80 81 82
;; Performs a defvar, then executes `make-variable-buffer-local' on
;; the variable.  Also sets the `permanent-local' property,
;; so that `kill-all-local-variables' (called by major-mode setting
;; commands) won't destroy Ediff control variables.
83
;;
Michael Kifer's avatar
Michael Kifer committed
84
;; Plagiarised from `emerge-defvar-local' for XEmacs.
85
(defmacro ediff-defvar-local (var value doc)
86
  "Defines VAR as a local variable."
87
  (declare (indent defun))
Michael Kifer's avatar
Michael Kifer committed
88 89 90 91
  `(progn
     (defvar ,var ,value ,doc)
     (make-variable-buffer-local ',var)
     (put ',var 'permanent-local t)))
92

Michael Kifer's avatar
Michael Kifer committed
93 94 95 96 97 98 99 100 101


;; Variables that control each Ediff session---local to the control buffer.

;; Mode variables
;; The buffer in which the A variant is stored.
(ediff-defvar-local ediff-buffer-A nil "")
;; The buffer in which the B variant is stored.
(ediff-defvar-local ediff-buffer-B nil "")
Michael Kifer's avatar
Michael Kifer committed
102
;; The buffer in which the C variant is stored or where the merge buffer lives.
Michael Kifer's avatar
Michael Kifer committed
103 104 105
(ediff-defvar-local ediff-buffer-C nil "")
;; Ancestor buffer
(ediff-defvar-local ediff-ancestor-buffer nil "")
Michael Kifer's avatar
Michael Kifer committed
106
;; The Ediff control buffer
Michael Kifer's avatar
Michael Kifer committed
107
(ediff-defvar-local ediff-control-buffer nil "")
Karl Heuer's avatar
Karl Heuer committed
108

109 110 111 112
(ediff-defvar-local ediff-temp-indirect-buffer nil
  "If t, the buffer is a temporary indirect buffer.
It needs to be killed when we quit the session.")

Michael Kifer's avatar
Michael Kifer committed
113 114 115 116 117 118 119

;; Association between buff-type and ediff-buffer-*
(defconst ediff-buffer-alist
  '((?A . ediff-buffer-A)
    (?B . ediff-buffer-B)
    (?C . ediff-buffer-C)))

Karl Heuer's avatar
Karl Heuer committed
120 121
;;; Macros
(defmacro ediff-odd-p (arg)
Michael Kifer's avatar
Michael Kifer committed
122
  `(eq (logand ,arg 1) 1))
Karl Heuer's avatar
Karl Heuer committed
123 124

(defmacro ediff-buffer-live-p (buf)
Michael Kifer's avatar
Michael Kifer committed
125
  `(and ,buf (get-buffer ,buf) (buffer-name (get-buffer ,buf))))
Karl Heuer's avatar
Karl Heuer committed
126 127

(defmacro ediff-get-buffer (arg)
Michael Kifer's avatar
Michael Kifer committed
128 129 130 131 132
  `(cond ((eq ,arg 'A) ediff-buffer-A)
	 ((eq ,arg 'B) ediff-buffer-B)
	 ((eq ,arg 'C) ediff-buffer-C)
	 ((eq ,arg 'Ancestor) ediff-ancestor-buffer)
	 ))
133

Karl Heuer's avatar
Karl Heuer committed
134
(defmacro ediff-get-value-according-to-buffer-type (buf-type list)
Michael Kifer's avatar
Michael Kifer committed
135 136 137 138
  `(cond ((eq ,buf-type 'A) (nth 0 ,list))
	 ((eq ,buf-type 'B) (nth 1 ,list))
	 ((eq ,buf-type 'C) (nth 2 ,list))
	 ))
139

Karl Heuer's avatar
Karl Heuer committed
140
(defmacro ediff-char-to-buftype (arg)
Michael Kifer's avatar
Michael Kifer committed
141 142 143 144
  `(cond ((memq ,arg '(?a ?A)) 'A)
	 ((memq ,arg '(?b ?B)) 'B)
	 ((memq ,arg '(?c ?C)) 'C)
	 ))
Michael Kifer's avatar
Michael Kifer committed
145

Michael Kifer's avatar
Michael Kifer committed
146

Michael Kifer's avatar
Michael Kifer committed
147 148
;; A-list is supposed to be of the form (A . symb) (B . symb)...)
;; where the first part of any association is a buffer type and the second is
Michael Kifer's avatar
Michael Kifer committed
149 150
;; an appropriate symbol.  Given buffer-type, this function returns the
;; symbol.  This is used to avoid using `intern'
Michael Kifer's avatar
Michael Kifer committed
151 152
(defsubst ediff-get-symbol-from-alist (buf-type alist)
  (cdr (assoc buf-type alist)))
153

Michael Kifer's avatar
Michael Kifer committed
154 155 156 157 158 159
(defconst ediff-difference-vector-alist
  '((A . ediff-difference-vector-A)
    (B . ediff-difference-vector-B)
    (C . ediff-difference-vector-C)
    (Ancestor . ediff-difference-vector-Ancestor)))

Karl Heuer's avatar
Karl Heuer committed
160
(defmacro ediff-get-difference (n buf-type)
Michael Kifer's avatar
Michael Kifer committed
161 162 163 164 165
  `(aref
    (symbol-value
     (ediff-get-symbol-from-alist
      ,buf-type ediff-difference-vector-alist))
    ,n))
166

Michael Kifer's avatar
Michael Kifer committed
167
;; Tell if it has been previously determined that the region has
Karl Heuer's avatar
Karl Heuer committed
168 169
;; no diffs other than the white space and newlines
;; The argument, N, is the diff region number used by Ediff to index the
Michael Kifer's avatar
Michael Kifer committed
170
;; diff vector.  It is 1 less than the number seen by the user.
Michael Kifer's avatar
Michael Kifer committed
171 172 173 174 175 176 177 178
;; Returns:
;;		t  if the diffs are whitespace in all buffers
;;		'A (in 3-buf comparison only) if there are only whitespace
;;		   diffs in bufs B and C
;;		'B (in 3-buf comparison only) if there are only whitespace
;;		   diffs in bufs A and C
;;		'C (in 3-buf comparison only) if there are only whitespace
;;		   diffs in bufs A and B
Karl Heuer's avatar
Karl Heuer committed
179
;;
Michael Kifer's avatar
Michael Kifer committed
180
;; A Difference Vector has the form:
Karl Heuer's avatar
Karl Heuer committed
181 182
;; [diff diff diff ...]
;; where each diff has the form:
Michael Kifer's avatar
Michael Kifer committed
183
;; [overlay fine-diff-vector no-fine-diffs-flag state-of-difference]
Karl Heuer's avatar
Karl Heuer committed
184
;; fine-diff-vector is a vector [fine-diff fine-diff fine-diff ...]
Michael Kifer's avatar
Michael Kifer committed
185 186 187
;; no-fine-diffs-flag says if there are fine differences.
;; state-of-difference is A, B, C, or nil, indicating which buffer is
;; 	different from the other two (used only in 3-way jobs).
Karl Heuer's avatar
Karl Heuer committed
188
(defmacro ediff-no-fine-diffs-p (n)
Michael Kifer's avatar
Michael Kifer committed
189
  `(aref (ediff-get-difference ,n 'A) 2))
190

Karl Heuer's avatar
Karl Heuer committed
191
(defmacro ediff-get-diff-overlay-from-diff-record (diff-rec)
Michael Kifer's avatar
Michael Kifer committed
192
  `(aref ,diff-rec 0))
193 194

(defmacro ediff-get-diff-overlay (n buf-type)
Michael Kifer's avatar
Michael Kifer committed
195 196
  `(ediff-get-diff-overlay-from-diff-record
    (ediff-get-difference ,n ,buf-type)))
Karl Heuer's avatar
Karl Heuer committed
197 198

(defmacro ediff-get-fine-diff-vector-from-diff-record (diff-rec)
Michael Kifer's avatar
Michael Kifer committed
199
  `(aref ,diff-rec 1))
200

Karl Heuer's avatar
Karl Heuer committed
201
(defmacro ediff-set-fine-diff-vector (n buf-type fine-vec)
Michael Kifer's avatar
Michael Kifer committed
202
  `(aset (ediff-get-difference ,n ,buf-type) 1 ,fine-vec))
203

Karl Heuer's avatar
Karl Heuer committed
204
(defmacro ediff-get-state-of-diff (n buf-type)
Michael Kifer's avatar
Michael Kifer committed
205 206
  `(if (ediff-buffer-live-p ediff-buffer-C)
       (aref (ediff-get-difference ,n ,buf-type) 3)))
Karl Heuer's avatar
Karl Heuer committed
207
(defmacro ediff-set-state-of-diff (n buf-type val)
Michael Kifer's avatar
Michael Kifer committed
208
  `(aset (ediff-get-difference ,n ,buf-type) 3 ,val))
Michael Kifer's avatar
Michael Kifer committed
209

Karl Heuer's avatar
Karl Heuer committed
210
(defmacro ediff-get-state-of-merge (n)
Michael Kifer's avatar
Michael Kifer committed
211 212
  `(if ediff-state-of-merge
       (aref (aref ediff-state-of-merge ,n) 0)))
Karl Heuer's avatar
Karl Heuer committed
213
(defmacro ediff-set-state-of-merge (n val)
Michael Kifer's avatar
Michael Kifer committed
214 215
  `(if ediff-state-of-merge
       (aset (aref ediff-state-of-merge ,n) 0 ,val)))
Karl Heuer's avatar
Karl Heuer committed
216

Michael Kifer's avatar
Michael Kifer committed
217
(defmacro ediff-get-state-of-ancestor (n)
Michael Kifer's avatar
Michael Kifer committed
218 219
  `(if ediff-state-of-merge
       (aref (aref ediff-state-of-merge ,n) 1)))
Michael Kifer's avatar
Michael Kifer committed
220

221
;; if flag is t, puts a mark on diff region saying that
Michael Kifer's avatar
Michael Kifer committed
222
;; the differences are in white space only.  If flag is nil,
Karl Heuer's avatar
Karl Heuer committed
223 224 225
;; the region is marked as essential (i.e., differences are
;; not just in the white space and newlines.)
(defmacro ediff-mark-diff-as-space-only (n flag)
Michael Kifer's avatar
Michael Kifer committed
226
  `(aset (ediff-get-difference ,n 'A) 2 ,flag))
227

Karl Heuer's avatar
Karl Heuer committed
228
(defmacro ediff-get-fine-diff-vector (n buf-type)
Michael Kifer's avatar
Michael Kifer committed
229 230
  `(ediff-get-fine-diff-vector-from-diff-record
    (ediff-get-difference ,n ,buf-type)))
231

Michael Kifer's avatar
Michael Kifer committed
232 233 234 235
;; Macro to switch to BUFFER, evaluate BODY, returns to original buffer.
;; Doesn't save the point and mark.
;; This is `with-current-buffer' with the added test for live buffers."
(defmacro ediff-with-current-buffer (buffer &rest body)
236
  "Evaluates BODY in BUFFER."
237
  (declare (indent 1) (debug (form body)))
Michael Kifer's avatar
Michael Kifer committed
238
  `(if (ediff-buffer-live-p ,buffer)
Michael Kifer's avatar
Michael Kifer committed
239
       (save-current-buffer
Michael Kifer's avatar
Michael Kifer committed
240 241
	 (set-buffer ,buffer)
	 ,@body)
Michael Kifer's avatar
Michael Kifer committed
242 243
     (or (eq this-command 'ediff-quit)
	 (error ediff-KILLED-VITAL-BUFFER))
Michael Kifer's avatar
Michael Kifer committed
244
     ))
245

Karl Heuer's avatar
Karl Heuer committed
246

247 248
(defsubst ediff-multiframe-setup-p ()
  (and (ediff-window-display-p) ediff-multiframe))
249

Karl Heuer's avatar
Karl Heuer committed
250
(defmacro ediff-narrow-control-frame-p ()
Michael Kifer's avatar
Michael Kifer committed
251 252
  `(and (ediff-multiframe-setup-p)
	(equal ediff-help-message ediff-brief-message-string)))
253

Karl Heuer's avatar
Karl Heuer committed
254
(defmacro ediff-3way-comparison-job ()
Michael Kifer's avatar
Michael Kifer committed
255 256 257
  `(memq
    ediff-job-name
    '(ediff-files3 ediff-buffers3)))
Karl Heuer's avatar
Karl Heuer committed
258
(ediff-defvar-local ediff-3way-comparison-job nil "")
259

Karl Heuer's avatar
Karl Heuer committed
260
(defmacro ediff-merge-job ()
Michael Kifer's avatar
Michael Kifer committed
261 262 263 264 265 266 267 268
  `(memq
    ediff-job-name
    '(ediff-merge-files
      ediff-merge-buffers
      ediff-merge-files-with-ancestor
      ediff-merge-buffers-with-ancestor
      ediff-merge-revisions
      ediff-merge-revisions-with-ancestor)))
Karl Heuer's avatar
Karl Heuer committed
269 270
(ediff-defvar-local ediff-merge-job nil "")

271 272 273
(defmacro ediff-patch-job ()
  `(eq ediff-job-name 'epatch))

Karl Heuer's avatar
Karl Heuer committed
274
(defmacro ediff-merge-with-ancestor-job ()
Michael Kifer's avatar
Michael Kifer committed
275 276 277 278 279
  `(memq
    ediff-job-name
    '(ediff-merge-files-with-ancestor
      ediff-merge-buffers-with-ancestor
      ediff-merge-revisions-with-ancestor)))
Karl Heuer's avatar
Karl Heuer committed
280 281 282
(ediff-defvar-local ediff-merge-with-ancestor-job nil "")

(defmacro ediff-3way-job ()
Michael Kifer's avatar
Michael Kifer committed
283
  `(or ediff-3way-comparison-job ediff-merge-job))
Karl Heuer's avatar
Karl Heuer committed
284 285 286 287 288
(ediff-defvar-local ediff-3way-job nil "")

;; A diff3 job is like a 3way job, but ediff-merge doesn't require the use
;; of diff3.
(defmacro ediff-diff3-job ()
Michael Kifer's avatar
Michael Kifer committed
289 290
  `(or ediff-3way-comparison-job
       ediff-merge-with-ancestor-job))
Karl Heuer's avatar
Karl Heuer committed
291
(ediff-defvar-local ediff-diff3-job nil "")
292

293
(defmacro ediff-windows-job ()
Michael Kifer's avatar
Michael Kifer committed
294
  `(memq ediff-job-name '(ediff-windows-wordwise ediff-windows-linewise)))
295 296
(ediff-defvar-local ediff-windows-job nil "")

Karl Heuer's avatar
Karl Heuer committed
297
(defmacro ediff-word-mode-job ()
Michael Kifer's avatar
Michael Kifer committed
298
  `(memq ediff-job-name '(ediff-windows-wordwise ediff-regions-wordwise)))
Karl Heuer's avatar
Karl Heuer committed
299 300
(ediff-defvar-local ediff-word-mode-job nil "")

301
(defmacro ediff-narrow-job ()
Michael Kifer's avatar
Michael Kifer committed
302 303 304 305
  `(memq ediff-job-name '(ediff-windows-wordwise
			  ediff-regions-wordwise
			  ediff-windows-linewise
			  ediff-regions-linewise)))
306 307
(ediff-defvar-local ediff-narrow-job nil "")

308 309 310 311 312 313 314 315
;; Note: ediff-merge-directory-revisions-with-ancestor is not treated as an
;; ancestor metajob, since it behaves differently.
(defsubst ediff-ancestor-metajob (&optional metajob)
  (memq (or metajob ediff-metajob-name)
	'(ediff-merge-directories-with-ancestor
	  ediff-merge-filegroups-with-ancestor)))
(defsubst ediff-revision-metajob (&optional metajob)
  (memq (or metajob ediff-metajob-name)
316
	'(ediff-directory-revisions
317 318
	  ediff-merge-directory-revisions
	  ediff-merge-directory-revisions-with-ancestor)))
Michael Kifer's avatar
Michael Kifer committed
319 320 321 322 323 324
(defsubst ediff-patch-metajob (&optional metajob)
  (memq (or metajob ediff-metajob-name)
	'(ediff-multifile-patch)))
;; metajob involving only one group of files, such as multipatch or directory
;; revision
(defsubst ediff-one-filegroup-metajob (&optional metajob)
325
  (or (ediff-revision-metajob metajob)
Michael Kifer's avatar
Michael Kifer committed
326
      (ediff-patch-metajob metajob)
327 328
      ;; add more here
      ))
Michael Kifer's avatar
Michael Kifer committed
329
;; jobs suitable for the operation of collecting diffs into a multifile patch
330
(defsubst ediff-collect-diffs-metajob (&optional metajob)
Michael Kifer's avatar
Michael Kifer committed
331 332 333 334
  (memq (or metajob ediff-metajob-name)
	'(ediff-directories
	  ediff-merge-directories
	  ediff-merge-directories-with-ancestor
Michael Kifer's avatar
Michael Kifer committed
335
	  ediff-directory-revisions
Michael Kifer's avatar
Michael Kifer committed
336 337 338 339
	  ediff-merge-directory-revisions
	  ediff-merge-directory-revisions-with-ancestor
	  ;; add more here
	  )))
Michael Kifer's avatar
Michael Kifer committed
340 341 342 343 344 345
(defsubst ediff-merge-metajob (&optional metajob)
  (memq (or metajob ediff-metajob-name)
	'(ediff-merge-directories
	  ediff-merge-directories-with-ancestor
	  ediff-merge-directory-revisions
	  ediff-merge-directory-revisions-with-ancestor
346
	  ediff-merge-filegroups-with-ancestor
Michael Kifer's avatar
Michael Kifer committed
347 348
	  ;; add more here
	  )))
Michael Kifer's avatar
Michael Kifer committed
349

350 351 352
(defsubst ediff-metajob3 (&optional metajob)
  (memq (or metajob ediff-metajob-name)
	'(ediff-merge-directories-with-ancestor
353
	  ediff-merge-filegroups-with-ancestor
354 355 356 357 358 359
	  ediff-directories3
	  ediff-filegroups3)))
(defsubst ediff-comparison-metajob3 (&optional metajob)
  (memq (or metajob ediff-metajob-name)
	'(ediff-directories3 ediff-filegroups3)))

Michael Kifer's avatar
Michael Kifer committed
360 361 362 363 364 365 366 367 368
;; with no argument, checks if we are in ediff-control-buffer
;; with argument, checks if we are in ediff-meta-buffer
(defun ediff-in-control-buffer-p (&optional meta-buf-p)
  (and (boundp 'ediff-control-buffer)
       (eq (if meta-buf-p ediff-meta-buffer ediff-control-buffer)
	   (current-buffer))))

(defsubst ediff-barf-if-not-control-buffer (&optional meta-buf-p)
  (or (ediff-in-control-buffer-p meta-buf-p)
369 370 371
      (error "%S: This command runs in Ediff Control Buffer only!"
	     this-command)))

Michael Kifer's avatar
Michael Kifer committed
372
(defgroup ediff-highlighting nil
373
  "Hilighting of difference regions in Ediff."
Michael Kifer's avatar
Michael Kifer committed
374 375 376 377
  :prefix "ediff-"
  :group 'ediff)

(defgroup ediff-merge nil
378
  "Merging utilities."
Michael Kifer's avatar
Michael Kifer committed
379 380 381 382
  :prefix "ediff-"
  :group 'ediff)

(defgroup ediff-hook nil
383
  "Hooks run by Ediff."
Michael Kifer's avatar
Michael Kifer committed
384 385 386
  :prefix "ediff-"
  :group 'ediff)

Karl Heuer's avatar
Karl Heuer committed
387 388
;; Hook variables

389
(defcustom ediff-before-setup-hook nil
Lute Kamstra's avatar
Lute Kamstra committed
390
  "Hooks to run before Ediff begins to set up windows and buffers.
391 392 393
This hook can be used to save the previous window config, which can be restored
on ediff-quit or ediff-suspend."
  :type 'hook
394
  :group 'ediff-hook)
Michael Kifer's avatar
Michael Kifer committed
395
(defcustom ediff-before-setup-windows-hook nil
Lute Kamstra's avatar
Lute Kamstra committed
396
  "Hooks to run before Ediff sets its window configuration.
397
This hook is run every time when Ediff arranges its windows.
398 399
This happens each time Ediff detects that the windows were messed up by the
user."
Michael Kifer's avatar
Michael Kifer committed
400
  :type 'hook
401
  :group 'ediff-hook)
Michael Kifer's avatar
Michael Kifer committed
402
(defcustom ediff-after-setup-windows-hook nil
Lute Kamstra's avatar
Lute Kamstra committed
403
  "Hooks to run after Ediff sets its window configuration.
Michael Kifer's avatar
Michael Kifer committed
404 405
This can be used to set up control window or icon in a desired place."
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
406
  :group 'ediff-hook)
Michael Kifer's avatar
Michael Kifer committed
407
(defcustom ediff-before-setup-control-frame-hook nil
Lute Kamstra's avatar
Lute Kamstra committed
408
  "Hooks run before setting up the frame to display Ediff Control Panel.
Karl Heuer's avatar
Karl Heuer committed
409
Can be used to change control frame parameters to position it where it
Michael Kifer's avatar
Michael Kifer committed
410 411
is desirable."
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
412
  :group 'ediff-hook)
Michael Kifer's avatar
Michael Kifer committed
413
(defcustom ediff-after-setup-control-frame-hook nil
Lute Kamstra's avatar
Lute Kamstra committed
414
  "Hooks run after setting up the frame to display Ediff Control Panel.
Michael Kifer's avatar
Michael Kifer committed
415 416
Can be used to move the frame where it is desired."
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
417
  :group 'ediff-hook)
Michael Kifer's avatar
Michael Kifer committed
418
(defcustom ediff-startup-hook nil
Lute Kamstra's avatar
Lute Kamstra committed
419
  "Hooks to run in the control buffer after Ediff has been set up and is ready for the job."
Michael Kifer's avatar
Michael Kifer committed
420
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
421
  :group 'ediff-hook)
Michael Kifer's avatar
Michael Kifer committed
422
(defcustom ediff-select-hook nil
Lute Kamstra's avatar
Lute Kamstra committed
423
  "Hooks to run after a difference has been selected."
Michael Kifer's avatar
Michael Kifer committed
424
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
425
  :group 'ediff-hook)
Michael Kifer's avatar
Michael Kifer committed
426
(defcustom ediff-unselect-hook nil
Lute Kamstra's avatar
Lute Kamstra committed
427
  "Hooks to run after a difference has been unselected."
Michael Kifer's avatar
Michael Kifer committed
428
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
429
  :group 'ediff-hook)
Michael Kifer's avatar
Michael Kifer committed
430
(defcustom ediff-prepare-buffer-hook  nil
Lute Kamstra's avatar
Lute Kamstra committed
431
  "Hooks run after buffers A, B, and C are set up.
432
For each buffer, the hooks are run with that buffer made current."
Michael Kifer's avatar
Michael Kifer committed
433
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
434
  :group 'ediff-hook)
Michael Kifer's avatar
Michael Kifer committed
435
(defcustom ediff-load-hook nil
Lute Kamstra's avatar
Lute Kamstra committed
436
  "Hook run after Ediff is loaded.  Can be used to change defaults."
Michael Kifer's avatar
Michael Kifer committed
437
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
438
  :group 'ediff-hook)
439

Michael Kifer's avatar
Michael Kifer committed
440
(defcustom ediff-mode-hook nil
Lute Kamstra's avatar
Lute Kamstra committed
441
  "Hook run just after ediff-mode is set up in the control buffer.
Michael Kifer's avatar
Michael Kifer committed
442
This is done before any windows or frames are created.  One can use it to
Michael Kifer's avatar
Michael Kifer committed
443 444
set local variables that determine how the display looks like."
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
445
  :group 'ediff-hook)
Michael Kifer's avatar
Michael Kifer committed
446
(defcustom ediff-keymap-setup-hook nil
Lute Kamstra's avatar
Lute Kamstra committed
447
  "Hook run just after the default bindings in Ediff keymap are set up."
Michael Kifer's avatar
Michael Kifer committed
448
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
449
  :group 'ediff-hook)
450

Michael Kifer's avatar
Michael Kifer committed
451
(defcustom ediff-display-help-hook nil
Lute Kamstra's avatar
Lute Kamstra committed
452
  "Hooks run after preparing the help message."
Michael Kifer's avatar
Michael Kifer committed
453
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
454
  :group 'ediff-hook)
Michael Kifer's avatar
Michael Kifer committed
455

456
(defcustom ediff-suspend-hook nil
Lute Kamstra's avatar
Lute Kamstra committed
457
  "Hooks to run in the Ediff control buffer when Ediff is suspended."
Michael Kifer's avatar
Michael Kifer committed
458
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
459
  :group 'ediff-hook)
460
(defcustom ediff-quit-hook nil
Lute Kamstra's avatar
Lute Kamstra committed
461
  "Hooks to run in the Ediff control buffer after finishing Ediff."
Michael Kifer's avatar
Michael Kifer committed
462
  :type 'hook
463
  :group 'ediff-hook)
Michael Kifer's avatar
Michael Kifer committed
464
(defcustom ediff-cleanup-hook nil
Lute Kamstra's avatar
Lute Kamstra committed
465
  "Hooks to run on exiting Ediff but before killing the control and variant buffers."
Michael Kifer's avatar
Michael Kifer committed
466
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
467
  :group 'ediff-hook)
Karl Heuer's avatar
Karl Heuer committed
468

Michael Kifer's avatar
Michael Kifer committed
469 470 471 472
;; Error messages
(defconst ediff-KILLED-VITAL-BUFFER
  "You have killed a vital Ediff buffer---you must leave Ediff now!")
(defconst ediff-NO-DIFFERENCES
Michael Kifer's avatar
Michael Kifer committed
473 474 475
  "Sorry, comparison of identical variants is not what I am made for...")
(defconst ediff-BAD-DIFF-NUMBER
  ;; %S stands for this-command, %d - diff number, %d - max diff
Michael Kifer's avatar
Michael Kifer committed
476
  "%S: Bad diff region number, %d.  Valid numbers are 1 to %d")
Michael Kifer's avatar
Michael Kifer committed
477 478 479
(defconst ediff-BAD-INFO (format "
*** The Info file for Ediff, a part of the standard distribution
*** of %sEmacs, does not seem to be properly installed.
480
***
Michael Kifer's avatar
Michael Kifer committed
481
*** Please contact your system administrator. "
482
				 (if (featurep 'xemacs) "X" "")))
483

Karl Heuer's avatar
Karl Heuer committed
484 485 486 487 488
;; Selective browsing

(ediff-defvar-local ediff-skip-diff-region-function 'ediff-show-all-diffs
  "Function that determines the next/previous diff region to show.
Should return t for regions to be ignored and nil otherwise.
Michael Kifer's avatar
Michael Kifer committed
489 490
This function gets a region number as an argument.  The region number
is the one used internally by Ediff.  It is 1 less than the number seen
Karl Heuer's avatar
Karl Heuer committed
491 492
by the user.")

493
(ediff-defvar-local ediff-hide-regexp-matches-function
494
  'ediff-hide-regexp-matches
495 496 497 498 499 500 501
  "Function to use in determining which regions to hide.
See the documentation string of `ediff-hide-regexp-matches' for details.")
(ediff-defvar-local ediff-focus-on-regexp-matches-function
  'ediff-focus-on-regexp-matches
  "Function to use in determining which regions to focus on.
See the documentation string of `ediff-focus-on-regexp-matches' for details.")

Karl Heuer's avatar
Karl Heuer committed
502 503 504 505 506 507 508 509 510
;; Regexp that determines buf A regions to focus on when skipping to diff
(ediff-defvar-local ediff-regexp-focus-A "" "")
;; Regexp that determines buf B regions to focus on when skipping to diff
(ediff-defvar-local ediff-regexp-focus-B "" "")
;; Regexp that determines buf C regions to focus on when skipping to diff
(ediff-defvar-local ediff-regexp-focus-C "" "")
;; connective that determines whether to focus regions that match both or
;; one of the regexps
(ediff-defvar-local ediff-focus-regexp-connective 'and "")
511

Karl Heuer's avatar
Karl Heuer committed
512 513 514 515 516 517 518 519 520
;; Regexp that determines buf A regions to ignore when skipping to diff
(ediff-defvar-local ediff-regexp-hide-A "" "")
;; Regexp that determines buf B regions to ignore when skipping to diff
(ediff-defvar-local ediff-regexp-hide-B "" "")
;; Regexp that determines buf C regions to ignore when skipping to diff
(ediff-defvar-local ediff-regexp-hide-C "" "")
;; connective that determines whether to hide regions that match both or
;; one of the regexps
(ediff-defvar-local ediff-hide-regexp-connective 'and "")
Michael Kifer's avatar
Michael Kifer committed
521

522 523 524 525

;;; Copying difference regions between buffers.

;; A list of killed diffs.
Michael Kifer's avatar
Michael Kifer committed
526 527 528 529 530
;; A diff is saved here if it is replaced by a diff
;; from another buffer.  This alist has the form:
;; \((num (buff-object . diff) (buff-object . diff) (buff-object . diff)) ...),
;; where some buffer-objects may be missing.
(ediff-defvar-local ediff-killed-diffs-alist nil "")
Karl Heuer's avatar
Karl Heuer committed
531

532 533 534 535 536
;; Syntax table to use in ediff-forward-word-function
;; This is chosen by a heuristic. The important thing is for all buffers to
;; have the same syntax table. Which is not too important.
(ediff-defvar-local ediff-syntax-table nil "")

Karl Heuer's avatar
Karl Heuer committed
537 538

;; Highlighting
Richard M. Stallman's avatar
Richard M. Stallman committed
539
(defcustom ediff-before-flag-bol (if (featurep 'xemacs) (make-glyph "->>") "->>")
Lute Kamstra's avatar
Lute Kamstra committed
540
  "Flag placed before a highlighted block of differences, if block starts at beginning of a line."
Michael Kifer's avatar
Michael Kifer committed
541 542 543 544
  :type 'string
  :tag  "Region before-flag at beginning of line"
  :group 'ediff)

Richard M. Stallman's avatar
Richard M. Stallman committed
545
(defcustom ediff-after-flag-eol  (if (featurep 'xemacs) (make-glyph "<<-") "<<-")
Lute Kamstra's avatar
Lute Kamstra committed
546
  "Flag placed after a highlighted block of differences, if block ends at end of a line."
Michael Kifer's avatar
Michael Kifer committed
547 548 549 550
  :type 'string
  :tag  "Region after-flag at end of line"
  :group 'ediff)

Richard M. Stallman's avatar
Richard M. Stallman committed
551
(defcustom ediff-before-flag-mol (if (featurep 'xemacs) (make-glyph "->>") "->>")
Lute Kamstra's avatar
Lute Kamstra committed
552
  "Flag placed before a highlighted block of differences, if block starts in mid-line."
Michael Kifer's avatar
Michael Kifer committed
553 554 555
  :type 'string
  :tag  "Region before-flag in the middle of line"
  :group 'ediff)
Richard M. Stallman's avatar
Richard M. Stallman committed
556
(defcustom ediff-after-flag-mol  (if (featurep 'xemacs) (make-glyph "<<-") "<<-")
Lute Kamstra's avatar
Lute Kamstra committed
557
  "Flag placed after a highlighted block of differences, if block ends in mid-line."
Michael Kifer's avatar
Michael Kifer committed
558 559 560
  :type 'string
  :tag  "Region after-flag in the middle of line"
  :group 'ediff)
Karl Heuer's avatar
Karl Heuer committed
561

562 563

(defcustom ediff-use-faces t
Michael Kifer's avatar
Michael Kifer committed
564 565
  "If t, differences are highlighted using faces, if device supports faces.
If nil, differences are highlighted using ASCII flags, ediff-before-flag
Karl Heuer's avatar
Karl Heuer committed
566
and ediff-after-flag.  On a non-window system, differences are always
Michael Kifer's avatar
Michael Kifer committed
567 568 569
highlighted using ASCII flags."
  :type 'boolean
  :group 'ediff-highlighting)
570
(ediff-defvar-local ediff-use-faces t "")
Karl Heuer's avatar
Karl Heuer committed
571 572

;; this indicates that diff regions are word-size, so fine diffs are
573
;; permanently nixed; used in ediff-windows-wordwise and ediff-regions-wordwise
Karl Heuer's avatar
Karl Heuer committed
574
(ediff-defvar-local ediff-word-mode nil "")
575
;; Name of the job (ediff-files, ediff-windows, etc.)
Karl Heuer's avatar
Karl Heuer committed
576 577 578 579 580 581 582 583 584 585 586 587 588
(ediff-defvar-local ediff-job-name nil "")

;; Narrowing and ediff-region/windows support
;; This is a list (overlay-A overlay-B overlay-C)
;; If set, Ediff compares only those parts of buffers A/B/C that lie within
;; the bounds of these overlays.
(ediff-defvar-local ediff-narrow-bounds nil "")

;; List (overlay-A overlay-B overlay-C), where each overlay spans the
;; entire corresponding buffer.
(ediff-defvar-local ediff-wide-bounds nil "")

;; Current visibility boundaries in buffers A, B, and C.
Michael Kifer's avatar
Michael Kifer committed
589
;; This is also a list of overlays.  When the user toggles narrow/widen,
Karl Heuer's avatar
Karl Heuer committed
590 591 592 593 594
;; this list changes from ediff-wide-bounds to ediff-narrow-bounds.
;; and back.
(ediff-defvar-local ediff-visible-bounds nil "")

(ediff-defvar-local ediff-start-narrowed t
595
  "Non-nil means start narrowed, if doing ediff-windows-* or ediff-regions-*")
Karl Heuer's avatar
Karl Heuer committed
596 597 598
(ediff-defvar-local ediff-quit-widened t
  "*Non-nil means: when finished, Ediff widens buffers A/B.
Actually, Ediff restores the scope of visibility that existed at startup.")
Michael Kifer's avatar
Michael Kifer committed
599 600

(defcustom ediff-keep-variants t
Lute Kamstra's avatar
Lute Kamstra committed
601
  "nil means prompt to remove unmodified buffers A/B/C at session end.
Karl Heuer's avatar
Karl Heuer committed
602
Supplying a prefix argument to the quit command `q' temporarily reverses the
Michael Kifer's avatar
Michael Kifer committed
603 604 605
meaning of this variable."
  :type 'boolean
  :group 'ediff)
Karl Heuer's avatar
Karl Heuer committed
606

Michael Kifer's avatar
Michael Kifer committed
607
(defcustom ediff-highlight-all-diffs t
Karl Heuer's avatar
Karl Heuer committed
608
  "If nil, only the selected differences are highlighted.
Michael Kifer's avatar
Michael Kifer committed
609 610 611 612
Otherwise, all difference regions are highlighted, but the selected region is
shown in brighter colors."
  :type 'boolean
  :group 'ediff-highlighting)
613
(ediff-defvar-local ediff-highlight-all-diffs t "")
Karl Heuer's avatar
Karl Heuer committed
614

615

Karl Heuer's avatar
Karl Heuer committed
616 617
;; The suffix of the control buffer name.
(ediff-defvar-local ediff-control-buffer-suffix nil "")
618
;; Same as ediff-control-buffer-suffix, but without <,>.
Karl Heuer's avatar
Karl Heuer committed
619 620 621 622 623
;; It's a number rather than string.
(ediff-defvar-local ediff-control-buffer-number nil "")


;; The original values of ediff-protected-variables for buffer A
624
(ediff-defvar-local ediff-buffer-values-orig-A nil "")
Karl Heuer's avatar
Karl Heuer committed
625
;; The original values of ediff-protected-variables for buffer B
626
(ediff-defvar-local ediff-buffer-values-orig-B nil "")
Karl Heuer's avatar
Karl Heuer committed
627
;; The original values of ediff-protected-variables for buffer C
628
(ediff-defvar-local ediff-buffer-values-orig-C nil "")
629 630
;; The original values of ediff-protected-variables for buffer Ancestor
(ediff-defvar-local ediff-buffer-values-orig-Ancestor nil "")
Michael Kifer's avatar
Michael Kifer committed
631

Michael Kifer's avatar
Michael Kifer committed
632 633 634 635 636 637 638
;; association between buff-type and ediff-buffer-values-orig-*
(defconst ediff-buffer-values-orig-alist
  '((A . ediff-buffer-values-orig-A)
    (B . ediff-buffer-values-orig-B)
    (C . ediff-buffer-values-orig-C)
    (Ancestor . ediff-buffer-values-orig-Ancestor)))

Karl Heuer's avatar
Karl Heuer committed
639
;; Buffer-local variables to be saved then restored during Ediff sessions
Michael Kifer's avatar
Michael Kifer committed
640
(defconst ediff-protected-variables '(
641
				      ;;buffer-read-only
Karl Heuer's avatar
Karl Heuer committed
642 643 644 645 646 647
				      mode-line-format))

;; Vector of differences between the variants.  Each difference is
;; represented by a vector of two overlays plus a vector of fine diffs,
;; plus a no-fine-diffs flag.  The first overlay spans the
;; difference region in the A buffer and the second overlays the diff in
Michael Kifer's avatar
Michael Kifer committed
648
;; the B buffer.  If a difference section is empty, the corresponding
Karl Heuer's avatar
Karl Heuer committed
649 650
;; overlay's endpoints coincide.
;;
Michael Kifer's avatar
Michael Kifer committed
651
;; The precise form of a Difference Vector for one buffer is:
Karl Heuer's avatar
Karl Heuer committed
652 653
;; [diff diff diff ...]
;; where each diff has the form:
Michael Kifer's avatar
Michael Kifer committed
654
;; [diff-overlay fine-diff-vector no-fine-diffs-flag state-of-diff]
Karl Heuer's avatar
Karl Heuer committed
655 656 657
;; fine-diff-vector is a vector [fine-diff-overlay fine-diff-overlay ...]
;; no-fine-diffs-flag says if there are fine differences.
;; state-of-difference is A, B, C, or nil, indicating which buffer is
Michael Kifer's avatar
Michael Kifer committed
658
;;	different from the other two (used only in 3-way jobs.
Karl Heuer's avatar
Karl Heuer committed
659 660 661
(ediff-defvar-local ediff-difference-vector-A nil "")
(ediff-defvar-local ediff-difference-vector-B nil "")
(ediff-defvar-local ediff-difference-vector-C nil "")
662
(ediff-defvar-local ediff-difference-vector-Ancestor nil "")
Michael Kifer's avatar
Michael Kifer committed
663 664 665 666 667 668
;; A-list of diff vector types associated with buffer types
(defconst ediff-difference-vector-alist
  '((A . ediff-difference-vector-A)
    (B . ediff-difference-vector-B)
    (C . ediff-difference-vector-C)
    (Ancestor . ediff-difference-vector-Ancestor)))
669 670 671

;; [ status status status ...]
;; Each status: [state-of-merge state-of-ancestor]
Michael Kifer's avatar
Michael Kifer committed
672
;; state-of-merge is default-A, default-B, prefer-A, or prefer-B.  It
673 674 675 676
;; indicates the way a diff region was created in buffer C.
;; state-of-ancestor says if the corresponding region in ancestor buffer is
;; empty.
(ediff-defvar-local ediff-state-of-merge nil "")
Karl Heuer's avatar
Karl Heuer committed
677 678 679 680 681

;; The difference that is currently selected.
(ediff-defvar-local ediff-current-difference -1 "")
;; Number of differences found.
(ediff-defvar-local ediff-number-of-differences nil "")
682

Karl Heuer's avatar
Karl Heuer committed
683 684 685
;; Buffer containing the output of diff, which is used by Ediff to step
;; through files.
(ediff-defvar-local ediff-diff-buffer nil "")
Michael Kifer's avatar
Michael Kifer committed
686
;; Like ediff-diff-buffer, but contains context diff.  It is not used by
Karl Heuer's avatar
Karl Heuer committed
687 688 689 690 691 692 693 694 695 696 697 698 699
;; Ediff, but it is saved in a file, if user requests so.
(ediff-defvar-local ediff-custom-diff-buffer nil "")
;; Buffer used for diff-style fine differences between regions.
(ediff-defvar-local ediff-fine-diff-buffer nil "")
;; Temporary buffer used for computing fine differences.
(defconst ediff-tmp-buffer " *ediff-tmp*" "")
;; Buffer used for messages
(defconst ediff-msg-buffer " *ediff-message*" "")
;; Buffer containing the output of diff when diff returns errors.
(ediff-defvar-local ediff-error-buffer nil "")
;; Buffer to display debug info
(ediff-defvar-local ediff-debug-buffer "*ediff-debug*" "")

700 701 702
;; List of ediff control panels associated with each buffer A/B/C/Ancestor.
;; Not used any more, but may be needed in the future.
(ediff-defvar-local ediff-this-buffer-ediff-sessions  nil "")
Karl Heuer's avatar
Karl Heuer committed
703 704 705 706

;; to be deleted in due time
;; List of difference overlays disturbed by working with the current diff.
(defvar ediff-disturbed-overlays nil "")
707

Karl Heuer's avatar
Karl Heuer committed
708 709 710
;; Priority of non-selected overlays.
(defvar ediff-shadow-overlay-priority  100 "")

Michael Kifer's avatar
Michael Kifer committed
711
(defcustom ediff-version-control-package 'vc
712
  "Version control package used.
Michael Kifer's avatar
Michael Kifer committed
713 714 715
Currently, Ediff supports vc.el, rcs.el, pcl-cvs.el, and generic-sc.el.  The
standard Emacs interface to RCS, CVS, SCCS, etc., is vc.el.  However, some
people find the other two packages more convenient.  Set this variable to the
Michael Kifer's avatar
Michael Kifer committed
716 717 718
appropriate symbol: `rcs', `pcl-cvs', or `generic-sc' if you so desire."
  :type 'symbol
  :group 'ediff)
719

720
(defcustom ediff-coding-system-for-read 'raw-text
Lute Kamstra's avatar
Lute Kamstra committed
721
  "The coding system for read to use when running the diff program as a subprocess.
722 723
In most cases, the default will do.  However, under certain circumstances in
MS-Windows you might need to use something like 'raw-text-dos here.
724 725 726 727 728 729
So, if the output that your diff program sends to Emacs contains extra ^M's,
you might need to experiment here, if the default or 'raw-text-dos doesn't
work."
  :type 'symbol
  :group 'ediff)

730 731 732
(defcustom ediff-coding-system-for-write (if (featurep 'xemacs)
					     'escape-quoted
					   'emacs-internal)
Lute Kamstra's avatar
Lute Kamstra committed
733
  "The coding system for write to use when writing out difference regions
734
to temp files in buffer jobs and when Ediff needs to find fine differences."
735 736 737
  :type 'symbol
  :group 'ediff)

Karl Heuer's avatar
Karl Heuer committed
738

739 740 741 742 743 744 745 746 747 748 749
(defalias 'ediff-read-event
  (if (featurep 'xemacs) 'next-command-event 'read-event))

(defalias 'ediff-overlayp
  (if (featurep 'xemacs) 'extentp 'overlayp))

(defalias 'ediff-make-overlay
  (if (featurep 'xemacs) 'make-extent 'make-overlay))

(defalias 'ediff-delete-overlay
  (if (featurep 'xemacs) 'delete-extent 'delete-overlay))
750

751
;; Assumes that emacs-major-version and emacs-minor-version are defined.
752
(defun ediff-check-version (op major minor &optional type-of-emacs)
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
  "Check the current version against MAJOR and MINOR version numbers.
The comparison uses operator OP, which may be any of: =, >, >=, <, <=.
TYPE-OF-EMACS is either 'xemacs or 'emacs."
  (and (cond ((eq type-of-emacs 'xemacs) (featurep 'xemacs))
	     ((eq type-of-emacs 'emacs) (featurep 'emacs))
	     (t))
       (cond ((eq op '=) (and (= emacs-minor-version minor)
			      (= emacs-major-version major)))
	     ((memq op '(> >= < <=))
	      (and (or (funcall op emacs-major-version major)
		       (= emacs-major-version major))
		   (if (= emacs-major-version major)
		       (funcall op emacs-minor-version minor)
		     t)))
	     (t
	      (error "%S: Invalid op in ediff-check-version" op)))))

;; ediff-check-version seems to be totally unused anyway.
(make-obsolete 'ediff-check-version 'version< "23.1")
772

773 774
(defun ediff-color-display-p ()
  (condition-case nil
775 776 777
      (if (featurep 'xemacs)
	  (eq (device-class (selected-device)) 'color) ; xemacs form
	(display-color-p)) ; emacs form
778
    (error nil)))
779

780

781 782 783
;; A var local to each control panel buffer.  Indicates highlighting style
;; in effect for this buffer: `face', `ascii',
;; `off' -- turned off \(on a dumb terminal only\).
784
(ediff-defvar-local ediff-highlighting-style
785 786 787 788
  (if (and (ediff-has-face-support-p) ediff-use-faces) 'face 'ascii)
  "")


Michael Kifer's avatar
Michael Kifer committed
789
(if (ediff-window-display-p)
790
    (if (featurep 'xemacs)
791
	(progn
792 793 794 795 796 797 798 799 800 801
	  (defalias 'ediff-display-pixel-width 'device-pixel-width)
	  (defalias 'ediff-display-pixel-height 'device-pixel-height))
      (defalias 'ediff-display-pixel-width
	(if (fboundp 'display-pixel-width)
	    'display-pixel-width
	  'x-display-pixel-width))
      (defalias 'ediff-display-pixel-height
	(if (fboundp 'display-pixel-height)
	    'display-pixel-height
	  'x-display-pixel-height))))
802

803
;; A-list of current-diff-overlay symbols associated with buf types
Michael Kifer's avatar
Michael Kifer committed
804 805 806 807 808
(defconst ediff-current-diff-overlay-alist
  '((A . ediff-current-diff-overlay-A)
    (B . ediff-current-diff-overlay-B)
    (C . ediff-current-diff-overlay-C)
    (Ancestor . ediff-current-diff-overlay-Ancestor)))
809

810
;; A-list of current-diff-face-* symbols associated with buf types
Michael Kifer's avatar
Michael Kifer committed
811
(defconst ediff-current-diff-face-alist
812 813 814 815
  '((A . ediff-current-diff-A)
    (B . ediff-current-diff-B)
    (C . ediff-current-diff-C)
    (Ancestor . ediff-current-diff-Ancestor)))
816

Karl Heuer's avatar
Karl Heuer committed
817

818 819 820
(defun ediff-set-overlay-face (extent face)
  (ediff-overlay-put extent 'face face)
  (ediff-overlay-put extent 'help-echo 'ediff-region-help-echo))
821

822 823 824 825 826
(defun ediff-region-help-echo (extent-or-window &optional overlay point)
  (unless overlay
    (setq overlay extent-or-window))
  (let ((is-current (ediff-overlay-get overlay 'ediff))
	(face (ediff-overlay-get overlay 'face))
827 828
	(diff-num (ediff-overlay-get overlay 'ediff-diff-num))
	face-help)
829 830

    ;; This happens only for refinement overlays
831 832
    (if (stringp face)
	(setq face (intern face)))
833 834
    (setq face-help (and face (get face 'ediff-help-echo)))

835
    (cond ((and is-current diff-num)	; current diff region
Michael Kifer's avatar
Michael Kifer committed
836
	   (format "Difference region %S -- current" (1+ diff-num)))
837
	  (face-help)			; refinement of current diff region
838
	  (diff-num			; non-current
Michael Kifer's avatar
Michael Kifer committed
839
	   (format "Difference region %S -- non-current" (1+ diff-num)))
840