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