(PENTIUM:CPunix:4.0*:*): New case.
[emacs/old-mirror.git] / lisp / ediff-mult.el
blob2a88f9dc036b0962b5030a370a9f1f983fc6ffba
1 ;;; ediff-mult.el --- support for multi-file/multi-buffer processing in Ediff
3 ;; Copyright (C) 1995, 1996 Free Software Foundation, Inc.
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
24 ;;; Commentary:
26 ;; Users are encouraged to add functionality to this file.
27 ;; The present file contains all the infrastructure needed for that.
29 ;; Generally, to to implement a new multisession capability within Ediff,
30 ;; you need to tell it
32 ;; 1. How to display the session group buffer.
33 ;; This function must indicate which Ediff sessions are active (+) and
34 ;; which are finished (-).
35 ;; See ediff-redraw-directory-group-buffer for an example.
36 ;; In all likelihood, ediff-redraw-directory-group-buffer can be used
37 ;; directly or after a small modification.
38 ;; 2. What action to take when the user clicks button 2 or types v,e, or
39 ;; RET. See ediff-filegroup-action.
40 ;; 3. Provide a list of pairs or triples of file names (or buffers,
41 ;; depending on the particular Ediff operation you want to invoke)
42 ;; in the following format:
43 ;; (descriptor (obj1 obj2 obj3) (...) ...)
44 ;; Actually, the format of this list is pretty much up to the
45 ;; developer. The only thing is that it must be a list of lists,
46 ;; and the first list must describe the meta session, and subsequent
47 ;; elements must describe individual sessions.
48 ;; This descriptor must be a list of two, three, or four elements (nil
49 ;; or string). The function ediff-redraw-registry-buffer displays the
50 ;; second through last of these in the registry buffer.
51 ;; Also, keep in mind that the function ediff-prepare-meta-buffer
52 ;; (which see) prepends the session group buffer to the descriptor and
53 ;; nil in front of each subsequent list (i.e., the above list
54 ;; will become
55 ;; ((meta-buf descriptor) (nil obj1 obj2 obj3) (nil ...) ...)
56 ;; Ediff expects that your function (in 2 above) will arrange to
57 ;; replace this prepended nil (via setcar) with the actual ediff
58 ;; control buffer associated with an appropriate Ediff session.
59 ;; This is arranged through internal startup hooks that can be passed
60 ;; to any of Ediff major entries (such as ediff-files, epatch, etc.).
61 ;; See how this is done in ediff-filegroup-action.
63 ;; Session descriptions are of the form (obj1 obj2 obj3), which
64 ;; describe objects relevant to the session. Usually they are names of
65 ;; files, but sometimes they may be other things. For instance, obj3 is
66 ;; nil for jobs that involve only two files. For patch jobs, obj2 and
67 ;; obj3 are markers that specify the patch corresponding to the file
68 ;; (whose name is obj1).
69 ;; 4. Write a function that makes a call to ediff-prepare-meta-buffer
70 ;; passing all this info.
71 ;; You may be able to use ediff-directories-internal as a template.
72 ;; 5. If you intend to add several related pieces of functionality,
73 ;; you may want to keep the function in 4 as an internal version
74 ;; and then write several top-level interactive functions that call it
75 ;; with different parameters.
76 ;; See how ediff-directories, ediff-merge-directories, and
77 ;; ediff-merge-directories-with-ancestor all use
78 ;; ediff-directories-internal.
80 ;; A useful addition here could be session groups selected by patterns
81 ;; (which are different in each directory). For instance, one may want to
82 ;; compare files of the form abc{something}.c to files old{something}.d
83 ;; which may be in the same or different directories. Or, one may want to
84 ;; compare all files of the form {something} to files of the form {something}~.
86 ;; Implementing this requires writing an collating function, which should pair
87 ;; up appropriate files. It will also require a generalization of the functions
88 ;; that do the layout of the meta- and differences buffers and of
89 ;; ediff-filegroup-action.
91 ;;; Code:
93 (require 'ediff-init)
95 ;; meta-buffer
96 (ediff-defvar-local ediff-meta-buffer nil "")
97 (ediff-defvar-local ediff-parent-meta-buffer nil "")
98 ;; the registry buffer
99 (defvar ediff-registry-buffer nil)
101 (defconst ediff-meta-buffer-message "This is an Ediff Session Group Panel: %s
103 Useful commands:
104 button2, `v', RET over a session line: start that Ediff session
105 `M':\tin any session invoked from here, brings back this group panel
106 `R':\tdisplay the registry of active Ediff sessions
107 `h':\tmark session for hiding (toggle)
108 `x':\thide marked sessions; with prefix arg--unhide hidden sessions
109 `m':\tmark session for a non-hiding operation (toggle)
110 SPC:\tnext session
111 DEL:\tprevious session
112 `E':\tbrowse Ediff on-line manual
113 `q':\tquit this session group
116 (ediff-defvar-local ediff-meta-buffer-map nil
117 "The keymap for the meta buffer.")
118 (defvar ediff-dir-diffs-buffer-map (make-sparse-keymap)
119 "The keymap to be installed in the buffer showing differences between
120 directories.")
122 ;; Variable specifying the action to take when the use invokes ediff in the
123 ;; meta buffer. This is usually ediff-registry-action or ediff-filegroup-action
124 (ediff-defvar-local ediff-meta-action-function nil "")
125 ;; Tells ediff-update-meta-buffer how to redraw it
126 (ediff-defvar-local ediff-meta-redraw-function nil "")
127 ;; Tells ediff-filegroup-action and similar procedures how to invoke Ediff for
128 ;; the sessions in a given session group
129 (ediff-defvar-local ediff-session-action-function nil "")
131 (ediff-defvar-local ediff-metajob-name nil "")
133 ;; buffer used to collect custom diffs from individual sessions in the group
134 (ediff-defvar-local ediff-meta-diff-buffer nil "")
136 ;; history var to use for filtering groups
137 (defvar ediff-filtering-regexp-history nil "")
139 ;; This has the form ((ctl-buf file1 file2) (stl-buf file1 file2) ...)
140 ;; If ctl-buf is nil, the file-pair wasn't processed yet. If it is
141 ;; killed-buffer object, the file pair has been processed. If it is a live
142 ;; buffer, this means ediff is still working on the pair
143 (ediff-defvar-local ediff-meta-list nil "")
146 ;; the difference list between directories in a directory session group
147 (ediff-defvar-local ediff-dir-difference-list nil "")
148 (ediff-defvar-local ediff-dir-diffs-buffer nil "")
150 ;; The registry of Ediff sessions. A list of control buffers.
151 (defvar ediff-session-registry nil)
153 (defvar ediff-registry-setup-hook nil
154 "*Hooks run just after the registry control panel is set up.")
155 (defvar ediff-session-group-setup-hook nil
156 "*Hooks run just after a meta-buffer controlling a session group, such as
157 ediff-directories, is run.")
158 (defvar ediff-quit-session-group-hook nil
159 "*Hooks run just before exiting a session group.")
160 (defvar ediff-show-registry-hook nil
161 "*Hooks run just after the registry buffer is shown.")
162 (defvar ediff-show-session-group-hook nil
163 "*Hooks run just after a session group buffer is shown.")
165 ;; buffer holding the multi-file patch. local to the meta buffer
166 (ediff-defvar-local ediff-meta-patchbufer nil "")
168 ;;; API for ediff-meta-list
170 ;; group buffer/regexp
171 (defun ediff-get-group-buffer (meta-list)
172 (nth 0 (car meta-list)))
174 (defun ediff-get-group-regexp (meta-list)
175 (nth 1 (car meta-list)))
176 ;; group objects
177 (defun ediff-get-group-objA (meta-list)
178 (nth 2 (car meta-list)))
179 (defun ediff-get-group-objB (meta-list)
180 (nth 3 (car meta-list)))
181 (defun ediff-get-group-objC (meta-list)
182 (nth 4 (car meta-list)))
183 (defun ediff-get-group-merge-autostore-dir (meta-list)
184 (nth 5 (car meta-list)))
186 ;; session buffer
187 (defun ediff-get-session-buffer (elt)
188 (nth 0 elt))
189 (defun ediff-get-session-status (elt)
190 (nth 1 elt))
191 (defun ediff-set-session-status (session-info new-status)
192 (setcar (cdr session-info) new-status))
193 ;; session objects
194 (defun ediff-get-session-objA (elt)
195 (nth 2 elt))
196 (defun ediff-get-session-objB (elt)
197 (nth 3 elt))
198 (defun ediff-get-session-objC (elt)
199 (nth 4 elt))
200 (defun ediff-get-session-objA-name (elt)
201 (car (nth 2 elt)))
202 (defun ediff-get-session-objB-name (elt)
203 (car (nth 3 elt)))
204 (defun ediff-get-session-objC-name (elt)
205 (car (nth 4 elt)))
206 ;; equality indicators
207 (defsubst ediff-get-file-eqstatus (elt)
208 (nth 1 elt))
209 (defsubst ediff-set-file-eqstatus (elt value)
210 (setcar (cdr elt) value))
212 ;; set up the keymap in the meta buffer
213 (defun ediff-setup-meta-map()
214 (setq ediff-meta-buffer-map (make-sparse-keymap))
215 (suppress-keymap ediff-meta-buffer-map)
216 (define-key ediff-meta-buffer-map "q" 'ediff-quit-meta-buffer)
217 (define-key ediff-meta-buffer-map "R" 'ediff-show-registry)
218 (define-key ediff-meta-buffer-map "E" 'ediff-documentation)
219 (define-key ediff-meta-buffer-map "v" ediff-meta-action-function)
220 (define-key ediff-meta-buffer-map "\C-m" ediff-meta-action-function)
221 (define-key ediff-meta-buffer-map " " 'ediff-next-meta-item)
222 (define-key ediff-meta-buffer-map "\C-?" 'ediff-previous-meta-item)
223 (define-key ediff-meta-buffer-map [delete] 'ediff-previous-meta-item)
224 (define-key ediff-meta-buffer-map [backspace] 'ediff-previous-meta-item)
225 (or (ediff-one-filegroup-metajob)
226 (define-key ediff-meta-buffer-map "=" 'ediff-meta-mark-equal-files))
227 (if ediff-no-emacs-help-in-control-buffer
228 (define-key ediff-meta-buffer-map "\C-h" 'ediff-previous-meta-item))
229 (if ediff-emacs-p
230 (define-key ediff-meta-buffer-map [mouse-2] ediff-meta-action-function)
231 (define-key ediff-meta-buffer-map [button2] ediff-meta-action-function))
233 (use-local-map ediff-meta-buffer-map))
235 (defun ediff-meta-mode ()
236 "This mode controls all operations on Ediff session groups.
237 It is entered through one of the following commands:
238 `ediff-directories'
239 `edirs'
240 `ediff-directories3'
241 `edirs3'
242 `ediff-merge-directories'
243 `edirs-merge'
244 `ediff-merge-directories-with-ancestor'
245 `edirs-merge-with-ancestor'
246 `ediff-directory-revisions'
247 `edir-revisions'
248 `ediff-merge-directory-revisions'
249 `edir-merge-revisions'
250 `ediff-merge-directory-revisions-with-ancestor'
251 `edir-merge-revisions-with-ancestor'
253 Commands:
254 \\{ediff-meta-buffer-map}"
255 (kill-all-local-variables)
256 (setq major-mode 'ediff-meta-mode)
257 (setq mode-name "MetaEdiff"))
260 ;; the keymap for the buffer showing directory differences
261 (suppress-keymap ediff-dir-diffs-buffer-map)
262 (define-key ediff-dir-diffs-buffer-map "q" 'ediff-bury-dir-diffs-buffer)
263 (define-key ediff-dir-diffs-buffer-map " " 'next-line)
264 (define-key ediff-dir-diffs-buffer-map "\C-?" 'previous-line)
265 (define-key ediff-dir-diffs-buffer-map [delete] 'previous-line)
266 (define-key ediff-dir-diffs-buffer-map [backspace] 'previous-line)
268 (defun ediff-next-meta-item (count)
269 "Move to the next item in Ediff registry or session group buffer.
270 Moves in circular fashion. With numeric prefix arg, skip this many items."
271 (interactive "p")
272 (or count (setq count 1))
273 (while (< 0 count)
274 (setq count (1- count))
275 (ediff-next-meta-item1)))
277 ;; Move to the next meta item
278 (defun ediff-next-meta-item1 ()
279 (let (pos)
280 (setq pos (ediff-next-meta-overlay-start (point)))
281 ;;; ;; skip deleted
282 ;;; (while (memq (ediff-get-session-status
283 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
284 ;;; '(?H ?I))
285 ;;; (setq pos (ediff-next-meta-overlay-start pos)))
287 (if pos (goto-char pos))
288 (if (eq ediff-metajob-name 'ediff-registry)
289 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
290 (search-forward "*Ediff" nil t))
291 (skip-chars-backward "a-zA-Z*"))
292 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
293 (backward-char 1)))))
296 (defun ediff-previous-meta-item (count)
297 "Move to the previous item in Ediff registry or session group buffer.
298 Moves in circular fashion. With numeric prefix arg, skip this many items."
299 (interactive "p")
300 (or count (setq count 1))
301 (while (< 0 count)
302 (setq count (1- count))
303 (ediff-previous-meta-item1)))
305 (defun ediff-previous-meta-item1 ()
306 (let (pos)
307 (setq pos (ediff-previous-meta-overlay-start (point)))
308 ;;; ;; skip deleted
309 ;;; (while (ediff-get-session-status
310 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
311 ;;; (setq pos (ediff-previous-meta-overlay-start pos)))
313 (if pos (goto-char pos))
314 (if (eq ediff-metajob-name 'ediff-registry)
315 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
316 (search-forward "*Ediff" nil t))
317 (skip-chars-backward "a-zA-Z*"))
318 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
319 (backward-char 1)))
322 (defsubst ediff-add-slash-if-directory (dir file)
323 (if (file-directory-p (concat dir file))
324 (file-name-as-directory file)
325 file))
328 ;; DIR1, DIR2, DIR3 are directories. DIR3 can be nil.
329 ;; OUTPUT-DIR is a directory for auto-storing the results of merge jobs.
330 ;; Can be nil.
331 ;; REGEXP is a regexp used to filter out files in the directories.
332 ;; If a file is a directory in dir1 but not dir2 (or vice versa), it is not
333 ;; included in the intersection. However, a regular file that is a dir in dir3
334 ;; is included, since dir3 files are supposed to be ancestors for merging.
335 ;; Returns a list of the form:
336 ;; ((dir1 dir2 dir3) (f1 f2 f3) (f1 f2 f3) ...)
337 ;; dir3, f3 can be nil if intersecting only 2 directories.
338 ;; If COMPARISON-FUNC is given, use it. Otherwise, use string=
339 ;; DIFF-VAR contains the name of the variable in which to return the
340 ;; difference list (which represents the differences among the contents of
341 ;; directories). The diff list is of the form:
342 ;; ((dir1 dir2 dir3) (file . num) (file . num)...)
343 ;; where num encodes the set of dirs where the file is found:
344 ;; 2 - only dir1; 3 - only dir2; 5 - only dir3; 6 - dir1&2; 10 - dir1&3; etc.
345 (defun ediff-intersect-directories (jobname
346 diff-var regexp dir1 dir2
347 &optional
348 dir3 merge-autostore-dir comparison-func)
349 (setq comparison-func (or comparison-func 'string=))
350 (let (lis1 lis2 lis3 common auxdir1 auxdir2 auxdir3 difflist)
352 (setq auxdir1 (file-name-as-directory dir1)
353 lis1 (directory-files auxdir1 nil regexp)
354 lis1 (delete "." lis1)
355 lis1 (delete ".." lis1)
356 lis1 (mapcar
357 (function
358 (lambda (elt)
359 (ediff-add-slash-if-directory auxdir1 elt)))
360 lis1)
361 auxdir2 (file-name-as-directory dir2)
362 lis2 (mapcar
363 (function
364 (lambda (elt)
365 (ediff-add-slash-if-directory auxdir2 elt)))
366 (directory-files auxdir2 nil regexp)))
368 (if (stringp dir3)
369 (setq auxdir3 (file-name-as-directory dir3)
370 lis3 (mapcar
371 (function
372 (lambda (elt)
373 (ediff-add-slash-if-directory auxdir3 elt)))
374 (directory-files auxdir3 nil regexp))))
376 (if (stringp merge-autostore-dir)
377 (setq merge-autostore-dir
378 (file-name-as-directory merge-autostore-dir)))
379 (setq common (ediff-intersection lis1 lis2 comparison-func))
381 ;; In merge with ancestor jobs, we don't intersect with lis3.
382 ;; If there is no ancestor, we'll offer to merge without the ancestor.
383 ;; So, we intersect with lis3 only when we are doing 3-way file comparison
384 (if (and lis3 (ediff-comparison-metajob3 jobname))
385 (setq common (ediff-intersection common lis3 comparison-func)))
387 ;; copying is needed because sort sorts via side effects
388 (setq common (sort (ediff-copy-list common) 'string-lessp))
390 ;; compute difference list
391 (setq difflist (ediff-set-difference
392 (ediff-union (ediff-union lis1 lis2 comparison-func)
393 lis3
394 comparison-func)
395 common
396 comparison-func)
397 difflist (delete "." difflist)
398 ;; copying is needed because sort sorts via side effects
399 difflist (sort (ediff-copy-list (delete ".." difflist))
400 'string-lessp))
402 (setq difflist (mapcar (function (lambda (elt) (cons elt 1))) difflist))
404 ;; check for files belonging to lis1/2/3
405 (mapcar (function (lambda (elt)
406 (if (member (car elt) lis1)
407 (setcdr elt (* (cdr elt) 2)))
408 (if (member (car elt) lis2)
409 (setcdr elt (* (cdr elt) 3)))
410 (if (member (car elt) lis3)
411 (setcdr elt (* (cdr elt) 5)))
413 difflist)
414 (setq difflist (cons (list regexp auxdir1 auxdir2 auxdir3) difflist))
416 ;; return the difference list back to the calling function
417 (set diff-var difflist)
419 ;; return result
420 (cons (list regexp auxdir1 auxdir2 auxdir3 merge-autostore-dir)
421 (mapcar
422 (function
423 (lambda (elt)
424 (list (concat auxdir1 elt)
425 (concat auxdir2 elt)
426 (if lis3
427 (progn
428 ;; The following is done because:
429 ;; In merging with ancestor, we don't intersect
430 ;; with lis3. So, it is possible that elt is a
431 ;; file in auxdir1/2 but a directory in auxdir3
432 ;; Or elt may not exist in auxdir3 at all.
433 ;; In the first case, we add a slash at the end.
434 ;; In the second case, we insert nil.
435 (setq elt (ediff-add-slash-if-directory auxdir3 elt))
436 (if (file-exists-p (concat auxdir3 elt))
437 (concat auxdir3 elt)))))))
438 common))
441 ;; find directory files that are under revision.
442 ;; Include subdirectories, since we may visit them recursively.
443 ;; DIR1 is the directory to inspect.
444 ;; OUTPUT-DIR is the directory where to auto-store the results of merges. Can
445 ;; be nil.
446 (defun ediff-get-directory-files-under-revision (jobname
447 regexp dir1
448 &optional merge-autostore-dir)
449 (let (lis1 elt common auxdir1)
450 (setq auxdir1 (file-name-as-directory dir1)
451 lis1 (directory-files auxdir1 nil regexp))
453 (if (stringp merge-autostore-dir)
454 (setq merge-autostore-dir
455 (file-name-as-directory merge-autostore-dir)))
457 (while lis1
458 (setq elt (car lis1)
459 lis1 (cdr lis1))
460 ;; take files under revision control
461 (cond ((file-directory-p (concat auxdir1 elt))
462 (setq common (cons elt common)))
463 ((file-exists-p (concat auxdir1 elt ",v"))
464 (setq common (cons elt common)))
465 ((file-exists-p (concat auxdir1 "RCS/" elt ",v"))
466 (setq common (cons elt common)))
467 ) ; cond
468 ) ; while
470 (setq common (delete "." common)
471 common (delete ".." common)
472 common (delete "RCS" common))
474 ;; copying is needed because sort sorts via side effects
475 (setq common (sort (ediff-copy-list common) 'string-lessp))
477 ;; return result
478 (cons (list regexp auxdir1 nil nil merge-autostore-dir)
479 (mapcar (function (lambda (elt)
480 (list (concat auxdir1 elt)
481 nil nil)))
482 common))
486 ;; If file groups selected by patterns will ever be implemented, this
487 ;; comparison function might become useful.
488 ;;;; uses external variables PAT1 PAT2 to compare str1/2
489 ;;;; patterns must be of the form ???*???? where ??? are strings of chars
490 ;;;; containing no *.
491 ;;(defun ediff-pattern= (str1 str2)
492 ;; (let (pos11 pos12 pos21 pos22 len1 len2)
493 ;; (setq pos11 0
494 ;; len (length epat1)
495 ;; pos12 len)
496 ;; (while (and (< pos11 len) (not (= (aref epat1 pos11) ?*)))
497 ;; (setq pos11 (1+ pos11)))
498 ;; (while (and (> pos12 0) (not (= (aref epat1 (1- pos12)) ?*)))
499 ;; (setq pos12 (1- pos12)))
501 ;; (setq pos21 0
502 ;; len (length epat2)
503 ;; pos22 len)
504 ;; (while (and (< pos21 len) (not (= (aref epat2 pos21) ?*)))
505 ;; (setq pos21 (1+ pos21)))
506 ;; (while (and (> pos22 0) (not (= (aref epat2 (1- pos22)) ?*)))
507 ;; (setq pos22 (1- pos22)))
509 ;; (if (and (> (length str1) pos12) (>= pos12 pos11) (> pos11 -1)
510 ;; (> (length str2) pos22) (>= pos22 pos21) (> pos21 -1))
511 ;; (string= (substring str1 pos11 pos12)
512 ;; (substring str2 pos21 pos22)))
513 ;; ))
516 ;; Prepare meta-buffer in accordance with the argument-function and
517 ;; redraw-function. Must return the created meta-buffer.
518 (defun ediff-prepare-meta-buffer (action-func meta-list
519 meta-buffer-name redraw-function
520 jobname &optional startup-hooks)
521 (let* ((meta-buffer-name
522 (ediff-unique-buffer-name meta-buffer-name "*"))
523 (meta-buffer (get-buffer-create meta-buffer-name)))
524 (ediff-eval-in-buffer meta-buffer
526 ;; comes first
527 (ediff-meta-mode)
529 (setq ediff-meta-action-function action-func
530 ediff-meta-redraw-function redraw-function
531 ediff-metajob-name jobname
532 ediff-meta-buffer meta-buffer)
534 ;; comes after ediff-meta-action-function is set
535 (ediff-setup-meta-map)
537 (if (eq ediff-metajob-name 'ediff-registry)
538 (progn
539 (setq ediff-registry-buffer meta-buffer
540 ediff-meta-list meta-list)
541 ;; this func is used only from registry buffer, not from other
542 ;; meta-buffs.
543 (define-key
544 ediff-meta-buffer-map "M" 'ediff-show-meta-buff-from-registry))
545 ;; Initialize the meta list -- don't do this for registry.
547 ;; We prepend '(nil nil) to all elts of meta-list, except the first.
548 ;; The first nil will later be replaced by the session buffer. The
549 ;; second is reserved for session status.
551 ;; (car ediff-meta-list) gets cons'ed with the session group buffer.
552 ;; Also, session objects A/B/C are turned into lists of the form
553 ;; (obj eq-indicator). Eq-indicator is either nil or =. Initialized to
554 ;; nil. If later it is discovered that this file is = to some other
555 ;; file in the same session, eq-indicator is changed to `='.
556 ;; For now, the eq-indicator is used only for 2 and 3-file jobs.
557 (setq ediff-meta-list
558 (cons (cons meta-buffer (car meta-list))
559 (mapcar
560 (function
561 (lambda (elt)
562 (cons nil
563 (cons nil
564 ;; convert each obj to (obj nil),
565 ;; where nil is the initial value
566 ;; for eq-indicator -- see above
567 (mapcar
568 (function (lambda (obj) (list obj nil)))
569 elt)))))
570 (cdr meta-list)))))
572 (or (eq meta-buffer ediff-registry-buffer)
573 (setq ediff-session-registry
574 (cons meta-buffer ediff-session-registry)))
576 ;; redraw-function uses ediff-meta-list
577 (funcall redraw-function ediff-meta-list)
579 ;; set read-only/non-modified
580 (setq buffer-read-only t)
581 (set-buffer-modified-p nil)
583 (run-hooks 'startup-hooks)
585 ;; Arrange to show directory contents differences
586 ;; Must be after run startup-hooks, since ediff-dir-difference-list is
587 ;; set inside these hooks
588 (if (eq action-func 'ediff-filegroup-action)
589 (progn
590 ;; put meta buffer in (car ediff-dir-difference-list)
591 (setq ediff-dir-difference-list
592 (cons (cons meta-buffer (car ediff-dir-difference-list))
593 (cdr ediff-dir-difference-list)))
595 (or (ediff-one-filegroup-metajob jobname)
596 (ediff-draw-dir-diffs ediff-dir-difference-list))
597 (define-key ediff-meta-buffer-map "h" 'ediff-mark-for-hiding)
598 (define-key
599 ediff-meta-buffer-map "x" 'ediff-hide-marked-sessions)
600 (define-key ediff-meta-buffer-map "m" 'ediff-mark-for-operation)
601 (cond ((ediff-collect-diffs-metajob jobname)
602 (define-key
603 ediff-meta-buffer-map "P" 'ediff-collect-custom-diffs))
604 ((ediff-patch-metajob jobname)
605 (define-key
606 ediff-meta-buffer-map "P" 'ediff-meta-show-patch)))
607 (define-key ediff-meta-buffer-map "u" 'ediff-up-meta-hierarchy)
608 (define-key ediff-meta-buffer-map "D" 'ediff-show-dir-diffs)))
610 (if (eq ediff-metajob-name 'ediff-registry)
611 (run-hooks 'ediff-registry-setup-hook)
612 (run-hooks 'ediff-session-group-setup-hook))
613 ) ; eval in meta-buffer
614 meta-buffer))
617 ;; this is a setup function for ediff-directories
618 ;; must return meta-buffer
619 (defun ediff-redraw-directory-group-buffer (meta-list)
620 ;; extract directories
621 (let ((meta-buf (ediff-get-group-buffer meta-list))
622 (empty t)
623 (sessionNum 0)
624 regexp elt session-buf f1 f2 f3 pt
625 merge-autostore-dir
626 point tmp-list buffer-read-only)
627 (ediff-eval-in-buffer meta-buf
628 (setq point (point))
629 (erase-buffer)
630 (insert (format ediff-meta-buffer-message
631 (ediff-abbrev-jobname ediff-metajob-name)))
633 (setq regexp (ediff-get-group-regexp meta-list)
634 merge-autostore-dir (ediff-get-group-merge-autostore-dir meta-list))
636 (cond ((ediff-collect-diffs-metajob)
637 (insert
638 " `P':\tcollect custom diffs of all marked sessions\n"))
639 ((ediff-patch-metajob)
640 (insert
641 " `P':\tshow patch appropriately for the context (session or group)\n")))
642 (insert
643 " `u':\tshow parent session group\n")
644 (or (ediff-one-filegroup-metajob)
645 (insert
646 " `D':\tshow differences among directories\n"
647 " `=':\tmark identical files in each session\n\n"))
649 (if (and (stringp regexp) (> (length regexp) 0))
650 (insert (format "Filter-through regular expression: %s\n" regexp)))
651 (if (and ediff-autostore-merges (ediff-merge-metajob)
652 (stringp merge-autostore-dir))
653 (insert (format
654 "\nMerges are automatically stored in directory: %s\n"
655 merge-autostore-dir)))
656 (insert "\n
657 Size Last modified Name
658 -----------------------------------------------------------------------
662 ;; discard info on directories and regexp
663 (setq meta-list (cdr meta-list)
664 tmp-list meta-list)
665 (while (and tmp-list empty)
666 (if (and (car tmp-list)
667 (not (eq (ediff-get-session-status (car tmp-list)) ?I)))
668 (setq empty nil))
669 (setq tmp-list (cdr tmp-list)))
671 (if empty
672 (insert
673 " ****** ****** This session group has no members\n"))
675 ;; now organize file names like this:
676 ;; use-mark sizeA dateA sizeB dateB filename
677 ;; make sure directories are displayed with a trailing slash.
678 (while meta-list
679 (setq elt (car meta-list)
680 meta-list (cdr meta-list)
681 sessionNum (1+ sessionNum))
682 (if (eq (ediff-get-session-status elt) ?I)
684 (setq session-buf (ediff-get-session-buffer elt)
685 f1 (ediff-get-session-objA elt)
686 f2 (ediff-get-session-objB elt)
687 f3 (ediff-get-session-objC elt))
688 (setq pt (point))
689 ;; insert markers
690 (insert (cond ((null session-buf) " ") ; virgin session
691 ((ediff-buffer-live-p session-buf) "+") ;active session
692 (t "-"))) ; finished session
693 (insert (cond ((ediff-get-session-status elt)) ; session has status,
694 ;;; e.g., ?H, ?I
695 (t " "))) ; normal session
696 (insert " Session " (int-to-string sessionNum) ":\n")
697 (ediff-meta-insert-file-info f1)
698 (ediff-meta-insert-file-info f2)
699 (ediff-meta-insert-file-info f3)
700 (ediff-set-meta-overlay pt (point) elt)))
701 (set-buffer-modified-p nil)
702 (goto-char point)
703 meta-buf)))
705 ;; Check if this is a problematic session.
706 ;; Return nil if not. Otherwise, return symbol representing the problem
707 ;; At present, problematic sessions occur only in -with-ancestor comparisons
708 ;; when the ancestor is a directory rather than a file, or when there is no
709 ;; suitable ancestor file in the ancestor directory
710 (defun ediff-problematic-session-p (session)
711 (let ((f1 (ediff-get-session-objA-name session))
712 (f2 (ediff-get-session-objB-name session))
713 (f3 (ediff-get-session-objC-name session)))
714 (cond ((and (stringp f1) (not (file-directory-p f1))
715 (stringp f2) (not (file-directory-p f2))
716 ;; either invalid file name or a directory
717 (or (not (stringp f3)) (file-directory-p f3))
718 (ediff-ancestor-metajob))
719 ;; more may be added later
720 'ancestor-is-dir)
721 (t nil))))
723 (defun ediff-meta-insert-file-info (fileinfo)
724 (let ((fname (car fileinfo))
725 (feq (ediff-get-file-eqstatus fileinfo))
726 file-modtime file-size)
728 (cond ((not (stringp fname)) (setq file-size -2)) ; file doesn't exits
729 ((not (ediff-file-remote-p fname))
730 (if (file-exists-p fname)
731 ;; set real size and modtime
732 (setq file-size (ediff-file-size fname)
733 file-modtime (ediff-file-modtime fname))
734 (setq file-size -2))) ; file doesn't exist
735 ( t (setq file-size -1))) ; remote file
736 (if (stringp fname)
737 (insert
738 (format
739 "%s %s %-20s %s\n"
740 (if feq "=" " ") ; equality indicator
741 (format "%10s" (cond ((= file-size -1) "--")
742 ((< file-size -1) "--")
743 (t file-size)))
744 (cond ((= file-size -1) "*remote file*")
745 ((< file-size -1) "*file doesn't exist*")
746 (t (ediff-format-date (decode-time file-modtime))))
748 ;; dir names in meta lists have training slashes, so we just
749 ;; abbreviate the file name, if file exists
750 (if (and (not (stringp fname)) (< file-size -1))
751 "-------" ; file doesn't exist
752 (ediff-abbreviate-file-name fname)))))))
754 (defconst ediff-months '((1 . "Jan") (2 . "Feb") (3 . "Mar") (4 . "Apr")
755 (5 . "May") (6 . "Jun") (7 . "Jul") (8 . "Aug")
756 (9 . "Sep") (10 . "Oct") (11 . "Nov") (12 . "Dec"))
757 "Months' associative array.")
759 ;; returns 2char string
760 (defsubst ediff-fill-leading-zero (num)
761 (if (< num 10)
762 (format "0%d" num)
763 (number-to-string num)))
765 ;; TIME is like the output of decode-time
766 (defun ediff-format-date (time)
767 (format "%s %2d %4d %s:%s:%s"
768 (cdr (assoc (nth 4 time) ediff-months)) ; month
769 (nth 3 time) ; day
770 (nth 5 time) ; year
771 (ediff-fill-leading-zero (nth 2 time)) ; hour
772 (ediff-fill-leading-zero (nth 1 time)) ; min
773 (ediff-fill-leading-zero (nth 0 time)) ; sec
776 (defun ediff-draw-dir-diffs (diff-list)
777 (if (null diff-list) (error "Lost difference info on these directories"))
778 (let* ((buf-name (ediff-unique-buffer-name
779 "*Ediff File Group Differences" "*"))
780 (regexp (ediff-get-group-regexp diff-list))
781 (dir1 (ediff-abbreviate-file-name (ediff-get-group-objA diff-list)))
782 (dir2 (ediff-abbreviate-file-name (ediff-get-group-objB diff-list)))
783 (dir3 (ediff-get-group-objC diff-list))
784 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3)))
785 (meta-buf (ediff-get-group-buffer diff-list))
786 (underline (make-string 26 ?-))
787 file code
788 buffer-read-only)
789 ;; skip the directory part
790 (setq diff-list (cdr diff-list))
791 (setq ediff-dir-diffs-buffer (get-buffer-create buf-name))
792 (ediff-eval-in-buffer ediff-dir-diffs-buffer
793 (use-local-map ediff-dir-diffs-buffer-map)
794 (erase-buffer)
795 (setq ediff-meta-buffer meta-buf)
796 (insert "\t\t*** Directory Differences ***\n")
797 (insert "
798 Useful commands:
799 `q': hide this buffer
800 SPC: next line
801 DEL: previous line\n\n")
803 (if (and (stringp regexp) (> (length regexp) 0))
804 (insert (format "Filter-through regular expression: %s\n" regexp)))
805 (insert "\n")
806 (insert (format "\n%-27s%-26s"
807 (ediff-truncate-string-left
808 (ediff-abbreviate-file-name
809 (file-name-as-directory dir1))
811 (ediff-truncate-string-left
812 (ediff-abbreviate-file-name
813 (file-name-as-directory dir2))
814 25)))
815 (if dir3
816 (insert (format " %-25s\n"
817 (ediff-truncate-string-left
818 (ediff-abbreviate-file-name
819 (file-name-as-directory dir3))
820 25)))
821 (insert "\n"))
822 (insert (format "%s%s" underline underline))
823 (if (stringp dir3)
824 (insert (format "%s\n\n" underline))
825 (insert "\n\n"))
827 (if (null diff-list)
828 (insert "\n\t*** No differences ***\n"))
830 (while diff-list
831 (setq file (car (car diff-list))
832 code (cdr (car diff-list))
833 diff-list (cdr diff-list))
834 (if (= (mod code 2) 0) ; dir1
835 (insert (format "%-27s"
836 (ediff-truncate-string-left
837 (ediff-abbreviate-file-name
838 (if (file-directory-p (concat dir1 file))
839 (file-name-as-directory file)
840 file))
841 24)))
842 (insert (format "%-27s" "---")))
843 (if (= (mod code 3) 0) ; dir2
844 (insert (format "%-26s"
845 (ediff-truncate-string-left
846 (ediff-abbreviate-file-name
847 (if (file-directory-p (concat dir2 file))
848 (file-name-as-directory file)
849 file))
850 24)))
851 (insert (format "%-26s" "---")))
852 (if (stringp dir3)
853 (if (= (mod code 5) 0) ; dir3
854 (insert (format " %-25s"
855 (ediff-truncate-string-left
856 (ediff-abbreviate-file-name
857 (if (file-directory-p (concat dir3 file))
858 (file-name-as-directory file)
859 file))
860 24)))
861 (insert (format " %-25s" "---"))))
862 (insert "\n"))
863 (setq buffer-read-only t)
864 (set-buffer-modified-p nil)) ; eval in diff buffer
867 (defun ediff-bury-dir-diffs-buffer ()
868 "Bury the directory difference buffer. Display the meta buffer instead."
869 (interactive)
870 (let ((buf ediff-meta-buffer)
871 wind)
872 (bury-buffer)
873 (if (setq wind (ediff-get-visible-buffer-window buf))
874 (select-window wind)
875 (set-window-buffer (selected-window) buf))))
877 ;; executes in dir session group buffer
878 ;; show buffer differences
879 (defun ediff-show-dir-diffs ()
880 "Display differences among the directories involved in session group."
881 (interactive)
882 (if (ediff-one-filegroup-metajob)
883 (error "This command is inapplicable in the present context"))
884 (or (ediff-buffer-live-p ediff-dir-diffs-buffer)
885 (ediff-draw-dir-diffs ediff-dir-difference-list))
886 (let ((buf ediff-dir-diffs-buffer))
887 (other-window 1)
888 (set-window-buffer (selected-window) buf)
889 (goto-char (point-min))))
891 (defun ediff-up-meta-hierarchy ()
892 "Go to the parent session group buffer."
893 (interactive)
894 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
895 (ediff-show-meta-buffer ediff-parent-meta-buffer)
896 (error "This session group has no parent")))
899 ;; argument is ignored
900 (defun ediff-redraw-registry-buffer (&optional ignore)
901 (ediff-eval-in-buffer ediff-registry-buffer
902 (let ((point (point))
903 elt bufAname bufBname bufCname cur-diff total-diffs pt
904 job-name meta-list registry-list buffer-read-only)
905 (erase-buffer)
906 (insert "This is a registry of all active Ediff sessions.
908 Useful commands:
909 button2, `v', RET over a session record: switch to that session
910 `M' over a session record: display the associated session group
911 `R' in any Ediff session: display session registry
912 SPC:\tnext session
913 DEL:\tprevious session
914 `E':\tbrowse Ediff on-line manual
915 `q':\tbury registry
918 \t\tActive Ediff Sessions:
919 \t\t----------------------
922 ;; purge registry list from dead buffers
923 (mapcar (function (lambda (elt)
924 (if (not (ediff-buffer-live-p elt))
925 (setq ediff-session-registry
926 (delq elt ediff-session-registry)))))
927 ediff-session-registry)
929 (if (null ediff-session-registry)
930 (insert " ******* No active Ediff sessions *******\n"))
932 (setq registry-list ediff-session-registry)
933 (while registry-list
934 (setq elt (car registry-list)
935 registry-list (cdr registry-list))
937 (if (ediff-buffer-live-p elt)
938 (if (ediff-eval-in-buffer elt
939 (setq job-name ediff-metajob-name
940 meta-list ediff-meta-list)
941 (and ediff-metajob-name
942 (not (eq ediff-metajob-name 'ediff-registry))))
943 (progn
944 (setq pt (point))
945 (insert (format " *group*\t%s: %s\n"
946 (buffer-name elt)
947 (ediff-abbrev-jobname job-name)))
948 (insert (format "\t\t %s %s %s\n"
949 (ediff-abbreviate-file-name
950 (ediff-get-group-objA meta-list))
951 (ediff-abbreviate-file-name
952 (if (stringp
953 (ediff-get-group-objB meta-list))
954 (ediff-get-group-objB meta-list)
955 ""))
956 (ediff-abbreviate-file-name
957 (if (stringp
958 (ediff-get-group-objC meta-list))
959 (ediff-get-group-objC meta-list)
960 ""))))
961 (ediff-set-meta-overlay pt (point) elt))
962 (progn
963 (ediff-eval-in-buffer elt
964 (setq bufAname (if (ediff-buffer-live-p ediff-buffer-A)
965 (buffer-name ediff-buffer-A)
966 "!!!killed buffer!!!")
967 bufBname (if (ediff-buffer-live-p ediff-buffer-B)
968 (buffer-name ediff-buffer-B)
969 "!!!killed buffer!!!")
970 bufCname (cond ((not (ediff-3way-job))
972 ((ediff-buffer-live-p ediff-buffer-C)
973 (buffer-name ediff-buffer-C))
974 (t "!!!killed buffer!!!")))
975 (setq total-diffs (format "%-4d" ediff-number-of-differences)
976 cur-diff
977 (cond ((= ediff-current-difference -1) " _")
978 ((= ediff-current-difference
979 ediff-number-of-differences)
980 " $")
981 (t (format
982 "%4d" (1+ ediff-current-difference))))
983 job-name ediff-job-name))
984 ;; back in the meta buf
985 (setq pt (point))
986 (insert cur-diff "/" total-diffs "\t"
987 (buffer-name elt)
988 (format ": %s" (ediff-abbrev-jobname job-name)))
989 (insert
990 "\n\t\t " bufAname " " bufBname " " bufCname "\n")
991 (ediff-set-meta-overlay pt (point) elt))))
992 ) ; while
993 (set-buffer-modified-p nil)
994 (goto-char point)
997 ;; sets overlay around a meta record with 'ediff-meta-info property PROP
998 (defun ediff-set-meta-overlay (b e prop)
999 (let (overl)
1000 (setq overl (ediff-make-overlay b e))
1001 (if ediff-emacs-p
1002 (ediff-overlay-put overl 'mouse-face 'highlight)
1003 (ediff-overlay-put overl 'highlight t))
1004 (ediff-overlay-put overl 'ediff-meta-info prop)))
1006 (defun ediff-mark-for-hiding (unmark)
1007 "Mark session for hiding. With prefix arg, unmark."
1008 (interactive "P")
1009 (let* ((pos (ediff-event-point last-command-event))
1010 (meta-buf (ediff-event-buffer last-command-event))
1011 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1012 (info (ediff-get-meta-info meta-buf pos))
1013 (session-buf (ediff-get-session-buffer info)))
1015 (if (eq (ediff-get-session-status info) ?H)
1016 (setq unmark t))
1017 (if unmark
1018 (ediff-set-session-status info nil)
1019 (if (ediff-buffer-live-p session-buf)
1020 (error "Can't hide active session, %s" (buffer-name session-buf)))
1021 (ediff-set-session-status info ?H))
1022 (or unmark
1023 (ediff-next-meta-item 1))
1024 (ediff-update-meta-buffer meta-buf)
1027 (defun ediff-mark-for-operation (unmark)
1028 "Mark session for a group operation. With prefix arg, unmark."
1029 (interactive "P")
1030 (let* ((pos (ediff-event-point last-command-event))
1031 (meta-buf (ediff-event-buffer last-command-event))
1032 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1033 (info (ediff-get-meta-info meta-buf pos)))
1035 (if (eq (ediff-get-session-status info) ?*)
1036 (setq unmark t))
1037 (if unmark
1038 (ediff-set-session-status info nil)
1039 (ediff-set-session-status info ?*))
1040 (or unmark
1041 (ediff-next-meta-item 1))
1042 (ediff-update-meta-buffer meta-buf)
1045 (defun ediff-hide-marked-sessions (unhide)
1046 "Hide marked sessions. With prefix arg, unhide."
1047 (interactive "P")
1048 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1049 (meta-list (cdr ediff-meta-list))
1050 (from (if unhide ?I ?H))
1051 (to (if unhide ?H ?I))
1052 (numMarked 0)
1053 active-sessions-exist session-buf elt)
1054 (while meta-list
1055 (setq elt (car meta-list)
1056 meta-list (cdr meta-list)
1057 session-buf (ediff-get-session-buffer elt))
1059 (if (eq (ediff-get-session-status elt) from)
1060 (progn
1061 (setq numMarked (1+ numMarked))
1062 (if (and (eq to ?I) (buffer-live-p session-buf))
1063 ;; shouldn't hide active sessions
1064 (setq active-sessions-exist t)
1065 (ediff-set-session-status elt to)))))
1066 (if (> numMarked 0)
1067 (ediff-update-meta-buffer grp-buf)
1068 (beep)
1069 (if unhide
1070 (message "Nothing to reveal...")
1071 (message "Nothing to hide...")))
1072 (if active-sessions-exist
1073 (message "Note: didn't hide active sessions!"))
1076 ;; Apply OPERATION to marked sessions. Operation expects one argument of type
1077 ;; meta-list member (not the first one), i.e., a regular session description.
1078 ;; Returns number of marked sessions on which operation was performed
1079 (defun ediff-operate-on-marked-sessions (operation)
1080 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1081 (meta-list (cdr ediff-meta-list))
1082 (marksym ?*)
1083 (numMarked 0)
1084 (sessionNum 0)
1085 elt)
1086 (while meta-list
1087 (setq elt (car meta-list)
1088 meta-list (cdr meta-list)
1089 sessionNum (1+ sessionNum))
1090 (if (eq (ediff-get-session-status elt) marksym)
1091 (save-excursion
1092 (setq numMarked (1+ numMarked))
1093 (funcall operation elt sessionNum))))
1094 (ediff-update-meta-buffer grp-buf) ; just in case
1095 numMarked
1098 (defun ediff-append-custom-diff (session sessionNum)
1099 (or (ediff-collect-diffs-metajob)
1100 (error "Sorry, I don't do this for everyone..."))
1101 (let ((session-buf (ediff-get-session-buffer session))
1102 (meta-diff-buff ediff-meta-diff-buffer)
1103 (metajob ediff-metajob-name)
1104 tmp-buf custom-diff-buf)
1105 (if (ediff-buffer-live-p session-buf)
1106 (ediff-eval-in-buffer session-buf
1107 (if (eq ediff-control-buffer session-buf) ; individual session
1108 (progn
1109 (ediff-compute-custom-diffs-maybe)
1110 (setq custom-diff-buf ediff-custom-diff-buffer)))))
1112 (or (ediff-buffer-live-p meta-diff-buff)
1113 (error "Ediff: something wrong--no multiple diffs buffer"))
1115 (cond ((ediff-buffer-live-p custom-diff-buf)
1116 (save-excursion
1117 (set-buffer meta-diff-buff)
1118 (goto-char (point-max))
1119 (insert-buffer custom-diff-buf)
1120 (insert "\n")))
1121 ((memq metajob '(ediff-directories
1122 ediff-merge-directories
1123 ediff-merge-directories-with-ancestor))
1124 ;; get diffs by calling shell command on ediff-custom-diff-program
1125 (save-excursion
1126 (set-buffer (setq tmp-buf (get-buffer-create ediff-tmp-buffer)))
1127 (erase-buffer)
1128 (shell-command
1129 (format "%s %s %s %s"
1130 ediff-custom-diff-program ediff-custom-diff-options
1131 (ediff-get-session-objA-name session)
1132 (ediff-get-session-objB-name session))
1134 (save-excursion
1135 (set-buffer meta-diff-buff)
1136 (goto-char (point-max))
1137 (insert-buffer tmp-buf)
1138 (insert "\n")))
1140 (error "Can't make context diff for Session %d" sessionNum )))
1143 (defun ediff-collect-custom-diffs ()
1144 "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'.
1145 This operation is defined only for `ediff-directories' and
1146 `ediff-directory-revisions', since its intent is to produce
1147 multifile patches. For `ediff-directory-revisions', we insist that
1148 all marked sessions must be active."
1149 (interactive)
1150 (or (ediff-buffer-live-p ediff-meta-diff-buffer)
1151 (setq ediff-meta-diff-buffer
1152 (get-buffer-create
1153 (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
1154 (ediff-eval-in-buffer ediff-meta-diff-buffer
1155 (erase-buffer))
1156 (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
1157 ;; did something
1158 (display-buffer ediff-meta-diff-buffer 'not-this-window)
1159 (beep)
1160 (message "No marked sessions found")))
1162 (defun ediff-meta-show-patch ()
1163 "Show the multi-file patch associated with this group session."
1164 (interactive)
1165 (let* ((pos (ediff-event-point last-command-event))
1166 (meta-buf (ediff-event-buffer last-command-event))
1167 (info (ediff-get-meta-info meta-buf pos 'noerror))
1168 (patchbuffer ediff-meta-patchbufer))
1169 (if (ediff-buffer-live-p patchbuffer)
1170 (ediff-eval-in-buffer patchbuffer
1171 (save-restriction
1172 (if (not info)
1173 (widen)
1174 (narrow-to-region
1175 (ediff-get-session-objB-name info)
1176 (ediff-get-session-objC-name info)))
1177 (set-buffer (get-buffer-create ediff-tmp-buffer))
1178 (erase-buffer)
1179 (insert-buffer patchbuffer)
1180 (display-buffer ediff-tmp-buffer 'not-this-window)
1182 (error "The patch buffer wasn't found"))))
1185 ;; This function executes in meta buffer. It knows where event happened.
1186 (defun ediff-filegroup-action ()
1187 "Execute appropriate action for the selected session."
1188 (interactive)
1189 (let* ((pos (ediff-event-point last-command-event))
1190 (meta-buf (ediff-event-buffer last-command-event))
1191 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1192 (info (ediff-get-meta-info meta-buf pos))
1193 merge-autostore-dir
1194 session-buf file1 file2 file3 regexp)
1196 (setq session-buf (ediff-get-session-buffer info)
1197 file1 (ediff-get-session-objA-name info)
1198 file2 (ediff-get-session-objB-name info)
1199 file3 (ediff-get-session-objC-name info))
1201 ;; make sure we don't start on hidden sessions
1202 ;; ?H means marked for hiding. ?I means invalid (hidden).
1203 (if (memq (ediff-get-session-status info) '(?I))
1204 (progn
1205 (beep)
1206 (if (y-or-n-p "This session is marked as hidden, unmark? ")
1207 (progn
1208 (ediff-set-session-status info nil)
1209 (ediff-update-meta-buffer meta-buf))
1210 (error "Aborted"))))
1212 (ediff-eval-in-buffer meta-buf
1213 (setq merge-autostore-dir
1214 (ediff-get-group-merge-autostore-dir ediff-meta-list))
1215 (goto-char pos) ; if the user clicked on session--move point there
1216 ;; First handle sessions involving directories (which are themselves
1217 ;; session groups)
1218 ;; After that handle individual sessions
1219 (cond ((and (file-directory-p file1)
1220 (stringp file2) (file-directory-p file2)
1221 (if (stringp file3) (file-directory-p file1) t))
1222 ;; do ediff/ediff-merge on subdirectories
1223 (if (ediff-buffer-live-p session-buf)
1224 (ediff-show-meta-buffer session-buf)
1225 (setq regexp (read-string "Filter through regular expression: "
1226 nil 'ediff-filtering-regexp-history))
1227 (ediff-directories-internal
1228 file1 file2 file3 regexp
1229 ediff-session-action-function
1230 ediff-metajob-name
1231 ;; make it update car info after startup
1232 (` (list (lambda ()
1233 ;; child session group should know its parent
1234 (setq ediff-parent-meta-buffer
1235 (quote (, ediff-meta-buffer)))
1236 ;; and parent will know its child
1237 (setcar (quote (, info)) ediff-meta-buffer)))))))
1239 ;; Do ediff-revision on a subdirectory
1240 ((and (ediff-one-filegroup-metajob)
1241 (ediff-revision-metajob)
1242 (file-directory-p file1))
1243 (if (ediff-buffer-live-p session-buf)
1244 (ediff-show-meta-buffer session-buf)
1245 (setq regexp (read-string "Filter through regular expression: "
1246 nil 'ediff-filtering-regexp-history))
1247 (ediff-directory-revisions-internal
1248 file1 regexp
1249 ediff-session-action-function ediff-metajob-name
1250 ;; make it update car info after startup
1251 (` (list (lambda ()
1252 ;; child session group should know its parent
1253 (setq ediff-parent-meta-buffer
1254 (quote (, ediff-meta-buffer)))
1255 ;; and parent will know its child
1256 (setcar (quote (, info)) ediff-meta-buffer)))))))
1258 ;; From here on---only individual session handlers
1260 ;; handle an individual session with a live control buffer
1261 ((ediff-buffer-live-p session-buf)
1262 (ediff-eval-in-buffer session-buf
1263 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1264 (ediff-recenter 'no-rehighlight)))
1266 ((ediff-problematic-session-p info)
1267 (beep)
1268 (if (y-or-n-p
1269 "This session has no ancestor. Merge without the ancestor? ")
1270 (ediff-merge-files
1271 file1 file2
1272 ;; provide startup hooks
1273 (` (list (lambda ()
1274 (setq ediff-meta-buffer (, (current-buffer)))
1275 (setq ediff-merge-store-file
1276 (, (concat
1277 merge-autostore-dir
1278 (file-name-nondirectory file1))))
1279 ;; make ediff-startup pass
1280 ;; ediff-control-buffer back to the meta
1281 ;; level; see below
1282 (setcar
1283 (quote (, info)) ediff-control-buffer)))))
1284 (error "Aborted")))
1285 ((ediff-one-filegroup-metajob) ; needs 1 file arg
1286 (funcall ediff-session-action-function
1287 file1
1288 ;; provide startup hooks
1289 (` (list (lambda ()
1290 (setq ediff-meta-buffer (, (current-buffer)))
1291 (setq ediff-merge-store-file
1292 (, (concat
1293 merge-autostore-dir
1294 (file-name-nondirectory file1))))
1295 ;; make ediff-startup pass
1296 ;; ediff-control-buffer back to the meta
1297 ;; level; see below
1298 (setcar
1299 (quote (, info)) ediff-control-buffer))))))
1300 ((not (ediff-metajob3)) ; need 2 file args
1301 (funcall ediff-session-action-function
1302 file1 file2
1303 ;; provide startup hooks
1304 (` (list (lambda ()
1305 (setq ediff-meta-buffer (, (current-buffer)))
1306 (setq ediff-merge-store-file
1307 (, (concat
1308 merge-autostore-dir
1309 (file-name-nondirectory file1))))
1310 ;; make ediff-startup pass
1311 ;; ediff-control-buffer back to the meta
1312 ;; level; see below
1313 (setcar
1314 (quote (, info)) ediff-control-buffer))))))
1315 ((ediff-metajob3) ; need 3 file args
1316 (funcall ediff-session-action-function
1317 file1 file2 file3
1318 ;; arrange startup hooks
1319 (` (list (lambda ()
1320 (setq ediff-merge-store-file
1321 (, (concat
1322 merge-autostore-dir
1323 (file-name-nondirectory file1))))
1324 (setq ediff-meta-buffer (, (current-buffer)))
1325 ;; this arranges that ediff-startup will pass
1326 ;; the value of ediff-control-buffer back to
1327 ;; the meta level, to the record in the meta
1328 ;; list containing the information about the
1329 ;; session associated with that
1330 ;; ediff-control-buffer
1331 (setcar
1332 (quote (, info)) ediff-control-buffer))))))
1333 ) ; cond
1334 ) ; eval in meta-buf
1337 (defun ediff-registry-action ()
1338 "Switch to a selected session."
1339 (interactive)
1340 (let* ((pos (ediff-event-point last-command-event))
1341 (buf (ediff-event-buffer last-command-event))
1342 (ctl-buf (ediff-get-meta-info buf pos)))
1344 (if (ediff-buffer-live-p ctl-buf)
1345 ;; check if this is ediff-control-buffer or ediff-meta-buffer
1346 (if (ediff-eval-in-buffer ctl-buf
1347 (eq (key-binding "q") 'ediff-quit-meta-buffer))
1348 ;; it's a meta-buffer -- last action should just display it
1349 (ediff-show-meta-buffer ctl-buf)
1350 ;; it's a session buffer -- invoke go back to session
1351 (ediff-eval-in-buffer ctl-buf
1352 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1353 (ediff-recenter 'no-rehighlight)))
1354 (beep)
1355 (message "You've selected a stale session --- try again")
1356 (ediff-update-registry))
1357 (ediff-eval-in-buffer buf
1358 (goto-char pos))
1362 (defun ediff-show-meta-buffer (&optional meta-buf)
1363 "Show the session group buffer."
1364 (interactive)
1365 (let (wind frame silent)
1366 (if meta-buf (setq silent t))
1368 (setq meta-buf (or meta-buf ediff-meta-buffer))
1369 (cond ((not (bufferp meta-buf))
1370 (error "This Ediff session is not part of a session group"))
1371 ((not (ediff-buffer-live-p meta-buf))
1372 (error
1373 "Can't find this session's group panel -- session itself is ok")))
1375 (ediff-cleanup-meta-buffer meta-buf)
1376 (ediff-eval-in-buffer meta-buf
1377 (save-excursion
1378 (cond ((setq wind (ediff-get-visible-buffer-window meta-buf))
1379 (or silent
1380 (message
1381 "Already showing the group panel for this session"))
1382 (set-window-buffer wind meta-buf)
1383 (select-window wind))
1384 ((window-live-p (setq wind ediff-window-C)) ;in merge--merge buf
1385 (set-window-buffer ediff-window-C meta-buf)
1386 (select-window wind))
1387 ((window-live-p (setq wind ediff-window-A))
1388 (set-window-buffer ediff-window-A meta-buf)
1389 (select-window wind))
1390 ((window-live-p (setq wind ediff-window-B))
1391 (set-window-buffer ediff-window-B meta-buf)
1392 (select-window wind))
1393 ((and
1394 (setq wind
1395 (ediff-get-visible-buffer-window ediff-registry-buffer))
1396 (ediff-window-display-p))
1397 (select-window wind)
1398 (other-window 1)
1399 (set-window-buffer (selected-window) meta-buf))
1400 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1401 (set-window-buffer (selected-window) meta-buf)))
1403 (if (and (ediff-window-display-p)
1404 (window-live-p
1405 (setq wind (ediff-get-visible-buffer-window meta-buf))))
1406 (progn
1407 (setq frame (window-frame wind))
1408 (raise-frame frame)
1409 (ediff-reset-mouse frame)))
1410 (run-hooks 'ediff-show-session-group-hook)
1413 (defun ediff-show-meta-buff-from-registry ()
1414 "Display the session group buffer for a selected session group."
1415 (interactive)
1416 (let* ((pos (ediff-event-point last-command-event))
1417 (meta-buf (ediff-event-buffer last-command-event))
1418 (info (ediff-get-meta-info meta-buf pos))
1419 (meta-or-session-buf info))
1420 (ediff-eval-in-buffer meta-or-session-buf
1421 (ediff-show-meta-buffer))))
1423 ;;;###autoload
1424 (defun ediff-show-registry ()
1425 "Display Ediff's registry."
1426 (interactive)
1427 (ediff-update-registry)
1428 (if (not (ediff-buffer-live-p ediff-registry-buffer))
1429 (error "No active Ediff sessions or corrupted session registry"))
1430 (let (wind frame)
1431 ;; for some reason, point moves in ediff-registry-buffer, so we preserve it
1432 ;; explicitly
1433 (ediff-eval-in-buffer ediff-registry-buffer
1434 (save-excursion
1435 (cond ((setq wind
1436 (ediff-get-visible-buffer-window ediff-registry-buffer))
1437 (message "Already showing the registry")
1438 (set-window-buffer wind ediff-registry-buffer)
1439 (select-window wind))
1440 ((window-live-p ediff-window-C)
1441 (set-window-buffer ediff-window-C ediff-registry-buffer)
1442 (select-window ediff-window-C))
1443 ((window-live-p ediff-window-A)
1444 (set-window-buffer ediff-window-A ediff-registry-buffer)
1445 (select-window ediff-window-A))
1446 ((window-live-p ediff-window-B)
1447 (set-window-buffer ediff-window-B ediff-registry-buffer)
1448 (select-window ediff-window-B))
1449 ((and (setq wind
1450 (ediff-get-visible-buffer-window ediff-meta-buffer))
1451 (ediff-window-display-p))
1452 (select-window wind)
1453 (other-window 1)
1454 (set-window-buffer (selected-window) ediff-registry-buffer))
1455 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1456 (set-window-buffer (selected-window) ediff-registry-buffer)))
1458 (if (ediff-window-display-p)
1459 (progn
1460 (setq frame
1461 (window-frame
1462 (ediff-get-visible-buffer-window ediff-registry-buffer)))
1463 (raise-frame frame)
1464 (ediff-reset-mouse frame)))
1465 (run-hooks 'ediff-show-registry-hook)
1468 ;;;###autoload
1469 (defalias 'eregistry 'ediff-show-registry)
1471 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a
1472 ;; parent meta-buf
1473 ;; Check if META-BUF exists before calling this function
1474 (defun ediff-update-meta-buffer (meta-buf)
1475 (ediff-eval-in-buffer (current-buffer)
1476 (if (ediff-buffer-live-p meta-buf)
1477 (ediff-eval-in-buffer meta-buf
1478 (funcall ediff-meta-redraw-function ediff-meta-list))
1481 (defun ediff-update-registry ()
1482 (ediff-eval-in-buffer (current-buffer)
1483 (if (ediff-buffer-live-p ediff-registry-buffer)
1484 (ediff-redraw-registry-buffer)
1485 (ediff-prepare-meta-buffer
1486 'ediff-registry-action
1487 ediff-session-registry
1488 "*Ediff Registry"
1489 'ediff-redraw-registry-buffer
1490 'ediff-registry))
1493 ;; If meta-buf exists, it is redrawn along with parent.
1494 ;; Otherwise, nothing happens.
1495 (defun ediff-cleanup-meta-buffer (meta-buffer)
1496 (if (ediff-buffer-live-p meta-buffer)
1497 (ediff-eval-in-buffer meta-buffer
1498 (ediff-update-meta-buffer meta-buffer)
1499 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1500 (ediff-update-meta-buffer ediff-parent-meta-buffer)))))
1502 ;; t if no session in progress
1503 (defun ediff-safe-to-quit (meta-buffer)
1504 (if (ediff-buffer-live-p meta-buffer)
1505 (let ((lis ediff-meta-list)
1506 (cont t)
1507 buffer-read-only)
1508 (ediff-update-meta-buffer meta-buffer)
1509 (ediff-eval-in-buffer meta-buffer
1510 (setq lis (cdr lis)) ; discard the description part of meta-list
1511 (while (and cont lis)
1512 (if (ediff-buffer-live-p
1513 (ediff-get-group-buffer lis)) ; in progress
1514 (setq cont nil))
1515 (setq lis (cdr lis)))
1516 cont))))
1518 (defun ediff-quit-meta-buffer ()
1519 "If the group has no active session, delete the meta buffer.
1520 If no session is in progress, ask to confirm before deleting meta buffer.
1521 Otherwise, bury the meta buffer.
1522 If this is a session registry buffer then just bury it."
1523 (interactive)
1524 (let* ((buf (current-buffer))
1525 (dir-diffs-buffer ediff-dir-diffs-buffer)
1526 (meta-diff-buffer ediff-meta-diff-buffer)
1527 (parent-buf ediff-parent-meta-buffer)
1528 (dont-show-registry (eq buf ediff-registry-buffer)))
1529 (if dont-show-registry
1530 (bury-buffer)
1531 (ediff-cleanup-meta-buffer buf)
1532 (cond ((and (ediff-safe-to-quit buf)
1533 (y-or-n-p "Quit this session group? "))
1534 (run-hooks 'ediff-quit-session-group-hook)
1535 (message "")
1536 (ediff-dispose-of-meta-buffer buf))
1537 ((ediff-safe-to-quit buf)
1538 (bury-buffer))
1540 (error
1541 "This session group has active sessions---cannot exit")))
1542 (ediff-cleanup-meta-buffer parent-buf)
1543 (ediff-kill-buffer-carefully dir-diffs-buffer)
1544 (ediff-kill-buffer-carefully meta-diff-buffer)
1545 (if (ediff-buffer-live-p parent-buf)
1546 (progn
1547 (setq dont-show-registry t)
1548 (ediff-show-meta-buffer parent-buf)))
1550 (or dont-show-registry
1551 (ediff-show-registry))))
1553 (defun ediff-dispose-of-meta-buffer (buf)
1554 (setq ediff-session-registry (delq buf ediff-session-registry))
1555 (ediff-eval-in-buffer buf
1556 (if (ediff-buffer-live-p ediff-dir-diffs-buffer)
1557 (kill-buffer ediff-dir-diffs-buffer)))
1558 (kill-buffer buf))
1561 ;; Obtain information on a meta record where the user clicked or typed
1562 ;; BUF is the buffer where this happened and POINT is the position
1563 ;; If optional NOERROR arg is given, don't report error and return nil if no
1564 ;; meta info is found on line.
1565 (defun ediff-get-meta-info (buf point &optional noerror)
1566 (let (result olist tmp)
1567 (if (and point (ediff-buffer-live-p buf))
1568 (ediff-eval-in-buffer buf
1569 (if ediff-xemacs-p
1570 (setq result
1571 (if (setq tmp (extent-at point buf 'ediff-meta-info))
1572 (ediff-overlay-get tmp 'ediff-meta-info)))
1573 (setq olist (overlays-at point))
1574 (setq olist
1575 (mapcar (function (lambda (elt)
1576 (overlay-get elt 'ediff-meta-info)))
1577 olist))
1578 (while (and olist (null (car olist))
1579 (overlay-get (car olist) 'invisible))
1580 (setq olist (cdr olist)))
1581 (setq result (car olist)))))
1582 (if result
1583 result
1584 (if noerror
1586 (ediff-update-registry)
1587 (error "No session info in this line")))))
1589 ;; return location of the next meta overlay after point
1590 (defun ediff-next-meta-overlay-start (point)
1591 (if (eobp)
1592 (goto-char (point-min))
1593 (let (overl)
1594 (if ediff-xemacs-p
1595 (progn
1596 (setq overl (extent-at point (current-buffer) 'ediff-meta-info))
1597 (if overl
1598 (setq overl (next-extent overl))
1599 (setq overl (next-extent (current-buffer))))
1600 (if overl
1601 (extent-start-position overl)
1602 (point-max)))
1603 (setq overl (car (overlays-at point)))
1604 (if (and overl (overlay-get overl 'ediff-meta-info))
1605 ;; note: end of current overlay is the beginning of the next one
1606 (overlay-end overl)
1607 (next-overlay-change point))))
1610 (defun ediff-previous-meta-overlay-start (point)
1611 (if (bobp)
1612 (goto-char (point-max))
1613 (let (overl)
1614 (if ediff-xemacs-p
1615 (progn
1616 (setq overl (extent-at point (current-buffer) 'ediff-meta-info))
1617 (if overl
1618 (setq overl (previous-extent overl))
1619 (setq overl (previous-extent (current-buffer))))
1620 (if overl
1621 (extent-start-position overl)
1622 (point-min)))
1623 (setq overl (car (overlays-at point)))
1624 (if (and overl (overlay-get overl 'ediff-meta-info))
1625 (setq point (overlay-start overl)))
1626 ;; to get to the beginning of prev overlay
1627 (if (not (bobp))
1628 ;; trickery to overcome an emacs bug--doesn't always find previous
1629 ;; overlay change correctly
1630 (setq point (1- point)))
1631 (setq point (previous-overlay-change point))
1632 ;; If we are not over an overlay after subtracting 1, it means we are
1633 ;; in the description area preceding session records. In this case,
1634 ;; goto the top of the registry buffer.
1635 (or (car (overlays-at point))
1636 (setq point (point-min)))
1637 point
1638 ))))
1640 ;; this is the action invoked when the user selects a patch from the meta
1641 ;; buffer.
1642 (defun ediff-patch-file-form-meta (file &optional startup-hooks)
1643 (let* ((pos (ediff-event-point last-command-event))
1644 (meta-buf (ediff-event-buffer last-command-event))
1645 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1646 (info (ediff-get-meta-info meta-buf pos))
1647 (meta-patchbuf ediff-meta-patchbufer)
1648 session-buf beg-marker end-marker)
1650 (if (or (file-directory-p file) (string-match "/dev/null" file))
1651 (error "`%s' is not an ordinary file" (file-name-as-directory file)))
1652 (setq session-buf (ediff-get-session-buffer info)
1653 beg-marker (ediff-get-session-objB-name info)
1654 end-marker (ediff-get-session-objC-name info))
1656 (or (ediff-buffer-live-p session-buf) ; either an active patch session
1657 (null session-buf) ; or it is a virgin session
1658 (error
1659 "Patch has been already applied to this file--cannot be repeated!"))
1661 (ediff-eval-in-buffer meta-patchbuf
1662 (save-restriction
1663 (widen)
1664 (narrow-to-region beg-marker end-marker)
1665 (ediff-patch-file-internal meta-patchbuf file startup-hooks)))))
1668 (defun ediff-meta-mark-equal-files ()
1669 "Run though the session list and mark identical files.
1670 This is used only for sessions that involve 2 or 3 files at the same time."
1671 (interactive)
1672 (let ((list (cdr ediff-meta-list))
1673 fileinfo1 fileinfo2 fileinfo3 elt)
1674 (while (setq elt (car list))
1675 (setq fileinfo1 (ediff-get-session-objA elt)
1676 fileinfo2 (ediff-get-session-objB elt)
1677 fileinfo3 (ediff-get-session-objC elt))
1678 (ediff-set-file-eqstatus fileinfo1 nil)
1679 (ediff-set-file-eqstatus fileinfo2 nil)
1680 (ediff-set-file-eqstatus fileinfo3 nil)
1682 (ediff-mark-if-equal fileinfo1 fileinfo2)
1683 (if (ediff-metajob3)
1684 (progn
1685 (ediff-mark-if-equal fileinfo1 fileinfo3)
1686 (ediff-mark-if-equal fileinfo2 fileinfo3)))
1687 (setq list (cdr list))))
1688 (ediff-update-meta-buffer (current-buffer)))
1690 ;; mark files 1 and 2 as equal, if they are.
1691 (defun ediff-mark-if-equal (fileinfo1 fileinfo2)
1692 (get-buffer-create ediff-tmp-buffer)
1693 (or (file-directory-p (car fileinfo1))
1694 (file-directory-p (car fileinfo2))
1695 (if (= (ediff-make-diff2-buffer
1696 ediff-tmp-buffer (car fileinfo1) (car fileinfo2))
1698 (progn
1699 (ediff-set-file-eqstatus fileinfo1 t)
1700 (ediff-set-file-eqstatus fileinfo2 t)))))
1704 ;;; Local Variables:
1705 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1706 ;;; eval: (put 'ediff-eval-in-buffer 'lisp-indent-hook 1)
1707 ;;; eval: (put 'ediff-eval-in-buffer 'edebug-form-spec '(form body))
1708 ;;; End:
1710 (provide 'ediff-mult)
1711 (require 'ediff-util)
1713 ;;; ediff-mult.el ends here