1 ;;; ediff-mult.el --- support for multi-file/multi-buffer processing in Ediff
3 ;; Copyright (C) 1995, 1996, 1997 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)
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.
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
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.
95 (defgroup ediff-mult nil
96 "Multi-file and multi-buffer processing in Ediff"
103 (let ((load-path (cons (expand-file-name ".") load-path
)))
104 (or (featurep 'ediff-init
)
105 (load "ediff-init.el" nil nil
'nosuffix
))
106 (or (featurep 'ediff-util
)
107 (load "ediff-util.el" nil nil
'nosuffix
))
111 (require 'ediff-init
)
112 (require 'ediff-util
)
115 (ediff-defvar-local ediff-meta-buffer nil
"")
116 (ediff-defvar-local ediff-parent-meta-buffer nil
"")
117 ;; the registry buffer
118 (defvar ediff-registry-buffer nil
)
120 (defconst ediff-meta-buffer-message
"This is an Ediff Session Group Panel: %s
123 button2, `v', RET over a session line: start that Ediff session
124 `M':\tin any session invoked from here, brings back this group panel
125 `R':\tdisplay the registry of active Ediff sessions
126 `h':\tmark session for hiding (toggle)
127 `x':\thide marked sessions; with prefix arg--unhide hidden sessions
128 `m':\tmark session for a non-hiding operation (toggle)
130 DEL:\tprevious session
131 `E':\tbrowse Ediff on-line manual
132 `q':\tquit this session group
135 (ediff-defvar-local ediff-meta-buffer-map nil
136 "The keymap for the meta buffer.")
137 (defvar ediff-dir-diffs-buffer-map
(make-sparse-keymap)
138 "The keymap to be installed in the buffer showing differences between
141 ;; Variable specifying the action to take when the use invokes ediff in the
142 ;; meta buffer. This is usually ediff-registry-action or ediff-filegroup-action
143 (ediff-defvar-local ediff-meta-action-function nil
"")
144 ;; Tells ediff-update-meta-buffer how to redraw it
145 (ediff-defvar-local ediff-meta-redraw-function nil
"")
146 ;; Tells ediff-filegroup-action and similar procedures how to invoke Ediff for
147 ;; the sessions in a given session group
148 (ediff-defvar-local ediff-session-action-function nil
"")
150 (ediff-defvar-local ediff-metajob-name nil
"")
152 ;; buffer used to collect custom diffs from individual sessions in the group
153 (ediff-defvar-local ediff-meta-diff-buffer nil
"")
155 ;; history var to use for filtering groups
156 (defvar ediff-filtering-regexp-history nil
"")
158 ;; This has the form ((ctl-buf file1 file2) (stl-buf file1 file2) ...)
159 ;; If ctl-buf is nil, the file-pair wasn't processed yet. If it is
160 ;; killed-buffer object, the file pair has been processed. If it is a live
161 ;; buffer, this means ediff is still working on the pair
162 (ediff-defvar-local ediff-meta-list nil
"")
165 ;; the difference list between directories in a directory session group
166 (ediff-defvar-local ediff-dir-difference-list nil
"")
167 (ediff-defvar-local ediff-dir-diffs-buffer nil
"")
169 ;; The registry of Ediff sessions. A list of control buffers.
170 (defvar ediff-session-registry nil
)
172 (defcustom ediff-registry-setup-hook nil
173 "*Hooks run just after the registry control panel is set up."
176 (defcustom ediff-session-group-setup-hook nil
177 "*Hooks run just after a meta-buffer controlling a session group, such as
178 ediff-directories, is run."
181 (defcustom ediff-quit-session-group-hook nil
182 "*Hooks run just before exiting a session group."
185 (defcustom ediff-show-registry-hook nil
186 "*Hooks run just after the registry buffer is shown."
189 (defcustom ediff-show-session-group-hook nil
190 "*Hooks run just after a session group buffer is shown."
193 (defcustom ediff-meta-buffer-keymap-setup-hook nil
194 "*Hooks run just after setting up the ediff-meta-buffer-map.
195 This keymap controls key bindings in the meta buffer and is a local variable.
196 This means that you can set different bindings for different kinds of meta
201 ;; buffer holding the multi-file patch. local to the meta buffer
202 (ediff-defvar-local ediff-meta-patchbufer nil
"")
204 ;;; API for ediff-meta-list
206 ;; group buffer/regexp
207 (defun ediff-get-group-buffer (meta-list)
208 (nth 0 (car meta-list
)))
210 (defun ediff-get-group-regexp (meta-list)
211 (nth 1 (car meta-list
)))
213 (defun ediff-get-group-objA (meta-list)
214 (nth 2 (car meta-list
)))
215 (defun ediff-get-group-objB (meta-list)
216 (nth 3 (car meta-list
)))
217 (defun ediff-get-group-objC (meta-list)
218 (nth 4 (car meta-list
)))
219 (defun ediff-get-group-merge-autostore-dir (meta-list)
220 (nth 5 (car meta-list
)))
223 (defun ediff-get-session-buffer (elt)
225 (defun ediff-get-session-status (elt)
227 (defun ediff-set-session-status (session-info new-status
)
228 (setcar (cdr session-info
) new-status
))
230 (defun ediff-get-session-objA (elt)
232 (defun ediff-get-session-objB (elt)
234 (defun ediff-get-session-objC (elt)
236 (defun ediff-get-session-objA-name (elt)
238 (defun ediff-get-session-objB-name (elt)
240 (defun ediff-get-session-objC-name (elt)
242 ;; equality indicators
243 (defsubst ediff-get-file-eqstatus
(elt)
245 (defsubst ediff-set-file-eqstatus
(elt value
)
246 (setcar (cdr elt
) value
))
248 ;; set up the keymap in the meta buffer
249 (defun ediff-setup-meta-map()
250 (setq ediff-meta-buffer-map
(make-sparse-keymap))
251 (suppress-keymap ediff-meta-buffer-map
)
252 (define-key ediff-meta-buffer-map
"q" 'ediff-quit-meta-buffer
)
253 (define-key ediff-meta-buffer-map
"R" 'ediff-show-registry
)
254 (define-key ediff-meta-buffer-map
"E" 'ediff-documentation
)
255 (define-key ediff-meta-buffer-map
"v" ediff-meta-action-function
)
256 (define-key ediff-meta-buffer-map
"\C-m" ediff-meta-action-function
)
257 (define-key ediff-meta-buffer-map
" " 'ediff-next-meta-item
)
258 (define-key ediff-meta-buffer-map
"\C-?" 'ediff-previous-meta-item
)
259 (define-key ediff-meta-buffer-map
[delete] 'ediff-previous-meta-item)
260 (define-key ediff-meta-buffer-map [backspace] 'ediff-previous-meta-item)
261 (or (ediff-one-filegroup-metajob)
262 (define-key ediff-meta-buffer-map "=" 'ediff-meta-mark-equal-files))
263 (if ediff-no-emacs-help-in-control-buffer
264 (define-key ediff-meta-buffer-map "\C-h" 'ediff-previous-meta-item))
266 (define-key ediff-meta-buffer-map [mouse-2] ediff-meta-action-function)
267 (define-key ediff-meta-buffer-map [button2] ediff-meta-action-function))
269 (use-local-map ediff-meta-buffer-map)
270 ;; modify ediff-meta-buffer-map here
271 (run-hooks 'ediff-meta-buffer-keymap-setup-hook))
273 (defun ediff-meta-mode ()
274 "This mode controls all operations on Ediff session groups.
275 It is entered through one of the following commands:
280 `ediff-merge-directories'
282 `ediff-merge-directories-with-ancestor'
283 `edirs-merge-with-ancestor'
284 `ediff-directory-revisions'
286 `ediff-merge-directory-revisions'
287 `edir-merge-revisions'
288 `ediff-merge-directory-revisions-with-ancestor'
289 `edir-merge-revisions-with-ancestor'
292 \\{ediff-meta-buffer-map}"
293 (kill-all-local-variables)
294 (setq major-mode 'ediff-meta-mode)
295 (setq mode-name "MetaEdiff"))
298 ;; the keymap for the buffer showing directory differences
299 (suppress-keymap ediff-dir-diffs-buffer-map)
300 (define-key ediff-dir-diffs-buffer-map "q" 'ediff-bury-dir-diffs-buffer)
301 (define-key ediff-dir-diffs-buffer-map " " 'next-line)
302 (define-key ediff-dir-diffs-buffer-map "\C-?" 'previous-line)
303 (define-key ediff-dir-diffs-buffer-map [delete] 'previous-line
)
304 (define-key ediff-dir-diffs-buffer-map
[backspace] 'previous-line)
306 (defun ediff-next-meta-item (count)
307 "Move to the next item in Ediff registry or session group buffer.
308 Moves in circular fashion. With numeric prefix arg, skip this many items."
310 (or count (setq count 1))
312 (setq count (1- count))
313 (ediff-next-meta-item1)))
315 ;; Move to the next meta item
316 (defun ediff-next-meta-item1 ()
318 (setq pos (ediff-next-meta-overlay-start (point)))
320 ;;; (while (memq (ediff-get-session-status
321 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
323 ;;; (setq pos (ediff-next-meta-overlay-start pos)))
325 (if pos (goto-char pos))
326 (if (eq ediff-metajob-name 'ediff-registry)
327 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
328 (search-forward "*Ediff" nil t))
329 (skip-chars-backward "a-zA-Z*"))
330 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
331 (backward-char 1)))))
334 (defun ediff-previous-meta-item (count)
335 "Move to the previous item in Ediff registry or session group buffer.
336 Moves in circular fashion. With numeric prefix arg, skip this many items."
338 (or count (setq count 1))
340 (setq count (1- count))
341 (ediff-previous-meta-item1)))
343 (defun ediff-previous-meta-item1 ()
345 (setq pos (ediff-previous-meta-overlay-start (point)))
347 ;;; (while (ediff-get-session-status
348 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
349 ;;; (setq pos (ediff-previous-meta-overlay-start pos)))
351 (if pos (goto-char pos))
352 (if (eq ediff-metajob-name 'ediff-registry)
353 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
354 (search-forward "*Ediff" nil t))
355 (skip-chars-backward "a-zA-Z*"))
356 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
360 (defsubst ediff-add-slash-if-directory (dir file)
361 (if (file-directory-p (concat dir file))
362 (file-name-as-directory file)
366 ;; DIR1, DIR2, DIR3 are directories. DIR3 can be nil.
367 ;; OUTPUT-DIR is a directory for auto-storing the results of merge jobs.
369 ;; REGEXP is a regexp used to filter out files in the directories.
370 ;; If a file is a directory in dir1 but not dir2 (or vice versa), it is not
371 ;; included in the intersection. However, a regular file that is a dir in dir3
372 ;; is included, since dir3 files are supposed to be ancestors for merging.
373 ;; Returns a list of the form:
374 ;; ((dir1 dir2 dir3) (f1 f2 f3) (f1 f2 f3) ...)
375 ;; dir3, f3 can be nil if intersecting only 2 directories.
376 ;; If COMPARISON-FUNC is given, use it. Otherwise, use string=
377 ;; DIFF-VAR contains the name of the variable in which to return the
378 ;; difference list (which represents the differences among the contents of
379 ;; directories). The diff list is of the form:
380 ;; ((dir1 dir2 dir3) (file . num) (file . num)...)
381 ;; where num encodes the set of dirs where the file is found:
382 ;; 2 - only dir1; 3 - only dir2; 5 - only dir3; 6 - dir1&2; 10 - dir1&3; etc.
383 (defun ediff-intersect-directories (jobname
384 diff-var regexp dir1 dir2
386 dir3 merge-autostore-dir comparison-func)
387 (setq comparison-func (or comparison-func 'string=))
388 (let (lis1 lis2 lis3 common auxdir1 auxdir2 auxdir3 difflist)
390 (setq auxdir1 (file-name-as-directory dir1)
391 lis1 (directory-files auxdir1 nil regexp)
392 lis1 (delete "." lis1)
393 lis1 (delete ".." lis1)
397 (ediff-add-slash-if-directory auxdir1 elt)))
399 auxdir2 (file-name-as-directory dir2)
403 (ediff-add-slash-if-directory auxdir2 elt)))
404 (directory-files auxdir2 nil regexp)))
407 (setq auxdir3 (file-name-as-directory dir3)
411 (ediff-add-slash-if-directory auxdir3 elt)))
412 (directory-files auxdir3 nil regexp))))
414 (if (stringp merge-autostore-dir)
415 (setq merge-autostore-dir
416 (file-name-as-directory merge-autostore-dir)))
417 (setq common (ediff-intersection lis1 lis2 comparison-func))
419 ;; In merge with ancestor jobs, we don't intersect with lis3.
420 ;; If there is no ancestor, we'll offer to merge without the ancestor.
421 ;; So, we intersect with lis3 only when we are doing 3-way file comparison
422 (if (and lis3 (ediff-comparison-metajob3 jobname))
423 (setq common (ediff-intersection common lis3 comparison-func)))
425 ;; copying is needed because sort sorts via side effects
426 (setq common (sort (ediff-copy-list common) 'string-lessp))
428 ;; compute difference list
429 (setq difflist (ediff-set-difference
430 (ediff-union (ediff-union lis1 lis2 comparison-func)
435 difflist (delete "." difflist)
436 ;; copying is needed because sort sorts via side effects
437 difflist (sort (ediff-copy-list (delete ".." difflist))
440 (setq difflist (mapcar (function (lambda (elt) (cons elt 1))) difflist))
442 ;; check for files belonging to lis1/2/3
443 (mapcar (function (lambda (elt)
444 (if (member (car elt) lis1)
445 (setcdr elt (* (cdr elt) 2)))
446 (if (member (car elt) lis2)
447 (setcdr elt (* (cdr elt) 3)))
448 (if (member (car elt) lis3)
449 (setcdr elt (* (cdr elt) 5)))
452 (setq difflist (cons (list regexp auxdir1 auxdir2 auxdir3) difflist))
454 ;; return the difference list back to the calling function
455 (set diff-var difflist)
458 (cons (list regexp auxdir1 auxdir2 auxdir3 merge-autostore-dir)
462 (list (concat auxdir1 elt)
466 ;; The following is done because:
467 ;; In merging with ancestor, we don't intersect
468 ;; with lis3. So, it is possible that elt is a
469 ;; file in auxdir1/2 but a directory in auxdir3
470 ;; Or elt may not exist in auxdir3 at all.
471 ;; In the first case, we add a slash at the end.
472 ;; In the second case, we insert nil.
473 (setq elt (ediff-add-slash-if-directory auxdir3 elt))
474 (if (file-exists-p (concat auxdir3 elt))
475 (concat auxdir3 elt)))))))
479 ;; find directory files that are under revision.
480 ;; Include subdirectories, since we may visit them recursively.
481 ;; DIR1 is the directory to inspect.
482 ;; OUTPUT-DIR is the directory where to auto-store the results of merges. Can
484 (defun ediff-get-directory-files-under-revision (jobname
486 &optional merge-autostore-dir)
487 (let (lis1 elt common auxdir1)
488 (setq auxdir1 (file-name-as-directory dir1)
489 lis1 (directory-files auxdir1 nil regexp))
491 (if (stringp merge-autostore-dir)
492 (setq merge-autostore-dir
493 (file-name-as-directory merge-autostore-dir)))
498 ;; take files under revision control
499 (cond ((file-directory-p (concat auxdir1 elt))
500 (setq common (cons elt common)))
501 ((file-exists-p (concat auxdir1 elt ",v"))
502 (setq common (cons elt common)))
503 ((file-exists-p (concat auxdir1 "RCS/" elt ",v"))
504 (setq common (cons elt common)))
508 (setq common (delete "." common)
509 common (delete ".." common)
510 common (delete "RCS" common))
512 ;; copying is needed because sort sorts via side effects
513 (setq common (sort (ediff-copy-list common) 'string-lessp))
516 (cons (list regexp auxdir1 nil nil merge-autostore-dir)
517 (mapcar (function (lambda (elt)
518 (list (concat auxdir1 elt)
524 ;; If file groups selected by patterns will ever be implemented, this
525 ;; comparison function might become useful.
526 ;;;; uses external variables PAT1 PAT2 to compare str1/2
527 ;;;; patterns must be of the form ???*???? where ??? are strings of chars
528 ;;;; containing no *.
529 ;;(defun ediff-pattern= (str1 str2)
530 ;; (let (pos11 pos12 pos21 pos22 len1 len2)
532 ;; len (length epat1)
534 ;; (while (and (< pos11 len) (not (= (aref epat1 pos11) ?*)))
535 ;; (setq pos11 (1+ pos11)))
536 ;; (while (and (> pos12 0) (not (= (aref epat1 (1- pos12)) ?*)))
537 ;; (setq pos12 (1- pos12)))
540 ;; len (length epat2)
542 ;; (while (and (< pos21 len) (not (= (aref epat2 pos21) ?*)))
543 ;; (setq pos21 (1+ pos21)))
544 ;; (while (and (> pos22 0) (not (= (aref epat2 (1- pos22)) ?*)))
545 ;; (setq pos22 (1- pos22)))
547 ;; (if (and (> (length str1) pos12) (>= pos12 pos11) (> pos11 -1)
548 ;; (> (length str2) pos22) (>= pos22 pos21) (> pos21 -1))
549 ;; (string= (substring str1 pos11 pos12)
550 ;; (substring str2 pos21 pos22)))
554 ;; Prepare meta-buffer in accordance with the argument-function and
555 ;; redraw-function. Must return the created meta-buffer.
556 (defun ediff-prepare-meta-buffer (action-func meta-list
557 meta-buffer-name redraw-function
558 jobname &optional startup-hooks)
559 (let* ((meta-buffer-name
560 (ediff-unique-buffer-name meta-buffer-name "*"))
561 (meta-buffer (get-buffer-create meta-buffer-name)))
562 (ediff-with-current-buffer meta-buffer
567 (setq ediff-meta-action-function action-func
568 ediff-meta-redraw-function redraw-function
569 ediff-metajob-name jobname
570 ediff-meta-buffer meta-buffer)
572 ;; comes after ediff-meta-action-function is set
573 (ediff-setup-meta-map)
575 (if (eq ediff-metajob-name 'ediff-registry)
577 (setq ediff-registry-buffer meta-buffer
578 ediff-meta-list meta-list)
579 ;; this func is used only from registry buffer, not from other
582 ediff-meta-buffer-map "M" 'ediff-show-meta-buff-from-registry))
583 ;; Initialize the meta list -- don't do this for registry.
585 ;; We prepend '(nil nil) to all elts of meta-list, except the first.
586 ;; The first nil will later be replaced by the session buffer. The
587 ;; second is reserved for session status.
589 ;; (car ediff-meta-list) gets cons'ed with the session group buffer.
590 ;; Also, session objects A/B/C are turned into lists of the form
591 ;; (obj eq-indicator). Eq-indicator is either nil or =. Initialized to
592 ;; nil. If later it is discovered that this file is = to some other
593 ;; file in the same session, eq-indicator is changed to `='.
594 ;; For now, the eq-indicator is used only for 2 and 3-file jobs.
595 (setq ediff-meta-list
596 (cons (cons meta-buffer (car meta-list))
602 ;; convert each obj to (obj nil),
603 ;; where nil is the initial value
604 ;; for eq-indicator -- see above
606 (function (lambda (obj) (list obj nil)))
610 (or (eq meta-buffer ediff-registry-buffer)
611 (setq ediff-session-registry
612 (cons meta-buffer ediff-session-registry)))
614 ;; redraw-function uses ediff-meta-list
615 (funcall redraw-function ediff-meta-list)
617 ;; set read-only/non-modified
618 (setq buffer-read-only t)
619 (set-buffer-modified-p nil)
621 (run-hooks 'startup-hooks)
623 ;; Arrange to show directory contents differences
624 ;; Must be after run startup-hooks, since ediff-dir-difference-list is
625 ;; set inside these hooks
626 (if (eq action-func 'ediff-filegroup-action)
628 ;; put meta buffer in (car ediff-dir-difference-list)
629 (setq ediff-dir-difference-list
630 (cons (cons meta-buffer (car ediff-dir-difference-list))
631 (cdr ediff-dir-difference-list)))
633 (or (ediff-one-filegroup-metajob jobname)
634 (ediff-draw-dir-diffs ediff-dir-difference-list))
635 (define-key ediff-meta-buffer-map "h" 'ediff-mark-for-hiding)
637 ediff-meta-buffer-map "x" 'ediff-hide-marked-sessions)
638 (define-key ediff-meta-buffer-map "m" 'ediff-mark-for-operation)
639 (cond ((ediff-collect-diffs-metajob jobname)
641 ediff-meta-buffer-map "P" 'ediff-collect-custom-diffs))
642 ((ediff-patch-metajob jobname)
644 ediff-meta-buffer-map "P" 'ediff-meta-show-patch)))
645 (define-key ediff-meta-buffer-map "u" 'ediff-up-meta-hierarchy)
646 (define-key ediff-meta-buffer-map "D" 'ediff-show-dir-diffs)))
648 (if (eq ediff-metajob-name 'ediff-registry)
649 (run-hooks 'ediff-registry-setup-hook)
650 (run-hooks 'ediff-session-group-setup-hook))
651 ) ; eval in meta-buffer
655 ;; this is a setup function for ediff-directories
656 ;; must return meta-buffer
657 (defun ediff-redraw-directory-group-buffer (meta-list)
658 ;; extract directories
659 (let ((meta-buf (ediff-get-group-buffer meta-list))
662 regexp elt session-buf f1 f2 f3 pt
664 point tmp-list buffer-read-only)
665 (ediff-with-current-buffer meta-buf
668 (insert (format ediff-meta-buffer-message
669 (ediff-abbrev-jobname ediff-metajob-name)))
671 (setq regexp (ediff-get-group-regexp meta-list)
672 merge-autostore-dir (ediff-get-group-merge-autostore-dir meta-list))
674 (cond ((ediff-collect-diffs-metajob)
676 " `P':\tcollect custom diffs of all marked sessions\n"))
677 ((ediff-patch-metajob)
679 " `P':\tshow patch appropriately for the context (session or group)\n")))
681 " `u':\tshow parent session group\n")
682 (or (ediff-one-filegroup-metajob)
684 " `D':\tshow differences among directories\n"
685 " `=':\tmark identical files in each session\n\n"))
687 (if (and (stringp regexp) (> (length regexp) 0))
689 (format "\n*** Filter-through regular expression: %s\n" regexp)))
690 (if (and ediff-autostore-merges (ediff-merge-metajob)
691 (stringp merge-autostore-dir))
693 "\nMerges are automatically stored in directory: %s\n"
694 merge-autostore-dir)))
696 Size Last modified Name
697 -----------------------------------------------------------------------
701 ;; discard info on directories and regexp
702 (setq meta-list (cdr meta-list)
704 (while (and tmp-list empty)
705 (if (and (car tmp-list)
706 (not (eq (ediff-get-session-status (car tmp-list)) ?I)))
708 (setq tmp-list (cdr tmp-list)))
712 " ****** ****** This session group has no members\n"))
714 ;; now organize file names like this:
715 ;; use-mark sizeA dateA sizeB dateB filename
716 ;; make sure directories are displayed with a trailing slash.
718 (setq elt (car meta-list)
719 meta-list (cdr meta-list)
720 sessionNum (1+ sessionNum))
721 (if (eq (ediff-get-session-status elt) ?I)
723 (setq session-buf (ediff-get-session-buffer elt)
724 f1 (ediff-get-session-objA elt)
725 f2 (ediff-get-session-objB elt)
726 f3 (ediff-get-session-objC elt))
729 (insert (cond ((null session-buf) " ") ; virgin session
730 ((ediff-buffer-live-p session-buf) "+") ;active session
731 (t "-"))) ; finished session
732 (insert (cond ((ediff-get-session-status elt)) ; session has status,
734 (t " "))) ; normal session
735 (insert " Session " (int-to-string sessionNum) ":\n")
736 (ediff-meta-insert-file-info f1)
737 (ediff-meta-insert-file-info f2)
738 (ediff-meta-insert-file-info f3)
739 (ediff-set-meta-overlay pt (point) elt)))
740 (set-buffer-modified-p nil)
744 ;; Check if this is a problematic session.
745 ;; Return nil if not. Otherwise, return symbol representing the problem
746 ;; At present, problematic sessions occur only in -with-ancestor comparisons
747 ;; when the ancestor is a directory rather than a file, or when there is no
748 ;; suitable ancestor file in the ancestor directory
749 (defun ediff-problematic-session-p (session)
750 (let ((f1 (ediff-get-session-objA-name session))
751 (f2 (ediff-get-session-objB-name session))
752 (f3 (ediff-get-session-objC-name session)))
753 (cond ((and (stringp f1) (not (file-directory-p f1))
754 (stringp f2) (not (file-directory-p f2))
755 ;; either invalid file name or a directory
756 (or (not (stringp f3)) (file-directory-p f3))
757 (ediff-ancestor-metajob))
758 ;; more may be added later
762 (defun ediff-meta-insert-file-info (fileinfo)
763 (let ((fname (car fileinfo))
764 (feq (ediff-get-file-eqstatus fileinfo))
765 file-modtime file-size)
767 (cond ((not (stringp fname)) (setq file-size -2)) ; file doesn't exits
768 ((not (ediff-file-remote-p fname))
769 (if (file-exists-p fname)
770 ;; set real size and modtime
771 (setq file-size (ediff-file-size fname)
772 file-modtime (ediff-file-modtime fname))
773 (setq file-size -2))) ; file doesn't exist
774 ( t (setq file-size -1))) ; remote file
779 (if feq "=" " ") ; equality indicator
780 (format "%10s" (cond ((= file-size -1) "--")
781 ((< file-size -1) "--")
783 (cond ((= file-size -1) "*remote file*")
784 ((< file-size -1) "*file doesn't exist*")
785 (t (ediff-format-date (decode-time file-modtime))))
787 ;; dir names in meta lists have training slashes, so we just
788 ;; abbreviate the file name, if file exists
789 (if (and (not (stringp fname)) (< file-size -1))
790 "-------" ; file doesn't exist
791 (ediff-abbreviate-file-name fname)))))))
793 (defconst ediff-months '((1 . "Jan") (2 . "Feb") (3 . "Mar") (4 . "Apr")
794 (5 . "May") (6 . "Jun") (7 . "Jul") (8 . "Aug")
795 (9 . "Sep") (10 . "Oct") (11 . "Nov") (12 . "Dec"))
796 "Months' associative array.")
798 ;; returns 2char string
799 (defsubst ediff-fill-leading-zero (num)
802 (number-to-string num)))
804 ;; TIME is like the output of decode-time
805 (defun ediff-format-date (time)
806 (format "%s %2d %4d %s:%s:%s"
807 (cdr (assoc (nth 4 time) ediff-months)) ; month
810 (ediff-fill-leading-zero (nth 2 time)) ; hour
811 (ediff-fill-leading-zero (nth 1 time)) ; min
812 (ediff-fill-leading-zero (nth 0 time)) ; sec
815 (defun ediff-draw-dir-diffs (diff-list)
816 (if (null diff-list) (error "Lost difference info on these directories"))
817 (let* ((buf-name (ediff-unique-buffer-name
818 "*Ediff File Group Differences" "*"))
819 (regexp (ediff-get-group-regexp diff-list))
820 (dir1 (ediff-abbreviate-file-name (ediff-get-group-objA diff-list)))
821 (dir2 (ediff-abbreviate-file-name (ediff-get-group-objB diff-list)))
822 (dir3 (ediff-get-group-objC diff-list))
823 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3)))
824 (meta-buf (ediff-get-group-buffer diff-list))
825 (underline (make-string 26 ?-))
828 ;; skip the directory part
829 (setq diff-list (cdr diff-list))
830 (setq ediff-dir-diffs-buffer (get-buffer-create buf-name))
831 (ediff-with-current-buffer ediff-dir-diffs-buffer
832 (use-local-map ediff-dir-diffs-buffer-map)
834 (setq ediff-meta-buffer meta-buf)
835 (insert "\t\t*** Directory Differences ***\n")
838 `q': hide this buffer
840 DEL: previous line\n\n")
842 (if (and (stringp regexp) (> (length regexp) 0))
844 (format "\n*** Filter-through regular expression: %s\n" regexp)))
846 (insert (format "\n%-27s%-26s"
847 (ediff-truncate-string-left
848 (ediff-abbreviate-file-name
849 (file-name-as-directory dir1))
851 (ediff-truncate-string-left
852 (ediff-abbreviate-file-name
853 (file-name-as-directory dir2))
856 (insert (format " %-25s\n"
857 (ediff-truncate-string-left
858 (ediff-abbreviate-file-name
859 (file-name-as-directory dir3))
862 (insert (format "%s%s" underline underline))
864 (insert (format "%s\n\n" underline))
868 (insert "\n\t*** No differences ***\n"))
871 (setq file (car (car diff-list))
872 code (cdr (car diff-list))
873 diff-list (cdr diff-list))
874 (if (= (mod code 2) 0) ; dir1
875 (insert (format "%-27s"
876 (ediff-truncate-string-left
877 (ediff-abbreviate-file-name
878 (if (file-directory-p (concat dir1 file))
879 (file-name-as-directory file)
882 (insert (format "%-27s" "---")))
883 (if (= (mod code 3) 0) ; dir2
884 (insert (format "%-26s"
885 (ediff-truncate-string-left
886 (ediff-abbreviate-file-name
887 (if (file-directory-p (concat dir2 file))
888 (file-name-as-directory file)
891 (insert (format "%-26s" "---")))
893 (if (= (mod code 5) 0) ; dir3
894 (insert (format " %-25s"
895 (ediff-truncate-string-left
896 (ediff-abbreviate-file-name
897 (if (file-directory-p (concat dir3 file))
898 (file-name-as-directory file)
901 (insert (format " %-25s" "---"))))
903 (setq buffer-read-only t)
904 (set-buffer-modified-p nil)) ; eval in diff buffer
907 (defun ediff-bury-dir-diffs-buffer ()
908 "Bury the directory difference buffer. Display the meta buffer instead."
910 (let ((buf ediff-meta-buffer)
913 (if (setq wind (ediff-get-visible-buffer-window buf))
915 (set-window-buffer (selected-window) buf))))
917 ;; executes in dir session group buffer
918 ;; show buffer differences
919 (defun ediff-show-dir-diffs ()
920 "Display differences among the directories involved in session group."
922 (if (ediff-one-filegroup-metajob)
923 (error "This command is inapplicable in the present context"))
924 (or (ediff-buffer-live-p ediff-dir-diffs-buffer)
925 (ediff-draw-dir-diffs ediff-dir-difference-list))
926 (let ((buf ediff-dir-diffs-buffer))
928 (set-window-buffer (selected-window) buf)
929 (goto-char (point-min))))
931 (defun ediff-up-meta-hierarchy ()
932 "Go to the parent session group buffer."
934 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
935 (ediff-show-meta-buffer ediff-parent-meta-buffer)
936 (error "This session group has no parent")))
939 ;; argument is ignored
940 (defun ediff-redraw-registry-buffer (&optional ignore)
941 (ediff-with-current-buffer ediff-registry-buffer
942 (let ((point (point))
943 elt bufAname bufBname bufCname cur-diff total-diffs pt
944 job-name meta-list registry-list buffer-read-only)
946 (insert "This is a registry of all active Ediff sessions.
949 button2, `v', RET over a session record: switch to that session
950 `M' over a session record: display the associated session group
951 `R' in any Ediff session: display session registry
953 DEL:\tprevious session
954 `E':\tbrowse Ediff on-line manual
958 \t\tActive Ediff Sessions:
959 \t\t----------------------
962 ;; purge registry list from dead buffers
963 (mapcar (function (lambda (elt)
964 (if (not (ediff-buffer-live-p elt))
965 (setq ediff-session-registry
966 (delq elt ediff-session-registry)))))
967 ediff-session-registry)
969 (if (null ediff-session-registry)
970 (insert " ******* No active Ediff sessions *******\n"))
972 (setq registry-list ediff-session-registry)
974 (setq elt (car registry-list)
975 registry-list (cdr registry-list))
977 (if (ediff-buffer-live-p elt)
978 (if (ediff-with-current-buffer elt
979 (setq job-name ediff-metajob-name
980 meta-list ediff-meta-list)
981 (and ediff-metajob-name
982 (not (eq ediff-metajob-name 'ediff-registry))))
985 (insert (format " *group*\t%s: %s\n"
987 (ediff-abbrev-jobname job-name)))
988 (insert (format "\t\t %s %s %s\n"
989 (ediff-abbreviate-file-name
990 (ediff-get-group-objA meta-list))
991 (ediff-abbreviate-file-name
993 (ediff-get-group-objB meta-list))
994 (ediff-get-group-objB meta-list)
996 (ediff-abbreviate-file-name
998 (ediff-get-group-objC meta-list))
999 (ediff-get-group-objC meta-list)
1001 (ediff-set-meta-overlay pt (point) elt))
1003 (ediff-with-current-buffer elt
1004 (setq bufAname (if (ediff-buffer-live-p ediff-buffer-A)
1005 (buffer-name ediff-buffer-A)
1006 "!!!killed buffer!!!")
1007 bufBname (if (ediff-buffer-live-p ediff-buffer-B)
1008 (buffer-name ediff-buffer-B)
1009 "!!!killed buffer!!!")
1010 bufCname (cond ((not (ediff-3way-job))
1012 ((ediff-buffer-live-p ediff-buffer-C)
1013 (buffer-name ediff-buffer-C))
1014 (t "!!!killed buffer!!!")))
1015 (setq total-diffs (format "%-4d" ediff-number-of-differences)
1017 (cond ((= ediff-current-difference -1) " _")
1018 ((= ediff-current-difference
1019 ediff-number-of-differences)
1022 "%4d" (1+ ediff-current-difference))))
1023 job-name ediff-job-name))
1024 ;; back in the meta buf
1026 (insert cur-diff "/" total-diffs "\t"
1028 (format ": %s" (ediff-abbrev-jobname job-name)))
1030 "\n\t\t " bufAname " " bufBname " " bufCname "\n")
1031 (ediff-set-meta-overlay pt (point) elt))))
1033 (set-buffer-modified-p nil)
1037 ;; sets overlay around a meta record with 'ediff-meta-info property PROP
1038 (defun ediff-set-meta-overlay (b e prop)
1040 (setq overl (ediff-make-overlay b e))
1042 (ediff-overlay-put overl 'mouse-face 'highlight)
1043 (ediff-overlay-put overl 'highlight t))
1044 (ediff-overlay-put overl 'ediff-meta-info prop)))
1046 (defun ediff-mark-for-hiding (unmark)
1047 "Mark session for hiding. With prefix arg, unmark."
1049 (let* ((pos (ediff-event-point last-command-event))
1050 (meta-buf (ediff-event-buffer last-command-event))
1051 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1052 (info (ediff-get-meta-info meta-buf pos))
1053 (session-buf (ediff-get-session-buffer info)))
1055 (if (eq (ediff-get-session-status info) ?H)
1058 (ediff-set-session-status info nil)
1059 (if (ediff-buffer-live-p session-buf)
1060 (error "Can't hide active session, %s" (buffer-name session-buf)))
1061 (ediff-set-session-status info ?H))
1063 (ediff-next-meta-item 1))
1064 (ediff-update-meta-buffer meta-buf)
1067 (defun ediff-mark-for-operation (unmark)
1068 "Mark session for a group operation. With prefix arg, unmark."
1070 (let* ((pos (ediff-event-point last-command-event))
1071 (meta-buf (ediff-event-buffer last-command-event))
1072 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1073 (info (ediff-get-meta-info meta-buf pos)))
1075 (if (eq (ediff-get-session-status info) ?*)
1078 (ediff-set-session-status info nil)
1079 (ediff-set-session-status info ?*))
1081 (ediff-next-meta-item 1))
1082 (ediff-update-meta-buffer meta-buf)
1085 (defun ediff-hide-marked-sessions (unhide)
1086 "Hide marked sessions. With prefix arg, unhide."
1088 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1089 (meta-list (cdr ediff-meta-list))
1090 (from (if unhide ?I ?H))
1091 (to (if unhide ?H ?I))
1093 active-sessions-exist session-buf elt)
1095 (setq elt (car meta-list)
1096 meta-list (cdr meta-list)
1097 session-buf (ediff-get-session-buffer elt))
1099 (if (eq (ediff-get-session-status elt) from)
1101 (setq numMarked (1+ numMarked))
1102 (if (and (eq to ?I) (buffer-live-p session-buf))
1103 ;; shouldn't hide active sessions
1104 (setq active-sessions-exist t)
1105 (ediff-set-session-status elt to)))))
1107 (ediff-update-meta-buffer grp-buf)
1110 (message "Nothing to reveal...")
1111 (message "Nothing to hide...")))
1112 (if active-sessions-exist
1113 (message "Note: didn't hide active sessions!"))
1116 ;; Apply OPERATION to marked sessions. Operation expects one argument of type
1117 ;; meta-list member (not the first one), i.e., a regular session description.
1118 ;; Returns number of marked sessions on which operation was performed
1119 (defun ediff-operate-on-marked-sessions (operation)
1120 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1121 (meta-list (cdr ediff-meta-list))
1127 (setq elt (car meta-list)
1128 meta-list (cdr meta-list)
1129 sessionNum (1+ sessionNum))
1130 (if (eq (ediff-get-session-status elt) marksym)
1132 (setq numMarked (1+ numMarked))
1133 (funcall operation elt sessionNum))))
1134 (ediff-update-meta-buffer grp-buf) ; just in case
1138 (defun ediff-append-custom-diff (session sessionNum)
1139 (or (ediff-collect-diffs-metajob)
1140 (error "Sorry, I don't do this for everyone..."))
1141 (let ((session-buf (ediff-get-session-buffer session))
1142 (meta-diff-buff ediff-meta-diff-buffer)
1143 (metajob ediff-metajob-name)
1144 tmp-buf custom-diff-buf)
1145 (if (ediff-buffer-live-p session-buf)
1146 (ediff-with-current-buffer session-buf
1147 (if (eq ediff-control-buffer session-buf) ; individual session
1149 (ediff-compute-custom-diffs-maybe)
1150 (setq custom-diff-buf ediff-custom-diff-buffer)))))
1152 (or (ediff-buffer-live-p meta-diff-buff)
1153 (error "Ediff: something wrong--no multiple diffs buffer"))
1155 (cond ((ediff-buffer-live-p custom-diff-buf)
1157 (set-buffer meta-diff-buff)
1158 (goto-char (point-max))
1159 (insert-buffer custom-diff-buf)
1161 ((memq metajob '(ediff-directories
1162 ediff-merge-directories
1163 ediff-merge-directories-with-ancestor))
1164 ;; get diffs by calling shell command on ediff-custom-diff-program
1166 (set-buffer (setq tmp-buf (get-buffer-create ediff-tmp-buffer)))
1169 (format "%s %s %s %s"
1170 ediff-custom-diff-program ediff-custom-diff-options
1171 (ediff-get-session-objA-name session)
1172 (ediff-get-session-objB-name session))
1175 (set-buffer meta-diff-buff)
1176 (goto-char (point-max))
1177 (insert-buffer tmp-buf)
1180 (error "Can't make context diff for Session %d" sessionNum )))
1183 (defun ediff-collect-custom-diffs ()
1184 "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'.
1185 This operation is defined only for `ediff-directories' and
1186 `ediff-directory-revisions', since its intent is to produce
1187 multifile patches. For `ediff-directory-revisions', we insist that
1188 all marked sessions must be active."
1190 (or (ediff-buffer-live-p ediff-meta-diff-buffer)
1191 (setq ediff-meta-diff-buffer
1193 (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
1194 (ediff-with-current-buffer ediff-meta-diff-buffer
1196 (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
1198 (display-buffer ediff-meta-diff-buffer 'not-this-window)
1200 (message "No marked sessions found")))
1202 (defun ediff-meta-show-patch ()
1203 "Show the multi-file patch associated with this group session."
1205 (let* ((pos (ediff-event-point last-command-event))
1206 (meta-buf (ediff-event-buffer last-command-event))
1207 (info (ediff-get-meta-info meta-buf pos 'noerror))
1208 (patchbuffer ediff-meta-patchbufer))
1209 (if (ediff-buffer-live-p patchbuffer)
1210 (ediff-with-current-buffer patchbuffer
1215 (ediff-get-session-objB-name info)
1216 (ediff-get-session-objC-name info)))
1217 (set-buffer (get-buffer-create ediff-tmp-buffer))
1219 (insert-buffer patchbuffer)
1220 (display-buffer ediff-tmp-buffer 'not-this-window)
1222 (error "The patch buffer wasn't found"))))
1225 ;; This function executes in meta buffer. It knows where event happened.
1226 (defun ediff-filegroup-action ()
1227 "Execute appropriate action for the selected session."
1229 (let* ((pos (ediff-event-point last-command-event))
1230 (meta-buf (ediff-event-buffer last-command-event))
1231 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1232 (info (ediff-get-meta-info meta-buf pos))
1234 session-buf file1 file2 file3 regexp)
1236 (setq session-buf (ediff-get-session-buffer info)
1237 file1 (ediff-get-session-objA-name info)
1238 file2 (ediff-get-session-objB-name info)
1239 file3 (ediff-get-session-objC-name info))
1241 ;; make sure we don't start on hidden sessions
1242 ;; ?H means marked for hiding. ?I means invalid (hidden).
1243 (if (memq (ediff-get-session-status info) '(?I))
1246 (if (y-or-n-p "This session is marked as hidden, unmark? ")
1248 (ediff-set-session-status info nil)
1249 (ediff-update-meta-buffer meta-buf))
1250 (error "Aborted"))))
1252 (ediff-with-current-buffer meta-buf
1253 (setq merge-autostore-dir
1254 (ediff-get-group-merge-autostore-dir ediff-meta-list))
1255 (goto-char pos) ; if the user clicked on session--move point there
1256 ;; First handle sessions involving directories (which are themselves
1258 ;; After that handle individual sessions
1259 (cond ((and (file-directory-p file1)
1260 (stringp file2) (file-directory-p file2)
1261 (if (stringp file3) (file-directory-p file1) t))
1262 ;; do ediff/ediff-merge on subdirectories
1263 (if (ediff-buffer-live-p session-buf)
1264 (ediff-show-meta-buffer session-buf)
1265 (setq regexp (read-string "Filter through regular expression: "
1266 nil 'ediff-filtering-regexp-history))
1267 (ediff-directories-internal
1268 file1 file2 file3 regexp
1269 ediff-session-action-function
1271 ;; make it update car info after startup
1273 ;; child session group should know its parent
1274 (setq ediff-parent-meta-buffer
1275 (quote (, ediff-meta-buffer)))
1276 ;; and parent will know its child
1277 (setcar (quote (, info)) ediff-meta-buffer)))))))
1279 ;; Do ediff-revision on a subdirectory
1280 ((and (ediff-one-filegroup-metajob)
1281 (ediff-revision-metajob)
1282 (file-directory-p file1))
1283 (if (ediff-buffer-live-p session-buf)
1284 (ediff-show-meta-buffer session-buf)
1285 (setq regexp (read-string "Filter through regular expression: "
1286 nil 'ediff-filtering-regexp-history))
1287 (ediff-directory-revisions-internal
1289 ediff-session-action-function ediff-metajob-name
1290 ;; make it update car info after startup
1292 ;; child session group should know its parent
1293 (setq ediff-parent-meta-buffer
1294 (quote (, ediff-meta-buffer)))
1295 ;; and parent will know its child
1296 (setcar (quote (, info)) ediff-meta-buffer)))))))
1298 ;; From here on---only individual session handlers
1300 ;; handle an individual session with a live control buffer
1301 ((ediff-buffer-live-p session-buf)
1302 (ediff-with-current-buffer session-buf
1303 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1304 (ediff-recenter 'no-rehighlight)))
1306 ((ediff-problematic-session-p info)
1309 "This session has no ancestor. Merge without the ancestor? ")
1312 ;; provide startup hooks
1314 (setq ediff-meta-buffer (, (current-buffer)))
1315 (setq ediff-merge-store-file
1319 (file-name-nondirectory file1))))
1320 ;; make ediff-startup pass
1321 ;; ediff-control-buffer back to the meta
1324 (quote (, info)) ediff-control-buffer)))))
1326 ((ediff-one-filegroup-metajob) ; needs 1 file arg
1327 (funcall ediff-session-action-function
1329 ;; provide startup hooks
1331 (setq ediff-meta-buffer (, (current-buffer)))
1332 (setq ediff-merge-store-file
1336 (file-name-nondirectory file1))))
1337 ;; make ediff-startup pass
1338 ;; ediff-control-buffer back to the meta
1341 (quote (, info)) ediff-control-buffer))))))
1342 ((not (ediff-metajob3)) ; need 2 file args
1343 (funcall ediff-session-action-function
1345 ;; provide startup hooks
1347 (setq ediff-meta-buffer (, (current-buffer)))
1348 (setq ediff-merge-store-file
1352 (file-name-nondirectory file1))))
1353 ;; make ediff-startup pass
1354 ;; ediff-control-buffer back to the meta
1357 (quote (, info)) ediff-control-buffer))))))
1358 ((ediff-metajob3) ; need 3 file args
1359 (funcall ediff-session-action-function
1361 ;; arrange startup hooks
1363 (setq ediff-merge-store-file
1367 (file-name-nondirectory file1))))
1368 (setq ediff-meta-buffer (, (current-buffer)))
1369 ;; this arranges that ediff-startup will pass
1370 ;; the value of ediff-control-buffer back to
1371 ;; the meta level, to the record in the meta
1372 ;; list containing the information about the
1373 ;; session associated with that
1374 ;; ediff-control-buffer
1376 (quote (, info)) ediff-control-buffer))))))
1378 ) ; eval in meta-buf
1381 (defun ediff-registry-action ()
1382 "Switch to a selected session."
1384 (let* ((pos (ediff-event-point last-command-event))
1385 (buf (ediff-event-buffer last-command-event))
1386 (ctl-buf (ediff-get-meta-info buf pos)))
1388 (if (ediff-buffer-live-p ctl-buf)
1389 ;; check if this is ediff-control-buffer or ediff-meta-buffer
1390 (if (ediff-with-current-buffer ctl-buf
1391 (eq (key-binding "q") 'ediff-quit-meta-buffer))
1392 ;; it's a meta-buffer -- last action should just display it
1393 (ediff-show-meta-buffer ctl-buf)
1394 ;; it's a session buffer -- invoke go back to session
1395 (ediff-with-current-buffer ctl-buf
1396 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1397 (ediff-recenter 'no-rehighlight)))
1399 (message "You've selected a stale session --- try again")
1400 (ediff-update-registry))
1401 (ediff-with-current-buffer buf
1406 (defun ediff-show-meta-buffer (&optional meta-buf)
1407 "Show the session group buffer."
1409 (let (wind frame silent)
1410 (if meta-buf (setq silent t))
1412 (setq meta-buf (or meta-buf ediff-meta-buffer))
1413 (cond ((not (bufferp meta-buf))
1414 (error "This Ediff session is not part of a session group"))
1415 ((not (ediff-buffer-live-p meta-buf))
1417 "Can't find this session's group panel -- session itself is ok")))
1419 (ediff-cleanup-meta-buffer meta-buf)
1420 (ediff-with-current-buffer meta-buf
1422 (cond ((setq wind (ediff-get-visible-buffer-window meta-buf))
1425 "Already showing the group panel for this session"))
1426 (set-window-buffer wind meta-buf)
1427 (select-window wind))
1428 ((window-live-p (setq wind ediff-window-C)) ;in merge--merge buf
1429 (set-window-buffer ediff-window-C meta-buf)
1430 (select-window wind))
1431 ((window-live-p (setq wind ediff-window-A))
1432 (set-window-buffer ediff-window-A meta-buf)
1433 (select-window wind))
1434 ((window-live-p (setq wind ediff-window-B))
1435 (set-window-buffer ediff-window-B meta-buf)
1436 (select-window wind))
1439 (ediff-get-visible-buffer-window ediff-registry-buffer))
1440 (ediff-window-display-p))
1441 (select-window wind)
1443 (set-window-buffer (selected-window) meta-buf))
1444 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1445 (set-window-buffer (selected-window) meta-buf)))
1447 (if (and (ediff-window-display-p)
1449 (setq wind (ediff-get-visible-buffer-window meta-buf))))
1451 (setq frame (window-frame wind))
1453 (ediff-reset-mouse frame)))
1454 (run-hooks 'ediff-show-session-group-hook)
1457 (defun ediff-show-meta-buff-from-registry ()
1458 "Display the session group buffer for a selected session group."
1460 (let* ((pos (ediff-event-point last-command-event))
1461 (meta-buf (ediff-event-buffer last-command-event))
1462 (info (ediff-get-meta-info meta-buf pos))
1463 (meta-or-session-buf info))
1464 (ediff-with-current-buffer meta-or-session-buf
1465 (ediff-show-meta-buffer))))
1468 (defun ediff-show-registry ()
1469 "Display Ediff's registry."
1471 (ediff-update-registry)
1472 (if (not (ediff-buffer-live-p ediff-registry-buffer))
1473 (error "No active Ediff sessions or corrupted session registry"))
1475 ;; for some reason, point moves in ediff-registry-buffer, so we preserve it
1477 (ediff-with-current-buffer ediff-registry-buffer
1480 (ediff-get-visible-buffer-window ediff-registry-buffer))
1481 (message "Already showing the registry")
1482 (set-window-buffer wind ediff-registry-buffer)
1483 (select-window wind))
1484 ((window-live-p ediff-window-C)
1485 (set-window-buffer ediff-window-C ediff-registry-buffer)
1486 (select-window ediff-window-C))
1487 ((window-live-p ediff-window-A)
1488 (set-window-buffer ediff-window-A ediff-registry-buffer)
1489 (select-window ediff-window-A))
1490 ((window-live-p ediff-window-B)
1491 (set-window-buffer ediff-window-B ediff-registry-buffer)
1492 (select-window ediff-window-B))
1494 (ediff-get-visible-buffer-window ediff-meta-buffer))
1495 (ediff-window-display-p))
1496 (select-window wind)
1498 (set-window-buffer (selected-window) ediff-registry-buffer))
1499 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1500 (set-window-buffer (selected-window) ediff-registry-buffer)))
1502 (if (ediff-window-display-p)
1506 (ediff-get-visible-buffer-window ediff-registry-buffer)))
1508 (ediff-reset-mouse frame)))
1509 (run-hooks 'ediff-show-registry-hook)
1513 (defalias 'eregistry 'ediff-show-registry)
1515 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a
1517 ;; Check if META-BUF exists before calling this function
1518 (defun ediff-update-meta-buffer (meta-buf)
1519 (ediff-with-current-buffer (current-buffer)
1520 (if (ediff-buffer-live-p meta-buf)
1521 (ediff-with-current-buffer meta-buf
1522 (funcall ediff-meta-redraw-function ediff-meta-list))
1525 (defun ediff-update-registry ()
1526 (ediff-with-current-buffer (current-buffer)
1527 (if (ediff-buffer-live-p ediff-registry-buffer)
1528 (ediff-redraw-registry-buffer)
1529 (ediff-prepare-meta-buffer
1530 'ediff-registry-action
1531 ediff-session-registry
1533 'ediff-redraw-registry-buffer
1537 ;; If meta-buf exists, it is redrawn along with parent.
1538 ;; Otherwise, nothing happens.
1539 (defun ediff-cleanup-meta-buffer (meta-buffer)
1540 (if (ediff-buffer-live-p meta-buffer)
1541 (ediff-with-current-buffer meta-buffer
1542 (ediff-update-meta-buffer meta-buffer)
1543 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1544 (ediff-update-meta-buffer ediff-parent-meta-buffer)))))
1546 ;; t if no session in progress
1547 (defun ediff-safe-to-quit (meta-buffer)
1548 (if (ediff-buffer-live-p meta-buffer)
1549 (let ((lis ediff-meta-list)
1552 (ediff-update-meta-buffer meta-buffer)
1553 (ediff-with-current-buffer meta-buffer
1554 (setq lis (cdr lis)) ; discard the description part of meta-list
1555 (while (and cont lis)
1556 (if (ediff-buffer-live-p
1557 (ediff-get-group-buffer lis)) ; in progress
1559 (setq lis (cdr lis)))
1562 (defun ediff-quit-meta-buffer ()
1563 "If the group has no active session, delete the meta buffer.
1564 If no session is in progress, ask to confirm before deleting meta buffer.
1565 Otherwise, bury the meta buffer.
1566 If this is a session registry buffer then just bury it."
1568 (let* ((buf (current-buffer))
1569 (dir-diffs-buffer ediff-dir-diffs-buffer)
1570 (meta-diff-buffer ediff-meta-diff-buffer)
1571 (parent-buf ediff-parent-meta-buffer)
1572 (dont-show-registry (eq buf ediff-registry-buffer)))
1573 (if dont-show-registry
1575 (ediff-cleanup-meta-buffer buf)
1576 (cond ((and (ediff-safe-to-quit buf)
1577 (y-or-n-p "Quit this session group? "))
1578 (run-hooks 'ediff-quit-session-group-hook)
1580 (ediff-dispose-of-meta-buffer buf))
1581 ((ediff-safe-to-quit buf)
1585 "This session group has active sessions---cannot exit")))
1586 (ediff-cleanup-meta-buffer parent-buf)
1587 (ediff-kill-buffer-carefully dir-diffs-buffer)
1588 (ediff-kill-buffer-carefully meta-diff-buffer)
1589 (if (ediff-buffer-live-p parent-buf)
1591 (setq dont-show-registry t)
1592 (ediff-show-meta-buffer parent-buf)))
1594 (or dont-show-registry
1595 (ediff-show-registry))))
1597 (defun ediff-dispose-of-meta-buffer (buf)
1598 (setq ediff-session-registry (delq buf ediff-session-registry))
1599 (ediff-with-current-buffer buf
1600 (if (ediff-buffer-live-p ediff-dir-diffs-buffer)
1601 (kill-buffer ediff-dir-diffs-buffer)))
1605 ;; Obtain information on a meta record where the user clicked or typed
1606 ;; BUF is the buffer where this happened and POINT is the position
1607 ;; If optional NOERROR arg is given, don't report error and return nil if no
1608 ;; meta info is found on line.
1609 (defun ediff-get-meta-info (buf point &optional noerror)
1610 (let (result olist tmp)
1611 (if (and point (ediff-buffer-live-p buf))
1612 (ediff-with-current-buffer buf
1615 (if (setq tmp (extent-at point buf 'ediff-meta-info))
1616 (ediff-overlay-get tmp 'ediff-meta-info)))
1617 (setq olist (overlays-at point))
1619 (mapcar (function (lambda (elt)
1620 (overlay-get elt 'ediff-meta-info)))
1622 (while (and olist (null (car olist))
1623 (overlay-get (car olist) 'invisible))
1624 (setq olist (cdr olist)))
1625 (setq result (car olist)))))
1630 (ediff-update-registry)
1631 (error "No session info in this line")))))
1633 ;; return location of the next meta overlay after point
1634 (defun ediff-next-meta-overlay-start (point)
1636 (goto-char (point-min))
1640 (setq overl (extent-at point (current-buffer) 'ediff-meta-info))
1642 (setq overl (next-extent overl))
1643 (setq overl (next-extent (current-buffer))))
1645 (extent-start-position overl)
1647 (setq overl (car (overlays-at point)))
1648 (if (and overl (overlay-get overl 'ediff-meta-info))
1649 ;; note: end of current overlay is the beginning of the next one
1651 (next-overlay-change point))))
1654 (defun ediff-previous-meta-overlay-start (point)
1656 (goto-char (point-max))
1660 (setq overl (extent-at point (current-buffer) 'ediff-meta-info))
1662 (setq overl (previous-extent overl))
1663 (setq overl (previous-extent (current-buffer))))
1665 (extent-start-position overl)
1667 (setq overl (car (overlays-at point)))
1668 (if (and overl (overlay-get overl 'ediff-meta-info))
1669 (setq point (overlay-start overl)))
1670 ;; to get to the beginning of prev overlay
1672 ;; trickery to overcome an emacs bug--doesn't always find previous
1673 ;; overlay change correctly
1674 (setq point (1- point)))
1675 (setq point (previous-overlay-change point))
1676 ;; If we are not over an overlay after subtracting 1, it means we are
1677 ;; in the description area preceding session records. In this case,
1678 ;; goto the top of the registry buffer.
1679 (or (car (overlays-at point))
1680 (setq point (point-min)))
1684 ;; this is the action invoked when the user selects a patch from the meta
1686 (defun ediff-patch-file-form-meta (file &optional startup-hooks)
1687 (let* ((pos (ediff-event-point last-command-event))
1688 (meta-buf (ediff-event-buffer last-command-event))
1689 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1690 (info (ediff-get-meta-info meta-buf pos))
1691 (meta-patchbuf ediff-meta-patchbufer)
1692 session-buf beg-marker end-marker)
1694 (if (or (file-directory-p file) (string-match "/dev/null" file))
1695 (error "`%s' is not an ordinary file" (file-name-as-directory file)))
1696 (setq session-buf (ediff-get-session-buffer info)
1697 beg-marker (ediff-get-session-objB-name info)
1698 end-marker (ediff-get-session-objC-name info))
1700 (or (ediff-buffer-live-p session-buf) ; either an active patch session
1701 (null session-buf) ; or it is a virgin session
1703 "Patch has been already applied to this file--cannot be repeated!"))
1705 (ediff-with-current-buffer meta-patchbuf
1708 (narrow-to-region beg-marker end-marker)
1709 (ediff-patch-file-internal meta-patchbuf file startup-hooks)))))
1712 (defun ediff-meta-mark-equal-files ()
1713 "Run though the session list and mark identical files.
1714 This is used only for sessions that involve 2 or 3 files at the same time."
1716 (let ((list (cdr ediff-meta-list))
1717 fileinfo1 fileinfo2 fileinfo3 elt)
1718 (while (setq elt (car list))
1719 (setq fileinfo1 (ediff-get-session-objA elt)
1720 fileinfo2 (ediff-get-session-objB elt)
1721 fileinfo3 (ediff-get-session-objC elt))
1722 (ediff-set-file-eqstatus fileinfo1 nil)
1723 (ediff-set-file-eqstatus fileinfo2 nil)
1724 (ediff-set-file-eqstatus fileinfo3 nil)
1726 (ediff-mark-if-equal fileinfo1 fileinfo2)
1727 (if (ediff-metajob3)
1729 (ediff-mark-if-equal fileinfo1 fileinfo3)
1730 (ediff-mark-if-equal fileinfo2 fileinfo3)))
1731 (setq list (cdr list))))
1732 (ediff-update-meta-buffer (current-buffer)))
1734 ;; mark files 1 and 2 as equal, if they are.
1735 (defun ediff-mark-if-equal (fileinfo1 fileinfo2)
1736 (get-buffer-create ediff-tmp-buffer)
1737 (or (file-directory-p (car fileinfo1))
1738 (file-directory-p (car fileinfo2))
1739 (if (= (ediff-make-diff2-buffer
1740 ediff-tmp-buffer (car fileinfo1) (car fileinfo2))
1743 (ediff-set-file-eqstatus fileinfo1 t)
1744 (ediff-set-file-eqstatus fileinfo2 t)))))
1748 ;;; Local Variables:
1749 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1750 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
1751 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1754 ;;; ediff-mult.el ends here