ediff-init.el 68 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, 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
Karl Heuer's avatar
Karl Heuer committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

;; Author: Michael Kifer <kifer@cs.sunysb.edu>

;; This file is part of GNU Emacs.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; 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
Erik Naggum's avatar
Erik Naggum committed
20 21 22
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
Karl Heuer's avatar
Karl Heuer committed
23

24 25
;;; Commentary:

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

Michael Kifer's avatar
Michael Kifer committed
28 29 30 31 32 33 34 35 36
;; Start compiler pacifier
(defvar ediff-metajob-name)
(defvar ediff-meta-buffer)
(defvar pm-color-alist)
(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
37
(defvar ediff-use-toolbar-p)
Michael Kifer's avatar
Michael Kifer committed
38 39 40 41

(and noninteractive
     (eval-when-compile
	 (load "ange-ftp" 'noerror)))
Michael Kifer's avatar
Michael Kifer committed
42 43
;; end pacifier

44
;; Is it XEmacs?
45
(defconst ediff-xemacs-p (string-match "XEmacs" emacs-version))
46 47
;; Is it Emacs?
(defconst ediff-emacs-p (not ediff-xemacs-p))
Michael Kifer's avatar
Michael Kifer committed
48 49 50 51 52 53

(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.")

54 55 56 57 58
;; Are we running as a window application or on a TTY?
(defsubst ediff-device-type ()
  (if ediff-emacs-p
      window-system
    (device-type (selected-device))))
Michael Kifer's avatar
Michael Kifer committed
59

60
;; in XEmacs: device-type is tty on tty and stream in batch.
Michael Kifer's avatar
Michael Kifer committed
61 62 63 64 65 66 67
(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)
68 69
	((ediff-color-display-p))
	(ediff-emacs-p (memq (ediff-device-type) '(pc)))
Michael Kifer's avatar
Michael Kifer committed
70
	(ediff-xemacs-p (memq (ediff-device-type) '(tty pc)))))
Michael Kifer's avatar
Michael Kifer committed
71

Michael Kifer's avatar
Michael Kifer committed
72 73 74 75 76 77 78 79 80 81
(defun ediff-has-toolbar-support-p ()
  (and ediff-xemacs-p
       (featurep 'toolbar)
       (console-on-window-system-p)))

(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 ?

82
;; Defines SYMBOL as an advertised local variable.
Michael Kifer's avatar
Michael Kifer committed
83 84 85 86
;; 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.
87
;;
Michael Kifer's avatar
Michael Kifer committed
88
;; Plagiarised from `emerge-defvar-local' for XEmacs.
89
(defmacro ediff-defvar-local (var value doc)
Michael Kifer's avatar
Michael Kifer committed
90 91 92 93
  `(progn
     (defvar ,var ,value ,doc)
     (make-variable-buffer-local ',var)
     (put ',var 'permanent-local t)))
94

Michael Kifer's avatar
Michael Kifer committed
95 96 97 98 99 100 101 102 103


;; 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
104
;; The buffer in which the C variant is stored or where the merge buffer lives.
Michael Kifer's avatar
Michael Kifer committed
105 106 107
(ediff-defvar-local ediff-buffer-C nil "")
;; Ancestor buffer
(ediff-defvar-local ediff-ancestor-buffer nil "")
Michael Kifer's avatar
Michael Kifer committed
108
;; The Ediff control buffer
Michael Kifer's avatar
Michael Kifer committed
109
(ediff-defvar-local ediff-control-buffer nil "")
Karl Heuer's avatar
Karl Heuer committed
110

Michael Kifer's avatar
Michael Kifer committed
111 112 113 114 115 116 117

;; 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
118 119
;;; Macros
(defmacro ediff-odd-p (arg)
Michael Kifer's avatar
Michael Kifer committed
120
  `(eq (logand ,arg 1) 1))
Karl Heuer's avatar
Karl Heuer committed
121 122

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

(defmacro ediff-get-buffer (arg)
Michael Kifer's avatar
Michael Kifer committed
126 127 128 129 130
  `(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)
	 ))
131

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

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

Michael Kifer's avatar
Michael Kifer committed
144

Michael Kifer's avatar
Michael Kifer committed
145 146
;; 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
147 148
;; 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
149 150
(defsubst ediff-get-symbol-from-alist (buf-type alist)
  (cdr (assoc buf-type alist)))
151

Michael Kifer's avatar
Michael Kifer committed
152 153 154 155 156 157
(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
158
(defmacro ediff-get-difference (n buf-type)
Michael Kifer's avatar
Michael Kifer committed
159 160 161 162 163
  `(aref
    (symbol-value
     (ediff-get-symbol-from-alist
      ,buf-type ediff-difference-vector-alist))
    ,n))
164

Michael Kifer's avatar
Michael Kifer committed
165
;; Tell if it has been previously determined that the region has
Karl Heuer's avatar
Karl Heuer committed
166 167
;; 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
168
;; diff vector.  It is 1 less than the number seen by the user.
Michael Kifer's avatar
Michael Kifer committed
169 170 171 172 173 174 175 176
;; 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
177
;;
Michael Kifer's avatar
Michael Kifer committed
178
;; A Difference Vector has the form:
Karl Heuer's avatar
Karl Heuer committed
179 180
;; [diff diff diff ...]
;; where each diff has the form:
Michael Kifer's avatar
Michael Kifer committed
181
;; [overlay fine-diff-vector no-fine-diffs-flag state-of-difference]
Karl Heuer's avatar
Karl Heuer committed
182
;; fine-diff-vector is a vector [fine-diff fine-diff fine-diff ...]
Michael Kifer's avatar
Michael Kifer committed
183 184 185
;; 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
186
(defmacro ediff-no-fine-diffs-p (n)
Michael Kifer's avatar
Michael Kifer committed
187
  `(aref (ediff-get-difference ,n 'A) 2))
188

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

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

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

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

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

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

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

219
;; if flag is t, puts a mark on diff region saying that
Michael Kifer's avatar
Michael Kifer committed
220
;; the differences are in white space only.  If flag is nil,
Karl Heuer's avatar
Karl Heuer committed
221 222 223
;; 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
224
  `(aset (ediff-get-difference ,n 'A) 2 ,flag))
225

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

Michael Kifer's avatar
Michael Kifer committed
230 231 232 233
;; 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)
Michael Kifer's avatar
Michael Kifer committed
234
  `(if (ediff-buffer-live-p ,buffer)
Michael Kifer's avatar
Michael Kifer committed
235
       (save-current-buffer
Michael Kifer's avatar
Michael Kifer committed
236 237
	 (set-buffer ,buffer)
	 ,@body)
Michael Kifer's avatar
Michael Kifer committed
238 239
     (or (eq this-command 'ediff-quit)
	 (error ediff-KILLED-VITAL-BUFFER))
Michael Kifer's avatar
Michael Kifer committed
240
     ))
241

Karl Heuer's avatar
Karl Heuer committed
242

243 244
(defsubst ediff-multiframe-setup-p ()
  (and (ediff-window-display-p) ediff-multiframe))
245

Karl Heuer's avatar
Karl Heuer committed
246
(defmacro ediff-narrow-control-frame-p ()
Michael Kifer's avatar
Michael Kifer committed
247 248
  `(and (ediff-multiframe-setup-p)
	(equal ediff-help-message ediff-brief-message-string)))
249

Karl Heuer's avatar
Karl Heuer committed
250
(defmacro ediff-3way-comparison-job ()
Michael Kifer's avatar
Michael Kifer committed
251 252 253
  `(memq
    ediff-job-name
    '(ediff-files3 ediff-buffers3)))
Karl Heuer's avatar
Karl Heuer committed
254
(ediff-defvar-local ediff-3way-comparison-job nil "")
255

Karl Heuer's avatar
Karl Heuer committed
256
(defmacro ediff-merge-job ()
Michael Kifer's avatar
Michael Kifer committed
257 258 259 260 261 262 263 264
  `(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
265 266 267
(ediff-defvar-local ediff-merge-job nil "")

(defmacro ediff-merge-with-ancestor-job ()
Michael Kifer's avatar
Michael Kifer committed
268 269 270 271 272
  `(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
273 274 275
(ediff-defvar-local ediff-merge-with-ancestor-job nil "")

(defmacro ediff-3way-job ()
Michael Kifer's avatar
Michael Kifer committed
276
  `(or ediff-3way-comparison-job ediff-merge-job))
Karl Heuer's avatar
Karl Heuer committed
277 278 279 280 281
(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
282 283
  `(or ediff-3way-comparison-job
       ediff-merge-with-ancestor-job))
Karl Heuer's avatar
Karl Heuer committed
284
(ediff-defvar-local ediff-diff3-job nil "")
285

286
(defmacro ediff-windows-job ()
Michael Kifer's avatar
Michael Kifer committed
287
  `(memq ediff-job-name '(ediff-windows-wordwise ediff-windows-linewise)))
288 289
(ediff-defvar-local ediff-windows-job nil "")

Karl Heuer's avatar
Karl Heuer committed
290
(defmacro ediff-word-mode-job ()
Michael Kifer's avatar
Michael Kifer committed
291
  `(memq ediff-job-name '(ediff-windows-wordwise ediff-regions-wordwise)))
Karl Heuer's avatar
Karl Heuer committed
292 293
(ediff-defvar-local ediff-word-mode-job nil "")

294
(defmacro ediff-narrow-job ()
Michael Kifer's avatar
Michael Kifer committed
295 296 297 298
  `(memq ediff-job-name '(ediff-windows-wordwise
			  ediff-regions-wordwise
			  ediff-windows-linewise
			  ediff-regions-linewise)))
299 300
(ediff-defvar-local ediff-narrow-job nil "")

301 302 303 304 305 306 307 308
;; 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)
309
	'(ediff-directory-revisions
310 311
	  ediff-merge-directory-revisions
	  ediff-merge-directory-revisions-with-ancestor)))
Michael Kifer's avatar
Michael Kifer committed
312 313 314 315 316 317
(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)
318
  (or (ediff-revision-metajob metajob)
Michael Kifer's avatar
Michael Kifer committed
319
      (ediff-patch-metajob metajob)
320 321 322
      ;; add more here
      ))
(defsubst ediff-collect-diffs-metajob (&optional metajob)
Michael Kifer's avatar
Michael Kifer committed
323 324 325 326 327 328 329 330 331
  (memq (or metajob ediff-metajob-name)
	'(ediff-directories
	  ediff-directory-revisions
	  ediff-merge-directories
	  ediff-merge-directories-with-ancestor
	  ediff-merge-directory-revisions
	  ediff-merge-directory-revisions-with-ancestor
	  ;; add more here
	  )))
Michael Kifer's avatar
Michael Kifer committed
332 333 334 335 336 337
(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
338
	  ediff-merge-filegroups-with-ancestor
Michael Kifer's avatar
Michael Kifer committed
339 340
	  ;; add more here
	  )))
Michael Kifer's avatar
Michael Kifer committed
341

342 343 344
(defsubst ediff-metajob3 (&optional metajob)
  (memq (or metajob ediff-metajob-name)
	'(ediff-merge-directories-with-ancestor
345
	  ediff-merge-filegroups-with-ancestor
346 347 348 349 350 351
	  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
352 353 354 355 356 357 358 359 360
;; 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)
361 362 363
      (error "%S: This command runs in Ediff Control Buffer only!"
	     this-command)))

Michael Kifer's avatar
Michael Kifer committed
364 365 366 367 368 369 370 371 372 373 374
(defgroup ediff-highlighting nil
  "Hilighting of difference regions in Ediff"
  :prefix "ediff-"
  :group 'ediff)

(defgroup ediff-merge nil
  "Merging utilities"
  :prefix "ediff-"
  :group 'ediff)

(defgroup ediff-hook nil
375
  "Hooks run by Ediff"
Michael Kifer's avatar
Michael Kifer committed
376 377 378
  :prefix "ediff-"
  :group 'ediff)

Karl Heuer's avatar
Karl Heuer committed
379 380
;; Hook variables

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

Michael Kifer's avatar
Michael Kifer committed
432
(defcustom ediff-mode-hook nil
433
  "*Hook run just after ediff-mode is set up in the control buffer.
Michael Kifer's avatar
Michael Kifer committed
434
This is done before any windows or frames are created.  One can use it to
Michael Kifer's avatar
Michael Kifer committed
435 436
set local variables that determine how the display looks like."
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
437
  :group 'ediff-hook)
Michael Kifer's avatar
Michael Kifer committed
438 439 440
(defcustom ediff-keymap-setup-hook nil
  "*Hook run just after the default bindings in Ediff keymap are set up."
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
441
  :group 'ediff-hook)
442

Michael Kifer's avatar
Michael Kifer committed
443 444 445
(defcustom ediff-display-help-hook nil
  "*Hooks run after preparing the help message."
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
446
  :group 'ediff-hook)
Michael Kifer's avatar
Michael Kifer committed
447

448
(defcustom ediff-suspend-hook nil
Michael Kifer's avatar
Michael Kifer committed
449 450
  "*Hooks to run in the Ediff control buffer when Ediff is suspended."
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
451
  :group 'ediff-hook)
452
(defcustom ediff-quit-hook nil
Michael Kifer's avatar
Michael Kifer committed
453 454
  "*Hooks to run in the Ediff control buffer after finishing Ediff."
  :type 'hook
455
  :group 'ediff-hook)
Michael Kifer's avatar
Michael Kifer committed
456
(defcustom ediff-cleanup-hook nil
Michael Kifer's avatar
Michael Kifer committed
457
  "*Hooks to run on exiting Ediff but before killing the control and variant buffers."
Michael Kifer's avatar
Michael Kifer committed
458
  :type 'hook
Michael Kifer's avatar
Michael Kifer committed
459
  :group 'ediff-hook)
Karl Heuer's avatar
Karl Heuer committed
460

Michael Kifer's avatar
Michael Kifer committed
461 462 463 464
;; 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
465 466 467
  "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
468
  "%S: Bad diff region number, %d.  Valid numbers are 1 to %d")
Michael Kifer's avatar
Michael Kifer committed
469 470 471
(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.
472
***
Michael Kifer's avatar
Michael Kifer committed
473 474
*** Please contact your system administrator. "
				 (if ediff-xemacs-p "X" "")))
475

Karl Heuer's avatar
Karl Heuer committed
476 477 478 479 480
;; 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
481 482
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
483 484
by the user.")

485
(ediff-defvar-local ediff-hide-regexp-matches-function
486
  'ediff-hide-regexp-matches
487 488 489 490 491 492 493
  "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
494 495 496 497 498 499 500 501 502
;; 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 "")
503

Karl Heuer's avatar
Karl Heuer committed
504 505 506 507 508 509 510 511 512
;; 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
513

514 515 516 517

;;; Copying difference regions between buffers.

;; A list of killed diffs.
Michael Kifer's avatar
Michael Kifer committed
518 519 520 521 522
;; 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
523

524 525 526 527 528
;; 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
529 530

;; Highlighting
Michael Kifer's avatar
Michael Kifer committed
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
(defcustom ediff-before-flag-bol (if ediff-xemacs-p (make-glyph "->>") "->>")
  "*Flag placed before a highlighted block of differences, if block starts at beginning of a line."
  :type 'string
  :tag  "Region before-flag at beginning of line"
  :group 'ediff)

(defcustom ediff-after-flag-eol  (if ediff-xemacs-p (make-glyph "<<-") "<<-")
  "*Flag placed after a highlighted block of differences, if block ends at end of a line."
  :type 'string
  :tag  "Region after-flag at end of line"
  :group 'ediff)

(defcustom ediff-before-flag-mol (if ediff-xemacs-p (make-glyph "->>") "->>")
  "*Flag placed before a highlighted block of differences, if block starts in mid-line."
  :type 'string
  :tag  "Region before-flag in the middle of line"
  :group 'ediff)
(defcustom ediff-after-flag-mol  (if ediff-xemacs-p (make-glyph "<<-") "<<-")
  "*Flag placed after a highlighted block of differences, if block ends in mid-line."
  :type 'string
  :tag  "Region after-flag in the middle of line"
  :group 'ediff)
Karl Heuer's avatar
Karl Heuer committed
553

554 555 556

(ediff-defvar-local ediff-use-faces t "")
(defcustom ediff-use-faces t
Michael Kifer's avatar
Michael Kifer committed
557 558
  "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
559
and ediff-after-flag.  On a non-window system, differences are always
Michael Kifer's avatar
Michael Kifer committed
560 561 562
highlighted using ASCII flags."
  :type 'boolean
  :group 'ediff-highlighting)
Karl Heuer's avatar
Karl Heuer committed
563 564

;; this indicates that diff regions are word-size, so fine diffs are
565
;; permanently nixed; used in ediff-windows-wordwise and ediff-regions-wordwise
Karl Heuer's avatar
Karl Heuer committed
566
(ediff-defvar-local ediff-word-mode nil "")
567
;; Name of the job (ediff-files, ediff-windows, etc.)
Karl Heuer's avatar
Karl Heuer committed
568 569 570 571 572 573 574 575 576 577 578 579 580
(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
581
;; This is also a list of overlays.  When the user toggles narrow/widen,
Karl Heuer's avatar
Karl Heuer committed
582 583 584 585 586
;; 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
587
  "Non-nil means start narrowed, if doing ediff-windows-* or ediff-regions-*")
Karl Heuer's avatar
Karl Heuer committed
588 589 590
(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
591 592 593

(defcustom ediff-keep-variants t
  "*Nil means that non-modified variant buffers should be removed at the end of the session after some interrogation.
Karl Heuer's avatar
Karl Heuer committed
594
Supplying a prefix argument to the quit command `q' temporarily reverses the
Michael Kifer's avatar
Michael Kifer committed
595 596 597
meaning of this variable."
  :type 'boolean
  :group 'ediff)
Karl Heuer's avatar
Karl Heuer committed
598

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

;; A var local to each control panel buffer.  Indicates highlighting style
;; in effect for this buffer: `face', `ascii', nil -- temporarily
;; unhighlighted, `off' -- turned off \(on a dumb terminal only\).
(ediff-defvar-local ediff-highlighting-style nil "")

612

Karl Heuer's avatar
Karl Heuer committed
613 614
;; The suffix of the control buffer name.
(ediff-defvar-local ediff-control-buffer-suffix nil "")
615
;; Same as ediff-control-buffer-suffix, but without <,>.
Karl Heuer's avatar
Karl Heuer committed
616 617 618 619 620
;; 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
621
(ediff-defvar-local ediff-buffer-values-orig-A nil "")
Karl Heuer's avatar
Karl Heuer committed
622
;; The original values of ediff-protected-variables for buffer B
623
(ediff-defvar-local ediff-buffer-values-orig-B nil "")
Karl Heuer's avatar
Karl Heuer committed
624
;; The original values of ediff-protected-variables for buffer C
625
(ediff-defvar-local ediff-buffer-values-orig-C nil "")
626 627
;; 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
628

Michael Kifer's avatar
Michael Kifer committed
629 630 631 632 633 634 635
;; 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
636
;; Buffer-local variables to be saved then restored during Ediff sessions
Michael Kifer's avatar
Michael Kifer committed
637
(defconst ediff-protected-variables '(
638
				      ;;buffer-read-only
Karl Heuer's avatar
Karl Heuer committed
639 640 641 642 643 644
				      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
645
;; the B buffer.  If a difference section is empty, the corresponding
Karl Heuer's avatar
Karl Heuer committed
646 647
;; overlay's endpoints coincide.
;;
Michael Kifer's avatar
Michael Kifer committed
648
;; The precise form of a Difference Vector for one buffer is:
Karl Heuer's avatar
Karl Heuer committed
649 650
;; [diff diff diff ...]
;; where each diff has the form:
Michael Kifer's avatar
Michael Kifer committed
651
;; [diff-overlay fine-diff-vector no-fine-diffs-flag state-of-diff]
Karl Heuer's avatar
Karl Heuer committed
652 653 654
;; 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
655
;;	different from the other two (used only in 3-way jobs.
Karl Heuer's avatar
Karl Heuer committed
656 657 658
(ediff-defvar-local ediff-difference-vector-A nil "")
(ediff-defvar-local ediff-difference-vector-B nil "")
(ediff-defvar-local ediff-difference-vector-C nil "")
659
(ediff-defvar-local ediff-difference-vector-Ancestor nil "")
Michael Kifer's avatar
Michael Kifer committed
660 661 662 663 664 665
;; 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)))
666 667 668

;; [ status status status ...]
;; Each status: [state-of-merge state-of-ancestor]
Michael Kifer's avatar
Michael Kifer committed
669
;; state-of-merge is default-A, default-B, prefer-A, or prefer-B.  It
670 671 672 673
;; 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
674 675 676 677 678

;; 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 "")
679

Karl Heuer's avatar
Karl Heuer committed
680 681 682
;; 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
683
;; Like ediff-diff-buffer, but contains context diff.  It is not used by
Karl Heuer's avatar
Karl Heuer committed
684 685 686 687 688 689 690 691 692 693 694 695 696
;; 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*" "")

697 698 699
;; 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
700 701 702 703

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

Karl Heuer's avatar
Karl Heuer committed
705 706 707
;; Priority of non-selected overlays.
(defvar ediff-shadow-overlay-priority  100 "")

Michael Kifer's avatar
Michael Kifer committed
708
(defcustom ediff-version-control-package 'vc
709
  "Version control package used.
Michael Kifer's avatar
Michael Kifer committed
710 711 712
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
713 714 715
appropriate symbol: `rcs', `pcl-cvs', or `generic-sc' if you so desire."
  :type 'symbol
  :group 'ediff)
716

717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
(defcustom ediff-coding-system-for-read 'raw-text
  "*The coding system for read to use when running the diff program as a subprocess. 
In most cases, the default will do. However, under certain circumstances in
Windows NT/98/95 you might need to use something like 'raw-text-dos here.
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)

(defcustom ediff-coding-system-for-write 'no-conversion
  "*The coding system for write to use when writing out difference regions
to temp files when Ediff needs to find fine differences."
  :type 'symbol
  :group 'ediff)

Karl Heuer's avatar
Karl Heuer committed
733 734 735 736 737 738

(if ediff-xemacs-p
    (progn
      (fset 'ediff-read-event (symbol-function 'next-command-event))
      (fset 'ediff-overlayp (symbol-function 'extentp))
      (fset 'ediff-make-overlay (symbol-function 'make-extent))
Michael Kifer's avatar
Michael Kifer committed
739
      (fset 'ediff-delete-overlay (symbol-function 'delete-extent)))
Karl Heuer's avatar
Karl Heuer committed
740 741 742
  (fset 'ediff-read-event (symbol-function 'read-event))
  (fset 'ediff-overlayp (symbol-function 'overlayp))
  (fset 'ediff-make-overlay (symbol-function 'make-overlay))
Michael Kifer's avatar
Michael Kifer committed
743
  (fset 'ediff-delete-overlay (symbol-function 'delete-overlay)))
744

745 746 747 748 749 750 751
;; Check the current version against the major and minor version numbers
;; using op: cur-vers op major.minor If emacs-major-version or
;; emacs-minor-version are not defined, we assume that the current version
;; is hopelessly outdated.  We assume that emacs-major-version and
;; emacs-minor-version are defined.  Otherwise, for Emacs/XEmacs 19, if the
;; current minor version is < 10 (xemacs) or < 23 (emacs) the return value
;; will be nil (when op is =, >, or >=) and t (when op is <, <=), which may be
Michael Kifer's avatar
Michael Kifer committed
752
;; incorrect.  However, this gives correct result in our cases, since we are
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
;; testing for sufficiently high Emacs versions.
(defun ediff-check-version (op major minor &optional type-of-emacs)
  (if (and (boundp 'emacs-major-version) (boundp 'emacs-minor-version))
      (and (cond ((eq type-of-emacs 'xemacs) ediff-xemacs-p)
		 ((eq type-of-emacs 'emacs) ediff-emacs-p)
		 (t 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))))
    (cond ((memq op '(= > >=)) nil)
	  ((memq op '(< <=)) t))))
771 772


773 774 775 776 777 778 779 780 781
(defun ediff-color-display-p ()
  (condition-case nil
      (if ediff-emacs-p
	  (if (fboundp 'display-color-p)
	      (display-color-p)
	    (x-display-color-p))
	(eq (device-class (selected-device)) 'color))
    (error
     nil)))
782

783

Michael Kifer's avatar
Michael Kifer committed
784
(if (ediff-has-face-support-p)
785 786 787 788
    (if ediff-xemacs-p
	(progn
	  (fset 'ediff-valid-color-p (symbol-function 'valid-color-name-p))
	  (fset 'ediff-get-face (symbol-function 'get-face)))
789 790 791 792
      (fset 'ediff-valid-color-p (symbol-function
				  (if (fboundp 'color-defined-p)
				      'color-defined-p
				    'x-color-defined-p)))
793
      (fset 'ediff-get-face (symbol-function 'internal-get-face))))
Michael Kifer's avatar
Michael Kifer committed
794 795 796 797 798 799 800 801

(if (ediff-window-display-p)
    (if ediff-xemacs-p
	(progn
	  (fset 'ediff-display-pixel-width
		(symbol-function 'device-pixel-width))
	  (fset 'ediff-display-pixel-height
		(symbol-function 'device-pixel-height)))
802 803 804 805 806 807 808 809
      (fset 'ediff-display-pixel-width (symbol-function
					(if (fboundp 'display-pixel-width)
					    'display-pixel-width
					  'x-display-pixel-width)))
      (fset 'ediff-display-pixel-height (symbol-function
					 (if (fboundp 'display-pixel-height)
					     'display-pixel-height
					   'x-display-pixel-height)))))
810

811
;; A-list of current-diff-overlay symbols associated with buf types
Michael Kifer's avatar
Michael Kifer committed
812 813 814 815 816
(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)))
817

818
;; A-list of current-diff-face-* symbols associated with buf types
Michael Kifer's avatar
Michael Kifer committed
819 820 821 822 823
(defconst ediff-current-diff-face-alist
  '((A . ediff-current-diff-face-A)
    (B . ediff-current-diff-face-B)
    (C . ediff-current-diff-face-C)
    (Ancestor . ediff-current-diff-face-Ancestor)))
824

Karl Heuer's avatar
Karl Heuer committed
825

826
(defun ediff-make-current-diff-overlay (type)
Michael Kifer's avatar
Michael Kifer committed
827
  (if (ediff-has-face-support-p)
Michael Kifer's avatar
Michael Kifer committed
828 829
      (let ((overlay (ediff-get-symbol-from-alist
		      type ediff-current-diff-overlay-alist))
830 831 832
	    (buffer (ediff-get-buffer type))
	    (face (face-name
		   (symbol-value
Michael Kifer's avatar
Michael Kifer committed
833 834
		    (ediff-get-symbol-from-alist
		     type ediff-current-diff-face-alist)))))
835 836 837 838 839 840 841 842 843
	(set overlay
	     (ediff-make-bullet-proof-overlay (point-max) (point-max) buffer))
	(ediff-set-overlay-face (symbol-value overlay) face)
	(ediff-overlay-put (symbol-value overlay) 'ediff ediff-control-buffer))
    ))

(defun ediff-set-overlay-face (extent face)
  (ediff-overlay-put extent 'face face)
  (ediff-overlay-put extent 'help-echo 'ediff-region-help-echo))
844

845 846 847 848 849
(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))
850 851
	(diff-num (ediff-overlay-get overlay 'ediff-diff-num))
	face-help)
852 853

    ;; This happens only for refinement overlays
854 855
    (if (stringp face)
	(setq face (intern face)))
856 857
    (setq face-help (and face (get face 'ediff-help-echo)))

858
    (cond ((and is-current diff-num)	; current diff region
Michael Kifer's avatar
Michael Kifer committed
859
	   (format "Difference region %S -- current" (1+ diff-num)))
860
	  (face-help)			; refinement of current diff region
861
	  (diff-num			; non-current
Michael Kifer's avatar
Michael Kifer committed
862
	   (format "Difference region %S -- non-current" (1+ diff-num)))
863
	  (t ""))			; none
Dave Love's avatar
Dave Love committed
864
    ))
865

866

Michael Kifer's avatar
Michael Kifer committed
867 868 869 870 871 872 873 874 875
(defun ediff-set-face-pixmap (face pixmap)
  "Set face pixmap on a monochrome display."
  (if (and (ediff-window-display-p) (not (ediff-color-display-p)))
      (condition-case nil
	  (set-face-background-pixmap face pixmap)
	(error
	 (message "Pixmap not found for %S: %s" (face-name face) pixmap)
	 (sit-for 1)))))

Michael Kifer's avatar
Michael Kifer committed
876 877 878
(defun ediff-hide-face (face)
  (if (and (ediff-has-face-support-p) ediff-emacs-p)
      (add-to-list 'facemenu-unlisted-faces face)))
879

Karl Heuer's avatar
Karl Heuer committed
880

Michael Kifer's avatar
Michael Kifer committed
881 882 883 884 885 886

(defface ediff-current-diff-face-A
  '((((class color)) (:foreground "firebrick" :background "pale green"))
    (t (:inverse-video t)))
  "Face for highlighting the selected difference in buffer A."
  :group 'ediff-highlighting)
Michael Kifer's avatar
Michael Kifer committed
887
;; An internal variable.  Ediff takes the face from here.  When unhighlighting,
Michael Kifer's avatar
Michael Kifer committed
888
;; this variable is set to nil, then again to the appropriate face.
Michael Kifer's avatar
Michael Kifer committed
889 890
(defvar ediff-current-diff-face-A 'ediff-current-diff-face-A
  "Face for highlighting the selected difference in buffer A.
Michael Kifer's avatar
Michael Kifer committed
891
DO NOT CHANGE this variable.  Instead, use the customization
Michael Kifer's avatar
Michael Kifer committed
892 893
widget to customize the actual face object `ediff-current-diff-face-A'
this variable represents.")
Michael Kifer's avatar
Michael Kifer committed
894 895 896 897 898
(ediff-hide-face 'ediff-current-diff-face-A)
;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
;; This means that some user customization may be trashed.
(if (and ediff-xemacs-p
	 (ediff-has-face-support-p)
899
	 (not (ediff-color-display-p)))
Michael Kifer's avatar
Michael Kifer committed
900 901 902 903 904 905 906 907 908
    (copy-face 'modeline 'ediff-current-diff-face-A))



(defface ediff-current-diff-face-B
  '((((class color)) (:foreground "DarkOrchid" :background "Yellow"))
    (t (:inverse-video t)))
  "Face for highlighting the selected difference in buffer B."
  :group 'ediff-highlighting)
Michael Kifer's avatar
Michael Kifer committed
909
;; An internal variable.  Ediff takes the face from here.  When unhighlighting,
Michael Kifer's avatar
Michael Kifer committed
910
;; this variable is set to nil, then again to the appropriate face.
Michael Kifer's avatar
Michael Kifer committed
911 912
(defvar ediff-current-diff-face-B 'ediff-current-diff-face-B
  "Face for highlighting the selected difference in buffer B.
Michael Kifer's avatar
Michael Kifer committed
913
 this variable.  Instead, use the customization
Michael Kifer's avatar
Michael Kifer committed
914 915
widget to customize the actual face `ediff-current-diff-face-B'
this variable represents.")
Michael Kifer's avatar
Michael Kifer committed
916 917 918 919 920
(ediff-hide-face 'ediff-current-diff-face-B)
;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
;; This means that some user customization may be trashed.
(if (and ediff-xemacs-p
	 (ediff-has-face-support-p)
921
	 (not (ediff-color-display-p)))
Michael Kifer's avatar
Michael Kifer committed
922 923 924 925 926 927 928 929
    (copy-face 'modeline 'ediff-current-diff-face-B))


(defface ediff-current-diff-face-C
  '((((class color)) (:foreground "Navy" :background "Pink"))
    (t (:inverse-video t)))
  "Face for highlighting the selected difference in buffer C."
  :group 'ediff-highlighting)
Michael Kifer's avatar
Michael Kifer committed
930
;; An internal variable.  Ediff takes the face from here.  When unhighlighting,
Michael Kifer's avatar
Michael Kifer committed
931
;; this variable is set to nil, then again to the appropriate face.
Michael Kifer's avatar
Michael Kifer committed
932 933
(defvar ediff-current-diff-face-C 'ediff-current-diff-face-C
  "Face for highlighting the selected difference in buffer C.
Michael Kifer's avatar
Michael Kifer committed
934
DO NOT CHANGE this variable.  Instead, use the customization
Michael Kifer's avatar
Michael Kifer committed
935 936
widget to customize the actual face object `ediff-current-diff-face-C'
this variable represents.")
Michael Kifer's avatar
Michael Kifer committed
937 938 939 940 941
(ediff-hide-face 'ediff-current-diff-face-C)
;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
;; This means that some user customization may be trashed.
(if (and ediff-xemacs-p
	 (ediff-has-face-support-p)
942
	 (not (ediff-color-display-p)))