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