Merge from emacs--devo--0
[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 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 (ediff-cond-compile-for-xemacs-or-emacs
799 (eq (device-class (selected-device)) 'color) ; xemacs form
800 (if (fboundp 'display-color-p) ; emacs form
801 (display-color-p)
802 (x-display-color-p))
803 )
804 (error nil)))
805
806
807 ;; A var local to each control panel buffer. Indicates highlighting style
808 ;; in effect for this buffer: `face', `ascii',
809 ;; `off' -- turned off \(on a dumb terminal only\).
810 (ediff-defvar-local ediff-highlighting-style
811 (if (and (ediff-has-face-support-p) ediff-use-faces) 'face 'ascii)
812 "")
813
814
815 (if (ediff-has-face-support-p)
816 (ediff-cond-compile-for-xemacs-or-emacs
817 (progn ; xemacs
818 (defalias 'ediff-valid-color-p 'valid-color-name-p)
819 (defalias 'ediff-get-face 'get-face))
820 (progn ; emacs
821 (defalias 'ediff-valid-color-p (if (fboundp 'color-defined-p)
822 'color-defined-p
823 'x-color-defined-p))
824 (defalias 'ediff-get-face 'internal-get-face))
825 ))
826
827 (if (ediff-window-display-p)
828 (ediff-cond-compile-for-xemacs-or-emacs
829 (progn ; xemacs
830 (defalias 'ediff-display-pixel-width 'device-pixel-width)
831 (defalias 'ediff-display-pixel-height 'device-pixel-height))
832 (progn ; emacs
833 (defalias 'ediff-display-pixel-width
834 (if (fboundp 'display-pixel-width)
835 'display-pixel-width
836 'x-display-pixel-width))
837 (defalias 'ediff-display-pixel-height
838 (if (fboundp 'display-pixel-height)
839 'display-pixel-height
840 'x-display-pixel-height)))
841 ))
842
843 ;; A-list of current-diff-overlay symbols associated with buf types
844 (defconst ediff-current-diff-overlay-alist
845 '((A . ediff-current-diff-overlay-A)
846 (B . ediff-current-diff-overlay-B)
847 (C . ediff-current-diff-overlay-C)
848 (Ancestor . ediff-current-diff-overlay-Ancestor)))
849
850 ;; A-list of current-diff-face-* symbols associated with buf types
851 (defconst ediff-current-diff-face-alist
852 '((A . ediff-current-diff-A)
853 (B . ediff-current-diff-B)
854 (C . ediff-current-diff-C)
855 (Ancestor . ediff-current-diff-Ancestor)))
856
857
858 (defun ediff-set-overlay-face (extent face)
859 (ediff-overlay-put extent 'face face)
860 (ediff-overlay-put extent 'help-echo 'ediff-region-help-echo))
861
862 (defun ediff-region-help-echo (extent-or-window &optional overlay point)
863 (unless overlay
864 (setq overlay extent-or-window))
865 (let ((is-current (ediff-overlay-get overlay 'ediff))
866 (face (ediff-overlay-get overlay 'face))
867 (diff-num (ediff-overlay-get overlay 'ediff-diff-num))
868 face-help)
869
870 ;; This happens only for refinement overlays
871 (if (stringp face)
872 (setq face (intern face)))
873 (setq face-help (and face (get face 'ediff-help-echo)))
874
875 (cond ((and is-current diff-num) ; current diff region
876 (format "Difference region %S -- current" (1+ diff-num)))
877 (face-help) ; refinement of current diff region
878 (diff-num ; non-current
879 (format "Difference region %S -- non-current" (1+ diff-num)))
880 (t "")) ; none
881 ))
882
883
884 (defun ediff-set-face-pixmap (face pixmap)
885 "Set face pixmap on a monochrome display."
886 (if (and (ediff-window-display-p) (not (ediff-color-display-p)))
887 (condition-case nil
888 (set-face-background-pixmap face pixmap)
889 (error
890 (message "Pixmap not found for %S: %s" (face-name face) pixmap)
891 (sit-for 1)))))
892
893 (defun ediff-hide-face (face)
894 (if (and (ediff-has-face-support-p)
895 (boundp 'add-to-list)
896 (boundp 'facemenu-unlisted-faces))
897 (add-to-list 'facemenu-unlisted-faces face)))
898
899
900
901 (defface ediff-current-diff-A
902 (if (featurep 'emacs)
903 '((((class color) (min-colors 16))
904 (:foreground "firebrick" :background "pale green"))
905 (((class color))
906 (:foreground "blue3" :background "yellow3"))
907 (t (:inverse-video t)))
908 '((((type tty)) (:foreground "blue3" :background "yellow3"))
909 (((class color)) (:foreground "firebrick" :background "pale green"))
910 (t (:inverse-video t))))
911 "Face for highlighting the selected difference in buffer A."
912 :group 'ediff-highlighting)
913 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
914 ;; this variable is set to nil, then again to the appropriate face.
915 (defvar ediff-current-diff-face-A 'ediff-current-diff-A
916 "Face for highlighting the selected difference in buffer A.
917 DO NOT CHANGE this variable. Instead, use the customization
918 widget to customize the actual face object `ediff-current-diff-A'
919 this variable represents.")
920 (ediff-hide-face ediff-current-diff-face-A)
921 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
922 ;; This means that some user customization may be trashed.
923 (if (and (featurep 'xemacs)
924 (ediff-has-face-support-p)
925 (not (ediff-color-display-p)))
926 (copy-face 'modeline ediff-current-diff-face-A))
927
928
929
930 (defface ediff-current-diff-B
931 (if (featurep 'emacs)
932 '((((class color) (min-colors 16))
933 (:foreground "DarkOrchid" :background "Yellow"))
934 (((class color))
935 (:foreground "magenta3" :background "yellow3"
936 :weight bold))
937 (t (:inverse-video t)))
938 '((((type tty)) (:foreground "magenta3" :background "yellow3"
939 :weight bold))
940 (((class color)) (:foreground "DarkOrchid" :background "Yellow"))
941 (t (:inverse-video t))))
942 "Face for highlighting the selected difference in buffer B."
943 :group 'ediff-highlighting)
944 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
945 ;; this variable is set to nil, then again to the appropriate face.
946 (defvar ediff-current-diff-face-B 'ediff-current-diff-B
947 "Face for highlighting the selected difference in buffer B.
948 this variable. Instead, use the customization
949 widget to customize the actual face `ediff-current-diff-B'
950 this variable represents.")
951 (ediff-hide-face ediff-current-diff-face-B)
952 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
953 ;; This means that some user customization may be trashed.
954 (if (and (featurep 'xemacs)
955 (ediff-has-face-support-p)
956 (not (ediff-color-display-p)))
957 (copy-face 'modeline ediff-current-diff-face-B))
958
959
960 (defface ediff-current-diff-C
961 (if (featurep 'emacs)
962 '((((class color) (min-colors 16))
963 (:foreground "Navy" :background "Pink"))
964 (((class color))
965 (:foreground "cyan3" :background "yellow3" :weight bold))
966 (t (:inverse-video t)))
967 '((((type tty)) (:foreground "cyan3" :background "yellow3" :weight bold))
968 (((class color)) (:foreground "Navy" :background "Pink"))
969 (t (:inverse-video t))))
970 "Face for highlighting the selected difference in buffer C."
971 :group 'ediff-highlighting)
972 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
973 ;; this variable is set to nil, then again to the appropriate face.
974 (defvar ediff-current-diff-face-C 'ediff-current-diff-C
975 "Face for highlighting the selected difference in buffer C.
976 DO NOT CHANGE this variable. Instead, use the customization
977 widget to customize the actual face object `ediff-current-diff-C'
978 this variable represents.")
979 (ediff-hide-face ediff-current-diff-face-C)
980 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
981 ;; This means that some user customization may be trashed.
982 (if (and (featurep 'xemacs)
983 (ediff-has-face-support-p)
984 (not (ediff-color-display-p)))
985 (copy-face 'modeline ediff-current-diff-face-C))
986
987
988 (defface ediff-current-diff-Ancestor
989 (if (featurep 'emacs)
990 '((((class color) (min-colors 16))
991 (:foreground "Black" :background "VioletRed"))
992 (((class color))
993 (:foreground "black" :background "magenta3"))
994 (t (:inverse-video t)))
995 '((((type tty)) (:foreground "black" :background "magenta3"))
996 (((class color)) (:foreground "Black" :background "VioletRed"))
997 (t (:inverse-video t))))
998 "Face for highlighting the selected difference in buffer Ancestor."
999 :group 'ediff-highlighting)
1000 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1001 ;; this variable is set to nil, then again to the appropriate face.
1002 (defvar ediff-current-diff-face-Ancestor 'ediff-current-diff-Ancestor
1003 "Face for highlighting the selected difference in buffer Ancestor.
1004 DO NOT CHANGE this variable. Instead, use the customization
1005 widget to customize the actual face object `ediff-current-diff-Ancestor'
1006 this variable represents.")
1007 (ediff-hide-face ediff-current-diff-face-Ancestor)
1008 ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
1009 ;; This means that some user customization may be trashed.
1010 (if (and (featurep 'xemacs)
1011 (ediff-has-face-support-p)
1012 (not (ediff-color-display-p)))
1013 (copy-face 'modeline ediff-current-diff-face-Ancestor))
1014
1015
1016 (defface ediff-fine-diff-A
1017 (if (featurep 'emacs)
1018 '((((class color) (min-colors 16))
1019 (:foreground "Navy" :background "sky blue"))
1020 (((class color))
1021 (:foreground "white" :background "sky blue" :weight bold))
1022 (t (:underline t :stipple "gray3")))
1023 '((((type tty)) (:foreground "white" :background "sky blue" :weight bold))
1024 (((class color)) (:foreground "Navy" :background "sky blue"))
1025 (t (:underline t :stipple "gray3"))))
1026 "Face for highlighting the refinement of the selected diff in buffer A."
1027 :group 'ediff-highlighting)
1028 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1029 ;; this variable is set to nil, then again to the appropriate face.
1030 (defvar ediff-fine-diff-face-A 'ediff-fine-diff-A
1031 "Face for highlighting the fine differences in buffer A.
1032 DO NOT CHANGE this variable. Instead, use the customization
1033 widget to customize the actual face object `ediff-fine-diff-A'
1034 this variable represents.")
1035 (ediff-hide-face ediff-fine-diff-face-A)
1036
1037 (defface ediff-fine-diff-B
1038 (if (featurep 'emacs)
1039 '((((class color) (min-colors 16))
1040 (:foreground "Black" :background "cyan"))
1041 (((class color))
1042 (:foreground "magenta3" :background "cyan3"))
1043 (t (:underline t :stipple "gray3")))
1044 '((((type tty)) (:foreground "magenta3" :background "cyan3"))
1045 (((class color)) (:foreground "Black" :background "cyan"))
1046 (t (:underline t :stipple "gray3"))))
1047 "Face for highlighting the refinement of the selected diff in buffer B."
1048 :group 'ediff-highlighting)
1049 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1050 ;; this variable is set to nil, then again to the appropriate face.
1051 (defvar ediff-fine-diff-face-B 'ediff-fine-diff-B
1052 "Face for highlighting the fine differences in buffer B.
1053 DO NOT CHANGE this variable. Instead, use the customization
1054 widget to customize the actual face object `ediff-fine-diff-B'
1055 this variable represents.")
1056 (ediff-hide-face ediff-fine-diff-face-B)
1057
1058 (defface ediff-fine-diff-C
1059 (if (featurep 'emacs)
1060 '((((type pc))
1061 (:foreground "white" :background "Turquoise"))
1062 (((class color) (min-colors 16))
1063 (:foreground "Black" :background "Turquoise"))
1064 (((class color))
1065 (:foreground "yellow3" :background "Turquoise"
1066 :weight bold))
1067 (t (:underline t :stipple "gray3")))
1068 '((((type tty)) (:foreground "yellow3" :background "Turquoise"
1069 :weight bold))
1070 (((type pc)) (:foreground "white" :background "Turquoise"))
1071 (((class color)) (:foreground "Black" :background "Turquoise"))
1072 (t (:underline t :stipple "gray3"))))
1073 "Face for highlighting the refinement of the selected diff in buffer C."
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-C 'ediff-fine-diff-C
1078 "Face for highlighting the fine differences in buffer C.
1079 DO NOT CHANGE this variable. Instead, use the customization
1080 widget to customize the actual face object `ediff-fine-diff-C'
1081 this variable represents.")
1082 (ediff-hide-face ediff-fine-diff-face-C)
1083
1084 (defface ediff-fine-diff-Ancestor
1085 (if (featurep 'emacs)
1086 '((((class color) (min-colors 16))
1087 (:foreground "Black" :background "Green"))
1088 (((class color))
1089 (:foreground "red3" :background "green"))
1090 (t (:underline t :stipple "gray3")))
1091 '((((type tty)) (:foreground "red3" :background "green"))
1092 (((class color)) (:foreground "Black" :background "Green"))
1093 (t (:underline t :stipple "gray3"))))
1094 "Face for highlighting the refinement of the selected diff in the ancestor buffer.
1095 At present, this face is not used and no fine differences are computed for the
1096 ancestor buffer."
1097 :group 'ediff-highlighting)
1098 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1099 ;; this variable is set to nil, then again to the appropriate face.
1100 (defvar ediff-fine-diff-face-Ancestor 'ediff-fine-diff-Ancestor
1101 "Face for highlighting the fine differences in buffer Ancestor.
1102 DO NOT CHANGE this variable. Instead, use the customization
1103 widget to customize the actual face object `ediff-fine-diff-Ancestor'
1104 this variable represents.")
1105 (ediff-hide-face ediff-fine-diff-face-Ancestor)
1106
1107 ;; Some installs don't have stipple or Stipple. So, try them in turn.
1108 (defvar stipple-pixmap
1109 (cond ((not (ediff-has-face-support-p)) nil)
1110 ((and (boundp 'x-bitmap-file-path)
1111 (locate-library "stipple" t x-bitmap-file-path)) "stipple")
1112 ((and (boundp 'mswindowsx-bitmap-file-path)
1113 (locate-library "stipple" t mswindowsx-bitmap-file-path)) "stipple")
1114 (t "Stipple")))
1115
1116 (defface ediff-even-diff-A
1117 (if (featurep 'emacs)
1118 `((((type pc))
1119 (:foreground "green3" :background "light grey"))
1120 (((class color) (min-colors 16))
1121 (:foreground "Black" :background "light grey"))
1122 (((class color))
1123 (:foreground "red3" :background "light grey"
1124 :weight bold))
1125 (t (:italic t :stipple ,stipple-pixmap)))
1126 `((((type tty)) (:foreground "red3" :background "light grey"
1127 :weight bold))
1128 (((type pc)) (:foreground "green3" :background "light grey"))
1129 (((class color)) (:foreground "Black" :background "light grey"))
1130 (t (:italic t :stipple ,stipple-pixmap))))
1131 "Face for highlighting even-numbered non-current differences in buffer A."
1132 :group 'ediff-highlighting)
1133 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1134 ;; this variable is set to nil, then again to the appropriate face.
1135 (defvar ediff-even-diff-face-A 'ediff-even-diff-A
1136 "Face for highlighting even-numbered non-current differences in buffer A.
1137 DO NOT CHANGE this variable. Instead, use the customization
1138 widget to customize the actual face object `ediff-even-diff-A'
1139 this variable represents.")
1140 (ediff-hide-face ediff-even-diff-face-A)
1141
1142 (defface ediff-even-diff-B
1143 (if (featurep 'emacs)
1144 `((((class color) (min-colors 16))
1145 (:foreground "White" :background "Grey"))
1146 (((class color))
1147 (:foreground "blue3" :background "Grey" :weight bold))
1148 (t (:italic t :stipple ,stipple-pixmap)))
1149 `((((type tty)) (:foreground "blue3" :background "Grey" :weight bold))
1150 (((class color)) (:foreground "White" :background "Grey"))
1151 (t (:italic t :stipple ,stipple-pixmap))))
1152 "Face for highlighting even-numbered non-current differences in buffer B."
1153 :group 'ediff-highlighting)
1154 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1155 ;; this variable is set to nil, then again to the appropriate face.
1156 (defvar ediff-even-diff-face-B 'ediff-even-diff-B
1157 "Face for highlighting even-numbered non-current differences in buffer B.
1158 DO NOT CHANGE this variable. Instead, use the customization
1159 widget to customize the actual face object `ediff-even-diff-B'
1160 this variable represents.")
1161 (ediff-hide-face ediff-even-diff-face-B)
1162
1163 (defface ediff-even-diff-C
1164 (if (featurep 'emacs)
1165 `((((type pc))
1166 (:foreground "yellow3" :background "light grey"))
1167 (((class color) (min-colors 16))
1168 (:foreground "Black" :background "light grey"))
1169 (((class color))
1170 (:foreground "yellow3" :background "light grey"
1171 :weight bold))
1172 (t (:italic t :stipple ,stipple-pixmap)))
1173 `((((type tty)) (:foreground "yellow3" :background "light grey"
1174 :weight bold))
1175 (((type pc)) (:foreground "yellow3" :background "light grey"))
1176 (((class color)) (:foreground "Black" :background "light grey"))
1177 (t (:italic t :stipple ,stipple-pixmap))))
1178 "Face for highlighting even-numbered non-current differences in buffer C."
1179 :group 'ediff-highlighting)
1180 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1181 ;; this variable is set to nil, then again to the appropriate face.
1182 (defvar ediff-even-diff-face-C 'ediff-even-diff-C
1183 "Face for highlighting even-numbered non-current differences in buffer C.
1184 DO NOT CHANGE this variable. Instead, use the customization
1185 widget to customize the actual face object `ediff-even-diff-C'
1186 this variable represents.")
1187 (ediff-hide-face ediff-even-diff-face-C)
1188
1189 (defface ediff-even-diff-Ancestor
1190 (if (featurep 'emacs)
1191 `((((type pc))
1192 (:foreground "cyan3" :background "light grey"))
1193 (((class color) (min-colors 16))
1194 (:foreground "White" :background "Grey"))
1195 (((class color))
1196 (:foreground "cyan3" :background "light grey"
1197 :weight bold))
1198 (t (:italic t :stipple ,stipple-pixmap)))
1199 `((((type tty)) (:foreground "cyan3" :background "light grey"
1200 :weight bold))
1201 (((type pc)) (:foreground "cyan3" :background "light grey"))
1202 (((class color)) (:foreground "White" :background "Grey"))
1203 (t (:italic t :stipple ,stipple-pixmap))))
1204 "Face for highlighting even-numbered non-current differences in the ancestor buffer."
1205 :group 'ediff-highlighting)
1206 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1207 ;; this variable is set to nil, then again to the appropriate face.
1208 (defvar ediff-even-diff-face-Ancestor 'ediff-even-diff-Ancestor
1209 "Face for highlighting even-numbered non-current differences in buffer Ancestor.
1210 DO NOT CHANGE this variable. Instead, use the customization
1211 widget to customize the actual face object `ediff-even-diff-Ancestor'
1212 this variable represents.")
1213 (ediff-hide-face ediff-even-diff-face-Ancestor)
1214
1215 ;; Association between buffer types and even-diff-face symbols
1216 (defconst ediff-even-diff-face-alist
1217 '((A . ediff-even-diff-A)
1218 (B . ediff-even-diff-B)
1219 (C . ediff-even-diff-C)
1220 (Ancestor . ediff-even-diff-Ancestor)))
1221
1222 (defface ediff-odd-diff-A
1223 (if (featurep 'emacs)
1224 '((((type pc))
1225 (:foreground "green3" :background "gray40"))
1226 (((class color) (min-colors 16))
1227 (:foreground "White" :background "Grey"))
1228 (((class color))
1229 (:foreground "red3" :background "black" :weight bold))
1230 (t (:italic t :stipple "gray1")))
1231 '((((type tty)) (:foreground "red3" :background "black" :weight bold))
1232 (((type pc)) (:foreground "green3" :background "gray40"))
1233 (((class color)) (:foreground "White" :background "Grey"))
1234 (t (:italic t :stipple "gray1"))))
1235 "Face for highlighting odd-numbered non-current differences in buffer A."
1236 :group 'ediff-highlighting)
1237 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1238 ;; this variable is set to nil, then again to the appropriate face.
1239 (defvar ediff-odd-diff-face-A 'ediff-odd-diff-A
1240 "Face for highlighting odd-numbered non-current differences in buffer A.
1241 DO NOT CHANGE this variable. Instead, use the customization
1242 widget to customize the actual face object `ediff-odd-diff-A'
1243 this variable represents.")
1244 (ediff-hide-face ediff-odd-diff-face-A)
1245
1246
1247 (defface ediff-odd-diff-B
1248 (if (featurep 'emacs)
1249 '((((type pc))
1250 (:foreground "White" :background "gray40"))
1251 (((class color) (min-colors 16))
1252 (:foreground "Black" :background "light grey"))
1253 (((class color))
1254 (:foreground "cyan3" :background "black" :weight bold))
1255 (t (:italic t :stipple "gray1")))
1256 '((((type tty)) (:foreground "cyan3" :background "black" :weight bold))
1257 (((type pc)) (:foreground "White" :background "gray40"))
1258 (((class color)) (:foreground "Black" :background "light grey"))
1259 (t (:italic t :stipple "gray1"))))
1260 "Face for highlighting odd-numbered non-current differences in buffer B."
1261 :group 'ediff-highlighting)
1262 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1263 ;; this variable is set to nil, then again to the appropriate face.
1264 (defvar ediff-odd-diff-face-B 'ediff-odd-diff-B
1265 "Face for highlighting odd-numbered non-current differences in buffer B.
1266 DO NOT CHANGE this variable. Instead, use the customization
1267 widget to customize the actual face object `ediff-odd-diff-B'
1268 this variable represents.")
1269 (ediff-hide-face ediff-odd-diff-face-B)
1270
1271 (defface ediff-odd-diff-C
1272 (if (featurep 'emacs)
1273 '((((type pc))
1274 (:foreground "yellow3" :background "gray40"))
1275 (((class color) (min-colors 16))
1276 (:foreground "White" :background "Grey"))
1277 (((class color))
1278 (:foreground "yellow3" :background "black" :weight bold))
1279 (t (:italic t :stipple "gray1")))
1280 '((((type tty)) (:foreground "yellow3" :background "black" :weight bold))
1281 (((type pc)) (:foreground "yellow3" :background "gray40"))
1282 (((class color)) (:foreground "White" :background "Grey"))
1283 (t (:italic t :stipple "gray1"))))
1284 "Face for highlighting odd-numbered non-current differences in buffer C."
1285 :group 'ediff-highlighting)
1286 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1287 ;; this variable is set to nil, then again to the appropriate face.
1288 (defvar ediff-odd-diff-face-C 'ediff-odd-diff-C
1289 "Face for highlighting odd-numbered non-current differences in buffer C.
1290 DO NOT CHANGE this variable. Instead, use the customization
1291 widget to customize the actual face object `ediff-odd-diff-C'
1292 this variable represents.")
1293 (ediff-hide-face ediff-odd-diff-face-C)
1294
1295 (defface ediff-odd-diff-Ancestor
1296 (if (featurep 'emacs)
1297 '((((class color) (min-colors 16))
1298 (:foreground "cyan3" :background "gray40"))
1299 (((class color))
1300 (:foreground "green3" :background "black" :weight bold))
1301 (t (:italic t :stipple "gray1")))
1302 '((((type tty)) (:foreground "green3" :background "black" :weight bold))
1303 (((class color)) (:foreground "cyan3" :background "gray40"))
1304 (t (:italic t :stipple "gray1"))))
1305 "Face for highlighting odd-numbered non-current differences in the ancestor buffer."
1306 :group 'ediff-highlighting)
1307 ;; An internal variable. Ediff takes the face from here. When unhighlighting,
1308 ;; this variable is set to nil, then again to the appropriate face.
1309 (defvar ediff-odd-diff-face-Ancestor 'ediff-odd-diff-Ancestor
1310 "Face for highlighting odd-numbered non-current differences in buffer Ancestor.
1311 DO NOT CHANGE this variable. Instead, use the customization
1312 widget to customize the actual face object `ediff-odd-diff-Ancestor'
1313 this variable represents.")
1314 (ediff-hide-face ediff-odd-diff-face-Ancestor)
1315
1316 ;; Association between buffer types and odd-diff-face symbols
1317 (defconst ediff-odd-diff-face-alist
1318 '((A . ediff-odd-diff-A)
1319 (B . ediff-odd-diff-B)
1320 (C . ediff-odd-diff-C)
1321 (Ancestor . ediff-odd-diff-Ancestor)))
1322
1323 ;; A-list of fine-diff face symbols associated with buffer types
1324 (defconst ediff-fine-diff-face-alist
1325 '((A . ediff-fine-diff-A)
1326 (B . ediff-fine-diff-B)
1327 (C . ediff-fine-diff-C)
1328 (Ancestor . ediff-fine-diff-Ancestor)))
1329
1330 ;; Help echo
1331 (put ediff-fine-diff-face-A 'ediff-help-echo
1332 "A `refinement' of the current difference region")
1333 (put ediff-fine-diff-face-B 'ediff-help-echo
1334 "A `refinement' of the current difference region")
1335 (put ediff-fine-diff-face-C 'ediff-help-echo
1336 "A `refinement' of the current difference region")
1337 (put ediff-fine-diff-face-Ancestor 'ediff-help-echo
1338 "A `refinement' of the current difference region")
1339
1340 (add-hook 'ediff-quit-hook 'ediff-cleanup-mess)
1341 (add-hook 'ediff-suspend-hook 'ediff-default-suspend-function)
1342
1343
1344 ;;; Overlays
1345
1346 (ediff-defvar-local ediff-current-diff-overlay-A nil
1347 "Overlay for the current difference region in buffer A.")
1348 (ediff-defvar-local ediff-current-diff-overlay-B nil
1349 "Overlay for the current difference region in buffer B.")
1350 (ediff-defvar-local ediff-current-diff-overlay-C nil
1351 "Overlay for the current difference region in buffer C.")
1352 (ediff-defvar-local ediff-current-diff-overlay-Ancestor nil
1353 "Overlay for the current difference region in the ancestor buffer.")
1354
1355 ;; Compute priority of a current ediff overlay.
1356 (defun ediff-highest-priority (start end buffer)
1357 (let ((pos (max 1 (1- start)))
1358 ovr-list)
1359 (ediff-cond-compile-for-xemacs-or-emacs
1360 (1+ ediff-shadow-overlay-priority) ; xemacs form
1361 ;; emacs form
1362 (ediff-with-current-buffer buffer
1363 (while (< pos (min (point-max) (1+ end)))
1364 (setq ovr-list (append (overlays-at pos) ovr-list))
1365 (setq pos (next-overlay-change pos)))
1366 (+ 1 ediff-shadow-overlay-priority
1367 (apply 'max
1368 (cons
1369 1
1370 (mapcar
1371 (lambda (ovr)
1372 (if (and ovr
1373 ;; exclude ediff overlays from priority
1374 ;; calculation, or else priority will keep
1375 ;; increasing
1376 (null (ediff-overlay-get ovr 'ediff))
1377 (null (ediff-overlay-get ovr 'ediff-diff-num)))
1378 ;; use the overlay priority or 0
1379 (or (ediff-overlay-get ovr 'priority) 0)
1380 0))
1381 ovr-list)
1382 )
1383 )))
1384 ) ; ediff-cond-compile-for-xemacs-or-emacs
1385 ))
1386
1387
1388 (defvar ediff-toggle-read-only-function nil
1389 "*Specifies the function to be used to toggle read-only.
1390 If nil, Ediff tries to deduce the function from the binding of C-x C-q.
1391 Normally, this is the `toggle-read-only' function, but, if version
1392 control is used, it could be `vc-toggle-read-only' or `rcs-toggle-read-only'.")
1393
1394 (defcustom ediff-make-buffers-readonly-at-startup nil
1395 "*Make all variant buffers read-only when Ediff starts up.
1396 This property can be toggled interactively."
1397 :type 'boolean
1398 :group 'ediff)
1399
1400
1401 ;;; Misc
1402
1403 ;; if nil, this silences some messages
1404 (defvar ediff-verbose-p t)
1405
1406 (defcustom ediff-autostore-merges 'group-jobs-only
1407 "*Save the results of merge jobs automatically.
1408 With value nil, don't save automatically. With value t, always
1409 save. Anything else means save automatically only if the merge
1410 job is part of a group of jobs, such as `ediff-merge-directory'
1411 or `ediff-merge-directory-revisions'."
1412 :type '(choice (const nil) (const t) (const group-jobs-only))
1413 :group 'ediff-merge)
1414 (make-variable-buffer-local 'ediff-autostore-merges)
1415
1416 ;; file where the result of the merge is to be saved. used internally
1417 (ediff-defvar-local ediff-merge-store-file nil "")
1418
1419 (defcustom ediff-merge-filename-prefix "merge_"
1420 "*Prefix to be attached to saved merge buffers."
1421 :type 'string
1422 :group 'ediff-merge)
1423
1424 (defcustom ediff-no-emacs-help-in-control-buffer nil
1425 "*Non-nil means C-h should not invoke Emacs help in control buffer.
1426 Instead, C-h would jump to previous difference."
1427 :type 'boolean
1428 :group 'ediff)
1429
1430 ;; This is the same as temporary-file-directory from Emacs 20.3.
1431 ;; Copied over here because XEmacs doesn't have this variable.
1432 (defcustom ediff-temp-file-prefix
1433 (file-name-as-directory
1434 (cond ((boundp 'temporary-file-directory) temporary-file-directory)
1435 ((fboundp 'temp-directory) (temp-directory))
1436 (t "/tmp/")))
1437 ;;; (file-name-as-directory
1438 ;;; (cond ((memq system-type '(ms-dos windows-nt))
1439 ;;; (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
1440 ;;; ((memq system-type '(vax-vms axp-vms))
1441 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
1442 ;;; (t
1443 ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))
1444 "*Prefix to put on Ediff temporary file names.
1445 Do not start with `~/' or `~USERNAME/'."
1446 :type 'string
1447 :group 'ediff)
1448
1449 (defcustom ediff-temp-file-mode 384 ; u=rw only
1450 "*Mode for Ediff temporary files."
1451 :type 'integer
1452 :group 'ediff)
1453
1454 ;; Metacharacters that have to be protected from the shell when executing
1455 ;; a diff/diff3 command.
1456 (defcustom ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
1457 "Regexp that matches characters that must be quoted with `\\' in shell command line.
1458 This default should work without changes."
1459 :type 'string
1460 :group 'ediff)
1461
1462 ;; needed to simulate frame-char-width in XEmacs.
1463 (defvar ediff-H-glyph (if (featurep 'xemacs) (make-glyph "H")))
1464
1465
1466 ;; Temporary file used for refining difference regions in buffer A.
1467 (ediff-defvar-local ediff-temp-file-A nil "")
1468 ;; Temporary file used for refining difference regions in buffer B.
1469 (ediff-defvar-local ediff-temp-file-B nil "")
1470 ;; Temporary file used for refining difference regions in buffer C.
1471 (ediff-defvar-local ediff-temp-file-C nil "")
1472
1473
1474 (defun ediff-file-remote-p (file-name)
1475 (file-remote-p file-name))
1476
1477 ;; File for which we can get attributes, such as size or date
1478 (defun ediff-listable-file (file-name)
1479 (let ((handler (find-file-name-handler file-name 'file-local-copy)))
1480 (or (null handler) (eq handler 'dired-handler-fn))))
1481
1482
1483 (defsubst ediff-frame-unsplittable-p (frame)
1484 (cdr (assq 'unsplittable (frame-parameters frame))))
1485
1486 (defsubst ediff-get-next-window (wind prev-wind)
1487 (cond ((window-live-p wind) wind)
1488 (prev-wind (next-window wind))
1489 (t (selected-window))
1490 ))
1491
1492
1493 (defsubst ediff-kill-buffer-carefully (buf)
1494 "Kill buffer BUF if it exists."
1495 (if (ediff-buffer-live-p buf)
1496 (kill-buffer (get-buffer buf))))
1497
1498 (defsubst ediff-background-face (buf-type dif-num)
1499 ;; The value of dif-num is always 1- the one that user sees.
1500 ;; This is why even face is used when dif-num is odd.
1501 (ediff-get-symbol-from-alist
1502 buf-type (if (ediff-odd-p dif-num)
1503 ediff-even-diff-face-alist
1504 ediff-odd-diff-face-alist)
1505 ))
1506
1507
1508 ;; activate faces on diff regions in buffer
1509 (defun ediff-paint-background-regions-in-one-buffer (buf-type unhighlight)
1510 (let ((diff-vector
1511 (eval (ediff-get-symbol-from-alist
1512 buf-type ediff-difference-vector-alist)))
1513 overl diff-num)
1514 (mapcar (lambda (rec)
1515 (setq overl (ediff-get-diff-overlay-from-diff-record rec)
1516 diff-num (ediff-overlay-get overl 'ediff-diff-num))
1517 (if (ediff-overlay-buffer overl)
1518 ;; only if overlay is alive
1519 (ediff-set-overlay-face
1520 overl
1521 (if (not unhighlight)
1522 (ediff-background-face buf-type diff-num))))
1523 )
1524 diff-vector)))
1525
1526
1527 ;; activate faces on diff regions in all buffers
1528 (defun ediff-paint-background-regions (&optional unhighlight)
1529 (ediff-paint-background-regions-in-one-buffer
1530 'A unhighlight)
1531 (ediff-paint-background-regions-in-one-buffer
1532 'B unhighlight)
1533 (ediff-paint-background-regions-in-one-buffer
1534 'C unhighlight)
1535 (ediff-paint-background-regions-in-one-buffer
1536 'Ancestor unhighlight))
1537
1538
1539 ;; arg is a record for a given diff in a difference vector
1540 ;; this record is itself a vector
1541 (defsubst ediff-clear-fine-diff-vector (diff-record)
1542 (if diff-record
1543 (mapcar 'ediff-delete-overlay
1544 (ediff-get-fine-diff-vector-from-diff-record diff-record))))
1545
1546 (defsubst ediff-clear-fine-differences-in-one-buffer (n buf-type)
1547 (ediff-clear-fine-diff-vector (ediff-get-difference n buf-type))
1548 (ediff-set-fine-diff-vector n buf-type nil))
1549
1550 (defsubst ediff-clear-fine-differences (n)
1551 (ediff-clear-fine-differences-in-one-buffer n 'A)
1552 (ediff-clear-fine-differences-in-one-buffer n 'B)
1553 (if ediff-3way-job
1554 (ediff-clear-fine-differences-in-one-buffer n 'C)))
1555
1556
1557 (defsubst ediff-mouse-event-p (event)
1558 (ediff-cond-compile-for-xemacs-or-emacs
1559 (button-event-p event) ; xemacs form
1560 (string-match "mouse" (format "%S" (event-basic-type event))) ; emacs form
1561 ))
1562
1563
1564 (defsubst ediff-key-press-event-p (event)
1565 (ediff-cond-compile-for-xemacs-or-emacs
1566 (key-press-event-p event) ; xemacs form
1567 (or (char-or-string-p event) (symbolp event)) ; emacs form
1568 ))
1569
1570 (defun ediff-event-point (event)
1571 (cond ((ediff-mouse-event-p event)
1572 (ediff-cond-compile-for-xemacs-or-emacs
1573 (event-point event) ; xemacs form
1574 (posn-point (event-start event)) ; emacs form
1575 )
1576 )
1577 ((ediff-key-press-event-p event)
1578 (point))
1579 (t (error nil))))
1580
1581 (defun ediff-event-buffer (event)
1582 (cond ((ediff-mouse-event-p event)
1583 (ediff-cond-compile-for-xemacs-or-emacs
1584 (event-buffer event) ; xemacs form
1585 (window-buffer (posn-window (event-start event))) ; emacs form
1586 )
1587 )
1588 ((ediff-key-press-event-p event)
1589 (current-buffer))
1590 (t (error nil))))
1591
1592 (defun ediff-event-key (event-or-key)
1593 (ediff-cond-compile-for-xemacs-or-emacs
1594 (if (eventp event-or-key) (event-key event-or-key) event-or-key) ; xemacs
1595 event-or-key ; emacs form
1596 ))
1597
1598
1599 (defsubst ediff-frame-iconified-p (frame)
1600 (if (and (ediff-window-display-p) (frame-live-p frame))
1601 (ediff-cond-compile-for-xemacs-or-emacs
1602 (frame-iconified-p frame) ; xemacs form
1603 (eq (frame-visible-p frame) 'icon) ; emacs form
1604 )
1605 ))
1606
1607 (defsubst ediff-window-visible-p (wind)
1608 ;; under TTY, window-live-p also means window is visible
1609 (and (window-live-p wind)
1610 (or (not (ediff-window-display-p))
1611 (frame-visible-p (window-frame wind)))))
1612
1613
1614 (defsubst ediff-frame-char-width (frame)
1615 (ediff-cond-compile-for-xemacs-or-emacs
1616 (/ (frame-pixel-width frame) (frame-width frame)) ; xemacs
1617 (frame-char-width frame) ; emacs
1618 ))
1619
1620 (defun ediff-reset-mouse (&optional frame do-not-grab-mouse)
1621 (or frame (setq frame (selected-frame)))
1622 (if (ediff-window-display-p)
1623 (let ((frame-or-wind frame))
1624 (if (featurep 'xemacs)
1625 (setq frame-or-wind (frame-selected-window frame)))
1626 (or do-not-grab-mouse
1627 ;; don't set mouse if the user said to never do this
1628 (not ediff-grab-mouse)
1629 ;; Don't grab on quit, if the user doesn't want to.
1630 ;; If ediff-grab-mouse = t, then mouse won't be grabbed for
1631 ;; sessions that are not part of a group (this is done in
1632 ;; ediff-recenter). The condition below affects only terminating
1633 ;; sessions in session groups (in which case mouse is warped into
1634 ;; a meta buffer).
1635 (and (eq ediff-grab-mouse 'maybe)
1636 (memq this-command '(ediff-quit ediff-update-diffs)))
1637 (set-mouse-position frame-or-wind 1 0))
1638 )))
1639
1640 (defsubst ediff-spy-after-mouse ()
1641 (setq ediff-mouse-pixel-position (mouse-pixel-position)))
1642
1643 ;; It is not easy to find out when the user grabs the mouse, since emacs and
1644 ;; xemacs behave differently when mouse is not in any frame. Also, this is
1645 ;; sensitive to when the user grabbed mouse. Not used for now.
1646 (defun ediff-user-grabbed-mouse ()
1647 (if ediff-mouse-pixel-position
1648 (cond ((not (eq (car ediff-mouse-pixel-position)
1649 (car (mouse-pixel-position)))))
1650 ((and (car (cdr ediff-mouse-pixel-position))
1651 (car (cdr (mouse-pixel-position)))
1652 (cdr (cdr ediff-mouse-pixel-position))
1653 (cdr (cdr (mouse-pixel-position))))
1654 (not (and (< (abs (- (car (cdr ediff-mouse-pixel-position))
1655 (car (cdr (mouse-pixel-position)))))
1656 ediff-mouse-pixel-threshold)
1657 (< (abs (- (cdr (cdr ediff-mouse-pixel-position))
1658 (cdr (cdr (mouse-pixel-position)))))
1659 ediff-mouse-pixel-threshold))))
1660 (t nil))))
1661
1662 (defsubst ediff-frame-char-height (frame)
1663 (ediff-cond-compile-for-xemacs-or-emacs
1664 (glyph-height ediff-H-glyph (frame-selected-window frame)) ; xemacs case
1665 (frame-char-height frame) ; emacs case
1666 )
1667 )
1668
1669 ;; Some overlay functions
1670
1671 (defsubst ediff-overlay-start (overl)
1672 (if (ediff-overlayp overl)
1673 (ediff-cond-compile-for-xemacs-or-emacs
1674 (extent-start-position overl) ; xemacs form
1675 (overlay-start overl) ; emacs form
1676 )
1677 ))
1678
1679 (defsubst ediff-overlay-end (overl)
1680 (if (ediff-overlayp overl)
1681 (ediff-cond-compile-for-xemacs-or-emacs
1682 (extent-end-position overl) ; xemacs form
1683 (overlay-end overl) ; emacs form
1684 )
1685 ))
1686
1687 (defsubst ediff-empty-overlay-p (overl)
1688 (= (ediff-overlay-start overl) (ediff-overlay-end overl)))
1689
1690 ;; like overlay-buffer in Emacs. In XEmacs, returns nil if the extent is
1691 ;; dead. Otherwise, works like extent-buffer
1692 (defun ediff-overlay-buffer (overl)
1693 (ediff-cond-compile-for-xemacs-or-emacs
1694 (and (extent-live-p overl) (extent-object overl)) ; xemacs form
1695 (overlay-buffer overl) ; emacs form
1696 ))
1697
1698 ;; like overlay-get in Emacs. In XEmacs, returns nil if the extent is
1699 ;; dead. Otherwise, like extent-property
1700 (defun ediff-overlay-get (overl property)
1701 (ediff-cond-compile-for-xemacs-or-emacs
1702 (and (extent-live-p overl) (extent-property overl property)) ; xemacs form
1703 (overlay-get overl property) ; emacs form
1704 ))
1705
1706
1707 ;; These two functions are here because XEmacs refuses to
1708 ;; handle overlays whose buffers were deleted.
1709 (defun ediff-move-overlay (overlay beg end &optional buffer)
1710 "Calls `move-overlay' in Emacs and `set-extent-endpoints' in Lemacs.
1711 Checks if overlay's buffer exists before actually doing the move."
1712 (let ((buf (and overlay (ediff-overlay-buffer overlay))))
1713 (if (ediff-buffer-live-p buf)
1714 (ediff-cond-compile-for-xemacs-or-emacs
1715 (set-extent-endpoints overlay beg end) ; xemacs form
1716 (move-overlay overlay beg end buffer) ; emacs form
1717 )
1718 ;; buffer's dead
1719 (if overlay
1720 (ediff-delete-overlay overlay)))))
1721
1722 (defun ediff-overlay-put (overlay prop value)
1723 "Calls `overlay-put' or `set-extent-property' depending on Emacs version.
1724 Checks if overlay's buffer exists."
1725 (if (ediff-buffer-live-p (ediff-overlay-buffer overlay))
1726 (ediff-cond-compile-for-xemacs-or-emacs
1727 (set-extent-property overlay prop value) ; xemacs form
1728 (overlay-put overlay prop value) ; emacs form
1729 )
1730 (ediff-delete-overlay overlay)))
1731
1732 ;; temporarily uses DIR to abbreviate file name
1733 ;; if DIR is nil, use default-directory
1734 (defun ediff-abbreviate-file-name (file &optional dir)
1735 (cond ((stringp dir)
1736 (let ((directory-abbrev-alist (list (cons dir ""))))
1737 (abbreviate-file-name file)))
1738 (t
1739 (ediff-cond-compile-for-xemacs-or-emacs
1740 ;; XEmacs requires addl argument
1741 (abbreviate-file-name file t) ; xemacs form
1742 (abbreviate-file-name file)) ; emacs form
1743 )
1744 ))
1745
1746 ;; Takes a directory and returns the parent directory.
1747 ;; does nothing to `/'. If the ARG is a regular file,
1748 ;; strip the file AND the last dir.
1749 (defun ediff-strip-last-dir (dir)
1750 (if (not (stringp dir)) (setq dir default-directory))
1751 (setq dir (expand-file-name dir))
1752 (or (file-directory-p dir) (setq dir (file-name-directory dir)))
1753 (let* ((pos (1- (length dir)))
1754 (last-char (aref dir pos)))
1755 (if (and (> pos 0) (= last-char ?/))
1756 (setq dir (substring dir 0 pos)))
1757 (ediff-abbreviate-file-name (file-name-directory dir))))
1758
1759 (defun ediff-truncate-string-left (str newlen)
1760 ;; leave space for ... on the left
1761 (let ((len (length str))
1762 substr)
1763 (if (<= len newlen)
1764 str
1765 (setq newlen (max 0 (- newlen 3)))
1766 (setq substr (substring str (max 0 (- len 1 newlen))))
1767 (concat "..." substr))))
1768
1769 (defsubst ediff-nonempty-string-p (string)
1770 (and (stringp string) (not (string= string ""))))
1771
1772 (unless (fboundp 'subst-char-in-string)
1773 (defun subst-char-in-string (fromchar tochar string &optional inplace)
1774 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1775 Unless optional argument INPLACE is non-nil, return a new string."
1776 (let ((i (length string))
1777 (newstr (if inplace string (copy-sequence string))))
1778 (while (> i 0)
1779 (setq i (1- i))
1780 (if (eq (aref newstr i) fromchar)
1781 (aset newstr i tochar)))
1782 newstr)))
1783
1784 (defun ediff-abbrev-jobname (jobname)
1785 (cond ((eq jobname 'ediff-directories)
1786 "Compare two directories")
1787 ((eq jobname 'ediff-files)
1788 "Compare two files")
1789 ((eq jobname 'ediff-buffers)
1790 "Compare two buffers")
1791 ((eq jobname 'ediff-directories3)
1792 "Compare three directories")
1793 ((eq jobname 'ediff-files3)
1794 "Compare three files")
1795 ((eq jobname 'ediff-buffers3)
1796 "Compare three buffers")
1797 ((eq jobname 'ediff-revision)
1798 "Compare file with a version")
1799 ((eq jobname 'ediff-directory-revisions)
1800 "Compare dir files with versions")
1801 ((eq jobname 'ediff-merge-directory-revisions)
1802 "Merge dir files with versions")
1803 ((eq jobname 'ediff-merge-directory-revisions-with-ancestor)
1804 "Merge dir versions via ancestors")
1805 (t
1806 (capitalize
1807 (subst-char-in-string ?- ?\s (substring (symbol-name jobname) 6))))
1808 ))
1809
1810
1811 ;; If ediff modified mode line, strip the modification
1812 (defsubst ediff-strip-mode-line-format ()
1813 (if (member (car mode-line-format) '(" A: " " B: " " C: " " Ancestor: "))
1814 (setq mode-line-format (nth 2 mode-line-format))))
1815
1816 ;; Verify that we have a difference selected.
1817 (defsubst ediff-valid-difference-p (&optional n)
1818 (or n (setq n ediff-current-difference))
1819 (and (>= n 0) (< n ediff-number-of-differences)))
1820
1821 (defsubst ediff-show-all-diffs (n)
1822 "Don't skip difference regions."
1823 nil)
1824
1825 (defsubst Xor (a b)
1826 (or (and a (not b)) (and (not a) b)))
1827
1828 (defsubst ediff-message-if-verbose (string &rest args)
1829 (if ediff-verbose-p
1830 (apply 'message string args)))
1831
1832 (defun ediff-file-attributes (filename attr-number)
1833 (if (ediff-listable-file filename)
1834 (nth attr-number (file-attributes filename))
1835 -1)
1836 )
1837
1838 (defsubst ediff-file-size (filename)
1839 (ediff-file-attributes filename 7))
1840 (defsubst ediff-file-modtime (filename)
1841 (ediff-file-attributes filename 5))
1842
1843
1844 (defun ediff-convert-standard-filename (fname)
1845 (if (fboundp 'convert-standard-filename)
1846 (convert-standard-filename fname)
1847 fname))
1848
1849
1850 (if (fboundp 'with-syntax-table)
1851 (defalias 'ediff-with-syntax-table 'with-syntax-table)
1852 ;; stolen from subr.el in emacs 21
1853 (defmacro ediff-with-syntax-table (table &rest body)
1854 (let ((old-table (make-symbol "table"))
1855 (old-buffer (make-symbol "buffer")))
1856 `(let ((,old-table (syntax-table))
1857 (,old-buffer (current-buffer)))
1858 (unwind-protect
1859 (progn
1860 (set-syntax-table (copy-syntax-table ,table))
1861 ,@body)
1862 (save-current-buffer
1863 (set-buffer ,old-buffer)
1864 (set-syntax-table ,old-table)))))))
1865
1866
1867 (provide 'ediff-init)
1868
1869
1870
1871 ;; Local Variables:
1872 ;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1873 ;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1874 ;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1875 ;; End:
1876
1877 ;; arch-tag: fa31d384-1e70-4d4b-82a7-3e96307c46f5
1878 ;;; ediff-init.el ends here