(read_minibuf): Clean up the binding stack if
[bpt/emacs.git] / 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 nil
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 nil
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 (add-hook 'ediff-quit-hook 'ediff-cleanup-mess)
1156 (add-hook 'ediff-suspend-hook 'ediff-default-suspend-function)
1157
1158
1159 ;;; Overlays
1160
1161 (ediff-defvar-local ediff-current-diff-overlay-A nil
1162 "Overlay for the current difference region in buffer A.")
1163 (ediff-defvar-local ediff-current-diff-overlay-B nil
1164 "Overlay for the current difference region in buffer B.")
1165 (ediff-defvar-local ediff-current-diff-overlay-C nil
1166 "Overlay for the current difference region in buffer C.")
1167 (ediff-defvar-local ediff-current-diff-overlay-Ancestor nil
1168 "Overlay for the current difference region in the ancestor buffer.")
1169
1170 ;; Compute priority of ediff overlay.
1171 (defun ediff-highest-priority (start end buffer)
1172 (let ((pos (max 1 (1- start)))
1173 ovr-list)
1174 (if ediff-xemacs-p
1175 (1+ ediff-shadow-overlay-priority)
1176 (ediff-with-current-buffer buffer
1177 (while (< pos (min (point-max) (1+ end)))
1178 (setq ovr-list (append (overlays-at pos) ovr-list))
1179 (setq pos (next-overlay-change pos)))
1180 (1+ (apply '+
1181 (mapcar (lambda (ovr)
1182 (if ovr
1183 (or (ediff-overlay-get ovr 'priority) 0)
1184 0))
1185 ovr-list)
1186 ))
1187 ))))
1188
1189
1190 (defvar ediff-toggle-read-only-function nil
1191 "*Specifies the function to be used to toggle read-only.
1192 If nil, Ediff tries to deduce the function from the binding of C-x C-q.
1193 Normally, this is the `toggle-read-only' function, but, if version
1194 control is used, it could be `vc-toggle-read-only' or `rcs-toggle-read-only'.")
1195
1196 (defcustom ediff-make-buffers-readonly-at-startup nil
1197 "*Make all variant buffers read-only when Ediff starts up.
1198 This property can be toggled interactively."
1199 :type 'boolean
1200 :group 'ediff)
1201
1202
1203 ;;; Misc
1204
1205 ;; if nil, this silences some messages
1206 (defconst ediff-verbose-p t)
1207
1208 (defcustom ediff-autostore-merges 'group-jobs-only
1209 "*Save the results of merge jobs automatically.
1210 Nil means don't save automatically. t means always save. Anything but nil or t
1211 means save automatically only if the merge job is part of a group of jobs, such
1212 as `ediff-merge-directory' or `ediff-merge-directory-revisions'."
1213 :type '(choice (const nil) (const t) (const group-jobs-only))
1214 :group 'ediff-merge)
1215 (make-variable-buffer-local 'ediff-autostore-merges)
1216
1217 ;; file where the result of the merge is to be saved. used internally
1218 (ediff-defvar-local ediff-merge-store-file nil "")
1219
1220 (defcustom ediff-merge-filename-prefix "merge_"
1221 "*Prefix to be attached to saved merge buffers."
1222 :type 'string
1223 :group 'ediff-merge)
1224
1225 (defcustom ediff-no-emacs-help-in-control-buffer nil
1226 "*Non-nil means C-h should not invoke Emacs help in control buffer.
1227 Instead, C-h would jump to previous difference."
1228 :type 'boolean
1229 :group 'ediff)
1230
1231 ;; This is the same as temporary-file-directory from Emacs 20.3.
1232 ;; Copied over here because XEmacs doesn't have this variable.
1233 (defcustom ediff-temp-file-prefix
1234 (file-name-as-directory
1235 (cond ((boundp 'temporary-file-directory) temporary-file-directory)
1236 ((fboundp 'temp-directory) (temp-directory))
1237 (t "/tmp/")))
1238 ;;; (file-name-as-directory
1239 ;;; (cond ((memq system-type '(ms-dos windows-nt))
1240 ;;; (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
1241 ;;; ((memq system-type '(vax-vms axp-vms))
1242 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
1243 ;;; (t
1244 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))
1245 "*Prefix to put on Ediff temporary file names.
1246 Do not start with `~/' or `~USERNAME/'."
1247 :type 'string
1248 :group 'ediff)
1249
1250 (defcustom ediff-temp-file-mode 384 ; u=rw only
1251 "*Mode for Ediff temporary files."
1252 :type 'integer
1253 :group 'ediff)
1254
1255 ;; Metacharacters that have to be protected from the shell when executing
1256 ;; a diff/diff3 command.
1257 (defcustom ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
1258 "Regexp that matches characters that must be quoted with `\\' in shell command line.
1259 This default should work without changes."
1260 :type 'string
1261 :group 'ediff)
1262
1263 ;; needed to simulate frame-char-width in XEmacs.
1264 (defvar ediff-H-glyph (if ediff-xemacs-p (make-glyph "H")))
1265
1266
1267 ;; Temporary file used for refining difference regions in buffer A.
1268 (ediff-defvar-local ediff-temp-file-A nil "")
1269 ;; Temporary file used for refining difference regions in buffer B.
1270 (ediff-defvar-local ediff-temp-file-B nil "")
1271 ;; Temporary file used for refining difference regions in buffer C.
1272 (ediff-defvar-local ediff-temp-file-C nil "")
1273
1274
1275 ;;; In-line functions
1276
1277 (or (fboundp 'ediff-file-remote-p) ; user supplied his own function: use it
1278 (defun ediff-file-remote-p (file-name)
1279 (find-file-name-handler file-name 'file-local-copy)))
1280 ;;; (or (and (featurep 'efs-auto) (efs-ftp-path file-name))
1281 ;;; (and (featurep 'tramp) (tramp-tramp-file-p file-name))
1282 ;;; (and (fboundp 'file-remote-p) (file-remote-p file-name))
1283 ;;; ;; Can happen only in Emacs, since XEmacs has file-remote-p
1284 ;;; (and (require 'ange-ftp) (ange-ftp-ftp-name file-name)))))
1285
1286
1287 (defsubst ediff-frame-unsplittable-p (frame)
1288 (cdr (assq 'unsplittable (frame-parameters frame))))
1289
1290 (defsubst ediff-get-next-window (wind prev-wind)
1291 (or (window-live-p wind)
1292 (setq wind (if prev-wind
1293 (next-window wind)
1294 (selected-window)))))
1295
1296
1297 (defsubst ediff-kill-buffer-carefully (buf)
1298 "Kill buffer BUF if it exists."
1299 (if (ediff-buffer-live-p buf)
1300 (kill-buffer (get-buffer buf))))
1301
1302 (defsubst ediff-background-face (buf-type dif-num)
1303 ;; The value of dif-num is always 1- the one that user sees.
1304 ;; This is why even face is used when dif-num is odd.
1305 (ediff-get-symbol-from-alist
1306 buf-type (if (ediff-odd-p dif-num)
1307 ediff-even-diff-face-alist
1308 ediff-odd-diff-face-alist)
1309 ))
1310
1311
1312 ;; activate faces on diff regions in buffer
1313 (defun ediff-paint-background-regions-in-one-buffer (buf-type unhighlight)
1314 (let ((diff-vector
1315 (eval (ediff-get-symbol-from-alist
1316 buf-type ediff-difference-vector-alist)))
1317 overl diff-num)
1318 (mapcar (lambda (rec)
1319 (setq overl (ediff-get-diff-overlay-from-diff-record rec)
1320 diff-num (ediff-overlay-get overl 'ediff-diff-num))
1321 (if (ediff-overlay-buffer overl)
1322 ;; only if overlay is alive
1323 (ediff-set-overlay-face
1324 overl
1325 (if (not unhighlight)
1326 (ediff-background-face buf-type diff-num))))
1327 )
1328 diff-vector)))
1329
1330
1331 ;; activate faces on diff regions in all buffers
1332 (defun ediff-paint-background-regions (&optional unhighlight)
1333 (ediff-paint-background-regions-in-one-buffer
1334 'A unhighlight)
1335 (ediff-paint-background-regions-in-one-buffer
1336 'B unhighlight)
1337 (ediff-paint-background-regions-in-one-buffer
1338 'C unhighlight)
1339 (ediff-paint-background-regions-in-one-buffer
1340 'Ancestor unhighlight))
1341
1342 (defun ediff-highlight-diff-in-one-buffer (n buf-type)
1343 (if (ediff-buffer-live-p (ediff-get-buffer buf-type))
1344 (let* ((buff (ediff-get-buffer buf-type))
1345 (last (ediff-with-current-buffer buff (point-max)))
1346 (begin (ediff-get-diff-posn buf-type 'beg n))
1347 (end (ediff-get-diff-posn buf-type 'end n))
1348 (xtra (if (equal begin end) 1 0))
1349 (end-hilit (min last (+ end xtra)))
1350 (current-diff-overlay
1351 (symbol-value
1352 (ediff-get-symbol-from-alist
1353 buf-type ediff-current-diff-overlay-alist))))
1354
1355 (if ediff-xemacs-p
1356 (ediff-move-overlay current-diff-overlay begin end-hilit)
1357 (ediff-move-overlay current-diff-overlay begin end-hilit buff))
1358 (ediff-overlay-put current-diff-overlay 'priority
1359 (ediff-highest-priority begin end-hilit buff))
1360 (ediff-overlay-put current-diff-overlay 'ediff-diff-num n)
1361
1362 ;; unhighlight the background overlay for diff n so it won't
1363 ;; interfere with the current diff overlay
1364 (ediff-set-overlay-face (ediff-get-diff-overlay n buf-type) nil)
1365 )))
1366
1367
1368 (defun ediff-unhighlight-diff-in-one-buffer (buf-type)
1369 (if (ediff-buffer-live-p (ediff-get-buffer buf-type))
1370 (let ((current-diff-overlay
1371 (symbol-value
1372 (ediff-get-symbol-from-alist
1373 buf-type ediff-current-diff-overlay-alist)))
1374 (overlay
1375 (ediff-get-diff-overlay ediff-current-difference buf-type))
1376 )
1377
1378 (ediff-move-overlay current-diff-overlay 1 1)
1379
1380 ;; rehighlight the overlay in the background of the
1381 ;; current difference region
1382 (ediff-set-overlay-face
1383 overlay
1384 (if (and (ediff-has-face-support-p)
1385 ediff-use-faces ediff-highlight-all-diffs)
1386 (ediff-background-face buf-type ediff-current-difference)))
1387 )))
1388
1389 (defun ediff-unhighlight-diffs-totally-in-one-buffer (buf-type)
1390 (ediff-unselect-and-select-difference -1)
1391 (if (and (ediff-has-face-support-p) ediff-use-faces)
1392 (let* ((inhibit-quit t)
1393 (current-diff-overlay-var
1394 (ediff-get-symbol-from-alist
1395 buf-type ediff-current-diff-overlay-alist))
1396 (current-diff-overlay (symbol-value current-diff-overlay-var)))
1397 (ediff-paint-background-regions 'unhighlight)
1398 (if (ediff-overlayp current-diff-overlay)
1399 (ediff-delete-overlay current-diff-overlay))
1400 (set current-diff-overlay-var nil)
1401 )))
1402
1403
1404 (defsubst ediff-highlight-diff (n)
1405 "Put face on diff N. Invoked for X displays only."
1406 (ediff-highlight-diff-in-one-buffer n 'A)
1407 (ediff-highlight-diff-in-one-buffer n 'B)
1408 (ediff-highlight-diff-in-one-buffer n 'C)
1409 (ediff-highlight-diff-in-one-buffer n 'Ancestor)
1410 )
1411
1412
1413 (defsubst ediff-unhighlight-diff ()
1414 "Remove overlays from buffers A, B, and C."
1415 (ediff-unhighlight-diff-in-one-buffer 'A)
1416 (ediff-unhighlight-diff-in-one-buffer 'B)
1417 (ediff-unhighlight-diff-in-one-buffer 'C)
1418 (ediff-unhighlight-diff-in-one-buffer 'Ancestor)
1419 )
1420
1421 ;; delete highlighting overlays, restore faces to their original form
1422 (defsubst ediff-unhighlight-diffs-totally ()
1423 (ediff-unhighlight-diffs-totally-in-one-buffer 'A)
1424 (ediff-unhighlight-diffs-totally-in-one-buffer 'B)
1425 (ediff-unhighlight-diffs-totally-in-one-buffer 'C)
1426 (ediff-unhighlight-diffs-totally-in-one-buffer 'Ancestor)
1427 )
1428
1429
1430 ;; arg is a record for a given diff in a difference vector
1431 ;; this record is itself a vector
1432 (defsubst ediff-clear-fine-diff-vector (diff-record)
1433 (if diff-record
1434 (mapcar 'ediff-delete-overlay
1435 (ediff-get-fine-diff-vector-from-diff-record diff-record))))
1436
1437 (defsubst ediff-clear-fine-differences-in-one-buffer (n buf-type)
1438 (ediff-clear-fine-diff-vector (ediff-get-difference n buf-type))
1439 (ediff-set-fine-diff-vector n buf-type nil))
1440
1441 (defsubst ediff-clear-fine-differences (n)
1442 (ediff-clear-fine-differences-in-one-buffer n 'A)
1443 (ediff-clear-fine-differences-in-one-buffer n 'B)
1444 (if ediff-3way-job
1445 (ediff-clear-fine-differences-in-one-buffer n 'C)))
1446
1447
1448 (defsubst ediff-convert-fine-diffs-to-overlays (diff-list region-num)
1449 (ediff-set-fine-overlays-in-one-buffer 'A diff-list region-num)
1450 (ediff-set-fine-overlays-in-one-buffer 'B diff-list region-num)
1451 (if ediff-3way-job
1452 (ediff-set-fine-overlays-in-one-buffer 'C diff-list region-num)
1453 ))
1454
1455 (defsubst ediff-mouse-event-p (event)
1456 (if ediff-xemacs-p
1457 (button-event-p event)
1458 (string-match "mouse" (format "%S" (event-basic-type event)))
1459 ))
1460
1461
1462 (defsubst ediff-key-press-event-p (event)
1463 (if ediff-xemacs-p
1464 (key-press-event-p event)
1465 (or (char-or-string-p event) (symbolp event))))
1466
1467 (defun ediff-event-point (event)
1468 (cond ((ediff-mouse-event-p event)
1469 (if ediff-xemacs-p
1470 (event-point event)
1471 (posn-point (event-start event))))
1472 ((ediff-key-press-event-p event)
1473 (point))
1474 (t (error))))
1475
1476 (defun ediff-event-buffer (event)
1477 (cond ((ediff-mouse-event-p event)
1478 (if ediff-xemacs-p
1479 (event-buffer event)
1480 (window-buffer (posn-window (event-start event)))))
1481 ((ediff-key-press-event-p event)
1482 (current-buffer))
1483 (t (error))))
1484
1485
1486 (defsubst ediff-frame-iconified-p (frame)
1487 (if (and (ediff-window-display-p) (frame-live-p frame))
1488 (if ediff-xemacs-p
1489 (frame-iconified-p frame)
1490 (eq (frame-visible-p frame) 'icon))))
1491
1492 (defsubst ediff-window-visible-p (wind)
1493 ;; under TTY, window-live-p also means window is visible
1494 (and (window-live-p wind)
1495 (or (not (ediff-window-display-p))
1496 (frame-visible-p (window-frame wind)))))
1497
1498
1499 (defsubst ediff-frame-char-width (frame)
1500 (if ediff-xemacs-p
1501 (/ (frame-pixel-width frame) (frame-width frame))
1502 (frame-char-width frame)))
1503
1504 (defun ediff-reset-mouse (&optional frame do-not-grab-mouse)
1505 (or frame (setq frame (selected-frame)))
1506 (if (ediff-window-display-p)
1507 (let ((frame-or-wind frame))
1508 (if ediff-xemacs-p
1509 (setq frame-or-wind (frame-selected-window frame)))
1510 (or do-not-grab-mouse
1511 ;; don't set mouse if the user said to never do this
1512 (not ediff-grab-mouse)
1513 ;; Don't grab on quit, if the user doesn't want to.
1514 ;; If ediff-grab-mouse = t, then mouse won't be grabbed for
1515 ;; sessions that are not part of a group (this is done in
1516 ;; ediff-recenter). The condition below affects only terminating
1517 ;; sessions in session groups (in which case mouse is warped into
1518 ;; a meta buffer).
1519 (and (eq ediff-grab-mouse 'maybe)
1520 (memq this-command '(ediff-quit ediff-update-diffs)))
1521 (set-mouse-position frame-or-wind 1 0))
1522 )))
1523
1524 (defsubst ediff-spy-after-mouse ()
1525 (setq ediff-mouse-pixel-position (mouse-pixel-position)))
1526
1527 ;; It is not easy to find out when the user grabs the mouse, since emacs and
1528 ;; xemacs behave differently when mouse is not in any frame. Also, this is
1529 ;; sensitive to when the user grabbed mouse. Not used for now.
1530 (defun ediff-user-grabbed-mouse ()
1531 (if ediff-mouse-pixel-position
1532 (cond ((not (eq (car ediff-mouse-pixel-position)
1533 (car (mouse-pixel-position)))))
1534 ((and (car (cdr ediff-mouse-pixel-position))
1535 (car (cdr (mouse-pixel-position)))
1536 (cdr (cdr ediff-mouse-pixel-position))
1537 (cdr (cdr (mouse-pixel-position))))
1538 (not (and (< (abs (- (car (cdr ediff-mouse-pixel-position))
1539 (car (cdr (mouse-pixel-position)))))
1540 ediff-mouse-pixel-threshold)
1541 (< (abs (- (cdr (cdr ediff-mouse-pixel-position))
1542 (cdr (cdr (mouse-pixel-position)))))
1543 ediff-mouse-pixel-threshold))))
1544 (t nil))))
1545
1546 (defsubst ediff-frame-char-height (frame)
1547 (if ediff-xemacs-p
1548 (glyph-height ediff-H-glyph (selected-window frame))
1549 (frame-char-height frame)))
1550
1551 ;; Some overlay functions
1552
1553 (defsubst ediff-overlay-start (overl)
1554 (if (ediff-overlayp overl)
1555 (if ediff-emacs-p
1556 (overlay-start overl)
1557 (extent-start-position overl))))
1558
1559 (defsubst ediff-overlay-end (overl)
1560 (if (ediff-overlayp overl)
1561 (if ediff-emacs-p
1562 (overlay-end overl)
1563 (extent-end-position overl))))
1564
1565 (defsubst ediff-empty-overlay-p (overl)
1566 (= (ediff-overlay-start overl) (ediff-overlay-end overl)))
1567
1568 ;; like overlay-buffer in Emacs. In XEmacs, returns nil if the extent is
1569 ;; dead. Otherwise, works like extent-buffer
1570 (defun ediff-overlay-buffer (overl)
1571 (if ediff-emacs-p
1572 (overlay-buffer overl)
1573 (and (extent-live-p overl) (extent-object overl))))
1574
1575 ;; like overlay-get in Emacs. In XEmacs, returns nil if the extent is
1576 ;; dead. Otherwise, like extent-property
1577 (defun ediff-overlay-get (overl property)
1578 (if ediff-emacs-p
1579 (overlay-get overl property)
1580 (and (extent-live-p overl) (extent-property overl property))))
1581
1582
1583 ;; These two functions are here because XEmacs refuses to
1584 ;; handle overlays whose buffers were deleted.
1585 (defun ediff-move-overlay (overlay beg end &optional buffer)
1586 "Calls `move-overlay' in Emacs and `set-extent-endpoints' in Lemacs.
1587 Checks if overlay's buffer exists before actually doing the move."
1588 (let ((buf (and overlay (ediff-overlay-buffer overlay))))
1589 (if (ediff-buffer-live-p buf)
1590 (if ediff-xemacs-p
1591 (set-extent-endpoints overlay beg end)
1592 (move-overlay overlay beg end buffer))
1593 ;; buffer's dead
1594 (if overlay
1595 (ediff-delete-overlay overlay)))))
1596
1597 (defun ediff-overlay-put (overlay prop value)
1598 "Calls `overlay-put' or `set-extent-property' depending on Emacs version.
1599 Checks if overlay's buffer exists."
1600 (if (ediff-buffer-live-p (ediff-overlay-buffer overlay))
1601 (if ediff-xemacs-p
1602 (set-extent-property overlay prop value)
1603 (overlay-put overlay prop value))
1604 (ediff-delete-overlay overlay)))
1605
1606 ;; Some diff region tests
1607
1608 ;; t if diff region is empty.
1609 ;; In case of buffer C, t also if it is not a 3way
1610 ;; comparison job (merging jobs return t as well).
1611 (defun ediff-empty-diff-region-p (n buf-type)
1612 (if (eq buf-type 'C)
1613 (or (not ediff-3way-comparison-job)
1614 (= (ediff-get-diff-posn 'C 'beg n)
1615 (ediff-get-diff-posn 'C 'end n)))
1616 (= (ediff-get-diff-posn buf-type 'beg n)
1617 (ediff-get-diff-posn buf-type 'end n))))
1618
1619 ;; Test if diff region is white space only.
1620 ;; If 2-way job and buf-type = C, then returns t.
1621 (defun ediff-whitespace-diff-region-p (n buf-type)
1622 (or (and (eq buf-type 'C) (not ediff-3way-job))
1623 (ediff-empty-diff-region-p n buf-type)
1624 (let ((beg (ediff-get-diff-posn buf-type 'beg n))
1625 (end (ediff-get-diff-posn buf-type 'end n)))
1626 (ediff-with-current-buffer (ediff-get-buffer buf-type)
1627 (save-excursion
1628 (goto-char beg)
1629 (skip-chars-forward ediff-whitespace)
1630 (>= (point) end))))))
1631
1632 ;; temporarily uses DIR to abbreviate file name
1633 ;; if DIR is nil, use default-directory
1634 (defun ediff-abbreviate-file-name (file &optional dir)
1635 (cond ((stringp dir)
1636 (let ((directory-abbrev-alist (list (cons dir ""))))
1637 (abbreviate-file-name file)))
1638 (ediff-emacs-p (abbreviate-file-name file))
1639 (t ; XEmacs requires addl argument
1640 (abbreviate-file-name file t))))
1641
1642 ;; Takes a directory and returns the parent directory.
1643 ;; does nothing to `/'. If the ARG is a regular file,
1644 ;; strip the file AND the last dir.
1645 (defun ediff-strip-last-dir (dir)
1646 (if (not (stringp dir)) (setq dir default-directory))
1647 (setq dir (expand-file-name dir))
1648 (or (file-directory-p dir) (setq dir (file-name-directory dir)))
1649 (let* ((pos (1- (length dir)))
1650 (last-char (aref dir pos)))
1651 (if (and (> pos 0) (= last-char ?/))
1652 (setq dir (substring dir 0 pos)))
1653 (ediff-abbreviate-file-name (file-name-directory dir))))
1654
1655 (defun ediff-truncate-string-left (str newlen)
1656 ;; leave space for ... on the left
1657 (let ((len (length str))
1658 substr)
1659 (if (<= len newlen)
1660 str
1661 (setq newlen (max 0 (- newlen 3)))
1662 (setq substr (substring str (max 0 (- len 1 newlen))))
1663 (concat "..." substr))))
1664
1665 (defsubst ediff-nonempty-string-p (string)
1666 (and (stringp string) (not (string= string ""))))
1667
1668 (unless (fboundp 'subst-char-in-string)
1669 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1670 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1671 Unless optional argument INPLACE is non-nil, return a new string."
1672 (let ((i (length string))
1673 (newstr (if inplace string (copy-sequence string))))
1674 (while (> i 0)
1675 (setq i (1- i))
1676 (if (eq (aref newstr i) fromchar)
1677 (aset newstr i tochar)))
1678 newstr)))
1679
1680 (defun ediff-abbrev-jobname (jobname)
1681 (cond ((eq jobname 'ediff-directories)
1682 "Compare two directories")
1683 ((eq jobname 'ediff-files)
1684 "Compare two files")
1685 ((eq jobname 'ediff-buffers)
1686 "Compare two buffers")
1687 ((eq jobname 'ediff-directories3)
1688 "Compare three directories")
1689 ((eq jobname 'ediff-files3)
1690 "Compare three files")
1691 ((eq jobname 'ediff-buffers3)
1692 "Compare three buffers")
1693 ((eq jobname 'ediff-revision)
1694 "Compare file with a version")
1695 ((eq jobname 'ediff-directory-revisions)
1696 "Compare dir files with versions")
1697 ((eq jobname 'ediff-merge-directory-revisions)
1698 "Merge dir files with versions")
1699 ((eq jobname 'ediff-merge-directory-revisions-with-ancestor)
1700 "Merge dir versions via ancestors")
1701 (t
1702 (capitalize
1703 (subst-char-in-string ?- ?\ (substring (symbol-name jobname) 6))))
1704 ))
1705
1706
1707 (defsubst ediff-get-region-contents (n buf-type ctrl-buf &optional start end)
1708 (ediff-with-current-buffer
1709 (ediff-with-current-buffer ctrl-buf (ediff-get-buffer buf-type))
1710 (buffer-substring
1711 (or start (ediff-get-diff-posn buf-type 'beg n ctrl-buf))
1712 (or end (ediff-get-diff-posn buf-type 'end n ctrl-buf)))))
1713
1714 ;; If ediff modified mode line, strip the modification
1715 (defsubst ediff-strip-mode-line-format ()
1716 (if (member (car mode-line-format) '(" A: " " B: " " C: " " Ancestor: "))
1717 (setq mode-line-format (nth 2 mode-line-format))))
1718
1719 ;; Verify that we have a difference selected.
1720 (defsubst ediff-valid-difference-p (&optional n)
1721 (or n (setq n ediff-current-difference))
1722 (and (>= n 0) (< n ediff-number-of-differences)))
1723
1724 (defsubst ediff-show-all-diffs (n)
1725 "Don't skip difference regions."
1726 nil)
1727
1728 (defsubst Xor (a b)
1729 (or (and a (not b)) (and (not a) b)))
1730
1731 (defsubst ediff-message-if-verbose (string &rest args)
1732 (if ediff-verbose-p
1733 (apply 'message string args)))
1734
1735 (defun ediff-file-attributes (filename attr-number)
1736 (if (ediff-file-remote-p filename)
1737 -1
1738 (nth attr-number (file-attributes filename))))
1739
1740 (defsubst ediff-file-size (filename)
1741 (ediff-file-attributes filename 7))
1742 (defsubst ediff-file-modtime (filename)
1743 (ediff-file-attributes filename 5))
1744
1745
1746 (defun ediff-convert-standard-filename (fname)
1747 (if (fboundp 'convert-standard-filename)
1748 (convert-standard-filename fname)
1749 fname))
1750
1751
1752 ;;; Local Variables:
1753 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1754 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1755 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1756 ;;; End:
1757
1758 (provide 'ediff-init)
1759
1760
1761 ;;; ediff-init.el ends here