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