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