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