0
|
1 ;;; ediff-util.el --- the core commands and utilities of ediff
|
|
2
|
70
|
3 ;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
|
0
|
4
|
|
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
|
|
6
|
|
7 ;; This file is part of GNU Emacs.
|
|
8
|
|
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
10 ;; it under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 ;; GNU General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
|
23
|
|
24 ;;; Code:
|
|
25
|
70
|
26 ;; Pacify compiler and avoid the need in checking for boundp
|
|
27 (defvar ediff-patch-diagnostics nil)
|
|
28 (defvar ediff-patchbufer nil)
|
78
|
29 (and noninteractive
|
|
30 (eval-when-compile
|
|
31 (let ((load-path (cons (expand-file-name ".") load-path)))
|
|
32 (load-file "ediff-init.el")
|
|
33 (load-file "ediff-help.el"))))
|
70
|
34 ;; end pacifier
|
12
|
35
|
78
|
36 (require 'ediff-init)
|
|
37 (require 'ediff-help)
|
|
38 (require 'ediff-mult)
|
|
39
|
|
40 ;;(if ediff-xemacs-p
|
|
41 ;; (require 'ediff-tbar)
|
|
42 ;; (defun ediff-use-toolbar-p () nil))
|
|
43 ;;
|
|
44 ;; for the time being
|
|
45 (defun ediff-use-toolbar-p () nil)
|
|
46
|
0
|
47
|
|
48 ;;; Functions
|
|
49
|
|
50 (defun ediff-mode ()
|
|
51 "Ediff mode controls all operations in a single Ediff session.
|
|
52 This mode is entered through one of the following commands:
|
|
53 `ediff'
|
|
54 `ediff-files'
|
|
55 `ediff-buffers'
|
|
56 `ebuffers'
|
|
57 `ediff3'
|
|
58 `ediff-files3'
|
|
59 `ediff-buffers3'
|
|
60 `ebuffers3'
|
|
61 `ediff-merge'
|
|
62 `ediff-merge-files'
|
|
63 `ediff-merge-files-with-ancestor'
|
|
64 `ediff-merge-buffers'
|
|
65 `ediff-merge-buffers-with-ancestor'
|
|
66 `ediff-merge-revisions'
|
|
67 `ediff-merge-revisions-with-ancestor'
|
|
68 `ediff-windows-wordwise'
|
|
69 `ediff-windows-linewise'
|
|
70 `ediff-regions-wordwise'
|
|
71 `ediff-regions-linewise'
|
|
72 `epatch'
|
|
73 `ediff-patch-file'
|
|
74 `ediff-patch-buffer'
|
|
75 `epatch-buffer'
|
|
76 `ediff-revision'
|
|
77
|
|
78 Commands:
|
|
79 \\{ediff-mode-map}"
|
|
80 (kill-all-local-variables)
|
|
81 (setq major-mode 'ediff-mode)
|
|
82 (setq mode-name "Ediff")
|
|
83 (run-hooks 'ediff-mode-hook))
|
|
84
|
|
85
|
70
|
86 (require 'ediff-diff)
|
|
87 (require 'ediff-merg)
|
|
88
|
0
|
89
|
|
90 ;;; Build keymaps
|
|
91
|
|
92 (ediff-defvar-local ediff-mode-map nil
|
|
93 "Local keymap used in Ediff mode.
|
|
94 This is local to each Ediff Control Panel, so they may vary from invocation
|
|
95 to invocation.")
|
|
96
|
|
97 ;; Set up the keymap in the control buffer
|
|
98 (defun ediff-set-keys ()
|
|
99 "Set up Ediff keymap, if necessary."
|
|
100 (if (null ediff-mode-map)
|
|
101 (ediff-setup-keymap))
|
|
102 (use-local-map ediff-mode-map))
|
|
103
|
|
104 ;; Reload Ediff keymap. For debugging only.
|
|
105 (defun ediff-reload-keymap ()
|
|
106 (interactive)
|
|
107 (setq ediff-mode-map nil)
|
|
108 (ediff-set-keys))
|
|
109
|
|
110
|
|
111 (defun ediff-setup-keymap ()
|
|
112 "Set up the keymap used in the control buffer of Ediff."
|
|
113 (setq ediff-mode-map (make-sparse-keymap))
|
|
114 (suppress-keymap ediff-mode-map)
|
|
115
|
78
|
116 (define-key ediff-mode-map
|
|
117 (if ediff-emacs-p [mouse-2] [button2]) 'ediff-help-for-quick-help)
|
|
118 (define-key ediff-mode-map "\C-m" 'ediff-help-for-quick-help)
|
|
119
|
0
|
120 (define-key ediff-mode-map "p" 'ediff-previous-difference)
|
|
121 (define-key ediff-mode-map "\C-?" 'ediff-previous-difference)
|
|
122 (define-key ediff-mode-map [backspace] 'ediff-previous-difference)
|
|
123 (define-key ediff-mode-map [delete] 'ediff-previous-difference)
|
|
124 (define-key ediff-mode-map "\C-h" (if ediff-no-emacs-help-in-control-buffer
|
|
125 'ediff-previous-difference nil))
|
|
126 (define-key ediff-mode-map "n" 'ediff-next-difference)
|
|
127 (define-key ediff-mode-map " " 'ediff-next-difference)
|
|
128 (define-key ediff-mode-map "j" 'ediff-jump-to-difference)
|
|
129 (define-key ediff-mode-map "g" nil)
|
|
130 (define-key ediff-mode-map "ga" 'ediff-jump-to-difference-at-point)
|
|
131 (define-key ediff-mode-map "gb" 'ediff-jump-to-difference-at-point)
|
|
132 (define-key ediff-mode-map "q" 'ediff-quit)
|
|
133 (define-key ediff-mode-map "D" 'ediff-show-diff-output)
|
|
134 (define-key ediff-mode-map "z" 'ediff-suspend)
|
|
135 (define-key ediff-mode-map "\C-l" 'ediff-recenter)
|
|
136 (define-key ediff-mode-map "|" 'ediff-toggle-split)
|
|
137 (define-key ediff-mode-map "h" 'ediff-toggle-hilit)
|
|
138 (or ediff-word-mode
|
|
139 (define-key ediff-mode-map "@" 'ediff-toggle-autorefine))
|
|
140 (if ediff-narrow-job
|
|
141 (define-key ediff-mode-map "%" 'ediff-toggle-narrow-region))
|
|
142 (define-key ediff-mode-map "~" 'ediff-swap-buffers)
|
|
143 (define-key ediff-mode-map "v" 'ediff-scroll-vertically)
|
|
144 (define-key ediff-mode-map "\C-v" 'ediff-scroll-vertically)
|
|
145 (define-key ediff-mode-map "^" 'ediff-scroll-vertically)
|
|
146 (define-key ediff-mode-map "\M-v" 'ediff-scroll-vertically)
|
|
147 (define-key ediff-mode-map "V" 'ediff-scroll-vertically)
|
|
148 (define-key ediff-mode-map "<" 'ediff-scroll-horizontally)
|
|
149 (define-key ediff-mode-map ">" 'ediff-scroll-horizontally)
|
|
150 (define-key ediff-mode-map "i" 'ediff-status-info)
|
|
151 (define-key ediff-mode-map "E" 'ediff-documentation)
|
|
152 (define-key ediff-mode-map "?" 'ediff-toggle-help)
|
|
153 (define-key ediff-mode-map "!" 'ediff-update-diffs)
|
|
154 (define-key ediff-mode-map "M" 'ediff-show-meta-buffer)
|
|
155 (define-key ediff-mode-map "R" 'ediff-show-registry)
|
|
156 (or ediff-word-mode
|
|
157 (define-key ediff-mode-map "*" 'ediff-make-or-kill-fine-diffs))
|
|
158 (define-key ediff-mode-map "a" nil)
|
|
159 (define-key ediff-mode-map "b" nil)
|
|
160 (define-key ediff-mode-map "r" nil)
|
|
161 (cond (ediff-merge-job
|
|
162 ;; Will barf if no ancestor
|
|
163 (define-key ediff-mode-map "/" 'ediff-show-ancestor)
|
|
164 ;; In merging, we allow only A->C and B->C copying.
|
|
165 (define-key ediff-mode-map "a" 'ediff-copy-A-to-C)
|
|
166 (define-key ediff-mode-map "b" 'ediff-copy-B-to-C)
|
|
167 (define-key ediff-mode-map "r" 'ediff-restore-diff-in-merge-buffer)
|
|
168 (define-key ediff-mode-map "s" 'ediff-shrink-window-C)
|
|
169 (define-key ediff-mode-map "+" 'ediff-combine-diffs)
|
|
170 (define-key ediff-mode-map "$" 'ediff-toggle-show-clashes-only)
|
|
171 (define-key ediff-mode-map "&" 'ediff-re-merge))
|
|
172 (ediff-3way-comparison-job
|
|
173 (define-key ediff-mode-map "ab" 'ediff-copy-A-to-B)
|
|
174 (define-key ediff-mode-map "ba" 'ediff-copy-B-to-A)
|
|
175 (define-key ediff-mode-map "ac" 'ediff-copy-A-to-C)
|
|
176 (define-key ediff-mode-map "bc" 'ediff-copy-B-to-C)
|
|
177 (define-key ediff-mode-map "c" nil)
|
|
178 (define-key ediff-mode-map "ca" 'ediff-copy-C-to-A)
|
|
179 (define-key ediff-mode-map "cb" 'ediff-copy-C-to-B)
|
|
180 (define-key ediff-mode-map "ra" 'ediff-restore-diff)
|
|
181 (define-key ediff-mode-map "rb" 'ediff-restore-diff)
|
|
182 (define-key ediff-mode-map "rc" 'ediff-restore-diff)
|
|
183 (define-key ediff-mode-map "C" 'ediff-toggle-read-only))
|
|
184 (t ; 2-way comparison
|
|
185 (define-key ediff-mode-map "a" 'ediff-copy-A-to-B)
|
|
186 (define-key ediff-mode-map "b" 'ediff-copy-B-to-A)
|
|
187 (define-key ediff-mode-map "ra" 'ediff-restore-diff)
|
|
188 (define-key ediff-mode-map "rb" 'ediff-restore-diff))
|
|
189 ) ; cond
|
|
190 (define-key ediff-mode-map "G" 'ediff-submit-report)
|
|
191 (define-key ediff-mode-map "#" nil)
|
|
192 (define-key ediff-mode-map "#h" 'ediff-toggle-regexp-match)
|
|
193 (define-key ediff-mode-map "#f" 'ediff-toggle-regexp-match)
|
|
194 (or ediff-word-mode
|
|
195 (define-key ediff-mode-map "##" 'ediff-toggle-skip-similar))
|
|
196 (define-key ediff-mode-map "o" nil)
|
|
197 (define-key ediff-mode-map "A" 'ediff-toggle-read-only)
|
|
198 (define-key ediff-mode-map "B" 'ediff-toggle-read-only)
|
|
199 (define-key ediff-mode-map "w" nil)
|
|
200 (define-key ediff-mode-map "wa" 'ediff-save-buffer)
|
|
201 (define-key ediff-mode-map "wb" 'ediff-save-buffer)
|
|
202 (define-key ediff-mode-map "wd" 'ediff-save-buffer)
|
78
|
203 (define-key ediff-mode-map "=" 'ediff-inferior-compare-regions)
|
0
|
204 (if (fboundp 'ediff-show-patch-diagnostics)
|
|
205 (define-key ediff-mode-map "P" 'ediff-show-patch-diagnostics))
|
|
206 (if ediff-3way-job
|
|
207 (progn
|
|
208 (define-key ediff-mode-map "wc" 'ediff-save-buffer)
|
|
209 (define-key ediff-mode-map "gc" 'ediff-jump-to-difference-at-point)
|
|
210 ))
|
|
211
|
|
212 (define-key ediff-mode-map "m" 'ediff-toggle-wide-display)
|
|
213
|
|
214 ;; Allow ediff-mode-map to be referenced indirectly
|
|
215 (fset 'ediff-mode-map ediff-mode-map)
|
|
216 (run-hooks 'ediff-keymap-setup-hook))
|
|
217
|
|
218
|
|
219 ;;; Setup functions
|
|
220
|
70
|
221 (require 'ediff-wind)
|
|
222
|
0
|
223 ;; No longer needed: XEmacs has surrogate minibuffers now.
|
|
224 ;;(or (boundp 'synchronize-minibuffers)
|
|
225 ;; (defvar synchronize-minibuffers nil))
|
|
226
|
|
227 ;; Common startup entry for all Ediff functions
|
|
228 ;; It now returns control buffer so other functions can do post-processing
|
|
229 (defun ediff-setup (buffer-A file-A buffer-B file-B buffer-C file-C
|
|
230 startup-hooks setup-parameters)
|
78
|
231 ;; ediff-convert-standard-filename puts file names in the form appropriate
|
|
232 ;; for the OS at hand.
|
|
233 (setq file-A (ediff-convert-standard-filename (expand-file-name file-A)))
|
|
234 (setq file-B (ediff-convert-standard-filename (expand-file-name file-B)))
|
0
|
235 (if (stringp file-C)
|
78
|
236 (setq file-C
|
|
237 (ediff-convert-standard-filename (expand-file-name file-C))))
|
0
|
238 (let* ((control-buffer-name
|
|
239 (ediff-unique-buffer-name "*Ediff Control Panel" "*"))
|
|
240 (control-buffer (ediff-eval-in-buffer buffer-A
|
|
241 (get-buffer-create control-buffer-name))))
|
|
242 (ediff-eval-in-buffer control-buffer
|
|
243 (ediff-mode)
|
|
244
|
|
245 ;; unwrap set up parameters passed as argument
|
|
246 (while setup-parameters
|
|
247 (set (car (car setup-parameters)) (cdr (car setup-parameters)))
|
|
248 (setq setup-parameters (cdr setup-parameters)))
|
|
249
|
|
250 ;; set variables classifying the current ediff job
|
|
251 (setq ediff-3way-comparison-job (ediff-3way-comparison-job)
|
|
252 ediff-merge-job (ediff-merge-job)
|
|
253 ediff-merge-with-ancestor-job (ediff-merge-with-ancestor-job)
|
|
254 ediff-3way-job (ediff-3way-job)
|
|
255 ediff-diff3-job (ediff-diff3-job)
|
|
256 ediff-narrow-job (ediff-narrow-job)
|
|
257 ediff-windows-job (ediff-windows-job)
|
|
258 ediff-word-mode-job (ediff-word-mode-job))
|
|
259
|
|
260 (make-local-variable 'ediff-use-long-help-message)
|
|
261 (make-local-variable 'ediff-prefer-iconified-control-frame)
|
|
262 (make-local-variable 'ediff-split-window-function)
|
|
263 (make-local-variable 'ediff-default-variant)
|
|
264 (make-local-variable 'ediff-merge-window-share)
|
|
265 (make-local-variable 'ediff-window-setup-function)
|
|
266 (make-local-variable 'ediff-keep-variants)
|
|
267
|
|
268 ;; Don't delete variants in case of ediff-buffer-* jobs without asking.
|
|
269 ;; This is because u may loose work---dangerous.
|
|
270 (if (string-match "buffer" (symbol-name ediff-job-name))
|
|
271 (setq ediff-keep-variants t))
|
|
272
|
|
273 (make-local-hook 'pre-command-hook)
|
|
274 (if (ediff-window-display-p)
|
|
275 (add-hook 'pre-command-hook 'ediff-spy-after-mouse nil t))
|
|
276 (setq ediff-mouse-pixel-position (mouse-pixel-position))
|
|
277
|
|
278 ;; adjust for merge jobs
|
|
279 (if ediff-merge-job
|
|
280 (let ((buf
|
|
281 ;; If default variant is `combined', the right stuff is
|
|
282 ;; inserted by ediff-do-merge
|
|
283 ;; Note: at some point, we tried to put ancestor buffer here
|
|
284 ;; (which is currently buffer C. This didn't work right
|
|
285 ;; because the merge buffer will contain lossage: diff regions
|
|
286 ;; in the ancestor, which correspond to revisions that agree
|
|
287 ;; in both buf A and B.
|
|
288 (cond ((eq ediff-default-variant 'default-B)
|
|
289 buffer-B)
|
|
290 (t buffer-A))))
|
|
291
|
|
292 (setq ediff-split-window-function
|
|
293 ediff-merge-split-window-function)
|
|
294
|
|
295 ;; remember the ancestor buffer, if any
|
|
296 (setq ediff-ancestor-buffer buffer-C)
|
|
297
|
|
298 (setq buffer-C
|
|
299 (get-buffer-create
|
|
300 (ediff-unique-buffer-name "*ediff-merge" "*")))
|
|
301 (save-excursion
|
|
302 (set-buffer buffer-C)
|
|
303 (insert-buffer buf)
|
|
304 (funcall (ediff-eval-in-buffer buf major-mode))
|
|
305 ;; after Stig@hackvan.com
|
|
306 (add-hook 'local-write-file-hooks 'ediff-set-merge-mode nil t)
|
|
307 )))
|
|
308 (setq buffer-read-only nil
|
|
309 ediff-buffer-A buffer-A
|
|
310 ediff-buffer-B buffer-B
|
|
311 ediff-buffer-C buffer-C
|
|
312 ediff-control-buffer control-buffer)
|
|
313
|
|
314 (setq ediff-control-buffer-suffix
|
|
315 (if (string-match "<[0-9]*>" control-buffer-name)
|
|
316 (substring control-buffer-name
|
|
317 (match-beginning 0) (match-end 0))
|
|
318 "")
|
|
319 ediff-control-buffer-number
|
|
320 (max
|
|
321 0
|
|
322 (1-
|
|
323 (string-to-number
|
|
324 (substring
|
|
325 ediff-control-buffer-suffix
|
|
326 (or
|
|
327 (string-match "[0-9]+" ediff-control-buffer-suffix)
|
|
328 0))))))
|
|
329
|
|
330 (setq ediff-error-buffer
|
|
331 (get-buffer-create (ediff-unique-buffer-name "*ediff-errors" "*")))
|
|
332
|
|
333 (ediff-eval-in-buffer buffer-A (ediff-strip-mode-line-format))
|
|
334 (ediff-eval-in-buffer buffer-B (ediff-strip-mode-line-format))
|
|
335 (if ediff-3way-job
|
|
336 (ediff-eval-in-buffer buffer-C (ediff-strip-mode-line-format)))
|
|
337 (if (ediff-buffer-live-p ediff-ancestor-buffer)
|
|
338 (ediff-eval-in-buffer ediff-ancestor-buffer
|
|
339 (ediff-strip-mode-line-format)))
|
|
340
|
|
341 (ediff-save-protected-variables) ; save variables to be restored on exit
|
|
342
|
|
343 ;; ediff-setup-diff-regions-function must be set after setup
|
|
344 ;; parameters are processed.
|
|
345 (setq ediff-setup-diff-regions-function
|
|
346 (if ediff-diff3-job
|
|
347 'ediff-setup-diff-regions3
|
|
348 'ediff-setup-diff-regions))
|
|
349
|
|
350 (setq ediff-wide-bounds
|
|
351 (list (ediff-make-bullet-proof-overlay
|
|
352 '(point-min) '(point-max) ediff-buffer-A)
|
|
353 (ediff-make-bullet-proof-overlay
|
|
354 '(point-min) '(point-max) ediff-buffer-B)
|
|
355 (ediff-make-bullet-proof-overlay
|
|
356 '(point-min) '(point-max) ediff-buffer-C)))
|
|
357
|
|
358 ;; This has effect only on ediff-windows/regions
|
|
359 ;; In all other cases, ediff-visible-region sets visibility bounds to
|
|
360 ;; ediff-wide-bounds, and ediff-narrow-bounds are ignored.
|
|
361 (if ediff-start-narrowed
|
|
362 (setq ediff-visible-bounds ediff-narrow-bounds)
|
|
363 (setq ediff-visible-bounds ediff-wide-bounds))
|
|
364
|
|
365 (ediff-set-keys) ; comes after parameter setup
|
|
366
|
|
367 ;; set up ediff-narrow-bounds, if not set
|
|
368 (or ediff-narrow-bounds
|
|
369 (setq ediff-narrow-bounds ediff-wide-bounds))
|
|
370
|
|
371 ;; All these must be inside ediff-eval-in-buffer control-buffer,
|
|
372 ;; since these vars are local to control-buffer
|
|
373 ;; These won't run if there are errors in diff
|
|
374 (ediff-eval-in-buffer ediff-buffer-A
|
|
375 (ediff-nuke-selective-display)
|
|
376 (run-hooks 'ediff-prepare-buffer-hook)
|
|
377 (if (ediff-eval-in-buffer control-buffer ediff-merge-job)
|
|
378 (setq buffer-read-only t))
|
|
379 ;; add control-buffer to the list of sessions--no longer used, but may
|
|
380 ;; be used again in the future
|
|
381 (or (memq control-buffer ediff-this-buffer-ediff-sessions)
|
|
382 (setq ediff-this-buffer-ediff-sessions
|
|
383 (cons control-buffer ediff-this-buffer-ediff-sessions)))
|
|
384 )
|
|
385 (ediff-eval-in-buffer ediff-buffer-B
|
|
386 (ediff-nuke-selective-display)
|
|
387 (run-hooks 'ediff-prepare-buffer-hook)
|
|
388 (if (ediff-eval-in-buffer control-buffer ediff-merge-job)
|
|
389 (setq buffer-read-only t))
|
|
390 ;; add control-buffer to the list of sessions
|
|
391 (or (memq control-buffer ediff-this-buffer-ediff-sessions)
|
|
392 (setq ediff-this-buffer-ediff-sessions
|
|
393 (cons control-buffer ediff-this-buffer-ediff-sessions)))
|
|
394 )
|
|
395 (if ediff-3way-job
|
|
396 (ediff-eval-in-buffer ediff-buffer-C
|
|
397 (ediff-nuke-selective-display)
|
|
398 (run-hooks 'ediff-prepare-buffer-hook)
|
|
399 ;; add control-buffer to the list of sessions
|
|
400 (or (memq control-buffer ediff-this-buffer-ediff-sessions)
|
|
401 (setq ediff-this-buffer-ediff-sessions
|
|
402 (cons control-buffer
|
|
403 ediff-this-buffer-ediff-sessions)))
|
|
404 ))
|
|
405
|
|
406 (if (ediff-buffer-live-p ediff-ancestor-buffer)
|
|
407 (ediff-eval-in-buffer ediff-ancestor-buffer
|
|
408 (ediff-nuke-selective-display)
|
|
409 (setq buffer-read-only t)
|
|
410 (run-hooks 'ediff-prepare-buffer-hook)
|
|
411 (or (memq control-buffer ediff-this-buffer-ediff-sessions)
|
|
412 (setq ediff-this-buffer-ediff-sessions
|
|
413 (cons control-buffer
|
|
414 ediff-this-buffer-ediff-sessions)))
|
|
415 ))
|
|
416
|
|
417 ;; must come after setting up ediff-narrow-bounds AND after
|
|
418 ;; nuking selective display
|
|
419 (funcall ediff-setup-diff-regions-function file-A file-B file-C)
|
|
420 (setq ediff-number-of-differences (length ediff-difference-vector-A))
|
|
421 (setq ediff-current-difference -1)
|
|
422
|
|
423 (ediff-make-current-diff-overlay 'A)
|
|
424 (ediff-make-current-diff-overlay 'B)
|
|
425 (if ediff-3way-job
|
|
426 (ediff-make-current-diff-overlay 'C))
|
|
427 (if ediff-merge-with-ancestor-job
|
|
428 (ediff-make-current-diff-overlay 'Ancestor))
|
|
429
|
|
430 (ediff-setup-windows buffer-A buffer-B buffer-C control-buffer)
|
|
431
|
|
432 (let ((shift-A (ediff-overlay-start
|
|
433 (ediff-get-value-according-to-buffer-type
|
|
434 'A ediff-narrow-bounds)))
|
|
435 (shift-B (ediff-overlay-start
|
|
436 (ediff-get-value-according-to-buffer-type
|
|
437 'B ediff-narrow-bounds)))
|
|
438 (shift-C (ediff-overlay-start
|
|
439 (ediff-get-value-according-to-buffer-type
|
|
440 'C ediff-narrow-bounds))))
|
|
441 ;; position point in buf A
|
|
442 (save-excursion
|
|
443 (select-window ediff-window-A)
|
|
444 (goto-char shift-A))
|
|
445 ;; position point in buf B
|
|
446 (save-excursion
|
|
447 (select-window ediff-window-B)
|
|
448 (goto-char shift-B))
|
|
449 (if ediff-3way-job
|
|
450 (save-excursion
|
|
451 (select-window ediff-window-C)
|
|
452 (goto-char shift-C)))
|
|
453 )
|
|
454
|
|
455 (select-window ediff-control-window)
|
|
456 (ediff-visible-region)
|
|
457
|
|
458 (run-hooks 'startup-hooks)
|
|
459 (ediff-refresh-mode-lines)
|
|
460 (setq buffer-read-only t)
|
|
461 (setq ediff-session-registry
|
|
462 (cons control-buffer ediff-session-registry))
|
|
463 (ediff-update-registry)
|
|
464 (if (ediff-buffer-live-p ediff-meta-buffer)
|
|
465 (ediff-update-meta-buffer ediff-meta-buffer))
|
|
466 (run-hooks 'ediff-startup-hook)
|
|
467 ) ; eval in control-buffer
|
|
468 control-buffer))
|
|
469
|
|
470
|
|
471 ;; This function assumes that we are in the window where control buffer is
|
|
472 ;; to reside.
|
|
473 (defun ediff-setup-control-buffer (ctl-buf)
|
|
474 "Set up window for control buffer."
|
|
475 (if (window-dedicated-p (selected-window))
|
|
476 (set-buffer ctl-buf) ; we are in control frame but just in case
|
|
477 (switch-to-buffer ctl-buf))
|
|
478 (let ((window-min-height 2))
|
|
479 (erase-buffer)
|
|
480 (ediff-set-help-message)
|
|
481 (insert ediff-help-message)
|
|
482 (shrink-window-if-larger-than-buffer)
|
|
483 (or (ediff-multiframe-setup-p)
|
|
484 (ediff-indent-help-message))
|
78
|
485 (ediff-set-help-overlays)
|
|
486
|
0
|
487 (set-buffer-modified-p nil)
|
|
488 (ediff-refresh-mode-lines)
|
|
489 (setq ediff-control-window (selected-window))
|
|
490 (setq ediff-window-config-saved
|
78
|
491 (format "%S%S%S%S%S%S%S"
|
0
|
492 ediff-control-window
|
|
493 ediff-window-A
|
|
494 ediff-window-B
|
|
495 ediff-window-C
|
|
496 ediff-split-window-function
|
|
497 (ediff-multiframe-setup-p)
|
|
498 ediff-wide-display-p))
|
78
|
499 (if (not (ediff-multiframe-setup-p))
|
|
500 (ediff-make-bottom-toolbar)) ; checks if toolbar is requested
|
0
|
501 (goto-char (point-min))
|
|
502 (skip-chars-forward ediff-whitespace)))
|
|
503
|
70
|
504
|
0
|
505
|
|
506
|
|
507 ;;; Commands for working with Ediff
|
|
508
|
|
509 (defun ediff-update-diffs ()
|
|
510 "Recompute difference regions in buffers A, B, and C.
|
|
511 Buffers are not synchronized with their respective files, so changes done
|
|
512 to these buffers are not saved at this point---the user can do this later,
|
|
513 if necessary."
|
|
514 (interactive)
|
|
515 (ediff-barf-if-not-control-buffer)
|
|
516 (if (and (ediff-buffer-live-p ediff-ancestor-buffer)
|
|
517 (not (y-or-n-p "Recompute differences during merge, really? ")))
|
|
518 (error "God forbid!"))
|
|
519
|
|
520 (let ((point-A (ediff-eval-in-buffer ediff-buffer-A (point)))
|
|
521 ;;(point-B (ediff-eval-in-buffer ediff-buffer-B (point)))
|
|
522 (tmp-buffer (get-buffer-create ediff-tmp-buffer))
|
|
523 (buf-A-file-name
|
|
524 (file-name-nondirectory (or (buffer-file-name ediff-buffer-A)
|
|
525 (buffer-name ediff-buffer-A)
|
|
526 )))
|
|
527 (buf-B-file-name
|
|
528 (file-name-nondirectory (or (buffer-file-name ediff-buffer-B)
|
|
529 (buffer-name ediff-buffer-B)
|
|
530 )))
|
|
531 (buf-C-file-name
|
|
532 (file-name-nondirectory (or (buffer-file-name ediff-buffer-C)
|
|
533 ;; if (null ediff-buffer-C), there is
|
|
534 ;; no danger, since we later check if
|
|
535 ;; ediff-buffer-C is alive
|
|
536 (buffer-name ediff-buffer-C)
|
|
537 )))
|
|
538 (overl-A (ediff-get-value-according-to-buffer-type
|
|
539 'A ediff-narrow-bounds))
|
|
540 (overl-B (ediff-get-value-according-to-buffer-type
|
|
541 'B ediff-narrow-bounds))
|
|
542 (overl-C (ediff-get-value-according-to-buffer-type
|
|
543 'C ediff-narrow-bounds))
|
|
544 beg-A end-A beg-B end-B beg-C end-C
|
|
545 file-A file-B file-C)
|
|
546 (ediff-unselect-and-select-difference -1)
|
|
547
|
|
548 (setq beg-A (ediff-overlay-start overl-A)
|
|
549 beg-B (ediff-overlay-start overl-B)
|
|
550 beg-C (ediff-overlay-start overl-C)
|
|
551 end-A (ediff-overlay-end overl-A)
|
|
552 end-B (ediff-overlay-end overl-B)
|
|
553 end-C (ediff-overlay-end overl-C))
|
|
554
|
|
555 (if ediff-word-mode
|
|
556 (progn
|
|
557 (ediff-wordify beg-A end-A ediff-buffer-A tmp-buffer)
|
|
558 (setq file-A (ediff-make-temp-file tmp-buffer "regA"))
|
|
559 (ediff-wordify beg-B end-B ediff-buffer-B tmp-buffer)
|
|
560 (setq file-B (ediff-make-temp-file tmp-buffer "regB"))
|
|
561 (if ediff-3way-job
|
|
562 (progn
|
|
563 (ediff-wordify beg-C end-C ediff-buffer-C tmp-buffer)
|
|
564 (setq file-C (ediff-make-temp-file tmp-buffer "regC"))))
|
|
565 )
|
|
566 ;; not word-mode
|
|
567 (setq file-A (ediff-make-temp-file ediff-buffer-A buf-A-file-name))
|
|
568 (setq file-B (ediff-make-temp-file ediff-buffer-B buf-B-file-name))
|
|
569 (if ediff-3way-job
|
|
570 (setq file-C (ediff-make-temp-file ediff-buffer-C buf-C-file-name)))
|
|
571 )
|
|
572
|
|
573 (ediff-clear-diff-vector 'ediff-difference-vector-A 'fine-diffs-also)
|
|
574 (ediff-clear-diff-vector 'ediff-difference-vector-B 'fine-diffs-also)
|
|
575 (ediff-clear-diff-vector 'ediff-difference-vector-C 'fine-diffs-also)
|
|
576 (ediff-clear-diff-vector
|
|
577 'ediff-difference-vector-Ancestor 'fine-diffs-also)
|
|
578 ;; let them garbage collect. we can't use the ancestor after recomputing
|
|
579 ;; the diffs.
|
|
580 (setq ediff-difference-vector-Ancestor nil
|
|
581 ediff-ancestor-buffer nil
|
|
582 ediff-state-of-merge nil)
|
|
583
|
|
584 (setq ediff-killed-diffs-alist nil) ; invalidate saved killed diff regions
|
|
585
|
|
586 ;; In case of merge job, fool it into thinking that it is just doing
|
|
587 ;; comparison
|
|
588 (let ((ediff-setup-diff-regions-function ediff-setup-diff-regions-function)
|
|
589 (ediff-3way-comparison-job ediff-3way-comparison-job)
|
|
590 (ediff-merge-job ediff-merge-job)
|
|
591 (ediff-merge-with-ancestor-job ediff-merge-with-ancestor-job)
|
|
592 (ediff-job-name ediff-job-name))
|
|
593 (if ediff-merge-job
|
|
594 (setq ediff-setup-diff-regions-function 'ediff-setup-diff-regions3
|
|
595 ediff-3way-comparison-job t
|
|
596 ediff-merge-job nil
|
|
597 ediff-merge-with-ancestor-job nil
|
|
598 ediff-job-name 'ediff-files3))
|
|
599 (funcall ediff-setup-diff-regions-function file-A file-B file-C))
|
|
600
|
|
601 (setq ediff-number-of-differences (length ediff-difference-vector-A))
|
|
602 (delete-file file-A)
|
|
603 (delete-file file-B)
|
|
604 (if file-C
|
|
605 (delete-file file-C))
|
|
606
|
|
607 (if ediff-3way-job
|
|
608 (ediff-set-state-of-all-diffs-in-all-buffers ediff-control-buffer))
|
|
609
|
|
610 (ediff-jump-to-difference (ediff-diff-at-point 'A point-A))
|
|
611 (message "")
|
|
612 ))
|
|
613
|
|
614 ;; Not bound to any key---to dangerous. A user can do it if necessary.
|
|
615 (defun ediff-revert-buffers-then-recompute-diffs (noconfirm)
|
|
616 "Revert buffers A, B and C. Then rerun Ediff on file A and file B."
|
|
617 (interactive "P")
|
|
618 (ediff-barf-if-not-control-buffer)
|
|
619 (let ((bufA ediff-buffer-A)
|
|
620 (bufB ediff-buffer-B)
|
|
621 (bufC ediff-buffer-C)
|
|
622 (ctl-buf ediff-control-buffer)
|
|
623 (keep-variants ediff-keep-variants)
|
|
624 (ancestor-buf ediff-ancestor-buffer)
|
|
625 (ancestor-job ediff-merge-with-ancestor-job)
|
|
626 (merge ediff-merge-job)
|
|
627 (comparison ediff-3way-comparison-job))
|
|
628 (ediff-eval-in-buffer bufA
|
|
629 (revert-buffer t noconfirm))
|
|
630 (ediff-eval-in-buffer bufB
|
|
631 (revert-buffer t noconfirm))
|
|
632 ;; this should only be executed in a 3way comparison, not in merge
|
|
633 (if comparison
|
|
634 (ediff-eval-in-buffer bufC
|
|
635 (revert-buffer t noconfirm)))
|
|
636 (if merge
|
|
637 (progn
|
|
638 (set-buffer ctl-buf)
|
|
639 ;; the argument says whether to reverse the meaning of
|
|
640 ;; ediff-keep-variants, i.e., ediff-really-quit runs here with
|
|
641 ;; variants kept.
|
|
642 (ediff-really-quit (not keep-variants))
|
|
643 (kill-buffer bufC)
|
|
644 (if ancestor-job
|
|
645 (ediff-merge-buffers-with-ancestor bufA bufB ancestor-buf)
|
|
646 (ediff-merge-buffers bufA bufB)))
|
|
647 (ediff-update-diffs))))
|
|
648
|
|
649
|
|
650 ;; optional NO-REHIGHLIGHT says to not rehighlight buffers
|
|
651 (defun ediff-recenter (&optional no-rehighlight)
|
|
652 "Bring the highlighted region of all buffers being compared into view.
|
|
653 Reestablish the default three-window display."
|
|
654 (interactive)
|
|
655 (ediff-barf-if-not-control-buffer)
|
|
656
|
|
657 ;; ;; No longer needed: XEmacs has surrogate minibuffers now.
|
|
658 ;; (if ediff-xemacs-p (setq synchronize-minibuffers t))
|
|
659
|
|
660 (let (buffer-read-only)
|
|
661 (if (and (ediff-buffer-live-p ediff-buffer-A)
|
|
662 (ediff-buffer-live-p ediff-buffer-B)
|
|
663 (or (not ediff-3way-job)
|
|
664 (ediff-buffer-live-p ediff-buffer-C)))
|
|
665 (ediff-setup-windows
|
|
666 ediff-buffer-A ediff-buffer-B ediff-buffer-C ediff-control-buffer)
|
|
667 (or (eq this-command 'ediff-quit)
|
|
668 (message ediff-KILLED-VITAL-BUFFER
|
|
669 (beep 1)))
|
|
670 ))
|
|
671
|
|
672 ;; set visibility range appropriate to this invocation of Ediff.
|
|
673 (ediff-visible-region)
|
|
674 ;; raise
|
|
675 (if (and (ediff-window-display-p)
|
|
676 (symbolp this-command)
|
|
677 (symbolp last-command)
|
|
678 ;; Either one of the display-changing commands
|
|
679 (or (memq this-command
|
|
680 '(ediff-recenter
|
|
681 ediff-dir-action ediff-registry-action
|
|
682 ediff-patch-action
|
|
683 ediff-toggle-wide-display ediff-toggle-multiframe))
|
|
684 ;; Or one of the movement cmds and prev cmd was an Ediff cmd
|
|
685 ;; This avoids raising frames unnecessarily.
|
|
686 (and (memq this-command
|
|
687 '(ediff-next-difference
|
|
688 ediff-previous-difference
|
|
689 ediff-jump-to-difference
|
|
690 ediff-jump-to-difference-at-point))
|
|
691 (not (string-match "^ediff-" (symbol-name last-command)))
|
|
692 )))
|
|
693 (progn
|
|
694 (if (window-live-p ediff-window-A)
|
|
695 (raise-frame (window-frame ediff-window-A)))
|
|
696 (if (window-live-p ediff-window-B)
|
|
697 (raise-frame (window-frame ediff-window-B)))
|
|
698 (if (window-live-p ediff-window-C)
|
|
699 (raise-frame (window-frame ediff-window-C)))))
|
|
700 (if (and (ediff-window-display-p)
|
|
701 (frame-live-p ediff-control-frame)
|
|
702 (not ediff-use-long-help-message)
|
|
703 (not (ediff-frame-iconified-p ediff-control-frame)))
|
|
704 (raise-frame ediff-control-frame))
|
|
705
|
|
706 ;; Redisplay whatever buffers are showing, if there is a selected difference
|
|
707 (let ((control-frame ediff-control-frame)
|
|
708 (control-buf ediff-control-buffer))
|
|
709 (if (and (ediff-buffer-live-p ediff-buffer-A)
|
|
710 (ediff-buffer-live-p ediff-buffer-B)
|
|
711 (or (not ediff-3way-job)
|
|
712 (ediff-buffer-live-p ediff-buffer-C)))
|
|
713 (progn
|
|
714 (or no-rehighlight
|
|
715 (ediff-select-difference ediff-current-difference))
|
|
716
|
|
717 (ediff-recenter-one-window 'A)
|
|
718 (ediff-recenter-one-window 'B)
|
|
719 (if ediff-3way-job
|
|
720 (ediff-recenter-one-window 'C))
|
|
721
|
|
722 (ediff-eval-in-buffer control-buf
|
|
723 (ediff-recenter-ancestor) ; check if ancestor is alive
|
|
724
|
|
725 (if (and (ediff-multiframe-setup-p)
|
|
726 (not ediff-use-long-help-message)
|
|
727 (not (ediff-frame-iconified-p ediff-control-frame)))
|
|
728 ;; never grab mouse on quit in this place
|
|
729 (ediff-reset-mouse
|
|
730 control-frame
|
|
731 (eq this-command 'ediff-quit))))
|
|
732 ))
|
78
|
733
|
|
734 (ediff-restore-highlighting)
|
|
735 (ediff-eval-in-buffer control-buf (ediff-refresh-mode-lines))
|
0
|
736 ))
|
|
737
|
|
738 ;; this function returns to the window it was called from
|
|
739 ;; (which was the control window)
|
|
740 (defun ediff-recenter-one-window (buf-type)
|
|
741 (if (ediff-valid-difference-p)
|
|
742 ;; context must be saved before switching to windows A/B/C
|
|
743 (let* ((ctl-wind (selected-window))
|
|
744 (shift (ediff-overlay-start
|
|
745 (ediff-get-value-according-to-buffer-type
|
|
746 buf-type ediff-narrow-bounds)))
|
|
747 (job-name ediff-job-name)
|
|
748 (control-buf ediff-control-buffer)
|
|
749 (window-name (intern (format "ediff-window-%S" buf-type)))
|
|
750 (window (if (window-live-p (symbol-value window-name))
|
|
751 (symbol-value window-name))))
|
|
752
|
|
753 (if (and window ediff-windows-job)
|
|
754 (set-window-start window shift))
|
|
755 (if window
|
|
756 (progn
|
|
757 (select-window window)
|
|
758 (ediff-deactivate-mark)
|
|
759 (ediff-position-region
|
|
760 (ediff-get-diff-posn buf-type 'beg nil control-buf)
|
|
761 (ediff-get-diff-posn buf-type 'end nil control-buf)
|
|
762 (ediff-get-diff-posn buf-type 'beg nil control-buf)
|
|
763 job-name
|
|
764 )))
|
|
765 (select-window ctl-wind)
|
|
766 )))
|
|
767
|
|
768 (defun ediff-recenter-ancestor ()
|
|
769 ;; do half-hearted job by recentering the ancestor buffer, if it is alive and
|
|
770 ;; visible.
|
|
771 (if (and (ediff-buffer-live-p ediff-ancestor-buffer)
|
|
772 (ediff-valid-difference-p))
|
|
773 (let ((window (ediff-get-visible-buffer-window ediff-ancestor-buffer))
|
|
774 (ctl-wind (selected-window))
|
|
775 (job-name ediff-job-name)
|
|
776 (ctl-buf ediff-control-buffer))
|
|
777 (ediff-eval-in-buffer ediff-ancestor-buffer
|
|
778 (goto-char (ediff-get-diff-posn 'Ancestor 'beg nil ctl-buf))
|
|
779 (if window
|
|
780 (progn
|
|
781 (select-window window)
|
|
782 (ediff-position-region
|
|
783 (ediff-get-diff-posn 'Ancestor 'beg nil ctl-buf)
|
|
784 (ediff-get-diff-posn 'Ancestor 'end nil ctl-buf)
|
|
785 (ediff-get-diff-posn 'Ancestor 'beg nil ctl-buf)
|
|
786 job-name))))
|
|
787 (select-window ctl-wind)
|
|
788 )))
|
|
789
|
|
790
|
|
791 ;; This will have to be refined for 3way jobs
|
|
792 (defun ediff-toggle-split ()
|
|
793 "Toggle vertical/horizontal window split.
|
|
794 Does nothing if file-A and file-B are in different frames."
|
|
795 (interactive)
|
|
796 (ediff-barf-if-not-control-buffer)
|
|
797 (let* ((wind-A (if (window-live-p ediff-window-A) ediff-window-A))
|
|
798 (wind-B (if (window-live-p ediff-window-B) ediff-window-B))
|
|
799 (wind-C (if (window-live-p ediff-window-C) ediff-window-C))
|
|
800 (frame-A (if wind-A (window-frame wind-A)))
|
|
801 (frame-B (if wind-B (window-frame wind-B)))
|
|
802 (frame-C (if wind-C (window-frame wind-C))))
|
|
803 (if (or (eq frame-A frame-B)
|
|
804 (not (frame-live-p frame-A))
|
|
805 (not (frame-live-p frame-B))
|
|
806 (if ediff-3way-comparison-job
|
|
807 (or (not (frame-live-p frame-C))
|
|
808 (eq frame-A frame-C) (eq frame-B frame-C))))
|
|
809 (setq ediff-split-window-function
|
|
810 (if (eq ediff-split-window-function 'split-window-vertically)
|
|
811 'split-window-horizontally
|
|
812 'split-window-vertically))
|
|
813 (message "Buffers being compared are in different frames"))
|
|
814 (ediff-recenter 'no-rehighlight)))
|
|
815
|
|
816 (defun ediff-toggle-hilit ()
|
|
817 "Switch between highlighting using ASCII flags and highlighting using faces.
|
|
818 On a dumb terminal, switches between ASCII highlighting and no highlighting."
|
|
819 (interactive)
|
|
820 (ediff-barf-if-not-control-buffer)
|
|
821 (if (not (ediff-has-face-support-p))
|
|
822 (if (eq ediff-highlighting-style 'ascii)
|
|
823 (progn
|
|
824 (message "ASCII highlighting flags removed")
|
|
825 (ediff-unselect-and-select-difference ediff-current-difference
|
|
826 'unselect-only)
|
|
827 (setq ediff-highlighting-style 'off))
|
|
828 (ediff-unselect-and-select-difference ediff-current-difference
|
|
829 'select-only))
|
|
830 (ediff-unselect-and-select-difference ediff-current-difference
|
|
831 'unselect-only)
|
|
832 ;; cycle through highlighting
|
|
833 (cond ((and ediff-use-faces ediff-highlight-all-diffs)
|
|
834 (message "Unhighlighting unselected difference regions")
|
|
835 (setq ediff-highlight-all-diffs nil))
|
|
836 (ediff-use-faces
|
|
837 (message "Highlighting with ASCII flags")
|
|
838 (setq ediff-use-faces nil))
|
|
839 (t
|
|
840 (message "Re-highlighting all difference regions")
|
|
841 (setq ediff-use-faces t
|
|
842 ediff-highlight-all-diffs t)))
|
|
843
|
|
844 (if (and ediff-use-faces ediff-highlight-all-diffs)
|
78
|
845 (ediff-paint-background-regions)
|
|
846 (ediff-paint-background-regions 'unhighlight))
|
0
|
847
|
|
848 (ediff-unselect-and-select-difference
|
|
849 ediff-current-difference 'select-only))
|
|
850 )
|
78
|
851
|
0
|
852
|
|
853 (defun ediff-toggle-autorefine ()
|
|
854 "Toggle auto-refine mode."
|
|
855 (interactive)
|
|
856 (ediff-barf-if-not-control-buffer)
|
|
857 (if ediff-word-mode
|
|
858 (error "No fine differences in this mode"))
|
|
859 (cond ((eq ediff-auto-refine 'nix)
|
|
860 (setq ediff-auto-refine 'on)
|
|
861 (ediff-make-fine-diffs ediff-current-difference 'noforce)
|
|
862 (message "Auto-refining is ON"))
|
|
863 ((eq ediff-auto-refine 'on)
|
|
864 (message "Auto-refining is OFF")
|
|
865 (setq ediff-auto-refine 'off))
|
|
866 (t ;; nix 'em
|
|
867 (ediff-set-fine-diff-properties ediff-current-difference 'default)
|
|
868 (message "Refinements are HIDDEN")
|
|
869 (setq ediff-auto-refine 'nix))
|
|
870 ))
|
|
871
|
|
872 (defun ediff-show-ancestor ()
|
|
873 "Show the ancestor buffer in a suitable window."
|
|
874 (interactive)
|
|
875 (ediff-recenter)
|
|
876 (or (ediff-buffer-live-p ediff-ancestor-buffer)
|
|
877 (if ediff-merge-with-ancestor-job
|
|
878 (error "Lost connection to ancestor buffer...sorry")
|
|
879 (error "Not merging with ancestor")))
|
|
880 (let (wind)
|
|
881 (cond ((setq wind (ediff-get-visible-buffer-window ediff-ancestor-buffer))
|
|
882 (raise-frame (window-frame wind)))
|
|
883 (t (set-window-buffer ediff-window-C ediff-ancestor-buffer)))))
|
|
884
|
|
885 (defun ediff-make-or-kill-fine-diffs (arg)
|
|
886 "Compute fine diffs. With negative prefix arg, kill fine diffs.
|
|
887 In both cases, operates on the currrent difference region."
|
|
888 (interactive "P")
|
|
889 (ediff-barf-if-not-control-buffer)
|
|
890 (cond ((eq arg '-)
|
|
891 (ediff-clear-fine-differences ediff-current-difference))
|
|
892 ((and (numberp arg) (< arg 0))
|
|
893 (ediff-clear-fine-differences ediff-current-difference))
|
|
894 (t (ediff-make-fine-diffs))))
|
|
895
|
|
896
|
|
897 (defun ediff-toggle-help ()
|
|
898 "Toggle short/long help message."
|
|
899 (interactive)
|
|
900 (ediff-barf-if-not-control-buffer)
|
|
901 (let (buffer-read-only)
|
|
902 (erase-buffer)
|
|
903 (setq ediff-use-long-help-message (not ediff-use-long-help-message))
|
|
904 (ediff-set-help-message))
|
|
905 ;; remember the icon status of the control frame when the user requested
|
|
906 ;; full control message
|
|
907 (if (and ediff-use-long-help-message (ediff-multiframe-setup-p))
|
|
908 (setq ediff-prefer-iconified-control-frame
|
|
909 (ediff-frame-iconified-p ediff-control-frame)))
|
|
910
|
|
911 (setq ediff-window-config-saved "") ; force redisplay
|
|
912 (ediff-recenter 'no-rehighlight))
|
|
913
|
|
914
|
|
915 ;; If BUF, this is the buffer to toggle, not current buffer.
|
|
916 (defun ediff-toggle-read-only (&optional buf)
|
|
917 "Toggle read-only in current buffer.
|
|
918 If buffer is under version control and locked, check it out first.
|
|
919 If optional argument BUF is specified, toggle read-only in that buffer instead
|
|
920 of the current buffer."
|
|
921 (interactive)
|
|
922 (ediff-barf-if-not-control-buffer)
|
|
923 (let ((ctl-buf (if (null buf) (current-buffer)))
|
|
924 (buf-type (ediff-char-to-buftype last-command-char)))
|
|
925 (or buf (ediff-recenter))
|
|
926 (or buf
|
|
927 (setq buf (ediff-get-buffer buf-type)))
|
|
928
|
|
929 (ediff-eval-in-buffer buf ; eval in buf A/B/C
|
|
930 (let* ((file (buffer-file-name buf))
|
|
931 (file-writable (and file
|
|
932 (file-exists-p file)
|
|
933 (file-writable-p file)))
|
|
934 (toggle-ro-cmd (cond (ediff-toggle-read-only-function)
|
|
935 ((ediff-file-checked-out-p file)
|
|
936 'toggle-read-only)
|
|
937 (file-writable 'toggle-read-only)
|
|
938 (t (key-binding "\C-x\C-q")))))
|
|
939 ;; If the file is checked in, make sure we don't make buffer modifiable
|
|
940 ;; without warning the user. The user can fool our checks by making the
|
|
941 ;; buffer non-RO without checking the file out. We regard this as a
|
|
942 ;; user problem.
|
|
943 (if (and (ediff-file-checked-in-p file)
|
|
944 ;; If ctl-buf is null, this means we called this
|
|
945 ;; non-interactively, in which case don't ask questions
|
|
946 ctl-buf)
|
|
947 (cond ((not buffer-read-only)
|
|
948 (setq toggle-ro-cmd 'toggle-read-only))
|
|
949 ((and (or (beep 1) t) ; always beep
|
|
950 (y-or-n-p
|
|
951 (format
|
|
952 "File %s is under version control. Check it out? "
|
|
953 (ediff-abbreviate-file-name file))))
|
|
954 ;; if we checked the file out, we should also change the
|
|
955 ;; original state of buffer-read-only to nil. If we don't
|
|
956 ;; do this, the mode line will show %%, since the file was
|
|
957 ;; RO before ediff started, so the user will think the file
|
|
958 ;; is checked in.
|
|
959 (ediff-eval-in-buffer ctl-buf
|
|
960 (ediff-change-saved-variable
|
|
961 'buffer-read-only nil buf-type)))
|
|
962 (t
|
|
963 (setq toggle-ro-cmd 'toggle-read-only)
|
|
964 (beep 1) (beep 1)
|
|
965 (message
|
78
|
966 "Boy, this is risky! Don't modify this file...")
|
0
|
967 (sit-for 3)))) ; let the user see the warning
|
|
968 (if (and toggle-ro-cmd
|
|
969 (string-match "toggle-read-only" (symbol-name toggle-ro-cmd)))
|
|
970 (save-excursion
|
|
971 (save-window-excursion
|
78
|
972 (select-window (ediff-get-visible-buffer-window buf))
|
0
|
973 (command-execute toggle-ro-cmd)))
|
|
974 (error "Don't know how to toggle read-only in buffer %S" buf))
|
|
975
|
|
976 ;; Check if we made the current buffer updatable, but its file is RO.
|
|
977 ;; Signal a warning in this case.
|
|
978 (if (and file (not buffer-read-only)
|
|
979 (eq this-command 'ediff-toggle-read-only)
|
|
980 (file-exists-p file)
|
|
981 (not (file-writable-p file)))
|
|
982 (message "Warning: file %s is read-only"
|
|
983 (ediff-abbreviate-file-name file) (beep 1)))
|
|
984 ))))
|
78
|
985
|
0
|
986
|
78
|
987 ;; checkout if visited file is checked in
|
|
988 (defun ediff-maybe-checkout (buf)
|
|
989 (let ((file (buffer-file-name buf))
|
|
990 (checkout-function (key-binding "\C-x\C-q")))
|
|
991 (if (and (ediff-file-checked-in-p file)
|
|
992 (or (beep 1) t)
|
|
993 (y-or-n-p
|
|
994 (format
|
|
995 "File %s is under version control. Check it out? "
|
|
996 (ediff-abbreviate-file-name file))))
|
|
997 (ediff-eval-in-buffer buf
|
|
998 (command-execute checkout-function)))))
|
|
999
|
|
1000
|
|
1001 ;; This is a simple-minded check for whether a file is under version control.
|
0
|
1002 ;; If file,v exists but file doesn't, this file is considered to be not checked
|
|
1003 ;; in and not checked out for the purpose of patching (since patch won't be
|
|
1004 ;; able to read such a file anyway).
|
|
1005 ;; FILE is a string representing file name
|
78
|
1006 (defun ediff-file-under-version-control (file)
|
|
1007 (let* ((filedir (file-name-directory file))
|
|
1008 (file-nondir (file-name-nondirectory file))
|
|
1009 (trial (concat file-nondir ",v"))
|
|
1010 (full-trial (concat filedir trial))
|
|
1011 (full-rcs-trial (concat filedir "RCS/" trial)))
|
|
1012 (and (stringp file)
|
|
1013 (file-exists-p file)
|
|
1014 (or
|
|
1015 (and
|
|
1016 (file-exists-p full-trial)
|
|
1017 ;; in FAT FS, `file,v' and `file' may turn out to be the same!
|
|
1018 ;; don't be fooled by this!
|
|
1019 (not (equal (file-attributes file)
|
|
1020 (file-attributes full-trial))))
|
|
1021 ;; check if a version is in RCS/ directory
|
|
1022 (file-exists-p full-rcs-trial)))
|
0
|
1023 ))
|
78
|
1024
|
|
1025 (defun ediff-file-checked-out-p (file)
|
|
1026 (and (ediff-file-under-version-control file)
|
|
1027 (file-writable-p file)))
|
0
|
1028 (defun ediff-file-checked-in-p (file)
|
78
|
1029 (and (ediff-file-under-version-control file)
|
|
1030 (not (file-writable-p file))))
|
0
|
1031
|
|
1032 (defun ediff-swap-buffers ()
|
|
1033 "Rotate the display of buffers A, B, and C."
|
|
1034 (interactive)
|
|
1035 (ediff-barf-if-not-control-buffer)
|
|
1036 (if (and (window-live-p ediff-window-A) (window-live-p ediff-window-B))
|
|
1037 (let ((buf ediff-buffer-A)
|
|
1038 (values ediff-buffer-values-orig-A)
|
|
1039 (diff-vec ediff-difference-vector-A)
|
|
1040 (hide-regexp ediff-regexp-hide-A)
|
|
1041 (focus-regexp ediff-regexp-focus-A)
|
|
1042 (wide-visibility-p (eq ediff-visible-bounds ediff-wide-bounds))
|
|
1043 (overlay (if (ediff-has-face-support-p)
|
|
1044 ediff-current-diff-overlay-A)))
|
|
1045 (if ediff-3way-comparison-job
|
|
1046 (progn
|
|
1047 (set-window-buffer ediff-window-A ediff-buffer-C)
|
|
1048 (set-window-buffer ediff-window-B ediff-buffer-A)
|
|
1049 (set-window-buffer ediff-window-C ediff-buffer-B)
|
|
1050 )
|
|
1051 (set-window-buffer ediff-window-A ediff-buffer-B)
|
|
1052 (set-window-buffer ediff-window-B ediff-buffer-A))
|
|
1053 ;; swap diff buffers
|
|
1054 (if ediff-3way-comparison-job
|
|
1055 (setq ediff-buffer-A ediff-buffer-C
|
|
1056 ediff-buffer-C ediff-buffer-B
|
|
1057 ediff-buffer-B buf)
|
|
1058 (setq ediff-buffer-A ediff-buffer-B
|
|
1059 ediff-buffer-B buf))
|
|
1060
|
|
1061 ;; swap saved buffer characteristics
|
|
1062 (if ediff-3way-comparison-job
|
|
1063 (setq ediff-buffer-values-orig-A ediff-buffer-values-orig-C
|
|
1064 ediff-buffer-values-orig-C ediff-buffer-values-orig-B
|
|
1065 ediff-buffer-values-orig-B values)
|
|
1066 (setq ediff-buffer-values-orig-A ediff-buffer-values-orig-B
|
|
1067 ediff-buffer-values-orig-B values))
|
|
1068
|
|
1069 ;; swap diff vectors
|
|
1070 (if ediff-3way-comparison-job
|
|
1071 (setq ediff-difference-vector-A ediff-difference-vector-C
|
|
1072 ediff-difference-vector-C ediff-difference-vector-B
|
|
1073 ediff-difference-vector-B diff-vec)
|
|
1074 (setq ediff-difference-vector-A ediff-difference-vector-B
|
|
1075 ediff-difference-vector-B diff-vec))
|
|
1076
|
|
1077 ;; swap hide/focus regexp
|
|
1078 (if ediff-3way-comparison-job
|
|
1079 (setq ediff-regexp-hide-A ediff-regexp-hide-C
|
|
1080 ediff-regexp-hide-C ediff-regexp-hide-B
|
|
1081 ediff-regexp-hide-B hide-regexp
|
|
1082 ediff-regexp-focus-A ediff-regexp-focus-C
|
|
1083 ediff-regexp-focus-C ediff-regexp-focus-B
|
|
1084 ediff-regexp-focus-B focus-regexp)
|
|
1085 (setq ediff-regexp-hide-A ediff-regexp-hide-B
|
|
1086 ediff-regexp-hide-B hide-regexp
|
|
1087 ediff-regexp-focus-A ediff-regexp-focus-B
|
|
1088 ediff-regexp-focus-B focus-regexp))
|
|
1089
|
|
1090 ;; The following is needed for XEmacs, since there one can't move
|
|
1091 ;; overlay to another buffer. In Emacs, this swap is redundant.
|
|
1092 (if (ediff-has-face-support-p)
|
|
1093 (if ediff-3way-comparison-job
|
|
1094 (setq ediff-current-diff-overlay-A ediff-current-diff-overlay-C
|
|
1095 ediff-current-diff-overlay-C ediff-current-diff-overlay-B
|
|
1096 ediff-current-diff-overlay-B overlay)
|
|
1097 (setq ediff-current-diff-overlay-A ediff-current-diff-overlay-B
|
|
1098 ediff-current-diff-overlay-B overlay)))
|
|
1099
|
|
1100 ;; swap wide bounds
|
|
1101 (setq ediff-wide-bounds
|
|
1102 (cond (ediff-3way-comparison-job
|
|
1103 (list (nth 2 ediff-wide-bounds)
|
|
1104 (nth 0 ediff-wide-bounds)
|
|
1105 (nth 1 ediff-wide-bounds)))
|
|
1106 (ediff-3way-job
|
|
1107 (list (nth 1 ediff-wide-bounds)
|
|
1108 (nth 0 ediff-wide-bounds)
|
|
1109 (nth 2 ediff-wide-bounds)))
|
|
1110 (t
|
|
1111 (list (nth 1 ediff-wide-bounds)
|
|
1112 (nth 0 ediff-wide-bounds)))))
|
|
1113 ;; swap narrow bounds
|
|
1114 (setq ediff-narrow-bounds
|
|
1115 (cond (ediff-3way-comparison-job
|
|
1116 (list (nth 2 ediff-narrow-bounds)
|
|
1117 (nth 0 ediff-narrow-bounds)
|
|
1118 (nth 1 ediff-narrow-bounds)))
|
|
1119 (ediff-3way-job
|
|
1120 (list (nth 1 ediff-narrow-bounds)
|
|
1121 (nth 0 ediff-narrow-bounds)
|
|
1122 (nth 2 ediff-narrow-bounds)))
|
|
1123 (t
|
|
1124 (list (nth 1 ediff-narrow-bounds)
|
|
1125 (nth 0 ediff-narrow-bounds)))))
|
|
1126 (if wide-visibility-p
|
|
1127 (setq ediff-visible-bounds ediff-wide-bounds)
|
|
1128 (setq ediff-visible-bounds ediff-narrow-bounds))
|
|
1129 ))
|
|
1130 (if ediff-3way-job
|
|
1131 (ediff-set-state-of-all-diffs-in-all-buffers ediff-control-buffer))
|
|
1132 (ediff-recenter 'no-rehighlight)
|
|
1133 )
|
|
1134
|
|
1135
|
|
1136 (defun ediff-toggle-wide-display ()
|
|
1137 "Toggle wide/regular display.
|
|
1138 This is especially useful when comparing buffers side-by-side."
|
|
1139 (interactive)
|
|
1140 (ediff-barf-if-not-control-buffer)
|
|
1141 (or (ediff-window-display-p)
|
|
1142 (error "%sEmacs is not running as a window application"
|
|
1143 (if ediff-emacs-p "" "X")))
|
|
1144 (ediff-recenter 'no-rehighlight) ; make sure buffs are displayed in windows
|
|
1145 (let ((ctl-buf ediff-control-buffer))
|
|
1146 (setq ediff-wide-display-p (not ediff-wide-display-p))
|
|
1147 (if (not ediff-wide-display-p)
|
|
1148 (ediff-eval-in-buffer ctl-buf
|
|
1149 (modify-frame-parameters
|
|
1150 ediff-wide-display-frame ediff-wide-display-orig-parameters)
|
|
1151 ;;(sit-for (if ediff-xemacs-p 0.4 0))
|
|
1152 ;; restore control buf, since ctl window may have been deleted
|
|
1153 ;; during resizing
|
|
1154 (set-buffer ctl-buf)
|
|
1155 (setq ediff-wide-display-orig-parameters nil
|
|
1156 ediff-window-B nil) ; force update of window config
|
|
1157 (ediff-recenter 'no-rehighlight))
|
|
1158 (funcall ediff-make-wide-display-function)
|
|
1159 ;;(sit-for (if ediff-xemacs-p 0.4 0))
|
|
1160 (ediff-eval-in-buffer ctl-buf
|
|
1161 (setq ediff-window-B nil) ; force update of window config
|
|
1162 (ediff-recenter 'no-rehighlight)))))
|
78
|
1163
|
|
1164 ;;;###autoload
|
0
|
1165 (defun ediff-toggle-multiframe ()
|
70
|
1166 "Switch from the multiframe display to single-frame display and back.
|
|
1167 For a permanent change, set the variable `ediff-window-setup-function',
|
0
|
1168 which see."
|
|
1169 (interactive)
|
78
|
1170 (let (set-func)
|
70
|
1171 (or (ediff-window-display-p)
|
|
1172 (error "%sEmacs is not running as a window application"
|
|
1173 (if ediff-emacs-p "" "X")))
|
78
|
1174
|
|
1175 (setq set-func (if (ediff-in-control-buffer-p) 'setq 'setq-default))
|
|
1176
|
0
|
1177 (cond ((eq ediff-window-setup-function 'ediff-setup-windows-multiframe)
|
78
|
1178 (eval
|
|
1179 (list
|
|
1180 set-func
|
|
1181 'ediff-window-setup-function ''ediff-setup-windows-plain)))
|
0
|
1182 ((eq ediff-window-setup-function 'ediff-setup-windows-plain)
|
78
|
1183 (if (ediff-in-control-buffer-p)
|
|
1184 (ediff-kill-bottom-toolbar))
|
|
1185 (eval
|
|
1186 (list
|
|
1187 set-func
|
|
1188 'ediff-window-setup-function ''ediff-setup-windows-multiframe))))
|
|
1189 (if (ediff-in-control-buffer-p)
|
|
1190 (progn
|
|
1191 (setq ediff-window-B nil)
|
|
1192 (ediff-recenter 'no-rehighlight)))))
|
|
1193
|
|
1194 ;; if was using toolbar, kill it
|
|
1195 (defun ediff-kill-bottom-toolbar ()
|
|
1196 ;; Using ctl-buffer or ediff-control-window for LOCALE does not
|
|
1197 ;; work properly in XEmacs 19.14: we have to use
|
|
1198 ;;(selected-frame).
|
|
1199 ;; The problem with this is that any previous bottom-toolbar
|
|
1200 ;; will not re-appear after our cleanup here. Is there a way
|
|
1201 ;; to do "push" and "pop" toolbars ? --marcpa
|
|
1202 (if (ediff-use-toolbar-p)
|
|
1203 (progn
|
|
1204 (set-specifier bottom-toolbar (list (selected-frame) nil))
|
|
1205 (set-specifier bottom-toolbar-visible-p (list (selected-frame) nil)))))
|
|
1206
|
|
1207 ;; if wants to use toolbar, make it
|
|
1208 (defun ediff-make-bottom-toolbar ()
|
|
1209 (if (ediff-use-toolbar-p)
|
|
1210 (progn
|
|
1211 (set-specifier bottom-toolbar (list (selected-frame) ediff-toolbar))
|
|
1212 (set-specifier bottom-toolbar-visible-p (list (selected-frame) t))
|
|
1213 (set-specifier bottom-toolbar-height (list (selected-frame) 34)))))
|
0
|
1214
|
|
1215 ;; Merging
|
|
1216
|
|
1217 (defun ediff-toggle-show-clashes-only ()
|
|
1218 "Toggle the mode where only the regions where both buffers differ with the ancestor are shown."
|
|
1219 (interactive)
|
|
1220 (ediff-barf-if-not-control-buffer)
|
|
1221 (if (not ediff-merge-with-ancestor-job)
|
|
1222 (error "This command makes sense only when merging with an ancestor"))
|
|
1223 (setq ediff-show-clashes-only (not ediff-show-clashes-only))
|
|
1224 (if ediff-show-clashes-only
|
|
1225 (message "Focus on regions where both buffers differ from the ancestor")
|
|
1226 (message "Canceling focus on regions where changes clash")))
|
|
1227
|
|
1228 ;; Widening/narrowing
|
|
1229
|
|
1230 (defun ediff-toggle-narrow-region ()
|
|
1231 "Toggle narrowing in buffers A, B, and C.
|
|
1232 Used in ediff-windows/regions only."
|
|
1233 (interactive)
|
|
1234 (if (eq ediff-buffer-A ediff-buffer-B)
|
|
1235 (error ediff-NO-DIFFERENCES))
|
|
1236 (if (eq ediff-visible-bounds ediff-wide-bounds)
|
|
1237 (setq ediff-visible-bounds ediff-narrow-bounds)
|
|
1238 (setq ediff-visible-bounds ediff-wide-bounds))
|
|
1239 (ediff-recenter 'no-rehighlight))
|
|
1240
|
|
1241 ;; Narrow bufs A/B/C to ediff-visible-bounds. If this is currently set to
|
|
1242 ;; ediff-wide-bounds, then this actually widens.
|
|
1243 ;; This function does nothing if job-name is not
|
|
1244 ;; ediff-regions-wordwise/linewise or ediff-windows-wordwise/linewise.
|
|
1245 ;; Does nothing if buffer-A = buffer-B since we can't narrow
|
|
1246 ;; to two different regions in one buffer.
|
|
1247 (defun ediff-visible-region ()
|
|
1248 (if (or (eq ediff-buffer-A ediff-buffer-B)
|
|
1249 (eq ediff-buffer-A ediff-buffer-C)
|
|
1250 (eq ediff-buffer-C ediff-buffer-B))
|
|
1251 ()
|
|
1252 ;; If ediff-*-regions/windows, ediff-visible-bounds is already set
|
|
1253 ;; Otherwise, always use full range.
|
|
1254 (if (not ediff-narrow-job)
|
|
1255 (setq ediff-visible-bounds ediff-wide-bounds))
|
|
1256 (let ((overl-A (ediff-get-value-according-to-buffer-type
|
|
1257 'A ediff-visible-bounds))
|
|
1258 (overl-B (ediff-get-value-according-to-buffer-type
|
|
1259 'B ediff-visible-bounds))
|
|
1260 (overl-C (ediff-get-value-according-to-buffer-type
|
|
1261 'C ediff-visible-bounds))
|
|
1262 )
|
|
1263 (ediff-eval-in-buffer ediff-buffer-A
|
|
1264 (narrow-to-region
|
|
1265 (ediff-overlay-start overl-A) (ediff-overlay-end overl-A)))
|
|
1266 (ediff-eval-in-buffer ediff-buffer-B
|
|
1267 (narrow-to-region
|
|
1268 (ediff-overlay-start overl-B) (ediff-overlay-end overl-B)))
|
|
1269
|
70
|
1270 (if ediff-3way-comparison-job
|
0
|
1271 (ediff-eval-in-buffer ediff-buffer-C
|
|
1272 (narrow-to-region
|
|
1273 (ediff-overlay-start overl-C) (ediff-overlay-end overl-C))))
|
|
1274 )))
|
|
1275
|
|
1276
|
|
1277 ;; Window scrolling operations
|
|
1278
|
|
1279 ;; Performs some operation on the two file windows (if they are showing).
|
|
1280 ;; Traps all errors on the operation in windows A/B/C.
|
|
1281 ;; Usually, errors come from scrolling off the
|
|
1282 ;; beginning or end of the buffer, and this gives error messages.
|
|
1283 (defun ediff-operate-on-windows (operation arg)
|
|
1284
|
|
1285 ;; make sure windows aren't dead
|
|
1286 (if (not (and (window-live-p ediff-window-A) (window-live-p ediff-window-B)))
|
|
1287 (ediff-recenter 'no-rehighlight))
|
|
1288 (if (not (and (ediff-buffer-live-p ediff-buffer-A)
|
|
1289 (ediff-buffer-live-p ediff-buffer-B)
|
|
1290 (or (not ediff-3way-job) ediff-buffer-C)
|
|
1291 ))
|
|
1292 (error ediff-KILLED-VITAL-BUFFER))
|
|
1293
|
|
1294 (let* ((wind (selected-window))
|
|
1295 (wind-A ediff-window-A)
|
|
1296 (wind-B ediff-window-B)
|
|
1297 (wind-C ediff-window-C)
|
|
1298 (coefA (ediff-get-region-size-coefficient 'A operation))
|
|
1299 (coefB (ediff-get-region-size-coefficient 'B operation))
|
|
1300 (three-way ediff-3way-job)
|
|
1301 (coefC (if three-way
|
|
1302 (ediff-get-region-size-coefficient 'C operation))))
|
|
1303
|
|
1304 (select-window wind-A)
|
|
1305 (condition-case nil
|
|
1306 (funcall operation (round (* coefA arg)))
|
|
1307 (error))
|
|
1308 (select-window wind-B)
|
|
1309 (condition-case nil
|
|
1310 (funcall operation (round (* coefB arg)))
|
|
1311 (error))
|
|
1312 (if three-way
|
|
1313 (progn
|
|
1314 (select-window wind-C)
|
|
1315 (condition-case nil
|
|
1316 (funcall operation (round (* coefC arg)))
|
|
1317 (error))))
|
|
1318 (select-window wind)))
|
|
1319
|
|
1320 (defun ediff-scroll-vertically (&optional arg)
|
|
1321 "Vertically scroll buffers A, B \(and C if appropriate\).
|
|
1322 With optional argument ARG, scroll ARG lines; otherwise scroll by nearly
|
|
1323 the one half of the height of window-A."
|
|
1324 (interactive "P")
|
|
1325 (ediff-barf-if-not-control-buffer)
|
|
1326
|
|
1327 ;; make sure windows aren't dead
|
|
1328 (if (not (and (window-live-p ediff-window-A) (window-live-p ediff-window-B)))
|
|
1329 (ediff-recenter 'no-rehighlight))
|
|
1330 (if (not (and (ediff-buffer-live-p ediff-buffer-A)
|
|
1331 (ediff-buffer-live-p ediff-buffer-B)
|
|
1332 (or (not ediff-3way-job)
|
|
1333 (ediff-buffer-live-p ediff-buffer-C))
|
|
1334 ))
|
|
1335 (error ediff-KILLED-VITAL-BUFFER))
|
|
1336
|
|
1337 (ediff-operate-on-windows
|
|
1338 (if (memq last-command-char '(?v ?\C-v))
|
|
1339 'scroll-up
|
|
1340 'scroll-down)
|
|
1341 ;; calculate argument to scroll-up/down
|
|
1342 ;; if there is an explicit argument
|
|
1343 (if (and arg (not (equal arg '-)))
|
|
1344 ;; use it
|
|
1345 (prefix-numeric-value arg)
|
|
1346 ;; if not, see if we can determine a default amount (the window height)
|
|
1347 (let (default-amount)
|
|
1348 (setq default-amount
|
|
1349 (- (/ (min (window-height ediff-window-A)
|
|
1350 (window-height ediff-window-B)
|
|
1351 (if ediff-3way-job
|
|
1352 (window-height ediff-window-C)
|
|
1353 500)) ; some large number
|
|
1354 2)
|
|
1355 1 next-screen-context-lines))
|
|
1356 ;; window found
|
|
1357 (if arg
|
|
1358 ;; C-u as argument means half of default amount
|
|
1359 (/ default-amount 2)
|
|
1360 ;; no argument means default amount
|
|
1361 default-amount)))))
|
|
1362
|
|
1363
|
|
1364 (defun ediff-scroll-horizontally (&optional arg)
|
|
1365 "Horizontally scroll buffers A, B \(and C if appropriate\).
|
|
1366 If an argument is given, that is how many columns are scrolled, else nearly
|
|
1367 the width of the A/B/C windows."
|
|
1368 (interactive "P")
|
|
1369 (ediff-barf-if-not-control-buffer)
|
|
1370
|
|
1371 ;; make sure windows aren't dead
|
|
1372 (if (not (and (window-live-p ediff-window-A) (window-live-p ediff-window-B)))
|
|
1373 (ediff-recenter 'no-rehighlight))
|
|
1374 (if (not (and (ediff-buffer-live-p ediff-buffer-A)
|
|
1375 (ediff-buffer-live-p ediff-buffer-B)
|
|
1376 (or (not ediff-3way-job)
|
|
1377 (ediff-buffer-live-p ediff-buffer-C))
|
|
1378 ))
|
|
1379 (error ediff-KILLED-VITAL-BUFFER))
|
|
1380
|
|
1381 (ediff-operate-on-windows
|
|
1382 (if (= last-command-char ?<)
|
|
1383 'scroll-left
|
|
1384 'scroll-right)
|
|
1385 ;; calculate argument to scroll-left/right
|
|
1386 ;; if there is an explicit argument
|
|
1387 (if (and arg (not (equal arg '-)))
|
|
1388 ;; use it
|
|
1389 (prefix-numeric-value arg)
|
|
1390 ;; if not, see if we can determine a default amount
|
|
1391 ;; (half the window width)
|
|
1392 (if (null ediff-control-window)
|
|
1393 ;; no control window, use nil
|
|
1394 nil
|
|
1395 (let ((default-amount
|
|
1396 (- (/ (min (window-width ediff-window-A)
|
|
1397 (window-width ediff-window-B)
|
|
1398 (if ediff-3way-comparison-job
|
|
1399 (window-width ediff-window-C)
|
|
1400 500) ; some large number
|
|
1401 )
|
|
1402 2)
|
|
1403 3)))
|
|
1404 ;; window found
|
|
1405 (if arg
|
|
1406 ;; C-u as argument means half of default amount
|
|
1407 (/ default-amount 2)
|
|
1408 ;; no argument means default amount
|
|
1409 default-amount))))))
|
|
1410
|
|
1411
|
|
1412 ;;BEG, END show the region to be positioned.
|
|
1413 ;;JOB-NAME holds ediff-job-name. The ediff-windows job positions regions
|
|
1414 ;;differently.
|
|
1415 (defun ediff-position-region (beg end pos job-name)
|
|
1416 (if (> end (point-max))
|
|
1417 (setq end (point-max)))
|
|
1418 (if ediff-windows-job
|
|
1419 (if (pos-visible-in-window-p end)
|
|
1420 () ; do nothing, wind is already positioned
|
|
1421 ;; at this point, windows are positioned at the beginning of the
|
|
1422 ;; file regions (not diff-regions) being compared.
|
|
1423 (save-excursion
|
|
1424 (move-to-window-line (- (window-height) 2))
|
|
1425 (let ((amount (+ 2 (count-lines (point) end))))
|
|
1426 (scroll-up amount))))
|
|
1427 (set-window-start (selected-window) beg)
|
|
1428 (if (pos-visible-in-window-p end)
|
|
1429 ;; Determine the number of lines that the region occupies
|
|
1430 (let ((lines 0)
|
|
1431 (prev-point 0))
|
|
1432 (while ( and (> end (progn
|
|
1433 (move-to-window-line lines)
|
|
1434 (point)))
|
|
1435 ;; `end' may be beyond the window bottom, so check
|
|
1436 ;; that we are making progress
|
|
1437 (< prev-point (point)))
|
|
1438 (setq prev-point (point))
|
|
1439 (setq lines (1+ lines)))
|
|
1440 ;; And position the beginning on the right line
|
|
1441 (goto-char beg)
|
|
1442 (recenter (/ (1+ (max (- (1- (window-height (selected-window)))
|
|
1443 lines)
|
|
1444 1)
|
|
1445 )
|
|
1446 2))))
|
|
1447 (goto-char pos)
|
|
1448 ))
|
|
1449
|
|
1450 ;; get number of lines from window start to region end
|
|
1451 (defun ediff-get-lines-to-region-end (buf-type &optional n ctl-buf)
|
|
1452 (or n (setq n ediff-current-difference))
|
|
1453 (or ctl-buf (setq ctl-buf ediff-control-buffer))
|
|
1454 (ediff-eval-in-buffer ctl-buf
|
|
1455 (let* ((buf (ediff-get-buffer buf-type))
|
|
1456 (wind (eval (intern (format "ediff-window-%S" buf-type))))
|
|
1457 (beg (window-start wind))
|
|
1458 (end (ediff-get-diff-posn buf-type 'end))
|
|
1459 lines)
|
|
1460 (ediff-eval-in-buffer buf
|
|
1461 (if (< beg end)
|
|
1462 (setq lines (count-lines beg end))
|
|
1463 (setq lines 0))
|
|
1464 lines
|
|
1465 ))))
|
|
1466
|
|
1467 ;; get number of lines from window end to region start
|
|
1468 (defun ediff-get-lines-to-region-start (buf-type &optional n ctl-buf)
|
|
1469 (or n (setq n ediff-current-difference))
|
|
1470 (or ctl-buf (setq ctl-buf ediff-control-buffer))
|
|
1471 (ediff-eval-in-buffer ctl-buf
|
|
1472 (let* ((buf (ediff-get-buffer buf-type))
|
|
1473 (wind (eval (intern (format "ediff-window-%S" buf-type))))
|
|
1474 (end (window-end wind))
|
|
1475 (beg (ediff-get-diff-posn buf-type 'beg)))
|
|
1476 (ediff-eval-in-buffer buf
|
|
1477 (if (< beg end) (count-lines beg end) 0))
|
|
1478 )))
|
|
1479
|
|
1480
|
|
1481 ;; region size coefficient is a coefficient by which to adjust scrolling
|
|
1482 ;; up/down of the window displaying buffer of type BUFTYPE.
|
|
1483 ;; The purpose of this coefficient is to make the windows scroll in sync, so
|
|
1484 ;; that it won't happen that one diff region is scrolled off while the other is
|
|
1485 ;; still seen.
|
|
1486 ;;
|
|
1487 ;; If the difference region is invalid, the coefficient is 1
|
|
1488 (defun ediff-get-region-size-coefficient (buf-type op &optional n ctl-buf)
|
|
1489 (ediff-eval-in-buffer (or ctl-buf ediff-control-buffer)
|
|
1490 (if (ediff-valid-difference-p n)
|
|
1491 (let* ((func (cond ((eq op 'scroll-down)
|
|
1492 'ediff-get-lines-to-region-start)
|
|
1493 ((eq op 'scroll-up)
|
|
1494 'ediff-get-lines-to-region-end)
|
|
1495 (t '(lambda (a b c) 0))))
|
|
1496 (max-lines (max (funcall func 'A n ctl-buf)
|
|
1497 (funcall func 'B n ctl-buf)
|
|
1498 (if (ediff-buffer-live-p ediff-buffer-C)
|
|
1499 (funcall func 'C n ctl-buf)
|
|
1500 0))))
|
|
1501 ;; this covers the horizontal coefficient as well:
|
|
1502 ;; if max-lines = 0 then coef = 1
|
|
1503 (if (> max-lines 0)
|
|
1504 (/ (+ (funcall func buf-type n ctl-buf) 0.0)
|
|
1505 (+ max-lines 0.0))
|
|
1506 1))
|
|
1507 1)))
|
|
1508
|
|
1509
|
|
1510 (defun ediff-next-difference (&optional arg)
|
|
1511 "Advance to the next difference.
|
|
1512 With a prefix argument, go forward that many differences."
|
|
1513 (interactive "p")
|
|
1514 (ediff-barf-if-not-control-buffer)
|
|
1515 (if (< ediff-current-difference ediff-number-of-differences)
|
|
1516 (let ((n (min ediff-number-of-differences
|
|
1517 (+ ediff-current-difference arg)))
|
|
1518 regexp-skip)
|
|
1519
|
|
1520 (or (>= n ediff-number-of-differences)
|
|
1521 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
|
|
1522 (ediff-install-fine-diff-if-necessary n))
|
|
1523 (while (and (< n ediff-number-of-differences)
|
|
1524 (or
|
|
1525 ;; regexp skip
|
|
1526 regexp-skip
|
|
1527 ;; skip clashes, if necessary
|
|
1528 (and ediff-show-clashes-only
|
|
1529 (string-match "prefer"
|
|
1530 (or (ediff-get-state-of-merge n) "")))
|
|
1531 ;; skip difference regions that differ in white space
|
|
1532 (and ediff-ignore-similar-regions
|
|
1533 (ediff-no-fine-diffs-p n))))
|
|
1534 (setq n (1+ n))
|
|
1535 (if (= 0 (mod n 20))
|
|
1536 (message "Skipped over region %d and counting ..." n))
|
|
1537 (or (>= n ediff-number-of-differences)
|
|
1538 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
|
|
1539 (ediff-install-fine-diff-if-necessary n))
|
|
1540 )
|
|
1541 (message "")
|
|
1542 (ediff-unselect-and-select-difference n)
|
|
1543 ) ; let
|
|
1544 (ediff-visible-region)
|
|
1545 (error "At end of the difference list")))
|
|
1546
|
|
1547 (defun ediff-previous-difference (&optional arg)
|
|
1548 "Go to the previous difference.
|
|
1549 With a prefix argument, go back that many differences."
|
|
1550 (interactive "p")
|
|
1551 (ediff-barf-if-not-control-buffer)
|
|
1552 (if (> ediff-current-difference -1)
|
|
1553 (let ((n (max -1 (- ediff-current-difference arg)))
|
|
1554 regexp-skip)
|
|
1555
|
|
1556 (or (< n 0)
|
|
1557 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
|
|
1558 (ediff-install-fine-diff-if-necessary n))
|
|
1559 (while (and (> n -1)
|
|
1560 (or
|
|
1561 ;; regexp skip
|
|
1562 regexp-skip
|
|
1563 ;; skip clashes, if necessary
|
|
1564 (and ediff-show-clashes-only
|
|
1565 (string-match "prefer"
|
|
1566 (or (ediff-get-state-of-merge n) "")))
|
|
1567 ;; skip difference regions that differ in white space
|
|
1568 (and ediff-ignore-similar-regions
|
|
1569 (ediff-no-fine-diffs-p n))))
|
|
1570 (if (= 0 (mod (1+ n) 20))
|
|
1571 (message "Skipped over region %d and counting ..." (1+ n)))
|
|
1572 (setq n (1- n))
|
|
1573 (or (< n 0)
|
|
1574 (setq regexp-skip (funcall ediff-skip-diff-region-function n))
|
|
1575 (ediff-install-fine-diff-if-necessary n))
|
|
1576 )
|
|
1577 (message "")
|
|
1578 (ediff-unselect-and-select-difference n)
|
|
1579 ) ; let
|
|
1580 (ediff-visible-region)
|
|
1581 (error "At beginning of the difference list")))
|
|
1582
|
|
1583 ;; The diff number is as perceived by the user (i.e., 1+ the internal
|
|
1584 ;; representation)
|
|
1585 (defun ediff-jump-to-difference (difference-number)
|
|
1586 "Go to the difference specified as a prefix argument.
|
|
1587 If the prefix is negative, count differences from the end."
|
|
1588 (interactive "p")
|
|
1589 (ediff-barf-if-not-control-buffer)
|
|
1590 (setq difference-number
|
|
1591 (cond ((< difference-number 0)
|
|
1592 (+ ediff-number-of-differences difference-number))
|
|
1593 ((> difference-number 0) (1- difference-number))
|
|
1594 (t -1)))
|
|
1595 ;; -1 is allowed by ediff-unselect-and-select-difference --- it is the
|
|
1596 ;; position before the first one.
|
|
1597 (if (and (>= difference-number -1)
|
|
1598 (<= difference-number ediff-number-of-differences))
|
|
1599 (ediff-unselect-and-select-difference difference-number)
|
|
1600 (error ediff-BAD-DIFF-NUMBER
|
|
1601 this-command (1+ difference-number) ediff-number-of-differences)))
|
|
1602
|
|
1603 (defun ediff-jump-to-difference-at-point (arg)
|
|
1604 "Go to difference closest to the point in buffer A, B, or C.
|
|
1605 The buffer depends on last command character \(a, b, or c\) that invoked this
|
|
1606 command. For instance, if the command was `ga' then the point value in buffer A
|
|
1607 is used.
|
|
1608 With a prefix argument, synchronize all files around the current point position
|
|
1609 in the specified buffer."
|
|
1610 (interactive "P")
|
|
1611 (ediff-barf-if-not-control-buffer)
|
|
1612 (let* ((buf-type (ediff-char-to-buftype last-command-char))
|
|
1613 (buffer (ediff-get-buffer buf-type))
|
|
1614 (pt (ediff-eval-in-buffer buffer (point)))
|
|
1615 (diff-no (ediff-diff-at-point buf-type nil (if arg 'after)))
|
|
1616 (past-last-diff (< ediff-number-of-differences diff-no))
|
|
1617 (beg (if past-last-diff
|
|
1618 (ediff-eval-in-buffer buffer (point-max))
|
|
1619 (ediff-get-diff-posn buf-type 'beg (1- diff-no))))
|
|
1620 ctl-wind wind-A wind-B wind-C
|
|
1621 shift)
|
|
1622 (if past-last-diff
|
|
1623 (ediff-jump-to-difference -1)
|
|
1624 (ediff-jump-to-difference diff-no))
|
|
1625 (setq ctl-wind (selected-window)
|
|
1626 wind-A ediff-window-A
|
|
1627 wind-B ediff-window-B
|
|
1628 wind-C ediff-window-C)
|
|
1629 (if arg
|
|
1630 (progn
|
|
1631 (ediff-eval-in-buffer buffer
|
|
1632 (setq shift (- beg pt)))
|
|
1633 (select-window wind-A)
|
|
1634 (if past-last-diff (goto-char (point-max)))
|
|
1635 (condition-case nil
|
|
1636 (backward-char shift) ; noerror, if beginning of buffer
|
|
1637 (error))
|
|
1638 (recenter)
|
|
1639 (select-window wind-B)
|
|
1640 (if past-last-diff (goto-char (point-max)))
|
|
1641 (condition-case nil
|
|
1642 (backward-char shift) ; noerror, if beginning of buffer
|
|
1643 (error))
|
|
1644 (recenter)
|
|
1645 (if (window-live-p wind-C)
|
|
1646 (progn
|
|
1647 (select-window wind-C)
|
|
1648 (if past-last-diff (goto-char (point-max)))
|
|
1649 (condition-case nil
|
|
1650 (backward-char shift) ; noerror, if beginning of buffer
|
|
1651 (error))
|
|
1652 (recenter)
|
|
1653 ))
|
|
1654 (select-window ctl-wind)
|
|
1655 ))
|
|
1656 ))
|
|
1657
|
|
1658
|
|
1659 ;; find region most related to the current point position (or POS, if given)
|
|
1660 ;; returns diff number as seen by the user (i.e., 1+ the internal
|
|
1661 ;; representation)
|
|
1662 ;; The optional argument WHICH-DIFF can be `after' or `before'. If `after',
|
|
1663 ;; find the diff after the point. If `before', find the diff before the
|
|
1664 ;; point. If the point is inside a diff, return that diff.
|
|
1665 (defun ediff-diff-at-point (buf-type &optional pos which-diff)
|
|
1666 (let ((buffer (ediff-get-buffer buf-type))
|
|
1667 (ctl-buffer ediff-control-buffer)
|
|
1668 (max-dif-num (1- ediff-number-of-differences))
|
|
1669 (diff-no -1)
|
|
1670 (prev-beg 0)
|
|
1671 (prev-end 0)
|
|
1672 (beg 0)
|
|
1673 (end 0))
|
|
1674
|
|
1675 (ediff-eval-in-buffer buffer
|
|
1676 (setq pos (or pos (point)))
|
|
1677 (while (and (or (< pos prev-beg) (> pos beg))
|
|
1678 (< diff-no max-dif-num))
|
|
1679 (setq diff-no (1+ diff-no))
|
|
1680 (setq prev-beg beg
|
|
1681 prev-end end)
|
|
1682 (setq beg (ediff-get-diff-posn buf-type 'beg diff-no ctl-buffer)
|
|
1683 end (ediff-get-diff-posn buf-type 'end diff-no ctl-buffer))
|
|
1684 )
|
|
1685
|
|
1686 ;; boost diff-no by 1, if past the last diff region
|
|
1687 (if (and (memq which-diff '(after before))
|
|
1688 (> pos beg) (= diff-no max-dif-num))
|
|
1689 (setq diff-no (1+ diff-no)))
|
|
1690
|
|
1691 (cond ((eq which-diff 'after) (1+ diff-no))
|
|
1692 ((eq which-diff 'before) diff-no)
|
|
1693 ((< (abs (count-lines pos (max 1 prev-end)))
|
|
1694 (abs (count-lines pos (max 1 beg))))
|
|
1695 diff-no) ; choose prev difference
|
|
1696 (t
|
|
1697 (1+ diff-no))) ; choose next difference
|
|
1698 )))
|
|
1699
|
|
1700
|
|
1701 ;;; Copying diffs.
|
|
1702
|
|
1703 (defun ediff-diff-to-diff (arg &optional keys)
|
|
1704 "Copy buffer-X'th difference region to buffer Y \(X,Y are A, B, or C\).
|
|
1705 If numerical prefix argument, copy the difference specified in the arg.
|
|
1706 Otherwise, copy the difference given by `ediff-current-difference'.
|
|
1707 This command assumes it is bound to a 2-character key sequence, `ab', `ba',
|
|
1708 `ac', etc., which is used to determine the types of buffers to be used for
|
|
1709 copying difference regions. The first character in the sequence specifies
|
|
1710 the source buffer and the second specifies the target.
|
|
1711
|
|
1712 If the second optional argument, a 2-character string, is given, use it to
|
|
1713 determine the source and the target buffers instead of the command keys."
|
|
1714 (interactive "P")
|
|
1715 (ediff-barf-if-not-control-buffer)
|
|
1716 (or keys (setq keys (this-command-keys)))
|
|
1717 (if (eq arg '-) (setq arg -1)) ; translate neg arg to -1
|
|
1718 (if (numberp arg) (ediff-jump-to-difference arg))
|
|
1719
|
|
1720 (let* ((key1 (aref keys 0))
|
|
1721 (key2 (aref keys 1))
|
|
1722 (char1 (if (and ediff-xemacs-p (eventp key1)) (event-key key1) key1))
|
|
1723 (char2 (if (and ediff-xemacs-p (eventp key1)) (event-key key2) key2))
|
|
1724 ediff-verbose-p)
|
|
1725 (ediff-copy-diff ediff-current-difference
|
|
1726 (ediff-char-to-buftype char1)
|
|
1727 (ediff-char-to-buftype char2))
|
|
1728 ;; recenter with rehighlighting, but no messages
|
|
1729 (ediff-recenter)))
|
|
1730
|
|
1731 (defun ediff-copy-A-to-B (arg)
|
|
1732 "Copy ARGth difference region from buffer A to B.
|
|
1733 ARG is a prefix argument. If nil, copy the current difference region."
|
|
1734 (interactive "P")
|
|
1735 (ediff-diff-to-diff arg "ab"))
|
|
1736
|
|
1737 (defun ediff-copy-B-to-A (arg)
|
|
1738 "Copy ARGth difference region from buffer B to A.
|
|
1739 ARG is a prefix argument. If nil, copy the current difference region."
|
|
1740 (interactive "P")
|
|
1741 (ediff-diff-to-diff arg "ba"))
|
|
1742
|
|
1743 (defun ediff-copy-A-to-C (arg)
|
|
1744 "Copy ARGth difference region from buffer A to buffer C.
|
|
1745 ARG is a prefix argument. If nil, copy the current difference region."
|
|
1746 (interactive "P")
|
|
1747 (ediff-diff-to-diff arg "ac"))
|
|
1748
|
|
1749 (defun ediff-copy-B-to-C (arg)
|
|
1750 "Copy ARGth difference region from buffer B to buffer C.
|
|
1751 ARG is a prefix argument. If nil, copy the current difference region."
|
|
1752 (interactive "P")
|
|
1753 (ediff-diff-to-diff arg "bc"))
|
|
1754
|
|
1755 (defun ediff-copy-C-to-B (arg)
|
|
1756 "Copy ARGth difference region from buffer C to B.
|
|
1757 ARG is a prefix argument. If nil, copy the current difference region."
|
|
1758 (interactive "P")
|
|
1759 (ediff-diff-to-diff arg "cb"))
|
|
1760
|
|
1761 (defun ediff-copy-C-to-A (arg)
|
|
1762 "Copy ARGth difference region from buffer C to A.
|
|
1763 ARG is a prefix argument. If nil, copy the current difference region."
|
|
1764 (interactive "P")
|
|
1765 (ediff-diff-to-diff arg "ca"))
|
|
1766
|
|
1767
|
|
1768
|
|
1769 ;; Copy diff N from FROM-BUF-TYPE \(given as A, B or C\) to TO-BUF-TYPE.
|
|
1770 ;; If optional DO-NOT-SAVE is non-nil, do not save the old value of the
|
|
1771 ;; target diff. This is used in merging, when constructing the merged
|
|
1772 ;; version.
|
|
1773 (defun ediff-copy-diff (n from-buf-type to-buf-type
|
|
1774 &optional batch-invocation reg-to-copy)
|
|
1775 (let* ((to-buf (ediff-get-buffer to-buf-type))
|
|
1776 ;;(from-buf (if (not reg-to-copy) (ediff-get-buffer from-buf-type)))
|
|
1777 (ctrl-buf ediff-control-buffer)
|
|
1778 (saved-p t)
|
|
1779 (three-way ediff-3way-job)
|
|
1780 messg
|
|
1781 ediff-verbose-p
|
|
1782 reg-to-delete reg-to-delete-beg reg-to-delete-end)
|
|
1783
|
|
1784 (setq reg-to-delete-beg
|
|
1785 (ediff-get-diff-posn to-buf-type 'beg n ctrl-buf))
|
|
1786 (setq reg-to-delete-end
|
|
1787 (ediff-get-diff-posn to-buf-type 'end n ctrl-buf))
|
|
1788
|
|
1789 (if reg-to-copy
|
|
1790 (setq from-buf-type nil)
|
|
1791 (setq reg-to-copy (ediff-get-region-contents n from-buf-type ctrl-buf)))
|
|
1792
|
|
1793 (setq reg-to-delete (ediff-get-region-contents
|
|
1794 n to-buf-type ctrl-buf
|
|
1795 reg-to-delete-beg reg-to-delete-end))
|
|
1796
|
|
1797 (if (string= reg-to-delete reg-to-copy)
|
|
1798 (setq saved-p nil) ; don't copy identical buffers
|
|
1799 ;; seems ok to copy
|
|
1800 (if (or batch-invocation (ediff-test-save-region n to-buf-type))
|
|
1801 (condition-case conds
|
|
1802 (progn
|
|
1803 (ediff-eval-in-buffer to-buf
|
|
1804 ;; to prevent flags from interfering if buffer is writable
|
|
1805 (let ((inhibit-read-only (null buffer-read-only)))
|
|
1806
|
|
1807 (goto-char reg-to-delete-end)
|
|
1808 (insert reg-to-copy)
|
|
1809
|
|
1810 (if (> reg-to-delete-end reg-to-delete-beg)
|
|
1811 (kill-region reg-to-delete-beg reg-to-delete-end))
|
|
1812 ))
|
|
1813 (or batch-invocation
|
|
1814 (setq
|
|
1815 messg
|
|
1816 (ediff-save-diff-region n to-buf-type reg-to-delete))))
|
|
1817 (error (message "ediff-copy-diff: %s %s"
|
|
1818 (car conds)
|
|
1819 (mapconcat 'prin1-to-string (cdr conds) " "))
|
|
1820 (beep 1)
|
|
1821 (sit-for 2) ; let the user see the error msg
|
|
1822 (setq saved-p nil)
|
|
1823 )))
|
|
1824 )
|
|
1825
|
|
1826 ;; adjust state of difference in case 3-way and diff was copied ok
|
|
1827 (if (and saved-p three-way)
|
|
1828 (ediff-set-state-of-diff-in-all-buffers n ctrl-buf))
|
|
1829
|
|
1830 (if batch-invocation
|
|
1831 (ediff-clear-fine-differences n)
|
|
1832 ;; If diff3 job, we should recompute fine diffs so we clear them
|
|
1833 ;; before reinserting flags (and thus before ediff-recenter).
|
|
1834 (if (and saved-p three-way)
|
|
1835 (ediff-clear-fine-differences n))
|
|
1836
|
|
1837 (ediff-refresh-mode-lines)
|
|
1838
|
|
1839 ;; For diff2 jobs, don't recompute fine diffs, since we know there
|
|
1840 ;; aren't any. So we clear diffs after ediff-recenter.
|
|
1841 (if (and saved-p (not three-way))
|
|
1842 (ediff-clear-fine-differences n))
|
|
1843 ;; Make sure that the message about saving and how to restore is seen
|
|
1844 ;; by the user
|
|
1845 (message messg))
|
|
1846 ))
|
|
1847
|
|
1848 ;; Save Nth diff of buffer BUF-TYPE \(A, B, or C\).
|
|
1849 ;; That is to say, the Nth diff on the `ediff-killed-diffs-alist'. REG
|
|
1850 ;; is the region to save. It is redundant here, but is passed anyway, for
|
|
1851 ;; convenience.
|
|
1852 (defun ediff-save-diff-region (n buf-type reg)
|
|
1853 (let* ((n-th-diff-saved (assoc n ediff-killed-diffs-alist))
|
|
1854 (buf (ediff-get-buffer buf-type))
|
|
1855 (this-buf-n-th-diff-saved (assoc buf (cdr n-th-diff-saved))))
|
|
1856
|
|
1857 (if this-buf-n-th-diff-saved
|
|
1858 ;; either nothing saved for n-th diff and buffer or we OK'ed
|
|
1859 ;; overriding
|
|
1860 (setcdr this-buf-n-th-diff-saved reg)
|
|
1861 (if n-th-diff-saved ;; n-th diff saved, but for another buffer
|
|
1862 (nconc n-th-diff-saved (list (cons buf reg)))
|
|
1863 (setq ediff-killed-diffs-alist ;; create record for n-th diff
|
|
1864 (cons (list n (cons buf reg))
|
|
1865 ediff-killed-diffs-alist))))
|
|
1866 (message "Saving old diff region #%d of buffer %S. To recover, type `r%s'"
|
|
1867 (1+ n) buf-type
|
|
1868 (if ediff-merge-job
|
|
1869 "" (downcase (symbol-name buf-type))))
|
|
1870 ))
|
|
1871
|
|
1872 ;; Test if saving Nth difference region of buffer BUF-TYPE is possible.
|
|
1873 (defun ediff-test-save-region (n buf-type)
|
|
1874 (let* ((n-th-diff-saved (assoc n ediff-killed-diffs-alist))
|
|
1875 (buf (ediff-get-buffer buf-type))
|
|
1876 (this-buf-n-th-diff-saved (assoc buf (cdr n-th-diff-saved))))
|
|
1877
|
|
1878 (if this-buf-n-th-diff-saved
|
|
1879 (if (yes-or-no-p
|
|
1880 (format
|
|
1881 "You've previously copied diff region %d to buffer %S. Confirm "
|
|
1882 (1+ n) buf-type))
|
|
1883 t
|
|
1884 (error "Quit"))
|
|
1885 t)))
|
|
1886
|
|
1887 (defun ediff-pop-diff (n buf-type)
|
|
1888 "Pop last killed Nth diff region from buffer BUF-TYPE."
|
|
1889 (let* ((n-th-record (assoc n ediff-killed-diffs-alist))
|
|
1890 (buf (ediff-get-buffer buf-type))
|
|
1891 (saved-rec (assoc buf (cdr n-th-record)))
|
|
1892 (three-way ediff-3way-job)
|
|
1893 (ctl-buf ediff-control-buffer)
|
|
1894 ediff-verbose-p
|
|
1895 saved-diff reg-beg reg-end recovered)
|
|
1896
|
|
1897 (if (cdr saved-rec)
|
|
1898 (setq saved-diff (cdr saved-rec))
|
|
1899 (if (> ediff-number-of-differences 0)
|
|
1900 (error "Nothing saved for diff %d in buffer %S" (1+ n) buf-type)
|
|
1901 (error ediff-NO-DIFFERENCES)))
|
|
1902
|
|
1903 (setq reg-beg (ediff-get-diff-posn buf-type 'beg n ediff-control-buffer))
|
|
1904 (setq reg-end (ediff-get-diff-posn buf-type 'end n ediff-control-buffer))
|
|
1905
|
|
1906 (condition-case conds
|
|
1907 (ediff-eval-in-buffer buf
|
|
1908 (let ((inhibit-read-only (null buffer-read-only)))
|
|
1909
|
|
1910 (goto-char reg-end)
|
|
1911 (insert saved-diff)
|
|
1912
|
|
1913 (if (> reg-end reg-beg)
|
|
1914 (kill-region reg-beg reg-end))
|
|
1915
|
|
1916 (setq recovered t)
|
|
1917 ))
|
|
1918 (error (message "ediff-pop-diff: %s %s"
|
|
1919 (car conds)
|
|
1920 (mapconcat 'prin1-to-string (cdr conds) " "))
|
|
1921 (beep 1)))
|
|
1922
|
|
1923 ;; Clearing fine diffs is necessary for
|
|
1924 ;; ediff-unselect-and-select-difference to properly recompute them. We
|
|
1925 ;; can't rely on ediff-copy-diff to clear this vector, as the user might
|
|
1926 ;; have modified diff regions after copying and, thus, may have recomputed
|
|
1927 ;; fine diffs.
|
|
1928 (if recovered
|
|
1929 (ediff-clear-fine-differences n))
|
|
1930
|
|
1931 ;; adjust state of difference
|
|
1932 (if (and three-way recovered)
|
|
1933 (ediff-set-state-of-diff-in-all-buffers n ctl-buf))
|
|
1934
|
|
1935 (ediff-refresh-mode-lines)
|
|
1936
|
|
1937 (if recovered
|
|
1938 (progn
|
|
1939 (setq n-th-record (delq saved-rec n-th-record))
|
|
1940 (message "Diff region %d in buffer %S restored" (1+ n) buf-type)
|
|
1941 ))
|
|
1942 ))
|
|
1943
|
|
1944 (defun ediff-restore-diff (arg &optional key)
|
|
1945 "Restore ARGth diff from `ediff-killed-diffs-alist'.
|
|
1946 ARG is a prefix argument. If ARG is nil, restore the current-difference.
|
|
1947 If the second optional argument, a character, is given, use it to
|
|
1948 determine the target buffer instead of last-command-char"
|
|
1949 (interactive "P")
|
|
1950 (ediff-barf-if-not-control-buffer)
|
|
1951 (if (numberp arg)
|
|
1952 (ediff-jump-to-difference arg))
|
|
1953 (ediff-pop-diff ediff-current-difference
|
|
1954 (ediff-char-to-buftype (or key last-command-char)))
|
|
1955 ;; recenter with rehighlighting, but no messages
|
|
1956 (let (ediff-verbose-p)
|
|
1957 (ediff-recenter)))
|
|
1958
|
|
1959 (defun ediff-restore-diff-in-merge-buffer (arg)
|
|
1960 "Restore ARGth diff in the merge buffer.
|
|
1961 ARG is a prefix argument. If nil, restore the current diff."
|
|
1962 (interactive "P")
|
|
1963 (ediff-restore-diff arg ?c))
|
|
1964
|
|
1965
|
|
1966 (defun ediff-toggle-regexp-match ()
|
|
1967 "Toggle between focusing and hiding of difference regions that match
|
|
1968 a regular expression typed in by the user."
|
|
1969 (interactive)
|
|
1970 (ediff-barf-if-not-control-buffer)
|
|
1971 (let ((regexp-A "")
|
|
1972 (regexp-B "")
|
|
1973 (regexp-C "")
|
|
1974 msg-connective alt-msg-connective alt-connective)
|
|
1975 (cond
|
|
1976 ((or (and (eq ediff-skip-diff-region-function
|
|
1977 ediff-focus-on-regexp-matches-function)
|
|
1978 (eq last-command-char ?f))
|
|
1979 (and (eq ediff-skip-diff-region-function
|
|
1980 ediff-hide-regexp-matches-function)
|
|
1981 (eq last-command-char ?h)))
|
|
1982 (message "Selective browsing by regexp turned off")
|
|
1983 (setq ediff-skip-diff-region-function 'ediff-show-all-diffs))
|
|
1984 ((eq last-command-char ?h)
|
|
1985 (setq ediff-skip-diff-region-function ediff-hide-regexp-matches-function
|
|
1986 regexp-A
|
|
1987 (read-string
|
|
1988 (format
|
|
1989 "Ignore A-regions matching this regexp (default \"%s\"): "
|
|
1990 ediff-regexp-hide-A))
|
|
1991 regexp-B
|
|
1992 (read-string
|
|
1993 (format
|
|
1994 "Ignore B-regions matching this regexp (default \"%s\"): "
|
|
1995 ediff-regexp-hide-B)))
|
|
1996 (if ediff-3way-comparison-job
|
|
1997 (setq regexp-C
|
|
1998 (read-string
|
|
1999 (format
|
|
2000 "Ignore C-regions matching this regexp (default \"%s\"): "
|
|
2001 ediff-regexp-hide-C))))
|
|
2002 (if (eq ediff-hide-regexp-connective 'and)
|
|
2003 (setq msg-connective "BOTH"
|
|
2004 alt-msg-connective "ONE OF"
|
|
2005 alt-connective 'or)
|
|
2006 (setq msg-connective "ONE OF"
|
|
2007 alt-msg-connective "BOTH"
|
|
2008 alt-connective 'and))
|
|
2009 (if (y-or-n-p
|
|
2010 (format
|
|
2011 "Ignore regions that match %s regexps, OK? "
|
|
2012 msg-connective alt-msg-connective))
|
|
2013 (message "Will ignore regions that match %s regexps" msg-connective)
|
|
2014 (setq ediff-hide-regexp-connective alt-connective)
|
|
2015 (message "Will ignore regions that match %s regexps"
|
|
2016 alt-msg-connective))
|
|
2017
|
|
2018 (or (string= regexp-A "") (setq ediff-regexp-hide-A regexp-A))
|
|
2019 (or (string= regexp-B "") (setq ediff-regexp-hide-B regexp-B))
|
|
2020 (or (string= regexp-C "") (setq ediff-regexp-hide-C regexp-C)))
|
|
2021
|
|
2022 ((eq last-command-char ?f)
|
|
2023 (setq ediff-skip-diff-region-function
|
|
2024 ediff-focus-on-regexp-matches-function
|
|
2025 regexp-A
|
|
2026 (read-string
|
|
2027 (format
|
|
2028 "Focus on A-regions matching this regexp (default \"%s\"): "
|
|
2029 ediff-regexp-focus-A))
|
|
2030 regexp-B
|
|
2031 (read-string
|
|
2032 (format
|
|
2033 "Focus on B-regions matching this regexp (default \"%s\"): "
|
|
2034 ediff-regexp-focus-B)))
|
|
2035 (if ediff-3way-comparison-job
|
|
2036 (setq regexp-C
|
|
2037 (read-string
|
|
2038 (format
|
|
2039 "Focus on C-regions matching this regexp (default \"%s\"): "
|
|
2040 ediff-regexp-focus-C))))
|
|
2041 (if (eq ediff-focus-regexp-connective 'and)
|
|
2042 (setq msg-connective "BOTH"
|
|
2043 alt-msg-connective "ONE OF"
|
|
2044 alt-connective 'or)
|
|
2045 (setq msg-connective "ONE OF"
|
|
2046 alt-msg-connective "BOTH"
|
|
2047 alt-connective 'and))
|
|
2048 (if (y-or-n-p
|
|
2049 (format
|
|
2050 "Focus on regions that match %s regexps, OK? "
|
|
2051 msg-connective alt-msg-connective))
|
|
2052 (message "Will focus on regions that match %s regexps"
|
|
2053 msg-connective)
|
|
2054 (setq ediff-focus-regexp-connective alt-connective)
|
|
2055 (message "Will focus on regions that match %s regexps"
|
|
2056 alt-msg-connective))
|
|
2057
|
|
2058 (or (string= regexp-A "") (setq ediff-regexp-focus-A regexp-A))
|
|
2059 (or (string= regexp-B "") (setq ediff-regexp-focus-B regexp-B))
|
|
2060 (or (string= regexp-C "") (setq ediff-regexp-focus-C regexp-C))))))
|
|
2061
|
|
2062 (defun ediff-toggle-skip-similar ()
|
|
2063 (interactive)
|
|
2064 (ediff-barf-if-not-control-buffer)
|
|
2065 (if (not (eq ediff-auto-refine 'on))
|
|
2066 (error
|
|
2067 "Can't skip over whitespace regions: first turn auto-refining on"))
|
|
2068 (setq ediff-ignore-similar-regions (not ediff-ignore-similar-regions))
|
|
2069 (if ediff-ignore-similar-regions
|
|
2070 (message
|
|
2071 "Skipping regions that differ only in white space & line breaks")
|
|
2072 (message "Skipping over white-space differences turned off")))
|
|
2073
|
|
2074 (defun ediff-focus-on-regexp-matches (n)
|
|
2075 "Focus on diffs that match regexp `ediff-regexp-focus-A/B'.
|
|
2076 Regions to be ignored according to this function are those where
|
|
2077 buf A region doesn't match `ediff-regexp-focus-A' and buf B region
|
|
2078 doesn't match `ediff-regexp-focus-B'.
|
|
2079 This function returns nil if the region number N (specified as
|
|
2080 an argument) is not to be ignored and t if region N is to be ignored.
|
|
2081
|
|
2082 N is a region number used by Ediff internally. It is 1 less
|
|
2083 the number seen by the user."
|
|
2084 (if (ediff-valid-difference-p n)
|
|
2085 (let* ((ctl-buf ediff-control-buffer)
|
|
2086 (regex-A ediff-regexp-focus-A)
|
|
2087 (regex-B ediff-regexp-focus-B)
|
|
2088 (regex-C ediff-regexp-focus-C)
|
|
2089 (reg-A-match (ediff-eval-in-buffer ediff-buffer-A
|
|
2090 (save-restriction
|
|
2091 (narrow-to-region
|
|
2092 (ediff-get-diff-posn 'A 'beg n ctl-buf)
|
|
2093 (ediff-get-diff-posn 'A 'end n ctl-buf))
|
|
2094 (goto-char (point-min))
|
|
2095 (re-search-forward regex-A nil t))))
|
|
2096 (reg-B-match (ediff-eval-in-buffer ediff-buffer-B
|
|
2097 (save-restriction
|
|
2098 (narrow-to-region
|
|
2099 (ediff-get-diff-posn 'B 'beg n ctl-buf)
|
|
2100 (ediff-get-diff-posn 'B 'end n ctl-buf))
|
|
2101 (re-search-forward regex-B nil t))))
|
|
2102 (reg-C-match (if ediff-3way-comparison-job
|
|
2103 (ediff-eval-in-buffer ediff-buffer-C
|
|
2104 (save-restriction
|
|
2105 (narrow-to-region
|
|
2106 (ediff-get-diff-posn 'C 'beg n ctl-buf)
|
|
2107 (ediff-get-diff-posn 'C 'end n ctl-buf))
|
|
2108 (re-search-forward regex-C nil t))))))
|
|
2109 (not (eval (if ediff-3way-comparison-job
|
|
2110 (list ediff-focus-regexp-connective
|
|
2111 reg-A-match reg-B-match reg-C-match)
|
|
2112 (list ediff-focus-regexp-connective
|
|
2113 reg-A-match reg-B-match))))
|
|
2114 )))
|
|
2115
|
|
2116 (defun ediff-hide-regexp-matches (n)
|
|
2117 "Hide diffs that match regexp `ediff-regexp-hide-A/B/C'.
|
|
2118 Regions to be ignored are those where buf A region matches
|
|
2119 `ediff-regexp-hide-A' and buf B region matches `ediff-regexp-hide-B'.
|
|
2120 This function returns nil if the region number N (specified as
|
|
2121 an argument) is not to be ignored and t if region N is to be ignored.
|
|
2122
|
|
2123 N is a region number used by Ediff internally. It is 1 less
|
|
2124 the number seen by the user."
|
|
2125 (if (ediff-valid-difference-p n)
|
|
2126 (let* ((ctl-buf ediff-control-buffer)
|
|
2127 (regex-A ediff-regexp-hide-A)
|
|
2128 (regex-B ediff-regexp-hide-B)
|
|
2129 (regex-C ediff-regexp-hide-C)
|
|
2130 (reg-A-match (ediff-eval-in-buffer ediff-buffer-A
|
|
2131 (save-restriction
|
|
2132 (narrow-to-region
|
|
2133 (ediff-get-diff-posn 'A 'beg n ctl-buf)
|
|
2134 (ediff-get-diff-posn 'A 'end n ctl-buf))
|
|
2135 (goto-char (point-min))
|
|
2136 (re-search-forward regex-A nil t))))
|
|
2137 (reg-B-match (ediff-eval-in-buffer ediff-buffer-B
|
|
2138 (save-restriction
|
|
2139 (narrow-to-region
|
|
2140 (ediff-get-diff-posn 'B 'beg n ctl-buf)
|
|
2141 (ediff-get-diff-posn 'B 'end n ctl-buf))
|
|
2142 (goto-char (point-min))
|
|
2143 (re-search-forward regex-B nil t))))
|
|
2144 (reg-C-match (if ediff-3way-comparison-job
|
|
2145 (ediff-eval-in-buffer ediff-buffer-C
|
|
2146 (save-restriction
|
|
2147 (narrow-to-region
|
|
2148 (ediff-get-diff-posn 'C 'beg n ctl-buf)
|
|
2149 (ediff-get-diff-posn 'C 'end n ctl-buf))
|
|
2150 (goto-char (point-min))
|
|
2151 (re-search-forward regex-C nil t))))))
|
|
2152 (eval (if ediff-3way-comparison-job
|
|
2153 (list ediff-hide-regexp-connective
|
|
2154 reg-A-match reg-B-match reg-C-match)
|
|
2155 (list ediff-hide-regexp-connective reg-A-match reg-B-match)))
|
|
2156 )))
|
|
2157
|
|
2158
|
|
2159
|
|
2160 ;;; Quitting, suspending, etc.
|
|
2161
|
|
2162 (defun ediff-quit (reverse-default-keep-variants)
|
|
2163 "Finish an Ediff session and exit Ediff.
|
|
2164 Unselects the selected difference, if any, restores the read-only and modified
|
|
2165 flags of the compared file buffers, kills Ediff buffers for this session
|
|
2166 \(but not buffers A, B, C\).
|
|
2167
|
|
2168 If `ediff-keep-variants' is nil, the user will be asked whether the buffers
|
|
2169 containing the variants should be removed \(if they haven't been modified\).
|
|
2170 If it is t, they will be preserved unconditionally. A prefix argument,
|
|
2171 temporarily reverses the meaning of this variable."
|
|
2172 (interactive "P")
|
|
2173 (ediff-barf-if-not-control-buffer)
|
70
|
2174 (if (y-or-n-p (format "Quit this Ediff session%s? "
|
|
2175 (if (ediff-buffer-live-p ediff-meta-buffer)
|
|
2176 " & show containing session group" "")))
|
|
2177 (progn
|
|
2178 (message "")
|
|
2179 (ediff-really-quit reverse-default-keep-variants))
|
|
2180 (message "")))
|
0
|
2181
|
|
2182
|
|
2183 ;; Perform the quit operations.
|
|
2184 (defun ediff-really-quit (reverse-default-keep-variants)
|
|
2185 (ediff-unhighlight-diffs-totally)
|
|
2186 (ediff-clear-diff-vector 'ediff-difference-vector-A 'fine-diffs-also)
|
|
2187 (ediff-clear-diff-vector 'ediff-difference-vector-B 'fine-diffs-also)
|
|
2188 (ediff-clear-diff-vector 'ediff-difference-vector-C 'fine-diffs-also)
|
|
2189 (ediff-clear-diff-vector 'ediff-difference-vector-Ancestor 'fine-diffs-also)
|
|
2190
|
|
2191 (ediff-delete-temp-files)
|
|
2192
|
|
2193 ;; Restore visibility range. This affects only ediff-*-regions/windows.
|
|
2194 ;; Since for other job names ediff-visible-region sets
|
|
2195 ;; ediff-visible-bounds to ediff-wide-bounds, the settings below are
|
|
2196 ;; ignored for such jobs.
|
|
2197 (if ediff-quit-widened
|
|
2198 (setq ediff-visible-bounds ediff-wide-bounds)
|
|
2199 (setq ediff-visible-bounds ediff-narrow-bounds))
|
|
2200
|
|
2201 ;; Apply selective display to narrow or widen
|
|
2202 (ediff-visible-region)
|
|
2203 (mapcar (function (lambda (overl)
|
|
2204 (if (ediff-overlayp overl)
|
|
2205 (ediff-delete-overlay overl))))
|
|
2206 ediff-wide-bounds)
|
|
2207 (mapcar (function (lambda (overl)
|
|
2208 (if (ediff-overlayp overl)
|
|
2209 (ediff-delete-overlay overl))))
|
|
2210 ediff-narrow-bounds)
|
78
|
2211
|
0
|
2212 ;; restore buffer mode line id's in buffer-A/B/C
|
|
2213 (let ((control-buffer ediff-control-buffer)
|
78
|
2214 (meta-buffer ediff-meta-buffer)
|
|
2215 ;; suitable working frame
|
|
2216 (warp-frame (if (and (ediff-window-display-p) (eq ediff-grab-mouse t))
|
|
2217 (cond ((window-live-p ediff-window-A)
|
|
2218 (window-frame ediff-window-A))
|
|
2219 ((window-live-p ediff-window-B)
|
|
2220 (window-frame ediff-window-B))
|
|
2221 (t (next-frame))))))
|
0
|
2222 (condition-case nil
|
|
2223 (ediff-eval-in-buffer ediff-buffer-A
|
|
2224 (setq ediff-this-buffer-ediff-sessions
|
|
2225 (delq control-buffer ediff-this-buffer-ediff-sessions))
|
|
2226 (kill-local-variable 'mode-line-buffer-identification)
|
|
2227 (kill-local-variable 'mode-line-format)
|
|
2228 )
|
|
2229 (error))
|
|
2230
|
|
2231 (condition-case nil
|
|
2232 (ediff-eval-in-buffer ediff-buffer-B
|
|
2233 (setq ediff-this-buffer-ediff-sessions
|
|
2234 (delq control-buffer ediff-this-buffer-ediff-sessions))
|
|
2235 (kill-local-variable 'mode-line-buffer-identification)
|
|
2236 (kill-local-variable 'mode-line-format)
|
|
2237 )
|
|
2238 (error))
|
|
2239
|
|
2240 (condition-case nil
|
|
2241 (ediff-eval-in-buffer ediff-buffer-C
|
|
2242 (setq ediff-this-buffer-ediff-sessions
|
|
2243 (delq control-buffer ediff-this-buffer-ediff-sessions))
|
|
2244 (kill-local-variable 'mode-line-buffer-identification)
|
|
2245 (kill-local-variable 'mode-line-format)
|
|
2246 )
|
|
2247 (error))
|
|
2248
|
|
2249 (condition-case nil
|
|
2250 (ediff-eval-in-buffer ediff-ancestor-buffer
|
|
2251 (setq ediff-this-buffer-ediff-sessions
|
|
2252 (delq control-buffer ediff-this-buffer-ediff-sessions))
|
|
2253 (kill-local-variable 'mode-line-buffer-identification)
|
|
2254 (kill-local-variable 'mode-line-format)
|
|
2255 )
|
|
2256 (error))
|
|
2257
|
|
2258 (setq ediff-session-registry
|
|
2259 (delq ediff-control-buffer ediff-session-registry))
|
|
2260 (ediff-update-registry)
|
|
2261 ;; restore state of buffers to what it was before ediff
|
|
2262 (ediff-restore-protected-variables)
|
78
|
2263
|
|
2264 ;; If the user interrupts (canceling saving the merge buffer), continue
|
|
2265 ;; normally.
|
|
2266 (condition-case nil
|
|
2267 (if (ediff-merge-job)
|
|
2268 (run-hooks 'ediff-quit-merge-hook))
|
|
2269 (quit))
|
|
2270
|
0
|
2271 ;; good place to kill buffers A/B/C
|
|
2272 (run-hooks 'ediff-cleanup-hook)
|
|
2273 (let ((ediff-keep-variants ediff-keep-variants))
|
|
2274 (if reverse-default-keep-variants
|
|
2275 (setq ediff-keep-variants (not ediff-keep-variants)))
|
|
2276 (or ediff-keep-variants (ediff-janitor 'ask)))
|
|
2277
|
|
2278 (run-hooks 'ediff-quit-hook)
|
|
2279 (ediff-cleanup-meta-buffer meta-buffer)
|
78
|
2280
|
|
2281 ;; warp mouse into a working window
|
|
2282 (setq warp-frame ; if mouse is over a reasonable frame, use it
|
|
2283 (cond ((and ediff-xemacs-p (window-live-p (car (mouse-position))))
|
|
2284 (window-frame (car (mouse-position))))
|
|
2285 ((frame-live-p (car (mouse-position)))
|
|
2286 (car (mouse-position)))
|
|
2287 (t warp-frame)))
|
|
2288 (if (frame-live-p warp-frame)
|
|
2289 (set-mouse-position (if ediff-emacs-p
|
|
2290 warp-frame
|
|
2291 (frame-selected-window warp-frame))
|
|
2292 2 1))
|
|
2293
|
0
|
2294 (if (ediff-buffer-live-p meta-buffer)
|
|
2295 (ediff-show-meta-buffer meta-buffer))
|
|
2296 ))
|
|
2297
|
|
2298
|
|
2299 (defun ediff-delete-temp-files ()
|
|
2300 (if (stringp ediff-temp-file-A)
|
|
2301 (delete-file ediff-temp-file-A))
|
|
2302 (if (stringp ediff-temp-file-B)
|
|
2303 (delete-file ediff-temp-file-B))
|
|
2304 (if (stringp ediff-temp-file-C)
|
|
2305 (delete-file ediff-temp-file-C)))
|
|
2306
|
|
2307
|
|
2308 ;; Kill control buffer, other auxiliary Ediff buffers.
|
|
2309 ;; Leave one of the frames split between buffers A/B/C
|
|
2310 (defun ediff-cleanup-mess ()
|
|
2311 (let ((buff-A ediff-buffer-A)
|
|
2312 (buff-B ediff-buffer-B)
|
|
2313 (buff-C ediff-buffer-C)
|
|
2314 (ctl-buf ediff-control-buffer)
|
|
2315 (ctl-frame ediff-control-frame)
|
|
2316 (three-way-job ediff-3way-job))
|
|
2317
|
|
2318 (ediff-kill-buffer-carefully ediff-diff-buffer)
|
|
2319 (ediff-kill-buffer-carefully ediff-custom-diff-buffer)
|
|
2320 (ediff-kill-buffer-carefully ediff-fine-diff-buffer)
|
|
2321 (ediff-kill-buffer-carefully ediff-tmp-buffer)
|
|
2322 (ediff-kill-buffer-carefully ediff-error-buffer)
|
70
|
2323 (ediff-kill-buffer-carefully ediff-patch-diagnostics)
|
0
|
2324 (ediff-kill-buffer-carefully ediff-msg-buffer)
|
|
2325 (ediff-kill-buffer-carefully ediff-debug-buffer)
|
|
2326
|
|
2327 (if (and (ediff-window-display-p) (frame-live-p ctl-frame))
|
|
2328 (delete-frame ctl-frame))
|
78
|
2329 ;; Hide bottom toolbar. --marcpa
|
|
2330 (if (not (ediff-multiframe-setup-p))
|
|
2331 (ediff-kill-bottom-toolbar))
|
|
2332
|
0
|
2333 (ediff-kill-buffer-carefully ctl-buf)
|
|
2334
|
|
2335 (delete-other-windows)
|
|
2336
|
|
2337 ;; display only if not visible
|
|
2338 (condition-case nil
|
|
2339 (or (ediff-get-visible-buffer-window buff-B)
|
|
2340 (switch-to-buffer buff-B))
|
|
2341 (error))
|
|
2342 (condition-case nil
|
|
2343 (or (ediff-get-visible-buffer-window buff-A)
|
|
2344 (progn
|
|
2345 (if (ediff-get-visible-buffer-window buff-B)
|
78
|
2346 (funcall ediff-split-window-function))
|
0
|
2347 (switch-to-buffer buff-A)))
|
|
2348 (error))
|
|
2349 (if three-way-job
|
|
2350 (condition-case nil
|
|
2351 (or (ediff-get-visible-buffer-window buff-C)
|
|
2352 (progn
|
|
2353 (if (or (ediff-get-visible-buffer-window buff-A)
|
|
2354 (ediff-get-visible-buffer-window buff-B))
|
78
|
2355 (funcall ediff-split-window-function))
|
0
|
2356 (switch-to-buffer buff-C)
|
|
2357 (balance-windows)))
|
|
2358 (error)))
|
|
2359 (message "")
|
|
2360 ))
|
|
2361
|
|
2362 (defun ediff-janitor (&optional ask)
|
|
2363 "Kill buffers A, B, and, possibly, C, if these buffers aren't modified.
|
|
2364 In merge jobs, buffer C is never deleted.
|
|
2365 However, the side effect of cleaning up may be that you cannot compare the same
|
|
2366 buffer in two separate Ediff sessions: quitting one of them will delete this
|
|
2367 buffer in another session as well."
|
|
2368 (or (not (ediff-buffer-live-p ediff-buffer-A))
|
|
2369 (buffer-modified-p ediff-buffer-A)
|
|
2370 (and ask
|
|
2371 (not (y-or-n-p (format "Kill buffer A [%s]? "
|
|
2372 (buffer-name ediff-buffer-A)))))
|
|
2373 (ediff-kill-buffer-carefully ediff-buffer-A))
|
|
2374 (or (not (ediff-buffer-live-p ediff-buffer-B))
|
|
2375 (buffer-modified-p ediff-buffer-B)
|
|
2376 (and ask
|
|
2377 (not (y-or-n-p (format "Kill buffer B [%s]? "
|
|
2378 (buffer-name ediff-buffer-B)))))
|
|
2379 (ediff-kill-buffer-carefully ediff-buffer-B))
|
|
2380 (if ediff-merge-job ; don't del buf C if merging--del ancestor buf instead
|
|
2381 (or (not (ediff-buffer-live-p ediff-ancestor-buffer))
|
|
2382 (buffer-modified-p ediff-ancestor-buffer)
|
|
2383 (and ask
|
|
2384 (not (y-or-n-p (format "Kill the ancestor buffer [%s]? "
|
|
2385 (buffer-name ediff-ancestor-buffer)))))
|
|
2386 (ediff-kill-buffer-carefully ediff-ancestor-buffer))
|
|
2387 (or (not (ediff-buffer-live-p ediff-buffer-C))
|
|
2388 (buffer-modified-p ediff-buffer-C)
|
|
2389 (and ask (not (y-or-n-p (format "Kill buffer C [%s]? "
|
|
2390 (buffer-name ediff-buffer-C)))))
|
|
2391 (ediff-kill-buffer-carefully ediff-buffer-C))))
|
|
2392
|
78
|
2393 (defun ediff-maybe-save-and-delete-merge ()
|
|
2394 "Default hook to run on quitting a merge job.
|
|
2395 If `ediff-autostore-merges' is nil, this does nothing.
|
|
2396 If it is t, it saves the merge buffer in the file `ediff-merge-store-file'
|
|
2397 or asks the user, if the latter is nil. It then then asks the user whether to
|
|
2398 delete the merge buffer.
|
|
2399 If `ediff-autostore-merges' is neither nil nor t, the merge buffer is saved
|
|
2400 only if this merge job is part of a group, i.e., was invoked from within
|
|
2401 `ediff-merge-directories', `ediff-merge-directory-revisions', and such."
|
|
2402 (let ((merge-store-file ediff-merge-store-file))
|
|
2403 (if ediff-autostore-merges
|
|
2404 (cond ((stringp ediff-merge-store-file)
|
|
2405 ;; store, ask to delete
|
|
2406 (ediff-write-merge-buffer-then-kill
|
|
2407 ediff-buffer-C merge-store-file 'show-file))
|
|
2408 ((eq ediff-autostore-merges t)
|
|
2409 ;; ask for file name
|
|
2410 (setq merge-store-file
|
|
2411 (read-file-name "Save the result of the merge in: "))
|
|
2412 (ediff-write-merge-buffer-then-kill
|
|
2413 ediff-buffer-C merge-store-file))
|
|
2414 ((and (ediff-buffer-live-p ediff-meta-buffer)
|
|
2415 (ediff-eval-in-buffer ediff-meta-buffer
|
|
2416 (ediff-merge-metajob)))
|
|
2417 ;; This case shouldn't occur, as the parent metajob must pass on
|
|
2418 ;; a file name, ediff-merge-store-file, where to save the result
|
|
2419 ;; of the merge.
|
|
2420 ;; Ask where to save anyway--will decide what to do here later.
|
|
2421 (setq merge-store-file
|
|
2422 (read-file-name "The result of the merge goes into: "))
|
|
2423 (ediff-write-merge-buffer-then-kill
|
|
2424 ediff-buffer-C merge-store-file))))
|
|
2425 ))
|
|
2426
|
|
2427 (defun ediff-write-merge-buffer-then-kill (buf file &optional show-file)
|
|
2428 (ediff-eval-in-buffer buf
|
|
2429 (if (or (not (file-exists-p file))
|
|
2430 (y-or-n-p (format "File %s exists, overwrite? " file)))
|
|
2431 (progn
|
|
2432 (write-region (point-min) (point-max) file)
|
|
2433 (if show-file
|
|
2434 (progn
|
|
2435 (message "Merge buffer saved in: %s" file)
|
|
2436 (sit-for 2)))
|
|
2437 (if (y-or-n-p "Merge buffer saved in file. Now kill the buffer? ")
|
|
2438 (ediff-kill-buffer-carefully buf))))))
|
|
2439
|
0
|
2440 ;; The default way of suspending Ediff.
|
|
2441 ;; Buries Ediff buffers, kills all windows.
|
|
2442 (defun ediff-default-suspend-function ()
|
|
2443 (let* ((buf-A ediff-buffer-A)
|
|
2444 (buf-B ediff-buffer-B)
|
|
2445 (buf-C ediff-buffer-C)
|
|
2446 (buf-A-wind (ediff-get-visible-buffer-window buf-A))
|
|
2447 (buf-B-wind (ediff-get-visible-buffer-window buf-B))
|
|
2448 (buf-C-wind (ediff-get-visible-buffer-window buf-C))
|
70
|
2449 (buf-patch ediff-patchbufer)
|
|
2450 (buf-patch-diag ediff-patch-diagnostics)
|
0
|
2451 (buf-err ediff-error-buffer)
|
|
2452 (buf-diff ediff-diff-buffer)
|
|
2453 (buf-custom-diff ediff-custom-diff-buffer)
|
|
2454 (buf-fine-diff ediff-fine-diff-buffer))
|
|
2455
|
|
2456 ;; hide the control panel
|
|
2457 (if (and (ediff-window-display-p) (frame-live-p ediff-control-frame))
|
|
2458 (iconify-frame ediff-control-frame)
|
|
2459 (bury-buffer))
|
|
2460 (if buf-err (bury-buffer buf-err))
|
|
2461 (if buf-diff (bury-buffer buf-diff))
|
|
2462 (if buf-custom-diff (bury-buffer buf-custom-diff))
|
|
2463 (if buf-fine-diff (bury-buffer buf-fine-diff))
|
|
2464 (if buf-patch (bury-buffer buf-patch))
|
|
2465 (if buf-patch-diag (bury-buffer buf-patch-diag))
|
|
2466 (if (window-live-p buf-A-wind)
|
|
2467 (progn
|
|
2468 (select-window buf-A-wind)
|
|
2469 (delete-other-windows)
|
|
2470 (bury-buffer))
|
70
|
2471 (if (ediff-buffer-live-p buf-A) (bury-buffer buf-A)))
|
0
|
2472 (if (window-live-p buf-B-wind)
|
|
2473 (progn
|
|
2474 (select-window buf-B-wind)
|
|
2475 (delete-other-windows)
|
|
2476 (bury-buffer))
|
70
|
2477 (if (ediff-buffer-live-p buf-B) (bury-buffer buf-B)))
|
0
|
2478 (if (window-live-p buf-C-wind)
|
|
2479 (progn
|
|
2480 (select-window buf-C-wind)
|
|
2481 (delete-other-windows)
|
|
2482 (bury-buffer))
|
70
|
2483 (if (ediff-buffer-live-p buf-C) (bury-buffer buf-C)))
|
|
2484
|
0
|
2485 ))
|
|
2486
|
|
2487
|
|
2488 (defun ediff-suspend ()
|
|
2489 "Suspend Ediff.
|
|
2490 To resume, switch to the appropriate `Ediff Control Panel'
|
|
2491 buffer and then type \\[ediff-recenter]. Ediff will automatically set
|
|
2492 up an appropriate window config."
|
|
2493 (interactive)
|
|
2494 (ediff-barf-if-not-control-buffer)
|
|
2495 (run-hooks 'ediff-suspend-hook)
|
|
2496 (message
|
|
2497 "To resume, type M-x eregistry and select the desired Ediff session"))
|
|
2498
|
|
2499
|
|
2500 (defun ediff-status-info ()
|
|
2501 "Show the names of the buffers or files being operated on by Ediff.
|
|
2502 Hit \\[ediff-recenter] to reset the windows afterward."
|
|
2503 (interactive)
|
|
2504 (ediff-barf-if-not-control-buffer)
|
|
2505 (save-excursion
|
|
2506 (ediff-skip-unsuitable-frames))
|
|
2507 (with-output-to-temp-buffer ediff-msg-buffer
|
|
2508 (raise-frame (selected-frame))
|
|
2509 (princ (ediff-version))
|
|
2510 (princ "\n\n")
|
|
2511 (ediff-eval-in-buffer ediff-buffer-A
|
|
2512 (if buffer-file-name
|
|
2513 (princ
|
|
2514 (format "File A = %S\n" buffer-file-name))
|
|
2515 (princ
|
|
2516 (format "Buffer A = %S\n" (buffer-name)))))
|
|
2517 (ediff-eval-in-buffer ediff-buffer-B
|
|
2518 (if buffer-file-name
|
|
2519 (princ
|
|
2520 (format "File B = %S\n" buffer-file-name))
|
|
2521 (princ
|
|
2522 (format "Buffer B = %S\n" (buffer-name)))))
|
|
2523 (if ediff-3way-job
|
|
2524 (ediff-eval-in-buffer ediff-buffer-C
|
|
2525 (if buffer-file-name
|
|
2526 (princ
|
|
2527 (format "File C = %S\n" buffer-file-name))
|
|
2528 (princ
|
|
2529 (format "Buffer C = %S\n" (buffer-name))))))
|
|
2530 (princ (format "Customized diff output %s\n"
|
|
2531 (if (ediff-buffer-live-p ediff-custom-diff-buffer)
|
|
2532 (concat "\tin buffer "
|
|
2533 (buffer-name ediff-custom-diff-buffer))
|
|
2534 "is not available")))
|
|
2535 (princ (format "Plain diff output %s\n"
|
|
2536 (if (ediff-buffer-live-p ediff-diff-buffer)
|
|
2537 (concat "\tin buffer "
|
|
2538 (buffer-name ediff-diff-buffer))
|
|
2539 "is not available")))
|
|
2540
|
|
2541 (let* ((A-line (ediff-eval-in-buffer ediff-buffer-A
|
|
2542 (1+ (count-lines (point-min) (point)))))
|
|
2543 (B-line (ediff-eval-in-buffer ediff-buffer-B
|
|
2544 (1+ (count-lines (point-min) (point)))))
|
|
2545 C-line)
|
|
2546 (princ (format "\Buffer A's point is on line %d\n" A-line))
|
|
2547 (princ (format "Buffer B's point is on line %d\n" B-line))
|
|
2548 (if ediff-3way-job
|
|
2549 (progn
|
|
2550 (setq C-line (ediff-eval-in-buffer ediff-buffer-C
|
|
2551 (1+ (count-lines (point-min) (point)))))
|
|
2552 (princ (format "Buffer C's point is on line %d\n" C-line)))))
|
|
2553
|
|
2554 (princ (format "\nCurrent difference number = %S\n"
|
|
2555 (cond ((< ediff-current-difference 0) 'start)
|
|
2556 ((>= ediff-current-difference
|
|
2557 ediff-number-of-differences) 'end)
|
|
2558 (t (1+ ediff-current-difference)))))
|
|
2559
|
|
2560 (princ
|
|
2561 (format "\n%s regions that differ only in white space & line breaks"
|
|
2562 (if ediff-ignore-similar-regions
|
|
2563 "Skipping" "Not skipping")))
|
|
2564 (if (and ediff-merge-job ediff-show-clashes-only)
|
|
2565 (princ
|
|
2566 "\nFocusing on regions where both buffers differ from the ancestor"))
|
|
2567
|
|
2568 (cond ((eq ediff-skip-diff-region-function 'ediff-show-all-diffs)
|
|
2569 (princ "\nSelective browsing by regexp is off\n"))
|
|
2570 ((eq ediff-skip-diff-region-function
|
|
2571 ediff-hide-regexp-matches-function)
|
|
2572 (princ
|
|
2573 "\nIgnoring regions that match")
|
|
2574 (princ
|
|
2575 (format
|
|
2576 "\n\t regexp `%s' in buffer A %S\n\t regexp `%s' in buffer B\n"
|
|
2577 ediff-regexp-hide-A ediff-hide-regexp-connective
|
|
2578 ediff-regexp-hide-B)))
|
|
2579 ((eq ediff-skip-diff-region-function
|
|
2580 ediff-focus-on-regexp-matches-function)
|
|
2581 (princ
|
|
2582 "\nFocusing on regions that match")
|
|
2583 (princ
|
|
2584 (format
|
|
2585 "\n\t regexp `%s' in buffer A %S\n\t regexp `%s' in buffer B\n"
|
|
2586 ediff-regexp-focus-A ediff-focus-regexp-connective
|
|
2587 ediff-regexp-focus-B)))
|
|
2588 (t (princ "\nSelective browsing via a user-defined method.\n")))
|
|
2589
|
|
2590 (princ
|
|
2591 (format "\nBugs/suggestions: type `%s' while in Ediff Control Panel."
|
|
2592 (substitute-command-keys "\\[ediff-submit-report]")))
|
|
2593 ) ; with output
|
|
2594 (if (frame-live-p ediff-control-frame)
|
|
2595 (ediff-reset-mouse ediff-control-frame))
|
|
2596 (if (window-live-p ediff-control-window)
|
|
2597 (select-window ediff-control-window)))
|
|
2598
|
|
2599
|
|
2600
|
|
2601
|
|
2602 ;;; Support routines
|
|
2603
|
|
2604 ;; Select a difference by placing the ASCII flags around the appropriate
|
|
2605 ;; group of lines in the A, B buffers
|
|
2606 ;; This may have to be modified for buffer C, when it will be supported.
|
|
2607 (defun ediff-select-difference (n)
|
|
2608 (if (and (ediff-buffer-live-p ediff-buffer-A)
|
|
2609 (ediff-buffer-live-p ediff-buffer-B)
|
|
2610 (ediff-valid-difference-p n))
|
|
2611 (progn
|
|
2612 (if (and (ediff-has-face-support-p) ediff-use-faces)
|
|
2613 (progn
|
|
2614 (ediff-highlight-diff n)
|
|
2615 (setq ediff-highlighting-style 'face))
|
|
2616 (setq ediff-highlighting-style 'ascii)
|
|
2617 (ediff-place-flags-in-buffer
|
|
2618 'A ediff-buffer-A ediff-control-buffer n)
|
|
2619 (ediff-place-flags-in-buffer
|
|
2620 'B ediff-buffer-B ediff-control-buffer n)
|
|
2621 (if ediff-3way-job
|
|
2622 (ediff-place-flags-in-buffer
|
|
2623 'C ediff-buffer-C ediff-control-buffer n))
|
|
2624 (if (ediff-buffer-live-p ediff-ancestor-buffer)
|
|
2625 (ediff-place-flags-in-buffer
|
|
2626 'Ancestor ediff-ancestor-buffer
|
|
2627 ediff-control-buffer n))
|
|
2628 )
|
|
2629
|
|
2630 (ediff-install-fine-diff-if-necessary n)
|
|
2631 (run-hooks 'ediff-select-hook))))
|
|
2632
|
|
2633
|
|
2634 ;; Unselect a difference by removing the ASCII flags in the buffers.
|
|
2635 ;; This may have to be modified for buffer C, when it will be supported.
|
|
2636 (defun ediff-unselect-difference (n)
|
|
2637 (if (ediff-valid-difference-p n)
|
|
2638 (progn
|
|
2639 (cond ((and (ediff-has-face-support-p) ediff-use-faces)
|
|
2640 (ediff-unhighlight-diff))
|
|
2641 ((eq ediff-highlighting-style 'ascii)
|
|
2642 (ediff-remove-flags-from-buffer
|
|
2643 ediff-buffer-A
|
|
2644 (ediff-get-diff-overlay n 'A))
|
|
2645 (ediff-remove-flags-from-buffer
|
|
2646 ediff-buffer-B
|
|
2647 (ediff-get-diff-overlay n 'B))
|
|
2648 (if ediff-3way-job
|
|
2649 (ediff-remove-flags-from-buffer
|
|
2650 ediff-buffer-C
|
|
2651 (ediff-get-diff-overlay n 'C)))
|
|
2652 (if (ediff-buffer-live-p ediff-ancestor-buffer)
|
|
2653 (ediff-remove-flags-from-buffer
|
|
2654 ediff-ancestor-buffer
|
|
2655 (ediff-get-diff-overlay n 'Ancestor)))
|
|
2656 ))
|
|
2657 (setq ediff-highlighting-style nil)
|
|
2658
|
|
2659 ;; unhighlight fine diffs
|
|
2660 (ediff-set-fine-diff-properties ediff-current-difference 'default)
|
|
2661 (run-hooks 'ediff-unselect-hook))))
|
|
2662
|
|
2663
|
|
2664 ;; Unselects prev diff and selects a new one, if FLAG has value other than
|
|
2665 ;; 'select-only or 'unselect-only. If FLAG is 'select-only, the
|
|
2666 ;; next difference is selected, but the current selection is not
|
|
2667 ;; unselected. If FLAG is 'unselect-only then the current selection is
|
|
2668 ;; unselected, but the next one is not selected. If NO-RECENTER is non-nil,
|
|
2669 ;; don't recenter buffers after selecting/unselecting.
|
|
2670 (defun ediff-unselect-and-select-difference (n &optional flag no-recenter)
|
|
2671 (let ((ediff-current-difference n))
|
|
2672 (or no-recenter
|
|
2673 (ediff-recenter 'no-rehighlight)))
|
|
2674
|
|
2675 (let ((control-buf ediff-control-buffer))
|
|
2676 (unwind-protect
|
|
2677 (progn
|
|
2678 (or (eq flag 'select-only)
|
|
2679 (ediff-unselect-difference ediff-current-difference))
|
|
2680
|
|
2681 (or (eq flag 'unselect-only)
|
|
2682 (ediff-select-difference n))
|
|
2683 (setq ediff-current-difference n)
|
|
2684 ) ; end protected section
|
|
2685
|
78
|
2686 (ediff-eval-in-buffer control-buf (ediff-refresh-mode-lines))
|
0
|
2687 )))
|
|
2688
|
|
2689
|
|
2690 (defun ediff-read-file-name (prompt default-dir default-file)
|
|
2691 ; This is a modified version of a similar function in `emerge.el'.
|
|
2692 ; PROMPT should not have trailing ': ', so that it can be modified
|
|
2693 ; according to context.
|
|
2694 ; If default-file is set, it should be used as the default value.
|
|
2695 ; If default-dir is non-nil, use it as the default directory.
|
|
2696 ; Otherwise, use the value of Emacs' variable `default-directory.'
|
|
2697
|
|
2698 ;; hack default-dir if it is not set
|
|
2699 (setq default-dir
|
|
2700 (file-name-as-directory
|
|
2701 (ediff-abbreviate-file-name
|
|
2702 (expand-file-name (or default-dir
|
|
2703 (and default-file
|
|
2704 (file-name-directory default-file))
|
|
2705 default-directory)))))
|
|
2706
|
|
2707 ;; strip the directory from default-file
|
|
2708 (if default-file
|
|
2709 (setq default-file (file-name-nondirectory default-file)))
|
|
2710 (if (string= default-file "")
|
|
2711 (setq default-file nil))
|
|
2712
|
|
2713 (let (f)
|
|
2714 (setq f (expand-file-name
|
|
2715 (read-file-name
|
|
2716 (format "%s%s "
|
|
2717 prompt
|
|
2718 (cond (default-file
|
|
2719 (concat " (default " default-file "):"))
|
|
2720 (t (concat " (default " default-dir "):"))))
|
|
2721 default-dir
|
|
2722 (or default-file default-dir)
|
|
2723 t ; must match, no-confirm
|
|
2724 (if default-file (file-name-directory default-file))
|
|
2725 )
|
|
2726 default-dir
|
|
2727 ))
|
|
2728 ;; If user enters a directory name, expand the default file in that
|
|
2729 ;; directory. This allows the user to enter a directory name for the
|
|
2730 ;; B-file and diff against the default-file in that directory instead
|
|
2731 ;; of a DIRED listing!
|
|
2732 (if (and (file-directory-p f) default-file)
|
|
2733 (setq f (expand-file-name
|
|
2734 (file-name-nondirectory default-file) f)))
|
|
2735 f))
|
|
2736
|
|
2737 ;; If PREFIX is given, then it is used as a prefix for the temp file
|
|
2738 ;; name. Otherwise, `ediff_' is used. If FILE is given, use this
|
|
2739 ;; file and don't create a new one.
|
|
2740 ;; On MS-DOS, make sure the prefix isn't longer than 7 characters, or
|
|
2741 ;; else `make-temp-name' isn't guaranteed to return a unique filename.
|
|
2742 ;; Also, save buffer from START to END in the file.
|
|
2743 ;; START defaults to (point-min), END to (point-max)
|
|
2744 (defun ediff-make-temp-file (buff &optional prefix given-file start end)
|
|
2745 (let ((p (or prefix "ediff"))
|
|
2746 f)
|
|
2747 (if (and (eq system-type 'ms-dos) (> (length p) 7))
|
|
2748 (setq p (substring p 0 7)))
|
|
2749
|
|
2750 (setq f (concat ediff-temp-file-prefix p)
|
|
2751 f (cond (given-file)
|
|
2752 ((find-file-name-handler f 'find-file-noselect)
|
|
2753 ;; to thwart file handlers in write-region, e.g., if file
|
|
2754 ;; name ends with .Z or .gz
|
|
2755 ;; This is needed so that patches produced by ediff will
|
|
2756 ;; have more meaningful names
|
|
2757 (make-temp-name f))
|
|
2758 ;; Prefix is most often the same as the file name for the
|
|
2759 ;; variant. Here we are trying to use the original file name
|
|
2760 ;; but in the temp directory.
|
|
2761 ((and prefix (not (file-exists-p f))) f)
|
|
2762 ;; If a file with the orig name exists, add some random stuff
|
|
2763 ;; to it.
|
|
2764 (t (make-temp-name f))))
|
|
2765
|
|
2766 ;; create the file
|
|
2767 (ediff-eval-in-buffer buff
|
|
2768 (write-region (if start start (point-min))
|
|
2769 (if end end (point-max))
|
|
2770 f
|
|
2771 nil ; don't append---erase
|
|
2772 'no-message)
|
|
2773 (set-file-modes f ediff-temp-file-mode)
|
78
|
2774 (ediff-convert-standard-filename (expand-file-name f)))))
|
0
|
2775
|
|
2776 ;; Quote metacharacters (using \) when executing diff in Unix, but not in
|
|
2777 ;; EMX OS/2
|
|
2778 ;;(defun ediff-protect-metachars (str)
|
|
2779 ;; (or (memq system-type '(emx vax-vms axp-vms))
|
|
2780 ;; (let ((limit 0))
|
|
2781 ;; (while (string-match ediff-metachars str limit)
|
|
2782 ;; (setq str (concat (substring str 0 (match-beginning 0))
|
|
2783 ;; "\\"
|
|
2784 ;; (substring str (match-beginning 0))))
|
|
2785 ;; (setq limit (1+ (match-end 0))))))
|
|
2786 ;; str)
|
|
2787
|
|
2788 ;; Make sure the current buffer (for a file) has the same contents as the
|
|
2789 ;; file on disk, and attempt to remedy the situation if not.
|
|
2790 ;; Signal an error if we can't make them the same, or the user doesn't want
|
|
2791 ;; to do what is necessary to make them the same.
|
|
2792 ;; Also, Ediff always offers to revert obsolete buffers, whether they
|
|
2793 ;; are modified or not.
|
|
2794 (defun ediff-verify-file-buffer (&optional file-magic)
|
|
2795 ;; First check if the file has been modified since the buffer visited it.
|
|
2796 (if (verify-visited-file-modtime (current-buffer))
|
|
2797 (if (buffer-modified-p)
|
|
2798 ;; If buffer is not obsolete and is modified, offer to save
|
|
2799 (if (yes-or-no-p
|
|
2800 (format "Buffer out of sync with visited file. Save file %s? "
|
|
2801 buffer-file-name))
|
|
2802 (condition-case nil
|
|
2803 (save-buffer)
|
|
2804 (error
|
|
2805 (beep)
|
|
2806 (message "Couldn't save %s" buffer-file-name)))
|
|
2807 (error "Buffer is out of sync for file %s" buffer-file-name))
|
|
2808 ;; If buffer is not obsolete and is not modified, do nothing
|
|
2809 nil)
|
|
2810 ;; If buffer is obsolete, offer to revert
|
|
2811 (if (yes-or-no-p
|
|
2812 (format "Buffer is out of sync with visited file. REVERT file %s? "
|
|
2813 buffer-file-name))
|
|
2814 (progn
|
|
2815 (if file-magic
|
|
2816 (erase-buffer))
|
|
2817 (revert-buffer t t))
|
|
2818 (error "Buffer out of sync for file %s" buffer-file-name))))
|
|
2819
|
|
2820
|
|
2821 (defun ediff-save-buffer (arg)
|
|
2822 "Safe way of saving buffers A, B, C, and the diff output.
|
|
2823 `wa' saves buffer A, `wb' saves buffer B, `wc' saves buffer C,
|
|
2824 and `wd' saves the diff output.
|
|
2825
|
|
2826 With prefix argument, `wd' saves plain diff output.
|
|
2827 Without an argument, it saves customized diff argument, if available
|
|
2828 \(and plain output, if customized output was not generated\)."
|
|
2829 (interactive "P")
|
|
2830 (ediff-barf-if-not-control-buffer)
|
|
2831 (ediff-compute-custom-diffs-maybe)
|
|
2832 (ediff-eval-in-buffer
|
|
2833 (cond ((memq last-command-char '(?a ?b ?c))
|
|
2834 (ediff-get-buffer
|
|
2835 (ediff-char-to-buftype last-command-char)))
|
|
2836 ((eq last-command-char ?d)
|
|
2837 (message "Saving diff output ...")
|
|
2838 (sit-for 1) ; let the user see the message
|
|
2839 (cond ((and arg (ediff-buffer-live-p ediff-diff-buffer))
|
|
2840 ediff-diff-buffer)
|
|
2841 ((ediff-buffer-live-p ediff-custom-diff-buffer)
|
|
2842 ediff-custom-diff-buffer)
|
|
2843 ((ediff-buffer-live-p ediff-diff-buffer)
|
|
2844 ediff-diff-buffer)
|
|
2845 (t (error "Output from `diff' not found"))))
|
|
2846 )
|
|
2847 (save-buffer)))
|
|
2848
|
|
2849 (defun ediff-compute-custom-diffs-maybe ()
|
|
2850 (let ((buf-A-file-name (buffer-file-name ediff-buffer-A))
|
|
2851 (buf-B-file-name (buffer-file-name ediff-buffer-B))
|
|
2852 file-A file-B)
|
|
2853 (if (stringp buf-A-file-name)
|
|
2854 (setq buf-A-file-name (file-name-nondirectory buf-A-file-name)))
|
|
2855 (if (stringp buf-B-file-name)
|
|
2856 (setq buf-B-file-name (file-name-nondirectory buf-B-file-name)))
|
|
2857 (setq file-A (ediff-make-temp-file ediff-buffer-A buf-A-file-name)
|
|
2858 file-B (ediff-make-temp-file ediff-buffer-B buf-B-file-name))
|
|
2859
|
|
2860 (or (ediff-buffer-live-p ediff-custom-diff-buffer)
|
|
2861 (setq ediff-custom-diff-buffer
|
|
2862 (get-buffer-create
|
|
2863 (ediff-unique-buffer-name "*ediff-custom-diff" "*"))))
|
|
2864 (ediff-exec-process
|
|
2865 ediff-custom-diff-program ediff-custom-diff-buffer 'synchronize
|
|
2866 ediff-custom-diff-options file-A file-B)
|
|
2867 (delete-file file-A)
|
|
2868 (delete-file file-B)
|
|
2869 ))
|
|
2870
|
|
2871 (defun ediff-show-diff-output (arg)
|
|
2872 (interactive "P")
|
|
2873 (ediff-barf-if-not-control-buffer)
|
|
2874 (ediff-compute-custom-diffs-maybe)
|
|
2875 (save-excursion
|
|
2876 (ediff-skip-unsuitable-frames ' ok-unsplittable))
|
|
2877 (let ((buf (cond ((and arg (ediff-buffer-live-p ediff-diff-buffer))
|
|
2878 ediff-diff-buffer)
|
|
2879 ((ediff-buffer-live-p ediff-custom-diff-buffer)
|
|
2880 ediff-custom-diff-buffer)
|
|
2881 ((ediff-buffer-live-p ediff-diff-buffer)
|
|
2882 ediff-diff-buffer)
|
|
2883 (t
|
|
2884 (beep)
|
|
2885 (message "Output from `diff' not found")
|
|
2886 nil))))
|
|
2887 (if buf
|
|
2888 (progn
|
|
2889 (ediff-eval-in-buffer buf
|
|
2890 (goto-char (point-min)))
|
|
2891 (switch-to-buffer buf)
|
|
2892 (raise-frame (selected-frame)))))
|
|
2893 (if (frame-live-p ediff-control-frame)
|
|
2894 (ediff-reset-mouse ediff-control-frame))
|
|
2895 (if (window-live-p ediff-control-window)
|
|
2896 (select-window ediff-control-window)))
|
78
|
2897
|
|
2898
|
|
2899 (defun ediff-inferior-compare-regions ()
|
|
2900 "Compare regions in an active Ediff session.
|
|
2901 Like ediff-regions-linewise but is called from under an active Ediff session on
|
|
2902 the files that belong to that session.
|
|
2903
|
|
2904 After quitting the session invoked via this function, type C-l to the parent
|
|
2905 Ediff Control Panel to restore highlighting."
|
|
2906 (interactive)
|
|
2907 (let ((answer "")
|
|
2908 (possibilities (list ?A ?B ?C))
|
|
2909 (zmacs-regions t)
|
|
2910 quit-now
|
|
2911 begA begB endA endB bufA bufB)
|
|
2912
|
|
2913 (cond ((ediff-merge-job)
|
|
2914 (setq bufB ediff-buffer-C)
|
|
2915 (while (cond ((memq answer '(?A ?a))
|
|
2916 (setq bufA ediff-buffer-A)
|
|
2917 nil)
|
|
2918 ((memq answer '(?B ?b))
|
|
2919 (setq bufA ediff-buffer-B)
|
|
2920 nil)
|
|
2921 ((equal answer ""))
|
|
2922 (t (beep 1)
|
|
2923 (message "Valid values are A or B")
|
|
2924 (sit-for 2)
|
|
2925 t))
|
|
2926 (let ((cursor-in-echo-area t))
|
|
2927 (message "Which buffer to compare to the merge buffer (A/B)? ")
|
|
2928 (setq answer (read-char-exclusive)))))
|
|
2929
|
|
2930 ((ediff-3way-comparison-job)
|
|
2931 (while (cond ((memq answer possibilities)
|
|
2932 (setq possibilities (delq answer possibilities))
|
|
2933 (setq bufA
|
|
2934 (eval
|
|
2935 (intern (format "ediff-buffer-%c" answer))))
|
|
2936 nil)
|
|
2937 ((equal answer ""))
|
|
2938 (t (beep 1)
|
|
2939 (message
|
|
2940 "Valid values are %s"
|
|
2941 (mapconcat 'char-to-string possibilities " or "))
|
|
2942 (sit-for 2)
|
|
2943 t))
|
|
2944 (let ((cursor-in-echo-area t))
|
|
2945 (message "Enter the 1st buffer you want to compare (%s): "
|
|
2946 (mapconcat 'char-to-string possibilities "/"))
|
|
2947 (setq answer (capitalize (read-char-exclusive)))))
|
|
2948 (setq answer "") ; silence error msg
|
|
2949 (while (cond ((memq answer possibilities)
|
|
2950 (setq possibilities (delq answer possibilities))
|
|
2951 (setq bufB
|
|
2952 (eval
|
|
2953 (intern (format "ediff-buffer-%c" answer))))
|
|
2954 nil)
|
|
2955 ((equal answer ""))
|
|
2956 (t (beep 1)
|
|
2957 (message
|
|
2958 "Valid values are %s"
|
|
2959 (mapconcat 'char-to-string possibilities " or "))
|
|
2960 (sit-for 2)
|
|
2961 t))
|
|
2962 (let ((cursor-in-echo-area t))
|
|
2963 (message "Enter the 2nd buffer you want to compare (%s): "
|
|
2964 (mapconcat 'char-to-string possibilities "/"))
|
|
2965 (setq answer (capitalize (read-char-exclusive))))))
|
|
2966 (t ; 2way comparison
|
|
2967 (setq bufA ediff-buffer-A
|
|
2968 bufB ediff-buffer-B)))
|
|
2969
|
|
2970 (ediff-eval-in-buffer bufA
|
|
2971 (or (mark t)
|
|
2972 (error "You forgot to specify a region in buffer %s" (buffer-name)))
|
|
2973 (setq begA (region-beginning)
|
|
2974 endA (region-end))
|
|
2975 (goto-char begA)
|
|
2976 (beginning-of-line)
|
|
2977 (setq begA (point))
|
|
2978 (goto-char endA)
|
|
2979 (end-of-line)
|
|
2980 (or (eobp) (forward-char)) ; include the newline char
|
|
2981 (setq endA (point)))
|
|
2982 (ediff-eval-in-buffer bufB
|
|
2983 (or (mark t)
|
|
2984 (error "You forgot to specify a region in buffer %s" (buffer-name)))
|
|
2985 (setq begB (region-beginning)
|
|
2986 endB (region-end))
|
|
2987 (goto-char begB)
|
|
2988 (beginning-of-line)
|
|
2989 (setq begB (point))
|
|
2990 (goto-char endB)
|
|
2991 (end-of-line)
|
|
2992 (or (eobp) (forward-char)) ; include the newline char
|
|
2993 (setq endB (point)))
|
|
2994
|
|
2995 (ediff-unselect-and-select-difference
|
|
2996 ediff-current-difference 'unselect-only)
|
|
2997 (ediff-paint-background-regions 'unhighlight)
|
|
2998
|
|
2999 (ediff-eval-in-buffer bufA
|
|
3000 (goto-char begA)
|
|
3001 (set-mark endA)
|
|
3002 (narrow-to-region begA endA)
|
|
3003 ;; (ediff-activate-mark)
|
|
3004 )
|
|
3005 ;; (sit-for 0)
|
|
3006 (ediff-eval-in-buffer bufB
|
|
3007 (goto-char begB)
|
|
3008 (set-mark endB)
|
|
3009 (narrow-to-region begB endB)
|
|
3010 ;; (ediff-activate-mark)
|
|
3011 )
|
|
3012 ;; (sit-for 0)
|
14
|
3013
|
78
|
3014 (or (y-or-n-p
|
|
3015 "Please check the selected regions. Continue? ")
|
|
3016 (setq quit-now t))
|
|
3017
|
|
3018 (ediff-eval-in-buffer bufA
|
|
3019 (widen))
|
|
3020 (ediff-eval-in-buffer bufB
|
|
3021 (widen))
|
|
3022 (if quit-now
|
|
3023 (error "Thank you. Come back another day..."))
|
12
|
3024
|
78
|
3025 (ediff-regions-internal
|
|
3026 bufA begA endA bufB begB endB
|
|
3027 nil ; startup hook
|
|
3028 'ediff-regions-linewise ; job name
|
|
3029 nil) ; no word mode
|
|
3030 ))
|
|
3031
|
|
3032
|
|
3033
|
0
|
3034 (defun ediff-remove-flags-from-buffer (buffer overlay)
|
|
3035 (ediff-eval-in-buffer buffer
|
|
3036 (let ((inhibit-read-only t))
|
|
3037 (if ediff-xemacs-p
|
|
3038 (ediff-overlay-put overlay 'begin-glyph nil)
|
|
3039 (ediff-overlay-put overlay 'before-string nil))
|
|
3040
|
|
3041 (if ediff-xemacs-p
|
|
3042 (ediff-overlay-put overlay 'end-glyph nil)
|
|
3043 (ediff-overlay-put overlay 'after-string nil))
|
|
3044 )))
|
|
3045
|
|
3046
|
|
3047
|
|
3048 (defun ediff-place-flags-in-buffer (buf-type buffer ctl-buffer diff)
|
|
3049 (ediff-eval-in-buffer buffer
|
|
3050 (ediff-place-flags-in-buffer1 buf-type ctl-buffer diff)))
|
|
3051
|
|
3052
|
|
3053 (defun ediff-place-flags-in-buffer1 (buf-type ctl-buffer diff-no)
|
|
3054 (let* ((curr-overl (ediff-eval-in-buffer ctl-buffer
|
|
3055 (ediff-get-diff-overlay diff-no buf-type)))
|
|
3056 (before (ediff-get-diff-posn buf-type 'beg diff-no ctl-buffer))
|
|
3057 after beg-of-line flag)
|
|
3058
|
|
3059 ;; insert flag before the difference
|
|
3060 (goto-char before)
|
|
3061 (setq beg-of-line (bolp))
|
|
3062
|
|
3063 (setq flag (ediff-eval-in-buffer ctl-buffer
|
|
3064 (if (eq ediff-highlighting-style 'ascii)
|
|
3065 (if beg-of-line
|
|
3066 ediff-before-flag-bol ediff-before-flag-mol))))
|
|
3067
|
|
3068 ;; insert the flag itself
|
|
3069 (if ediff-xemacs-p
|
|
3070 (ediff-overlay-put curr-overl 'begin-glyph flag)
|
|
3071 (ediff-overlay-put curr-overl 'before-string flag))
|
|
3072
|
|
3073 ;; insert the flag after the difference
|
|
3074 ;; `after' must be set here, after the before-flag was inserted
|
|
3075 (setq after (ediff-get-diff-posn buf-type 'end diff-no ctl-buffer))
|
|
3076 (goto-char after)
|
|
3077 (setq beg-of-line (bolp))
|
|
3078
|
|
3079 (setq flag (ediff-eval-in-buffer ctl-buffer
|
|
3080 (if (eq ediff-highlighting-style 'ascii)
|
|
3081 (if beg-of-line
|
|
3082 ediff-after-flag-eol ediff-after-flag-mol))))
|
|
3083
|
|
3084 ;; insert the flag itself
|
|
3085 (if ediff-xemacs-p
|
|
3086 (ediff-overlay-put curr-overl 'end-glyph flag)
|
|
3087 (ediff-overlay-put curr-overl 'after-string flag))
|
|
3088 ))
|
|
3089
|
|
3090
|
|
3091 ;; Returns positions of difference sectors in the BUF-TYPE buffer.
|
|
3092 ;; BUF-TYPE should be a symbol -- `A', `B', or `C'.
|
|
3093 ;; POS is either `beg' or `end'--it specifies whether you want the position at
|
|
3094 ;; the beginning of a difference or at the end.
|
|
3095 ;;
|
|
3096 ;; The optional argument N says which difference (default:
|
|
3097 ;; `ediff-current-difference'). N is the internal difference number (1- what
|
|
3098 ;; the user sees). The optional argument CONTROL-BUF says
|
|
3099 ;; which control buffer is in effect in case it is not the current
|
|
3100 ;; buffer.
|
|
3101 (defun ediff-get-diff-posn (buf-type pos &optional n control-buf)
|
|
3102 (let (diff-overlay)
|
|
3103 (or control-buf
|
|
3104 (setq control-buf (current-buffer)))
|
|
3105
|
|
3106 (ediff-eval-in-buffer control-buf
|
|
3107 (or n (setq n ediff-current-difference))
|
|
3108 (if (or (< n 0) (>= n ediff-number-of-differences))
|
|
3109 (if (> ediff-number-of-differences 0)
|
|
3110 (error ediff-BAD-DIFF-NUMBER
|
|
3111 this-command (1+ n) ediff-number-of-differences)
|
|
3112 (error ediff-NO-DIFFERENCES)))
|
|
3113 (setq diff-overlay (ediff-get-diff-overlay n buf-type)))
|
|
3114 (if (not (ediff-buffer-live-p (ediff-overlay-buffer diff-overlay)))
|
|
3115 (error ediff-KILLED-VITAL-BUFFER))
|
|
3116 (if (eq pos 'beg)
|
|
3117 (ediff-overlay-start diff-overlay)
|
|
3118 (ediff-overlay-end diff-overlay))
|
|
3119 ))
|
|
3120
|
|
3121
|
78
|
3122 ;; Restore highlighting to what it should be according to ediff-use-faces,
|
|
3123 ;; ediff-highlighting-style, and ediff-highlight-all-diffs variables.
|
|
3124 (defun ediff-restore-highlighting (&optional ctl-buf)
|
|
3125 (ediff-eval-in-buffer (or ctl-buf (current-buffer))
|
|
3126 (if (and (ediff-has-face-support-p)
|
|
3127 ediff-use-faces
|
|
3128 ediff-highlight-all-diffs)
|
|
3129 (ediff-paint-background-regions))
|
|
3130 (ediff-select-difference ediff-current-difference)))
|
0
|
3131
|
|
3132
|
|
3133
|
|
3134 ;; null out difference overlays so they won't slow down future
|
|
3135 ;; editing operations
|
|
3136 ;; VEC is either a difference vector or a fine-diff vector
|
|
3137 (defun ediff-clear-diff-vector (vec-var &optional fine-diffs-also)
|
|
3138 (if (vectorp (symbol-value vec-var))
|
|
3139 (mapcar (function
|
|
3140 (lambda (elt)
|
|
3141 (ediff-delete-overlay
|
|
3142 (ediff-get-diff-overlay-from-diff-record elt))
|
|
3143 (if fine-diffs-also
|
|
3144 (ediff-clear-fine-diff-vector elt))
|
|
3145 ))
|
|
3146 (symbol-value vec-var)))
|
|
3147 ;; allow them to be garbage collected
|
|
3148 (set vec-var nil))
|
|
3149
|
|
3150
|
|
3151
|
|
3152 ;;; Misc
|
|
3153
|
|
3154 ;; In Emacs, this just makes overlay. In the future, when Emacs will start
|
|
3155 ;; supporting sticky overlays, this function will make a sticky overlay.
|
|
3156 ;; BEG and END are expressions telling where overlay starts.
|
|
3157 ;; If they are numbers or buffers, then all is well. Otherwise, they must
|
|
3158 ;; be expressions to be evaluated in buffer BUF in order to get the overlay
|
|
3159 ;; bounds.
|
|
3160 ;; If BUFF is not a live buffer, then return nil; otherwise, return the
|
|
3161 ;; newly created overlay.
|
|
3162 (defun ediff-make-bullet-proof-overlay (beg end buff)
|
|
3163 (if (ediff-buffer-live-p buff)
|
|
3164 (let (overl)
|
|
3165 (ediff-eval-in-buffer buff
|
|
3166 (or (number-or-marker-p beg)
|
|
3167 (setq beg (eval beg)))
|
|
3168 (or (number-or-marker-p end)
|
|
3169 (setq end (eval end)))
|
|
3170 (setq overl
|
|
3171 (if ediff-xemacs-p
|
|
3172 (make-extent beg end buff)
|
|
3173 ;; advance front and rear of the overlay
|
|
3174 (make-overlay beg end buff nil 'rear-advance)))
|
|
3175
|
|
3176 ;; never detach
|
|
3177 (ediff-overlay-put
|
|
3178 overl (if ediff-emacs-p 'evaporate 'detachable) nil)
|
|
3179 ;; make vip-minibuffer-overlay open-ended
|
|
3180 ;; In emacs, it is made open ended at creation time
|
|
3181 (if ediff-xemacs-p
|
|
3182 (progn
|
|
3183 (ediff-overlay-put overl 'start-open nil)
|
|
3184 (ediff-overlay-put overl 'end-open nil)))
|
|
3185 (ediff-overlay-put overl 'ediff-diff-num 0)
|
|
3186 overl))))
|
|
3187
|
70
|
3188 (defsubst ediff-overlay-start (overl)
|
|
3189 (if (ediff-overlayp overl)
|
|
3190 (if ediff-emacs-p
|
|
3191 (overlay-start overl)
|
|
3192 (extent-start-position overl))))
|
|
3193
|
|
3194 (defsubst ediff-overlay-end (overl)
|
|
3195 (if (ediff-overlayp overl)
|
|
3196 (if ediff-emacs-p
|
|
3197 (overlay-end overl)
|
|
3198 (extent-end-position overl))))
|
|
3199
|
0
|
3200
|
|
3201 ;; Like other-buffer, but prefers visible buffers and ignores temporary or
|
|
3202 ;; other insignificant buffers (those beginning with "^[ *]").
|
|
3203 ;; Gets one arg--buffer name or a list of buffer names (it won't return
|
|
3204 ;; these buffers).
|
|
3205 (defun ediff-other-buffer (buff)
|
|
3206 (if (not (listp buff)) (setq buff (list buff)))
|
|
3207 (let* ((frame-buffers (buffer-list))
|
|
3208 (significant-buffers
|
|
3209 (mapcar
|
|
3210 (function (lambda (x)
|
|
3211 (cond ((member (buffer-name x) buff)
|
|
3212 nil)
|
|
3213 ((not (ediff-get-visible-buffer-window x))
|
|
3214 nil)
|
|
3215 ((string-match "^ " (buffer-name x))
|
|
3216 nil)
|
|
3217 (t x))))
|
|
3218 frame-buffers))
|
|
3219 (buffers (delq nil significant-buffers))
|
|
3220 less-significant-buffers)
|
|
3221
|
|
3222 (cond (buffers (car buffers))
|
|
3223 ;; try also buffers that are not displayed in windows
|
|
3224 ((setq less-significant-buffers
|
|
3225 (delq nil
|
|
3226 (mapcar
|
|
3227 (function
|
|
3228 (lambda (x)
|
|
3229 (cond ((member (buffer-name x) buff) nil)
|
|
3230 ((string-match "^[ *]" (buffer-name x)) nil)
|
|
3231 (t x))))
|
|
3232 frame-buffers)))
|
|
3233 (car less-significant-buffers))
|
|
3234 (t (other-buffer (current-buffer))))
|
|
3235 ))
|
|
3236
|
|
3237
|
|
3238 ;; Construct a unique buffer name.
|
|
3239 ;; The first one tried is prefixsuffix, then prefix<2>suffix,
|
|
3240 ;; prefix<3>suffix, etc.
|
|
3241 (defun ediff-unique-buffer-name (prefix suffix)
|
|
3242 (if (null (get-buffer (concat prefix suffix)))
|
|
3243 (concat prefix suffix)
|
|
3244 (let ((n 2))
|
|
3245 (while (get-buffer (format "%s<%d>%s" prefix n suffix))
|
|
3246 (setq n (1+ n)))
|
|
3247 (format "%s<%d>%s" prefix n suffix))))
|
|
3248
|
|
3249
|
|
3250 ;; splits at a white space, returns a list
|
|
3251 (defun ediff-split-string (string)
|
|
3252 (let ((start 0)
|
|
3253 (result '())
|
|
3254 substr)
|
|
3255 (while (string-match "[ \t]+" string start)
|
|
3256 (let ((match (string-match "[ \t]+" string start)))
|
|
3257 (setq substr (substring string start match))
|
|
3258 (if (> (length substr) 0)
|
|
3259 (setq result (cons substr result)))
|
|
3260 (setq start (match-end 0))))
|
|
3261 (setq substr (substring string start nil))
|
|
3262 (if (> (length substr) 0)
|
|
3263 (setq result (cons substr result)))
|
|
3264 (nreverse result)))
|
|
3265
|
|
3266 (defun ediff-submit-report ()
|
|
3267 "Submit bug report on Ediff."
|
|
3268 (interactive)
|
|
3269 (ediff-barf-if-not-control-buffer)
|
|
3270 (let ((reporter-prompt-for-summary-p t)
|
|
3271 (ctl-buf ediff-control-buffer)
|
|
3272 (ediff-device-type (ediff-device-type))
|
|
3273 varlist salutation buffer-name)
|
|
3274 (setq varlist '(ediff-diff-program ediff-diff-options
|
|
3275 ediff-patch-program ediff-patch-options
|
|
3276 ediff-shell
|
|
3277 ediff-use-faces
|
|
3278 ediff-auto-refine ediff-highlighting-style
|
|
3279 ediff-buffer-A ediff-buffer-B ediff-control-buffer
|
|
3280 ediff-forward-word-function
|
|
3281 ediff-control-frame
|
|
3282 ediff-control-frame-parameters
|
|
3283 ediff-control-frame-position-function
|
|
3284 ediff-prefer-iconified-control-frame
|
|
3285 ediff-window-setup-function
|
|
3286 ediff-split-window-function
|
|
3287 ediff-job-name
|
|
3288 ediff-word-mode
|
|
3289 buffer-name
|
|
3290 ediff-device-type
|
|
3291 ))
|
|
3292 (setq salutation "
|
|
3293 Congratulations! You may have unearthed a bug in Ediff!
|
|
3294
|
|
3295 Please make a concise and accurate summary of what happened
|
|
3296 and mail it to the address above.
|
|
3297 -----------------------------------------------------------
|
|
3298 ")
|
|
3299
|
|
3300 (ediff-skip-unsuitable-frames)
|
|
3301 (ediff-reset-mouse)
|
|
3302
|
|
3303 (switch-to-buffer ediff-msg-buffer)
|
|
3304 (erase-buffer)
|
|
3305 (delete-other-windows)
|
|
3306 (insert "
|
|
3307 Please read this first:
|
|
3308 ----------------------
|
|
3309
|
|
3310 Some ``bugs'' may actually be no bugs at all. For instance, if you are
|
|
3311 reporting that certain difference regions are not matched as you think they
|
|
3312 should, this is most likely due to the way Unix diff program decides what
|
|
3313 constitutes a difference region. Ediff is an Emacs interface to diff, and
|
|
3314 it has nothing to do with those decisions---it only takes the output from
|
|
3315 diff and presents it in a way that is better suited for human browsing and
|
|
3316 manipulation.
|
|
3317
|
|
3318 If Emacs happens to dump core, this is NOT an Ediff problem---it is
|
|
3319 an Emacs bug. Report this to Emacs maintainers.
|
|
3320
|
|
3321 Another popular topic for reports is compilation messages. Because Ediff
|
|
3322 interfaces to several other packages and runs under Emacs and XEmacs,
|
|
3323 byte-compilation may produce output like this:
|
|
3324
|
|
3325 While compiling toplevel forms in file ediff.el:
|
|
3326 ** reference to free variable pm-color-alist
|
|
3327 ........................
|
|
3328 While compiling the end of the data:
|
|
3329 ** The following functions are not known to be defined:
|
|
3330 ediff-valid-color-p, ediff-set-face,
|
|
3331 ........................
|
|
3332
|
|
3333 These are NOT errors, but inevitable warnings, which ought to be ignored.
|
|
3334
|
|
3335 Please do not report those and similar things. However, comments and
|
|
3336 suggestions are always welcome.
|
|
3337
|
|
3338 Mail anyway? (y or n) ")
|
|
3339
|
|
3340 (if (y-or-n-p "Mail anyway? ")
|
|
3341 (progn
|
|
3342 (if (ediff-buffer-live-p ctl-buf)
|
|
3343 (set-buffer ctl-buf))
|
|
3344 (setq buffer-name (buffer-name))
|
|
3345 (require 'reporter)
|
|
3346 (reporter-submit-bug-report "kifer@cs.sunysb.edu"
|
|
3347 (ediff-version)
|
|
3348 varlist
|
|
3349 nil
|
|
3350 'delete-other-windows
|
|
3351 salutation))
|
|
3352 (bury-buffer)
|
|
3353 (beep 1)(message "Bug report aborted")
|
|
3354 (if (ediff-buffer-live-p ctl-buf)
|
|
3355 (ediff-eval-in-buffer ctl-buf
|
|
3356 (ediff-recenter 'no-rehighlight))))
|
|
3357 ))
|
|
3358
|
|
3359
|
|
3360 (defun ediff-deactivate-mark ()
|
|
3361 (if ediff-xemacs-p
|
|
3362 (zmacs-deactivate-region)
|
|
3363 (deactivate-mark)))
|
78
|
3364 (defun ediff-activate-mark ()
|
|
3365 (if ediff-emacs-p
|
|
3366 (setq mark-active t)
|
|
3367 (zmacs-activate-region)))
|
0
|
3368
|
|
3369 (cond ((fboundp 'nuke-selective-display)
|
|
3370 ;; XEmacs 19.12 has nuke-selective-display
|
|
3371 (fset 'ediff-nuke-selective-display 'nuke-selective-display))
|
|
3372 (t
|
|
3373 (defun ediff-nuke-selective-display ()
|
|
3374 (save-excursion
|
|
3375 (save-restriction
|
|
3376 (widen)
|
|
3377 (goto-char (point-min))
|
|
3378 (let ((mod-p (buffer-modified-p))
|
|
3379 buffer-read-only end)
|
|
3380 (and (eq t selective-display)
|
|
3381 (while (search-forward "\^M" nil t)
|
|
3382 (end-of-line)
|
|
3383 (setq end (point))
|
|
3384 (beginning-of-line)
|
|
3385 (while (search-forward "\^M" end t)
|
|
3386 (delete-char -1)
|
|
3387 (insert "\^J"))))
|
|
3388 (set-buffer-modified-p mod-p)
|
|
3389 (setq selective-display nil)))))
|
|
3390 ))
|
|
3391
|
|
3392
|
|
3393 ;; The next two are modified versions from emerge.el.
|
|
3394 ;; VARS must be a list of symbols
|
|
3395 ;; ediff-save-variables returns an association list: ((var . val) ...)
|
|
3396 (defsubst ediff-save-variables (vars)
|
|
3397 (mapcar (function (lambda (v) (cons v (symbol-value v))))
|
|
3398 vars))
|
|
3399 ;; VARS is a list of variable symbols.
|
|
3400 (defun ediff-restore-variables (vars assoc-list)
|
|
3401 (while vars
|
|
3402 (set (car vars) (cdr (assoc (car vars) assoc-list)))
|
|
3403 (setq vars (cdr vars))))
|
|
3404
|
|
3405 (defun ediff-change-saved-variable (var value buf-type)
|
|
3406 (let* ((assoc-list
|
|
3407 (symbol-value (intern
|
|
3408 (concat "ediff-buffer-values-orig-"
|
|
3409 (symbol-name buf-type)))))
|
|
3410 (assoc-elt (assoc var assoc-list)))
|
|
3411 (if assoc-elt
|
|
3412 (setcdr assoc-elt value))))
|
|
3413
|
|
3414
|
|
3415 ;; must execute in control buf
|
|
3416 (defun ediff-save-protected-variables ()
|
|
3417 (setq ediff-buffer-values-orig-A
|
|
3418 (ediff-eval-in-buffer ediff-buffer-A
|
|
3419 (ediff-save-variables ediff-protected-variables)))
|
|
3420 (setq ediff-buffer-values-orig-B
|
|
3421 (ediff-eval-in-buffer ediff-buffer-B
|
|
3422 (ediff-save-variables ediff-protected-variables)))
|
|
3423 (if ediff-3way-comparison-job
|
|
3424 (setq ediff-buffer-values-orig-C
|
|
3425 (ediff-eval-in-buffer ediff-buffer-C
|
|
3426 (ediff-save-variables ediff-protected-variables))))
|
|
3427 (if (ediff-buffer-live-p ediff-ancestor-buffer)
|
|
3428 (setq ediff-buffer-values-orig-Ancestor
|
|
3429 (ediff-eval-in-buffer ediff-ancestor-buffer
|
|
3430 (ediff-save-variables ediff-protected-variables)))))
|
|
3431
|
|
3432 ;; must execute in control buf
|
|
3433 (defun ediff-restore-protected-variables ()
|
|
3434 (let ((values-A ediff-buffer-values-orig-A)
|
|
3435 (values-B ediff-buffer-values-orig-B)
|
|
3436 (values-C ediff-buffer-values-orig-C)
|
|
3437 (values-Ancestor ediff-buffer-values-orig-Ancestor))
|
|
3438 (ediff-eval-in-buffer ediff-buffer-A
|
|
3439 (ediff-restore-variables ediff-protected-variables values-A))
|
|
3440 (ediff-eval-in-buffer ediff-buffer-B
|
|
3441 (ediff-restore-variables ediff-protected-variables values-B))
|
|
3442 (if ediff-3way-comparison-job
|
|
3443 (ediff-eval-in-buffer ediff-buffer-C
|
|
3444 (ediff-restore-variables ediff-protected-variables values-C)))
|
|
3445 (if (ediff-buffer-live-p ediff-ancestor-buffer)
|
|
3446 (ediff-eval-in-buffer ediff-ancestor-buffer
|
|
3447 (ediff-restore-variables ediff-protected-variables values-Ancestor)))
|
|
3448 ))
|
|
3449
|
|
3450 ;; save BUFFER in FILE. used in hooks.
|
|
3451 (defun ediff-save-buffer-in-file (buffer file)
|
|
3452 (ediff-eval-in-buffer buffer
|
|
3453 (write-file file)))
|
|
3454
|
|
3455
|
|
3456 ;;; Debug
|
|
3457
|
|
3458 (ediff-defvar-local ediff-command-begin-time '(0 0 0) "")
|
|
3459
|
|
3460 ;; calculate time used by command
|
|
3461 (defun ediff-calc-command-time ()
|
|
3462 (let ((end (current-time))
|
|
3463 micro sec)
|
|
3464 (setq micro
|
|
3465 (if (>= (nth 2 end) (nth 2 ediff-command-begin-time))
|
|
3466 (- (nth 2 end) (nth 2 ediff-command-begin-time))
|
|
3467 (+ (nth 2 end) (- 1000000 (nth 2 ediff-command-begin-time)))))
|
|
3468 (setq sec (- (nth 1 end) (nth 1 ediff-command-begin-time)))
|
|
3469 (or (equal ediff-command-begin-time '(0 0 0))
|
|
3470 (message "Elapsed time: %d second(s) + %d microsecond(s)" sec micro))))
|
|
3471
|
|
3472 (defsubst ediff-save-time ()
|
|
3473 (setq ediff-command-begin-time (current-time)))
|
|
3474
|
|
3475 (defun ediff-profile ()
|
|
3476 "Toggle profiling Ediff commands."
|
|
3477 (interactive)
|
|
3478 (ediff-barf-if-not-control-buffer)
|
|
3479 (make-local-hook 'post-command-hook)
|
|
3480 (let ((pre-hook 'pre-command-hook)
|
|
3481 (post-hook 'post-command-hook))
|
|
3482 (if (not (equal ediff-command-begin-time '(0 0 0)))
|
|
3483 (progn (remove-hook pre-hook 'ediff-save-time)
|
|
3484 (remove-hook post-hook 'ediff-calc-command-time)
|
|
3485 (setq ediff-command-begin-time '(0 0 0))
|
|
3486 (message "Ediff profiling disabled"))
|
|
3487 (add-hook pre-hook 'ediff-save-time t t)
|
|
3488 (add-hook post-hook 'ediff-calc-command-time nil t)
|
|
3489 (message "Ediff profiling enabled"))))
|
|
3490
|
|
3491 (defun ediff-print-diff-vector (diff-vector-var)
|
|
3492 (princ (format "\n*** %S ***\n" diff-vector-var))
|
|
3493 (mapcar (function
|
|
3494 (lambda (overl-vec)
|
|
3495 (princ
|
|
3496 (format
|
|
3497 "Diff %d: \tOverlay: %S
|
|
3498 \t\tFine diffs: %s
|
|
3499 \t\tNo-fine-diff-flag: %S
|
|
3500 \t\tState-of-diff:\t %S
|
|
3501 \t\tState-of-merge:\t %S
|
|
3502 "
|
|
3503 (1+ (ediff-overlay-get (aref overl-vec 0) 'ediff-diff-num))
|
|
3504 (aref overl-vec 0)
|
|
3505 ;; fine-diff-vector
|
|
3506 (if (= (length (aref overl-vec 1)) 0)
|
|
3507 "none\n"
|
|
3508 (mapconcat 'prin1-to-string
|
|
3509 (aref overl-vec 1) "\n\t\t\t "))
|
|
3510 (aref overl-vec 2) ; no fine diff flag
|
|
3511 (aref overl-vec 3) ; state-of-diff
|
|
3512 (aref overl-vec 4) ; state-of-merge
|
|
3513 ))))
|
|
3514 (eval diff-vector-var)))
|
|
3515
|
|
3516
|
|
3517
|
|
3518 (defun ediff-debug-info ()
|
|
3519 (interactive)
|
|
3520 (ediff-barf-if-not-control-buffer)
|
|
3521 (with-output-to-temp-buffer ediff-debug-buffer
|
|
3522 (princ (format "\nCtl buffer: %S\n" ediff-control-buffer))
|
|
3523 (ediff-print-diff-vector (intern "ediff-difference-vector-A"))
|
|
3524 (ediff-print-diff-vector (intern "ediff-difference-vector-B"))
|
|
3525 (ediff-print-diff-vector (intern "ediff-difference-vector-C"))
|
|
3526 (ediff-print-diff-vector (intern "ediff-difference-vector-Ancestor"))
|
|
3527 ))
|
|
3528
|
|
3529
|
|
3530 ;;; General utilities
|
|
3531
|
|
3532 ;; this uses comparison-func to decide who is a member
|
|
3533 (defun ediff-member (elt lis comparison-func)
|
|
3534 (while (and lis (not (funcall comparison-func (car lis) elt)))
|
|
3535 (setq lis (cdr lis)))
|
|
3536 lis)
|
|
3537
|
|
3538 ;; this uses comparison-func to decide who is a member, and this determines how
|
|
3539 ;; intersection looks like
|
|
3540 (defun ediff-intersection (lis1 lis2 comparison-func)
|
|
3541 (let ((result (list 'a)))
|
|
3542 (while lis1
|
|
3543 (if (ediff-member (car lis1) lis2 comparison-func)
|
|
3544 (nconc result (list (car lis1))))
|
|
3545 (setq lis1 (cdr lis1)))
|
|
3546 (cdr result)))
|
|
3547
|
|
3548
|
|
3549 ;; eliminates duplicates using comparison-func
|
|
3550 (defun ediff-union (lis1 lis2 comparison-func)
|
|
3551 (let ((result (list 'a)))
|
|
3552 (while lis1
|
|
3553 (or (ediff-member (car lis1) (cdr result) comparison-func)
|
|
3554 (nconc result (list (car lis1))))
|
|
3555 (setq lis1 (cdr lis1)))
|
|
3556 (while lis2
|
|
3557 (or (ediff-member (car lis2) (cdr result) comparison-func)
|
|
3558 (nconc result (list (car lis2))))
|
|
3559 (setq lis2 (cdr lis2)))
|
|
3560 (cdr result)))
|
|
3561
|
|
3562 ;; eliminates duplicates using comparison-func
|
|
3563 (defun ediff-set-difference (lis1 lis2 comparison-func)
|
|
3564 (let ((result (list 'a)))
|
|
3565 (while lis1
|
|
3566 (or (ediff-member (car lis1) (cdr result) comparison-func)
|
|
3567 (ediff-member (car lis1) lis2 comparison-func)
|
|
3568 (nconc result (list (car lis1))))
|
|
3569 (setq lis1 (cdr lis1)))
|
|
3570 (cdr result)))
|
|
3571
|
|
3572 (defun ediff-copy-list (list)
|
|
3573 (if (consp list)
|
|
3574 ;;;(let ((res nil))
|
|
3575 ;;; (while (consp list) (push (pop list) res))
|
|
3576 ;;; (prog1 (nreverse res) (setcdr res list)))
|
|
3577 (let (res elt)
|
|
3578 (while (consp list)
|
|
3579 (setq elt (car list)
|
|
3580 res (cons elt res)
|
|
3581 list (cdr list)))
|
|
3582 (nreverse res))
|
|
3583 (car list)))
|
|
3584
|
|
3585
|
|
3586 ;; don't report error if version control package wasn't found
|
|
3587 ;;(ediff-load-version-control 'silent)
|
|
3588
|
|
3589 (run-hooks 'ediff-load-hook)
|
|
3590
|
|
3591
|
|
3592 ;;; Local Variables:
|
|
3593 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
|
|
3594 ;;; eval: (put 'ediff-eval-in-buffer 'lisp-indent-hook 1)
|
78
|
3595 ;;; eval: (put 'ediff-eval-in-buffer 'edebug-form-spec '(form body))
|
0
|
3596 ;;; End:
|
|
3597
|
70
|
3598 (provide 'ediff-util)
|
|
3599
|
0
|
3600 ;;; ediff-util.el ends here
|