* lisp/desktop.el: Disable restore frameset if in non-graphic display.
[emacs.git] / lisp / vc / ediff-init.el
blobb0d5d2fabc49e8c3a7f89b963683c4df4cfb09a8
1 ;;; ediff-init.el --- Macros, variables, and defsubsts used by Ediff
3 ;; Copyright (C) 1994-2016 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 (defconst ediff-difference-vector-alist
154 '((A . ediff-difference-vector-A)
155 (B . ediff-difference-vector-B)
156 (C . ediff-difference-vector-C)
157 (Ancestor . ediff-difference-vector-Ancestor)))
159 (defmacro ediff-get-difference (n buf-type)
160 `(aref
161 (symbol-value
162 (ediff-get-symbol-from-alist
163 ,buf-type ediff-difference-vector-alist))
164 ,n))
166 ;; Tell if it has been previously determined that the region has
167 ;; no diffs other than the white space and newlines
168 ;; The argument, N, is the diff region number used by Ediff to index the
169 ;; diff vector. It is 1 less than the number seen by the user.
170 ;; Returns:
171 ;; t if the diffs are whitespace in all buffers
172 ;; 'A (in 3-buf comparison only) if there are only whitespace
173 ;; diffs in bufs B and C
174 ;; 'B (in 3-buf comparison only) if there are only whitespace
175 ;; diffs in bufs A and C
176 ;; 'C (in 3-buf comparison only) if there are only whitespace
177 ;; diffs in bufs A and B
179 ;; A Difference Vector has the form:
180 ;; [diff diff diff ...]
181 ;; where each diff has the form:
182 ;; [overlay fine-diff-vector no-fine-diffs-flag state-of-difference]
183 ;; fine-diff-vector is a vector [fine-diff fine-diff fine-diff ...]
184 ;; no-fine-diffs-flag says if there are fine differences.
185 ;; state-of-difference is A, B, C, or nil, indicating which buffer is
186 ;; different from the other two (used only in 3-way jobs).
187 (defmacro ediff-no-fine-diffs-p (n)
188 `(aref (ediff-get-difference ,n 'A) 2))
190 (defmacro ediff-get-diff-overlay-from-diff-record (diff-rec)
191 `(aref ,diff-rec 0))
193 (defmacro ediff-get-diff-overlay (n buf-type)
194 `(ediff-get-diff-overlay-from-diff-record
195 (ediff-get-difference ,n ,buf-type)))
197 (defmacro ediff-get-fine-diff-vector-from-diff-record (diff-rec)
198 `(aref ,diff-rec 1))
200 (defmacro ediff-set-fine-diff-vector (n buf-type fine-vec)
201 `(aset (ediff-get-difference ,n ,buf-type) 1 ,fine-vec))
203 (defmacro ediff-get-state-of-diff (n buf-type)
204 `(if (ediff-buffer-live-p ediff-buffer-C)
205 (aref (ediff-get-difference ,n ,buf-type) 3)))
206 (defmacro ediff-set-state-of-diff (n buf-type val)
207 `(aset (ediff-get-difference ,n ,buf-type) 3 ,val))
209 (defmacro ediff-get-state-of-merge (n)
210 `(if ediff-state-of-merge
211 (aref (aref ediff-state-of-merge ,n) 0)))
212 (defmacro ediff-set-state-of-merge (n val)
213 `(if ediff-state-of-merge
214 (aset (aref ediff-state-of-merge ,n) 0 ,val)))
216 (defmacro ediff-get-state-of-ancestor (n)
217 `(if ediff-state-of-merge
218 (aref (aref ediff-state-of-merge ,n) 1)))
220 ;; if flag is t, puts a mark on diff region saying that
221 ;; the differences are in white space only. If flag is nil,
222 ;; the region is marked as essential (i.e., differences are
223 ;; not just in the white space and newlines.)
224 (defmacro ediff-mark-diff-as-space-only (n flag)
225 `(aset (ediff-get-difference ,n 'A) 2 ,flag))
227 (defmacro ediff-get-fine-diff-vector (n buf-type)
228 `(ediff-get-fine-diff-vector-from-diff-record
229 (ediff-get-difference ,n ,buf-type)))
231 ;; Macro to switch to BUFFER, evaluate BODY, returns to original buffer.
232 ;; Doesn't save the point and mark.
233 ;; This is `with-current-buffer' with the added test for live buffers."
234 (defmacro ediff-with-current-buffer (buffer &rest body)
235 "Evaluates BODY in BUFFER."
236 (declare (indent 1) (debug (form body)))
237 `(if (ediff-buffer-live-p ,buffer)
238 (save-current-buffer
239 (set-buffer ,buffer)
240 ,@body)
241 (or (eq this-command 'ediff-quit)
242 (error ediff-KILLED-VITAL-BUFFER))
246 (defsubst ediff-multiframe-setup-p ()
247 (and (ediff-window-display-p) ediff-multiframe))
249 (defmacro ediff-narrow-control-frame-p ()
250 `(and (ediff-multiframe-setup-p)
251 (equal ediff-help-message ediff-brief-message-string)))
253 (defmacro ediff-3way-comparison-job ()
254 `(memq
255 ediff-job-name
256 '(ediff-files3 ediff-buffers3)))
257 (ediff-defvar-local ediff-3way-comparison-job nil "")
259 (defmacro ediff-merge-job ()
260 `(memq
261 ediff-job-name
262 '(ediff-merge-files
263 ediff-merge-buffers
264 ediff-merge-files-with-ancestor
265 ediff-merge-buffers-with-ancestor
266 ediff-merge-revisions
267 ediff-merge-revisions-with-ancestor)))
268 (ediff-defvar-local ediff-merge-job nil "")
270 (defmacro ediff-patch-job ()
271 `(eq ediff-job-name 'epatch))
273 (defmacro ediff-merge-with-ancestor-job ()
274 `(memq
275 ediff-job-name
276 '(ediff-merge-files-with-ancestor
277 ediff-merge-buffers-with-ancestor
278 ediff-merge-revisions-with-ancestor)))
279 (ediff-defvar-local ediff-merge-with-ancestor-job nil "")
281 (defmacro ediff-3way-job ()
282 `(or ediff-3way-comparison-job ediff-merge-job))
283 (ediff-defvar-local ediff-3way-job nil "")
285 ;; A diff3 job is like a 3way job, but ediff-merge doesn't require the use
286 ;; of diff3.
287 (defmacro ediff-diff3-job ()
288 `(or ediff-3way-comparison-job
289 ediff-merge-with-ancestor-job))
290 (ediff-defvar-local ediff-diff3-job nil "")
292 (defmacro ediff-windows-job ()
293 `(memq ediff-job-name '(ediff-windows-wordwise ediff-windows-linewise)))
294 (ediff-defvar-local ediff-windows-job nil "")
296 (defmacro ediff-word-mode-job ()
297 `(memq ediff-job-name '(ediff-windows-wordwise ediff-regions-wordwise)))
298 (ediff-defvar-local ediff-word-mode-job nil "")
300 (defmacro ediff-narrow-job ()
301 `(memq ediff-job-name '(ediff-windows-wordwise
302 ediff-regions-wordwise
303 ediff-windows-linewise
304 ediff-regions-linewise)))
305 (ediff-defvar-local ediff-narrow-job nil "")
307 ;; Note: ediff-merge-directory-revisions-with-ancestor is not treated as an
308 ;; ancestor metajob, since it behaves differently.
309 (defsubst ediff-ancestor-metajob (&optional metajob)
310 (memq (or metajob ediff-metajob-name)
311 '(ediff-merge-directories-with-ancestor
312 ediff-merge-filegroups-with-ancestor)))
313 (defsubst ediff-revision-metajob (&optional metajob)
314 (memq (or metajob ediff-metajob-name)
315 '(ediff-directory-revisions
316 ediff-merge-directory-revisions
317 ediff-merge-directory-revisions-with-ancestor)))
318 (defsubst ediff-patch-metajob (&optional metajob)
319 (memq (or metajob ediff-metajob-name)
320 '(ediff-multifile-patch)))
321 ;; metajob involving only one group of files, such as multipatch or directory
322 ;; revision
323 (defsubst ediff-one-filegroup-metajob (&optional metajob)
324 (or (ediff-revision-metajob metajob)
325 (ediff-patch-metajob metajob)
326 ;; add more here
328 ;; jobs suitable for the operation of collecting diffs into a multifile patch
329 (defsubst ediff-collect-diffs-metajob (&optional metajob)
330 (memq (or metajob ediff-metajob-name)
331 '(ediff-directories
332 ediff-merge-directories
333 ediff-merge-directories-with-ancestor
334 ediff-directory-revisions
335 ediff-merge-directory-revisions
336 ediff-merge-directory-revisions-with-ancestor
337 ;; add more here
339 (defsubst ediff-merge-metajob (&optional metajob)
340 (memq (or metajob ediff-metajob-name)
341 '(ediff-merge-directories
342 ediff-merge-directories-with-ancestor
343 ediff-merge-directory-revisions
344 ediff-merge-directory-revisions-with-ancestor
345 ediff-merge-filegroups-with-ancestor
346 ;; add more here
349 (defsubst ediff-metajob3 (&optional metajob)
350 (memq (or metajob ediff-metajob-name)
351 '(ediff-merge-directories-with-ancestor
352 ediff-merge-filegroups-with-ancestor
353 ediff-directories3
354 ediff-filegroups3)))
355 (defsubst ediff-comparison-metajob3 (&optional metajob)
356 (memq (or metajob ediff-metajob-name)
357 '(ediff-directories3 ediff-filegroups3)))
359 ;; with no argument, checks if we are in ediff-control-buffer
360 ;; with argument, checks if we are in ediff-meta-buffer
361 (defun ediff-in-control-buffer-p (&optional meta-buf-p)
362 (and (boundp 'ediff-control-buffer)
363 (eq (if meta-buf-p ediff-meta-buffer ediff-control-buffer)
364 (current-buffer))))
366 (defsubst ediff-barf-if-not-control-buffer (&optional meta-buf-p)
367 (or (ediff-in-control-buffer-p meta-buf-p)
368 (error "%S: This command runs in Ediff Control Buffer only!"
369 this-command)))
371 (defgroup ediff-highlighting nil
372 "Highlighting of difference regions in Ediff."
373 :prefix "ediff-"
374 :group 'ediff)
376 (defgroup ediff-merge nil
377 "Merging utilities."
378 :prefix "ediff-"
379 :group 'ediff)
381 (defgroup ediff-hook nil
382 "Hooks run by Ediff."
383 :prefix "ediff-"
384 :group 'ediff)
386 ;; Hook variables
388 (defcustom ediff-before-setup-hook nil
389 "Hooks to run before Ediff begins to set up windows and buffers.
390 This hook can be used to save the previous window config, which can be restored
391 on ediff-quit or ediff-suspend."
392 :type 'hook
393 :group 'ediff-hook)
394 (defcustom ediff-before-setup-windows-hook nil
395 "Hooks to run before Ediff sets its window configuration.
396 This hook is run every time when Ediff arranges its windows.
397 This happens each time Ediff detects that the windows were messed up by the
398 user."
399 :type 'hook
400 :group 'ediff-hook)
401 (defcustom ediff-after-setup-windows-hook nil
402 "Hooks to run after Ediff sets its window configuration.
403 This can be used to set up control window or icon in a desired place."
404 :type 'hook
405 :group 'ediff-hook)
406 (defcustom ediff-before-setup-control-frame-hook nil
407 "Hooks run before setting up the frame to display Ediff Control Panel.
408 Can be used to change control frame parameters to position it where it
409 is desirable."
410 :type 'hook
411 :group 'ediff-hook)
412 (defcustom ediff-after-setup-control-frame-hook nil
413 "Hooks run after setting up the frame to display Ediff Control Panel.
414 Can be used to move the frame where it is desired."
415 :type 'hook
416 :group 'ediff-hook)
417 (defcustom ediff-startup-hook nil
418 "Hooks to run in the control buffer after Ediff has been set up and is ready for the job."
419 :type 'hook
420 :group 'ediff-hook)
421 (defcustom ediff-select-hook nil
422 "Hooks to run after a difference has been selected."
423 :type 'hook
424 :group 'ediff-hook)
425 (defcustom ediff-unselect-hook nil
426 "Hooks to run after a difference has been unselected."
427 :type 'hook
428 :group 'ediff-hook)
429 (defcustom ediff-prepare-buffer-hook nil
430 "Hooks run after buffers A, B, and C are set up.
431 For each buffer, the hooks are run with that buffer made current."
432 :type 'hook
433 :group 'ediff-hook)
434 (defcustom ediff-load-hook nil
435 "Hook run after Ediff is loaded. Can be used to change defaults."
436 :type 'hook
437 :group 'ediff-hook)
439 (defcustom ediff-mode-hook nil
440 "Hook run just after ediff-mode is set up in the control buffer.
441 This is done before any windows or frames are created. One can use it to
442 set local variables that determine how the display looks like."
443 :type 'hook
444 :group 'ediff-hook)
445 (defcustom ediff-keymap-setup-hook nil
446 "Hook run just after the default bindings in Ediff keymap are set up."
447 :type 'hook
448 :group 'ediff-hook)
450 (defcustom ediff-display-help-hook nil
451 "Hooks run after preparing the help message."
452 :type 'hook
453 :group 'ediff-hook)
455 (defcustom ediff-suspend-hook nil
456 "Hooks to run in the Ediff control buffer when Ediff is suspended."
457 :type 'hook
458 :group 'ediff-hook)
459 (defcustom ediff-quit-hook nil
460 "Hooks to run in the Ediff control buffer after finishing Ediff."
461 :type 'hook
462 :group 'ediff-hook)
463 (defcustom ediff-cleanup-hook nil
464 "Hooks to run on exiting Ediff but before killing the control and variant buffers."
465 :type 'hook
466 :group 'ediff-hook)
468 ;; Error messages
469 (defconst ediff-KILLED-VITAL-BUFFER
470 "You have killed a vital Ediff buffer---you must leave Ediff now!")
471 (defconst ediff-NO-DIFFERENCES
472 "Sorry, comparison of identical variants is not what I am made for...")
473 (defconst ediff-BAD-DIFF-NUMBER
474 ;; %S stands for this-command, %d - diff number, %d - max diff
475 "%S: Bad diff region number, %d. Valid numbers are 1 to %d")
476 (defconst ediff-BAD-INFO (format "
477 *** The Info file for Ediff, a part of the standard distribution
478 *** of %sEmacs, does not seem to be properly installed.
480 *** Please contact your system administrator. "
481 (if (featurep 'xemacs) "X" "")))
483 ;; Selective browsing
485 (ediff-defvar-local ediff-skip-diff-region-function 'ediff-show-all-diffs
486 "Function that determines the next/previous diff region to show.
487 Should return t for regions to be ignored and nil otherwise.
488 This function gets a region number as an argument. The region number
489 is the one used internally by Ediff. It is 1 less than the number seen
490 by the user.")
492 (ediff-defvar-local ediff-hide-regexp-matches-function
493 'ediff-hide-regexp-matches
494 "Function to use in determining which regions to hide.
495 See the documentation string of `ediff-hide-regexp-matches' for details.")
496 (ediff-defvar-local ediff-focus-on-regexp-matches-function
497 'ediff-focus-on-regexp-matches
498 "Function to use in determining which regions to focus on.
499 See the documentation string of `ediff-focus-on-regexp-matches' for details.")
501 ;; Regexp that determines buf A regions to focus on when skipping to diff
502 (ediff-defvar-local ediff-regexp-focus-A "" "")
503 ;; Regexp that determines buf B regions to focus on when skipping to diff
504 (ediff-defvar-local ediff-regexp-focus-B "" "")
505 ;; Regexp that determines buf C regions to focus on when skipping to diff
506 (ediff-defvar-local ediff-regexp-focus-C "" "")
507 ;; connective that determines whether to focus regions that match both or
508 ;; one of the regexps
509 (ediff-defvar-local ediff-focus-regexp-connective 'and "")
511 ;; Regexp that determines buf A regions to ignore when skipping to diff
512 (ediff-defvar-local ediff-regexp-hide-A "" "")
513 ;; Regexp that determines buf B regions to ignore when skipping to diff
514 (ediff-defvar-local ediff-regexp-hide-B "" "")
515 ;; Regexp that determines buf C regions to ignore when skipping to diff
516 (ediff-defvar-local ediff-regexp-hide-C "" "")
517 ;; connective that determines whether to hide regions that match both or
518 ;; one of the regexps
519 (ediff-defvar-local ediff-hide-regexp-connective 'and "")
522 ;;; Copying difference regions between buffers.
524 ;; A list of killed diffs.
525 ;; A diff is saved here if it is replaced by a diff
526 ;; from another buffer. This alist has the form:
527 ;; \((num (buff-object . diff) (buff-object . diff) (buff-object . diff)) ...),
528 ;; where some buffer-objects may be missing.
529 (ediff-defvar-local ediff-killed-diffs-alist nil "")
531 ;; Syntax table to use in ediff-forward-word-function
532 ;; This is chosen by a heuristic. The important thing is for all buffers to
533 ;; have the same syntax table. Which is not too important.
534 (ediff-defvar-local ediff-syntax-table nil "")
537 ;; Highlighting
538 (defcustom ediff-before-flag-bol (if (featurep 'xemacs) (make-glyph "->>") "->>")
539 "Flag placed before a highlighted block of differences, if block starts at beginning of a line."
540 :type 'string
541 :tag "Region before-flag at beginning of line"
542 :group 'ediff)
544 (defcustom ediff-after-flag-eol (if (featurep 'xemacs) (make-glyph "<<-") "<<-")
545 "Flag placed after a highlighted block of differences, if block ends at end of a line."
546 :type 'string
547 :tag "Region after-flag at end of line"
548 :group 'ediff)
550 (defcustom ediff-before-flag-mol (if (featurep 'xemacs) (make-glyph "->>") "->>")
551 "Flag placed before a highlighted block of differences, if block starts in mid-line."
552 :type 'string
553 :tag "Region before-flag in the middle of line"
554 :group 'ediff)
555 (defcustom ediff-after-flag-mol (if (featurep 'xemacs) (make-glyph "<<-") "<<-")
556 "Flag placed after a highlighted block of differences, if block ends in mid-line."
557 :type 'string
558 :tag "Region after-flag in the middle of line"
559 :group 'ediff)
562 (defcustom ediff-use-faces t
563 "If t, differences are highlighted using faces, if device supports faces.
564 If nil, differences are highlighted using ASCII flags, ediff-before-flag
565 and ediff-after-flag. On a non-window system, differences are always
566 highlighted using ASCII flags."
567 :type 'boolean
568 :group 'ediff-highlighting)
569 (make-variable-buffer-local 'ediff-use-faces)
570 (put 'ediff-use-faces 'permanent-local t)
572 ;; this indicates that diff regions are word-size, so fine diffs are
573 ;; permanently nixed; used in ediff-windows-wordwise and ediff-regions-wordwise
574 (ediff-defvar-local ediff-word-mode nil "")
575 ;; Name of the job (ediff-files, ediff-windows, etc.)
576 (ediff-defvar-local ediff-job-name nil "")
578 ;; Narrowing and ediff-region/windows support
579 ;; This is a list (overlay-A overlay-B overlay-C)
580 ;; If set, Ediff compares only those parts of buffers A/B/C that lie within
581 ;; the bounds of these overlays.
582 (ediff-defvar-local ediff-narrow-bounds nil "")
584 ;; List (overlay-A overlay-B overlay-C), where each overlay spans the
585 ;; entire corresponding buffer.
586 (ediff-defvar-local ediff-wide-bounds nil "")
588 ;; Current visibility boundaries in buffers A, B, and C.
589 ;; This is also a list of overlays. When the user toggles narrow/widen,
590 ;; this list changes from ediff-wide-bounds to ediff-narrow-bounds.
591 ;; and back.
592 (ediff-defvar-local ediff-visible-bounds nil "")
594 (ediff-defvar-local ediff-start-narrowed t
595 "Non-nil means start narrowed, if doing ediff-windows-* or ediff-regions-*")
596 (ediff-defvar-local ediff-quit-widened t
597 "Non-nil means: when finished, Ediff widens buffers A/B.
598 Actually, Ediff restores the scope of visibility that existed at startup.")
600 (defcustom ediff-keep-variants t
601 "nil means prompt to remove unmodified buffers A/B/C at session end.
602 Supplying a prefix argument to the quit command `q' temporarily reverses the
603 meaning of this variable."
604 :type 'boolean
605 :group 'ediff)
607 (defcustom ediff-highlight-all-diffs t
608 "If nil, only the selected differences are highlighted.
609 Otherwise, all difference regions are highlighted, but the selected region is
610 shown in brighter colors."
611 :type 'boolean
612 :group 'ediff-highlighting)
613 (make-variable-buffer-local 'ediff-highlight-all-diffs)
614 (put 'ediff-highlight-all-diffs 'permanent-local t)
617 ;; The suffix of the control buffer name.
618 (ediff-defvar-local ediff-control-buffer-suffix nil "")
619 ;; Same as ediff-control-buffer-suffix, but without <,>.
620 ;; It's a number rather than string.
621 (ediff-defvar-local ediff-control-buffer-number nil "")
624 ;; The original values of ediff-protected-variables for buffer A
625 (ediff-defvar-local ediff-buffer-values-orig-A nil "")
626 ;; The original values of ediff-protected-variables for buffer B
627 (ediff-defvar-local ediff-buffer-values-orig-B nil "")
628 ;; The original values of ediff-protected-variables for buffer C
629 (ediff-defvar-local ediff-buffer-values-orig-C nil "")
630 ;; The original values of ediff-protected-variables for buffer Ancestor
631 (ediff-defvar-local ediff-buffer-values-orig-Ancestor nil "")
633 ;; association between buff-type and ediff-buffer-values-orig-*
634 (defconst ediff-buffer-values-orig-alist
635 '((A . ediff-buffer-values-orig-A)
636 (B . ediff-buffer-values-orig-B)
637 (C . ediff-buffer-values-orig-C)
638 (Ancestor . ediff-buffer-values-orig-Ancestor)))
640 ;; Buffer-local variables to be saved then restored during Ediff sessions
641 (defconst ediff-protected-variables '(
642 ;;buffer-read-only
643 mode-line-format))
645 ;; Vector of differences between the variants. Each difference is
646 ;; represented by a vector of two overlays plus a vector of fine diffs,
647 ;; plus a no-fine-diffs flag. The first overlay spans the
648 ;; difference region in the A buffer and the second overlays the diff in
649 ;; the B buffer. If a difference section is empty, the corresponding
650 ;; overlay's endpoints coincide.
652 ;; The precise form of a Difference Vector for one buffer is:
653 ;; [diff diff diff ...]
654 ;; where each diff has the form:
655 ;; [diff-overlay fine-diff-vector no-fine-diffs-flag state-of-diff]
656 ;; fine-diff-vector is a vector [fine-diff-overlay fine-diff-overlay ...]
657 ;; no-fine-diffs-flag says if there are fine differences.
658 ;; state-of-difference is A, B, C, or nil, indicating which buffer is
659 ;; different from the other two (used only in 3-way jobs.
660 (ediff-defvar-local ediff-difference-vector-A nil "")
661 (ediff-defvar-local ediff-difference-vector-B nil "")
662 (ediff-defvar-local ediff-difference-vector-C nil "")
663 (ediff-defvar-local ediff-difference-vector-Ancestor nil "")
664 ;; A-list of diff vector types associated with buffer types
665 (defconst ediff-difference-vector-alist
666 '((A . ediff-difference-vector-A)
667 (B . ediff-difference-vector-B)
668 (C . ediff-difference-vector-C)
669 (Ancestor . ediff-difference-vector-Ancestor)))
671 ;; [ status status status ...]
672 ;; Each status: [state-of-merge state-of-ancestor]
673 ;; state-of-merge is default-A, default-B, prefer-A, or prefer-B. It
674 ;; indicates the way a diff region was created in buffer C.
675 ;; state-of-ancestor says if the corresponding region in ancestor buffer is
676 ;; empty.
677 (ediff-defvar-local ediff-state-of-merge nil "")
679 ;; The difference that is currently selected.
680 (ediff-defvar-local ediff-current-difference -1 "")
681 ;; Number of differences found.
682 (ediff-defvar-local ediff-number-of-differences nil "")
684 ;; Buffer containing the output of diff, which is used by Ediff to step
685 ;; through files.
686 (ediff-defvar-local ediff-diff-buffer nil "")
687 ;; Like ediff-diff-buffer, but contains context diff. It is not used by
688 ;; Ediff, but it is saved in a file, if user requests so.
689 (ediff-defvar-local ediff-custom-diff-buffer nil "")
690 ;; Buffer used for diff-style fine differences between regions.
691 (ediff-defvar-local ediff-fine-diff-buffer nil "")
692 ;; Temporary buffer used for computing fine differences.
693 (defconst ediff-tmp-buffer " *ediff-tmp*" "")
694 ;; Buffer used for messages
695 (defconst ediff-msg-buffer " *ediff-message*" "")
696 ;; Buffer containing the output of diff when diff returns errors.
697 (ediff-defvar-local ediff-error-buffer nil "")
698 ;; Buffer to display debug info
699 (ediff-defvar-local ediff-debug-buffer "*ediff-debug*" "")
701 ;; List of ediff control panels associated with each buffer A/B/C/Ancestor.
702 ;; Not used any more, but may be needed in the future.
703 (ediff-defvar-local ediff-this-buffer-ediff-sessions nil "")
705 ;; to be deleted in due time
706 ;; List of difference overlays disturbed by working with the current diff.
707 (defvar ediff-disturbed-overlays nil "")
709 (defcustom ediff-version-control-package 'vc
710 "Version control package used.
711 Currently, Ediff supports vc.el, rcs.el, pcl-cvs.el, and generic-sc.el. The
712 standard Emacs interface to RCS, CVS, SCCS, etc., is vc.el. However, some
713 people find the other two packages more convenient. Set this variable to the
714 appropriate symbol: `rcs', `pcl-cvs', or `generic-sc' if you so desire."
715 :type 'symbol
716 :group 'ediff)
718 (defcustom ediff-coding-system-for-read 'raw-text
719 "The coding system for read to use when running the diff program as a subprocess.
720 In most cases, the default will do. However, under certain circumstances in
721 MS-Windows you might need to use something like `raw-text-dos' here.
722 So, if the output that your diff program sends to Emacs contains extra ^M's,
723 you might need to experiment here, if the default or `raw-text-dos' doesn't
724 work."
725 :type 'symbol
726 :group 'ediff)
728 (defcustom ediff-coding-system-for-write (if (featurep 'xemacs)
729 'escape-quoted
730 'emacs-internal)
731 "The coding system for write to use when writing out difference regions
732 to temp files in buffer jobs and when Ediff needs to find fine differences."
733 :type 'symbol
734 :group 'ediff)
737 (defalias 'ediff-read-event
738 (if (featurep 'xemacs) 'next-command-event 'read-event))
740 (defalias 'ediff-overlayp
741 (if (featurep 'xemacs) 'extentp 'overlayp))
743 (defalias 'ediff-make-overlay
744 (if (featurep 'xemacs) 'make-extent 'make-overlay))
746 (defalias 'ediff-delete-overlay
747 (if (featurep 'xemacs) 'delete-extent 'delete-overlay))
749 ;; Assumes that emacs-major-version and emacs-minor-version are defined.
750 (defun ediff-check-version (op major minor &optional type-of-emacs)
751 "Check the current version against MAJOR and MINOR version numbers.
752 The comparison uses operator OP, which may be any of: =, >, >=, <, <=.
753 TYPE-OF-EMACS is either `emacs' or `xemacs'."
754 (declare (obsolete version< "23.1"))
755 (and (cond ((eq type-of-emacs 'xemacs) (featurep 'xemacs))
756 ((eq type-of-emacs 'emacs) (featurep 'emacs))
757 (t))
758 (cond ((eq op '=) (and (= emacs-minor-version minor)
759 (= emacs-major-version major)))
760 ((memq op '(> >= < <=))
761 (and (or (funcall op emacs-major-version major)
762 (= emacs-major-version major))
763 (if (= emacs-major-version major)
764 (funcall op emacs-minor-version minor)
765 t)))
767 (error "%S: Invalid op in ediff-check-version" op)))))
769 (defun ediff-color-display-p ()
770 (condition-case nil
771 (if (featurep 'xemacs)
772 (eq (device-class (selected-device)) 'color) ; xemacs form
773 (display-color-p)) ; emacs form
774 (error nil)))
777 ;; A var local to each control panel buffer. Indicates highlighting style
778 ;; in effect for this buffer: `face', `ascii',
779 ;; `off' -- turned off (on a dumb terminal only).
780 (ediff-defvar-local ediff-highlighting-style
781 (if (and (ediff-has-face-support-p) ediff-use-faces) 'face 'ascii)
785 (if (featurep 'xemacs)
786 (progn
787 (defalias 'ediff-display-pixel-width 'device-pixel-width)
788 (defalias 'ediff-display-pixel-height 'device-pixel-height))
789 (defalias 'ediff-display-pixel-width 'display-pixel-width)
790 (defalias 'ediff-display-pixel-height 'display-pixel-height))
792 ;; A-list of current-diff-overlay symbols associated with buf types
793 (defconst ediff-current-diff-overlay-alist
794 '((A . ediff-current-diff-overlay-A)
795 (B . ediff-current-diff-overlay-B)
796 (C . ediff-current-diff-overlay-C)
797 (Ancestor . ediff-current-diff-overlay-Ancestor)))
799 ;; A-list of current-diff-face-* symbols associated with buf types
800 (defconst ediff-current-diff-face-alist
801 '((A . ediff-current-diff-A)
802 (B . ediff-current-diff-B)
803 (C . ediff-current-diff-C)
804 (Ancestor . ediff-current-diff-Ancestor)))
807 (defun ediff-set-overlay-face (extent face)
808 (ediff-overlay-put extent 'face face)
809 (ediff-overlay-put extent 'help-echo (if face 'ediff-region-help-echo)))
811 (defun ediff-region-help-echo (extent-or-window &optional overlay _point)
812 (unless overlay
813 (setq overlay extent-or-window))
814 (let ((is-current (ediff-overlay-get overlay 'ediff))
815 (face (ediff-overlay-get overlay 'face))
816 (diff-num (ediff-overlay-get overlay 'ediff-diff-num))
817 face-help)
819 ;; This happens only for refinement overlays
820 (if (stringp face)
821 (setq face (intern face)))
822 (setq face-help (and face (get face 'ediff-help-echo)))
824 (cond ((and is-current diff-num) ; current diff region
825 (format "Difference region %S -- current" (1+ diff-num)))
826 (face-help) ; refinement of current diff region
827 (diff-num ; non-current
828 (format "Difference region %S -- non-current" (1+ diff-num)))
829 (t "")) ; none
833 (defun ediff-set-face-pixmap (face pixmap)
834 "Set face pixmap on a monochrome display."
835 (if (and (ediff-window-display-p) (not (ediff-color-display-p)))
836 (condition-case nil
837 (set-face-background-pixmap face pixmap)
838 (error
839 (message "Pixmap not found for %S: %s" (face-name face) pixmap)
840 (sit-for 1)))))
842 (defun ediff-hide-face (face)
843 (if (and (ediff-has-face-support-p)
844 (boundp 'add-to-list)
845 (boundp 'facemenu-unlisted-faces))
846 (add-to-list 'facemenu-unlisted-faces face)))
850 (defface ediff-current-diff-A
851 (if (featurep 'emacs)
852 '((((class color) (min-colors 88) (background light))
853 :background "#ffdddd")
854 (((class color) (min-colors 88) (background dark))
855 :background "#553333")
856 (((class color) (min-colors 16))
857 (:foreground "firebrick" :background "pale green"))
858 (((class color))
859 (:foreground "blue3" :background "yellow3"))
860 (t (:inverse-video t)))
861 '((((type tty)) (:foreground "blue3" :background "yellow3"))
862 (((class color)) (:foreground "firebrick" :background "pale green"))
863 (t (:inverse-video t))))
864 "Face for highlighting the selected difference in buffer A."
865 :group 'ediff-highlighting)
866 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
867 ;; this variable is set to nil, then again to the appropriate face.
868 (defvar ediff-current-diff-face-A 'ediff-current-diff-A
869 "Face for highlighting the selected difference in buffer A.
870 DO NOT CHANGE this variable. Instead, use the customization
871 widget to customize the actual face object `ediff-current-diff-A'
872 this variable represents.")
873 (ediff-hide-face ediff-current-diff-face-A)
874 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
875 ;; This means that some user customization may be trashed.
876 (and (featurep 'xemacs)
877 (ediff-has-face-support-p)
878 (not (ediff-color-display-p))
879 (copy-face 'modeline ediff-current-diff-face-A))
883 (defface ediff-current-diff-B
884 (if (featurep 'emacs)
885 '((((class color) (min-colors 88) (background light))
886 :background "#ddffdd")
887 (((class color) (min-colors 88) (background dark))
888 :background "#335533")
889 (((class color) (min-colors 16))
890 (:foreground "DarkOrchid" :background "Yellow"))
891 (((class color))
892 (:foreground "magenta3" :background "yellow3"
893 :weight bold))
894 (t (:inverse-video t)))
895 '((((type tty)) (:foreground "magenta3" :background "yellow3"
896 :weight bold))
897 (((class color)) (:foreground "DarkOrchid" :background "Yellow"))
898 (t (:inverse-video t))))
899 "Face for highlighting the selected difference in buffer B."
900 :group 'ediff-highlighting)
901 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
902 ;; this variable is set to nil, then again to the appropriate face.
903 (defvar ediff-current-diff-face-B 'ediff-current-diff-B
904 "Face for highlighting the selected difference in buffer B.
905 this variable. Instead, use the customization
906 widget to customize the actual face `ediff-current-diff-B'
907 this variable represents.")
908 (ediff-hide-face ediff-current-diff-face-B)
909 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
910 ;; This means that some user customization may be trashed.
911 (and (featurep 'xemacs)
912 (ediff-has-face-support-p)
913 (not (ediff-color-display-p))
914 (copy-face 'modeline ediff-current-diff-face-B))
917 (defface ediff-current-diff-C
918 (if (featurep 'emacs)
919 '((((class color) (min-colors 88) (background light))
920 :background "#ffffaa")
921 (((class color) (min-colors 88) (background dark))
922 :background "#888833")
923 (((class color) (min-colors 16))
924 (:foreground "Navy" :background "Pink"))
925 (((class color))
926 (:foreground "cyan3" :background "yellow3" :weight bold))
927 (t (:inverse-video t)))
928 '((((type tty)) (:foreground "cyan3" :background "yellow3" :weight bold))
929 (((class color)) (:foreground "Navy" :background "Pink"))
930 (t (:inverse-video t))))
931 "Face for highlighting the selected difference in buffer C."
932 :group 'ediff-highlighting)
933 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
934 ;; this variable is set to nil, then again to the appropriate face.
935 (defvar ediff-current-diff-face-C 'ediff-current-diff-C
936 "Face for highlighting the selected difference in buffer C.
937 DO NOT CHANGE this variable. Instead, use the customization
938 widget to customize the actual face object `ediff-current-diff-C'
939 this variable represents.")
940 (ediff-hide-face ediff-current-diff-face-C)
941 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
942 ;; This means that some user customization may be trashed.
943 (and (featurep 'xemacs)
944 (ediff-has-face-support-p)
945 (not (ediff-color-display-p))
946 (copy-face 'modeline ediff-current-diff-face-C))
949 (defface ediff-current-diff-Ancestor
950 (if (featurep 'emacs)
951 '((((class color) (min-colors 88))
952 (:background "VioletRed"))
953 (((class color) (min-colors 16))
954 (:foreground "Black" :background "VioletRed"))
955 (((class color))
956 (:foreground "black" :background "magenta3"))
957 (t (:inverse-video t)))
958 '((((type tty)) (:foreground "black" :background "magenta3"))
959 (((class color)) (:foreground "Black" :background "VioletRed"))
960 (t (:inverse-video t))))
961 "Face for highlighting the selected difference in buffer Ancestor."
962 :group 'ediff-highlighting)
963 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
964 ;; this variable is set to nil, then again to the appropriate face.
965 (defvar ediff-current-diff-face-Ancestor 'ediff-current-diff-Ancestor
966 "Face for highlighting the selected difference in buffer Ancestor.
967 DO NOT CHANGE this variable. Instead, use the customization
968 widget to customize the actual face object `ediff-current-diff-Ancestor'
969 this variable represents.")
970 (ediff-hide-face ediff-current-diff-face-Ancestor)
971 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
972 ;; This means that some user customization may be trashed.
973 (and (featurep 'xemacs)
974 (ediff-has-face-support-p)
975 (not (ediff-color-display-p))
976 (copy-face 'modeline ediff-current-diff-face-Ancestor))
979 (defface ediff-fine-diff-A
980 (if (featurep 'emacs)
981 '((((class color) (min-colors 88) (background light))
982 :background "#ffbbbb")
983 (((class color) (min-colors 88) (background dark))
984 :background "#aa2222")
985 (((class color) (min-colors 16))
986 (:foreground "Navy" :background "sky blue"))
987 (((class color))
988 (:foreground "white" :background "sky blue" :weight bold))
989 (t (:underline t :stipple "gray3")))
990 '((((type tty)) (:foreground "white" :background "sky blue" :weight bold))
991 (((class color)) (:foreground "Navy" :background "sky blue"))
992 (t (:underline t :stipple "gray3"))))
993 "Face for highlighting the refinement of the selected diff in buffer A."
994 :group 'ediff-highlighting)
995 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
996 ;; this variable is set to nil, then again to the appropriate face.
997 (defvar ediff-fine-diff-face-A 'ediff-fine-diff-A
998 "Face for highlighting the fine differences in buffer A.
999 DO NOT CHANGE this variable. Instead, use the customization
1000 widget to customize the actual face object `ediff-fine-diff-A'
1001 this variable represents.")
1002 (ediff-hide-face ediff-fine-diff-face-A)
1004 (defface ediff-fine-diff-B
1005 (if (featurep 'emacs)
1006 '((((class color) (min-colors 88) (background light))
1007 :background "#aaffaa")
1008 (((class color) (min-colors 88) (background dark))
1009 :background "#22aa22")
1010 (((class color) (min-colors 16))
1011 (:foreground "Black" :background "cyan"))
1012 (((class color))
1013 (:foreground "magenta3" :background "cyan3"))
1014 (t (:underline t :stipple "gray3")))
1015 '((((type tty)) (:foreground "magenta3" :background "cyan3"))
1016 (((class color)) (:foreground "Black" :background "cyan"))
1017 (t (:underline t :stipple "gray3"))))
1018 "Face for highlighting the refinement of the selected diff in buffer B."
1019 :group 'ediff-highlighting)
1020 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1021 ;; this variable is set to nil, then again to the appropriate face.
1022 (defvar ediff-fine-diff-face-B 'ediff-fine-diff-B
1023 "Face for highlighting the fine differences in buffer B.
1024 DO NOT CHANGE this variable. Instead, use the customization
1025 widget to customize the actual face object `ediff-fine-diff-B'
1026 this variable represents.")
1027 (ediff-hide-face ediff-fine-diff-face-B)
1029 (defface ediff-fine-diff-C
1030 (if (featurep 'emacs)
1031 '((((class color) (min-colors 88) (background light))
1032 :background "#ffff55")
1033 (((class color) (min-colors 88) (background dark))
1034 :background "#aaaa22")
1035 (((type pc))
1036 (:foreground "white" :background "Turquoise"))
1037 (((class color) (min-colors 16))
1038 (:foreground "Black" :background "Turquoise"))
1039 (((class color))
1040 (:foreground "yellow3" :background "Turquoise"
1041 :weight bold))
1042 (t (:underline t :stipple "gray3")))
1043 '((((type tty)) (:foreground "yellow3" :background "Turquoise"
1044 :weight bold))
1045 (((type pc)) (:foreground "white" :background "Turquoise"))
1046 (((class color)) (:foreground "Black" :background "Turquoise"))
1047 (t (:underline t :stipple "gray3"))))
1048 "Face for highlighting the refinement of the selected diff in buffer C."
1049 :group 'ediff-highlighting)
1050 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1051 ;; this variable is set to nil, then again to the appropriate face.
1052 (defvar ediff-fine-diff-face-C 'ediff-fine-diff-C
1053 "Face for highlighting the fine differences in buffer C.
1054 DO NOT CHANGE this variable. Instead, use the customization
1055 widget to customize the actual face object `ediff-fine-diff-C'
1056 this variable represents.")
1057 (ediff-hide-face ediff-fine-diff-face-C)
1059 (defface ediff-fine-diff-Ancestor
1060 (if (featurep 'emacs)
1061 '((((class color) (min-colors 88))
1062 (:background "Green"))
1063 (((class color) (min-colors 16))
1064 (:foreground "Black" :background "Green"))
1065 (((class color))
1066 (:foreground "red3" :background "green"))
1067 (t (:underline t :stipple "gray3")))
1068 '((((type tty)) (:foreground "red3" :background "green"))
1069 (((class color)) (:foreground "Black" :background "Green"))
1070 (t (:underline t :stipple "gray3"))))
1071 "Face for highlighting the refinement of the selected diff in the ancestor buffer.
1072 At present, this face is not used and no fine differences are computed for the
1073 ancestor buffer."
1074 :group 'ediff-highlighting)
1075 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1076 ;; this variable is set to nil, then again to the appropriate face.
1077 (defvar ediff-fine-diff-face-Ancestor 'ediff-fine-diff-Ancestor
1078 "Face for highlighting the fine differences in buffer Ancestor.
1079 DO NOT CHANGE this variable. Instead, use the customization
1080 widget to customize the actual face object `ediff-fine-diff-Ancestor'
1081 this variable represents.")
1082 (ediff-hide-face ediff-fine-diff-face-Ancestor)
1084 ;; Some installs don't have stipple or Stipple. So, try them in turn.
1085 (defvar stipple-pixmap
1086 (cond ((not (ediff-has-face-support-p)) nil)
1087 ((and (boundp 'x-bitmap-file-path)
1088 (locate-library "stipple" t x-bitmap-file-path)) "stipple")
1089 ((and (boundp 'mswindowsx-bitmap-file-path)
1090 (locate-library "stipple" t mswindowsx-bitmap-file-path)) "stipple")
1091 (t "Stipple")))
1093 (defface ediff-even-diff-A
1094 (if (featurep 'emacs)
1095 `((((type pc))
1096 (:foreground "green3" :background "light grey"))
1097 (((class color) (min-colors 88))
1098 (:background "light grey"))
1099 (((class color) (min-colors 16))
1100 (:foreground "Black" :background "light grey"))
1101 (((class color))
1102 (:foreground "red3" :background "light grey"
1103 :weight bold))
1104 (t (:italic t :stipple ,stipple-pixmap)))
1105 `((((type tty)) (:foreground "red3" :background "light grey"
1106 :weight bold))
1107 (((type pc)) (:foreground "green3" :background "light grey"))
1108 (((class color)) (:foreground "Black" :background "light grey"))
1109 (t (:italic t :stipple ,stipple-pixmap))))
1110 "Face for highlighting even-numbered non-current differences in buffer A."
1111 :group 'ediff-highlighting)
1112 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1113 ;; this variable is set to nil, then again to the appropriate face.
1114 (defvar ediff-even-diff-face-A 'ediff-even-diff-A
1115 "Face for highlighting even-numbered non-current differences in buffer A.
1116 DO NOT CHANGE this variable. Instead, use the customization
1117 widget to customize the actual face object `ediff-even-diff-A'
1118 this variable represents.")
1119 (ediff-hide-face ediff-even-diff-face-A)
1121 (defface ediff-even-diff-B
1122 (if (featurep 'emacs)
1123 `((((class color) (min-colors 88))
1124 (:background "Grey"))
1125 (((class color) (min-colors 16))
1126 (:foreground "White" :background "Grey"))
1127 (((class color))
1128 (:foreground "blue3" :background "Grey" :weight bold))
1129 (t (:italic t :stipple ,stipple-pixmap)))
1130 `((((type tty)) (:foreground "blue3" :background "Grey" :weight bold))
1131 (((class color)) (:foreground "White" :background "Grey"))
1132 (t (:italic t :stipple ,stipple-pixmap))))
1133 "Face for highlighting even-numbered non-current differences in buffer B."
1134 :group 'ediff-highlighting)
1135 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1136 ;; this variable is set to nil, then again to the appropriate face.
1137 (defvar ediff-even-diff-face-B 'ediff-even-diff-B
1138 "Face for highlighting even-numbered non-current differences in buffer B.
1139 DO NOT CHANGE this variable. Instead, use the customization
1140 widget to customize the actual face object `ediff-even-diff-B'
1141 this variable represents.")
1142 (ediff-hide-face ediff-even-diff-face-B)
1144 (defface ediff-even-diff-C
1145 (if (featurep 'emacs)
1146 `((((type pc))
1147 (:foreground "yellow3" :background "light grey"))
1148 (((class color) (min-colors 88))
1149 (:background "light grey"))
1150 (((class color) (min-colors 16))
1151 (:foreground "Black" :background "light grey"))
1152 (((class color))
1153 (:foreground "yellow3" :background "light grey"
1154 :weight bold))
1155 (t (:italic t :stipple ,stipple-pixmap)))
1156 `((((type tty)) (:foreground "yellow3" :background "light grey"
1157 :weight bold))
1158 (((type pc)) (:foreground "yellow3" :background "light grey"))
1159 (((class color)) (:foreground "Black" :background "light grey"))
1160 (t (:italic t :stipple ,stipple-pixmap))))
1161 "Face for highlighting even-numbered non-current differences in buffer C."
1162 :group 'ediff-highlighting)
1163 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1164 ;; this variable is set to nil, then again to the appropriate face.
1165 (defvar ediff-even-diff-face-C 'ediff-even-diff-C
1166 "Face for highlighting even-numbered non-current differences in buffer C.
1167 DO NOT CHANGE this variable. Instead, use the customization
1168 widget to customize the actual face object `ediff-even-diff-C'
1169 this variable represents.")
1170 (ediff-hide-face ediff-even-diff-face-C)
1172 (defface ediff-even-diff-Ancestor
1173 (if (featurep 'emacs)
1174 `((((type pc))
1175 (:foreground "cyan3" :background "light grey"))
1176 (((class color) (min-colors 88))
1177 (:background "Grey"))
1178 (((class color) (min-colors 16))
1179 (:foreground "White" :background "Grey"))
1180 (((class color))
1181 (:foreground "cyan3" :background "light grey"
1182 :weight bold))
1183 (t (:italic t :stipple ,stipple-pixmap)))
1184 `((((type tty)) (:foreground "cyan3" :background "light grey"
1185 :weight bold))
1186 (((type pc)) (:foreground "cyan3" :background "light grey"))
1187 (((class color)) (:foreground "White" :background "Grey"))
1188 (t (:italic t :stipple ,stipple-pixmap))))
1189 "Face for highlighting even-numbered non-current differences in the ancestor buffer."
1190 :group 'ediff-highlighting)
1191 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1192 ;; this variable is set to nil, then again to the appropriate face.
1193 (defvar ediff-even-diff-face-Ancestor 'ediff-even-diff-Ancestor
1194 "Face for highlighting even-numbered non-current differences in buffer Ancestor.
1195 DO NOT CHANGE this variable. Instead, use the customization
1196 widget to customize the actual face object `ediff-even-diff-Ancestor'
1197 this variable represents.")
1198 (ediff-hide-face ediff-even-diff-face-Ancestor)
1200 ;; Association between buffer types and even-diff-face symbols
1201 (defconst ediff-even-diff-face-alist
1202 '((A . ediff-even-diff-A)
1203 (B . ediff-even-diff-B)
1204 (C . ediff-even-diff-C)
1205 (Ancestor . ediff-even-diff-Ancestor)))
1207 (defface ediff-odd-diff-A
1208 (if (featurep 'emacs)
1209 '((((type pc))
1210 (:foreground "green3" :background "gray40"))
1211 (((class color) (min-colors 88))
1212 (:background "Grey"))
1213 (((class color) (min-colors 16))
1214 (:foreground "White" :background "Grey"))
1215 (((class color))
1216 (:foreground "red3" :background "black" :weight bold))
1217 (t (:italic t :stipple "gray1")))
1218 '((((type tty)) (:foreground "red3" :background "black" :weight bold))
1219 (((type pc)) (:foreground "green3" :background "gray40"))
1220 (((class color)) (:foreground "White" :background "Grey"))
1221 (t (:italic t :stipple "gray1"))))
1222 "Face for highlighting odd-numbered non-current differences in buffer A."
1223 :group 'ediff-highlighting)
1224 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1225 ;; this variable is set to nil, then again to the appropriate face.
1226 (defvar ediff-odd-diff-face-A 'ediff-odd-diff-A
1227 "Face for highlighting odd-numbered non-current differences in buffer A.
1228 DO NOT CHANGE this variable. Instead, use the customization
1229 widget to customize the actual face object `ediff-odd-diff-A'
1230 this variable represents.")
1231 (ediff-hide-face ediff-odd-diff-face-A)
1234 (defface ediff-odd-diff-B
1235 (if (featurep 'emacs)
1236 '((((type pc))
1237 (:foreground "White" :background "gray40"))
1238 (((class color) (min-colors 88))
1239 (:background "light grey"))
1240 (((class color) (min-colors 16))
1241 (:foreground "Black" :background "light grey"))
1242 (((class color))
1243 (:foreground "cyan3" :background "black" :weight bold))
1244 (t (:italic t :stipple "gray1")))
1245 '((((type tty)) (:foreground "cyan3" :background "black" :weight bold))
1246 (((type pc)) (:foreground "White" :background "gray40"))
1247 (((class color)) (:foreground "Black" :background "light grey"))
1248 (t (:italic t :stipple "gray1"))))
1249 "Face for highlighting odd-numbered non-current differences in buffer B."
1250 :group 'ediff-highlighting)
1251 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1252 ;; this variable is set to nil, then again to the appropriate face.
1253 (defvar ediff-odd-diff-face-B 'ediff-odd-diff-B
1254 "Face for highlighting odd-numbered non-current differences in buffer B.
1255 DO NOT CHANGE this variable. Instead, use the customization
1256 widget to customize the actual face object `ediff-odd-diff-B'
1257 this variable represents.")
1258 (ediff-hide-face ediff-odd-diff-face-B)
1260 (defface ediff-odd-diff-C
1261 (if (featurep 'emacs)
1262 '((((type pc))
1263 (:foreground "yellow3" :background "gray40"))
1264 (((class color) (min-colors 88))
1265 (:background "Grey"))
1266 (((class color) (min-colors 16))
1267 (:foreground "White" :background "Grey"))
1268 (((class color))
1269 (:foreground "yellow3" :background "black" :weight bold))
1270 (t (:italic t :stipple "gray1")))
1271 '((((type tty)) (:foreground "yellow3" :background "black" :weight bold))
1272 (((type pc)) (:foreground "yellow3" :background "gray40"))
1273 (((class color)) (:foreground "White" :background "Grey"))
1274 (t (:italic t :stipple "gray1"))))
1275 "Face for highlighting odd-numbered non-current differences in buffer C."
1276 :group 'ediff-highlighting)
1277 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1278 ;; this variable is set to nil, then again to the appropriate face.
1279 (defvar ediff-odd-diff-face-C 'ediff-odd-diff-C
1280 "Face for highlighting odd-numbered non-current differences in buffer C.
1281 DO NOT CHANGE this variable. Instead, use the customization
1282 widget to customize the actual face object `ediff-odd-diff-C'
1283 this variable represents.")
1284 (ediff-hide-face ediff-odd-diff-face-C)
1286 (defface ediff-odd-diff-Ancestor
1287 (if (featurep 'emacs)
1288 '((((class color) (min-colors 88))
1289 (:background "gray40"))
1290 (((class color) (min-colors 16))
1291 (:foreground "cyan3" :background "gray40"))
1292 (((class color))
1293 (:foreground "green3" :background "black" :weight bold))
1294 (t (:italic t :stipple "gray1")))
1295 '((((type tty)) (:foreground "green3" :background "black" :weight bold))
1296 (((class color)) (:foreground "cyan3" :background "gray40"))
1297 (t (:italic t :stipple "gray1"))))
1298 "Face for highlighting odd-numbered non-current differences in the ancestor buffer."
1299 :group 'ediff-highlighting)
1300 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1301 ;; this variable is set to nil, then again to the appropriate face.
1302 (defvar ediff-odd-diff-face-Ancestor 'ediff-odd-diff-Ancestor
1303 "Face for highlighting odd-numbered non-current differences in buffer Ancestor.
1304 DO NOT CHANGE this variable. Instead, use the customization
1305 widget to customize the actual face object `ediff-odd-diff-Ancestor'
1306 this variable represents.")
1307 (ediff-hide-face ediff-odd-diff-face-Ancestor)
1309 ;; Association between buffer types and odd-diff-face symbols
1310 (defconst ediff-odd-diff-face-alist
1311 '((A . ediff-odd-diff-A)
1312 (B . ediff-odd-diff-B)
1313 (C . ediff-odd-diff-C)
1314 (Ancestor . ediff-odd-diff-Ancestor)))
1316 ;; A-list of fine-diff face symbols associated with buffer types
1317 (defconst ediff-fine-diff-face-alist
1318 '((A . ediff-fine-diff-A)
1319 (B . ediff-fine-diff-B)
1320 (C . ediff-fine-diff-C)
1321 (Ancestor . ediff-fine-diff-Ancestor)))
1323 ;; Help echo
1324 (put ediff-fine-diff-face-A 'ediff-help-echo
1325 "A `refinement' of the current difference region")
1326 (put ediff-fine-diff-face-B 'ediff-help-echo
1327 "A `refinement' of the current difference region")
1328 (put ediff-fine-diff-face-C 'ediff-help-echo
1329 "A `refinement' of the current difference region")
1330 (put ediff-fine-diff-face-Ancestor 'ediff-help-echo
1331 "A `refinement' of the current difference region")
1333 (add-hook 'ediff-quit-hook 'ediff-cleanup-mess)
1334 (add-hook 'ediff-suspend-hook 'ediff-default-suspend-function)
1337 ;;; Overlays
1339 (ediff-defvar-local ediff-current-diff-overlay-A nil
1340 "Overlay for the current difference region in buffer A.")
1341 (ediff-defvar-local ediff-current-diff-overlay-B nil
1342 "Overlay for the current difference region in buffer B.")
1343 (ediff-defvar-local ediff-current-diff-overlay-C nil
1344 "Overlay for the current difference region in buffer C.")
1345 (ediff-defvar-local ediff-current-diff-overlay-Ancestor nil
1346 "Overlay for the current difference region in the ancestor buffer.")
1348 (defvar ediff-toggle-read-only-function 'read-only-mode
1349 "Function to be used to toggle read-only status of the buffer.
1350 If nil, Ediff tries using the command bound to C-x C-q.")
1352 (defcustom ediff-make-buffers-readonly-at-startup nil
1353 "Make all variant buffers read-only when Ediff starts up.
1354 This property can be toggled interactively."
1355 :type 'boolean
1356 :group 'ediff)
1359 ;;; Misc
1361 ;; if nil, this silences some messages
1362 (defvar ediff-verbose-p t)
1364 (defcustom ediff-autostore-merges 'group-jobs-only
1365 "Save the results of merge jobs automatically.
1366 With value nil, don't save automatically. With value t, always
1367 save. Anything else means save automatically only if the merge
1368 job is part of a group of jobs, such as `ediff-merge-directory'
1369 or `ediff-merge-directory-revisions'."
1370 :type '(choice (const nil) (const t) (const group-jobs-only))
1371 :group 'ediff-merge)
1372 (make-variable-buffer-local 'ediff-autostore-merges)
1374 ;; file where the result of the merge is to be saved. used internally
1375 (ediff-defvar-local ediff-merge-store-file nil "")
1377 (defcustom ediff-merge-filename-prefix "merge_"
1378 "Prefix to be attached to saved merge buffers."
1379 :type 'string
1380 :group 'ediff-merge)
1382 (defcustom ediff-no-emacs-help-in-control-buffer nil
1383 "Non-nil means C-h should not invoke Emacs help in control buffer.
1384 Instead, C-h would jump to previous difference."
1385 :type 'boolean
1386 :group 'ediff)
1388 ;; This is the same as temporary-file-directory from Emacs 20.3.
1389 ;; Copied over here because XEmacs doesn't have this variable.
1390 (defcustom ediff-temp-file-prefix
1391 (file-name-as-directory
1392 (cond ((boundp 'temporary-file-directory) temporary-file-directory)
1393 ((fboundp 'temp-directory) (temp-directory))
1394 (t "/tmp/")))
1395 ;;; (file-name-as-directory
1396 ;;; (cond ((memq system-type '(ms-dos windows-nt))
1397 ;;; (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
1398 ;;; (t
1399 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))
1400 "Prefix to put on Ediff temporary file names.
1401 Do not start with `~/' or `~USERNAME/'."
1402 :type 'string
1403 :group 'ediff)
1405 (defcustom ediff-temp-file-mode 384 ; u=rw only
1406 "Mode for Ediff temporary files."
1407 :type 'integer
1408 :group 'ediff)
1410 ;; Metacharacters that have to be protected from the shell when executing
1411 ;; a diff/diff3 command.
1412 (defcustom ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
1413 "Regexp that matches characters that must be quoted with `\\' in shell command line.
1414 This default should work without changes."
1415 :type 'string
1416 :group 'ediff)
1418 ;; needed to simulate frame-char-width in XEmacs.
1419 (defvar ediff-H-glyph (if (featurep 'xemacs) (make-glyph "H")))
1422 ;; Temporary file used for refining difference regions in buffer A.
1423 (ediff-defvar-local ediff-temp-file-A nil "")
1424 ;; Temporary file used for refining difference regions in buffer B.
1425 (ediff-defvar-local ediff-temp-file-B nil "")
1426 ;; Temporary file used for refining difference regions in buffer C.
1427 (ediff-defvar-local ediff-temp-file-C nil "")
1430 (defun ediff-file-remote-p (file-name)
1431 (file-remote-p file-name))
1433 ;; File for which we can get attributes, such as size or date
1434 (defun ediff-listable-file (file-name)
1435 (let ((handler (find-file-name-handler file-name 'file-local-copy)))
1436 (or (null handler) (eq handler 'dired-handler-fn))))
1439 (defsubst ediff-frame-unsplittable-p (frame)
1440 (cdr (assq 'unsplittable (frame-parameters frame))))
1442 (defsubst ediff-get-next-window (wind prev-wind)
1443 (cond ((window-live-p wind) wind)
1444 (prev-wind (next-window wind))
1445 (t (selected-window))
1449 (defsubst ediff-kill-buffer-carefully (buf)
1450 "Kill buffer BUF if it exists."
1451 (if (ediff-buffer-live-p buf)
1452 (kill-buffer (get-buffer buf))))
1454 (defsubst ediff-background-face (buf-type dif-num)
1455 ;; The value of dif-num is always 1- the one that user sees.
1456 ;; This is why even face is used when dif-num is odd.
1457 (ediff-get-symbol-from-alist
1458 buf-type (if (cl-oddp dif-num)
1459 ediff-even-diff-face-alist
1460 ediff-odd-diff-face-alist)
1464 ;; activate faces on diff regions in buffer
1465 (defun ediff-paint-background-regions-in-one-buffer (buf-type unhighlight)
1466 (let ((diff-vector
1467 (eval (ediff-get-symbol-from-alist
1468 buf-type ediff-difference-vector-alist)))
1469 overl diff-num)
1470 (mapcar (lambda (rec)
1471 (setq overl (ediff-get-diff-overlay-from-diff-record rec)
1472 diff-num (ediff-overlay-get overl 'ediff-diff-num))
1473 (if (ediff-overlay-buffer overl)
1474 ;; only if overlay is alive
1475 (ediff-set-overlay-face
1476 overl
1477 (if (not unhighlight)
1478 (ediff-background-face buf-type diff-num))))
1480 diff-vector)))
1483 ;; activate faces on diff regions in all buffers
1484 (defun ediff-paint-background-regions (&optional unhighlight)
1485 (ediff-paint-background-regions-in-one-buffer
1486 'A unhighlight)
1487 (ediff-paint-background-regions-in-one-buffer
1488 'B unhighlight)
1489 (ediff-paint-background-regions-in-one-buffer
1490 'C unhighlight)
1491 (ediff-paint-background-regions-in-one-buffer
1492 'Ancestor unhighlight))
1495 ;; arg is a record for a given diff in a difference vector
1496 ;; this record is itself a vector
1497 (defsubst ediff-clear-fine-diff-vector (diff-record)
1498 (if diff-record
1499 (mapc 'ediff-delete-overlay
1500 (ediff-get-fine-diff-vector-from-diff-record diff-record))))
1502 (defsubst ediff-clear-fine-differences-in-one-buffer (n buf-type)
1503 (ediff-clear-fine-diff-vector (ediff-get-difference n buf-type))
1504 (ediff-set-fine-diff-vector n buf-type nil))
1506 (defsubst ediff-clear-fine-differences (n)
1507 (ediff-clear-fine-differences-in-one-buffer n 'A)
1508 (ediff-clear-fine-differences-in-one-buffer n 'B)
1509 (if ediff-3way-job
1510 (ediff-clear-fine-differences-in-one-buffer n 'C)))
1513 (defsubst ediff-mouse-event-p (event)
1514 (if (featurep 'xemacs)
1515 (button-event-p event)
1516 (string-match "mouse" (format "%S" (event-basic-type event)))))
1519 (defsubst ediff-key-press-event-p (event)
1520 (if (featurep 'xemacs)
1521 (key-press-event-p event)
1522 (or (char-or-string-p event) (symbolp event))))
1524 (defun ediff-event-point (event)
1525 (cond ((ediff-mouse-event-p event)
1526 (if (featurep 'xemacs)
1527 (event-point event)
1528 (posn-point (event-start event))))
1529 ((ediff-key-press-event-p event)
1530 (point))
1531 (t (error "Error"))))
1533 (defun ediff-event-buffer (event)
1534 (cond ((ediff-mouse-event-p event)
1535 (if (featurep 'xemacs)
1536 (event-buffer event)
1537 (window-buffer (posn-window (event-start event)))))
1538 ((ediff-key-press-event-p event)
1539 (current-buffer))
1540 (t (error "Error"))))
1542 (defun ediff-event-key (event-or-key)
1543 (if (featurep 'xemacs)
1544 ;;(if (eventp event-or-key) (event-key event-or-key) event-or-key)
1545 (if (eventp event-or-key) (event-to-character event-or-key t t) event-or-key)
1546 event-or-key))
1548 (defun ediff-last-command-char ()
1549 (ediff-event-key last-command-event))
1552 (defsubst ediff-frame-iconified-p (frame)
1553 (and (ediff-window-display-p) (frame-live-p frame)
1554 (if (featurep 'xemacs)
1555 (frame-iconified-p frame)
1556 (eq (frame-visible-p frame) 'icon))))
1558 (defsubst ediff-window-visible-p (wind)
1559 ;; under TTY, window-live-p also means window is visible
1560 (and (window-live-p wind)
1561 (or (not (ediff-window-display-p))
1562 (frame-visible-p (window-frame wind)))))
1565 (defsubst ediff-frame-char-width (frame)
1566 (if (featurep 'xemacs)
1567 (/ (frame-pixel-width frame) (frame-width frame))
1568 (frame-char-width frame)))
1570 (defun ediff-reset-mouse (&optional frame do-not-grab-mouse)
1571 (or frame (setq frame (selected-frame)))
1572 (if (ediff-window-display-p)
1573 (let ((frame-or-wind frame))
1574 (if (featurep 'xemacs)
1575 (setq frame-or-wind (frame-selected-window frame)))
1576 (or do-not-grab-mouse
1577 ;; don't set mouse if the user said to never do this
1578 (not ediff-grab-mouse)
1579 ;; Don't grab on quit, if the user doesn't want to.
1580 ;; If ediff-grab-mouse = t, then mouse won't be grabbed for
1581 ;; sessions that are not part of a group (this is done in
1582 ;; ediff-recenter). The condition below affects only terminating
1583 ;; sessions in session groups (in which case mouse is warped into
1584 ;; a meta buffer).
1585 (and (eq ediff-grab-mouse 'maybe)
1586 (memq this-command '(ediff-quit ediff-update-diffs)))
1587 (set-mouse-position frame-or-wind 1 0))
1590 (defsubst ediff-spy-after-mouse ()
1591 (setq ediff-mouse-pixel-position (mouse-pixel-position)))
1593 ;; It is not easy to find out when the user grabs the mouse, since emacs and
1594 ;; xemacs behave differently when mouse is not in any frame. Also, this is
1595 ;; sensitive to when the user grabbed mouse. Not used for now.
1596 (defun ediff-user-grabbed-mouse ()
1597 (if ediff-mouse-pixel-position
1598 (cond ((not (eq (car ediff-mouse-pixel-position)
1599 (car (mouse-pixel-position)))))
1600 ((and (car (cdr ediff-mouse-pixel-position))
1601 (car (cdr (mouse-pixel-position)))
1602 (cdr (cdr ediff-mouse-pixel-position))
1603 (cdr (cdr (mouse-pixel-position))))
1604 (not (and (< (abs (- (car (cdr ediff-mouse-pixel-position))
1605 (car (cdr (mouse-pixel-position)))))
1606 ediff-mouse-pixel-threshold)
1607 (< (abs (- (cdr (cdr ediff-mouse-pixel-position))
1608 (cdr (cdr (mouse-pixel-position)))))
1609 ediff-mouse-pixel-threshold))))
1610 (t nil))))
1612 (defsubst ediff-frame-char-height (frame)
1613 (if (featurep 'xemacs)
1614 (glyph-height ediff-H-glyph (frame-selected-window frame))
1615 (frame-char-height frame)))
1617 ;; Some overlay functions
1619 (defsubst ediff-overlay-start (overl)
1620 (if (ediff-overlayp overl)
1621 (if (featurep 'xemacs)
1622 (extent-start-position overl)
1623 (overlay-start overl))))
1625 (defsubst ediff-overlay-end (overl)
1626 (if (ediff-overlayp overl)
1627 (if (featurep 'xemacs)
1628 (extent-end-position overl)
1629 (overlay-end overl))))
1631 (defsubst ediff-empty-overlay-p (overl)
1632 (= (ediff-overlay-start overl) (ediff-overlay-end overl)))
1634 ;; like overlay-buffer in Emacs. In XEmacs, returns nil if the extent is
1635 ;; dead. Otherwise, works like extent-buffer
1636 (defun ediff-overlay-buffer (overl)
1637 (if (featurep 'xemacs)
1638 (and (extent-live-p overl) (extent-object overl))
1639 (overlay-buffer overl)))
1641 ;; like overlay-get in Emacs. In XEmacs, returns nil if the extent is
1642 ;; dead. Otherwise, like extent-property
1643 (defun ediff-overlay-get (overl property)
1644 (if (featurep 'xemacs)
1645 (and (extent-live-p overl) (extent-property overl property))
1646 (overlay-get overl property)))
1649 ;; These two functions are here because XEmacs refuses to
1650 ;; handle overlays whose buffers were deleted.
1651 (defun ediff-move-overlay (overlay beg end &optional buffer)
1652 "Calls `move-overlay' in Emacs and `set-extent-endpoints' in Lemacs.
1653 Checks if overlay's buffer exists before actually doing the move."
1654 (let ((buf (and overlay (ediff-overlay-buffer overlay))))
1655 (if (ediff-buffer-live-p buf)
1656 (if (featurep 'xemacs)
1657 (set-extent-endpoints overlay beg end)
1658 (move-overlay overlay beg end buffer))
1659 ;; buffer's dead
1660 (if overlay
1661 (ediff-delete-overlay overlay)))))
1663 (defun ediff-overlay-put (overlay prop value)
1664 "Calls `overlay-put' or `set-extent-property' depending on Emacs version.
1665 Checks if overlay's buffer exists."
1666 (if (ediff-buffer-live-p (ediff-overlay-buffer overlay))
1667 (if (featurep 'xemacs)
1668 (set-extent-property overlay prop value)
1669 (overlay-put overlay prop value))
1670 (ediff-delete-overlay overlay)))
1672 ;; temporarily uses DIR to abbreviate file name
1673 ;; if DIR is nil, use default-directory
1674 (defun ediff-abbreviate-file-name (file &optional dir)
1675 (cond ((stringp dir)
1676 (let ((directory-abbrev-alist (list (cons dir ""))))
1677 (abbreviate-file-name file)))
1679 (if (featurep 'xemacs)
1680 ;; XEmacs requires addl argument
1681 (abbreviate-file-name file t)
1682 (abbreviate-file-name file)))))
1684 ;; Takes a directory and returns the parent directory.
1685 ;; does nothing to `/'. If the ARG is a regular file,
1686 ;; strip the file AND the last dir.
1687 (defun ediff-strip-last-dir (dir)
1688 (if (not (stringp dir)) (setq dir default-directory))
1689 (setq dir (expand-file-name dir))
1690 (or (file-directory-p dir) (setq dir (file-name-directory dir)))
1691 (let* ((pos (1- (length dir)))
1692 (last-char (aref dir pos)))
1693 (if (and (> pos 0) (= last-char ?/))
1694 (setq dir (substring dir 0 pos)))
1695 (ediff-abbreviate-file-name (file-name-directory dir))))
1697 (defun ediff-truncate-string-left (str newlen)
1698 ;; leave space for ... on the left
1699 (let ((len (length str))
1700 substr)
1701 (if (<= len newlen)
1703 (setq newlen (max 0 (- newlen 3)))
1704 (setq substr (substring str (max 0 (- len 1 newlen))))
1705 (concat "..." substr))))
1707 (defsubst ediff-nonempty-string-p (string)
1708 (and (stringp string) (not (string= string ""))))
1710 (unless (fboundp 'subst-char-in-string)
1711 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1712 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1713 Unless optional argument INPLACE is non-nil, return a new string."
1714 (let ((i (length string))
1715 (newstr (if inplace string (copy-sequence string))))
1716 (while (> i 0)
1717 (setq i (1- i))
1718 (if (eq (aref newstr i) fromchar)
1719 (aset newstr i tochar)))
1720 newstr)))
1722 (unless (fboundp 'format-message)
1723 (defalias 'format-message 'format))
1725 (defun ediff-abbrev-jobname (jobname)
1726 (cond ((eq jobname 'ediff-directories)
1727 "Compare two directories")
1728 ((eq jobname 'ediff-files)
1729 "Compare two files")
1730 ((eq jobname 'ediff-buffers)
1731 "Compare two buffers")
1732 ((eq jobname 'ediff-directories3)
1733 "Compare three directories")
1734 ((eq jobname 'ediff-files3)
1735 "Compare three files")
1736 ((eq jobname 'ediff-buffers3)
1737 "Compare three buffers")
1738 ((eq jobname 'ediff-revision)
1739 "Compare file with a version")
1740 ((eq jobname 'ediff-directory-revisions)
1741 "Compare dir files with versions")
1742 ((eq jobname 'ediff-merge-directory-revisions)
1743 "Merge dir files with versions")
1744 ((eq jobname 'ediff-merge-directory-revisions-with-ancestor)
1745 "Merge dir versions via ancestors")
1747 (capitalize
1748 (subst-char-in-string ?- ?\s (substring (symbol-name jobname) 6))))
1752 ;; If ediff modified mode line, strip the modification
1753 (defsubst ediff-strip-mode-line-format ()
1754 (and (consp mode-line-format)
1755 (member (car mode-line-format)
1756 '(" A: " " B: " " C: " " Ancestor: "))
1757 (setq mode-line-format (nth 2 mode-line-format))))
1759 ;; Verify that we have a difference selected.
1760 (defsubst ediff-valid-difference-p (&optional n)
1761 (or n (setq n ediff-current-difference))
1762 (and (>= n 0) (< n ediff-number-of-differences)))
1764 (defsubst ediff-show-all-diffs (_n)
1765 "Don't skip difference regions."
1766 nil)
1768 (defsubst ediff-message-if-verbose (string &rest args)
1769 (if ediff-verbose-p
1770 (apply 'message string args)))
1772 (defun ediff-file-attributes (filename attr-number)
1773 (if (ediff-listable-file filename)
1774 (nth attr-number (file-attributes filename))
1778 (defsubst ediff-file-size (filename)
1779 (ediff-file-attributes filename 7))
1780 (defsubst ediff-file-modtime (filename)
1781 (ediff-file-attributes filename 5))
1784 (defun ediff-convert-standard-filename (fname)
1785 (if (fboundp 'convert-standard-filename)
1786 (convert-standard-filename fname)
1787 fname))
1789 (if (featurep 'emacs)
1790 (defalias 'ediff-with-syntax-table 'with-syntax-table)
1791 (if (fboundp 'with-syntax-table)
1792 (defalias 'ediff-with-syntax-table 'with-syntax-table)
1793 ;; stolen from subr.el in emacs 21
1794 (defmacro ediff-with-syntax-table (table &rest body)
1795 (let ((old-table (make-symbol "table"))
1796 (old-buffer (make-symbol "buffer")))
1797 `(let ((,old-table (syntax-table))
1798 (,old-buffer (current-buffer)))
1799 (unwind-protect
1800 (progn
1801 (set-syntax-table (copy-syntax-table ,table))
1802 ,@body)
1803 (save-current-buffer
1804 (set-buffer ,old-buffer)
1805 (set-syntax-table ,old-table))))))))
1808 (provide 'ediff-init)
1812 ;; Local Variables:
1813 ;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1814 ;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1815 ;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1816 ;; End:
1818 ;;; ediff-init.el ends here