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