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