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