Some fixes to follow coding conventions in files maintained by FSF.
[emacs.git] / lisp / ediff-init.el
blobda6ac26a738f3abbd11e6964571fd14c9a1c009d
1 ;;; ediff-init.el --- Macros, variables, and defsubsts used by Ediff
3 ;; Copyright (C) 1994, 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
7 ;; This file is part of GNU Emacs.
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.
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.
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.
24 ;;; Code:
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)
37 (and noninteractive
38 (eval-when-compile
39 (load "ange-ftp" 'noerror)))
40 ;; end pacifier
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))
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.")
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))))
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)))))
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)))))
70 (defun ediff-has-toolbar-support-p ()
71 (and ediff-xemacs-p
72 (featurep 'toolbar)
73 (console-on-window-system-p)))
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 ?
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.
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)))
95 ;; Variables that control each Ediff session---local to the control buffer.
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 "")
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)))
116 ;;; Macros
117 (defmacro ediff-odd-p (arg)
118 `(eq (logand ,arg 1) 1))
120 (defmacro ediff-buffer-live-p (buf)
121 `(and ,buf (get-buffer ,buf) (buffer-name (get-buffer ,buf))))
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)
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))
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)
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)))
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)))
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))
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
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))
187 (defmacro ediff-get-diff-overlay-from-diff-record (diff-rec)
188 `(aref ,diff-rec 0))
190 (defmacro ediff-get-diff-overlay (n buf-type)
191 `(ediff-get-diff-overlay-from-diff-record
192 (ediff-get-difference ,n ,buf-type)))
194 (defmacro ediff-get-fine-diff-vector-from-diff-record (diff-rec)
195 `(aref ,diff-rec 1))
197 (defmacro ediff-set-fine-diff-vector (n buf-type fine-vec)
198 `(aset (ediff-get-difference ,n ,buf-type) 1 ,fine-vec))
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))
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)))
213 (defmacro ediff-get-state-of-ancestor (n)
214 `(if ediff-state-of-merge
215 (aref (aref ediff-state-of-merge ,n) 1)))
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))
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)))
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))
241 (defsubst ediff-multiframe-setup-p ()
242 (and (ediff-window-display-p) ediff-multiframe))
244 (defmacro ediff-narrow-control-frame-p ()
245 `(and (ediff-multiframe-setup-p)
246 (equal ediff-help-message ediff-brief-message-string)))
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 "")
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 "")
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 "")
273 (defmacro ediff-3way-job ()
274 `(or ediff-3way-comparison-job ediff-merge-job))
275 (ediff-defvar-local ediff-3way-job nil "")
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 "")
284 (defmacro ediff-windows-job ()
285 `(memq ediff-job-name '(ediff-windows-wordwise ediff-windows-linewise)))
286 (ediff-defvar-local ediff-windows-job nil "")
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 "")
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 "")
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
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
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
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)))
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))))
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)))
362 (defgroup ediff-highlighting nil
363 "Hilighting of difference regions in Ediff"
364 :prefix "ediff-"
365 :group 'ediff)
367 (defgroup ediff-merge nil
368 "Merging utilities"
369 :prefix "ediff-"
370 :group 'ediff)
372 (defgroup ediff-hook nil
373 "Hooks run by Ediff"
374 :prefix "ediff-"
375 :group 'ediff)
377 ;; Hook variables
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)
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)
441 (defcustom ediff-display-help-hook nil
442 "*Hooks run after preparing the help message."
443 :type 'hook
444 :group 'ediff-hook)
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)
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.
471 *** Please contact your system administrator. "
472 (if ediff-xemacs-p "X" "")))
474 ;; Selective browsing
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.")
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.")
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 "")
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 "")
513 ;;; Copying difference regions between buffers.
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 "")
522 ;; Syntax table to use in ediff-forward-word-function
523 ;; This is chosen by a heuristic. The important thing is for all buffers to
524 ;; have the same syntax table. Which is not too important.
525 (ediff-defvar-local ediff-syntax-table nil "")
528 ;; Highlighting
529 (defcustom ediff-before-flag-bol (if ediff-xemacs-p (make-glyph "->>") "->>")
530 "*Flag placed before a highlighted block of differences, if block starts at beginning of a line."
531 :type 'string
532 :tag "Region before-flag at beginning of line"
533 :group 'ediff)
535 (defcustom ediff-after-flag-eol (if ediff-xemacs-p (make-glyph "<<-") "<<-")
536 "*Flag placed after a highlighted block of differences, if block ends at end of a line."
537 :type 'string
538 :tag "Region after-flag at end of line"
539 :group 'ediff)
541 (defcustom ediff-before-flag-mol (if ediff-xemacs-p (make-glyph "->>") "->>")
542 "*Flag placed before a highlighted block of differences, if block starts in mid-line."
543 :type 'string
544 :tag "Region before-flag in the middle of line"
545 :group 'ediff)
546 (defcustom ediff-after-flag-mol (if ediff-xemacs-p (make-glyph "<<-") "<<-")
547 "*Flag placed after a highlighted block of differences, if block ends in mid-line."
548 :type 'string
549 :tag "Region after-flag in the middle of line"
550 :group 'ediff)
553 (ediff-defvar-local ediff-use-faces t "")
554 (defcustom ediff-use-faces t
555 "If t, differences are highlighted using faces, if device supports faces.
556 If nil, differences are highlighted using ASCII flags, ediff-before-flag
557 and ediff-after-flag. On a non-window system, differences are always
558 highlighted using ASCII flags."
559 :type 'boolean
560 :group 'ediff-highlighting)
562 ;; this indicates that diff regions are word-size, so fine diffs are
563 ;; permanently nixed; used in ediff-windows-wordwise and ediff-regions-wordwise
564 (ediff-defvar-local ediff-word-mode nil "")
565 ;; Name of the job (ediff-files, ediff-windows, etc.)
566 (ediff-defvar-local ediff-job-name nil "")
568 ;; Narrowing and ediff-region/windows support
569 ;; This is a list (overlay-A overlay-B overlay-C)
570 ;; If set, Ediff compares only those parts of buffers A/B/C that lie within
571 ;; the bounds of these overlays.
572 (ediff-defvar-local ediff-narrow-bounds nil "")
574 ;; List (overlay-A overlay-B overlay-C), where each overlay spans the
575 ;; entire corresponding buffer.
576 (ediff-defvar-local ediff-wide-bounds nil "")
578 ;; Current visibility boundaries in buffers A, B, and C.
579 ;; This is also a list of overlays. When the user toggles narrow/widen,
580 ;; this list changes from ediff-wide-bounds to ediff-narrow-bounds.
581 ;; and back.
582 (ediff-defvar-local ediff-visible-bounds nil "")
584 (ediff-defvar-local ediff-start-narrowed t
585 "Non-nil means start narrowed, if doing ediff-windows-* or ediff-regions-*")
586 (ediff-defvar-local ediff-quit-widened t
587 "*Non-nil means: when finished, Ediff widens buffers A/B.
588 Actually, Ediff restores the scope of visibility that existed at startup.")
590 (defcustom ediff-keep-variants t
591 "*Nil means that non-modified variant buffers should be removed at the end of the session after some interrogation.
592 Supplying a prefix argument to the quit command `q' temporarily reverses the
593 meaning of this variable."
594 :type 'boolean
595 :group 'ediff)
597 (ediff-defvar-local ediff-highlight-all-diffs t "")
598 (defcustom ediff-highlight-all-diffs t
599 "If nil, only the selected differences are highlighted.
600 Otherwise, all difference regions are highlighted, but the selected region is
601 shown in brighter colors."
602 :type 'boolean
603 :group 'ediff-highlighting)
605 ;; A var local to each control panel buffer. Indicates highlighting style
606 ;; in effect for this buffer: `face', `ascii', nil -- temporarily
607 ;; unhighlighted, `off' -- turned off \(on a dumb terminal only\).
608 (ediff-defvar-local ediff-highlighting-style nil "")
611 ;; The suffix of the control buffer name.
612 (ediff-defvar-local ediff-control-buffer-suffix nil "")
613 ;; Same as ediff-control-buffer-suffix, but without <,>.
614 ;; It's a number rather than string.
615 (ediff-defvar-local ediff-control-buffer-number nil "")
618 ;; The original values of ediff-protected-variables for buffer A
619 (ediff-defvar-local ediff-buffer-values-orig-A nil "")
620 ;; The original values of ediff-protected-variables for buffer B
621 (ediff-defvar-local ediff-buffer-values-orig-B nil "")
622 ;; The original values of ediff-protected-variables for buffer C
623 (ediff-defvar-local ediff-buffer-values-orig-C nil "")
624 ;; The original values of ediff-protected-variables for buffer Ancestor
625 (ediff-defvar-local ediff-buffer-values-orig-Ancestor nil "")
627 ;; association between buff-type and ediff-buffer-values-orig-*
628 (defconst ediff-buffer-values-orig-alist
629 '((A . ediff-buffer-values-orig-A)
630 (B . ediff-buffer-values-orig-B)
631 (C . ediff-buffer-values-orig-C)
632 (Ancestor . ediff-buffer-values-orig-Ancestor)))
634 ;; Buffer-local variables to be saved then restored during Ediff sessions
635 (defconst ediff-protected-variables '(
636 ;;buffer-read-only
637 mode-line-format))
639 ;; Vector of differences between the variants. Each difference is
640 ;; represented by a vector of two overlays plus a vector of fine diffs,
641 ;; plus a no-fine-diffs flag. The first overlay spans the
642 ;; difference region in the A buffer and the second overlays the diff in
643 ;; the B buffer. If a difference section is empty, the corresponding
644 ;; overlay's endpoints coincide.
646 ;; The precise form of a Difference Vector for one buffer is:
647 ;; [diff diff diff ...]
648 ;; where each diff has the form:
649 ;; [diff-overlay fine-diff-vector no-fine-diffs-flag state-of-diff]
650 ;; fine-diff-vector is a vector [fine-diff-overlay fine-diff-overlay ...]
651 ;; no-fine-diffs-flag says if there are fine differences.
652 ;; state-of-difference is A, B, C, or nil, indicating which buffer is
653 ;; different from the other two (used only in 3-way jobs.
654 (ediff-defvar-local ediff-difference-vector-A nil "")
655 (ediff-defvar-local ediff-difference-vector-B nil "")
656 (ediff-defvar-local ediff-difference-vector-C nil "")
657 (ediff-defvar-local ediff-difference-vector-Ancestor nil "")
658 ;; A-list of diff vector types associated with buffer types
659 (defconst ediff-difference-vector-alist
660 '((A . ediff-difference-vector-A)
661 (B . ediff-difference-vector-B)
662 (C . ediff-difference-vector-C)
663 (Ancestor . ediff-difference-vector-Ancestor)))
665 ;; [ status status status ...]
666 ;; Each status: [state-of-merge state-of-ancestor]
667 ;; state-of-merge is default-A, default-B, prefer-A, or prefer-B. It
668 ;; indicates the way a diff region was created in buffer C.
669 ;; state-of-ancestor says if the corresponding region in ancestor buffer is
670 ;; empty.
671 (ediff-defvar-local ediff-state-of-merge nil "")
673 ;; The difference that is currently selected.
674 (ediff-defvar-local ediff-current-difference -1 "")
675 ;; Number of differences found.
676 (ediff-defvar-local ediff-number-of-differences nil "")
678 ;; Buffer containing the output of diff, which is used by Ediff to step
679 ;; through files.
680 (ediff-defvar-local ediff-diff-buffer nil "")
681 ;; Like ediff-diff-buffer, but contains context diff. It is not used by
682 ;; Ediff, but it is saved in a file, if user requests so.
683 (ediff-defvar-local ediff-custom-diff-buffer nil "")
684 ;; Buffer used for diff-style fine differences between regions.
685 (ediff-defvar-local ediff-fine-diff-buffer nil "")
686 ;; Temporary buffer used for computing fine differences.
687 (defconst ediff-tmp-buffer " *ediff-tmp*" "")
688 ;; Buffer used for messages
689 (defconst ediff-msg-buffer " *ediff-message*" "")
690 ;; Buffer containing the output of diff when diff returns errors.
691 (ediff-defvar-local ediff-error-buffer nil "")
692 ;; Buffer to display debug info
693 (ediff-defvar-local ediff-debug-buffer "*ediff-debug*" "")
695 ;; List of ediff control panels associated with each buffer A/B/C/Ancestor.
696 ;; Not used any more, but may be needed in the future.
697 (ediff-defvar-local ediff-this-buffer-ediff-sessions nil "")
699 ;; to be deleted in due time
700 ;; List of difference overlays disturbed by working with the current diff.
701 (defvar ediff-disturbed-overlays nil "")
703 ;; Priority of non-selected overlays.
704 (defvar ediff-shadow-overlay-priority 100 "")
706 (defcustom ediff-version-control-package 'vc
707 "Version control package used.
708 Currently, Ediff supports vc.el, rcs.el, pcl-cvs.el, and generic-sc.el. The
709 standard Emacs interface to RCS, CVS, SCCS, etc., is vc.el. However, some
710 people find the other two packages more convenient. Set this variable to the
711 appropriate symbol: `rcs', `pcl-cvs', or `generic-sc' if you so desire."
712 :type 'symbol
713 :group 'ediff)
716 (if ediff-xemacs-p
717 (progn
718 (fset 'ediff-read-event (symbol-function 'next-command-event))
719 (fset 'ediff-overlayp (symbol-function 'extentp))
720 (fset 'ediff-make-overlay (symbol-function 'make-extent))
721 (fset 'ediff-delete-overlay (symbol-function 'delete-extent)))
722 (fset 'ediff-read-event (symbol-function 'read-event))
723 (fset 'ediff-overlayp (symbol-function 'overlayp))
724 (fset 'ediff-make-overlay (symbol-function 'make-overlay))
725 (fset 'ediff-delete-overlay (symbol-function 'delete-overlay)))
727 ;; Check the current version against the major and minor version numbers
728 ;; using op: cur-vers op major.minor If emacs-major-version or
729 ;; emacs-minor-version are not defined, we assume that the current version
730 ;; is hopelessly outdated. We assume that emacs-major-version and
731 ;; emacs-minor-version are defined. Otherwise, for Emacs/XEmacs 19, if the
732 ;; current minor version is < 10 (xemacs) or < 23 (emacs) the return value
733 ;; will be nil (when op is =, >, or >=) and t (when op is <, <=), which may be
734 ;; incorrect. However, this gives correct result in our cases, since we are
735 ;; testing for sufficiently high Emacs versions.
736 (defun ediff-check-version (op major minor &optional type-of-emacs)
737 (if (and (boundp 'emacs-major-version) (boundp 'emacs-minor-version))
738 (and (cond ((eq type-of-emacs 'xemacs) ediff-xemacs-p)
739 ((eq type-of-emacs 'emacs) ediff-emacs-p)
740 (t t))
741 (cond ((eq op '=) (and (= emacs-minor-version minor)
742 (= emacs-major-version major)))
743 ((memq op '(> >= < <=))
744 (and (or (funcall op emacs-major-version major)
745 (= emacs-major-version major))
746 (if (= emacs-major-version major)
747 (funcall op emacs-minor-version minor)
748 t)))
750 (error "%S: Invalid op in ediff-check-version" op))))
751 (cond ((memq op '(= > >=)) nil)
752 ((memq op '(< <=)) t))))
755 (defun ediff-color-display-p ()
756 (condition-case nil
757 (if ediff-emacs-p
758 (if (fboundp 'display-color-p)
759 (display-color-p)
760 (x-display-color-p))
761 (eq (device-class (selected-device)) 'color))
762 (error
763 nil)))
766 (if (ediff-has-face-support-p)
767 (if ediff-xemacs-p
768 (progn
769 (fset 'ediff-valid-color-p (symbol-function 'valid-color-name-p))
770 (fset 'ediff-get-face (symbol-function 'get-face)))
771 (fset 'ediff-valid-color-p (symbol-function
772 (if (fboundp 'color-defined-p)
773 'color-defined-p
774 'x-color-defined-p)))
775 (fset 'ediff-get-face (symbol-function 'internal-get-face))))
777 (if (ediff-window-display-p)
778 (if ediff-xemacs-p
779 (progn
780 (fset 'ediff-display-pixel-width
781 (symbol-function 'device-pixel-width))
782 (fset 'ediff-display-pixel-height
783 (symbol-function 'device-pixel-height)))
784 (fset 'ediff-display-pixel-width (symbol-function
785 (if (fboundp 'display-pixel-width)
786 'display-pixel-width
787 'x-display-pixel-width)))
788 (fset 'ediff-display-pixel-height (symbol-function
789 (if (fboundp 'display-pixel-height)
790 'display-pixel-height
791 'x-display-pixel-height)))))
793 ;; A-list of current-diff-overlay symbols associated with buf types
794 (defconst ediff-current-diff-overlay-alist
795 '((A . ediff-current-diff-overlay-A)
796 (B . ediff-current-diff-overlay-B)
797 (C . ediff-current-diff-overlay-C)
798 (Ancestor . ediff-current-diff-overlay-Ancestor)))
800 ;; A-list of current-diff-face-* symbols associated with buf types
801 (defconst ediff-current-diff-face-alist
802 '((A . ediff-current-diff-face-A)
803 (B . ediff-current-diff-face-B)
804 (C . ediff-current-diff-face-C)
805 (Ancestor . ediff-current-diff-face-Ancestor)))
808 (defun ediff-make-current-diff-overlay (type)
809 (if (ediff-has-face-support-p)
810 (let ((overlay (ediff-get-symbol-from-alist
811 type ediff-current-diff-overlay-alist))
812 (buffer (ediff-get-buffer type))
813 (face (face-name
814 (symbol-value
815 (ediff-get-symbol-from-alist
816 type ediff-current-diff-face-alist)))))
817 (set overlay
818 (ediff-make-bullet-proof-overlay (point-max) (point-max) buffer))
819 (ediff-set-overlay-face (symbol-value overlay) face)
820 (ediff-overlay-put (symbol-value overlay) 'ediff ediff-control-buffer))
823 (defun ediff-set-overlay-face (extent face)
824 (ediff-overlay-put extent 'face face)
825 (ediff-overlay-put extent 'help-echo 'ediff-region-help-echo))
827 (defun ediff-region-help-echo (extent-or-window &optional overlay point)
828 (unless overlay
829 (setq overlay extent-or-window))
830 (let ((is-current (ediff-overlay-get overlay 'ediff))
831 (face (ediff-overlay-get overlay 'face))
832 (diff-num (ediff-overlay-get overlay 'ediff-diff-num))
833 face-help)
835 ;; This happens only for refinement overlays
836 (if (stringp face)
837 (setq face (intern face)))
838 (setq face-help (and face (get face 'ediff-help-echo)))
840 (cond ((and is-current diff-num) ; current diff region
841 (format "Difference region %S -- current" (1+ diff-num)))
842 (face-help) ; refinement of current diff region
843 (diff-num ; non-current
844 (format "Difference region %S -- non-current" (1+ diff-num)))
845 (t "")) ; none
849 (defun ediff-set-face-pixmap (face pixmap)
850 "Set face pixmap on a monochrome display."
851 (if (and (ediff-window-display-p) (not (ediff-color-display-p)))
852 (condition-case nil
853 (set-face-background-pixmap face pixmap)
854 (error
855 (message "Pixmap not found for %S: %s" (face-name face) pixmap)
856 (sit-for 1)))))
858 (defun ediff-hide-face (face)
859 (if (and (ediff-has-face-support-p) ediff-emacs-p)
860 (add-to-list 'facemenu-unlisted-faces face)))
864 (defface ediff-current-diff-face-A
865 '((((class color)) (:foreground "firebrick" :background "pale green"))
866 (t (:inverse-video t)))
867 "Face for highlighting the selected difference in buffer A."
868 :group 'ediff-highlighting)
869 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
870 ;; this variable is set to nil, then again to the appropriate face.
871 (defvar ediff-current-diff-face-A 'ediff-current-diff-face-A
872 "Face for highlighting the selected difference in buffer A.
873 DO NOT CHANGE this variable. Instead, use the customization
874 widget to customize the actual face object `ediff-current-diff-face-A'
875 this variable represents.")
876 (ediff-hide-face 'ediff-current-diff-face-A)
877 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
878 ;; This means that some user customization may be trashed.
879 (if (and ediff-xemacs-p
880 (ediff-has-face-support-p)
881 (not (ediff-color-display-p)))
882 (copy-face 'modeline 'ediff-current-diff-face-A))
886 (defface ediff-current-diff-face-B
887 '((((class color)) (:foreground "DarkOrchid" :background "Yellow"))
888 (t (:inverse-video t)))
889 "Face for highlighting the selected difference in buffer B."
890 :group 'ediff-highlighting)
891 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
892 ;; this variable is set to nil, then again to the appropriate face.
893 (defvar ediff-current-diff-face-B 'ediff-current-diff-face-B
894 "Face for highlighting the selected difference in buffer B.
895 this variable. Instead, use the customization
896 widget to customize the actual face `ediff-current-diff-face-B'
897 this variable represents.")
898 (ediff-hide-face 'ediff-current-diff-face-B)
899 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
900 ;; This means that some user customization may be trashed.
901 (if (and ediff-xemacs-p
902 (ediff-has-face-support-p)
903 (not (ediff-color-display-p)))
904 (copy-face 'modeline 'ediff-current-diff-face-B))
907 (defface ediff-current-diff-face-C
908 '((((class color)) (:foreground "Navy" :background "Pink"))
909 (t (:inverse-video t)))
910 "Face for highlighting the selected difference in buffer C."
911 :group 'ediff-highlighting)
912 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
913 ;; this variable is set to nil, then again to the appropriate face.
914 (defvar ediff-current-diff-face-C 'ediff-current-diff-face-C
915 "Face for highlighting the selected difference in buffer C.
916 DO NOT CHANGE this variable. Instead, use the customization
917 widget to customize the actual face object `ediff-current-diff-face-C'
918 this variable represents.")
919 (ediff-hide-face 'ediff-current-diff-face-C)
920 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
921 ;; This means that some user customization may be trashed.
922 (if (and ediff-xemacs-p
923 (ediff-has-face-support-p)
924 (not (ediff-color-display-p)))
925 (copy-face 'modeline 'ediff-current-diff-face-C))
928 (defface ediff-current-diff-face-Ancestor
929 '((((class color)) (:foreground "Black" :background "VioletRed"))
930 (t (:inverse-video t)))
931 "Face for highlighting the selected difference in buffer Ancestor."
932 :group 'ediff-highlighting)
933 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
934 ;; this variable is set to nil, then again to the appropriate face.
935 (defvar ediff-current-diff-face-Ancestor 'ediff-current-diff-face-Ancestor
936 "Face for highlighting the selected difference in buffer Ancestor.
937 DO NOT CHANGE this variable. Instead, use the customization
938 widget to customize the actual face object `ediff-current-diff-face-Ancestor'
939 this variable represents.")
940 (ediff-hide-face 'ediff-current-diff-face-Ancestor)
941 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
942 ;; This means that some user customization may be trashed.
943 (if (and ediff-xemacs-p
944 (ediff-has-face-support-p)
945 (not (ediff-color-display-p)))
946 (copy-face 'modeline 'ediff-current-diff-face-Ancestor))
949 (defface ediff-fine-diff-face-A
950 '((((class color)) (:foreground "Navy" :background "sky blue"))
951 (t (:underline t :stipple "gray3")))
952 "Face for highlighting the refinement of the selected diff in buffer A."
953 :group 'ediff-highlighting)
954 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
955 ;; this variable is set to nil, then again to the appropriate face.
956 (defvar ediff-fine-diff-face-A 'ediff-fine-diff-face-A
957 "Face for highlighting the fine differences in buffer A.
958 DO NOT CHANGE this variable. Instead, use the customization
959 widget to customize the actual face object `ediff-fine-diff-face-A'
960 this variable represents.")
961 (ediff-hide-face 'ediff-fine-diff-face-A)
963 (defface ediff-fine-diff-face-B
964 '((((class color)) (:foreground "Black" :background "cyan"))
965 (t (:underline t :stipple "gray3")))
966 "Face for highlighting the refinement of the selected diff in buffer B."
967 :group 'ediff-highlighting)
968 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
969 ;; this variable is set to nil, then again to the appropriate face.
970 (defvar ediff-fine-diff-face-B 'ediff-fine-diff-face-B
971 "Face for highlighting the fine differences in buffer B.
972 DO NOT CHANGE this variable. Instead, use the customization
973 widget to customize the actual face object `ediff-fine-diff-face-B'
974 this variable represents.")
975 (ediff-hide-face 'ediff-fine-diff-face-B)
977 (defface ediff-fine-diff-face-C
978 '((((class color)) (:foreground "Black" :background "Turquoise"))
979 (t (:underline t :stipple "gray3")))
980 "Face for highlighting the refinement of the selected diff in buffer C."
981 :group 'ediff-highlighting)
982 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
983 ;; this variable is set to nil, then again to the appropriate face.
984 (defvar ediff-fine-diff-face-C 'ediff-fine-diff-face-C
985 "Face for highlighting the fine differences in buffer C.
986 DO NOT CHANGE this variable. Instead, use the customization
987 widget to customize the actual face object `ediff-fine-diff-face-C'
988 this variable represents.")
989 (ediff-hide-face 'ediff-fine-diff-face-C)
991 (defface ediff-fine-diff-face-Ancestor
992 '((((class color)) (:foreground "Black" :background "Green"))
993 (t (:underline t :stipple "gray3")))
994 "Face for highlighting the refinement of the selected diff in the ancestor buffer.
995 At present, this face is not used and no fine differences are computed for the
996 ancestor buffer."
997 :group 'ediff-highlighting)
998 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
999 ;; this variable is set to nil, then again to the appropriate face.
1000 (defvar ediff-fine-diff-face-Ancestor 'ediff-fine-diff-face-Ancestor
1001 "Face for highlighting the fine differences in buffer Ancestor.
1002 DO NOT CHANGE this variable. Instead, use the customization
1003 widget to customize the actual face object `ediff-fine-diff-face-Ancestor'
1004 this variable represents.")
1005 (ediff-hide-face 'ediff-fine-diff-face-Ancestor)
1007 ;; Some installs don't have stipple or Stipple. So, try them in turn.
1008 (defvar stipple-pixmap
1009 (cond ((not (ediff-has-face-support-p)) nil)
1010 ((and (boundp 'x-bitmap-file-path)
1011 (locate-library "stipple" t x-bitmap-file-path)) "stipple")
1012 ((and (boundp 'mswindowsx-bitmap-file-path)
1013 (locate-library "stipple" t mswindowsx-bitmap-file-path)) "stipple")
1014 (t "Stipple")))
1016 (defface ediff-even-diff-face-A
1017 `((((class color)) (:foreground "Black" :background "light grey"))
1018 (t (:italic t :stipple ,stipple-pixmap)))
1019 "Face for highlighting even-numbered non-current differences in buffer A."
1020 :group 'ediff-highlighting)
1021 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1022 ;; this variable is set to nil, then again to the appropriate face.
1023 (defvar ediff-even-diff-face-A 'ediff-even-diff-face-A
1024 "Face for highlighting even-numbered non-current differences in buffer A.
1025 DO NOT CHANGE this variable. Instead, use the customization
1026 widget to customize the actual face object `ediff-even-diff-face-A'
1027 this variable represents.")
1028 (ediff-hide-face 'ediff-even-diff-face-A)
1030 (defface ediff-even-diff-face-B
1031 `((((class color)) (:foreground "White" :background "Grey"))
1032 (t (:italic t :stipple ,stipple-pixmap)))
1033 "Face for highlighting even-numbered non-current differences in buffer B."
1034 :group 'ediff-highlighting)
1035 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1036 ;; this variable is set to nil, then again to the appropriate face.
1037 (defvar ediff-even-diff-face-B 'ediff-even-diff-face-B
1038 "Face for highlighting even-numbered non-current differences in buffer B.
1039 DO NOT CHANGE this variable. Instead, use the customization
1040 widget to customize the actual face object `ediff-even-diff-face-B'
1041 this variable represents.")
1042 (ediff-hide-face 'ediff-even-diff-face-B)
1044 (defface ediff-even-diff-face-C
1045 `((((class color)) (:foreground "Black" :background "light grey"))
1046 (t (:italic t :stipple ,stipple-pixmap)))
1047 "Face for highlighting even-numbered non-current differences in buffer C."
1048 :group 'ediff-highlighting)
1049 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1050 ;; this variable is set to nil, then again to the appropriate face.
1051 (defvar ediff-even-diff-face-C 'ediff-even-diff-face-C
1052 "Face for highlighting even-numbered non-current differences in buffer C.
1053 DO NOT CHANGE this variable. Instead, use the customization
1054 widget to customize the actual face object `ediff-even-diff-face-C'
1055 this variable represents.")
1056 (ediff-hide-face 'ediff-even-diff-face-C)
1058 (defface ediff-even-diff-face-Ancestor
1059 `((((class color)) (:foreground "White" :background "Grey"))
1060 (t (:italic t :stipple ,stipple-pixmap)))
1061 "Face for highlighting even-numbered non-current differences in the ancestor buffer."
1062 :group 'ediff-highlighting)
1063 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1064 ;; this variable is set to nil, then again to the appropriate face.
1065 (defvar ediff-even-diff-face-Ancestor 'ediff-even-diff-face-Ancestor
1066 "Face for highlighting even-numbered non-current differences in buffer Ancestor.
1067 DO NOT CHANGE this variable. Instead, use the customization
1068 widget to customize the actual face object `ediff-even-diff-face-Ancestor'
1069 this variable represents.")
1070 (ediff-hide-face 'ediff-even-diff-face-Ancestor)
1072 ;; Association between buffer types and even-diff-face symbols
1073 (defconst ediff-even-diff-face-alist
1074 '((A . ediff-even-diff-face-A)
1075 (B . ediff-even-diff-face-B)
1076 (C . ediff-even-diff-face-C)
1077 (Ancestor . ediff-even-diff-face-Ancestor)))
1079 (defface ediff-odd-diff-face-A
1080 '((((class color)) (:foreground "White" :background "Grey"))
1081 (t (:italic t :stipple "gray1")))
1082 "Face for highlighting odd-numbered non-current differences in buffer A."
1083 :group 'ediff-highlighting)
1084 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1085 ;; this variable is set to nil, then again to the appropriate face.
1086 (defvar ediff-odd-diff-face-A 'ediff-odd-diff-face-A
1087 "Face for highlighting odd-numbered non-current differences in buffer A.
1088 DO NOT CHANGE this variable. Instead, use the customization
1089 widget to customize the actual face object `ediff-odd-diff-face-A'
1090 this variable represents.")
1091 (ediff-hide-face 'ediff-odd-diff-face-A)
1094 (defface ediff-odd-diff-face-B
1095 '((((class color)) (:foreground "Black" :background "light grey"))
1096 (t (:italic t :stipple "gray1")))
1097 "Face for highlighting odd-numbered non-current differences in buffer B."
1098 :group 'ediff-highlighting)
1099 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1100 ;; this variable is set to nil, then again to the appropriate face.
1101 (defvar ediff-odd-diff-face-B 'ediff-odd-diff-face-B
1102 "Face for highlighting odd-numbered non-current differences in buffer B.
1103 DO NOT CHANGE this variable. Instead, use the customization
1104 widget to customize the actual face object `ediff-odd-diff-face-B'
1105 this variable represents.")
1106 (ediff-hide-face 'ediff-odd-diff-face-B)
1108 (defface ediff-odd-diff-face-C
1109 '((((class color)) (:foreground "White" :background "Grey"))
1110 (t (:italic t :stipple "gray1")))
1111 "Face for highlighting odd-numbered non-current differences in buffer C."
1112 :group 'ediff-highlighting)
1113 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1114 ;; this variable is set to nil, then again to the appropriate face.
1115 (defvar ediff-odd-diff-face-C 'ediff-odd-diff-face-C
1116 "Face for highlighting odd-numbered non-current differences in buffer C.
1117 DO NOT CHANGE this variable. Instead, use the customization
1118 widget to customize the actual face object `ediff-odd-diff-face-C'
1119 this variable represents.")
1120 (ediff-hide-face 'ediff-odd-diff-face-C)
1122 (defface ediff-odd-diff-face-Ancestor
1123 '((((class color)) (:foreground "Black" :background "light grey"))
1124 (t (:italic t :stipple "gray1")))
1125 "Face for highlighting odd-numbered non-current differences in the ancestor buffer."
1126 :group 'ediff-highlighting)
1127 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1128 ;; this variable is set to nil, then again to the appropriate face.
1129 (defvar ediff-odd-diff-face-Ancestor 'ediff-odd-diff-face-Ancestor
1130 "Face for highlighting odd-numbered non-current differences in buffer Ancestor.
1131 DO NOT CHANGE this variable. Instead, use the customization
1132 widget to customize the actual face object `ediff-odd-diff-face-Ancestor'
1133 this variable represents.")
1134 (ediff-hide-face 'ediff-odd-diff-face-Ancestor)
1136 ;; Association between buffer types and odd-diff-face symbols
1137 (defconst ediff-odd-diff-face-alist
1138 '((A . ediff-odd-diff-face-A)
1139 (B . ediff-odd-diff-face-B)
1140 (C . ediff-odd-diff-face-C)
1141 (Ancestor . ediff-odd-diff-face-Ancestor)))
1143 ;; A-list of fine-diff face symbols associated with buffer types
1144 (defconst ediff-fine-diff-face-alist
1145 '((A . ediff-fine-diff-face-A)
1146 (B . ediff-fine-diff-face-B)
1147 (C . ediff-fine-diff-face-C)
1148 (Ancestor . ediff-fine-diff-face-Ancestor)))
1150 ;; Help echo
1151 (put 'ediff-fine-diff-face-A 'ediff-help-echo
1152 "A `refinement' of the current difference region")
1153 (put 'ediff-fine-diff-face-B 'ediff-help-echo
1154 "A `refinement' of the current difference region")
1155 (put 'ediff-fine-diff-face-C 'ediff-help-echo
1156 "A `refinement' of the current difference region")
1157 (put 'ediff-fine-diff-face-Ancestor 'ediff-help-echo
1158 "A `refinement' of the current difference region")
1160 (add-hook 'ediff-quit-hook 'ediff-cleanup-mess)
1161 (add-hook 'ediff-suspend-hook 'ediff-default-suspend-function)
1164 ;;; Overlays
1166 (ediff-defvar-local ediff-current-diff-overlay-A nil
1167 "Overlay for the current difference region in buffer A.")
1168 (ediff-defvar-local ediff-current-diff-overlay-B nil
1169 "Overlay for the current difference region in buffer B.")
1170 (ediff-defvar-local ediff-current-diff-overlay-C nil
1171 "Overlay for the current difference region in buffer C.")
1172 (ediff-defvar-local ediff-current-diff-overlay-Ancestor nil
1173 "Overlay for the current difference region in the ancestor buffer.")
1175 ;; Compute priority of ediff overlay.
1176 (defun ediff-highest-priority (start end buffer)
1177 (let ((pos (max 1 (1- start)))
1178 ovr-list)
1179 (if ediff-xemacs-p
1180 (1+ ediff-shadow-overlay-priority)
1181 (ediff-with-current-buffer buffer
1182 (while (< pos (min (point-max) (1+ end)))
1183 (setq ovr-list (append (overlays-at pos) ovr-list))
1184 (setq pos (next-overlay-change pos)))
1185 (1+ (apply '+
1186 (mapcar (lambda (ovr)
1187 (if ovr
1188 (or (ediff-overlay-get ovr 'priority) 0)
1190 ovr-list)
1192 ))))
1195 (defvar ediff-toggle-read-only-function nil
1196 "*Specifies the function to be used to toggle read-only.
1197 If nil, Ediff tries to deduce the function from the binding of C-x C-q.
1198 Normally, this is the `toggle-read-only' function, but, if version
1199 control is used, it could be `vc-toggle-read-only' or `rcs-toggle-read-only'.")
1201 (defcustom ediff-make-buffers-readonly-at-startup nil
1202 "*Make all variant buffers read-only when Ediff starts up.
1203 This property can be toggled interactively."
1204 :type 'boolean
1205 :group 'ediff)
1208 ;;; Misc
1210 ;; if nil, this silences some messages
1211 (defconst ediff-verbose-p t)
1213 (defcustom ediff-autostore-merges 'group-jobs-only
1214 "*Save the results of merge jobs automatically.
1215 Nil means don't save automatically. t means always save. Anything but nil or t
1216 means save automatically only if the merge job is part of a group of jobs, such
1217 as `ediff-merge-directory' or `ediff-merge-directory-revisions'."
1218 :type '(choice (const nil) (const t) (const group-jobs-only))
1219 :group 'ediff-merge)
1220 (make-variable-buffer-local 'ediff-autostore-merges)
1222 ;; file where the result of the merge is to be saved. used internally
1223 (ediff-defvar-local ediff-merge-store-file nil "")
1225 (defcustom ediff-merge-filename-prefix "merge_"
1226 "*Prefix to be attached to saved merge buffers."
1227 :type 'string
1228 :group 'ediff-merge)
1230 (defcustom ediff-no-emacs-help-in-control-buffer nil
1231 "*Non-nil means C-h should not invoke Emacs help in control buffer.
1232 Instead, C-h would jump to previous difference."
1233 :type 'boolean
1234 :group 'ediff)
1236 ;; This is the same as temporary-file-directory from Emacs 20.3.
1237 ;; Copied over here because XEmacs doesn't have this variable.
1238 (defcustom ediff-temp-file-prefix
1239 (file-name-as-directory
1240 (cond ((boundp 'temporary-file-directory) temporary-file-directory)
1241 ((fboundp 'temp-directory) (temp-directory))
1242 (t "/tmp/")))
1243 ;;; (file-name-as-directory
1244 ;;; (cond ((memq system-type '(ms-dos windows-nt))
1245 ;;; (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
1246 ;;; ((memq system-type '(vax-vms axp-vms))
1247 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
1248 ;;; (t
1249 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))
1250 "*Prefix to put on Ediff temporary file names.
1251 Do not start with `~/' or `~USERNAME/'."
1252 :type 'string
1253 :group 'ediff)
1255 (defcustom ediff-temp-file-mode 384 ; u=rw only
1256 "*Mode for Ediff temporary files."
1257 :type 'integer
1258 :group 'ediff)
1260 ;; Metacharacters that have to be protected from the shell when executing
1261 ;; a diff/diff3 command.
1262 (defcustom ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
1263 "Regexp that matches characters that must be quoted with `\\' in shell command line.
1264 This default should work without changes."
1265 :type 'string
1266 :group 'ediff)
1268 ;; needed to simulate frame-char-width in XEmacs.
1269 (defvar ediff-H-glyph (if ediff-xemacs-p (make-glyph "H")))
1272 ;; Temporary file used for refining difference regions in buffer A.
1273 (ediff-defvar-local ediff-temp-file-A nil "")
1274 ;; Temporary file used for refining difference regions in buffer B.
1275 (ediff-defvar-local ediff-temp-file-B nil "")
1276 ;; Temporary file used for refining difference regions in buffer C.
1277 (ediff-defvar-local ediff-temp-file-C nil "")
1280 ;;; In-line functions
1282 (or (fboundp 'ediff-file-remote-p) ; user supplied his own function: use it
1283 (defun ediff-file-remote-p (file-name)
1284 (find-file-name-handler file-name 'file-local-copy)))
1285 ;;; (or (and (featurep 'efs-auto) (efs-ftp-path file-name))
1286 ;;; (and (featurep 'tramp) (tramp-tramp-file-p file-name))
1287 ;;; (and (fboundp 'file-remote-p) (file-remote-p file-name))
1288 ;;; ;; Can happen only in Emacs, since XEmacs has file-remote-p
1289 ;;; (and (require 'ange-ftp) (ange-ftp-ftp-name file-name)))))
1292 (defsubst ediff-frame-unsplittable-p (frame)
1293 (cdr (assq 'unsplittable (frame-parameters frame))))
1295 (defsubst ediff-get-next-window (wind prev-wind)
1296 (or (window-live-p wind)
1297 (setq wind (if prev-wind
1298 (next-window wind)
1299 (selected-window)))))
1302 (defsubst ediff-kill-buffer-carefully (buf)
1303 "Kill buffer BUF if it exists."
1304 (if (ediff-buffer-live-p buf)
1305 (kill-buffer (get-buffer buf))))
1307 (defsubst ediff-background-face (buf-type dif-num)
1308 ;; The value of dif-num is always 1- the one that user sees.
1309 ;; This is why even face is used when dif-num is odd.
1310 (ediff-get-symbol-from-alist
1311 buf-type (if (ediff-odd-p dif-num)
1312 ediff-even-diff-face-alist
1313 ediff-odd-diff-face-alist)
1317 ;; activate faces on diff regions in buffer
1318 (defun ediff-paint-background-regions-in-one-buffer (buf-type unhighlight)
1319 (let ((diff-vector
1320 (eval (ediff-get-symbol-from-alist
1321 buf-type ediff-difference-vector-alist)))
1322 overl diff-num)
1323 (mapcar (lambda (rec)
1324 (setq overl (ediff-get-diff-overlay-from-diff-record rec)
1325 diff-num (ediff-overlay-get overl 'ediff-diff-num))
1326 (if (ediff-overlay-buffer overl)
1327 ;; only if overlay is alive
1328 (ediff-set-overlay-face
1329 overl
1330 (if (not unhighlight)
1331 (ediff-background-face buf-type diff-num))))
1333 diff-vector)))
1336 ;; activate faces on diff regions in all buffers
1337 (defun ediff-paint-background-regions (&optional unhighlight)
1338 (ediff-paint-background-regions-in-one-buffer
1339 'A unhighlight)
1340 (ediff-paint-background-regions-in-one-buffer
1341 'B unhighlight)
1342 (ediff-paint-background-regions-in-one-buffer
1343 'C unhighlight)
1344 (ediff-paint-background-regions-in-one-buffer
1345 'Ancestor unhighlight))
1347 (defun ediff-highlight-diff-in-one-buffer (n buf-type)
1348 (if (ediff-buffer-live-p (ediff-get-buffer buf-type))
1349 (let* ((buff (ediff-get-buffer buf-type))
1350 (last (ediff-with-current-buffer buff (point-max)))
1351 (begin (ediff-get-diff-posn buf-type 'beg n))
1352 (end (ediff-get-diff-posn buf-type 'end n))
1353 (xtra (if (equal begin end) 1 0))
1354 (end-hilit (min last (+ end xtra)))
1355 (current-diff-overlay
1356 (symbol-value
1357 (ediff-get-symbol-from-alist
1358 buf-type ediff-current-diff-overlay-alist))))
1360 (if ediff-xemacs-p
1361 (ediff-move-overlay current-diff-overlay begin end-hilit)
1362 (ediff-move-overlay current-diff-overlay begin end-hilit buff))
1363 (ediff-overlay-put current-diff-overlay 'priority
1364 (ediff-highest-priority begin end-hilit buff))
1365 (ediff-overlay-put current-diff-overlay 'ediff-diff-num n)
1367 ;; unhighlight the background overlay for diff n so it won't
1368 ;; interfere with the current diff overlay
1369 (ediff-set-overlay-face (ediff-get-diff-overlay n buf-type) nil)
1373 (defun ediff-unhighlight-diff-in-one-buffer (buf-type)
1374 (if (ediff-buffer-live-p (ediff-get-buffer buf-type))
1375 (let ((current-diff-overlay
1376 (symbol-value
1377 (ediff-get-symbol-from-alist
1378 buf-type ediff-current-diff-overlay-alist)))
1379 (overlay
1380 (ediff-get-diff-overlay ediff-current-difference buf-type))
1383 (ediff-move-overlay current-diff-overlay 1 1)
1385 ;; rehighlight the overlay in the background of the
1386 ;; current difference region
1387 (ediff-set-overlay-face
1388 overlay
1389 (if (and (ediff-has-face-support-p)
1390 ediff-use-faces ediff-highlight-all-diffs)
1391 (ediff-background-face buf-type ediff-current-difference)))
1394 (defun ediff-unhighlight-diffs-totally-in-one-buffer (buf-type)
1395 (ediff-unselect-and-select-difference -1)
1396 (if (and (ediff-has-face-support-p) ediff-use-faces)
1397 (let* ((inhibit-quit t)
1398 (current-diff-overlay-var
1399 (ediff-get-symbol-from-alist
1400 buf-type ediff-current-diff-overlay-alist))
1401 (current-diff-overlay (symbol-value current-diff-overlay-var)))
1402 (ediff-paint-background-regions 'unhighlight)
1403 (if (ediff-overlayp current-diff-overlay)
1404 (ediff-delete-overlay current-diff-overlay))
1405 (set current-diff-overlay-var nil)
1409 (defsubst ediff-highlight-diff (n)
1410 "Put face on diff N. Invoked for X displays only."
1411 (ediff-highlight-diff-in-one-buffer n 'A)
1412 (ediff-highlight-diff-in-one-buffer n 'B)
1413 (ediff-highlight-diff-in-one-buffer n 'C)
1414 (ediff-highlight-diff-in-one-buffer n 'Ancestor)
1418 (defsubst ediff-unhighlight-diff ()
1419 "Remove overlays from buffers A, B, and C."
1420 (ediff-unhighlight-diff-in-one-buffer 'A)
1421 (ediff-unhighlight-diff-in-one-buffer 'B)
1422 (ediff-unhighlight-diff-in-one-buffer 'C)
1423 (ediff-unhighlight-diff-in-one-buffer 'Ancestor)
1426 ;; delete highlighting overlays, restore faces to their original form
1427 (defsubst ediff-unhighlight-diffs-totally ()
1428 (ediff-unhighlight-diffs-totally-in-one-buffer 'A)
1429 (ediff-unhighlight-diffs-totally-in-one-buffer 'B)
1430 (ediff-unhighlight-diffs-totally-in-one-buffer 'C)
1431 (ediff-unhighlight-diffs-totally-in-one-buffer 'Ancestor)
1435 ;; arg is a record for a given diff in a difference vector
1436 ;; this record is itself a vector
1437 (defsubst ediff-clear-fine-diff-vector (diff-record)
1438 (if diff-record
1439 (mapcar 'ediff-delete-overlay
1440 (ediff-get-fine-diff-vector-from-diff-record diff-record))))
1442 (defsubst ediff-clear-fine-differences-in-one-buffer (n buf-type)
1443 (ediff-clear-fine-diff-vector (ediff-get-difference n buf-type))
1444 (ediff-set-fine-diff-vector n buf-type nil))
1446 (defsubst ediff-clear-fine-differences (n)
1447 (ediff-clear-fine-differences-in-one-buffer n 'A)
1448 (ediff-clear-fine-differences-in-one-buffer n 'B)
1449 (if ediff-3way-job
1450 (ediff-clear-fine-differences-in-one-buffer n 'C)))
1453 (defsubst ediff-convert-fine-diffs-to-overlays (diff-list region-num)
1454 (ediff-set-fine-overlays-in-one-buffer 'A diff-list region-num)
1455 (ediff-set-fine-overlays-in-one-buffer 'B diff-list region-num)
1456 (if ediff-3way-job
1457 (ediff-set-fine-overlays-in-one-buffer 'C diff-list region-num)
1460 (defsubst ediff-mouse-event-p (event)
1461 (if ediff-xemacs-p
1462 (button-event-p event)
1463 (string-match "mouse" (format "%S" (event-basic-type event)))
1467 (defsubst ediff-key-press-event-p (event)
1468 (if ediff-xemacs-p
1469 (key-press-event-p event)
1470 (or (char-or-string-p event) (symbolp event))))
1472 (defun ediff-event-point (event)
1473 (cond ((ediff-mouse-event-p event)
1474 (if ediff-xemacs-p
1475 (event-point event)
1476 (posn-point (event-start event))))
1477 ((ediff-key-press-event-p event)
1478 (point))
1479 (t (error))))
1481 (defun ediff-event-buffer (event)
1482 (cond ((ediff-mouse-event-p event)
1483 (if ediff-xemacs-p
1484 (event-buffer event)
1485 (window-buffer (posn-window (event-start event)))))
1486 ((ediff-key-press-event-p event)
1487 (current-buffer))
1488 (t (error))))
1491 (defsubst ediff-frame-iconified-p (frame)
1492 (if (and (ediff-window-display-p) (frame-live-p frame))
1493 (if ediff-xemacs-p
1494 (frame-iconified-p frame)
1495 (eq (frame-visible-p frame) 'icon))))
1497 (defsubst ediff-window-visible-p (wind)
1498 ;; under TTY, window-live-p also means window is visible
1499 (and (window-live-p wind)
1500 (or (not (ediff-window-display-p))
1501 (frame-visible-p (window-frame wind)))))
1504 (defsubst ediff-frame-char-width (frame)
1505 (if ediff-xemacs-p
1506 (/ (frame-pixel-width frame) (frame-width frame))
1507 (frame-char-width frame)))
1509 (defun ediff-reset-mouse (&optional frame do-not-grab-mouse)
1510 (or frame (setq frame (selected-frame)))
1511 (if (ediff-window-display-p)
1512 (let ((frame-or-wind frame))
1513 (if ediff-xemacs-p
1514 (setq frame-or-wind (frame-selected-window frame)))
1515 (or do-not-grab-mouse
1516 ;; don't set mouse if the user said to never do this
1517 (not ediff-grab-mouse)
1518 ;; Don't grab on quit, if the user doesn't want to.
1519 ;; If ediff-grab-mouse = t, then mouse won't be grabbed for
1520 ;; sessions that are not part of a group (this is done in
1521 ;; ediff-recenter). The condition below affects only terminating
1522 ;; sessions in session groups (in which case mouse is warped into
1523 ;; a meta buffer).
1524 (and (eq ediff-grab-mouse 'maybe)
1525 (memq this-command '(ediff-quit ediff-update-diffs)))
1526 (set-mouse-position frame-or-wind 1 0))
1529 (defsubst ediff-spy-after-mouse ()
1530 (setq ediff-mouse-pixel-position (mouse-pixel-position)))
1532 ;; It is not easy to find out when the user grabs the mouse, since emacs and
1533 ;; xemacs behave differently when mouse is not in any frame. Also, this is
1534 ;; sensitive to when the user grabbed mouse. Not used for now.
1535 (defun ediff-user-grabbed-mouse ()
1536 (if ediff-mouse-pixel-position
1537 (cond ((not (eq (car ediff-mouse-pixel-position)
1538 (car (mouse-pixel-position)))))
1539 ((and (car (cdr ediff-mouse-pixel-position))
1540 (car (cdr (mouse-pixel-position)))
1541 (cdr (cdr ediff-mouse-pixel-position))
1542 (cdr (cdr (mouse-pixel-position))))
1543 (not (and (< (abs (- (car (cdr ediff-mouse-pixel-position))
1544 (car (cdr (mouse-pixel-position)))))
1545 ediff-mouse-pixel-threshold)
1546 (< (abs (- (cdr (cdr ediff-mouse-pixel-position))
1547 (cdr (cdr (mouse-pixel-position)))))
1548 ediff-mouse-pixel-threshold))))
1549 (t nil))))
1551 (defsubst ediff-frame-char-height (frame)
1552 (if ediff-xemacs-p
1553 (glyph-height ediff-H-glyph (selected-window frame))
1554 (frame-char-height frame)))
1556 ;; Some overlay functions
1558 (defsubst ediff-overlay-start (overl)
1559 (if (ediff-overlayp overl)
1560 (if ediff-emacs-p
1561 (overlay-start overl)
1562 (extent-start-position overl))))
1564 (defsubst ediff-overlay-end (overl)
1565 (if (ediff-overlayp overl)
1566 (if ediff-emacs-p
1567 (overlay-end overl)
1568 (extent-end-position overl))))
1570 (defsubst ediff-empty-overlay-p (overl)
1571 (= (ediff-overlay-start overl) (ediff-overlay-end overl)))
1573 ;; like overlay-buffer in Emacs. In XEmacs, returns nil if the extent is
1574 ;; dead. Otherwise, works like extent-buffer
1575 (defun ediff-overlay-buffer (overl)
1576 (if ediff-emacs-p
1577 (overlay-buffer overl)
1578 (and (extent-live-p overl) (extent-object overl))))
1580 ;; like overlay-get in Emacs. In XEmacs, returns nil if the extent is
1581 ;; dead. Otherwise, like extent-property
1582 (defun ediff-overlay-get (overl property)
1583 (if ediff-emacs-p
1584 (overlay-get overl property)
1585 (and (extent-live-p overl) (extent-property overl property))))
1588 ;; These two functions are here because XEmacs refuses to
1589 ;; handle overlays whose buffers were deleted.
1590 (defun ediff-move-overlay (overlay beg end &optional buffer)
1591 "Calls `move-overlay' in Emacs and `set-extent-endpoints' in Lemacs.
1592 Checks if overlay's buffer exists before actually doing the move."
1593 (let ((buf (and overlay (ediff-overlay-buffer overlay))))
1594 (if (ediff-buffer-live-p buf)
1595 (if ediff-xemacs-p
1596 (set-extent-endpoints overlay beg end)
1597 (move-overlay overlay beg end buffer))
1598 ;; buffer's dead
1599 (if overlay
1600 (ediff-delete-overlay overlay)))))
1602 (defun ediff-overlay-put (overlay prop value)
1603 "Calls `overlay-put' or `set-extent-property' depending on Emacs version.
1604 Checks if overlay's buffer exists."
1605 (if (ediff-buffer-live-p (ediff-overlay-buffer overlay))
1606 (if ediff-xemacs-p
1607 (set-extent-property overlay prop value)
1608 (overlay-put overlay prop value))
1609 (ediff-delete-overlay overlay)))
1611 ;; Some diff region tests
1613 ;; t if diff region is empty.
1614 ;; In case of buffer C, t also if it is not a 3way
1615 ;; comparison job (merging jobs return t as well).
1616 (defun ediff-empty-diff-region-p (n buf-type)
1617 (if (eq buf-type 'C)
1618 (or (not ediff-3way-comparison-job)
1619 (= (ediff-get-diff-posn 'C 'beg n)
1620 (ediff-get-diff-posn 'C 'end n)))
1621 (= (ediff-get-diff-posn buf-type 'beg n)
1622 (ediff-get-diff-posn buf-type 'end n))))
1624 ;; Test if diff region is white space only.
1625 ;; If 2-way job and buf-type = C, then returns t.
1626 (defun ediff-whitespace-diff-region-p (n buf-type)
1627 (or (and (eq buf-type 'C) (not ediff-3way-job))
1628 (ediff-empty-diff-region-p n buf-type)
1629 (let ((beg (ediff-get-diff-posn buf-type 'beg n))
1630 (end (ediff-get-diff-posn buf-type 'end n)))
1631 (ediff-with-current-buffer (ediff-get-buffer buf-type)
1632 (save-excursion
1633 (goto-char beg)
1634 (skip-chars-forward ediff-whitespace)
1635 (>= (point) end))))))
1637 ;; temporarily uses DIR to abbreviate file name
1638 ;; if DIR is nil, use default-directory
1639 (defun ediff-abbreviate-file-name (file &optional dir)
1640 (cond ((stringp dir)
1641 (let ((directory-abbrev-alist (list (cons dir ""))))
1642 (abbreviate-file-name file)))
1643 (ediff-emacs-p (abbreviate-file-name file))
1644 (t ; XEmacs requires addl argument
1645 (abbreviate-file-name file t))))
1647 ;; Takes a directory and returns the parent directory.
1648 ;; does nothing to `/'. If the ARG is a regular file,
1649 ;; strip the file AND the last dir.
1650 (defun ediff-strip-last-dir (dir)
1651 (if (not (stringp dir)) (setq dir default-directory))
1652 (setq dir (expand-file-name dir))
1653 (or (file-directory-p dir) (setq dir (file-name-directory dir)))
1654 (let* ((pos (1- (length dir)))
1655 (last-char (aref dir pos)))
1656 (if (and (> pos 0) (= last-char ?/))
1657 (setq dir (substring dir 0 pos)))
1658 (ediff-abbreviate-file-name (file-name-directory dir))))
1660 (defun ediff-truncate-string-left (str newlen)
1661 ;; leave space for ... on the left
1662 (let ((len (length str))
1663 substr)
1664 (if (<= len newlen)
1666 (setq newlen (max 0 (- newlen 3)))
1667 (setq substr (substring str (max 0 (- len 1 newlen))))
1668 (concat "..." substr))))
1670 (defsubst ediff-nonempty-string-p (string)
1671 (and (stringp string) (not (string= string ""))))
1673 (unless (fboundp 'subst-char-in-string)
1674 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1675 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1676 Unless optional argument INPLACE is non-nil, return a new string."
1677 (let ((i (length string))
1678 (newstr (if inplace string (copy-sequence string))))
1679 (while (> i 0)
1680 (setq i (1- i))
1681 (if (eq (aref newstr i) fromchar)
1682 (aset newstr i tochar)))
1683 newstr)))
1685 (defun ediff-abbrev-jobname (jobname)
1686 (cond ((eq jobname 'ediff-directories)
1687 "Compare two directories")
1688 ((eq jobname 'ediff-files)
1689 "Compare two files")
1690 ((eq jobname 'ediff-buffers)
1691 "Compare two buffers")
1692 ((eq jobname 'ediff-directories3)
1693 "Compare three directories")
1694 ((eq jobname 'ediff-files3)
1695 "Compare three files")
1696 ((eq jobname 'ediff-buffers3)
1697 "Compare three buffers")
1698 ((eq jobname 'ediff-revision)
1699 "Compare file with a version")
1700 ((eq jobname 'ediff-directory-revisions)
1701 "Compare dir files with versions")
1702 ((eq jobname 'ediff-merge-directory-revisions)
1703 "Merge dir files with versions")
1704 ((eq jobname 'ediff-merge-directory-revisions-with-ancestor)
1705 "Merge dir versions via ancestors")
1707 (capitalize
1708 (subst-char-in-string ?- ?\ (substring (symbol-name jobname) 6))))
1712 (defsubst ediff-get-region-contents (n buf-type ctrl-buf &optional start end)
1713 (ediff-with-current-buffer
1714 (ediff-with-current-buffer ctrl-buf (ediff-get-buffer buf-type))
1715 (buffer-substring
1716 (or start (ediff-get-diff-posn buf-type 'beg n ctrl-buf))
1717 (or end (ediff-get-diff-posn buf-type 'end n ctrl-buf)))))
1719 ;; If ediff modified mode line, strip the modification
1720 (defsubst ediff-strip-mode-line-format ()
1721 (if (member (car mode-line-format) '(" A: " " B: " " C: " " Ancestor: "))
1722 (setq mode-line-format (nth 2 mode-line-format))))
1724 ;; Verify that we have a difference selected.
1725 (defsubst ediff-valid-difference-p (&optional n)
1726 (or n (setq n ediff-current-difference))
1727 (and (>= n 0) (< n ediff-number-of-differences)))
1729 (defsubst ediff-show-all-diffs (n)
1730 "Don't skip difference regions."
1731 nil)
1733 (defsubst Xor (a b)
1734 (or (and a (not b)) (and (not a) b)))
1736 (defsubst ediff-message-if-verbose (string &rest args)
1737 (if ediff-verbose-p
1738 (apply 'message string args)))
1740 (defun ediff-file-attributes (filename attr-number)
1741 (if (ediff-file-remote-p filename)
1743 (nth attr-number (file-attributes filename))))
1745 (defsubst ediff-file-size (filename)
1746 (ediff-file-attributes filename 7))
1747 (defsubst ediff-file-modtime (filename)
1748 (ediff-file-attributes filename 5))
1751 (defun ediff-convert-standard-filename (fname)
1752 (if (fboundp 'convert-standard-filename)
1753 (convert-standard-filename fname)
1754 fname))
1757 (if (fboundp 'with-syntax-table)
1758 (fset 'ediff-with-syntax-table 'with-syntax-table)
1759 ;; stolen from subr.el in emacs 21
1760 (defmacro ediff-with-syntax-table (table &rest body)
1761 (let ((old-table (make-symbol "table"))
1762 (old-buffer (make-symbol "buffer")))
1763 `(let ((,old-table (syntax-table))
1764 (,old-buffer (current-buffer)))
1765 (unwind-protect
1766 (progn
1767 (set-syntax-table (copy-syntax-table ,table))
1768 ,@body)
1769 (save-current-buffer
1770 (set-buffer ,old-buffer)
1771 (set-syntax-table ,old-table)))))))
1775 ;;; Local Variables:
1776 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1777 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1778 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1779 ;;; End:
1781 (provide 'ediff-init)
1784 ;;; ediff-init.el ends here