Followup to last change in browse-url.el
[emacs.git] / lisp / vc / ediff-init.el
blobe5e2a042305edc7f50af82c1e5c237c2c51229f7
1 ;;; ediff-init.el --- Macros, variables, and defsubsts used by Ediff
3 ;; Copyright (C) 1994-2018 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 <https://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 (user-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 (user-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) (background light))
946 :background "#cfdeee")
947 (((class color) (min-colors 88) (background dark))
948 :background "#004151")
949 (((class color) (min-colors 16) (background light))
950 :background "#cfdeee")
951 (((class color) (min-colors 16) (background dark))
952 :background "#004151")
953 (((class color))
954 (:foreground "black" :background "magenta3"))
955 (t (:inverse-video t)))
956 '((((type tty)) (:foreground "black" :background "magenta3"))
957 (((class color)) (:foreground "Black" :background "VioletRed"))
958 (t (:inverse-video t))))
959 "Face for highlighting the selected difference in buffer Ancestor."
960 :group 'ediff-highlighting)
961 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
962 ;; this variable is set to nil, then again to the appropriate face.
963 (defvar ediff-current-diff-face-Ancestor 'ediff-current-diff-Ancestor
964 "Face for highlighting the selected difference in buffer Ancestor.
965 DO NOT CHANGE this variable. Instead, use the customization
966 widget to customize the actual face object `ediff-current-diff-Ancestor'
967 this variable represents.")
968 (ediff-hide-face ediff-current-diff-face-Ancestor)
969 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
970 ;; This means that some user customization may be trashed.
971 (and (featurep 'xemacs)
972 (ediff-has-face-support-p)
973 (not (ediff-color-display-p))
974 (copy-face 'modeline ediff-current-diff-face-Ancestor))
977 (defface ediff-fine-diff-A
978 (if (featurep 'emacs)
979 '((((class color) (min-colors 88) (background light))
980 :background "#ffbbbb")
981 (((class color) (min-colors 88) (background dark))
982 :background "#aa2222")
983 (((class color) (min-colors 16))
984 (:foreground "Navy" :background "sky blue"))
985 (((class color))
986 (:foreground "white" :background "sky blue" :weight bold))
987 (t (:underline t :stipple "gray3")))
988 '((((type tty)) (:foreground "white" :background "sky blue" :weight bold))
989 (((class color)) (:foreground "Navy" :background "sky blue"))
990 (t (:underline t :stipple "gray3"))))
991 "Face for highlighting the refinement of the selected diff in buffer A."
992 :group 'ediff-highlighting)
993 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
994 ;; this variable is set to nil, then again to the appropriate face.
995 (defvar ediff-fine-diff-face-A 'ediff-fine-diff-A
996 "Face for highlighting the fine differences in buffer A.
997 DO NOT CHANGE this variable. Instead, use the customization
998 widget to customize the actual face object `ediff-fine-diff-A'
999 this variable represents.")
1000 (ediff-hide-face ediff-fine-diff-face-A)
1002 (defface ediff-fine-diff-B
1003 (if (featurep 'emacs)
1004 '((((class color) (min-colors 88) (background light))
1005 :background "#aaffaa")
1006 (((class color) (min-colors 88) (background dark))
1007 :background "#22aa22")
1008 (((class color) (min-colors 16))
1009 (:foreground "Black" :background "cyan"))
1010 (((class color))
1011 (:foreground "magenta3" :background "cyan3"))
1012 (t (:underline t :stipple "gray3")))
1013 '((((type tty)) (:foreground "magenta3" :background "cyan3"))
1014 (((class color)) (:foreground "Black" :background "cyan"))
1015 (t (:underline t :stipple "gray3"))))
1016 "Face for highlighting the refinement of the selected diff in buffer B."
1017 :group 'ediff-highlighting)
1018 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1019 ;; this variable is set to nil, then again to the appropriate face.
1020 (defvar ediff-fine-diff-face-B 'ediff-fine-diff-B
1021 "Face for highlighting the fine differences in buffer B.
1022 DO NOT CHANGE this variable. Instead, use the customization
1023 widget to customize the actual face object `ediff-fine-diff-B'
1024 this variable represents.")
1025 (ediff-hide-face ediff-fine-diff-face-B)
1027 (defface ediff-fine-diff-C
1028 (if (featurep 'emacs)
1029 '((((class color) (min-colors 88) (background light))
1030 :background "#ffff55")
1031 (((class color) (min-colors 88) (background dark))
1032 :background "#aaaa22")
1033 (((type pc))
1034 (:foreground "white" :background "Turquoise"))
1035 (((class color) (min-colors 16))
1036 (:foreground "Black" :background "Turquoise"))
1037 (((class color))
1038 (:foreground "yellow3" :background "Turquoise"
1039 :weight bold))
1040 (t (:underline t :stipple "gray3")))
1041 '((((type tty)) (:foreground "yellow3" :background "Turquoise"
1042 :weight bold))
1043 (((type pc)) (:foreground "white" :background "Turquoise"))
1044 (((class color)) (:foreground "Black" :background "Turquoise"))
1045 (t (:underline t :stipple "gray3"))))
1046 "Face for highlighting the refinement of the selected diff in buffer C."
1047 :group 'ediff-highlighting)
1048 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1049 ;; this variable is set to nil, then again to the appropriate face.
1050 (defvar ediff-fine-diff-face-C 'ediff-fine-diff-C
1051 "Face for highlighting the fine differences in buffer C.
1052 DO NOT CHANGE this variable. Instead, use the customization
1053 widget to customize the actual face object `ediff-fine-diff-C'
1054 this variable represents.")
1055 (ediff-hide-face ediff-fine-diff-face-C)
1057 (defface ediff-fine-diff-Ancestor
1058 (if (featurep 'emacs)
1059 '((((class color) (min-colors 88) (background light))
1060 :background "#00c5c0")
1061 (((class color) (min-colors 88) (background dark))
1062 :background "#009591")
1063 (((class color) (min-colors 16) (background light))
1064 :background "#00c5c0")
1065 (((class color) (min-colors 16) (background dark))
1066 :background "#009591")
1067 (((class color))
1068 (:foreground "red3" :background "green"))
1069 (t (:underline t :stipple "gray3")))
1070 '((((type tty)) (:foreground "red3" :background "green"))
1071 (((class color)) (:foreground "Black" :background "Green"))
1072 (t (:underline t :stipple "gray3"))))
1073 "Face for highlighting the refinement of the selected diff in the ancestor buffer.
1074 At present, this face is not used and no fine differences are computed for the
1075 ancestor buffer."
1076 :group 'ediff-highlighting)
1077 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1078 ;; this variable is set to nil, then again to the appropriate face.
1079 (defvar ediff-fine-diff-face-Ancestor 'ediff-fine-diff-Ancestor
1080 "Face for highlighting the fine differences in buffer Ancestor.
1081 DO NOT CHANGE this variable. Instead, use the customization
1082 widget to customize the actual face object `ediff-fine-diff-Ancestor'
1083 this variable represents.")
1084 (ediff-hide-face ediff-fine-diff-face-Ancestor)
1086 ;; Some installs don't have stipple or Stipple. So, try them in turn.
1087 (defvar stipple-pixmap
1088 (cond ((not (ediff-has-face-support-p)) nil)
1089 ((and (boundp 'x-bitmap-file-path)
1090 (locate-library "stipple" t x-bitmap-file-path)) "stipple")
1091 ((and (boundp 'mswindowsx-bitmap-file-path)
1092 (locate-library "stipple" t mswindowsx-bitmap-file-path)) "stipple")
1093 (t "Stipple")))
1095 (defface ediff-even-diff-A
1096 (if (featurep 'emacs)
1097 `((((type pc))
1098 (:foreground "green3" :background "light grey"))
1099 (((class color) (min-colors 88))
1100 (:background "light grey"))
1101 (((class color) (min-colors 16))
1102 (:foreground "Black" :background "light grey"))
1103 (((class color))
1104 (:foreground "red3" :background "light grey"
1105 :weight bold))
1106 (t (:italic t :stipple ,stipple-pixmap)))
1107 `((((type tty)) (:foreground "red3" :background "light grey"
1108 :weight bold))
1109 (((type pc)) (:foreground "green3" :background "light grey"))
1110 (((class color)) (:foreground "Black" :background "light grey"))
1111 (t (:italic t :stipple ,stipple-pixmap))))
1112 "Face for highlighting even-numbered non-current differences in buffer A."
1113 :group 'ediff-highlighting)
1114 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1115 ;; this variable is set to nil, then again to the appropriate face.
1116 (defvar ediff-even-diff-face-A 'ediff-even-diff-A
1117 "Face for highlighting even-numbered non-current differences in buffer A.
1118 DO NOT CHANGE this variable. Instead, use the customization
1119 widget to customize the actual face object `ediff-even-diff-A'
1120 this variable represents.")
1121 (ediff-hide-face ediff-even-diff-face-A)
1123 (defface ediff-even-diff-B
1124 (if (featurep 'emacs)
1125 `((((class color) (min-colors 88))
1126 (:background "Grey"))
1127 (((class color) (min-colors 16))
1128 (:foreground "White" :background "Grey"))
1129 (((class color))
1130 (:foreground "blue3" :background "Grey" :weight bold))
1131 (t (:italic t :stipple ,stipple-pixmap)))
1132 `((((type tty)) (:foreground "blue3" :background "Grey" :weight bold))
1133 (((class color)) (:foreground "White" :background "Grey"))
1134 (t (:italic t :stipple ,stipple-pixmap))))
1135 "Face for highlighting even-numbered non-current differences in buffer B."
1136 :group 'ediff-highlighting)
1137 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1138 ;; this variable is set to nil, then again to the appropriate face.
1139 (defvar ediff-even-diff-face-B 'ediff-even-diff-B
1140 "Face for highlighting even-numbered non-current differences in buffer B.
1141 DO NOT CHANGE this variable. Instead, use the customization
1142 widget to customize the actual face object `ediff-even-diff-B'
1143 this variable represents.")
1144 (ediff-hide-face ediff-even-diff-face-B)
1146 (defface ediff-even-diff-C
1147 (if (featurep 'emacs)
1148 `((((type pc))
1149 (:foreground "yellow3" :background "light grey"))
1150 (((class color) (min-colors 88))
1151 (:background "light grey"))
1152 (((class color) (min-colors 16))
1153 (:foreground "Black" :background "light grey"))
1154 (((class color))
1155 (:foreground "yellow3" :background "light grey"
1156 :weight bold))
1157 (t (:italic t :stipple ,stipple-pixmap)))
1158 `((((type tty)) (:foreground "yellow3" :background "light grey"
1159 :weight bold))
1160 (((type pc)) (:foreground "yellow3" :background "light grey"))
1161 (((class color)) (:foreground "Black" :background "light grey"))
1162 (t (:italic t :stipple ,stipple-pixmap))))
1163 "Face for highlighting even-numbered non-current differences in buffer C."
1164 :group 'ediff-highlighting)
1165 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1166 ;; this variable is set to nil, then again to the appropriate face.
1167 (defvar ediff-even-diff-face-C 'ediff-even-diff-C
1168 "Face for highlighting even-numbered non-current differences in buffer C.
1169 DO NOT CHANGE this variable. Instead, use the customization
1170 widget to customize the actual face object `ediff-even-diff-C'
1171 this variable represents.")
1172 (ediff-hide-face ediff-even-diff-face-C)
1174 (defface ediff-even-diff-Ancestor
1175 (if (featurep 'emacs)
1176 `((((type pc))
1177 (:foreground "cyan3" :background "light grey"))
1178 (((class color) (min-colors 88))
1179 (:background "Grey"))
1180 (((class color) (min-colors 16))
1181 (:foreground "White" :background "Grey"))
1182 (((class color))
1183 (:foreground "cyan3" :background "light grey"
1184 :weight bold))
1185 (t (:italic t :stipple ,stipple-pixmap)))
1186 `((((type tty)) (:foreground "cyan3" :background "light grey"
1187 :weight bold))
1188 (((type pc)) (:foreground "cyan3" :background "light grey"))
1189 (((class color)) (:foreground "White" :background "Grey"))
1190 (t (:italic t :stipple ,stipple-pixmap))))
1191 "Face for highlighting even-numbered non-current differences in the ancestor buffer."
1192 :group 'ediff-highlighting)
1193 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1194 ;; this variable is set to nil, then again to the appropriate face.
1195 (defvar ediff-even-diff-face-Ancestor 'ediff-even-diff-Ancestor
1196 "Face for highlighting even-numbered non-current differences in buffer Ancestor.
1197 DO NOT CHANGE this variable. Instead, use the customization
1198 widget to customize the actual face object `ediff-even-diff-Ancestor'
1199 this variable represents.")
1200 (ediff-hide-face ediff-even-diff-face-Ancestor)
1202 ;; Association between buffer types and even-diff-face symbols
1203 (defconst ediff-even-diff-face-alist
1204 '((A . ediff-even-diff-A)
1205 (B . ediff-even-diff-B)
1206 (C . ediff-even-diff-C)
1207 (Ancestor . ediff-even-diff-Ancestor)))
1209 (defface ediff-odd-diff-A
1210 (if (featurep 'emacs)
1211 '((((type pc))
1212 (:foreground "green3" :background "gray40"))
1213 (((class color) (min-colors 88))
1214 (:background "Grey"))
1215 (((class color) (min-colors 16))
1216 (:foreground "White" :background "Grey"))
1217 (((class color))
1218 (:foreground "red3" :background "black" :weight bold))
1219 (t (:italic t :stipple "gray1")))
1220 '((((type tty)) (:foreground "red3" :background "black" :weight bold))
1221 (((type pc)) (:foreground "green3" :background "gray40"))
1222 (((class color)) (:foreground "White" :background "Grey"))
1223 (t (:italic t :stipple "gray1"))))
1224 "Face for highlighting odd-numbered non-current differences in buffer A."
1225 :group 'ediff-highlighting)
1226 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1227 ;; this variable is set to nil, then again to the appropriate face.
1228 (defvar ediff-odd-diff-face-A 'ediff-odd-diff-A
1229 "Face for highlighting odd-numbered non-current differences in buffer A.
1230 DO NOT CHANGE this variable. Instead, use the customization
1231 widget to customize the actual face object `ediff-odd-diff-A'
1232 this variable represents.")
1233 (ediff-hide-face ediff-odd-diff-face-A)
1236 (defface ediff-odd-diff-B
1237 (if (featurep 'emacs)
1238 '((((type pc))
1239 (:foreground "White" :background "gray40"))
1240 (((class color) (min-colors 88))
1241 (:background "light grey"))
1242 (((class color) (min-colors 16))
1243 (:foreground "Black" :background "light grey"))
1244 (((class color))
1245 (:foreground "cyan3" :background "black" :weight bold))
1246 (t (:italic t :stipple "gray1")))
1247 '((((type tty)) (:foreground "cyan3" :background "black" :weight bold))
1248 (((type pc)) (:foreground "White" :background "gray40"))
1249 (((class color)) (:foreground "Black" :background "light grey"))
1250 (t (:italic t :stipple "gray1"))))
1251 "Face for highlighting odd-numbered non-current differences in buffer B."
1252 :group 'ediff-highlighting)
1253 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1254 ;; this variable is set to nil, then again to the appropriate face.
1255 (defvar ediff-odd-diff-face-B 'ediff-odd-diff-B
1256 "Face for highlighting odd-numbered non-current differences in buffer B.
1257 DO NOT CHANGE this variable. Instead, use the customization
1258 widget to customize the actual face object `ediff-odd-diff-B'
1259 this variable represents.")
1260 (ediff-hide-face ediff-odd-diff-face-B)
1262 (defface ediff-odd-diff-C
1263 (if (featurep 'emacs)
1264 '((((type pc))
1265 (:foreground "yellow3" :background "gray40"))
1266 (((class color) (min-colors 88))
1267 (:background "Grey"))
1268 (((class color) (min-colors 16))
1269 (:foreground "White" :background "Grey"))
1270 (((class color))
1271 (:foreground "yellow3" :background "black" :weight bold))
1272 (t (:italic t :stipple "gray1")))
1273 '((((type tty)) (:foreground "yellow3" :background "black" :weight bold))
1274 (((type pc)) (:foreground "yellow3" :background "gray40"))
1275 (((class color)) (:foreground "White" :background "Grey"))
1276 (t (:italic t :stipple "gray1"))))
1277 "Face for highlighting odd-numbered non-current differences in buffer C."
1278 :group 'ediff-highlighting)
1279 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1280 ;; this variable is set to nil, then again to the appropriate face.
1281 (defvar ediff-odd-diff-face-C 'ediff-odd-diff-C
1282 "Face for highlighting odd-numbered non-current differences in buffer C.
1283 DO NOT CHANGE this variable. Instead, use the customization
1284 widget to customize the actual face object `ediff-odd-diff-C'
1285 this variable represents.")
1286 (ediff-hide-face ediff-odd-diff-face-C)
1288 (defface ediff-odd-diff-Ancestor
1289 (if (featurep 'emacs)
1290 '((((class color) (min-colors 88))
1291 (:background "gray40"))
1292 (((class color) (min-colors 16))
1293 (:foreground "cyan3" :background "gray40"))
1294 (((class color))
1295 (:foreground "green3" :background "black" :weight bold))
1296 (t (:italic t :stipple "gray1")))
1297 '((((type tty)) (:foreground "green3" :background "black" :weight bold))
1298 (((class color)) (:foreground "cyan3" :background "gray40"))
1299 (t (:italic t :stipple "gray1"))))
1300 "Face for highlighting odd-numbered non-current differences in the ancestor buffer."
1301 :group 'ediff-highlighting)
1302 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1303 ;; this variable is set to nil, then again to the appropriate face.
1304 (defvar ediff-odd-diff-face-Ancestor 'ediff-odd-diff-Ancestor
1305 "Face for highlighting odd-numbered non-current differences in buffer Ancestor.
1306 DO NOT CHANGE this variable. Instead, use the customization
1307 widget to customize the actual face object `ediff-odd-diff-Ancestor'
1308 this variable represents.")
1309 (ediff-hide-face ediff-odd-diff-face-Ancestor)
1311 ;; Association between buffer types and odd-diff-face symbols
1312 (defconst ediff-odd-diff-face-alist
1313 '((A . ediff-odd-diff-A)
1314 (B . ediff-odd-diff-B)
1315 (C . ediff-odd-diff-C)
1316 (Ancestor . ediff-odd-diff-Ancestor)))
1318 ;; A-list of fine-diff face symbols associated with buffer types
1319 (defconst ediff-fine-diff-face-alist
1320 '((A . ediff-fine-diff-A)
1321 (B . ediff-fine-diff-B)
1322 (C . ediff-fine-diff-C)
1323 (Ancestor . ediff-fine-diff-Ancestor)))
1325 ;; Help echo
1326 (put ediff-fine-diff-face-A 'ediff-help-echo
1327 "A `refinement' of the current difference region")
1328 (put ediff-fine-diff-face-B 'ediff-help-echo
1329 "A `refinement' of the current difference region")
1330 (put ediff-fine-diff-face-C 'ediff-help-echo
1331 "A `refinement' of the current difference region")
1332 (put ediff-fine-diff-face-Ancestor 'ediff-help-echo
1333 "A `refinement' of the current difference region")
1335 (add-hook 'ediff-quit-hook 'ediff-cleanup-mess)
1336 (add-hook 'ediff-suspend-hook 'ediff-default-suspend-function)
1339 ;;; Overlays
1341 (ediff-defvar-local ediff-current-diff-overlay-A nil
1342 "Overlay for the current difference region in buffer A.")
1343 (ediff-defvar-local ediff-current-diff-overlay-B nil
1344 "Overlay for the current difference region in buffer B.")
1345 (ediff-defvar-local ediff-current-diff-overlay-C nil
1346 "Overlay for the current difference region in buffer C.")
1347 (ediff-defvar-local ediff-current-diff-overlay-Ancestor nil
1348 "Overlay for the current difference region in the ancestor buffer.")
1350 (defvar ediff-toggle-read-only-function 'read-only-mode
1351 "Function to be used to toggle read-only status of the buffer.
1352 If nil, Ediff tries using the command bound to C-x C-q.")
1354 (defcustom ediff-make-buffers-readonly-at-startup nil
1355 "Make all variant buffers read-only when Ediff starts up.
1356 This property can be toggled interactively."
1357 :type 'boolean
1358 :group 'ediff)
1361 ;;; Misc
1363 ;; if nil, this silences some messages
1364 (defvar ediff-verbose-p t)
1366 (defcustom ediff-show-ancestor t
1367 "If non-nil, show ancestor buffer in 3way merges and refine it."
1368 :type 'boolean
1369 :group 'ediff-merge
1370 :version "26.1")
1372 ;; Store orig value of `ediff-show-ancestor' when changed in
1373 ;; `ediff-toggle-show-ancestor' and restore it on exit.
1374 (ediff-defvar-local ediff--show-ancestor-orig nil "")
1376 (defcustom ediff-autostore-merges 'group-jobs-only
1377 "Save the results of merge jobs automatically.
1378 With value nil, don't save automatically. With value t, always
1379 save. Anything else means save automatically only if the merge
1380 job is part of a group of jobs, such as `ediff-merge-directory'
1381 or `ediff-merge-directory-revisions'."
1382 :type '(choice (const nil) (const t) (const group-jobs-only))
1383 :group 'ediff-merge)
1384 (make-variable-buffer-local 'ediff-autostore-merges)
1386 ;; file where the result of the merge is to be saved. used internally
1387 (ediff-defvar-local ediff-merge-store-file nil "")
1389 (defcustom ediff-merge-filename-prefix "merge_"
1390 "Prefix to be attached to saved merge buffers."
1391 :type 'string
1392 :group 'ediff-merge)
1394 (defcustom ediff-no-emacs-help-in-control-buffer nil
1395 "Non-nil means C-h should not invoke Emacs help in control buffer.
1396 Instead, C-h would jump to previous difference."
1397 :type 'boolean
1398 :group 'ediff)
1400 ;; This is the same as temporary-file-directory from Emacs 20.3.
1401 ;; Copied over here because XEmacs doesn't have this variable.
1402 (defcustom ediff-temp-file-prefix
1403 (file-name-as-directory
1404 (cond ((boundp 'temporary-file-directory) temporary-file-directory)
1405 ((fboundp 'temp-directory) (temp-directory))
1406 (t "/tmp/")))
1407 ;;; (file-name-as-directory
1408 ;;; (cond ((memq system-type '(ms-dos windows-nt))
1409 ;;; (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
1410 ;;; (t
1411 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))
1412 "Prefix to put on Ediff temporary file names.
1413 Do not start with `~/' or `~USERNAME/'."
1414 :type 'string
1415 :group 'ediff)
1417 (defcustom ediff-temp-file-mode 384 ; u=rw only
1418 "Mode for Ediff temporary files."
1419 :type 'integer
1420 :group 'ediff)
1422 ;; Metacharacters that have to be protected from the shell when executing
1423 ;; a diff/diff3 command.
1424 (defcustom ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
1425 "Regexp that matches characters that must be quoted with `\\' in shell command line.
1426 This default should work without changes."
1427 :type 'string
1428 :group 'ediff)
1430 ;; needed to simulate frame-char-width in XEmacs.
1431 (defvar ediff-H-glyph (if (featurep 'xemacs) (make-glyph "H")))
1434 ;; Temporary file used for refining difference regions in buffer A.
1435 (ediff-defvar-local ediff-temp-file-A nil "")
1436 ;; Temporary file used for refining difference regions in buffer B.
1437 (ediff-defvar-local ediff-temp-file-B nil "")
1438 ;; Temporary file used for refining difference regions in buffer C.
1439 (ediff-defvar-local ediff-temp-file-C nil "")
1442 (defun ediff-file-remote-p (file-name)
1443 (file-remote-p file-name))
1445 ;; File for which we can get attributes, such as size or date
1446 (defun ediff-listable-file (file-name)
1447 (let ((handler (find-file-name-handler file-name 'file-local-copy)))
1448 (or (null handler) (eq handler 'dired-handler-fn))))
1451 (defsubst ediff-frame-unsplittable-p (frame)
1452 (cdr (assq 'unsplittable (frame-parameters frame))))
1454 (defsubst ediff-get-next-window (wind prev-wind)
1455 (cond ((window-live-p wind) wind)
1456 (prev-wind (next-window wind))
1457 (t (selected-window))
1461 (defsubst ediff-kill-buffer-carefully (buf)
1462 "Kill buffer BUF if it exists."
1463 (if (ediff-buffer-live-p buf)
1464 (kill-buffer (get-buffer buf))))
1466 (defsubst ediff-background-face (buf-type dif-num)
1467 ;; The value of dif-num is always 1- the one that user sees.
1468 ;; This is why even face is used when dif-num is odd.
1469 (ediff-get-symbol-from-alist
1470 buf-type (if (cl-oddp dif-num)
1471 ediff-even-diff-face-alist
1472 ediff-odd-diff-face-alist)
1476 ;; activate faces on diff regions in buffer
1477 (defun ediff-paint-background-regions-in-one-buffer (buf-type unhighlight)
1478 (let ((diff-vector
1479 (eval (ediff-get-symbol-from-alist
1480 buf-type ediff-difference-vector-alist)))
1481 overl diff-num)
1482 (mapcar (lambda (rec)
1483 (setq overl (ediff-get-diff-overlay-from-diff-record rec)
1484 diff-num (ediff-overlay-get overl 'ediff-diff-num))
1485 (if (ediff-overlay-buffer overl)
1486 ;; only if overlay is alive
1487 (ediff-set-overlay-face
1488 overl
1489 (if (not unhighlight)
1490 (ediff-background-face buf-type diff-num))))
1492 diff-vector)))
1495 ;; activate faces on diff regions in all buffers
1496 (defun ediff-paint-background-regions (&optional unhighlight)
1497 (ediff-paint-background-regions-in-one-buffer
1498 'A unhighlight)
1499 (ediff-paint-background-regions-in-one-buffer
1500 'B unhighlight)
1501 (ediff-paint-background-regions-in-one-buffer
1502 'C unhighlight)
1503 (ediff-paint-background-regions-in-one-buffer
1504 'Ancestor unhighlight))
1507 ;; arg is a record for a given diff in a difference vector
1508 ;; this record is itself a vector
1509 (defsubst ediff-clear-fine-diff-vector (diff-record)
1510 (if diff-record
1511 (mapc 'ediff-delete-overlay
1512 (ediff-get-fine-diff-vector-from-diff-record diff-record))))
1514 (defsubst ediff-clear-fine-differences-in-one-buffer (n buf-type)
1515 (ediff-clear-fine-diff-vector (ediff-get-difference n buf-type))
1516 (ediff-set-fine-diff-vector n buf-type nil))
1518 (defsubst ediff-clear-fine-differences (n)
1519 (ediff-clear-fine-differences-in-one-buffer n 'A)
1520 (ediff-clear-fine-differences-in-one-buffer n 'B)
1521 (if ediff-3way-job
1522 (ediff-clear-fine-differences-in-one-buffer n 'C)))
1525 (defsubst ediff-mouse-event-p (event)
1526 (if (featurep 'xemacs)
1527 (button-event-p event)
1528 (string-match "mouse" (format "%S" (event-basic-type event)))))
1531 (defsubst ediff-key-press-event-p (event)
1532 (if (featurep 'xemacs)
1533 (key-press-event-p event)
1534 (or (char-or-string-p event) (symbolp event))))
1536 (defun ediff-event-point (event)
1537 (cond ((ediff-mouse-event-p event)
1538 (if (featurep 'xemacs)
1539 (event-point event)
1540 (posn-point (event-start event))))
1541 ((ediff-key-press-event-p event)
1542 (point))
1543 (t (error "Error"))))
1545 (defun ediff-event-buffer (event)
1546 (cond ((ediff-mouse-event-p event)
1547 (if (featurep 'xemacs)
1548 (event-buffer event)
1549 (window-buffer (posn-window (event-start event)))))
1550 ((ediff-key-press-event-p event)
1551 (current-buffer))
1552 (t (error "Error"))))
1554 (defun ediff-event-key (event-or-key)
1555 (if (featurep 'xemacs)
1556 ;;(if (eventp event-or-key) (event-key event-or-key) event-or-key)
1557 (if (eventp event-or-key) (event-to-character event-or-key t t) event-or-key)
1558 event-or-key))
1560 (defun ediff-last-command-char ()
1561 (ediff-event-key last-command-event))
1564 (defsubst ediff-frame-iconified-p (frame)
1565 (and (ediff-window-display-p) (frame-live-p frame)
1566 (if (featurep 'xemacs)
1567 (frame-iconified-p frame)
1568 (eq (frame-visible-p frame) 'icon))))
1570 (defsubst ediff-window-visible-p (wind)
1571 ;; under TTY, window-live-p also means window is visible
1572 (and (window-live-p wind)
1573 (or (not (ediff-window-display-p))
1574 (frame-visible-p (window-frame wind)))))
1577 (defsubst ediff-frame-char-width (frame)
1578 (if (featurep 'xemacs)
1579 (/ (frame-pixel-width frame) (frame-width frame))
1580 (frame-char-width frame)))
1582 (defun ediff-reset-mouse (&optional frame do-not-grab-mouse)
1583 (or frame (setq frame (selected-frame)))
1584 (if (ediff-window-display-p)
1585 (let ((frame-or-wind frame))
1586 (if (featurep 'xemacs)
1587 (setq frame-or-wind (frame-selected-window frame)))
1588 (or do-not-grab-mouse
1589 ;; don't set mouse if the user said to never do this
1590 (not ediff-grab-mouse)
1591 ;; Don't grab on quit, if the user doesn't want to.
1592 ;; If ediff-grab-mouse = t, then mouse won't be grabbed for
1593 ;; sessions that are not part of a group (this is done in
1594 ;; ediff-recenter). The condition below affects only terminating
1595 ;; sessions in session groups (in which case mouse is warped into
1596 ;; a meta buffer).
1597 (and (eq ediff-grab-mouse 'maybe)
1598 (memq this-command '(ediff-quit ediff-update-diffs)))
1599 (set-mouse-position frame-or-wind 1 0))
1602 (defsubst ediff-spy-after-mouse ()
1603 (setq ediff-mouse-pixel-position (mouse-pixel-position)))
1605 ;; It is not easy to find out when the user grabs the mouse, since emacs and
1606 ;; xemacs behave differently when mouse is not in any frame. Also, this is
1607 ;; sensitive to when the user grabbed mouse. Not used for now.
1608 (defun ediff-user-grabbed-mouse ()
1609 (if ediff-mouse-pixel-position
1610 (cond ((not (eq (car ediff-mouse-pixel-position)
1611 (car (mouse-pixel-position)))))
1612 ((and (car (cdr ediff-mouse-pixel-position))
1613 (car (cdr (mouse-pixel-position)))
1614 (cdr (cdr ediff-mouse-pixel-position))
1615 (cdr (cdr (mouse-pixel-position))))
1616 (not (and (< (abs (- (car (cdr ediff-mouse-pixel-position))
1617 (car (cdr (mouse-pixel-position)))))
1618 ediff-mouse-pixel-threshold)
1619 (< (abs (- (cdr (cdr ediff-mouse-pixel-position))
1620 (cdr (cdr (mouse-pixel-position)))))
1621 ediff-mouse-pixel-threshold))))
1622 (t nil))))
1624 (defsubst ediff-frame-char-height (frame)
1625 (if (featurep 'xemacs)
1626 (glyph-height ediff-H-glyph (frame-selected-window frame))
1627 (frame-char-height frame)))
1629 ;; Some overlay functions
1631 (defsubst ediff-overlay-start (overl)
1632 (if (ediff-overlayp overl)
1633 (if (featurep 'xemacs)
1634 (extent-start-position overl)
1635 (overlay-start overl))))
1637 (defsubst ediff-overlay-end (overl)
1638 (if (ediff-overlayp overl)
1639 (if (featurep 'xemacs)
1640 (extent-end-position overl)
1641 (overlay-end overl))))
1643 (defsubst ediff-empty-overlay-p (overl)
1644 (= (ediff-overlay-start overl) (ediff-overlay-end overl)))
1646 ;; like overlay-buffer in Emacs. In XEmacs, returns nil if the extent is
1647 ;; dead. Otherwise, works like extent-buffer
1648 (defun ediff-overlay-buffer (overl)
1649 (if (featurep 'xemacs)
1650 (and (extent-live-p overl) (extent-object overl))
1651 (overlay-buffer overl)))
1653 ;; like overlay-get in Emacs. In XEmacs, returns nil if the extent is
1654 ;; dead. Otherwise, like extent-property
1655 (defun ediff-overlay-get (overl property)
1656 (if (featurep 'xemacs)
1657 (and (extent-live-p overl) (extent-property overl property))
1658 (overlay-get overl property)))
1661 ;; These two functions are here because XEmacs refuses to
1662 ;; handle overlays whose buffers were deleted.
1663 (defun ediff-move-overlay (overlay beg end &optional buffer)
1664 "Calls `move-overlay' in Emacs and `set-extent-endpoints' in Lemacs.
1665 Checks if overlay's buffer exists before actually doing the move."
1666 (let ((buf (and overlay (ediff-overlay-buffer overlay))))
1667 (if (ediff-buffer-live-p buf)
1668 (if (featurep 'xemacs)
1669 (set-extent-endpoints overlay beg end)
1670 (move-overlay overlay beg end buffer))
1671 ;; buffer's dead
1672 (if overlay
1673 (ediff-delete-overlay overlay)))))
1675 (defun ediff-overlay-put (overlay prop value)
1676 "Calls `overlay-put' or `set-extent-property' depending on Emacs version.
1677 Checks if overlay's buffer exists."
1678 (if (ediff-buffer-live-p (ediff-overlay-buffer overlay))
1679 (if (featurep 'xemacs)
1680 (set-extent-property overlay prop value)
1681 (overlay-put overlay prop value))
1682 (ediff-delete-overlay overlay)))
1684 ;; temporarily uses DIR to abbreviate file name
1685 ;; if DIR is nil, use default-directory
1686 (defun ediff-abbreviate-file-name (file &optional dir)
1687 (cond ((stringp dir)
1688 (let ((directory-abbrev-alist (list (cons dir ""))))
1689 (abbreviate-file-name file)))
1691 (if (featurep 'xemacs)
1692 ;; XEmacs requires addl argument
1693 (abbreviate-file-name file t)
1694 (abbreviate-file-name file)))))
1696 ;; Takes a directory and returns the parent directory.
1697 ;; does nothing to `/'. If the ARG is a regular file,
1698 ;; strip the file AND the last dir.
1699 (defun ediff-strip-last-dir (dir)
1700 (if (not (stringp dir)) (setq dir default-directory))
1701 (setq dir (expand-file-name dir))
1702 (or (file-directory-p dir) (setq dir (file-name-directory dir)))
1703 (let* ((pos (1- (length dir)))
1704 (last-char (aref dir pos)))
1705 (if (and (> pos 0) (= last-char ?/))
1706 (setq dir (substring dir 0 pos)))
1707 (ediff-abbreviate-file-name (file-name-directory dir))))
1709 (defun ediff-truncate-string-left (str newlen)
1710 ;; leave space for ... on the left
1711 (let ((len (length str))
1712 substr)
1713 (if (<= len newlen)
1715 (setq newlen (max 0 (- newlen 3)))
1716 (setq substr (substring str (max 0 (- len 1 newlen))))
1717 (concat "..." substr))))
1719 (defsubst ediff-nonempty-string-p (string)
1720 (and (stringp string) (not (string= string ""))))
1722 (unless (fboundp 'subst-char-in-string)
1723 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1724 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1725 Unless optional argument INPLACE is non-nil, return a new string."
1726 (let ((i (length string))
1727 (newstr (if inplace string (copy-sequence string))))
1728 (while (> i 0)
1729 (setq i (1- i))
1730 (if (eq (aref newstr i) fromchar)
1731 (aset newstr i tochar)))
1732 newstr)))
1734 (unless (fboundp 'format-message)
1735 (defalias 'format-message 'format))
1737 (defun ediff-abbrev-jobname (jobname)
1738 (cond ((eq jobname 'ediff-directories)
1739 "Compare two directories")
1740 ((eq jobname 'ediff-files)
1741 "Compare two files")
1742 ((eq jobname 'ediff-buffers)
1743 "Compare two buffers")
1744 ((eq jobname 'ediff-directories3)
1745 "Compare three directories")
1746 ((eq jobname 'ediff-files3)
1747 "Compare three files")
1748 ((eq jobname 'ediff-buffers3)
1749 "Compare three buffers")
1750 ((eq jobname 'ediff-revision)
1751 "Compare file with a version")
1752 ((eq jobname 'ediff-directory-revisions)
1753 "Compare dir files with versions")
1754 ((eq jobname 'ediff-merge-directory-revisions)
1755 "Merge dir files with versions")
1756 ((eq jobname 'ediff-merge-directory-revisions-with-ancestor)
1757 "Merge dir versions via ancestors")
1759 (capitalize
1760 (subst-char-in-string ?- ?\s (substring (symbol-name jobname) 6))))
1764 ;; If ediff modified mode line, strip the modification
1765 (defsubst ediff-strip-mode-line-format ()
1766 (and (consp mode-line-format)
1767 (member (car mode-line-format)
1768 '(" A: " " B: " " C: " " Ancestor: "))
1769 (setq mode-line-format (nth 2 mode-line-format))))
1771 ;; Verify that we have a difference selected.
1772 (defsubst ediff-valid-difference-p (&optional n)
1773 (or n (setq n ediff-current-difference))
1774 (and (>= n 0) (< n ediff-number-of-differences)))
1776 (defsubst ediff-show-all-diffs (_n)
1777 "Don't skip difference regions."
1778 nil)
1780 (defsubst ediff-message-if-verbose (string &rest args)
1781 (if ediff-verbose-p
1782 (apply 'message string args)))
1784 (defun ediff-file-attributes (filename attr-number)
1785 (if (ediff-listable-file filename)
1786 (nth attr-number (file-attributes filename))
1790 (defsubst ediff-file-size (filename)
1791 (ediff-file-attributes filename 7))
1792 (defsubst ediff-file-modtime (filename)
1793 (ediff-file-attributes filename 5))
1796 (defun ediff-convert-standard-filename (fname)
1797 (if (fboundp 'convert-standard-filename)
1798 (convert-standard-filename fname)
1799 fname))
1801 (if (featurep 'emacs)
1802 (defalias 'ediff-with-syntax-table 'with-syntax-table)
1803 (if (fboundp 'with-syntax-table)
1804 (defalias 'ediff-with-syntax-table 'with-syntax-table)
1805 ;; stolen from subr.el in emacs 21
1806 (defmacro ediff-with-syntax-table (table &rest body)
1807 (let ((old-table (make-symbol "table"))
1808 (old-buffer (make-symbol "buffer")))
1809 `(let ((,old-table (syntax-table))
1810 (,old-buffer (current-buffer)))
1811 (unwind-protect
1812 (progn
1813 (set-syntax-table (copy-syntax-table ,table))
1814 ,@body)
1815 (save-current-buffer
1816 (set-buffer ,old-buffer)
1817 (set-syntax-table ,old-table))))))))
1820 (provide 'ediff-init)
1824 ;; Local Variables:
1825 ;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1826 ;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1827 ;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1828 ;; End:
1830 ;;; ediff-init.el ends here