Commit | Line | Data |
---|---|---|
0f0b0a86 | 1 | ;;; ediff.el --- a comprehensive visual interface to diff & patch |
b578f267 | 2 | |
ddc90f39 | 3 | ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc. |
813f532d RS |
4 | |
5 | ;; Author: Michael Kifer <kifer@cs.sunysb.edu> | |
6 | ;; Created: February 2, 1994 | |
fcbadd58 | 7 | ;; Keywords: comparing, merging, patching, version control. |
813f532d | 8 | |
64c9affc KH |
9 | (defconst ediff-version "2.70.2" "The current version of Ediff") |
10 | (defconst ediff-date "May 21, 1998" "Date of last update") | |
bbe6126c | 11 | |
eaccd4d8 | 12 | |
813f532d RS |
13 | ;; This file is part of GNU Emacs. |
14 | ||
15 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
16 | ;; it under the terms of the GNU General Public License as published by | |
17 | ;; the Free Software Foundation; either version 2, or (at your option) | |
18 | ;; any later version. | |
19 | ||
20 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
21 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | ;; GNU General Public License for more details. | |
24 | ||
25 | ;; You should have received a copy of the GNU General Public License | |
b578f267 EN |
26 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
27 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
28 | ;; Boston, MA 02111-1307, USA. | |
813f532d | 29 | |
813f532d | 30 | ;;; Commentary: |
813f532d | 31 | |
0f0b0a86 | 32 | ;; Never read that diff output again! |
bbe6126c | 33 | ;; Apply patch interactively! |
0f0b0a86 | 34 | ;; Merge with ease! |
813f532d | 35 | |
fcbadd58 | 36 | ;; This package provides a convenient way of simultaneous browsing through |
f1a5512a | 37 | ;; the differences between a pair (or a triple) of files or buffers. The |
0f0b0a86 KH |
38 | ;; files being compared, file-A, file-B, and file-C (if applicable) are |
39 | ;; shown in separate windows (side by side, one above the another, or in | |
40 | ;; separate frames), and the differences are highlighted as you step | |
41 | ;; through them. You can also copy difference regions from one buffer to | |
42 | ;; another (and recover old differences if you change your mind). | |
813f532d | 43 | |
87c668b4 MK |
44 | ;; Ediff also supports merging operations on files and buffers, including |
45 | ;; merging using ancestor versions. Both comparison and merging operations can | |
46 | ;; be performed on directories, i.e., by pairwise comparison of files in those | |
47 | ;; directories. | |
48 | ||
813f532d | 49 | ;; In addition, Ediff can apply a patch to a file and then let you step |
fcbadd58 | 50 | ;; though both files, the patched and the original one, simultaneously, |
813f532d RS |
51 | ;; difference-by-difference. You can even apply a patch right out of a |
52 | ;; mail buffer, i.e., patches received by mail don't even have to be saved. | |
53 | ;; Since Ediff lets you copy differences between buffers, you can, in | |
54 | ;; effect, apply patches selectively (i.e., you can copy a difference | |
0f0b0a86 | 55 | ;; region from file_orig to file, thereby undoing any particular patch that |
813f532d RS |
56 | ;; you don't like). |
57 | ||
f1a5512a KH |
58 | ;; Ediff is aware of version control, which lets the user compare |
59 | ;; files with their older versions. Ediff can also work with remote and | |
60 | ;; compressed files. Details are given below. | |
61 | ||
bbe6126c | 62 | ;; Finally, Ediff supports directory-level comparison, merging and patching. |
87c668b4 | 63 | ;; See the on-line manual for details. |
813f532d | 64 | |
87c668b4 MK |
65 | ;; This package builds upon the ideas borrowed from emerge.el and several |
66 | ;; Ediff's functions are adaptations from emerge.el. Much of the functionality | |
67 | ;; Ediff provides is also influenced by emerge.el. | |
68 | ||
69 | ;; The present version of Ediff supersedes Emerge. It provides a superior user | |
70 | ;; interface and has numerous major features not found in Emerge. In | |
71 | ;; particular, it can do patching, and 2-way and 3-way file comparison, | |
72 | ;; merging, and directory operations. | |
fcbadd58 | 73 | |
4ae69eac MK |
74 | |
75 | ||
813f532d | 76 | ;;; Bugs: |
813f532d RS |
77 | |
78 | ;; 1. The undo command doesn't restore deleted regions well. That is, if | |
79 | ;; you delete all characters in a difference region and then invoke | |
0f0b0a86 | 80 | ;; `undo', the reinstated text will most likely be inserted outside of |
b3a26225 | 81 | ;; what Ediff thinks is the current difference region. (This problem |
0f0b0a86 | 82 | ;; doesn't seem to exist with XEmacs.) |
b3a26225 RS |
83 | ;; |
84 | ;; If at any point you feel that difference regions are no longer correct, | |
85 | ;; you can hit '!' to recompute the differences. | |
86 | ||
f1a5512a | 87 | ;; 2. On a monochrome display, the repertoire of faces with which to |
b3a26225 | 88 | ;; highlight fine differences is limited. By default, Ediff is using |
a7acbbe4 | 89 | ;; underlining. However, if the region is already underlined by some other |
b3a26225 RS |
90 | ;; overlays, there is no simple way to temporarily remove that residual |
91 | ;; underlining. This problem occurs when a buffer is highlighted with | |
92 | ;; hilit19.el or font-lock.el packages. If this residual highlighting gets | |
93 | ;; in the way, you can do the following. Both font-lock.el and hilit19.el | |
94 | ;; provide commands for unhighlighting buffers. You can either place these | |
87c668b4 | 95 | ;; commands in `ediff-prepare-buffer-hook' (which will unhighlight every |
b3a26225 RS |
96 | ;; buffer used by Ediff) or you can execute them interactively, at any time |
97 | ;; and on any buffer. | |
0f0b0a86 | 98 | |
4ae69eac | 99 | |
0f0b0a86 KH |
100 | ;;; Acknowledgements: |
101 | ||
87c668b4 MK |
102 | ;; Ediff was inspired by Dale R. Worley's <drw@math.mit.edu> emerge.el. |
103 | ;; Ediff would not have been possible without the help and encouragement of | |
104 | ;; its many users. See Ediff on-line Info for the full list of those who | |
105 | ;; helped. Improved defaults in Ediff file-name reading commands. | |
0f0b0a86 | 106 | |
0f0b0a86 KH |
107 | ;;; Code: |
108 | ||
ddc90f39 | 109 | (provide 'ediff) |
eaccd4d8 | 110 | |
ddc90f39 | 111 | ;; Compiler pacifier |
1e70790f MK |
112 | (defvar cvs-cookie-handle) |
113 | (defvar ediff-last-dir-patch) | |
114 | (defvar ediff-patch-default-directory) | |
115 | ||
92c51e07 MK |
116 | (and noninteractive |
117 | (eval-when-compile | |
92c51e07 | 118 | (load-library "dired") |
ddc90f39 MK |
119 | (load-library "info") |
120 | (load "pcl-cvs" 'noerror))) | |
121 | (eval-when-compile | |
122 | (let ((load-path (cons (expand-file-name ".") load-path))) | |
123 | (or (featurep 'ediff-init) | |
124 | (load "ediff-init.el" nil nil 'nosuffix)) | |
125 | (or (featurep 'ediff-mult) | |
126 | (load "ediff-mult.el" nil nil 'nosuffix)) | |
127 | (or (featurep 'ediff-ptch) | |
128 | (load "ediff-ptch.el" nil nil 'nosuffix)) | |
129 | (or (featurep 'ediff-vers) | |
130 | (load "ediff-vers.el" nil nil 'nosuffix)) | |
131 | )) | |
132 | ;; end pacifier | |
133 | ||
134 | (require 'ediff-init) | |
135 | (require 'ediff-mult) ; required because of the registry stuff | |
136 | ||
137 | (defgroup ediff nil | |
138 | "A comprehensive visual interface to diff & patch" | |
34317da2 | 139 | :tag "Ediff" |
ddc90f39 MK |
140 | :group 'tools) |
141 | ||
142 | ||
143 | (defcustom ediff-use-last-dir nil | |
1e70790f | 144 | "*If t, Ediff will use previous directory as default when reading file name." |
ddc90f39 MK |
145 | :type 'boolean |
146 | :group 'ediff) | |
bbe6126c | 147 | |
1e70790f MK |
148 | ;; Last directory used by an Ediff command for file-A. |
149 | (defvar ediff-last-dir-A nil) | |
150 | ;; Last directory used by an Ediff command for file-B. | |
151 | (defvar ediff-last-dir-B nil) | |
152 | ;; Last directory used by an Ediff command for file-C. | |
153 | (defvar ediff-last-dir-C nil) | |
154 | ;; Last directory used by an Ediff command for the ancestor file. | |
155 | (defvar ediff-last-dir-ancestor nil) | |
156 | ;; Last directory used by an Ediff command as the output directory for merge. | |
157 | (defvar ediff-last-merge-autostore-dir) | |
813f532d | 158 | |
87c668b4 | 159 | |
4ae69eac | 160 | ;; Used as a startup hook to set `_orig' patch file read-only. |
f1a5512a | 161 | (defun ediff-set-read-only-in-buf-A () |
e756eb9f | 162 | (ediff-with-current-buffer ediff-buffer-A |
f1a5512a | 163 | (toggle-read-only 1))) |
813f532d | 164 | |
87c668b4 MK |
165 | ;; Return a plausible default for ediff's first file: |
166 | ;; In dired, return the file name under the point, unless it is a directory | |
167 | ;; If the buffer has a file name, return that file name. | |
168 | (defun ediff-get-default-file-name () | |
169 | (cond ((eq major-mode 'dired-mode) | |
170 | (let ((f (dired-get-filename nil 'no-error))) | |
171 | (if (and (stringp f) (not (file-directory-p f))) | |
172 | f))) | |
173 | ((buffer-file-name (current-buffer)) | |
174 | (file-name-nondirectory (buffer-file-name (current-buffer)))) | |
175 | )) | |
176 | ||
0f0b0a86 | 177 | ;;; Compare files/buffers |
813f532d RS |
178 | |
179 | ;;;###autoload | |
180 | (defun ediff-files (file-A file-B &optional startup-hooks) | |
0f0b0a86 | 181 | "Run Ediff on a pair of files, FILE-A and FILE-B." |
813f532d | 182 | (interactive |
0f0b0a86 KH |
183 | (let ((dir-A (if ediff-use-last-dir |
184 | ediff-last-dir-A | |
185 | default-directory)) | |
186 | dir-B f) | |
87c668b4 MK |
187 | (list (setq f (ediff-read-file-name |
188 | "File A to compare" dir-A | |
189 | (ediff-get-default-file-name))) | |
813f532d | 190 | (ediff-read-file-name "File B to compare" |
0f0b0a86 KH |
191 | (setq dir-B |
192 | (if ediff-use-last-dir | |
193 | ediff-last-dir-B | |
194 | (file-name-directory f))) | |
195 | (progn | |
196 | (setq file-name-history | |
87c668b4 | 197 | (cons (ediff-abbreviate-file-name |
0f0b0a86 KH |
198 | (expand-file-name |
199 | (file-name-nondirectory f) | |
200 | dir-B)) | |
201 | file-name-history)) | |
202 | f)) | |
203 | ))) | |
204 | (ediff-files-internal file-A | |
205 | (if (file-directory-p file-B) | |
206 | (expand-file-name | |
207 | (file-name-nondirectory file-A) file-B) | |
208 | file-B) | |
209 | nil ; file-C | |
210 | startup-hooks | |
211 | 'ediff-files)) | |
212 | ||
213 | ;;;###autoload | |
214 | (defun ediff-files3 (file-A file-B file-C &optional startup-hooks) | |
215 | "Run Ediff on three files, FILE-A, FILE-B, and FILE-C." | |
216 | (interactive | |
217 | (let ((dir-A (if ediff-use-last-dir | |
218 | ediff-last-dir-A | |
219 | default-directory)) | |
220 | dir-B dir-C f ff) | |
87c668b4 MK |
221 | (list (setq f (ediff-read-file-name |
222 | "File A to compare" dir-A | |
223 | (ediff-get-default-file-name))) | |
0f0b0a86 KH |
224 | (setq ff (ediff-read-file-name "File B to compare" |
225 | (setq dir-B | |
226 | (if ediff-use-last-dir | |
227 | ediff-last-dir-B | |
228 | (file-name-directory f))) | |
229 | (progn | |
230 | (setq file-name-history | |
231 | (cons | |
87c668b4 | 232 | (ediff-abbreviate-file-name |
0f0b0a86 KH |
233 | (expand-file-name |
234 | (file-name-nondirectory f) | |
235 | dir-B)) | |
236 | file-name-history)) | |
237 | f))) | |
238 | (ediff-read-file-name "File C to compare" | |
239 | (setq dir-C (if ediff-use-last-dir | |
240 | ediff-last-dir-C | |
241 | (file-name-directory ff))) | |
242 | (progn | |
243 | (setq file-name-history | |
87c668b4 | 244 | (cons (ediff-abbreviate-file-name |
0f0b0a86 KH |
245 | (expand-file-name |
246 | (file-name-nondirectory ff) | |
247 | dir-C)) | |
248 | file-name-history)) | |
249 | ff)) | |
813f532d | 250 | ))) |
b3a26225 RS |
251 | (ediff-files-internal file-A |
252 | (if (file-directory-p file-B) | |
253 | (expand-file-name | |
254 | (file-name-nondirectory file-A) file-B) | |
255 | file-B) | |
0f0b0a86 KH |
256 | (if (file-directory-p file-C) |
257 | (expand-file-name | |
258 | (file-name-nondirectory file-A) file-C) | |
259 | file-C) | |
260 | startup-hooks | |
261 | 'ediff-files3)) | |
813f532d | 262 | |
0f0b0a86 KH |
263 | ;;;###autoload |
264 | (defalias 'ediff3 'ediff-files3) | |
813f532d | 265 | |
813f532d | 266 | |
4ae69eac MK |
267 | ;; Visit FILE and arrange its buffer to Ediff's liking. |
268 | ;; FILE is actually a variable symbol that must contain a true file name. | |
269 | ;; BUFFER-NAME is a variable symbol, which will get the buffer object into | |
270 | ;; which FILE is read. | |
271 | ;; LAST-DIR is the directory variable symbol where FILE's | |
272 | ;; directory name should be returned. HOOKS-VAR is a variable symbol that will | |
273 | ;; be assigned the hook to be executed after `ediff-startup' is finished. | |
274 | ;; `ediff-find-file' arranges that the temp files it might create will be | |
275 | ;; deleted. | |
0f0b0a86 | 276 | (defun ediff-find-file (file-var buffer-name &optional last-dir hooks-var) |
0f0b0a86 | 277 | (let* ((file (symbol-value file-var)) |
bd698e98 | 278 | (file-magic (ediff-filename-magic-p file)) |
0f0b0a86 | 279 | (temp-file-name-prefix (file-name-nondirectory file))) |
87c668b4 MK |
280 | (cond ((not (file-readable-p file)) |
281 | (error "File `%s' does not exist or is not readable" file)) | |
282 | ((file-directory-p file) | |
283 | (error "File `%s' is a directory" file))) | |
0f0b0a86 | 284 | |
4ae69eac | 285 | ;; some of the commands, below, require full file name |
0f0b0a86 KH |
286 | (setq file (expand-file-name file)) |
287 | ||
288 | ;; Record the directory of the file | |
289 | (if last-dir | |
290 | (set last-dir (expand-file-name (file-name-directory file)))) | |
291 | ||
292 | ;; Setup the buffer | |
293 | (set buffer-name (find-file-noselect file)) | |
294 | ||
e756eb9f | 295 | (ediff-with-current-buffer (symbol-value buffer-name) |
0f0b0a86 | 296 | (widen) ; Make sure the entire file is seen |
ddc90f39 MK |
297 | (cond (file-magic ; file has a handler, such as jka-compr-handler or |
298 | ;;; ange-ftp-hook-function--arrange for temp file | |
0f0b0a86 | 299 | (ediff-verify-file-buffer 'magic) |
87c668b4 MK |
300 | (setq file |
301 | (ediff-make-temp-file | |
302 | (current-buffer) temp-file-name-prefix)) | |
0f0b0a86 KH |
303 | (set hooks-var (cons (` (lambda () (delete-file (, file)))) |
304 | (symbol-value hooks-var)))) | |
305 | ;; file processed via auto-mode-alist, a la uncompress.el | |
306 | ((not (equal (file-truename file) | |
307 | (file-truename (buffer-file-name)))) | |
87c668b4 MK |
308 | (setq file |
309 | (ediff-make-temp-file | |
310 | (current-buffer) temp-file-name-prefix)) | |
0f0b0a86 KH |
311 | (set hooks-var (cons (` (lambda () (delete-file (, file)))) |
312 | (symbol-value hooks-var)))) | |
313 | (t ;; plain file---just check that the file matches the buffer | |
314 | (ediff-verify-file-buffer)))) | |
315 | (set file-var file))) | |
316 | ||
328b4b70 MK |
317 | ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer |
318 | (defun ediff-files-internal (file-A file-B file-C startup-hooks job-name | |
319 | &optional merge-buffer-file) | |
0f0b0a86 | 320 | (let (buf-A buf-B buf-C) |
87c668b4 MK |
321 | (message "Reading file %s ... " file-A) |
322 | ;;(sit-for 0) | |
0f0b0a86 | 323 | (ediff-find-file 'file-A 'buf-A 'ediff-last-dir-A 'startup-hooks) |
87c668b4 MK |
324 | (message "Reading file %s ... " file-B) |
325 | ;;(sit-for 0) | |
0f0b0a86 | 326 | (ediff-find-file 'file-B 'buf-B 'ediff-last-dir-B 'startup-hooks) |
87c668b4 | 327 | (if (stringp file-C) |
0f0b0a86 | 328 | (progn |
87c668b4 MK |
329 | (message "Reading file %s ... " file-C) |
330 | ;;(sit-for 0) | |
0f0b0a86 KH |
331 | (ediff-find-file |
332 | 'file-C 'buf-C | |
333 | (if (eq job-name 'ediff-merge-files-with-ancestor) | |
334 | 'ediff-last-dir-ancestor 'ediff-last-dir-C) | |
335 | 'startup-hooks))) | |
336 | (ediff-setup buf-A file-A | |
337 | buf-B file-B | |
338 | buf-C file-C | |
339 | startup-hooks | |
328b4b70 MK |
340 | (list (cons 'ediff-job-name job-name)) |
341 | merge-buffer-file))) | |
0f0b0a86 KH |
342 | |
343 | ||
344 | ;;;###autoload | |
345 | (defalias 'ediff 'ediff-files) | |
813f532d | 346 | |
813f532d RS |
347 | |
348 | ;;;###autoload | |
0f0b0a86 | 349 | (defun ediff-buffers (buffer-A buffer-B &optional startup-hooks job-name) |
813f532d | 350 | "Run Ediff on a pair of buffers, BUFFER-A and BUFFER-B." |
fcbadd58 | 351 | (interactive |
0f0b0a86 KH |
352 | (let (bf) |
353 | (list (setq bf (read-buffer "Buffer A to compare: " | |
354 | (ediff-other-buffer "") t)) | |
355 | (read-buffer "Buffer B to compare: " | |
356 | (progn | |
357 | ;; realign buffers so that two visible bufs will be | |
358 | ;; at the top | |
359 | (save-window-excursion (other-window 1)) | |
360 | (ediff-other-buffer bf)) | |
361 | t)))) | |
0f0b0a86 KH |
362 | (or job-name (setq job-name 'ediff-buffers)) |
363 | (ediff-buffers-internal buffer-A buffer-B nil startup-hooks job-name)) | |
bbe6126c MK |
364 | |
365 | ;;;###autoload | |
366 | (defalias 'ebuffers 'ediff-buffers) | |
367 | ||
0f0b0a86 KH |
368 | |
369 | ;;;###autoload | |
370 | (defun ediff-buffers3 (buffer-A buffer-B buffer-C | |
371 | &optional startup-hooks job-name) | |
372 | "Run Ediff on three buffers, BUFFER-A, BUFFER-B, and BUFFER-C." | |
373 | (interactive | |
374 | (let (bf bff) | |
375 | (list (setq bf (read-buffer "Buffer A to compare: " | |
376 | (ediff-other-buffer "") t)) | |
377 | (setq bff (read-buffer "Buffer B to compare: " | |
378 | (progn | |
379 | ;; realign buffers so that two visible | |
380 | ;; bufs will be at the top | |
381 | (save-window-excursion (other-window 1)) | |
382 | (ediff-other-buffer bf)) | |
383 | t)) | |
384 | (read-buffer "Buffer C to compare: " | |
385 | (progn | |
386 | ;; realign buffers so that three visible | |
387 | ;; bufs will be at the top | |
388 | (save-window-excursion (other-window 1)) | |
389 | (ediff-other-buffer (list bf bff))) | |
390 | t) | |
391 | ))) | |
0f0b0a86 KH |
392 | (or job-name (setq job-name 'ediff-buffers3)) |
393 | (ediff-buffers-internal buffer-A buffer-B buffer-C startup-hooks job-name)) | |
bbe6126c MK |
394 | |
395 | ;;;###autoload | |
396 | (defalias 'ebuffers3 'ediff-buffers3) | |
0f0b0a86 KH |
397 | |
398 | ||
399 | ||
328b4b70 MK |
400 | ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer |
401 | (defun ediff-buffers-internal (buf-A buf-B buf-C startup-hooks job-name | |
402 | &optional merge-buffer-file) | |
0f0b0a86 KH |
403 | (let* ((buf-A-file-name (buffer-file-name (get-buffer buf-A))) |
404 | (buf-B-file-name (buffer-file-name (get-buffer buf-B))) | |
405 | (buf-C-is-alive (ediff-buffer-live-p buf-C)) | |
406 | (buf-C-file-name (if buf-C-is-alive | |
407 | (buffer-file-name (get-buffer buf-B)))) | |
408 | file-A file-B file-C) | |
409 | (if (not (ediff-buffer-live-p buf-A)) | |
410 | (error "Buffer %S doesn't exist" buf-A)) | |
411 | (if (not (ediff-buffer-live-p buf-B)) | |
412 | (error "Buffer %S doesn't exist" buf-B)) | |
413 | (let ((ediff-job-name job-name)) | |
414 | (if (and ediff-3way-comparison-job | |
415 | (not buf-C-is-alive)) | |
416 | (error "Buffer %S doesn't exist" buf-C))) | |
417 | (if (stringp buf-A-file-name) | |
418 | (setq buf-A-file-name (file-name-nondirectory buf-A-file-name))) | |
419 | (if (stringp buf-B-file-name) | |
420 | (setq buf-B-file-name (file-name-nondirectory buf-B-file-name))) | |
421 | (if (stringp buf-C-file-name) | |
422 | (setq buf-C-file-name (file-name-nondirectory buf-C-file-name))) | |
423 | ||
4ae69eac MK |
424 | (setq file-A (ediff-make-temp-file buf-A buf-A-file-name) |
425 | file-B (ediff-make-temp-file buf-B buf-B-file-name)) | |
0f0b0a86 | 426 | (if buf-C-is-alive |
87c668b4 | 427 | (setq file-C (ediff-make-temp-file buf-C buf-C-file-name))) |
0f0b0a86 KH |
428 | |
429 | (ediff-setup (get-buffer buf-A) file-A | |
430 | (get-buffer buf-B) file-B | |
431 | (if buf-C-is-alive (get-buffer buf-C)) | |
432 | file-C | |
433 | (cons (` (lambda () | |
434 | (delete-file (, file-A)) | |
435 | (delete-file (, file-B)) | |
436 | (if (stringp (, file-C)) (delete-file (, file-C))) | |
437 | )) | |
438 | startup-hooks) | |
439 | (list (cons 'ediff-job-name job-name)) | |
328b4b70 | 440 | merge-buffer-file))) |
87c668b4 MK |
441 | |
442 | ||
443 | ;;; Directory and file group operations | |
444 | ||
445 | ;; Get appropriate default name for directory: | |
446 | ;; If ediff-use-last-dir, use ediff-last-dir-A. | |
447 | ;; In dired mode, use the directory that is under the point (if any); | |
448 | ;; otherwise, use default-directory | |
449 | (defun ediff-get-default-directory-name () | |
450 | (cond (ediff-use-last-dir ediff-last-dir-A) | |
451 | ((eq major-mode 'dired-mode) | |
452 | (let ((f (dired-get-filename nil 'noerror))) | |
453 | (if (and (stringp f) (file-directory-p f)) | |
454 | f | |
455 | default-directory))) | |
456 | (t default-directory))) | |
457 | ||
458 | ||
459 | ;;;###autoload | |
460 | (defun ediff-directories (dir1 dir2 regexp) | |
461 | "Run Ediff on a pair of directories, DIR1 and DIR2, comparing files that have | |
462 | the same name in both. The third argument, REGEXP, is a regular expression that | |
bbe6126c | 463 | can be used to filter out certain file names." |
87c668b4 MK |
464 | (interactive |
465 | (let ((dir-A (ediff-get-default-directory-name)) | |
466 | f) | |
bbe6126c MK |
467 | (list (setq f (ediff-read-file-name "Directory A to compare:" dir-A nil)) |
468 | (ediff-read-file-name "Directory B to compare:" | |
87c668b4 MK |
469 | (if ediff-use-last-dir |
470 | ediff-last-dir-B | |
471 | (ediff-strip-last-dir f)) | |
472 | nil) | |
473 | (read-string "Filter through regular expression: " | |
bbe6126c | 474 | nil 'ediff-filtering-regexp-history) |
87c668b4 MK |
475 | ))) |
476 | (ediff-directories-internal | |
477 | dir1 dir2 nil regexp 'ediff-files 'ediff-directories | |
478 | )) | |
479 | ||
480 | ;;;###autoload | |
481 | (defalias 'edirs 'ediff-directories) | |
482 | ||
483 | ||
484 | ;;;###autoload | |
485 | (defun ediff-directory-revisions (dir1 regexp) | |
486 | "Run Ediff on a directory, DIR1, comparing its files with their revisions. | |
487 | The second argument, REGEXP, is a regular expression that filters the file | |
488 | names. Only the files that are under revision control are taken into account." | |
489 | (interactive | |
490 | (let ((dir-A (ediff-get-default-directory-name))) | |
491 | (list (ediff-read-file-name | |
bbe6126c | 492 | "Directory to compare with revision:" dir-A nil) |
87c668b4 | 493 | (read-string "Filter through regular expression: " |
bbe6126c | 494 | nil 'ediff-filtering-regexp-history) |
87c668b4 MK |
495 | ))) |
496 | (ediff-directory-revisions-internal | |
497 | dir1 regexp 'ediff-revision 'ediff-directory-revisions | |
498 | )) | |
499 | ||
500 | ;;;###autoload | |
501 | (defalias 'edir-revisions 'ediff-directory-revisions) | |
502 | ||
503 | ||
504 | ;;;###autoload | |
505 | (defun ediff-directories3 (dir1 dir2 dir3 regexp) | |
506 | "Run Ediff on three directories, DIR1, DIR2, and DIR3, comparing files that | |
507 | have the same name in all three. The last argument, REGEXP, is a regular | |
bbe6126c | 508 | expression that can be used to filter out certain file names." |
87c668b4 MK |
509 | (interactive |
510 | (let ((dir-A (ediff-get-default-directory-name)) | |
511 | f) | |
bbe6126c MK |
512 | (list (setq f (ediff-read-file-name "Directory A to compare:" dir-A nil)) |
513 | (setq f (ediff-read-file-name "Directory B to compare:" | |
87c668b4 MK |
514 | (if ediff-use-last-dir |
515 | ediff-last-dir-B | |
516 | (ediff-strip-last-dir f)) | |
517 | nil)) | |
bbe6126c | 518 | (ediff-read-file-name "Directory C to compare:" |
87c668b4 MK |
519 | (if ediff-use-last-dir |
520 | ediff-last-dir-C | |
521 | (ediff-strip-last-dir f)) | |
522 | nil) | |
523 | (read-string "Filter through regular expression: " | |
bbe6126c | 524 | nil 'ediff-filtering-regexp-history) |
87c668b4 MK |
525 | ))) |
526 | (ediff-directories-internal | |
527 | dir1 dir2 dir3 regexp 'ediff-files3 'ediff-directories3 | |
528 | )) | |
529 | ||
530 | ;;;###autoload | |
531 | (defalias 'edirs3 'ediff-directories3) | |
532 | ||
533 | ;;;###autoload | |
534 | (defun ediff-merge-directories (dir1 dir2 regexp) | |
535 | "Run Ediff on a pair of directories, DIR1 and DIR2, merging files that have | |
536 | the same name in both. The third argument, REGEXP, is a regular expression that | |
bbe6126c | 537 | can be used to filter out certain file names." |
87c668b4 MK |
538 | (interactive |
539 | (let ((dir-A (ediff-get-default-directory-name)) | |
540 | f) | |
bbe6126c MK |
541 | (list (setq f (ediff-read-file-name "Directory A to merge:" dir-A nil)) |
542 | (ediff-read-file-name "Directory B to merge:" | |
87c668b4 MK |
543 | (if ediff-use-last-dir |
544 | ediff-last-dir-B | |
545 | (ediff-strip-last-dir f)) | |
546 | nil) | |
547 | (read-string "Filter through regular expression: " | |
bbe6126c | 548 | nil 'ediff-filtering-regexp-history) |
87c668b4 MK |
549 | ))) |
550 | (ediff-directories-internal | |
551 | dir1 dir2 nil regexp 'ediff-merge-files 'ediff-merge-directories | |
552 | )) | |
553 | ||
554 | ;;;###autoload | |
555 | (defalias 'edirs-merge 'ediff-merge-directories) | |
556 | ||
557 | ;;;###autoload | |
bbe6126c MK |
558 | (defun ediff-merge-directories-with-ancestor (dir1 dir2 ancestor-dir regexp) |
559 | "Merge files in directories DIR1 and DIR2 using files in ANCESTOR-DIR as ancestors. | |
560 | Ediff merges files that have identical names in DIR1, DIR2. If a pair of files | |
561 | in DIR1 and DIR2 doesn't have an ancestor in ANCESTOR-DIR, Ediff will merge | |
562 | without ancestor. The fourth argument, REGEXP, is a regular expression that | |
563 | can be used to filter out certain file names." | |
87c668b4 MK |
564 | (interactive |
565 | (let ((dir-A (ediff-get-default-directory-name)) | |
566 | f) | |
bbe6126c MK |
567 | (list (setq f (ediff-read-file-name "Directory A to merge:" dir-A nil)) |
568 | (setq f (ediff-read-file-name "Directory B to merge:" | |
87c668b4 MK |
569 | (if ediff-use-last-dir |
570 | ediff-last-dir-B | |
571 | (ediff-strip-last-dir f)) | |
572 | nil)) | |
bbe6126c | 573 | (ediff-read-file-name "Ancestor directory:" |
87c668b4 MK |
574 | (if ediff-use-last-dir |
575 | ediff-last-dir-C | |
576 | (ediff-strip-last-dir f)) | |
577 | nil) | |
578 | (read-string "Filter through regular expression: " | |
bbe6126c | 579 | nil 'ediff-filtering-regexp-history) |
87c668b4 MK |
580 | ))) |
581 | (ediff-directories-internal | |
bbe6126c | 582 | dir1 dir2 ancestor-dir regexp |
87c668b4 MK |
583 | 'ediff-merge-files-with-ancestor 'ediff-merge-directories-with-ancestor |
584 | )) | |
585 | ||
586 | ;;;###autoload | |
587 | (defun ediff-merge-directory-revisions (dir1 regexp) | |
588 | "Run Ediff on a directory, DIR1, merging its files with their revisions. | |
589 | The second argument, REGEXP, is a regular expression that filters the file | |
590 | names. Only the files that are under revision control are taken into account." | |
591 | (interactive | |
bf5d92c5 | 592 | (let ((dir-A (ediff-get-default-directory-name))) |
87c668b4 | 593 | (list (ediff-read-file-name |
bbe6126c | 594 | "Directory to merge with revisions:" dir-A nil) |
87c668b4 | 595 | (read-string "Filter through regular expression: " |
bbe6126c | 596 | nil 'ediff-filtering-regexp-history) |
87c668b4 MK |
597 | ))) |
598 | (ediff-directory-revisions-internal | |
599 | dir1 regexp 'ediff-merge-revisions 'ediff-merge-directory-revisions | |
600 | )) | |
601 | ||
602 | ;;;###autoload | |
603 | (defalias 'edir-merge-revisions 'ediff-merge-directory-revisions) | |
604 | ||
605 | ;;;###autoload | |
606 | (defun ediff-merge-directory-revisions-with-ancestor (dir1 regexp) | |
607 | "Run Ediff on a directory, DIR1, merging its files with their revisions and ancestors. | |
608 | The second argument, REGEXP, is a regular expression that filters the file | |
609 | names. Only the files that are under revision control are taken into account." | |
610 | (interactive | |
bf5d92c5 | 611 | (let ((dir-A (ediff-get-default-directory-name))) |
87c668b4 | 612 | (list (ediff-read-file-name |
bbe6126c | 613 | "Directory to merge with revisions and ancestors:" dir-A nil) |
87c668b4 | 614 | (read-string "Filter through regular expression: " |
bbe6126c | 615 | nil 'ediff-filtering-regexp-history) |
87c668b4 MK |
616 | ))) |
617 | (ediff-directory-revisions-internal | |
618 | dir1 regexp 'ediff-merge-revisions-with-ancestor | |
619 | 'ediff-merge-directory-revisions-with-ancestor | |
620 | )) | |
621 | ||
622 | ;;;###autoload | |
623 | (defalias | |
624 | 'edir-merge-revisions-with-ancestor | |
625 | 'ediff-merge-directory-revisions-with-ancestor) | |
626 | ||
627 | ;;;###autoload | |
628 | (defalias 'edirs-merge-with-ancestor 'ediff-merge-directories-with-ancestor) | |
629 | ||
630 | ;; Run ediff-action (ediff-files, ediff-merge, ediff-merge-with-ancestors) | |
631 | ;; on a pair of directories (three directories, in case of ancestor). | |
bbe6126c MK |
632 | ;; The third argument, REGEXP, is a regular expression that can be used to |
633 | ;; filter out certain file names. | |
87c668b4 | 634 | ;; JOBNAME is the symbol indicating the meta-job to be performed. |
92c51e07 MK |
635 | ;; MERGE-DIR is the directory in which to store merged files. |
636 | (defun ediff-directories-internal (dir1 dir2 dir3 regexp action jobname | |
87c668b4 MK |
637 | &optional startup-hooks) |
638 | ;; ediff-read-file-name is set to attach a previously entered file name if | |
639 | ;; the currently entered file is a directory. This code takes care of that. | |
640 | (setq dir1 (if (file-directory-p dir1) dir1 (file-name-directory dir1)) | |
641 | dir2 (if (file-directory-p dir2) dir2 (file-name-directory dir2))) | |
642 | ||
643 | (if (stringp dir3) | |
644 | (setq dir3 (if (file-directory-p dir3) dir3 (file-name-directory dir3)))) | |
645 | ||
646 | (cond ((string= dir1 dir2) | |
647 | (error "Directories A and B are the same: %s" dir1)) | |
648 | ((and (eq jobname 'ediff-directories3) | |
649 | (string= dir1 dir3)) | |
650 | (error "Directories A and C are the same: %s" dir1)) | |
651 | ((and (eq jobname 'ediff-directories3) | |
652 | (string= dir2 dir3)) | |
653 | (error "Directories B and C are the same: %s" dir1))) | |
654 | ||
655 | (let (diffs ; var where ediff-intersect-directories returns the diff list | |
92c51e07 | 656 | merge-autostore-dir |
87c668b4 | 657 | file-list meta-buf) |
92c51e07 MK |
658 | (if (and ediff-autostore-merges (ediff-merge-metajob jobname)) |
659 | (setq merge-autostore-dir | |
660 | (ediff-read-file-name "Directory to save merged files:" | |
661 | (if ediff-use-last-dir | |
662 | ediff-last-merge-autostore-dir | |
663 | (ediff-strip-last-dir dir1)) | |
664 | nil))) | |
665 | ;; verify we are not merging into an orig directory | |
666 | (if (stringp merge-autostore-dir) | |
667 | (cond ((and (stringp dir1) (string= merge-autostore-dir dir1)) | |
668 | (or (y-or-n-p "Merge directory same as directory A, sure? ") | |
669 | (error "Directory merge aborted"))) | |
670 | ((and (stringp dir2) (string= merge-autostore-dir dir2)) | |
671 | (or (y-or-n-p "Merge directory same as directory B, sure? ") | |
672 | (error "Directory merge aborted"))) | |
673 | ((and (stringp dir3) (string= merge-autostore-dir dir3)) | |
674 | (or (y-or-n-p | |
675 | "Merge directory same as ancestor directory, sure? ") | |
676 | (error "Directory merge aborted"))))) | |
677 | ||
87c668b4 | 678 | (setq file-list (ediff-intersect-directories |
92c51e07 MK |
679 | jobname 'diffs |
680 | regexp dir1 dir2 dir3 merge-autostore-dir)) | |
87c668b4 MK |
681 | (setq startup-hooks |
682 | ;; this sets various vars in the meta buffer inside | |
683 | ;; ediff-prepare-meta-buffer | |
684 | (cons (` (lambda () | |
685 | ;; tell what to do if the user clicks on a session record | |
686 | (setq ediff-session-action-function (quote (, action))) | |
687 | ;; set ediff-dir-difference-list | |
688 | (setq ediff-dir-difference-list (quote (, diffs))))) | |
689 | startup-hooks)) | |
690 | (setq meta-buf (ediff-prepare-meta-buffer | |
bbe6126c | 691 | 'ediff-filegroup-action |
87c668b4 MK |
692 | file-list |
693 | "*Ediff Session Group Panel" | |
694 | 'ediff-redraw-directory-group-buffer | |
695 | jobname | |
696 | startup-hooks)) | |
697 | (ediff-show-meta-buffer meta-buf) | |
698 | )) | |
699 | ||
700 | (defun ediff-directory-revisions-internal (dir1 regexp action jobname | |
701 | &optional startup-hooks) | |
702 | (setq dir1 (if (file-directory-p dir1) dir1 (file-name-directory dir1))) | |
92c51e07 MK |
703 | |
704 | (let (file-list meta-buf merge-autostore-dir) | |
705 | (if (and ediff-autostore-merges (ediff-merge-metajob jobname)) | |
706 | (setq merge-autostore-dir | |
707 | (ediff-read-file-name "Directory to save merged files:" | |
708 | (if ediff-use-last-dir | |
709 | ediff-last-merge-autostore-dir | |
710 | (ediff-strip-last-dir dir1)) | |
711 | nil))) | |
712 | ;; verify merge-autostore-dir != dir1 | |
713 | (if (and (stringp merge-autostore-dir) | |
714 | (stringp dir1) | |
715 | (string= merge-autostore-dir dir1)) | |
716 | (or (y-or-n-p | |
717 | "Directory for saving merges is the same as directory A. Sure? ") | |
718 | (error "Merge of directory revisions aborted"))) | |
719 | ||
87c668b4 | 720 | (setq file-list |
92c51e07 MK |
721 | (ediff-get-directory-files-under-revision |
722 | jobname regexp dir1 merge-autostore-dir)) | |
87c668b4 MK |
723 | (setq startup-hooks |
724 | ;; this sets various vars in the meta buffer inside | |
725 | ;; ediff-prepare-meta-buffer | |
726 | (cons (` (lambda () | |
727 | ;; tell what to do if the user clicks on a session record | |
728 | (setq ediff-session-action-function (quote (, action))) | |
729 | )) | |
730 | startup-hooks)) | |
731 | (setq meta-buf (ediff-prepare-meta-buffer | |
bbe6126c | 732 | 'ediff-filegroup-action |
87c668b4 MK |
733 | file-list |
734 | "*Ediff Session Group Panel" | |
735 | 'ediff-redraw-directory-group-buffer | |
736 | jobname | |
737 | startup-hooks)) | |
738 | (ediff-show-meta-buffer meta-buf) | |
739 | )) | |
0f0b0a86 KH |
740 | |
741 | ||
742 | ;;; Compare regions and windows | |
743 | ||
744 | ;;;###autoload | |
f1a5512a KH |
745 | (defun ediff-windows-wordwise (dumb-mode &optional wind-A wind-B startup-hooks) |
746 | "Compare WIND-A and WIND-B, which are selected by clicking, wordwise. | |
0f0b0a86 KH |
747 | With prefix argument, DUMB-MODE, or on a non-windowing display, works as |
748 | follows: | |
749 | If WIND-A is nil, use selected window. | |
750 | If WIND-B is nil, use window next to WIND-A." | |
0f0b0a86 | 751 | (interactive "P") |
f1a5512a KH |
752 | (ediff-windows dumb-mode wind-A wind-B |
753 | startup-hooks 'ediff-windows-wordwise 'word-mode)) | |
754 | ||
755 | ;;;###autoload | |
756 | (defun ediff-windows-linewise (dumb-mode &optional wind-A wind-B startup-hooks) | |
757 | "Compare WIND-A and WIND-B, which are selected by clicking, linewise. | |
758 | With prefix argument, DUMB-MODE, or on a non-windowing display, works as | |
759 | follows: | |
760 | If WIND-A is nil, use selected window. | |
761 | If WIND-B is nil, use window next to WIND-A." | |
762 | (interactive "P") | |
763 | (ediff-windows dumb-mode wind-A wind-B | |
764 | startup-hooks 'ediff-windows-linewise nil)) | |
0f0b0a86 | 765 | |
f1a5512a KH |
766 | ;; Compare WIND-A and WIND-B, which are selected by clicking. |
767 | ;; With prefix argument, DUMB-MODE, or on a non-windowing display, | |
768 | ;; works as follows: | |
769 | ;; If WIND-A is nil, use selected window. | |
770 | ;; If WIND-B is nil, use window next to WIND-A. | |
771 | (defun ediff-windows (dumb-mode wind-A wind-B startup-hooks job-name word-mode) | |
772 | (if (or dumb-mode (not (ediff-window-display-p))) | |
0f0b0a86 KH |
773 | (setq wind-A (ediff-get-next-window wind-A nil) |
774 | wind-B (ediff-get-next-window wind-B wind-A)) | |
775 | (setq wind-A (ediff-get-window-by-clicking wind-A nil 1) | |
776 | wind-B (ediff-get-window-by-clicking wind-B wind-A 2))) | |
777 | ||
778 | (let ((buffer-A (window-buffer wind-A)) | |
779 | (buffer-B (window-buffer wind-B)) | |
780 | beg-A end-A beg-B end-B) | |
781 | ||
782 | (save-excursion | |
783 | (save-window-excursion | |
a7acbbe4 | 784 | (sit-for 0) ; sync before using window-start/end -- a precaution |
0f0b0a86 KH |
785 | (select-window wind-A) |
786 | (setq beg-A (window-start) | |
787 | end-A (window-end)) | |
788 | (select-window wind-B) | |
789 | (setq beg-B (window-start) | |
790 | end-B (window-end)))) | |
791 | (ediff-regions-internal | |
792 | buffer-A beg-A end-A buffer-B beg-B end-B | |
ddc90f39 | 793 | startup-hooks job-name word-mode nil))) |
0f0b0a86 KH |
794 | |
795 | ;;;###autoload | |
f1a5512a | 796 | (defun ediff-regions-wordwise (buffer-A buffer-B &optional startup-hooks) |
0f0b0a86 KH |
797 | "Run Ediff on a pair of regions in two different buffers. |
798 | Regions \(i.e., point and mark\) are assumed to be set in advance. | |
799 | This function is effective only for relatively small regions, up to 200 | |
f1a5512a | 800 | lines. For large regions, use `ediff-regions-linewise'." |
0f0b0a86 KH |
801 | (interactive |
802 | (let (bf) | |
803 | (list (setq bf (read-buffer "Region's A buffer: " | |
804 | (ediff-other-buffer "") t)) | |
805 | (read-buffer "Region's B buffer: " | |
806 | (progn | |
807 | ;; realign buffers so that two visible bufs will be | |
808 | ;; at the top | |
809 | (save-window-excursion (other-window 1)) | |
810 | (ediff-other-buffer bf)) | |
811 | t)))) | |
812 | (if (not (ediff-buffer-live-p buffer-A)) | |
813 | (error "Buffer %S doesn't exist" buffer-A)) | |
814 | (if (not (ediff-buffer-live-p buffer-B)) | |
815 | (error "Buffer %S doesn't exist" buffer-B)) | |
816 | ||
817 | ||
818 | (let (reg-A-beg reg-A-end reg-B-beg reg-B-end) | |
819 | (save-excursion | |
820 | (set-buffer buffer-A) | |
821 | (setq reg-A-beg (region-beginning) | |
822 | reg-A-end (region-end)) | |
823 | (set-buffer buffer-B) | |
824 | (setq reg-B-beg (region-beginning) | |
825 | reg-B-end (region-end))) | |
826 | ||
827 | (ediff-regions-internal | |
828 | (get-buffer buffer-A) reg-A-beg reg-A-end | |
829 | (get-buffer buffer-B) reg-B-beg reg-B-end | |
ddc90f39 | 830 | startup-hooks 'ediff-regions-wordwise 'word-mode nil))) |
0f0b0a86 KH |
831 | |
832 | ;;;###autoload | |
f1a5512a | 833 | (defun ediff-regions-linewise (buffer-A buffer-B &optional startup-hooks) |
0f0b0a86 KH |
834 | "Run Ediff on a pair of regions in two different buffers. |
835 | Regions \(i.e., point and mark\) are assumed to be set in advance. | |
836 | Each region is enlarged to contain full lines. | |
837 | This function is effective for large regions, over 100-200 | |
f1a5512a | 838 | lines. For small regions, use `ediff-regions-wordwise'." |
0f0b0a86 KH |
839 | (interactive |
840 | (let (bf) | |
841 | (list (setq bf (read-buffer "Region A's buffer: " | |
842 | (ediff-other-buffer "") t)) | |
843 | (read-buffer "Region B's buffer: " | |
844 | (progn | |
845 | ;; realign buffers so that two visible bufs will be | |
846 | ;; at the top | |
847 | (save-window-excursion (other-window 1)) | |
848 | (ediff-other-buffer bf)) | |
849 | t)))) | |
fcbadd58 | 850 | (if (not (ediff-buffer-live-p buffer-A)) |
0f0b0a86 | 851 | (error "Buffer %S doesn't exist" buffer-A)) |
fcbadd58 | 852 | (if (not (ediff-buffer-live-p buffer-B)) |
0f0b0a86 KH |
853 | (error "Buffer %S doesn't exist" buffer-B)) |
854 | ||
855 | (let (reg-A-beg reg-A-end reg-B-beg reg-B-end) | |
856 | (save-excursion | |
857 | (set-buffer buffer-A) | |
858 | (setq reg-A-beg (region-beginning) | |
859 | reg-A-end (region-end)) | |
860 | ;; enlarge the region to hold full lines | |
861 | (goto-char reg-A-beg) | |
862 | (beginning-of-line) | |
863 | (setq reg-A-beg (point)) | |
864 | (goto-char reg-A-end) | |
865 | (end-of-line) | |
866 | (or (eobp) (forward-char)) ; include the newline char | |
867 | (setq reg-A-end (point)) | |
fcbadd58 | 868 | |
0f0b0a86 KH |
869 | (set-buffer buffer-B) |
870 | (setq reg-B-beg (region-beginning) | |
871 | reg-B-end (region-end)) | |
872 | ;; enlarge the region to hold full lines | |
0f0b0a86 KH |
873 | (goto-char reg-B-beg) |
874 | (beginning-of-line) | |
875 | (setq reg-B-beg (point)) | |
876 | (goto-char reg-B-end) | |
877 | (end-of-line) | |
878 | (or (eobp) (forward-char)) ; include the newline char | |
879 | (setq reg-B-end (point)) | |
880 | ) ; save excursion | |
881 | ||
882 | (ediff-regions-internal | |
883 | (get-buffer buffer-A) reg-A-beg reg-A-end | |
884 | (get-buffer buffer-B) reg-B-beg reg-B-end | |
1e70790f | 885 | startup-hooks 'ediff-regions-linewise nil nil))) ; no word mode |
0f0b0a86 KH |
886 | |
887 | ;; compare region beg-A to end-A of buffer-A | |
888 | ;; to regions beg-B -- end-B in buffer-B. | |
889 | (defun ediff-regions-internal (buffer-A beg-A end-A buffer-B beg-B end-B | |
ddc90f39 MK |
890 | startup-hooks job-name word-mode |
891 | setup-parameters) | |
0f0b0a86 KH |
892 | (let ((tmp-buffer (get-buffer-create ediff-tmp-buffer)) |
893 | overl-A overl-B | |
894 | file-A file-B) | |
895 | ||
896 | ;; in case beg/end-A/B aren't markers--make them into markers | |
e756eb9f | 897 | (ediff-with-current-buffer buffer-A |
0f0b0a86 KH |
898 | (setq beg-A (move-marker (make-marker) beg-A) |
899 | end-A (move-marker (make-marker) end-A))) | |
e756eb9f | 900 | (ediff-with-current-buffer buffer-B |
0f0b0a86 KH |
901 | (setq beg-B (move-marker (make-marker) beg-B) |
902 | end-B (move-marker (make-marker) end-B))) | |
903 | ||
904 | (if (and (eq buffer-A buffer-B) | |
905 | (or (and (< beg-A end-B) (<= beg-B beg-A)) ; b-B b-A e-B | |
906 | (and (< beg-B end-A) (<= end-A end-B)))) ; b-B e-A e-B | |
907 | (progn | |
908 | (with-output-to-temp-buffer ediff-msg-buffer | |
909 | (princ " | |
910 | You have requested to compare overlapping regions of the same buffer. | |
911 | ||
912 | In this case, Ediff's highlighting may be confusing---in the same window, | |
913 | you may see highlighted regions that belong to different regions. | |
914 | ||
915 | Continue anyway? (y/n) ")) | |
916 | ||
917 | (if (y-or-n-p "Continue anyway? ") | |
918 | () | |
919 | (error "%S aborted" job-name)))) | |
920 | ||
921 | ;; make file-A | |
922 | (if word-mode | |
923 | (ediff-wordify beg-A end-A buffer-A tmp-buffer) | |
924 | (ediff-copy-to-buffer beg-A end-A buffer-A tmp-buffer)) | |
87c668b4 | 925 | (setq file-A (ediff-make-temp-file tmp-buffer "regA")) |
0f0b0a86 KH |
926 | |
927 | ;; make file-B | |
928 | (if word-mode | |
929 | (ediff-wordify beg-B end-B buffer-B tmp-buffer) | |
930 | (ediff-copy-to-buffer beg-B end-B buffer-B tmp-buffer)) | |
87c668b4 | 931 | (setq file-B (ediff-make-temp-file tmp-buffer "regB")) |
0f0b0a86 KH |
932 | |
933 | (setq overl-A (ediff-make-bullet-proof-overlay beg-A end-A buffer-A)) | |
934 | (setq overl-B (ediff-make-bullet-proof-overlay beg-B end-B buffer-B)) | |
935 | (ediff-setup buffer-A file-A | |
936 | buffer-B file-B | |
937 | nil nil ; buffer & file C | |
813f532d | 938 | (cons (` (lambda () |
b3a26225 RS |
939 | (delete-file (, file-A)) |
940 | (delete-file (, file-B)))) | |
813f532d | 941 | startup-hooks) |
ddc90f39 MK |
942 | (append |
943 | (list (cons 'ediff-word-mode word-mode) | |
944 | (cons 'ediff-narrow-bounds (list overl-A overl-B)) | |
945 | (cons 'ediff-job-name job-name)) | |
328b4b70 | 946 | setup-parameters)) |
0f0b0a86 KH |
947 | )) |
948 | ||
949 | ||
950 | ;;; Merge files and buffers | |
951 | ||
952 | ;;;###autoload | |
953 | (defalias 'ediff-merge 'ediff-merge-files) | |
954 | ||
955 | (defsubst ediff-merge-on-startup () | |
956 | (ediff-do-merge 0) | |
e756eb9f | 957 | (ediff-with-current-buffer ediff-buffer-C |
0f0b0a86 KH |
958 | (set-buffer-modified-p nil))) |
959 | ||
960 | ;;;###autoload | |
328b4b70 MK |
961 | (defun ediff-merge-files (file-A file-B |
962 | ;; MERGE-BUFFER-FILE is the file to be | |
963 | ;; associated with the merge buffer | |
964 | &optional startup-hooks merge-buffer-file) | |
0f0b0a86 KH |
965 | "Merge two files without ancestor." |
966 | (interactive | |
967 | (let ((dir-A (if ediff-use-last-dir | |
968 | ediff-last-dir-A | |
969 | default-directory)) | |
970 | dir-B f) | |
87c668b4 MK |
971 | (list (setq f (ediff-read-file-name |
972 | "File A to merge" dir-A | |
973 | (ediff-get-default-file-name))) | |
0f0b0a86 KH |
974 | (ediff-read-file-name "File B to merge" |
975 | (setq dir-B | |
976 | (if ediff-use-last-dir | |
977 | ediff-last-dir-B | |
978 | (file-name-directory f))) | |
979 | (progn | |
980 | (setq file-name-history | |
87c668b4 | 981 | (cons (ediff-abbreviate-file-name |
0f0b0a86 KH |
982 | (expand-file-name |
983 | (file-name-nondirectory f) | |
984 | dir-B)) | |
985 | file-name-history)) | |
986 | f)) | |
987 | ))) | |
988 | (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks)) | |
989 | (ediff-files-internal file-A | |
990 | (if (file-directory-p file-B) | |
991 | (expand-file-name | |
992 | (file-name-nondirectory file-A) file-B) | |
993 | file-B) | |
994 | nil ; file-C | |
995 | startup-hooks | |
328b4b70 MK |
996 | 'ediff-merge-files |
997 | merge-buffer-file)) | |
0f0b0a86 KH |
998 | |
999 | ;;;###autoload | |
1000 | (defun ediff-merge-files-with-ancestor (file-A file-B file-ancestor | |
328b4b70 MK |
1001 | &optional |
1002 | startup-hooks | |
1003 | ;; MERGE-BUFFER-FILE is the file | |
1004 | ;; to be associated with the | |
1005 | ;; merge buffer | |
1006 | merge-buffer-file) | |
0f0b0a86 KH |
1007 | "Merge two files with ancestor." |
1008 | (interactive | |
1009 | (let ((dir-A (if ediff-use-last-dir | |
1010 | ediff-last-dir-A | |
1011 | default-directory)) | |
1012 | dir-B dir-ancestor f ff) | |
87c668b4 MK |
1013 | (list (setq f (ediff-read-file-name |
1014 | "File A to merge" dir-A | |
1015 | (ediff-get-default-file-name))) | |
0f0b0a86 KH |
1016 | (setq ff (ediff-read-file-name "File B to merge" |
1017 | (setq dir-B | |
1018 | (if ediff-use-last-dir | |
1019 | ediff-last-dir-B | |
1020 | (file-name-directory f))) | |
1021 | (progn | |
1022 | (setq file-name-history | |
1023 | (cons | |
87c668b4 | 1024 | (ediff-abbreviate-file-name |
0f0b0a86 KH |
1025 | (expand-file-name |
1026 | (file-name-nondirectory f) | |
1027 | dir-B)) | |
1028 | file-name-history)) | |
1029 | f))) | |
1030 | (ediff-read-file-name "Ancestor file" | |
1031 | (setq dir-ancestor | |
1032 | (if ediff-use-last-dir | |
1033 | ediff-last-dir-ancestor | |
1034 | (file-name-directory ff))) | |
1035 | (progn | |
1036 | (setq file-name-history | |
87c668b4 | 1037 | (cons (ediff-abbreviate-file-name |
0f0b0a86 KH |
1038 | (expand-file-name |
1039 | (file-name-nondirectory ff) | |
1040 | dir-ancestor)) | |
1041 | file-name-history)) | |
1042 | ff)) | |
1043 | ))) | |
1044 | (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks)) | |
1045 | (ediff-files-internal file-A | |
1046 | (if (file-directory-p file-B) | |
1047 | (expand-file-name | |
1048 | (file-name-nondirectory file-A) file-B) | |
1049 | file-B) | |
1050 | file-ancestor | |
1051 | startup-hooks | |
328b4b70 MK |
1052 | 'ediff-merge-files-with-ancestor |
1053 | merge-buffer-file)) | |
0f0b0a86 KH |
1054 | |
1055 | ;;;###autoload | |
1056 | (defalias 'ediff-merge-with-ancestor 'ediff-merge-files-with-ancestor) | |
1057 | ||
1058 | ;;;###autoload | |
328b4b70 MK |
1059 | (defun ediff-merge-buffers (buffer-A buffer-B |
1060 | &optional | |
1061 | ;; MERGE-BUFFER-FILE is the file to be | |
1062 | ;; associated with the merge buffer | |
1063 | startup-hooks job-name merge-buffer-file) | |
0f0b0a86 KH |
1064 | "Merge buffers without ancestor." |
1065 | (interactive | |
1066 | (let (bf) | |
1067 | (list (setq bf (read-buffer "Buffer A to merge: " | |
1068 | (ediff-other-buffer "") t)) | |
1069 | (read-buffer "Buffer B to merge: " | |
1070 | (progn | |
1071 | ;; realign buffers so that two visible bufs will be | |
1072 | ;; at the top | |
1073 | (save-window-excursion (other-window 1)) | |
1074 | (ediff-other-buffer bf)) | |
1075 | t)))) | |
1076 | ||
1077 | (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks)) | |
1078 | (or job-name (setq job-name 'ediff-merge-buffers)) | |
1079 | (ediff-buffers-internal | |
328b4b70 | 1080 | buffer-A buffer-B nil startup-hooks job-name merge-buffer-file)) |
0f0b0a86 KH |
1081 | |
1082 | ;;;###autoload | |
328b4b70 MK |
1083 | (defun ediff-merge-buffers-with-ancestor (buffer-A buffer-B buffer-ancestor |
1084 | &optional | |
1085 | startup-hooks | |
1086 | job-name | |
1087 | ;; MERGE-BUFFER-FILE is the | |
1088 | ;; file to be associated | |
1089 | ;; with the merge buffer | |
1090 | merge-buffer-file) | |
0f0b0a86 KH |
1091 | "Merge buffers with ancestor." |
1092 | (interactive | |
1093 | (let (bf bff) | |
1094 | (list (setq bf (read-buffer "Buffer A to merge: " | |
1095 | (ediff-other-buffer "") t)) | |
1096 | (setq bff (read-buffer "Buffer B to merge: " | |
1097 | (progn | |
1098 | ;; realign buffers so that two visible | |
1099 | ;; bufs will be at the top | |
1100 | (save-window-excursion (other-window 1)) | |
1101 | (ediff-other-buffer bf)) | |
1102 | t)) | |
1103 | (read-buffer "Ancestor buffer: " | |
1104 | (progn | |
1105 | ;; realign buffers so that three visible | |
1106 | ;; bufs will be at the top | |
1107 | (save-window-excursion (other-window 1)) | |
1108 | (ediff-other-buffer (list bf bff))) | |
1109 | t) | |
1110 | ))) | |
1111 | ||
1112 | (setq startup-hooks (cons 'ediff-merge-on-startup startup-hooks)) | |
1113 | (or job-name (setq job-name 'ediff-merge-buffers-with-ancestor)) | |
1114 | (ediff-buffers-internal | |
328b4b70 | 1115 | buffer-A buffer-B buffer-ancestor startup-hooks job-name merge-buffer-file)) |
0f0b0a86 KH |
1116 | |
1117 | ||
1118 | ;;;###autoload | |
328b4b70 MK |
1119 | (defun ediff-merge-revisions (&optional file startup-hooks merge-buffer-file) |
1120 | ;; MERGE-BUFFER-FILE is the file to be associated with the merge buffer | |
0f0b0a86 | 1121 | "Run Ediff by merging two revisions of a file. |
87c668b4 MK |
1122 | The file is the optional FILE argument or the file visited by the current |
1123 | buffer." | |
1124 | (interactive) | |
87c668b4 | 1125 | (if (stringp file) (find-file file)) |
4ae69eac | 1126 | (let (rev1 rev2) |
87c668b4 MK |
1127 | (setq rev1 |
1128 | (read-string | |
1129 | (format | |
1130 | "Version 1 to merge (default: %s's latest version): " | |
1131 | (if (stringp file) | |
1132 | (file-name-nondirectory file) "current buffer"))) | |
1133 | rev2 | |
1134 | (read-string | |
1135 | (format | |
1136 | "Version 2 to merge (default: %s): " | |
1137 | (if (stringp file) | |
1138 | (file-name-nondirectory file) "current buffer")))) | |
4ae69eac MK |
1139 | (ediff-load-version-control) |
1140 | ;; ancestor-revision=nil | |
1141 | (funcall | |
92c51e07 | 1142 | (intern (format "ediff-%S-merge-internal" ediff-version-control-package)) |
328b4b70 | 1143 | rev1 rev2 nil startup-hooks merge-buffer-file))) |
0f0b0a86 KH |
1144 | |
1145 | ||
1146 | ;;;###autoload | |
328b4b70 MK |
1147 | (defun ediff-merge-revisions-with-ancestor (&optional |
1148 | file startup-hooks | |
1149 | ;; MERGE-BUFFER-FILE is the file to | |
1150 | ;; be associated with the merge | |
1151 | ;; buffer | |
1152 | merge-buffer-file) | |
87c668b4 MK |
1153 | "Run Ediff by merging two revisions of a file with a common ancestor. |
1154 | The file is the the optional FILE argument or the file visited by the current | |
1155 | buffer." | |
1156 | (interactive) | |
87c668b4 | 1157 | (if (stringp file) (find-file file)) |
4ae69eac | 1158 | (let (rev1 rev2 ancestor-rev) |
87c668b4 MK |
1159 | (setq rev1 |
1160 | (read-string | |
1161 | (format | |
1162 | "Version 1 to merge (default: %s's latest version): " | |
1163 | (if (stringp file) | |
1164 | (file-name-nondirectory file) "current buffer"))) | |
1165 | rev2 | |
1166 | (read-string | |
1167 | (format | |
1168 | "Version 2 to merge (default: %s): " | |
1169 | (if (stringp file) | |
1170 | (file-name-nondirectory file) "current buffer"))) | |
1171 | ancestor-rev | |
1172 | (read-string | |
1173 | (format | |
1174 | "Ancestor version (default: %s): " | |
1175 | (if (stringp file) | |
1176 | (file-name-nondirectory file) "current buffer")))) | |
4ae69eac MK |
1177 | (ediff-load-version-control) |
1178 | (funcall | |
92c51e07 | 1179 | (intern (format "ediff-%S-merge-internal" ediff-version-control-package)) |
328b4b70 | 1180 | rev1 rev2 ancestor-rev startup-hooks merge-buffer-file))) |
4ae69eac MK |
1181 | |
1182 | ;;;###autoload | |
1183 | (defun run-ediff-from-cvs-buffer (pos) | |
1184 | "Run Ediff-merge on appropriate revisions of the selected file. | |
ddc90f39 | 1185 | First run after `M-x cvs-update'. Then place the cursor on a line describing a |
4ae69eac MK |
1186 | file and then run `run-ediff-from-cvs-buffer'." |
1187 | (interactive "d") | |
1188 | (ediff-load-version-control) | |
1189 | (let ((tin (tin-locate cvs-cookie-handle pos))) | |
1190 | (if tin | |
1191 | (cvs-run-ediff-on-file-descriptor tin) | |
1192 | (error "There is no file to merge")))) | |
0f0b0a86 KH |
1193 | |
1194 | ||
1195 | ;;; Apply patch | |
0f0b0a86 | 1196 | |
bbe6126c MK |
1197 | ;;;###autoload |
1198 | (defun ediff-patch-file () | |
1199 | "Run Ediff by patching SOURCE-FILENAME." | |
1200 | ;; This now returns the control buffer | |
1201 | (interactive) | |
1202 | (let (source-dir source-file patch-buf) | |
1203 | (require 'ediff-ptch) | |
1204 | (setq patch-buf (ediff-get-patch-buffer)) | |
1205 | (setq source-dir (cond (ediff-use-last-dir ediff-last-dir-patch) | |
1206 | ((and (not ediff-patch-default-directory) | |
1207 | (buffer-file-name patch-buf)) | |
1208 | (file-name-directory | |
1209 | (expand-file-name | |
1210 | (buffer-file-name patch-buf)))) | |
1211 | (t default-directory))) | |
1212 | (setq source-file | |
1213 | ;; the default is the directory, not the visited file name | |
bd698e98 MK |
1214 | (ediff-read-file-name |
1215 | "Which file to patch? " source-dir (ediff-get-default-file-name))) | |
bbe6126c | 1216 | (ediff-dispatch-file-patching-job patch-buf source-file))) |
0f0b0a86 | 1217 | |
bbe6126c MK |
1218 | ;;;###autoload |
1219 | (defun ediff-patch-buffer () | |
1220 | "Run Ediff by patching BUFFER-NAME." | |
1221 | (interactive) | |
1222 | (let (patch-buf) | |
1223 | (require 'ediff-ptch) | |
1224 | (setq patch-buf (ediff-get-patch-buffer)) | |
1225 | (ediff-patch-buffer-internal | |
1226 | patch-buf | |
1227 | (read-buffer "Which buffer to patch? " | |
1228 | (cond ((eq patch-buf (current-buffer)) | |
bd698e98 | 1229 | (ediff-other-buffer (current-buffer))) |
bbe6126c MK |
1230 | (t (current-buffer))) |
1231 | 'must-match)))) | |
0f0b0a86 | 1232 | |
bbe6126c MK |
1233 | ;;;###autoload |
1234 | (defalias 'epatch 'ediff-patch-file) | |
1235 | ;;;###autoload | |
1236 | (defalias 'epatch-buffer 'ediff-patch-buffer) | |
0f0b0a86 KH |
1237 | |
1238 | ||
813f532d | 1239 | |
0f0b0a86 | 1240 | \f |
813f532d RS |
1241 | ;;; Versions Control functions |
1242 | ||
1243 | ;;;###autoload | |
87c668b4 MK |
1244 | (defun ediff-revision (&optional file startup-hooks) |
1245 | "Run Ediff by comparing versions of a file. | |
1246 | The file is an optional FILE argument or the file visited by the current | |
1247 | buffer. Use `vc.el' or `rcs.el' depending on `ediff-version-control-package'." | |
1248 | ;; if buffer is non-nil, use that buffer instead of the current buffer | |
f1a5512a | 1249 | (interactive "P") |
87c668b4 | 1250 | (if (stringp file) (find-file file)) |
f1a5512a | 1251 | (let (rev1 rev2) |
87c668b4 MK |
1252 | (setq rev1 |
1253 | (read-string | |
1254 | (format "Version 1 to compare (default: %s's latest version): " | |
1255 | (if (stringp file) | |
1256 | (file-name-nondirectory file) "current buffer"))) | |
1257 | rev2 | |
1258 | (read-string | |
1259 | (format "Version 2 to compare (default: %s): " | |
1260 | (if (stringp file) | |
1261 | (file-name-nondirectory file) "current buffer")))) | |
f1a5512a KH |
1262 | (ediff-load-version-control) |
1263 | (funcall | |
92c51e07 | 1264 | (intern (format "ediff-%S-internal" ediff-version-control-package)) |
87c668b4 | 1265 | rev1 rev2 startup-hooks) |
f1a5512a | 1266 | )) |
1e70790f MK |
1267 | |
1268 | ||
1269 | ;;;###autoload | |
1270 | (defalias 'erevision 'ediff-revision) | |
0f0b0a86 | 1271 | |
0f0b0a86 KH |
1272 | |
1273 | ;; Test if version control package is loaded and load if not | |
1274 | ;; Is SILENT is non-nil, don't report error if package is not found. | |
1275 | (defun ediff-load-version-control (&optional silent) | |
4ae69eac | 1276 | (require 'ediff-vers) |
0f0b0a86 KH |
1277 | (or (featurep ediff-version-control-package) |
1278 | (if (locate-library (symbol-name ediff-version-control-package)) | |
1279 | (progn | |
1280 | (message "") ; kill the message from `locate-library' | |
87c668b4 | 1281 | (require ediff-version-control-package)) |
0f0b0a86 | 1282 | (or silent |
f1a5512a | 1283 | (error "Version control package %S.el not found. Use vc.el instead" |
0f0b0a86 | 1284 | ediff-version-control-package))))) |
87c668b4 | 1285 | |
b3a26225 | 1286 | |
138df2ce MK |
1287 | ;;;###autoload |
1288 | (defun ediff-version () | |
1289 | "Return string describing the version of Ediff. | |
1290 | When called interactively, displays the version." | |
1291 | (interactive) | |
1292 | (if (interactive-p) | |
1293 | (message (ediff-version)) | |
1294 | (format "Ediff %s of %s" ediff-version ediff-date))) | |
1295 | ||
813f532d | 1296 | |
4ae69eac | 1297 | ;;;###autoload |
92c51e07 MK |
1298 | (defun ediff-documentation (&optional node) |
1299 | "Display Ediff's manual. | |
1300 | With optional NODE, goes to that node." | |
4ae69eac MK |
1301 | (interactive) |
1302 | (let ((ctl-window ediff-control-window) | |
1303 | (ctl-buf ediff-control-buffer)) | |
1304 | ||
1305 | (ediff-skip-unsuitable-frames) | |
1306 | (condition-case nil | |
1307 | (progn | |
1308 | (pop-to-buffer (get-buffer-create "*info*")) | |
1309 | (info (if ediff-xemacs-p "ediff.info" "ediff")) | |
92c51e07 MK |
1310 | (if node |
1311 | (Info-goto-node node) | |
1312 | (message "Type `i' to search for a specific topic")) | |
1313 | (raise-frame (selected-frame))) | |
4ae69eac | 1314 | (error (beep 1) |
bbe6126c | 1315 | (with-output-to-temp-buffer ediff-msg-buffer |
92c51e07 | 1316 | (princ ediff-BAD-INFO)) |
4ae69eac MK |
1317 | (if (window-live-p ctl-window) |
1318 | (progn | |
1319 | (select-window ctl-window) | |
1320 | (set-window-buffer ctl-window ctl-buf))))))) | |
1321 | ||
1322 | ||
1323 | ||
1324 | ||
1325 | ;;; Local Variables: | |
1326 | ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun) | |
e756eb9f MK |
1327 | ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1) |
1328 | ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body)) | |
4ae69eac MK |
1329 | ;;; End: |
1330 | ||
0f0b0a86 | 1331 | (require 'ediff-util) |
813f532d RS |
1332 | |
1333 | ;;; ediff.el ends here |