Commit | Line | Data |
---|---|---|
8343426b | 1 | ;;; ediff-init.el --- Macros, variables, and defsubsts used by Ediff |
732be465 | 2 | ;;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. |
475f9031 KH |
3 | |
4 | ;; Author: Michael Kifer <kifer@cs.sunysb.edu> | |
5 | ||
6 | ;; This file is part of GNU Emacs. | |
7 | ||
8 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
9 | ;; it under the terms of the GNU General Public License as published by | |
10 | ;; the Free Software Foundation; either version 2, or (at your option) | |
11 | ;; any later version. | |
12 | ||
13 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | ;; GNU General Public License for more details. | |
17 | ||
18 | ;; You should have received a copy of the GNU General Public License | |
19 | ;; along with GNU Emacs; see the file COPYING. If not, write to | |
20 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | ||
22 | ||
41d25ad0 | 23 | ;; Is it XEmacs? |
8343426b | 24 | (defconst ediff-xemacs-p (string-match "XEmacs" emacs-version)) |
41d25ad0 KH |
25 | ;; Is it Emacs? |
26 | (defconst ediff-emacs-p (not ediff-xemacs-p)) | |
27 | ;; Are we running as a window application or on a TTY? | |
28 | (defsubst ediff-device-type () | |
29 | (if ediff-emacs-p | |
30 | window-system | |
31 | (device-type (selected-device)))) | |
32 | ;; in XEmacs: device-type is tty on tty and stream in batch. | |
33 | (defsubst ediff-window-display-p () | |
34 | (and (ediff-device-type) (not (memq (ediff-device-type) '(tty stream))))) | |
475f9031 KH |
35 | |
36 | ;;; Macros | |
37 | (defmacro ediff-odd-p (arg) | |
38 | (` (eq (logand (, arg) 1) 1))) | |
39 | ||
40 | (defmacro ediff-buffer-live-p (buf) | |
41 | (` (and (, buf) (get-buffer (, buf)) (buffer-name (get-buffer (, buf)))))) | |
42 | ||
43 | (defmacro ediff-get-buffer (arg) | |
44 | (` (cond ((eq (, arg) 'A) ediff-buffer-A) | |
45 | ((eq (, arg) 'B) ediff-buffer-B) | |
46 | ((eq (, arg) 'C) ediff-buffer-C) | |
8343426b | 47 | ((eq (, arg) 'Ancestor) ediff-ancestor-buffer) |
475f9031 KH |
48 | ) |
49 | )) | |
50 | ||
51 | (defmacro ediff-get-value-according-to-buffer-type (buf-type list) | |
52 | (` (cond ((eq (, buf-type) 'A) (nth 0 (, list))) | |
53 | ((eq (, buf-type) 'B) (nth 1 (, list))) | |
54 | ((eq (, buf-type) 'C) (nth 2 (, list)))))) | |
55 | ||
56 | (defmacro ediff-char-to-buftype (arg) | |
57 | (` (cond ((memq (, arg) '(?a ?A)) 'A) | |
58 | ((memq (, arg) '(?b ?B)) 'B) | |
59 | ((memq (, arg) '(?c ?C)) 'C) | |
60 | ) | |
61 | )) | |
62 | ||
63 | (defmacro ediff-get-difference (n buf-type) | |
64 | (` (aref | |
65 | (symbol-value | |
66 | (intern (format "ediff-difference-vector-%S" (, buf-type)))) (, n)))) | |
67 | ||
68 | ;; tell if it has been previously determined that the region has | |
69 | ;; no diffs other than the white space and newlines | |
70 | ;; The argument, N, is the diff region number used by Ediff to index the | |
71 | ;; diff vector. It is 1 less than the number seen by the user. | |
72 | ;; | |
73 | ;; A difference vector has the form: | |
74 | ;; [diff diff diff ...] | |
75 | ;; where each diff has the form: | |
76 | ;; [overlay fine-diff-vector no-fine-diffs-flag] | |
77 | ;; fine-diff-vector is a vector [fine-diff fine-diff fine-diff ...] | |
78 | (defmacro ediff-no-fine-diffs-p (n) | |
79 | (` (aref (ediff-get-difference (, n) 'A) 2))) | |
80 | ||
81 | (defmacro ediff-get-diff-overlay-from-diff-record (diff-rec) | |
82 | (` (aref (, diff-rec) 0))) | |
83 | ||
84 | (defmacro ediff-get-diff-overlay (n buf-type) | |
85 | (` (ediff-get-diff-overlay-from-diff-record | |
86 | (ediff-get-difference (, n) (, buf-type))))) | |
87 | ||
88 | (defmacro ediff-get-fine-diff-vector-from-diff-record (diff-rec) | |
89 | (` (aref (, diff-rec) 1))) | |
90 | ||
91 | (defmacro ediff-set-fine-diff-vector (n buf-type fine-vec) | |
92 | (` (aset (ediff-get-difference (, n) (, buf-type)) 1 (, fine-vec)))) | |
93 | ||
94 | (defmacro ediff-get-state-of-diff (n buf-type) | |
95 | (` (if (ediff-buffer-live-p ediff-buffer-C) | |
96 | (aref (ediff-get-difference (, n) (, buf-type)) 3)))) | |
97 | (defmacro ediff-set-state-of-diff (n buf-type val) | |
98 | (` (aset (ediff-get-difference (, n) (, buf-type)) 3 (, val)))) | |
99 | (defmacro ediff-get-state-of-merge (n) | |
8343426b MK |
100 | (` (if ediff-state-of-merge |
101 | (aref (aref ediff-state-of-merge (, n)) 0)))) | |
102 | (defmacro ediff-get-state-of-ancestor (n) | |
103 | (` (if ediff-state-of-merge | |
104 | (aref (aref ediff-state-of-merge (, n)) 1)))) | |
475f9031 | 105 | (defmacro ediff-set-state-of-merge (n val) |
8343426b MK |
106 | (` (if ediff-state-of-merge |
107 | (aset (aref ediff-state-of-merge (, n)) 0 (, val))))) | |
475f9031 KH |
108 | |
109 | ;; if flag is t, puts a mark on diff region saying that | |
110 | ;; the differences are in white space only. If flag is nil, | |
111 | ;; the region is marked as essential (i.e., differences are | |
112 | ;; not just in the white space and newlines.) | |
113 | (defmacro ediff-mark-diff-as-space-only (n flag) | |
114 | (` (aset (ediff-get-difference (, n) 'A) 2 (, flag)))) | |
115 | ||
116 | (defmacro ediff-get-fine-diff-vector (n buf-type) | |
117 | (` (ediff-get-fine-diff-vector-from-diff-record | |
118 | (ediff-get-difference (, n) (, buf-type))))) | |
119 | ||
120 | ||
121 | ;; Defines SYMBOL as an advertised local variable. | |
122 | ;; Performs a defvar, then executes `make-variable-buffer-local' on | |
123 | ;; the variable. Also sets the `permanent-local' property, | |
124 | ;; so that `kill-all-local-variables' (called by major-mode setting | |
125 | ;; commands) won't destroy Ediff control variables. | |
126 | ;; | |
127 | ;; Plagiarised from `emerge-defvar-local' for XEmacs. | |
128 | (defmacro ediff-defvar-local (var value doc) | |
129 | (` (progn | |
130 | (defvar (, var) (, value) (, doc)) | |
131 | (make-variable-buffer-local '(, var)) | |
132 | (put '(, var) 'permanent-local t)))) | |
133 | ||
134 | ;; Macro to switch to BUFFER, evaluate FORMS, returns to original buffer. | |
135 | ;; Differs from `save-excursion' in that it doesn't save the point and mark. | |
136 | ;; This is essentially `emerge-eval-in-buffer' with the test for live buffers." | |
137 | (defmacro ediff-eval-in-buffer (buffer &rest forms) | |
138 | (` (let ((StartBuffer (current-buffer))) | |
139 | (if (ediff-buffer-live-p (, buffer)) | |
140 | (unwind-protect | |
141 | (progn | |
142 | (set-buffer (, buffer)) | |
143 | (,@ forms)) | |
144 | (set-buffer StartBuffer)) | |
145 | (or (eq this-command 'ediff-quit) | |
146 | (error | |
147 | "You've killed an essential Ediff buffer---Please quit Ediff")) | |
148 | )))) | |
149 | ||
150 | ||
8343426b MK |
151 | (defsubst ediff-multiframe-setup-p () |
152 | (and (ediff-window-display-p) ediff-multiframe)) | |
475f9031 KH |
153 | |
154 | (defmacro ediff-narrow-control-frame-p () | |
155 | (` (and (ediff-multiframe-setup-p) | |
156 | (equal ediff-help-message ediff-brief-message-string)))) | |
157 | ||
158 | (defmacro ediff-3way-comparison-job () | |
159 | (` (memq | |
160 | ediff-job-name | |
161 | '(ediff-files3 ediff-buffers3)))) | |
162 | (ediff-defvar-local ediff-3way-comparison-job nil "") | |
163 | ||
164 | (defmacro ediff-merge-job () | |
165 | (` (memq | |
166 | ediff-job-name | |
167 | '(ediff-merge-files | |
168 | ediff-merge-buffers | |
169 | ediff-merge-files-with-ancestor | |
170 | ediff-merge-buffers-with-ancestor | |
171 | ediff-merge-revisions | |
172 | ediff-merge-revisions-with-ancestor)))) | |
173 | (ediff-defvar-local ediff-merge-job nil "") | |
174 | ||
175 | (defmacro ediff-merge-with-ancestor-job () | |
176 | (` (memq | |
177 | ediff-job-name | |
178 | '(ediff-merge-files-with-ancestor | |
179 | ediff-merge-buffers-with-ancestor | |
180 | ediff-merge-revisions-with-ancestor)))) | |
181 | (ediff-defvar-local ediff-merge-with-ancestor-job nil "") | |
182 | ||
183 | (defmacro ediff-3way-job () | |
184 | (` (or ediff-3way-comparison-job ediff-merge-job))) | |
185 | (ediff-defvar-local ediff-3way-job nil "") | |
186 | ||
187 | ;; A diff3 job is like a 3way job, but ediff-merge doesn't require the use | |
188 | ;; of diff3. | |
189 | (defmacro ediff-diff3-job () | |
190 | (` (or ediff-3way-comparison-job | |
191 | ediff-merge-with-ancestor-job))) | |
192 | (ediff-defvar-local ediff-diff3-job nil "") | |
193 | ||
41d25ad0 KH |
194 | (defmacro ediff-windows-job () |
195 | (` (memq ediff-job-name '(ediff-windows-wordwise ediff-windows-linewise)))) | |
196 | (ediff-defvar-local ediff-windows-job nil "") | |
197 | ||
475f9031 | 198 | (defmacro ediff-word-mode-job () |
41d25ad0 | 199 | (` (memq ediff-job-name '(ediff-windows-wordwise ediff-regions-wordwise)))) |
475f9031 KH |
200 | (ediff-defvar-local ediff-word-mode-job nil "") |
201 | ||
41d25ad0 KH |
202 | (defmacro ediff-narrow-job () |
203 | (` (memq ediff-job-name '(ediff-windows-wordwise | |
204 | ediff-regions-wordwise | |
205 | ediff-windows-linewise | |
206 | ediff-regions-linewise)))) | |
207 | (ediff-defvar-local ediff-narrow-job nil "") | |
208 | ||
8343426b MK |
209 | ;; Note: ediff-merge-directory-revisions-with-ancestor is not treated as an |
210 | ;; ancestor metajob, since it behaves differently. | |
211 | (defsubst ediff-ancestor-metajob (&optional metajob) | |
212 | (memq (or metajob ediff-metajob-name) | |
213 | '(ediff-merge-directories-with-ancestor | |
214 | ediff-merge-filegroups-with-ancestor))) | |
215 | (defsubst ediff-revision-metajob (&optional metajob) | |
216 | (memq (or metajob ediff-metajob-name) | |
217 | '(ediff-directory-revisions | |
218 | ediff-merge-directory-revisions | |
219 | ediff-merge-directory-revisions-with-ancestor))) | |
220 | ;; metajob involving only one directory | |
221 | (defsubst ediff-dir1-metajob (&optional metajob) | |
222 | (or (ediff-revision-metajob metajob) | |
223 | ;; add more here | |
224 | )) | |
225 | (defsubst ediff-collect-diffs-metajob (&optional metajob) | |
226 | (or (ediff-revision-metajob metajob) | |
227 | (memq ediff-metajob-name | |
228 | '(ediff-directories | |
229 | ;; add more here | |
230 | ediff-directory-revisions)))) | |
231 | (defsubst ediff-metajob3 (&optional metajob) | |
232 | (memq (or metajob ediff-metajob-name) | |
233 | '(ediff-merge-directories-with-ancestor | |
234 | ediff-merge-filegroups-with-ancestor | |
235 | ediff-directories3 | |
236 | ediff-filegroups3))) | |
237 | (defsubst ediff-comparison-metajob3 (&optional metajob) | |
238 | (memq (or metajob ediff-metajob-name) | |
239 | '(ediff-directories3 ediff-filegroups3))) | |
240 | ||
241 | (defsubst ediff-barf-if-not-control-buffer (&optional meta-buf) | |
242 | (or (eq (if meta-buf ediff-meta-buffer ediff-control-buffer) | |
243 | (current-buffer)) | |
244 | (error "%S: This command runs in Ediff Control Buffer only!" | |
245 | this-command))) | |
246 | ||
475f9031 KH |
247 | |
248 | ;; Hook variables | |
249 | ||
8343426b MK |
250 | (defvar ediff-before-setup-windows-hook nil |
251 | "*Hooks to run before Ediff sets its window configuration. | |
475f9031 KH |
252 | This can be used to save the previous window config, which can be restored |
253 | on ediff-quit or ediff-suspend.") | |
8343426b MK |
254 | (defvar ediff-after-setup-windows-hook nil |
255 | "*Hooks to run after Ediff sets its window configuration. | |
475f9031 | 256 | This can be used to set up control window or icon in a desired place.") |
8343426b | 257 | (defvar ediff-before-setup-control-frame-hook nil |
475f9031 KH |
258 | "*Hooks run before setting up the frame to display Ediff Control Panel. |
259 | Can be used to change control frame parameters to position it where it | |
260 | is desirable.") | |
8343426b | 261 | (defvar ediff-after-setup-control-frame-hook nil |
475f9031 KH |
262 | "*Hooks run after setting up the frame to display Ediff Control Panel. |
263 | Can be used to move the frame where it is desired.") | |
8343426b | 264 | (defvar ediff-startup-hook nil |
475f9031 | 265 | "*Hooks to run in the control buffer after Ediff has been set up.") |
8343426b | 266 | (defvar ediff-select-hook nil |
475f9031 | 267 | "*Hooks to run after a difference has been selected.") |
8343426b | 268 | (defvar ediff-unselect-hook nil |
475f9031 | 269 | "*Hooks to run after a difference has been unselected.") |
8343426b | 270 | (defvar ediff-prepare-buffer-hook nil |
475f9031 | 271 | "*Hooks called after buffers A, B, and C are set up.") |
8343426b | 272 | (defvar ediff-load-hook nil |
475f9031 KH |
273 | "*Hook run after Ediff is loaded. Can be used to change defaults.") |
274 | ||
8343426b | 275 | (defvar ediff-mode-hook nil |
475f9031 KH |
276 | "*Hook run just after ediff-mode is set up in the control buffer. |
277 | This is done before any windows or frames are created. One can use it to | |
278 | set local variables that determine how the display looks like.") | |
8343426b | 279 | (defvar ediff-keymap-setup-hook nil |
475f9031 KH |
280 | "*Hook run just after the default bindings in Ediff keymap are set up.") |
281 | ||
8343426b | 282 | (defvar ediff-display-help-hook nil |
475f9031 KH |
283 | "*Hooks run after preparing the help message.") |
284 | ||
8343426b | 285 | (defvar ediff-suspend-hook (list 'ediff-default-suspend-function) |
475f9031 | 286 | "*Hooks to run in the Ediff control buffer when Ediff is suspended.") |
8343426b | 287 | (defvar ediff-quit-hook (list 'ediff-cleanup-mess) |
475f9031 | 288 | "*Hooks to run in the Ediff control buffer after finishing Ediff.") |
8343426b | 289 | (defvar ediff-cleanup-hook nil |
41d25ad0 KH |
290 | "*Hooks to run on exiting Ediff but before killing the control buffer. |
291 | This is a place to do various cleanups, such as deleting the variant buffers. | |
292 | Ediff provides a function, `ediff-janitor', as one such possible hook.") | |
475f9031 KH |
293 | |
294 | ||
295 | ;; Help messages | |
296 | ||
297 | (defconst ediff-long-help-message-head | |
298 | " Moving around | Toggling features | Manipulations | |
299 | =====================|===========================|=============================" | |
300 | "The head of the full help message.") | |
301 | (defconst ediff-long-help-message-tail | |
302 | "=====================|===========================|============================= | |
8343426b MK |
303 | R -show registry | | M -show session group |
304 | D -diff output | E -browse Ediff manual| G -send bug report | |
305 | i -status info | ? -help off | z/q -suspend/quit | |
475f9031 KH |
306 | ------------------------------------------------------------------------------- |
307 | X,Y (x,y) on the left are meta-symbols for the keys A,B,C (a,b,c). | |
308 | X,Y on the right are meta-symbols for buffers A,B,C. | |
309 | A,B,C on the right denote the working buffers A,B,C, respectively." | |
310 | "The tail of the full-help message.") | |
311 | ||
312 | (defconst ediff-long-help-message-compare3 | |
313 | " | |
314 | p,DEL -previous diff | | -vert/horiz split | xy -copy buf X's region to Y | |
315 | n,SPC -next diff | h -hiliting | rx -restore buf X's old diff | |
316 | j -jump to diff | @ -auto-refinement | * -refine current region | |
317 | gx -goto X's point| | ! -update diff regions | |
318 | C-l -recenter | ## -ignore whitespace | | |
319 | v/V -scroll up/dn | #f/#h -focus/hide regions | wx -save buf X | |
320 | </> -scroll lt/rt | X -read-only in buf X | wd -save diff output | |
8343426b | 321 | | m -wide display | ~ -rotate buffers |
475f9031 | 322 | " |
41d25ad0 KH |
323 | "Help message usually used for 3-way comparison. |
324 | Normally, not a user option. See `ediff-help-message' for details.") | |
475f9031 KH |
325 | |
326 | (defconst ediff-long-help-message-compare2 | |
327 | " | |
328 | p,DEL -previous diff | | -vert/horiz split |a/b -copy A/B's region to B/A | |
329 | n,SPC -next diff | h -hiliting | rx -restore buf X's old diff | |
330 | j -jump to diff | @ -auto-refinement | * -refine current region | |
331 | gx -goto X's point| | ! -update diff regions | |
332 | C-l -recenter | ## -ignore whitespace | | |
333 | v/V -scroll up/dn | #f/#h -focus/hide regions | wx -save buf X | |
334 | </> -scroll lt/rt | X -read-only in buf X | wd -save diff output | |
8343426b | 335 | | m -wide display | ~ -swap buffers |
475f9031 | 336 | " |
41d25ad0 KH |
337 | "Help message usually used for 2-way comparison. |
338 | Normally, not a user option. See `ediff-help-message' for details.") | |
339 | ||
340 | (defconst ediff-long-help-message-narrow2 | |
341 | " | |
342 | p,DEL -previous diff | | -vert/horiz split |a/b -copy A/B's region to B/A | |
343 | n,SPC -next diff | h -hiliting | rx -restore buf X's old diff | |
344 | j -jump to diff | @ -auto-refinement | * -refine current region | |
345 | gx -goto X's point| % -narrow/widen buffs | ! -update diff regions | |
346 | C-l -recenter | ## -ignore whitespace | | |
347 | v/V -scroll up/dn | #f/#h -focus/hide regions | wx -save buf X | |
348 | </> -scroll lt/rt | X -read-only in buf X | wd -save diff output | |
8343426b | 349 | | m -wide display | ~ -swap buffers |
41d25ad0 KH |
350 | " |
351 | "Help message when comparing windows or regions line-by-line. | |
352 | Normally, not a user option. See `ediff-help-message' for details.") | |
475f9031 KH |
353 | |
354 | (defconst ediff-long-help-message-word-mode | |
355 | " | |
356 | p,DEL -previous diff | | -vert/horiz split | xy -copy buf X's region to Y | |
357 | n,SPC -next diff | h -hiliting | rx -restore buf X's old diff | |
358 | j -jump to diff | | | |
359 | gx -goto X's point| % -narrow/widen buffs | ! -recompute diffs | |
360 | C-l -recenter | | | |
361 | v/V -scroll up/dn | #f/#h -focus/hide regions | wx -save buf X | |
362 | </> -scroll lt/rt | X -read-only in buf X | wd -save diff output | |
8343426b | 363 | | m -wide display | ~ -swap buffers |
475f9031 | 364 | " |
41d25ad0 KH |
365 | "Help message when comparing windows or regions word-by-word. |
366 | Normally, not a user option. See `ediff-help-message' for details.") | |
475f9031 KH |
367 | |
368 | (defconst ediff-long-help-message-merge | |
369 | " | |
370 | p,DEL -previous diff | | -vert/horiz split | x -copy buf X's region to C | |
371 | n,SPC -next diff | h -hiliting | r -restore buf C's old diff | |
372 | j -jump to diff | @ -auto-refinement | * -refine current region | |
373 | gx -goto X's point| ## -ignore whitespace | ! -update diff regions | |
374 | C-l -recenter | #f/#h -focus/hide regions | + -combine diff regions | |
375 | v/V -scroll up/dn | X -read-only in buf X | wx -save buf X | |
376 | </> -scroll lt/rt | m -wide display | wd -save diff output | |
8343426b | 377 | / -ancestor buff | s -shrink window C | ~ -swap buffers |
475f9031 KH |
378 | | $ -show clashes only | & -merge w/new default |
379 | " | |
41d25ad0 KH |
380 | "Help message during merging. |
381 | Normally, not a user option. See `ediff-help-message' for details.") | |
475f9031 KH |
382 | |
383 | ;; The actual long help message. | |
384 | (ediff-defvar-local ediff-long-help-message "" | |
385 | "Normally, not a user option. See `ediff-help-message' for details.") | |
386 | ||
387 | (defconst ediff-brief-message-string | |
388 | " ? - help " | |
389 | "Contents of the brief help message.") | |
390 | ;; The actual brief help message | |
391 | (ediff-defvar-local ediff-brief-help-message "" | |
392 | "Normally, not a user option. See `ediff-help-message' for details.") | |
393 | ||
8343426b | 394 | (ediff-defvar-local ediff-brief-help-message-function nil |
475f9031 KH |
395 | "The brief help message that the user can customize. |
396 | If the user sets this to a parameter-less function, Ediff will use it to | |
397 | produce the brief help message. This function must return a string.") | |
8343426b | 398 | (ediff-defvar-local ediff-long-help-message-function nil |
475f9031 | 399 | "The long help message that the user can customize. |
8343426b | 400 | See `ediff-brief-help-message-function' for more.") |
475f9031 KH |
401 | |
402 | (defvar ediff-prefer-long-help-message nil | |
403 | "*If t, Ediff starts with a long help message. Short help msg otherwise.") | |
404 | ||
405 | ;; The actual help message. | |
406 | (ediff-defvar-local ediff-help-message "" | |
407 | "The actual help message. | |
408 | Normally, the user shouldn't touch this. However, if you want Ediff to | |
409 | start up with different help messages for different jobs, you can change | |
410 | the value of this variable and the variables `ediff-help-message-*' in | |
8343426b | 411 | `ediff-startup-hook'.") |
475f9031 KH |
412 | |
413 | ;; Selective browsing | |
414 | ||
415 | (ediff-defvar-local ediff-skip-diff-region-function 'ediff-show-all-diffs | |
416 | "Function that determines the next/previous diff region to show. | |
417 | Should return t for regions to be ignored and nil otherwise. | |
418 | This function gets a region number as an argument. The region number | |
419 | is the one used internally by Ediff. It is 1 less than the number seen | |
420 | by the user.") | |
421 | ||
8343426b MK |
422 | (ediff-defvar-local ediff-hide-regexp-matches-function |
423 | 'ediff-hide-regexp-matches | |
424 | "Function to use in determining which regions to hide. | |
425 | See the documentation string of `ediff-hide-regexp-matches' for details.") | |
426 | (ediff-defvar-local ediff-focus-on-regexp-matches-function | |
427 | 'ediff-focus-on-regexp-matches | |
428 | "Function to use in determining which regions to focus on. | |
429 | See the documentation string of `ediff-focus-on-regexp-matches' for details.") | |
430 | ||
475f9031 KH |
431 | ;; Regexp that determines buf A regions to focus on when skipping to diff |
432 | (ediff-defvar-local ediff-regexp-focus-A "" "") | |
433 | ;; Regexp that determines buf B regions to focus on when skipping to diff | |
434 | (ediff-defvar-local ediff-regexp-focus-B "" "") | |
435 | ;; Regexp that determines buf C regions to focus on when skipping to diff | |
436 | (ediff-defvar-local ediff-regexp-focus-C "" "") | |
437 | ;; connective that determines whether to focus regions that match both or | |
438 | ;; one of the regexps | |
439 | (ediff-defvar-local ediff-focus-regexp-connective 'and "") | |
440 | ||
441 | ;; Regexp that determines buf A regions to ignore when skipping to diff | |
442 | (ediff-defvar-local ediff-regexp-hide-A "" "") | |
443 | ;; Regexp that determines buf B regions to ignore when skipping to diff | |
444 | (ediff-defvar-local ediff-regexp-hide-B "" "") | |
445 | ;; Regexp that determines buf C regions to ignore when skipping to diff | |
446 | (ediff-defvar-local ediff-regexp-hide-C "" "") | |
447 | ;; connective that determines whether to hide regions that match both or | |
448 | ;; one of the regexps | |
449 | (ediff-defvar-local ediff-hide-regexp-connective 'and "") | |
450 | ||
451 | ||
452 | (defvar ediff-ange-ftp-ftp-name (if ediff-xemacs-p | |
453 | 'ange-ftp-ftp-path | |
454 | 'ange-ftp-ftp-name) | |
455 | "Function ange-ftp uses to find out if file is remote.") | |
456 | ||
457 | ||
458 | ;; Copying difference regions between buffers. | |
459 | (ediff-defvar-local ediff-killed-diffs-alist nil | |
460 | "A list of killed diffs. | |
461 | A diff is saved here if it is replaced by a diff | |
462 | from another buffer. This alist has the form: | |
463 | \((num (buff-object . diff) (buff-object . diff) (buff-object . diff)) ...), | |
464 | where some buffer-objects may be missing.") | |
465 | ||
466 | ||
467 | ;; Highlighting | |
41d25ad0 KH |
468 | ;;(defvar ediff-before-flag-bol (if ediff-emacs-p "->>\n" (make-glyph "->>\n")) |
469 | (defvar ediff-before-flag-bol (if ediff-xemacs-p (make-glyph "->>") "->>") | |
475f9031 KH |
470 | "*Flag placed above the highlighted block of differences. |
471 | Must end with newline.") | |
41d25ad0 KH |
472 | ;;(defvar ediff-after-flag-eol (if ediff-emacs-p "<<-\n" (make-glyph "<<-")) |
473 | (defvar ediff-after-flag-eol (if ediff-xemacs-p (make-glyph "<<-") "<<-") | |
475f9031 KH |
474 | "*Flag placed below the highlighted block of differences. |
475 | Must end with newline.") | |
476 | ||
41d25ad0 | 477 | (defvar ediff-before-flag-mol (if ediff-xemacs-p (make-glyph "->>") "->>") |
475f9031 | 478 | "*Like ediff-before-flag, used when a difference starts in mid-line.") |
41d25ad0 | 479 | (defvar ediff-after-flag-mol (if ediff-xemacs-p (make-glyph "<<-") "<<-") |
475f9031 KH |
480 | "*Like ediff-after-flag, used when a difference starts in mid-line.") |
481 | ||
475f9031 KH |
482 | |
483 | (ediff-defvar-local ediff-use-faces t | |
484 | "If t, differences are highlighted using faces on a window system. | |
485 | If nil, they are highlighted using ASCII flags, ediff-before-flag | |
486 | and ediff-after-flag. On a non-window system, differences are always | |
487 | highlighted using ASCII flags. | |
488 | This variable can be set either in .emacs or toggled interactively. | |
489 | Use `setq-default' if setting it in .emacs") | |
490 | ||
491 | ||
492 | ;; this indicates that diff regions are word-size, so fine diffs are | |
41d25ad0 | 493 | ;; permanently nixed; used in ediff-windows-wordwise and ediff-regions-wordwise |
475f9031 | 494 | (ediff-defvar-local ediff-word-mode nil "") |
8343426b | 495 | ;; Name of the job (ediff-files, ediff-windows, etc.) |
475f9031 KH |
496 | (ediff-defvar-local ediff-job-name nil "") |
497 | ||
498 | ;; Narrowing and ediff-region/windows support | |
499 | ;; This is a list (overlay-A overlay-B overlay-C) | |
500 | ;; If set, Ediff compares only those parts of buffers A/B/C that lie within | |
501 | ;; the bounds of these overlays. | |
502 | (ediff-defvar-local ediff-narrow-bounds nil "") | |
503 | ||
504 | ;; List (overlay-A overlay-B overlay-C), where each overlay spans the | |
505 | ;; entire corresponding buffer. | |
506 | (ediff-defvar-local ediff-wide-bounds nil "") | |
507 | ||
508 | ;; Current visibility boundaries in buffers A, B, and C. | |
509 | ;; This is also a list of overlays. When the user toggles narrow/widen, | |
510 | ;; this list changes from ediff-wide-bounds to ediff-narrow-bounds. | |
511 | ;; and back. | |
512 | (ediff-defvar-local ediff-visible-bounds nil "") | |
513 | ||
514 | (ediff-defvar-local ediff-start-narrowed t | |
41d25ad0 | 515 | "Non-nil means start narrowed, if doing ediff-windows-* or ediff-regions-*") |
475f9031 KH |
516 | (ediff-defvar-local ediff-quit-widened t |
517 | "*Non-nil means: when finished, Ediff widens buffers A/B. | |
518 | Actually, Ediff restores the scope of visibility that existed at startup.") | |
8343426b MK |
519 | (defvar ediff-keep-variants t |
520 | "*Nil means that non-modified variant buffers should be removed after some | |
521 | interrogation. | |
ceb0ea8b | 522 | Supplying a prefix argument to the quit command `q' temporarily reverses the |
8343426b | 523 | meaning of this variable.") |
475f9031 KH |
524 | |
525 | (ediff-defvar-local ediff-highlight-all-diffs t | |
526 | "If nil, only the selected differences are highlighted. | |
527 | This variable can be set either in .emacs or toggled interactively, using | |
528 | ediff-toggle-hilit. Use `setq-default' to set it.") | |
529 | ||
530 | ;; A var local to each control panel buffer. Indicates highlighting style | |
531 | ;; in effect for this buffer: `face', `ascii', nil -- temporarily | |
532 | ;; unhighlighted, `off' -- turned off \(on a dumb terminal only\). | |
533 | (ediff-defvar-local ediff-highlighting-style nil "") | |
534 | ||
535 | ||
536 | ;; Variables that control each Ediff session. They are local to the | |
537 | ;; control buffer. | |
538 | ||
539 | ;; Mode variables | |
540 | ;; The buffer in which the A variant is stored. | |
541 | (ediff-defvar-local ediff-buffer-A nil "") | |
542 | ;; The buffer in which the B variant is stored. | |
543 | (ediff-defvar-local ediff-buffer-B nil "") | |
544 | ;; The buffer in which the C variant is stored. | |
545 | (ediff-defvar-local ediff-buffer-C nil "") | |
546 | ;; Ancestor buffer | |
547 | (ediff-defvar-local ediff-ancestor-buffer nil "") | |
548 | ;; The control buffer of ediff. | |
549 | (ediff-defvar-local ediff-control-buffer nil "") | |
550 | ||
551 | ||
552 | ;; The suffix of the control buffer name. | |
553 | (ediff-defvar-local ediff-control-buffer-suffix nil "") | |
554 | ;; Same as ediff-control-buffer-suffix, but without <,>. | |
555 | ;; It's a number rather than string. | |
556 | (ediff-defvar-local ediff-control-buffer-number nil "") | |
557 | ||
558 | ||
475f9031 | 559 | ;; The original values of ediff-protected-variables for buffer A |
41d25ad0 | 560 | (ediff-defvar-local ediff-buffer-values-orig-A nil "") |
475f9031 | 561 | ;; The original values of ediff-protected-variables for buffer B |
41d25ad0 | 562 | (ediff-defvar-local ediff-buffer-values-orig-B nil "") |
475f9031 | 563 | ;; The original values of ediff-protected-variables for buffer C |
41d25ad0 | 564 | (ediff-defvar-local ediff-buffer-values-orig-C nil "") |
8343426b MK |
565 | ;; The original values of ediff-protected-variables for buffer Ancestor |
566 | (ediff-defvar-local ediff-buffer-values-orig-Ancestor nil "") | |
567 | ;; Buffer-local variables to be saved then restored during Ediff sessions | |
475f9031 KH |
568 | ;; Buffer-local variables to be saved then restored during Ediff sessions |
569 | (defconst ediff-protected-variables '(buffer-read-only | |
8343426b | 570 | synchronize-minibuffers |
475f9031 KH |
571 | mode-line-format)) |
572 | ||
475f9031 KH |
573 | ;; Vector of differences between the variants. Each difference is |
574 | ;; represented by a vector of two overlays plus a vector of fine diffs, | |
575 | ;; plus a no-fine-diffs flag. The first overlay spans the | |
576 | ;; difference region in the A buffer and the second overlays the diff in | |
577 | ;; the B buffer. If a difference section is empty, the corresponding | |
578 | ;; overlay's endpoints coincide. | |
579 | ;; | |
580 | ;; The precise form of a difference vector for one buffer is: | |
581 | ;; [diff diff diff ...] | |
582 | ;; where each diff has the form: | |
8343426b | 583 | ;; [diff-overlay fine-diff-vector no-fine-diffs-flag state-of-difference] |
475f9031 KH |
584 | ;; fine-diff-vector is a vector [fine-diff-overlay fine-diff-overlay ...] |
585 | ;; no-fine-diffs-flag says if there are fine differences. | |
586 | ;; state-of-difference is A, B, C, or nil, indicating which buffer is | |
587 | ;; different from the other two (used only in 3-way jobs. | |
475f9031 KH |
588 | (ediff-defvar-local ediff-difference-vector-A nil "") |
589 | (ediff-defvar-local ediff-difference-vector-B nil "") | |
590 | (ediff-defvar-local ediff-difference-vector-C nil "") | |
8343426b MK |
591 | (ediff-defvar-local ediff-difference-vector-Ancestor nil "") |
592 | ||
593 | ;; [ status status status ...] | |
594 | ;; Each status: [state-of-merge state-of-ancestor] | |
595 | ;; state-of-merge is default-A, default-B, prefer-A, or prefer-B. It | |
596 | ;; indicates the way a diff region was created in buffer C. | |
597 | ;; state-of-ancestor says if the corresponding region in ancestor buffer is | |
598 | ;; empty. | |
599 | (ediff-defvar-local ediff-state-of-merge nil "") | |
475f9031 KH |
600 | |
601 | ;; The difference that is currently selected. | |
602 | (ediff-defvar-local ediff-current-difference -1 "") | |
603 | ;; Number of differences found. | |
604 | (ediff-defvar-local ediff-number-of-differences nil "") | |
605 | ||
606 | ;; Buffer containing the output of diff, which is used by Ediff to step | |
607 | ;; through files. | |
608 | (ediff-defvar-local ediff-diff-buffer nil "") | |
609 | ;; Like ediff-diff-buffer, but contains context diff. It is not used by | |
610 | ;; Ediff, but it is saved in a file, if user requests so. | |
611 | (ediff-defvar-local ediff-custom-diff-buffer nil "") | |
612 | ;; Buffer used for diff-style fine differences between regions. | |
613 | (ediff-defvar-local ediff-fine-diff-buffer nil "") | |
614 | ;; Temporary buffer used for computing fine differences. | |
615 | (defconst ediff-tmp-buffer " *ediff-tmp*" "") | |
616 | ;; Buffer used for messages | |
617 | (defconst ediff-msg-buffer " *ediff-message*" "") | |
618 | ;; Buffer containing the output of diff when diff returns errors. | |
619 | (ediff-defvar-local ediff-error-buffer nil "") | |
620 | ;; Buffer to display debug info | |
621 | (ediff-defvar-local ediff-debug-buffer "*ediff-debug*" "") | |
622 | ||
8343426b MK |
623 | ;; List of ediff control panels associated with each buffer A/B/C/Ancestor. |
624 | ;; Not used any more, but may be needed in the future. | |
625 | (ediff-defvar-local ediff-this-buffer-ediff-sessions nil "") | |
475f9031 KH |
626 | |
627 | ;; to be deleted in due time | |
628 | ;; List of difference overlays disturbed by working with the current diff. | |
629 | (defvar ediff-disturbed-overlays nil "") | |
630 | ||
631 | ;; Priority of non-selected overlays. | |
632 | (defvar ediff-shadow-overlay-priority 100 "") | |
633 | ||
8343426b MK |
634 | (defvar ediff-version-control-package 'vc |
635 | "Version control package used. | |
636 | Currently, Ediff supports vc.el, rcs.el, and generic-sc.el. The standard Emacs | |
637 | interface to RCS, CVS, SCCS, etc., is vc.el. However, some people find the | |
638 | other two packages more convenient. Set this variable `rcs' or `generic-sc' if | |
639 | you are such a person.") | |
640 | ||
475f9031 KH |
641 | |
642 | (if ediff-xemacs-p | |
643 | (progn | |
644 | (fset 'ediff-read-event (symbol-function 'next-command-event)) | |
645 | (fset 'ediff-overlayp (symbol-function 'extentp)) | |
646 | (fset 'ediff-make-overlay (symbol-function 'make-extent)) | |
647 | (fset 'ediff-delete-overlay (symbol-function 'delete-extent)) | |
648 | (fset 'ediff-overlay-buffer (symbol-function 'extent-buffer)) | |
475f9031 KH |
649 | (fset 'ediff-overlay-get (symbol-function 'extent-property))) |
650 | (fset 'ediff-read-event (symbol-function 'read-event)) | |
651 | (fset 'ediff-overlayp (symbol-function 'overlayp)) | |
41d25ad0 | 652 | (fset 'ediff-overlayp (symbol-function 'overlayp)) |
475f9031 KH |
653 | (fset 'ediff-make-overlay (symbol-function 'make-overlay)) |
654 | (fset 'ediff-delete-overlay (symbol-function 'delete-overlay)) | |
655 | (fset 'ediff-overlay-buffer (symbol-function 'overlay-buffer)) | |
475f9031 KH |
656 | (fset 'ediff-overlay-get (symbol-function 'overlay-get))) |
657 | ||
41d25ad0 KH |
658 | ;; Check the current version against the major and minor version numbers |
659 | ;; using op: cur-vers op major.minor If emacs-major-version or | |
660 | ;; emacs-minor-version are not defined, we assume that the current version | |
661 | ;; is hopelessly outdated. We assume that emacs-major-version and | |
662 | ;; emacs-minor-version are defined. Otherwise, for Emacs/XEmacs 19, if the | |
663 | ;; current minor version is < 10 (xemacs) or < 23 (emacs) the return value | |
664 | ;; will be nil (when op is =, >, or >=) and t (when op is <, <=), which may be | |
665 | ;; incorrect. However, this gives correct result in our cases, since we are | |
666 | ;; testing for sufficiently high Emacs versions. | |
667 | (defun ediff-check-version (op major minor &optional type-of-emacs) | |
668 | (if (and (boundp 'emacs-major-version) (boundp 'emacs-minor-version)) | |
669 | (and (cond ((eq type-of-emacs 'xemacs) ediff-xemacs-p) | |
670 | ((eq type-of-emacs 'emacs) ediff-emacs-p) | |
671 | (t t)) | |
672 | (cond ((eq op '=) (and (= emacs-minor-version minor) | |
673 | (= emacs-major-version major))) | |
674 | ((memq op '(> >= < <=)) | |
675 | (and (or (funcall op emacs-major-version major) | |
676 | (= emacs-major-version major)) | |
677 | (if (= emacs-major-version major) | |
678 | (funcall op emacs-minor-version minor) | |
679 | t))) | |
680 | (t | |
681 | (error "%S: Invalid op in ediff-check-version" op)))) | |
682 | (cond ((memq op '(= > >=)) nil) | |
683 | ((memq op '(< <=)) t)))) | |
684 | ||
8343426b MK |
685 | |
686 | ;;;; warn if it is a wrong version of emacs | |
687 | ;;(if (or (ediff-check-version '< 19 29 'emacs) | |
688 | ;; (ediff-check-version '< 19 12 'xemacs)) | |
689 | ;; (progn | |
690 | ;; (with-output-to-temp-buffer ediff-msg-buffer | |
691 | ;; (switch-to-buffer ediff-msg-buffer) | |
692 | ;; (insert | |
693 | ;; (format " | |
694 | ;; | |
695 | ;;This version of Ediff requires | |
696 | ;; | |
697 | ;;\t Emacs 19.29 and higher | |
698 | ;;\t OR | |
699 | ;;\t XEmacs 19.12 and higher | |
700 | ;; | |
701 | ;;It is unlikely to work under Emacs version %s | |
702 | ;;that you are using... " emacs-version)) | |
703 | ;; (if noninteractive | |
704 | ;; () | |
705 | ;; (beep 1) | |
706 | ;; (beep 1) | |
707 | ;; (insert "\n\nType any key to continue...") | |
708 | ;; (ediff-read-event))) | |
709 | ;; (kill-buffer ediff-msg-buffer))) | |
710 | ||
475f9031 KH |
711 | ;; A fix for NeXT Step |
712 | ;; Should probably be eliminated in later versions. | |
41d25ad0 | 713 | (if (and (ediff-window-display-p) (eq (ediff-device-type) 'ns)) |
475f9031 KH |
714 | (progn |
715 | (fset 'x-display-color-p (symbol-function 'ns-display-color-p)) | |
716 | (fset 'x-color-defined-p (symbol-function 'ns-color-defined-p)) | |
717 | (fset 'x-display-pixel-height (symbol-function 'ns-display-pixel-height)) | |
718 | (fset 'x-display-pixel-width (symbol-function 'ns-display-pixel-width)) | |
719 | )) | |
41d25ad0 | 720 | |
8343426b | 721 | |
41d25ad0 KH |
722 | (defsubst ediff-color-display-p () |
723 | (if ediff-emacs-p | |
724 | (x-display-color-p) | |
725 | (eq (device-class (selected-device)) 'color))) | |
8343426b | 726 | |
475f9031 | 727 | |
41d25ad0 KH |
728 | (if (ediff-window-display-p) |
729 | (if ediff-xemacs-p | |
730 | (progn | |
731 | (fset 'ediff-display-pixel-width | |
732 | (symbol-function 'device-pixel-width)) | |
733 | (fset 'ediff-display-pixel-height | |
734 | (symbol-function 'device-pixel-height)) | |
735 | (fset 'ediff-valid-color-p (symbol-function 'valid-color-name-p)) | |
736 | (fset 'ediff-get-face (symbol-function 'get-face))) | |
737 | ;; Temporary fix for OS/2 port of Emacs | |
738 | ;; pm-win.el in PM-Emacs should be fixed. | |
739 | (fset 'ediff-display-pixel-width | |
740 | (symbol-function 'x-display-pixel-width)) | |
741 | (fset 'ediff-display-pixel-height | |
742 | (symbol-function 'x-display-pixel-height)) | |
743 | (if (eq (ediff-device-type) 'pm) | |
744 | (fset 'ediff-valid-color-p | |
745 | (function (lambda (color) (assoc color pm-color-alist)))) | |
746 | (fset 'ediff-valid-color-p (symbol-function 'x-color-defined-p))) | |
747 | (fset 'ediff-get-face (symbol-function 'internal-get-face)))) | |
475f9031 | 748 | |
475f9031 | 749 | |
8343426b MK |
750 | (defun ediff-make-current-diff-overlay (type) |
751 | (if (ediff-window-display-p) | |
752 | (let ((overlay (intern (format "ediff-current-diff-overlay-%S" type))) | |
753 | (buffer (ediff-get-buffer type)) | |
754 | (face (face-name | |
755 | (symbol-value | |
756 | (intern (format "ediff-current-diff-face-%S" type)))))) | |
757 | (set overlay | |
758 | (ediff-make-bullet-proof-overlay (point-max) (point-max) buffer)) | |
759 | (ediff-set-overlay-face (symbol-value overlay) face) | |
760 | (ediff-overlay-put (symbol-value overlay) 'ediff ediff-control-buffer)) | |
761 | )) | |
762 | ||
763 | (defun ediff-set-overlay-face (extent face) | |
764 | (ediff-overlay-put extent 'face face) | |
765 | (ediff-overlay-put extent 'help-echo 'ediff-region-help-echo)) | |
766 | ||
767 | ;; This does nothing in Emacs, since overlays there have no help-echo property | |
768 | (defun ediff-region-help-echo (extent) | |
769 | (let ((is-current (ediff-overlay-get extent 'ediff)) | |
770 | (face (ediff-overlay-get extent 'face)) | |
771 | (diff-num (ediff-overlay-get extent 'ediff-diff-num)) | |
772 | face-help help-msg) | |
773 | ||
774 | ;; This happens only for refinement overlays | |
775 | (setq face-help (and face (get face 'ediff-help-echo))) | |
776 | ||
777 | (setq help-msg | |
778 | (cond ((and is-current diff-num) ; current diff region | |
779 | (format "Difference region %S -- current" (1+ diff-num))) | |
780 | (face-help) ; refinement of current diff region | |
781 | (diff-num ; non-current | |
782 | (format "Difference region %S -- non-current" (1+ diff-num))) | |
783 | (t ""))))) ; none | |
784 | ||
785 | (defun ediff-set-face (ground face color) | |
786 | "Set face foreground/background." | |
787 | (if (ediff-window-display-p) | |
788 | (if (ediff-valid-color-p color) | |
789 | (if (eq ground 'foreground) | |
790 | (set-face-foreground face color) | |
791 | (set-face-background face color)) | |
792 | (cond ((memq face | |
793 | '(ediff-current-diff-face-A | |
794 | ediff-current-diff-face-B | |
795 | ediff-current-diff-face-C | |
796 | ediff-current-diff-face-Ancestor)) | |
797 | (copy-face 'highlight face)) | |
798 | ((memq face | |
799 | '(ediff-fine-diff-face-A | |
800 | ediff-fine-diff-face-B | |
801 | ediff-fine-diff-face-C | |
802 | ediff-fine-diff-face-Ancestor)) | |
803 | (copy-face 'secondary-selection face) | |
804 | (set-face-underline-p face t)) | |
805 | ((memq face | |
806 | '(ediff-even-diff-face-A | |
807 | ediff-odd-diff-face-A | |
808 | ediff-even-diff-face-B ediff-odd-diff-face-B | |
809 | ediff-even-diff-face-C ediff-odd-diff-face-C | |
810 | ediff-even-diff-face-Ancestor | |
811 | ediff-odd-diff-face-Ancestor)) | |
812 | (copy-face 'secondary-selection face)))) | |
813 | )) | |
475f9031 | 814 | |
2ff24a23 | 815 | (add-to-list 'facemenu-unlisted-faces 'ediff-current-diff-face-A) |
8343426b MK |
816 | (defvar ediff-current-diff-face-A |
817 | (if (ediff-window-display-p) | |
818 | (progn | |
819 | (make-face 'ediff-current-diff-face-A) | |
820 | (or (face-differs-from-default-p 'ediff-current-diff-face-A) | |
821 | (cond ((ediff-color-display-p) | |
822 | (ediff-set-face | |
823 | 'foreground 'ediff-current-diff-face-A "firebrick") | |
824 | (ediff-set-face | |
825 | 'background 'ediff-current-diff-face-A "pale green")) | |
826 | (t | |
827 | (if ediff-xemacs-p | |
828 | (copy-face 'modeline 'ediff-current-diff-face-A) | |
829 | (copy-face 'highlight 'ediff-current-diff-face-A)) | |
830 | ))) | |
831 | 'ediff-current-diff-face-A)) | |
832 | "Face for highlighting the selected difference in buffer A.") | |
833 | ||
2ff24a23 | 834 | (add-to-list 'facemenu-unlisted-faces 'ediff-current-diff-face-B) |
8343426b MK |
835 | (defvar ediff-current-diff-face-B |
836 | (if (ediff-window-display-p) | |
837 | (progn | |
838 | (make-face 'ediff-current-diff-face-B) | |
839 | (or (face-differs-from-default-p 'ediff-current-diff-face-B) | |
840 | (cond ((ediff-color-display-p) | |
841 | (ediff-set-face | |
842 | 'foreground 'ediff-current-diff-face-B "DarkOrchid") | |
843 | (ediff-set-face | |
844 | 'background 'ediff-current-diff-face-B "Yellow")) | |
845 | (t | |
846 | (if ediff-xemacs-p | |
847 | (copy-face 'modeline 'ediff-current-diff-face-B) | |
848 | (copy-face 'highlight 'ediff-current-diff-face-B)) | |
849 | ))) | |
850 | 'ediff-current-diff-face-B)) | |
851 | "Face for highlighting the selected difference in buffer B.") | |
475f9031 KH |
852 | |
853 | ||
2ff24a23 | 854 | (add-to-list 'facemenu-unlisted-faces 'ediff-current-diff-face-C) |
8343426b MK |
855 | (defvar ediff-current-diff-face-C |
856 | (if (ediff-window-display-p) | |
857 | (progn | |
858 | (make-face 'ediff-current-diff-face-C) | |
859 | (or (face-differs-from-default-p 'ediff-current-diff-face-C) | |
860 | (cond ((ediff-color-display-p) | |
861 | (ediff-set-face | |
862 | 'foreground 'ediff-current-diff-face-C "Navy") | |
863 | (ediff-set-face | |
864 | 'background 'ediff-current-diff-face-C "Pink")) | |
865 | (t | |
866 | (if ediff-xemacs-p | |
867 | (copy-face 'modeline 'ediff-current-diff-face-C) | |
868 | (copy-face 'highlight 'ediff-current-diff-face-C)) | |
869 | ))) | |
870 | 'ediff-current-diff-face-C)) | |
871 | "Face for highlighting the selected difference in buffer C.") | |
872 | ||
2ff24a23 | 873 | (add-to-list 'facemenu-unlisted-faces 'ediff-current-diff-face-Ancestor) |
8343426b MK |
874 | (defvar ediff-current-diff-face-Ancestor |
875 | (if (ediff-window-display-p) | |
876 | (progn | |
877 | (make-face 'ediff-current-diff-face-Ancestor) | |
878 | (or (face-differs-from-default-p 'ediff-current-diff-face-Ancestor) | |
879 | (copy-face | |
880 | 'ediff-current-diff-face-C 'ediff-current-diff-face-Ancestor)))) | |
881 | "Face for highlighting the selected difference in the ancestor buffer.") | |
882 | ||
2ff24a23 | 883 | (add-to-list 'facemenu-unlisted-faces 'ediff-fine-diff-face-A) |
8343426b MK |
884 | (defvar ediff-fine-diff-face-A |
885 | (if (ediff-window-display-p) | |
886 | (progn | |
887 | (make-face 'ediff-fine-diff-face-A) | |
888 | (or (face-differs-from-default-p 'ediff-fine-diff-face-A) | |
889 | (cond ((ediff-color-display-p) | |
890 | (ediff-set-face 'foreground 'ediff-fine-diff-face-A | |
891 | "Navy") | |
892 | (ediff-set-face 'background 'ediff-fine-diff-face-A | |
893 | "sky blue")) | |
894 | (t (set-face-underline-p 'ediff-fine-diff-face-A t)))) | |
895 | 'ediff-fine-diff-face-A)) | |
896 | "Face for highlighting the refinement of the selected diff in buffer A.") | |
897 | ||
2ff24a23 | 898 | (add-to-list 'facemenu-unlisted-faces 'ediff-fine-diff-face-B) |
8343426b MK |
899 | (defvar ediff-fine-diff-face-B |
900 | (if (ediff-window-display-p) | |
901 | (progn | |
902 | (make-face 'ediff-fine-diff-face-B) | |
903 | (or (face-differs-from-default-p 'ediff-fine-diff-face-B) | |
904 | (cond ((ediff-color-display-p) | |
905 | (ediff-set-face 'foreground 'ediff-fine-diff-face-B "Black") | |
906 | (ediff-set-face 'background 'ediff-fine-diff-face-B "cyan")) | |
907 | (t (set-face-underline-p 'ediff-fine-diff-face-B t)))) | |
908 | 'ediff-fine-diff-face-B)) | |
909 | "Face for highlighting the refinement of the selected diff in buffer B.") | |
475f9031 | 910 | |
2ff24a23 | 911 | (add-to-list 'facemenu-unlisted-faces 'ediff-fine-diff-face-C) |
8343426b MK |
912 | (defvar ediff-fine-diff-face-C |
913 | (if (ediff-window-display-p) | |
914 | (progn | |
915 | (make-face 'ediff-fine-diff-face-C) | |
916 | (or (face-differs-from-default-p 'ediff-fine-diff-face-C) | |
917 | (cond ((ediff-color-display-p) | |
918 | (ediff-set-face 'foreground 'ediff-fine-diff-face-C "black") | |
919 | (ediff-set-face | |
920 | 'background 'ediff-fine-diff-face-C "Turquoise")) | |
921 | (t (set-face-underline-p 'ediff-fine-diff-face-C t)))) | |
922 | 'ediff-fine-diff-face-C)) | |
923 | "Face for highlighting the refinement of the selected diff in buffer C.") | |
924 | ||
2ff24a23 | 925 | (add-to-list 'facemenu-unlisted-faces 'ediff-fine-diff-face-Ancestor) |
8343426b MK |
926 | (defvar ediff-fine-diff-face-Ancestor |
927 | (if (ediff-window-display-p) | |
928 | (progn | |
929 | (make-face 'ediff-fine-diff-face-Ancestor) | |
930 | (or (face-differs-from-default-p 'ediff-fine-diff-face-Ancestor) | |
931 | (copy-face | |
932 | 'ediff-fine-diff-face-C 'ediff-fine-diff-face-Ancestor)))) | |
933 | "Face highlighting refinements of the selected diff in ancestor buffer. | |
934 | Presently, this is not used, as difference regions are not refined in the | |
935 | ancestor buffer.") | |
475f9031 | 936 | |
2ff24a23 | 937 | (add-to-list 'facemenu-unlisted-faces 'ediff-even-diff-face-A) |
8343426b MK |
938 | (defvar ediff-even-diff-face-A |
939 | (if (ediff-window-display-p) | |
940 | (progn | |
941 | (make-face 'ediff-even-diff-face-A) | |
942 | (or (face-differs-from-default-p 'ediff-even-diff-face-A) | |
943 | (cond ((ediff-color-display-p) | |
944 | (ediff-set-face | |
945 | 'foreground 'ediff-even-diff-face-A "black") | |
946 | (ediff-set-face | |
947 | 'background 'ediff-even-diff-face-A "light grey")) | |
948 | (t | |
949 | (copy-face 'italic 'ediff-even-diff-face-A)))) | |
950 | 'ediff-even-diff-face-A)) | |
951 | "Face used to highlight even-numbered differences in buffer A.") | |
475f9031 | 952 | |
2ff24a23 | 953 | (add-to-list 'facemenu-unlisted-faces 'ediff-even-diff-face-B) |
8343426b MK |
954 | (defvar ediff-even-diff-face-B |
955 | (if (ediff-window-display-p) | |
956 | (progn | |
957 | (make-face 'ediff-even-diff-face-B) | |
958 | (or (face-differs-from-default-p 'ediff-even-diff-face-B) | |
959 | (cond ((ediff-color-display-p) | |
960 | (ediff-set-face | |
961 | 'foreground 'ediff-even-diff-face-B "White") | |
962 | (ediff-set-face | |
963 | 'background 'ediff-even-diff-face-B "Gray")) | |
964 | (t | |
965 | (copy-face 'italic 'ediff-even-diff-face-B)))) | |
966 | 'ediff-even-diff-face-B)) | |
967 | "Face used to highlight even-numbered differences in buffer B.") | |
475f9031 | 968 | |
2ff24a23 | 969 | (add-to-list 'facemenu-unlisted-faces 'ediff-even-diff-face-C) |
8343426b MK |
970 | (defvar ediff-even-diff-face-C |
971 | (if (ediff-window-display-p) | |
972 | (progn | |
973 | (make-face 'ediff-even-diff-face-C) | |
974 | (or (face-differs-from-default-p 'ediff-even-diff-face-C) | |
975 | (copy-face 'ediff-even-diff-face-A 'ediff-even-diff-face-C)) | |
976 | 'ediff-even-diff-face-C)) | |
977 | "Face used to highlight even-numbered differences in buffer C.") | |
978 | ||
2ff24a23 | 979 | (add-to-list 'facemenu-unlisted-faces 'ediff-even-diff-face-Ancestor) |
8343426b MK |
980 | (defvar ediff-even-diff-face-Ancestor |
981 | (if (ediff-window-display-p) | |
982 | (progn | |
983 | (make-face 'ediff-even-diff-face-Ancestor) | |
984 | (or (face-differs-from-default-p 'ediff-even-diff-face-Ancestor) | |
985 | (copy-face 'ediff-even-diff-face-C 'ediff-even-diff-face-Ancestor)) | |
986 | 'ediff-even-diff-face-Ancestor)) | |
987 | "Face highlighting even-numbered differences in the ancestor buffer.") | |
475f9031 | 988 | |
2ff24a23 | 989 | (add-to-list 'facemenu-unlisted-faces 'ediff-odd-diff-face-A) |
8343426b MK |
990 | (defvar ediff-odd-diff-face-A |
991 | (if (ediff-window-display-p) | |
992 | (progn | |
993 | (make-face 'ediff-odd-diff-face-A) | |
994 | (or (face-differs-from-default-p 'ediff-odd-diff-face-A) | |
995 | (cond ((ediff-color-display-p) | |
996 | (ediff-set-face | |
997 | 'foreground 'ediff-odd-diff-face-A "White") | |
998 | (ediff-set-face | |
999 | 'background 'ediff-odd-diff-face-A "Gray")) | |
1000 | (t | |
1001 | (copy-face 'italic 'ediff-odd-diff-face-A)))) | |
1002 | 'ediff-odd-diff-face-A)) | |
1003 | "Face used to highlight odd-numbered differences in buffer A.") | |
475f9031 | 1004 | |
2ff24a23 | 1005 | (add-to-list 'facemenu-unlisted-faces 'ediff-odd-diff-face-B) |
8343426b MK |
1006 | (defvar ediff-odd-diff-face-B |
1007 | (if (ediff-window-display-p) | |
1008 | (progn | |
1009 | (make-face 'ediff-odd-diff-face-B) | |
1010 | (or (face-differs-from-default-p 'ediff-odd-diff-face-B) | |
1011 | (cond ((ediff-color-display-p) | |
1012 | (ediff-set-face | |
1013 | 'foreground 'ediff-odd-diff-face-B "Black") | |
1014 | (ediff-set-face | |
1015 | 'background 'ediff-odd-diff-face-B "light grey")) | |
1016 | (t | |
1017 | (copy-face 'italic 'ediff-odd-diff-face-B)))) | |
1018 | 'ediff-odd-diff-face-B)) | |
1019 | "Face used to highlight odd-numbered differences in buffer B.") | |
475f9031 | 1020 | |
2ff24a23 | 1021 | (add-to-list 'facemenu-unlisted-faces 'ediff-odd-diff-face-C) |
8343426b MK |
1022 | (defvar ediff-odd-diff-face-C |
1023 | (if (ediff-window-display-p) | |
1024 | (progn | |
1025 | (make-face 'ediff-odd-diff-face-C) | |
1026 | (or (face-differs-from-default-p 'ediff-odd-diff-face-C) | |
1027 | (copy-face 'ediff-odd-diff-face-A 'ediff-odd-diff-face-C)) | |
1028 | 'ediff-odd-diff-face-C)) | |
1029 | "Face used to highlight odd-numbered differences in buffer C.") | |
1030 | ||
2ff24a23 | 1031 | (add-to-list 'facemenu-unlisted-faces 'ediff-odd-diff-face-Ancestor ) |
8343426b MK |
1032 | (defvar ediff-odd-diff-face-Ancestor |
1033 | (if (ediff-window-display-p) | |
1034 | (progn | |
1035 | (make-face 'ediff-odd-diff-face-Ancestor) | |
1036 | (or (face-differs-from-default-p 'ediff-odd-diff-face-Ancestor) | |
1037 | (copy-face 'ediff-odd-diff-face-C 'ediff-odd-diff-face-Ancestor)) | |
1038 | 'ediff-odd-diff-face-Ancestor)) | |
1039 | "Face used to highlight even-numbered differences in the ancestor buffer.") | |
1040 | ||
1041 | ;; Help echo | |
1042 | (put 'ediff-fine-diff-face-A 'ediff-help-echo | |
1043 | "A `refinement' of the current difference region") | |
1044 | (put 'ediff-fine-diff-face-B 'ediff-help-echo | |
1045 | "A `refinement' of the current difference region") | |
1046 | (put 'ediff-fine-diff-face-C 'ediff-help-echo | |
1047 | "A `refinement' of the current difference region") | |
1048 | (put 'ediff-fine-diff-face-Ancestor 'ediff-help-echo | |
1049 | "A `refinement' of the current difference region") | |
1050 | ||
475f9031 KH |
1051 | |
1052 | ;;; Overlays | |
1053 | ||
8343426b MK |
1054 | (ediff-defvar-local ediff-current-diff-overlay-A nil |
1055 | "Overlay for the current difference region in buffer A.") | |
1056 | (ediff-defvar-local ediff-current-diff-overlay-B nil | |
1057 | "Overlay for the current difference region in buffer B.") | |
1058 | (ediff-defvar-local ediff-current-diff-overlay-C nil | |
1059 | "Overlay for the current difference region in buffer C.") | |
1060 | (ediff-defvar-local ediff-current-diff-overlay-Ancestor nil | |
1061 | "Overlay for the current difference region in the ancestor buffer.") | |
475f9031 | 1062 | |
8343426b MK |
1063 | ;; Compute priority of ediff overlay. |
1064 | (defun ediff-highest-priority (start end buffer) | |
1065 | (let ((pos (max 1 (1- start))) | |
1066 | ovr-list) | |
1067 | (if ediff-xemacs-p | |
1068 | (1+ ediff-shadow-overlay-priority) | |
1069 | (ediff-eval-in-buffer buffer | |
1070 | (while (< pos (min (point-max) (1+ end))) | |
1071 | (setq ovr-list (append (overlays-at pos) ovr-list)) | |
1072 | (setq pos (next-overlay-change pos))) | |
1073 | (1+ (apply '+ | |
1074 | (mapcar (function | |
1075 | (lambda (ovr) | |
1076 | (if ovr | |
1077 | (or (ediff-overlay-get ovr 'priority) 0) | |
1078 | 0))) | |
1079 | ovr-list) | |
1080 | )) | |
1081 | )))) | |
475f9031 KH |
1082 | |
1083 | ||
1084 | (defvar ediff-toggle-read-only-function nil | |
1085 | "*Specifies the function to be used to toggle read-only. | |
1086 | If nil, Ediff tries to deduce the function from the binding of C-x C-q. | |
1087 | Normally, this is the `toggle-read-only' function, but, if version | |
1088 | control is used, it could be `vc-toggle-read-only' or `rcs-toggle-read-only'.") | |
1089 | ||
475f9031 KH |
1090 | |
1091 | ;;; Misc | |
1092 | ||
475f9031 KH |
1093 | ;; if nil, this silences some messages |
1094 | (defconst ediff-verbose-p t) | |
1095 | ||
1096 | (defvar ediff-no-emacs-help-in-control-buffer nil | |
1097 | "*Non-nil means C-h should not invoke Emacs help in control buffer. | |
1098 | Instead, C-h jumps to previous difference.") | |
1099 | ||
1100 | (defvar ediff-temp-file-prefix | |
1101 | (let ((env (or (getenv "TMPDIR") | |
1102 | (getenv "TMP") | |
1103 | (getenv "TEMP"))) | |
1104 | d) | |
1105 | (setq d (if (and env (> (length env) 0)) | |
1106 | env | |
1107 | (if (memq system-type '(vax-vms axp-vms)) | |
1108 | "SYS$SCRATCH:" | |
1109 | "/tmp"))) | |
1110 | ;; The following is to make sure we get something to which we can | |
1111 | ;; add directory levels on VMS. | |
1112 | (setq d (file-name-as-directory (directory-file-name d))) | |
475f9031 KH |
1113 | ) |
1114 | "*Prefix to put on Ediff temporary file names. | |
1115 | Do not start with `~/' or `~user-name/'.") | |
1116 | ||
1117 | (defvar ediff-temp-file-mode 384 ; u=rw only | |
1118 | "*Mode for Ediff temporary files.") | |
1119 | ||
1120 | ;; Metacharacters that have to be protected from the shell when executing | |
1121 | ;; a diff/diff3 command. | |
1122 | (defvar ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]" | |
1123 | "Characters that must be quoted with \\ when used in a shell command line. | |
1124 | More precisely, a regexp to match any one such character.") | |
1125 | ||
1126 | ||
1127 | (ediff-defvar-local ediff-temp-file-A nil | |
1128 | "Temporary file used for refining difference regions in buffer A.") | |
1129 | (ediff-defvar-local ediff-temp-file-B nil | |
1130 | "Temporary file used for refining difference regions in buffer B.") | |
1131 | (ediff-defvar-local ediff-temp-file-C nil | |
1132 | "Temporary file used for refining difference regions in buffer C.") | |
1133 | ||
1134 | ;;; In-line functions | |
1135 | ||
1136 | (defsubst ediff-file-remote-p (file-name) | |
1137 | (if (fboundp ediff-ange-ftp-ftp-name) | |
1138 | (funcall ediff-ange-ftp-ftp-name file-name))) | |
1139 | ||
41d25ad0 KH |
1140 | ;;(defun ediff-frame-has-menubar () |
1141 | ;; (and (ediff-window-display-p) | |
1142 | ;; (if ediff-xemacs-p | |
1143 | ;; current-menubar | |
1144 | ;; (let ((lines (cdr (assq 'menu-bar-lines | |
1145 | ;; (frame-parameters (selected-frame)))))) | |
1146 | ;; (or (eq lines t) (and (numberp lines) (< 0 lines)))) | |
1147 | ;; ))) | |
475f9031 KH |
1148 | |
1149 | (defsubst ediff-frame-unsplittable-p (frame) | |
41d25ad0 | 1150 | (cdr (assq 'unsplittable (frame-parameters frame)))) |
475f9031 KH |
1151 | |
1152 | (defsubst ediff-get-next-window (wind prev-wind) | |
1153 | (or (window-live-p wind) | |
1154 | (setq wind (if prev-wind | |
1155 | (next-window wind) | |
1156 | (selected-window))))) | |
1157 | ||
475f9031 KH |
1158 | |
1159 | (defsubst ediff-kill-buffer-carefully (buf) | |
1160 | "Kill buffer BUF if it exists." | |
1161 | (if (ediff-buffer-live-p buf) | |
1162 | (kill-buffer (get-buffer buf)))) | |
1163 | ||
1164 | ||
1165 | (defsubst ediff-highlight-diff (n) | |
1166 | "Put face on diff N. Invoked for X displays only." | |
1167 | (ediff-highlight-diff-in-one-buffer n 'A) | |
1168 | (ediff-highlight-diff-in-one-buffer n 'B) | |
8343426b MK |
1169 | (ediff-highlight-diff-in-one-buffer n 'C) |
1170 | (ediff-highlight-diff-in-one-buffer n 'Ancestor) | |
1171 | ) | |
475f9031 KH |
1172 | |
1173 | ||
1174 | (defsubst ediff-unhighlight-diff () | |
1175 | "Remove overlays from buffers A, B, and C." | |
1176 | (ediff-unhighlight-diff-in-one-buffer 'A) | |
1177 | (ediff-unhighlight-diff-in-one-buffer 'B) | |
8343426b MK |
1178 | (ediff-unhighlight-diff-in-one-buffer 'C) |
1179 | (ediff-unhighlight-diff-in-one-buffer 'Ancestor) | |
1180 | ) | |
475f9031 KH |
1181 | |
1182 | ;; delete highlighting overlays, restore faces to their original form | |
1183 | (defsubst ediff-unhighlight-diffs-totally () | |
1184 | (ediff-unhighlight-diffs-totally-in-one-buffer 'A) | |
1185 | (ediff-unhighlight-diffs-totally-in-one-buffer 'B) | |
8343426b MK |
1186 | (ediff-unhighlight-diffs-totally-in-one-buffer 'C) |
1187 | (ediff-unhighlight-diffs-totally-in-one-buffer 'Ancestor) | |
1188 | ) | |
1189 | ||
1190 | (defsubst ediff-background-face (buf-type dif-num) | |
1191 | ;; The value of dif-num is always 1- the one that user sees. | |
1192 | ;; This is why even face is used when dif-num is odd. | |
1193 | (intern (format (if (ediff-odd-p dif-num) | |
1194 | "ediff-even-diff-face-%S" | |
1195 | "ediff-odd-diff-face-%S") | |
1196 | buf-type))) | |
475f9031 KH |
1197 | |
1198 | ||
1199 | ;; arg is a record for a given diff in a difference vector | |
1200 | ;; this record is itself a vector | |
1201 | (defsubst ediff-clear-fine-diff-vector (diff-record) | |
1202 | (if diff-record | |
1203 | (mapcar 'ediff-delete-overlay | |
1204 | (ediff-get-fine-diff-vector-from-diff-record diff-record)))) | |
1205 | ||
1206 | (defsubst ediff-clear-fine-differences-in-one-buffer (n buf-type) | |
1207 | (ediff-clear-fine-diff-vector (ediff-get-difference n buf-type)) | |
1208 | (ediff-set-fine-diff-vector n buf-type nil)) | |
1209 | ||
1210 | (defsubst ediff-clear-fine-differences (n) | |
1211 | (ediff-clear-fine-differences-in-one-buffer n 'A) | |
1212 | (ediff-clear-fine-differences-in-one-buffer n 'B) | |
1213 | (if ediff-3way-job | |
1214 | (ediff-clear-fine-differences-in-one-buffer n 'C))) | |
1215 | ||
1216 | ||
1217 | (defsubst ediff-convert-fine-diffs-to-overlays (diff-list region-num) | |
1218 | (ediff-set-fine-overlays-in-one-buffer 'A diff-list region-num) | |
1219 | (ediff-set-fine-overlays-in-one-buffer 'B diff-list region-num) | |
1220 | (if ediff-3way-job | |
1221 | (ediff-set-fine-overlays-in-one-buffer 'C diff-list region-num) | |
1222 | )) | |
1223 | ||
1224 | (defsubst ediff-mouse-event-p (event) | |
1225 | (if ediff-xemacs-p | |
1226 | (button-event-p event) | |
1227 | (string-match "mouse" (format "%S" (event-basic-type event))) | |
1228 | )) | |
8343426b MK |
1229 | |
1230 | ||
1231 | (defsubst ediff-key-press-event-p (event) | |
1232 | (if ediff-xemacs-p | |
1233 | (key-press-event-p event) | |
1234 | (or (char-or-string-p event) (symbolp event)))) | |
1235 | ||
1236 | (defun ediff-event-point (event) | |
1237 | (cond ((ediff-mouse-event-p event) | |
1238 | (if ediff-xemacs-p | |
1239 | (event-point event) | |
1240 | (posn-point (event-start event)))) | |
1241 | ((ediff-key-press-event-p event) | |
1242 | (point)) | |
1243 | (t (error)))) | |
1244 | ||
1245 | (defun ediff-event-buffer (event) | |
1246 | (cond ((ediff-mouse-event-p event) | |
1247 | (if ediff-xemacs-p | |
1248 | (event-buffer event) | |
1249 | (window-buffer (posn-window (event-start event))))) | |
1250 | ((ediff-key-press-event-p event) | |
1251 | (current-buffer)) | |
1252 | (t (error)))) | |
1253 | ||
475f9031 KH |
1254 | |
1255 | (defsubst ediff-frame-iconified-p (frame) | |
41d25ad0 | 1256 | (if (and (ediff-window-display-p) (frame-live-p frame)) |
475f9031 | 1257 | (if ediff-xemacs-p |
41d25ad0 | 1258 | (frame-iconified-p frame) |
475f9031 KH |
1259 | (eq (frame-visible-p frame) 'icon)))) |
1260 | ||
1261 | (defsubst ediff-window-visible-p (wind) | |
41d25ad0 | 1262 | ;; under TTY, window-live-p also means window is visible |
475f9031 | 1263 | (and (window-live-p wind) |
41d25ad0 KH |
1264 | (or (not (ediff-window-display-p)) |
1265 | (frame-visible-p (window-frame wind))))) | |
475f9031 KH |
1266 | |
1267 | ||
1268 | (defsubst ediff-frame-char-width (frame) | |
1269 | (if ediff-xemacs-p | |
41d25ad0 | 1270 | (/ (frame-pixel-width frame) (frame-width frame)) |
475f9031 KH |
1271 | (frame-char-width frame))) |
1272 | ||
8343426b MK |
1273 | (defun ediff-reset-mouse (&optional frame do-not-grab-mouse) |
1274 | (or frame (setq frame (selected-frame))) | |
41d25ad0 | 1275 | (if (ediff-window-display-p) |
8343426b MK |
1276 | (let ((frame-or-wind frame)) |
1277 | (if ediff-xemacs-p | |
1278 | (setq frame-or-wind (frame-selected-window frame))) | |
1279 | (or do-not-grab-mouse | |
1280 | ;; don't set mouse if the user said to never do this | |
1281 | (not ediff-grab-mouse) | |
1282 | ;; Don't grab on quit, if the user doesn't want to. | |
1283 | ;; If ediff-grab-mouse = t, then mouse won't be grabbed for | |
1284 | ;; sessions that are not part of a group (this is done in | |
1285 | ;; ediff-recenter). The condition below affects only terminating | |
ceb0ea8b | 1286 | ;; sessions in session groups (in which case mouse is warped into |
8343426b MK |
1287 | ;; a meta buffer). |
1288 | (and (eq ediff-grab-mouse 'maybe) | |
1289 | (memq this-command '(ediff-quit ediff-update-diffs))) | |
1290 | (set-mouse-position frame-or-wind 1 0)) | |
1291 | ))) | |
1292 | ||
1293 | (defsubst ediff-spy-after-mouse () | |
1294 | (setq ediff-mouse-pixel-position (mouse-pixel-position))) | |
1295 | ||
1296 | ;; This is actually not easy to find out since emacs and xemacs behave | |
1297 | ;; differently when mouse is not in any frame. Also, this is sensitive to | |
1298 | ;; when the user grabbed mouse. | |
1299 | ;; Not used for now. | |
1300 | (defun ediff-user-grabbed-mouse () | |
1301 | (if ediff-mouse-pixel-position | |
1302 | (cond ((not (eq (car ediff-mouse-pixel-position) | |
1303 | (car (mouse-pixel-position))))) | |
1304 | ((and (car (cdr ediff-mouse-pixel-position)) | |
1305 | (car (cdr (mouse-pixel-position))) | |
1306 | (cdr (cdr ediff-mouse-pixel-position)) | |
1307 | (cdr (cdr (mouse-pixel-position)))) | |
1308 | (not (and (< (abs (- (car (cdr ediff-mouse-pixel-position)) | |
1309 | (car (cdr (mouse-pixel-position))))) | |
ceb0ea8b | 1310 | ediff-mouse-pixel-threshold) |
8343426b MK |
1311 | (< (abs (- (cdr (cdr ediff-mouse-pixel-position)) |
1312 | (cdr (cdr (mouse-pixel-position))))) | |
ceb0ea8b | 1313 | ediff-mouse-pixel-threshold)))) |
8343426b | 1314 | (t nil)))) |
41d25ad0 | 1315 | |
475f9031 KH |
1316 | (defsubst ediff-frame-char-height (frame) |
1317 | (if ediff-xemacs-p | |
41d25ad0 | 1318 | (/ (frame-pixel-height frame) (frame-height frame)) |
475f9031 KH |
1319 | (frame-char-height frame))) |
1320 | ||
1321 | ||
1322 | (defsubst ediff-empty-overlay-p (overl) | |
1323 | (= (ediff-overlay-start overl) (ediff-overlay-end overl))) | |
1324 | ||
1325 | ;; t if diff region is empty. | |
1326 | ;; In case of buffer C, t also if it is not a 3way | |
1327 | ;; comparison job (merging jobs return t as well). | |
1328 | (defun ediff-empty-diff-region-p (n buf-type) | |
1329 | (if (eq buf-type 'C) | |
1330 | (or (not ediff-3way-comparison-job) | |
1331 | (= (ediff-get-diff-posn 'C 'beg n) | |
1332 | (ediff-get-diff-posn 'C 'end n))) | |
1333 | (= (ediff-get-diff-posn buf-type 'beg n) | |
1334 | (ediff-get-diff-posn buf-type 'end n)))) | |
1335 | ||
1336 | ;; Test if diff region is white space only. | |
1337 | ;; If 2-way job and buf-type = C, then returns t. | |
1338 | (defun ediff-whitespace-diff-region-p (n buf-type) | |
1339 | (or (and (eq buf-type 'C) (not ediff-3way-job)) | |
8343426b | 1340 | (ediff-empty-diff-region-p n buf-type) |
475f9031 KH |
1341 | (let ((beg (ediff-get-diff-posn buf-type 'beg n)) |
1342 | (end (ediff-get-diff-posn buf-type 'end n))) | |
1343 | (ediff-eval-in-buffer (ediff-get-buffer buf-type) | |
1344 | (save-excursion | |
1345 | (goto-char beg) | |
1346 | (skip-chars-forward ediff-whitespace) | |
1347 | (>= (point) end)))))) | |
1348 | ||
1349 | ;; temporarily uses DIR to abbreviate file name | |
1350 | ;; if DIR is nil, use default-directory | |
8343426b MK |
1351 | (defsubst ediff-abbreviate-file-name (file &optional dir) |
1352 | (cond ((stringp dir) | |
1353 | (let ((directory-abbrev-alist (list (cons dir "")))) | |
1354 | (abbreviate-file-name file))) | |
1355 | (ediff-emacs-p (abbreviate-file-name file)) | |
1356 | (t ; XEmacs requires addl argument | |
1357 | (abbreviate-file-name file t)))) | |
1358 | ||
1359 | ;; Takes a directory and returns the parent directory. | |
1360 | ;; does nothing to `/'. If the ARG is a regular file, | |
1361 | ;; strip the file AND the last dir. | |
1362 | (defun ediff-strip-last-dir (dir) | |
1363 | (if (not (stringp dir)) (setq dir default-directory)) | |
1364 | (setq dir (expand-file-name dir)) | |
1365 | (or (file-directory-p dir) (setq dir (file-name-directory dir))) | |
1366 | (let* ((pos (1- (length dir))) | |
1367 | (last-char (aref dir pos))) | |
1368 | (if (and (> pos 0) (= last-char ?/)) | |
1369 | (setq dir (substring dir 0 pos))) | |
1370 | (ediff-abbreviate-file-name (file-name-directory dir)))) | |
1371 | ||
1372 | (defun ediff-truncate-string-left (str newlen) | |
1373 | ;; leave space for ... on the left | |
1374 | (let ((len (length str)) | |
1375 | substr) | |
1376 | (if (<= len newlen) | |
1377 | str | |
1378 | (setq newlen (max 0 (- newlen 3))) | |
1379 | (setq substr (substring str (max 0 (- len 1 newlen)))) | |
1380 | (concat "..." substr)))) | |
1381 | ||
1382 | (defun ediff-abbrev-jobname (jobname) | |
1383 | (cond ((eq jobname 'ediff-directories) | |
1384 | "Compare two directories") | |
1385 | ((eq jobname 'ediff-files) | |
1386 | "Compare two files") | |
1387 | ((eq jobname 'ediff-buffers) | |
1388 | "Compare two buffers") | |
1389 | ((eq jobname 'ediff-directories3) | |
1390 | "Compare three directories") | |
1391 | ((eq jobname 'ediff-files3) | |
1392 | "Compare three files") | |
1393 | ((eq jobname 'ediff-buffers3) | |
1394 | "Compare three buffers") | |
1395 | ((eq jobname 'ediff-revision) | |
1396 | "Compare file with a version") | |
1397 | ((eq jobname 'ediff-directory-revisions) | |
1398 | "Compare dir files with versions") | |
1399 | ((eq jobname 'ediff-merge-directory-revisions) | |
1400 | "Merge dir files with versions") | |
1401 | ((eq jobname 'ediff-merge-directory-revisions-with-ancestor) | |
1402 | "Merge dir versions via ancestors") | |
1403 | (t | |
1404 | (let* ((str (substring (symbol-name jobname) 6)) | |
1405 | (len (length str)) | |
1406 | (pos 0)) | |
1407 | (while (< pos len) | |
1408 | (if (= pos 0) | |
1409 | (aset str pos (upcase (aref str pos)))) | |
1410 | (if (= (aref str pos) ?-) | |
1411 | (aset str pos ?\ )) | |
1412 | (setq pos (1+ pos))) | |
1413 | str)))) | |
1414 | ||
1415 | ||
475f9031 KH |
1416 | |
1417 | (defsubst ediff-get-region-contents (n buf-type ctrl-buf &optional start end) | |
1418 | (ediff-eval-in-buffer | |
1419 | (ediff-eval-in-buffer ctrl-buf (ediff-get-buffer buf-type)) | |
1420 | (buffer-substring | |
1421 | (or start (ediff-get-diff-posn buf-type 'beg n ctrl-buf)) | |
1422 | (or end (ediff-get-diff-posn buf-type 'end n ctrl-buf))))) | |
1423 | ||
1424 | ;; If ediff modified mode line, strip the modification | |
1425 | (defsubst ediff-strip-mode-line-format () | |
8343426b | 1426 | (if (member (car mode-line-format) '(" A: " " B: " " C: " " Ancestor: ")) |
475f9031 KH |
1427 | (setq mode-line-format (nth 2 mode-line-format)))) |
1428 | ||
1429 | ;; Verify that we have a difference selected. | |
1430 | (defsubst ediff-valid-difference-p (&optional n) | |
1431 | (or n (setq n ediff-current-difference)) | |
1432 | (and (>= n 0) (< n ediff-number-of-differences))) | |
1433 | ||
1434 | (defsubst ediff-show-all-diffs (n) | |
1435 | "Don't skip difference regions." | |
1436 | nil) | |
8343426b MK |
1437 | |
1438 | (defsubst Xor (a b) | |
1439 | (or (and a (not b)) (and (not a) b))) | |
009650b3 MK |
1440 | |
1441 | (defsubst ediff-message-if-verbose (string &rest args) | |
1442 | (if ediff-verbose-p | |
1443 | (apply 'message string args))) | |
475f9031 KH |
1444 | |
1445 | (provide 'ediff-init) | |
1446 | ||
1447 | ||
1448 | ;;; ediff-init.el ends here |