1 ;;; ediff-mult.el --- support for multi-file/multi-buffer processing in Ediff
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
4 ;; 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
27 ;; Users are encouraged to add functionality to this file.
28 ;; The present file contains all the infrastructure needed for that.
30 ;; Generally, to implement a new multisession capability within Ediff,
31 ;; you need to tell it
33 ;; 1. How to display the session group buffer.
34 ;; This function must indicate which Ediff sessions are active (+) and
35 ;; which are finished (-).
36 ;; See ediff-redraw-directory-group-buffer for an example.
37 ;; In all likelihood, ediff-redraw-directory-group-buffer can be used
38 ;; directly or after a small modification.
39 ;; 2. What action to take when the user clicks button 2 or types v,e, or
40 ;; RET. See ediff-filegroup-action.
41 ;; 3. Provide a list of pairs or triples of file names (or buffers,
42 ;; depending on the particular Ediff operation you want to invoke)
43 ;; in the following format:
44 ;; (HEADER (nil nil (obj1 nil) (obj2 nil) (obj3 nil))
46 ;; The function ediff-make-new-meta-list-element can be used to create
47 ;; 2nd and subsequent elements of that list (i.e., after the
48 ;; description header). See ediff-make-new-meta-list-element for the
49 ;; explanation of the two nil placeholders in such elements.
51 ;; There is API for extracting the components of the members of the
52 ;; above list. Search for `API for ediff-meta-list' for details.
54 ;; HEADER must be a list of SIX elements (nil or string):
55 ;; (regexp metaobj1 metaobj2 metaobj3 merge-save-buffer
56 ;; comparison-function)
57 ;; The function ediff-redraw-registry-buffer displays the
58 ;; 1st - 4th of these in the registry buffer.
59 ;; For some jobs some of the members of the header might be nil.
60 ;; The meaning of metaobj1, metaobj2, and metaobj3 depend on the job.
61 ;; Typically these are directories where the files to be compared are
63 ;; Also, keep in mind that the function ediff-prepare-meta-buffer
64 ;; (which see) prepends the session group buffer to the descriptor, so
65 ;; the descriptor becomes 7-long.
66 ;; Ediff expects that your function (in 2 above) will arrange to
67 ;; replace this prepended nil (via setcar) with the actual ediff
68 ;; control buffer associated with an appropriate Ediff session.
69 ;; This is arranged through internal startup hooks that can be passed
70 ;; to any of Ediff major entries (such as ediff-files, epatch, etc.).
71 ;; See how this is done in ediff-filegroup-action.
73 ;; Session descriptions are of the form
74 ;; (nil nil (obj1 . nil) (obj2 . nil) (obj3 . nil))
75 ;; which describe the objects relevant to the session.
76 ;; Use ediff-make-new-meta-list-element to create these things.
77 ;; Usually obj1/2/3 are names of files, but they may also be other
78 ;; things for some jobs. For instance, obj3 is nil for jobs that
79 ;; involve only two files. For patch jobs, obj2 and obj3 are markers
80 ;; that specify the patch corresponding to the file
81 ;; (whose name is obj1).
82 ;; The nil's are placeholders, which are used internally by ediff.
83 ;; 4. Write a function that makes a call to ediff-prepare-meta-buffer
84 ;; passing all this info.
85 ;; You may be able to use ediff-directories-internal as a template.
86 ;; 5. If you intend to add several related pieces of functionality,
87 ;; you may want to keep the function in 4 as an internal version
88 ;; and then write several top-level interactive functions that call it
89 ;; with different parameters.
90 ;; See how ediff-directories, ediff-merge-directories, and
91 ;; ediff-merge-directories-with-ancestor all use
92 ;; ediff-directories-internal.
94 ;; A useful addition here could be session groups selected by patterns
95 ;; (which are different in each directory). For instance, one may want to
96 ;; compare files of the form abc{something}.c to files old{something}.d
97 ;; which may be in the same or different directories. Or, one may want to
98 ;; compare all files of the form {something} to files of the form {something}~.
100 ;; Implementing this requires writing a collating function, which should pair
101 ;; up appropriate files. It will also require a generalization of the
102 ;; functions that do the layout of the meta- and differences buffers and of
103 ;; ediff-filegroup-action.
108 (defgroup ediff-mult nil
109 "Multi-file and multi-buffer processing in Ediff."
116 (let ((load-path (cons (expand-file-name ".") load-path
)))
117 (or (featurep 'ediff-init
)
118 (load "ediff-init.el" nil t
'nosuffix
))
119 (or (featurep 'ediff-util
)
120 (load "ediff-util.el" nil t
'nosuffix
))
124 (require 'ediff-init
)
127 (ediff-defvar-local ediff-meta-buffer nil
"")
128 (ediff-defvar-local ediff-parent-meta-buffer nil
"")
129 ;; the registry buffer
130 (defvar ediff-registry-buffer nil
)
132 (defconst ediff-meta-buffer-brief-message
"Ediff Session Group Panel: %s
134 Type ? to show useful commands in this buffer
138 (defconst ediff-meta-buffer-verbose-message
"Ediff Session Group Panel: %s
140 Useful commands (type ? to hide them and free up screen):
141 button2, v, or RET over session record: start that Ediff session
142 M:\tin sessions invoked from here, brings back this group panel
143 R:\tdisplay the registry of active Ediff sessions
144 h:\tmark session for hiding (toggle)
145 x:\thide marked sessions; with prefix arg: unhide
146 m:\tmark session for a non-hiding operation (toggle)
147 uh/um:\tunmark all sessions marked for hiding/operation
149 p,DEL:\tprevious session
150 E:\tbrowse Ediff on-line manual
151 T:\ttoggle truncation of long file names
152 q:\tquit this session group
155 (ediff-defvar-local ediff-meta-buffer-map nil
156 "The keymap for the meta buffer.")
157 (defvar ediff-dir-diffs-buffer-map
(make-sparse-keymap)
158 "The keymap to be installed in the buffer showing differences between
161 ;; Variable specifying the action to take when the use invokes ediff in the
162 ;; meta buffer. This is usually ediff-registry-action or ediff-filegroup-action
163 (ediff-defvar-local ediff-meta-action-function nil
"")
164 ;; Tells ediff-update-meta-buffer how to redraw it
165 (ediff-defvar-local ediff-meta-redraw-function nil
"")
166 ;; Tells ediff-filegroup-action and similar procedures how to invoke Ediff for
167 ;; the sessions in a given session group
168 (ediff-defvar-local ediff-session-action-function nil
"")
170 (ediff-defvar-local ediff-metajob-name nil
"")
172 ;; buffer used to collect custom diffs from individual sessions in the group
173 (ediff-defvar-local ediff-meta-diff-buffer nil
"")
175 ;; t means recurse into subdirs when deciding which files have same contents
176 (ediff-defvar-local ediff-recurse-to-subdirectories nil
"")
178 ;; history var to use for filtering groups of files
179 (defvar ediff-filtering-regexp-history nil
"")
181 (defcustom ediff-default-filtering-regexp nil
182 "The default regular expression used as a filename filter in multifile comparisons.
183 Should be a sexp. For instance (car ediff-filtering-regexp-history) or nil."
187 ;; This has the form ((meta-buf regexp dir1 dir2 dir3 merge-auto-store-dir)
188 ;; (ctl-buf session-status (file1 . eq-status) (file2 . eq-status) (file3
189 ;; . eq-status)) (ctl-buf session-status (file1 . eq-status) (file2
190 ;; . eq-status)) ...)
191 ;; If ctl-buf is nil, the file-pair hasn't processed yet. If it is
192 ;; killed-buffer object, the file pair has been processed. If it is a live
193 ;; buffer, this means ediff is still working on the pair.
194 ;; Eq-status of a file is t if the file equals some other file in the same
196 (ediff-defvar-local ediff-meta-list nil
"")
198 (ediff-defvar-local ediff-meta-session-number nil
"")
201 ;; the difference list between directories in a directory session group
202 (ediff-defvar-local ediff-dir-difference-list nil
"")
203 (ediff-defvar-local ediff-dir-diffs-buffer nil
"")
205 ;; The registry of Ediff sessions. A list of control buffers.
206 (defvar ediff-session-registry nil
)
208 (defcustom ediff-meta-truncate-filenames t
209 "*If non-nil, truncate long file names in the session group buffers.
210 This can be toggled with `ediff-toggle-filename-truncation'."
214 (defcustom ediff-meta-mode-hook nil
215 "*Hooks run just after setting up meta mode."
219 (defcustom ediff-registry-setup-hook nil
220 "*Hooks run just after the registry control panel is set up."
224 (defcustom ediff-before-session-group-setup-hooks nil
225 "*Hooks to run before Ediff arranges the window for group-level operations.
226 It is used by commands such as `ediff-directories'.
227 This hook can be used to save the previous window config, which can be restored
228 on `ediff-quit', `ediff-suspend', or `ediff-quit-session-group-hook'."
231 (defcustom ediff-after-session-group-setup-hook nil
232 "*Hooks run just after a meta-buffer controlling a session group, such as
233 ediff-directories, is run."
236 (defcustom ediff-quit-session-group-hook nil
237 "*Hooks run just before exiting a session group."
240 (defcustom ediff-show-registry-hook nil
241 "*Hooks run just after the registry buffer is shown."
244 (defcustom ediff-show-session-group-hook
'(delete-other-windows)
245 "*Hooks run just after a session group buffer is shown."
248 (defcustom ediff-meta-buffer-keymap-setup-hook nil
249 "*Hooks run just after setting up the `ediff-meta-buffer-map'.
250 This keymap controls key bindings in the meta buffer and is a local variable.
251 This means that you can set different bindings for different kinds of meta
256 ;; Buffer holding the multi-file patch. Local to the meta buffer
257 (ediff-defvar-local ediff-meta-patchbufer nil
"")
259 ;;; API for ediff-meta-list
261 ;; A meta-list is either ediff-meta-list, which contains a header and the list
262 ;; of ediff sessions or ediff-dir-difference-list, which is a header followed
263 ;; by the list of differences among the directories (i.e., files that are not
264 ;; in all directories). The header is the same in all meta lists, but the rest
266 ;; Structure of the meta-list:
267 ;; (HEADER SESSION1 SESSION2 ...)
268 ;; HEADER: (GROUP-BUF REGEXP OBJA OBJB OBJC SAVE-DIR COMPARISON-FUNC)
269 ;; OBJA - first directory
270 ;; OBJB - second directory
271 ;; OBJC - third directory
272 ;; SESSION1/2/... are described below
273 ;; group buffer/regexp
274 (defsubst ediff-get-group-buffer
(meta-list)
275 (nth 0 (car meta-list
)))
277 (defsubst ediff-get-group-regexp
(meta-list)
278 (nth 1 (car meta-list
)))
280 (defsubst ediff-get-group-objA
(meta-list)
281 (nth 2 (car meta-list
)))
282 (defsubst ediff-get-group-objB
(meta-list)
283 (nth 3 (car meta-list
)))
284 (defsubst ediff-get-group-objC
(meta-list)
285 (nth 4 (car meta-list
)))
286 (defsubst ediff-get-group-merge-autostore-dir
(meta-list)
287 (nth 5 (car meta-list
)))
288 (defsubst ediff-get-group-comparison-func
(meta-list)
289 (nth 6 (car meta-list
)))
291 ;; ELT is a session meta descriptor (what is being preserved as
293 ;; The structure is: (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
294 ;; STATUS is ?I (hidden or invalid), ?* (marked for operation), ?H (hidden)
296 ;; OBJA/B/C is (FILENAME EQSTATUS)
297 ;; EQSTATUS is ?= or nil (?= means that this file is equal to some other
298 ;; file in this session)
300 (defsubst ediff-get-session-buffer
(elt)
302 (defsubst ediff-get-session-status
(elt)
304 (defsubst ediff-set-session-status
(session-info new-status
)
305 (setcar (cdr session-info
) new-status
))
307 (defsubst ediff-get-session-objA
(elt)
309 (defsubst ediff-get-session-objB
(elt)
311 (defsubst ediff-get-session-objC
(elt)
313 ;; Take the "name" component of the object into acount. ObjA/C/B is of the form
314 ;; (name . equality-indicator)
315 (defsubst ediff-get-session-objA-name
(elt)
317 (defsubst ediff-get-session-objB-name
(elt)
319 (defsubst ediff-get-session-objC-name
(elt)
321 ;; equality indicators
322 (defsubst ediff-get-file-eqstatus
(elt)
324 (defsubst ediff-set-file-eqstatus
(elt value
)
325 (setcar (cdr elt
) value
))
327 ;; Create a new element for the meta list out of obj1/2/3, which usually are
330 ;; The first nil in such an element is later replaced with the session buffer.
331 ;; The second nil is reserved for session status.
333 ;; Also, session objects A/B/C are turned into lists of the form (obj nil).
334 ;; This nil is a placeholder for eq-indicator. It is either nil or =.
335 ;; If it is discovered that this file is = to some other
336 ;; file in the same session, eq-indicator is changed to `='.
337 ;; Curently, the eq-indicator is used only for 2 and 3-file jobs.
338 (defun ediff-make-new-meta-list-element (obj1 obj2 obj3
)
339 (list nil nil
(list obj1 nil
) (list obj2 nil
) (list obj3 nil
)))
341 ;; Constructs a meta list header.
342 ;; OBJA, OBJB, OBJC are usually directories involved, but can be different for
343 ;; different jobs. For instance, multifile patch has only OBJA, which is the
345 (defun ediff-make-new-meta-list-header (regexp
349 (list regexp objA objB objC merge-auto-store-dir comparison-func
))
351 ;; The activity marker is either or + (active session, i.e., ediff is currently
352 ;; run in it), or - (finished session, i.e., we've ran ediff in it and then
353 ;; exited). Return nil, if session is neither active nor finished
354 (defun ediff-get-session-activity-marker (session)
355 (let ((session-buf (ediff-get-session-buffer session
)))
356 (cond ((null session-buf
) nil
) ; virgin session
357 ((ediff-buffer-live-p session-buf
) ?
+) ;active session
360 ;; checks if the session is a meta session
361 (defun ediff-meta-session-p (session-info)
362 (and (stringp (ediff-get-session-objA-name session-info
))
363 (file-directory-p (ediff-get-session-objA-name session-info
))
364 (stringp (ediff-get-session-objB-name session-info
))
365 (file-directory-p (ediff-get-session-objB-name session-info
))
366 (if (stringp (ediff-get-session-objC-name session-info
))
367 (file-directory-p (ediff-get-session-objC-name session-info
)) t
)))
370 (ediff-defvar-local ediff-verbose-help-enabled nil
371 "If t, display redundant help in ediff-directories and other meta buffers.
372 Toggled by ediff-toggle-verbose-help-meta-buffer" )
374 ;; Toggle verbose help in meta-buffers
375 ;; TODO: Someone who understands all this can make it better.
376 (defun ediff-toggle-verbose-help-meta-buffer ()
377 "Toggle showing tediously verbose help in meta buffers."
379 (setq ediff-verbose-help-enabled
(not ediff-verbose-help-enabled
))
380 (ediff-update-meta-buffer (current-buffer) 'must-redraw
))
382 ;; set up the keymap in the meta buffer
383 (defun ediff-setup-meta-map ()
384 (setq ediff-meta-buffer-map
(make-sparse-keymap))
385 (suppress-keymap ediff-meta-buffer-map
)
386 (define-key ediff-meta-buffer-map
"?" 'ediff-toggle-verbose-help-meta-buffer
)
387 (define-key ediff-meta-buffer-map
"q" 'ediff-quit-meta-buffer
)
388 (define-key ediff-meta-buffer-map
"T" 'ediff-toggle-filename-truncation
)
389 (define-key ediff-meta-buffer-map
"R" 'ediff-show-registry
)
390 (define-key ediff-meta-buffer-map
"E" 'ediff-documentation
)
391 (define-key ediff-meta-buffer-map
"v" ediff-meta-action-function
)
392 (define-key ediff-meta-buffer-map
"\C-m" ediff-meta-action-function
)
393 (define-key ediff-meta-buffer-map
" " 'ediff-next-meta-item
)
394 (define-key ediff-meta-buffer-map
"n" 'ediff-next-meta-item
)
395 (define-key ediff-meta-buffer-map
"\C-?" 'ediff-previous-meta-item
)
396 (define-key ediff-meta-buffer-map
"p" 'ediff-previous-meta-item
)
397 (define-key ediff-meta-buffer-map
[delete] 'ediff-previous-meta-item)
398 (define-key ediff-meta-buffer-map [backspace] 'ediff-previous-meta-item)
399 (or (ediff-one-filegroup-metajob)
401 (define-key ediff-meta-buffer-map "=" nil)
402 (define-key ediff-meta-buffer-map "==" 'ediff-meta-mark-equal-files)
403 (define-key ediff-meta-buffer-map "=m" 'ediff-meta-mark-equal-files)
404 (define-key ediff-meta-buffer-map "=h" 'ediff-meta-mark-equal-files)))
405 (if ediff-no-emacs-help-in-control-buffer
406 (define-key ediff-meta-buffer-map "\C-h" 'ediff-previous-meta-item))
407 (if (featurep 'emacs)
408 (define-key ediff-meta-buffer-map [mouse-2] ediff-meta-action-function)
409 (define-key ediff-meta-buffer-map [button2] ediff-meta-action-function))
411 (use-local-map ediff-meta-buffer-map)
412 ;; modify ediff-meta-buffer-map here
413 (run-hooks 'ediff-meta-buffer-keymap-setup-hook))
416 (defun ediff-meta-mode ()
417 "This mode controls all operations on Ediff session groups.
418 It is entered through one of the following commands:
423 `ediff-merge-directories'
425 `ediff-merge-directories-with-ancestor'
426 `edirs-merge-with-ancestor'
427 `ediff-directory-revisions'
429 `ediff-merge-directory-revisions'
430 `edir-merge-revisions'
431 `ediff-merge-directory-revisions-with-ancestor'
432 `edir-merge-revisions-with-ancestor'
435 \\{ediff-meta-buffer-map}"
436 (kill-all-local-variables)
437 (setq major-mode 'ediff-meta-mode)
438 (setq mode-name "MetaEdiff")
439 ;; don't use run-mode-hooks here!
440 (run-hooks 'ediff-meta-mode-hook))
443 ;; the keymap for the buffer showing directory differences
444 (suppress-keymap ediff-dir-diffs-buffer-map)
445 (define-key ediff-dir-diffs-buffer-map "q" 'ediff-bury-dir-diffs-buffer)
446 (define-key ediff-dir-diffs-buffer-map " " 'next-line)
447 (define-key ediff-dir-diffs-buffer-map "n" 'next-line)
448 (define-key ediff-dir-diffs-buffer-map "\C-?" 'previous-line)
449 (define-key ediff-dir-diffs-buffer-map "p" 'previous-line)
450 (define-key ediff-dir-diffs-buffer-map "C" 'ediff-dir-diff-copy-file)
451 (if (featurep 'emacs)
452 (define-key ediff-dir-diffs-buffer-map [mouse-2] 'ediff-dir-diff-copy-file)
453 (define-key ediff-dir-diffs-buffer-map [button2] 'ediff-dir-diff-copy-file))
454 (define-key ediff-dir-diffs-buffer-map [delete] 'previous-line
)
455 (define-key ediff-dir-diffs-buffer-map
[backspace] 'previous-line)
457 (defun ediff-next-meta-item (count)
458 "Move to the next item in Ediff registry or session group buffer.
459 Moves in circular fashion. With numeric prefix arg, skip this many items."
461 (or count (setq count 1))
464 (setq count (1- count))
465 (ediff-next-meta-item1)
466 (setq overl (ediff-get-meta-overlay-at-pos (point)))
467 ;; skip invisible ones
468 (while (and overl (ediff-overlay-get overl 'invisible))
469 (ediff-next-meta-item1)
470 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
472 ;; Move to the next meta item
473 (defun ediff-next-meta-item1 ()
475 (setq pos (ediff-next-meta-overlay-start (point)))
476 (if pos (goto-char pos))
477 (if (eq ediff-metajob-name 'ediff-registry)
478 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
479 (search-forward "*Ediff" nil t))
480 (skip-chars-backward "a-zA-Z*"))
481 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
482 (backward-char 1)))))
485 (defun ediff-previous-meta-item (count)
486 "Move to the previous item in Ediff registry or session group buffer.
487 Moves in circular fashion. With numeric prefix arg, skip this many items."
489 (or count (setq count 1))
492 (setq count (1- count))
493 (ediff-previous-meta-item1)
494 (setq overl (ediff-get-meta-overlay-at-pos (point)))
495 ;; skip invisible ones
496 (while (and overl (ediff-overlay-get overl 'invisible))
497 (ediff-previous-meta-item1)
498 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
500 (defun ediff-previous-meta-item1 ()
502 (setq pos (ediff-previous-meta-overlay-start (point)))
504 ;;; (while (ediff-get-session-status
505 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
506 ;;; (setq pos (ediff-previous-meta-overlay-start pos)))
508 (if pos (goto-char pos))
509 (if (eq ediff-metajob-name 'ediff-registry)
510 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
511 (search-forward "*Ediff" nil t))
512 (skip-chars-backward "a-zA-Z*"))
513 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
517 (defsubst ediff-add-slash-if-directory (dir file)
518 (if (file-directory-p (concat dir file))
519 (file-name-as-directory file)
522 (defun ediff-toggle-filename-truncation ()
523 "Toggle truncation of long file names in session group buffers.
524 Set `ediff-meta-truncate-filenames' variable if you want to change the default
527 (setq ediff-meta-truncate-filenames (not ediff-meta-truncate-filenames))
528 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
531 ;; These are used to encode membership of files in directory1/2/3
532 ;; Membership code of a file is a product of codes for the directories where
534 (defvar ediff-membership-code1 2)
535 (defvar ediff-membership-code2 3)
536 (defvar ediff-membership-code3 5)
537 (defvar ediff-product-of-memcodes (* ediff-membership-code1
538 ediff-membership-code2
539 ediff-membership-code3))
541 ;; DIR1, DIR2, DIR3 are directories. DIR3 can be nil.
542 ;; OUTPUT-DIR is a directory for auto-storing the results of merge jobs.
544 ;; REGEXP is nil or a filter regexp; only file names that match the regexp
546 ;; If a file is a directory in dir1 but not dir2 (or vice versa), it is not
547 ;; included in the intersection. However, a regular file that is a dir in dir3
548 ;; is included, since dir3 files are supposed to be ancestors for merging.
549 ;; If COMPARISON-FUNC is given, use it. Otherwise, use string=
551 ;; Returns a list of the form:
552 ;; (COMMON-PART DIFF-LIST)
553 ;; COMMON-PART is car and DIFF-LIST is cdr.
555 ;; COMMON-PART is of the form:
556 ;; (META-HEADER (f1 f2 f3) (f1 f2 f3) ...)
557 ;; f3 can be nil if intersecting only 2 directories.
558 ;; Each triple (f1 f2 f3) represents the files to be compared in the
559 ;; corresponding ediff subsession.
561 ;; DIFF-LIST is of the form:
562 ;; (META-HEADER (file . num) (file . num)...)
563 ;; where num encodes the set of dirs where the file is found:
564 ;; 2 - only dir1; 3 - only dir2; 5 - only dir3; 6 - dir1&2; 10 - dir1&3; etc.
566 ;; Contains the meta info about this ediff operation
567 ;; (regexp dir1 dir2 dir3 merge-auto-store-dir comparison-func)
568 ;; Later the meta-buffer is prepended to this list.
570 ;; Some operations might use a different meta header. For instance,
571 ;; ediff-multifile-patch doesn't have dir2 and dir3, and regexp,
572 ;; comparison-func don't apply.
574 (defun ediff-intersect-directories (jobname
577 dir3 merge-autostore-dir comparison-func)
578 (setq comparison-func (or comparison-func 'string=))
579 (let (lis1 lis2 lis3 common auxdir1 auxdir2 auxdir3 common-part difflist)
581 (setq auxdir1 (file-name-as-directory dir1)
582 lis1 (directory-files auxdir1 nil regexp)
583 lis1 (delete "." lis1)
584 lis1 (delete ".." lis1)
587 (ediff-add-slash-if-directory auxdir1 elt))
589 auxdir2 (file-name-as-directory dir2)
590 lis2 (directory-files auxdir2 nil regexp)
591 lis2 (delete "." lis2)
592 lis2 (delete ".." lis2)
595 (ediff-add-slash-if-directory auxdir2 elt))
599 (setq auxdir3 (file-name-as-directory dir3)
600 lis3 (directory-files auxdir3 nil regexp)
601 lis3 (delete "." lis3)
602 lis3 (delete ".." lis3)
605 (ediff-add-slash-if-directory auxdir3 elt))
608 (if (ediff-nonempty-string-p merge-autostore-dir)
609 (setq merge-autostore-dir
610 (file-name-as-directory merge-autostore-dir)))
611 (setq common (ediff-intersection lis1 lis2 comparison-func))
613 ;; In merge with ancestor jobs, we don't intersect with lis3.
614 ;; If there is no ancestor, we'll offer to merge without the ancestor.
615 ;; So, we intersect with lis3 only when we are doing 3-way file comparison
616 (if (and lis3 (ediff-comparison-metajob3 jobname))
617 (setq common (ediff-intersection common lis3 comparison-func)))
619 ;; copying is needed because sort sorts via side effects
620 (setq common (sort (ediff-copy-list common) 'string-lessp))
622 ;; compute difference list
623 (setq difflist (ediff-set-difference
624 (ediff-union (ediff-union lis1 lis2 comparison-func)
629 difflist (delete "." difflist)
630 ;; copying is needed because sort sorts via side effects
631 difflist (sort (ediff-copy-list (delete ".." difflist))
634 (setq difflist (mapcar (lambda (elt) (cons elt 1)) difflist))
636 ;; check for files belonging to lis1/2/3
637 ;; Each elt is of the norm (file . number)
638 ;; Number encodes the directories to which file belongs.
639 ;; It is a product of a subset of ediff-membership-code1=2,
640 ;; ediff-membership-code2=3, and ediff-membership-code3=5.
641 ;; If file belongs to dir 1 only, the membership code is 2.
642 ;; If it is in dir1 and dir3, then the membership code is 2*5=10;
643 ;; if it is in dir1 and dir2, then the membership code is 2*3=6, etc.
645 (if (member (car elt) lis1)
646 (setcdr elt (* (cdr elt) ediff-membership-code1)))
647 (if (member (car elt) lis2)
648 (setcdr elt (* (cdr elt) ediff-membership-code2)))
649 (if (member (car elt) lis3)
650 (setcdr elt (* (cdr elt) ediff-membership-code3)))
654 ;; diff metalist header
655 (ediff-make-new-meta-list-header regexp
656 auxdir1 auxdir2 auxdir3
664 (ediff-make-new-meta-list-header regexp
665 auxdir1 auxdir2 auxdir3
670 (ediff-make-new-meta-list-element
671 (expand-file-name (concat auxdir1 elt))
672 (expand-file-name (concat auxdir2 elt))
675 ;; The following is done because: In merging with
676 ;; ancestor, we don't intersect with lis3. So, it is
677 ;; possible that elt is a file in auxdir1/2 but a
678 ;; directory in auxdir3 Or elt may not exist in auxdir3 at
679 ;; all. In the first case, we add a slash at the end. In
680 ;; the second case, we insert nil.
681 (setq elt (ediff-add-slash-if-directory auxdir3 elt))
682 (if (file-exists-p (concat auxdir3 elt))
683 (expand-file-name (concat auxdir3 elt)))))))
686 (cons common-part difflist)
689 ;; find directory files that are under revision. Include subdirectories, since
690 ;; we may visit them recursively. DIR1 is the directory to inspect.
691 ;; MERGE-AUTOSTORE-DIR is the directory where to auto-store the results of
692 ;; merges. Can be nil.
693 (defun ediff-get-directory-files-under-revision (jobname
695 &optional merge-autostore-dir)
696 (let (lis1 elt common auxdir1)
697 (setq auxdir1 (file-name-as-directory dir1)
698 lis1 (directory-files auxdir1 nil regexp))
700 (if (ediff-nonempty-string-p merge-autostore-dir)
701 (setq merge-autostore-dir
702 (file-name-as-directory merge-autostore-dir)))
707 ;; take files under revision control
708 (cond ((file-directory-p (concat auxdir1 elt))
710 (cons (ediff-add-slash-if-directory auxdir1 elt) common)))
711 ((and (featurep 'vc-hooks) (vc-backend (concat auxdir1 elt)))
712 (setq common (cons elt common)))
713 ;; The following two are needed only if vc-hooks isn't loaded.
714 ;; They won't recognize CVS files.
715 ((file-exists-p (concat auxdir1 elt ",v"))
716 (setq common (cons elt common)))
717 ((file-exists-p (concat auxdir1 "RCS/" elt ",v"))
718 (setq common (cons elt common)))
722 (setq common (delete "./" common)
723 common (delete "../" common)
724 common (delete "RCS" common)
725 common (delete "CVS" common)
728 ;; copying is needed because sort sorts via side effects
729 (setq common (sort (ediff-copy-list common) 'string-lessp))
733 ;; header -- has 6 elements. Meta buffer is prepended later by
734 ;; ediff-prepare-meta-buffer
735 (ediff-make-new-meta-list-header regexp
737 merge-autostore-dir nil)
738 (mapcar (lambda (elt) (ediff-make-new-meta-list-element
739 (expand-file-name (concat auxdir1 elt)) nil nil))
744 ;; If file groups selected by patterns will ever be implemented, this
745 ;; comparison function might become useful.
746 ;;;; uses external variables PAT1 PAT2 to compare str1/2
747 ;;;; patterns must be of the form ???*???? where ??? are strings of chars
748 ;;;; containing no *.
749 ;;(defun ediff-pattern= (str1 str2)
750 ;; (let (pos11 pos12 pos21 pos22 len1 len2)
752 ;; len (length epat1)
754 ;; (while (and (< pos11 len) (not (= (aref epat1 pos11) ?*)))
755 ;; (setq pos11 (1+ pos11)))
756 ;; (while (and (> pos12 0) (not (= (aref epat1 (1- pos12)) ?*)))
757 ;; (setq pos12 (1- pos12)))
760 ;; len (length epat2)
762 ;; (while (and (< pos21 len) (not (= (aref epat2 pos21) ?*)))
763 ;; (setq pos21 (1+ pos21)))
764 ;; (while (and (> pos22 0) (not (= (aref epat2 (1- pos22)) ?*)))
765 ;; (setq pos22 (1- pos22)))
767 ;; (if (and (> (length str1) pos12) (>= pos12 pos11) (> pos11 -1)
768 ;; (> (length str2) pos22) (>= pos22 pos21) (> pos21 -1))
769 ;; (string= (substring str1 pos11 pos12)
770 ;; (substring str2 pos21 pos22)))
774 ;; Prepare meta-buffer in accordance with the argument-function and
775 ;; redraw-function. Must return the created meta-buffer.
776 (defun ediff-prepare-meta-buffer (action-func meta-list
777 meta-buffer-name redraw-function
778 jobname &optional startup-hooks)
779 (let* ((meta-buffer-name
780 (ediff-unique-buffer-name meta-buffer-name "*"))
781 (meta-buffer (get-buffer-create meta-buffer-name)))
782 (ediff-with-current-buffer meta-buffer
787 (setq ediff-meta-action-function action-func
788 ediff-meta-redraw-function redraw-function
789 ediff-metajob-name jobname
790 ediff-meta-buffer meta-buffer)
792 ;; comes after ediff-meta-action-function is set
793 (ediff-setup-meta-map)
795 (if (eq ediff-metajob-name 'ediff-registry)
797 (setq ediff-registry-buffer meta-buffer
798 ediff-meta-list meta-list)
799 ;; this func is used only from registry buffer, not from other
802 ediff-meta-buffer-map "M" 'ediff-show-meta-buff-from-registry))
803 ;; Initialize the meta list -- we don't do this for registry.
804 (setq ediff-meta-list
805 ;; add meta-buffer to the list header
806 (cons (cons meta-buffer (car meta-list))
809 (or (eq meta-buffer ediff-registry-buffer)
810 (setq ediff-session-registry
811 (cons meta-buffer ediff-session-registry)))
813 ;; redraw-function uses ediff-meta-list
814 (funcall redraw-function ediff-meta-list)
816 ;; set read-only/non-modified
817 (setq buffer-read-only t)
818 (set-buffer-modified-p nil)
820 (run-hooks 'startup-hooks)
822 ;; Arrange to show directory contents differences
823 ;; Must be after run startup-hooks, since ediff-dir-difference-list is
824 ;; set inside these hooks
825 (if (eq action-func 'ediff-filegroup-action)
827 ;; put meta buffer in (car ediff-dir-difference-list)
828 (setq ediff-dir-difference-list
829 (cons (cons meta-buffer (car ediff-dir-difference-list))
830 (cdr ediff-dir-difference-list)))
832 (or (ediff-one-filegroup-metajob jobname)
833 (ediff-draw-dir-diffs ediff-dir-difference-list))
835 ediff-meta-buffer-map "h" 'ediff-mark-for-hiding-at-pos)
836 (define-key ediff-meta-buffer-map "x" 'ediff-hide-marked-sessions)
838 ediff-meta-buffer-map "m" 'ediff-mark-for-operation-at-pos)
839 (define-key ediff-meta-buffer-map "u" nil)
841 ediff-meta-buffer-map "um" 'ediff-unmark-all-for-operation)
843 ediff-meta-buffer-map "uh" 'ediff-unmark-all-for-hiding)
844 (cond ((ediff-collect-diffs-metajob jobname)
846 ediff-meta-buffer-map "P" 'ediff-collect-custom-diffs))
847 ((ediff-patch-metajob jobname)
849 ediff-meta-buffer-map "P" 'ediff-meta-show-patch)))
850 (define-key ediff-meta-buffer-map "^" 'ediff-up-meta-hierarchy)
851 (define-key ediff-meta-buffer-map "D" 'ediff-show-dir-diffs)))
853 (if (eq ediff-metajob-name 'ediff-registry)
854 (run-hooks 'ediff-registry-setup-hook)
855 (run-hooks 'ediff-after-session-group-setup-hook))
856 ) ; eval in meta-buffer
859 ;; Insert the activity marker for session SESSION in the meta buffer at point
860 ;; The activity marker is either SPC (untouched session), or + (active session,
861 ;; i.e., ediff is currently run in it), or - (finished session, i.e., we've ran
862 ;; ediff in it and then exited)
863 (defun ediff-insert-session-activity-marker-in-meta-buffer (session)
865 (cond ((ediff-get-session-activity-marker session))
869 ;; Insert session status at point. Status is either ?H (marked for hiding), or
870 ;; ?I (hidden or invalid), or ?* (meaning marked for an operation; currently,
871 ;; such op can only be checking for equality)), or SPC (meaning neither marked
873 (defun ediff-insert-session-status-in-meta-buffer (session)
875 (cond ((ediff-get-session-status session)) ; session has status: ?H, ?I, ?*
876 ;; normal session, no marks or hidings
879 ;; If NEW-MARKER is non-nil, use it to substitute the current activity marker
880 ;; in the meta buffer. If nil, use SPC
881 (defun ediff-replace-session-activity-marker-in-meta-buffer (point new-marker)
882 (let* ((overl (ediff-get-meta-overlay-at-pos point))
883 (session-info (ediff-overlay-get overl 'ediff-meta-info))
884 (activity-marker (ediff-get-session-activity-marker session-info))
886 (or new-marker activity-marker (setq new-marker ?\s))
887 (goto-char (ediff-overlay-start overl))
888 (if (eq (char-after (point)) new-marker)
889 () ; if marker shown in buffer is the same as new-marker, do nothing
892 (set-buffer-modified-p nil))))
894 ;; If NEW-STATUS is non-nil, use it to substitute the current status marker in
895 ;; the meta buffer. If nil, use SPC
896 (defun ediff-replace-session-status-in-meta-buffer (point new-status)
897 (let* ((overl (ediff-get-meta-overlay-at-pos point))
898 (session-info (ediff-overlay-get overl 'ediff-meta-info))
899 (status (ediff-get-session-status session-info))
901 (setq new-status (or new-status status ?\s))
902 (goto-char (ediff-overlay-start overl))
903 (forward-char 1) ; status is the second char in session record
904 (if (eq (char-after (point)) new-status)
905 () ; if marker shown in buffer is the same as new-marker, do nothing
908 (set-buffer-modified-p nil))))
910 ;; insert all file info in meta buffer for a given session
911 (defun ediff-insert-session-info-in-meta-buffer (session-info sessionNum)
912 (let ((f1 (ediff-get-session-objA session-info))
913 (f2 (ediff-get-session-objB session-info))
914 (f3 (ediff-get-session-objC session-info))
916 (hidden (eq (ediff-get-session-status session-info) ?I)))
917 ;; insert activity marker, i.e., SPC, - or +
918 (ediff-insert-session-activity-marker-in-meta-buffer session-info)
919 ;; insert session status, i.e., *, H
920 (ediff-insert-session-status-in-meta-buffer session-info)
921 (insert " Session " (int-to-string sessionNum) ":\n")
922 (ediff-meta-insert-file-info1 f1)
923 (ediff-meta-insert-file-info1 f2)
924 (ediff-meta-insert-file-info1 f3)
925 (ediff-set-meta-overlay pt (point) session-info sessionNum hidden)))
928 ;; this is a setup function for ediff-directories
929 ;; must return meta-buffer
930 (defun ediff-redraw-directory-group-buffer (meta-list)
931 ;; extract directories
932 (let ((meta-buf (ediff-get-group-buffer meta-list))
935 regexp elt merge-autostore-dir
936 point tmp-list buffer-read-only)
937 (ediff-with-current-buffer meta-buf
940 ;; delete phony overlays that used to represent sessions before the buff
942 (if (featurep 'xemacs)
943 (map-extents 'delete-extent)
944 (mapc 'delete-overlay (overlays-in 1 1)))
946 (setq regexp (ediff-get-group-regexp meta-list)
948 (ediff-get-group-merge-autostore-dir meta-list))
950 (if ediff-verbose-help-enabled
952 (insert (format ediff-meta-buffer-verbose-message
953 (ediff-abbrev-jobname ediff-metajob-name)))
955 (cond ((ediff-collect-diffs-metajob)
957 " P:\tcollect custom diffs of all marked sessions\n"))
958 ((ediff-patch-metajob)
960 " P:\tshow patch appropriately for the context (session or group)\n")))
962 " ^:\tshow parent session group\n")
963 (or (ediff-one-filegroup-metajob)
965 " D:\tshow differences among directories\n"
966 " ==:\tfor each session, show which files are identical\n"
967 " =h:\tlike ==, but also marks sessions for hiding\n"
968 " =m:\tlike ==, but also marks sessions for operation\n\n")))
969 (insert (format ediff-meta-buffer-brief-message
970 (ediff-abbrev-jobname ediff-metajob-name))))
973 (if (and (stringp regexp) (> (length regexp) 0))
975 (format "*** Filter-through regular expression: %s\n" regexp)))
976 (ediff-insert-dirs-in-meta-buffer meta-list)
977 (if (and ediff-autostore-merges (ediff-merge-metajob)
978 (ediff-nonempty-string-p merge-autostore-dir))
980 "\nMerge results are automatically stored in:\n\t%s\n"
981 merge-autostore-dir)))
983 Size Last modified Name
984 ----------------------------------------------
988 ;; discard info on directories and regexp
989 (setq meta-list (cdr meta-list)
991 (while (and tmp-list empty)
992 (if (and (car tmp-list)
993 (not (eq (ediff-get-session-status (car tmp-list)) ?I)))
995 (setq tmp-list (cdr tmp-list)))
999 " ****** ****** This session group has no members\n"))
1001 ;; now organize file names like this:
1002 ;; use-mark sizeA dateA sizeB dateB filename
1003 ;; make sure directories are displayed with a trailing slash.
1005 (setq elt (car meta-list)
1006 meta-list (cdr meta-list)
1007 sessionNum (1+ sessionNum))
1008 (if (eq (ediff-get-session-status elt) ?I)
1010 (ediff-insert-session-info-in-meta-buffer elt sessionNum)))
1011 (set-buffer-modified-p nil)
1015 (defun ediff-update-markers-in-dir-meta-buffer (meta-list)
1016 (let ((meta-buf (ediff-get-group-buffer meta-list))
1017 session-info point overl buffer-read-only)
1018 (ediff-with-current-buffer meta-buf
1019 (setq point (point))
1020 (goto-char (point-min))
1021 (ediff-next-meta-item1)
1023 (setq session-info (ediff-get-meta-info meta-buf (point) 'no-error)
1024 overl (ediff-get-meta-overlay-at-pos (point)))
1027 (cond ((eq (ediff-get-session-status session-info) ?I)
1029 (if overl (ediff-overlay-put overl 'invisible t)))
1030 ((and (eq (ediff-get-session-status session-info) ?H)
1031 overl (ediff-overlay-get overl 'invisible))
1033 (ediff-overlay-put overl 'invisible nil))
1034 (t (ediff-replace-session-activity-marker-in-meta-buffer
1036 (ediff-get-session-activity-marker session-info))
1037 (ediff-replace-session-status-in-meta-buffer
1039 (ediff-get-session-status session-info))))))
1040 (ediff-next-meta-item1) ; advance to the next item
1042 (set-buffer-modified-p nil)
1046 (defun ediff-update-session-marker-in-dir-meta-buffer (session-num)
1047 (let (buffer-meta-overlays session-info overl buffer-read-only)
1049 (if (featurep 'xemacs)
1051 (lambda (ext maparg)
1053 (ediff-overlay-get ext 'ediff-meta-info)
1054 (eq (ediff-overlay-get ext 'ediff-meta-session-number)
1057 ;; Emacs doesn't have map-extents, so try harder
1058 ;; Splice overlay lists to get all buffer overlays
1059 (setq buffer-meta-overlays (overlay-lists)
1060 buffer-meta-overlays (append (car buffer-meta-overlays)
1061 (cdr buffer-meta-overlays)))
1067 (ediff-overlay-get overl 'ediff-meta-info)
1068 (eq (ediff-overlay-get
1069 overl 'ediff-meta-session-number)
1072 buffer-meta-overlays)))))
1075 "Bug in ediff-update-session-marker-in-dir-meta-buffer: no overlay with given number %S"
1077 (setq session-info (ediff-overlay-get overl 'ediff-meta-info))
1078 (goto-char (ediff-overlay-start overl))
1079 (ediff-replace-session-activity-marker-in-meta-buffer
1081 (ediff-get-session-activity-marker session-info))
1082 (ediff-replace-session-status-in-meta-buffer
1084 (ediff-get-session-status session-info)))
1085 (ediff-next-meta-item1))
1089 ;; Check if this is a problematic session.
1090 ;; Return nil if not. Otherwise, return symbol representing the problem
1091 ;; At present, problematic sessions occur only in -with-ancestor comparisons
1092 ;; when the ancestor is a directory rather than a file, or when there is no
1093 ;; suitable ancestor file in the ancestor directory
1094 (defun ediff-problematic-session-p (session)
1095 (let ((f1 (ediff-get-session-objA-name session))
1096 (f2 (ediff-get-session-objB-name session))
1097 (f3 (ediff-get-session-objC-name session)))
1098 (cond ((and (stringp f1) (not (file-directory-p f1))
1099 (stringp f2) (not (file-directory-p f2))
1100 ;; either invalid file name or a directory
1101 (or (not (stringp f3)) (file-directory-p f3))
1102 (ediff-ancestor-metajob))
1103 ;; more may be added later
1107 (defun ediff-meta-insert-file-info1 (fileinfo)
1108 (let ((fname (car fileinfo))
1109 (feq (ediff-get-file-eqstatus fileinfo))
1110 (max-filename-width (if ediff-meta-truncate-filenames
1111 (- (window-width) 41)
1113 file-modtime file-size)
1114 (cond ((not (stringp fname)) (setq file-size -2)) ; file doesn't exits
1115 ((ediff-listable-file fname)
1116 (if (file-exists-p fname)
1117 ;; set real size and modtime
1118 (setq file-size (ediff-file-size fname)
1119 file-modtime (ediff-file-modtime fname))
1120 (setq file-size -2))) ; file doesn't exist
1121 ( t (setq file-size -1))) ; remote file
1126 (if feq "=" " ") ; equality indicator
1127 (format "%10s" (cond ((= file-size -1) "--")
1128 ((< file-size -1) "--")
1130 (cond ((= file-size -1) "*remote file*")
1131 ((< file-size -1) "*file doesn't exist*")
1132 (t (ediff-format-date (decode-time file-modtime))))
1134 ;; dir names in meta lists have training slashes, so we just
1135 ;; abbreviate the file name, if file exists
1136 (if (and (not (stringp fname)) (< file-size -1))
1137 "-------" ; file doesn't exist
1138 (ediff-truncate-string-left
1139 (ediff-abbreviate-file-name fname)
1140 max-filename-width)))))))
1142 (defconst ediff-months '((1 . "Jan") (2 . "Feb") (3 . "Mar") (4 . "Apr")
1143 (5 . "May") (6 . "Jun") (7 . "Jul") (8 . "Aug")
1144 (9 . "Sep") (10 . "Oct") (11 . "Nov") (12 . "Dec"))
1145 "Months' associative array.")
1147 ;; returns 2char string
1148 (defsubst ediff-fill-leading-zero (num)
1151 (number-to-string num)))
1153 ;; TIME is like the output of decode-time
1154 (defun ediff-format-date (time)
1155 (format "%s %2d %4d %s:%s:%s"
1156 (cdr (assoc (nth 4 time) ediff-months)) ; month
1159 (ediff-fill-leading-zero (nth 2 time)) ; hour
1160 (ediff-fill-leading-zero (nth 1 time)) ; min
1161 (ediff-fill-leading-zero (nth 0 time)) ; sec
1164 ;; Draw the directories
1165 (defun ediff-insert-dirs-in-meta-buffer (meta-list)
1166 (let* ((dir1 (ediff-abbreviate-file-name (ediff-get-group-objA meta-list)))
1167 (dir2 (ediff-get-group-objB meta-list))
1168 (dir2 (if (stringp dir2) (ediff-abbreviate-file-name dir2)))
1169 (dir3 (ediff-get-group-objC meta-list))
1170 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3))))
1171 (insert "*** Directory A: " dir1 "\n")
1172 (if dir2 (insert "*** Directory B: " dir2 "\n"))
1173 (if dir3 (insert "*** Directory C: " dir3 "\n"))
1176 (defun ediff-draw-dir-diffs (diff-list &optional buf-name)
1177 (if (null diff-list) (error "Lost difference info on these directories"))
1180 (ediff-unique-buffer-name "*Ediff File Group Differences" "*")))
1181 (let* ((regexp (ediff-get-group-regexp diff-list))
1182 (dir1 (ediff-abbreviate-file-name (ediff-get-group-objA diff-list)))
1183 (dir2 (ediff-abbreviate-file-name (ediff-get-group-objB diff-list)))
1184 (dir3 (ediff-get-group-objC diff-list))
1185 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3)))
1186 (meta-buf (ediff-get-group-buffer diff-list))
1187 (underline (make-string 26 ?-))
1188 file membership-code saved-point
1190 ;; skip the directory part
1191 (setq diff-list (cdr diff-list))
1192 (setq ediff-dir-diffs-buffer (get-buffer-create buf-name))
1193 (ediff-with-current-buffer ediff-dir-diffs-buffer
1194 (setq saved-point (point))
1195 (use-local-map ediff-dir-diffs-buffer-map)
1197 (setq ediff-meta-buffer meta-buf)
1198 (insert "\t\t*** Directory Differences ***\n")
1201 C,button2: over file name -- copy this file to directory that doesn't have it
1204 p,DEL: previous line\n\n")
1206 (insert (format "\n*** Directory A: %s\n" dir1))
1207 (if dir2 (insert (format "*** Directory B: %s\n" dir2)))
1208 (if dir3 (insert (format "*** Directory C: %s\n" dir3)))
1209 (if (and (stringp regexp) (> (length regexp) 0))
1211 (format "*** Filter-through regular expression: %s\n" regexp)))
1213 (insert (format "\n%-27s%-26s" "Directory A" "Directory B"))
1215 (insert (format " %-25s\n" "Directory C"))
1217 (insert (format "%s%s" underline underline))
1219 (insert (format "%s\n\n" underline))
1222 (if (null diff-list)
1223 (insert "\n\t*** No differences ***\n"))
1226 (setq file (car (car diff-list))
1227 membership-code (cdr (car diff-list))
1228 diff-list (cdr diff-list))
1229 (if (= (mod membership-code ediff-membership-code1) 0) ; dir1
1230 (let ((beg (point)))
1231 (insert (format "%-27s"
1232 (ediff-truncate-string-left
1233 (ediff-abbreviate-file-name
1234 (if (file-directory-p (concat dir1 file))
1235 (file-name-as-directory file)
1238 ;; format of meta info in the dir-diff-buffer:
1239 ;; (filename-tail filename-full otherdir1 otherdir2 otherdir3)
1240 (ediff-set-meta-overlay
1242 (list meta-buf file (concat dir1 file) dir1 dir2 dir3)))
1243 (insert (format "%-27s" "---")))
1244 (if (= (mod membership-code ediff-membership-code2) 0) ; dir2
1245 (let ((beg (point)))
1246 (insert (format "%-26s"
1247 (ediff-truncate-string-left
1248 (ediff-abbreviate-file-name
1249 (if (file-directory-p (concat dir2 file))
1250 (file-name-as-directory file)
1253 (ediff-set-meta-overlay
1255 (list meta-buf file (concat dir2 file) dir1 dir2 dir3)))
1256 (insert (format "%-26s" "---")))
1258 (if (= (mod membership-code ediff-membership-code3) 0) ; dir3
1259 (let ((beg (point)))
1260 (insert (format " %-25s"
1261 (ediff-truncate-string-left
1262 (ediff-abbreviate-file-name
1263 (if (file-directory-p (concat dir3 file))
1264 (file-name-as-directory file)
1267 (ediff-set-meta-overlay
1269 (list meta-buf file (concat dir3 file) dir1 dir2 dir3)))
1270 (insert (format " %-25s" "---"))))
1272 (setq buffer-read-only t)
1273 (set-buffer-modified-p nil)
1274 (goto-char saved-point)) ; end eval in diff buffer
1277 (defun ediff-bury-dir-diffs-buffer ()
1278 "Bury the directory difference buffer. Display the meta buffer instead."
1280 ;; ediff-meta-buffer is set in ediff-draw-dir-diffs so the directory
1281 ;; difference buffer remembers the meta buffer
1282 (let ((buf ediff-meta-buffer)
1284 (ediff-kill-buffer-carefully ediff-dir-diffs-buffer)
1285 (if (setq wind (ediff-get-visible-buffer-window buf))
1286 (select-window wind)
1287 (set-window-buffer (selected-window) buf))))
1289 ;; executes in dir session group buffer
1290 ;; show buffer differences
1291 (defun ediff-show-dir-diffs ()
1292 "Display differences among the directories involved in session group."
1294 (if (ediff-one-filegroup-metajob)
1295 (error "This command is inapplicable in the present context"))
1296 (or (ediff-buffer-live-p ediff-dir-diffs-buffer)
1297 (ediff-draw-dir-diffs ediff-dir-difference-list))
1298 (let ((buf ediff-dir-diffs-buffer))
1300 (set-window-buffer (selected-window) buf)
1301 (goto-char (point-min))))
1303 ;; Format of meta info in dir-diff-buffer:
1304 ;; (filename-tail filename-full otherdir1 otherdir2)
1305 (defun ediff-dir-diff-copy-file ()
1306 "Copy file described at point to directories where this file is missing."
1308 (let* ((pos (ediff-event-point last-command-event))
1309 (info (ediff-get-meta-info (current-buffer) pos 'noerror))
1310 (meta-buf (car info))
1311 (file-tail (nth 1 info))
1312 (file-abs (nth 2 info))
1313 (otherdir1 (nth 3 info))
1314 (otherfile1 (if otherdir1 (concat otherdir1 file-tail)))
1315 (otherdir2 (nth 4 info))
1316 (otherfile2 (if otherdir2 (concat otherdir2 file-tail)))
1317 (otherdir3 (nth 5 info))
1318 (otherfile3 (if otherdir3 (concat otherdir3 file-tail)))
1319 meta-list dir-diff-list
1322 (error "No file suitable for copying described at this location"))
1323 (ediff-with-current-buffer meta-buf
1324 (setq meta-list ediff-meta-list
1325 dir-diff-list ediff-dir-difference-list))
1327 ;; copy file to directories where it doesn't exist, update
1328 ;; ediff-dir-difference-list and redisplay
1330 (lambda (otherfile-struct)
1331 (let ((otherfile (car otherfile-struct))
1332 (file-mem-code (cdr otherfile-struct)))
1334 (or (file-exists-p otherfile)
1336 (format "Copy %s to %s? " file-abs otherfile))
1337 (let* ((file-diff-record (assoc file-tail dir-diff-list))
1339 (* (cdr file-diff-record) file-mem-code)))
1340 (copy-file file-abs otherfile)
1341 (setcdr file-diff-record new-mem-code)
1342 (ediff-draw-dir-diffs dir-diff-list (buffer-name))
1344 ;; if file is in all three dirs or in two dirs and only
1345 ;; two dirs are involved, delete this file's record
1346 (if (or (= new-mem-code ediff-product-of-memcodes)
1347 (and (> new-mem-code ediff-membership-code3)
1349 (delq file-diff-record dir-diff-list))
1352 ;; 2,3,5 are numbers used to encode membership of a file in
1353 ;; dir1/2/3. See ediff-intersect-directories.
1354 (list (cons otherfile1 2) (cons otherfile2 3) (cons otherfile3 5)))
1356 (if (and (file-exists-p otherfile1)
1357 (file-exists-p otherfile2)
1358 (or (not otherfile3) (file-exists-p otherfile3)))
1359 ;; update ediff-meta-list by direct modification
1361 (list (ediff-make-new-meta-list-element
1362 (expand-file-name otherfile1)
1363 (expand-file-name otherfile2)
1365 (expand-file-name otherfile3)))))
1367 (ediff-update-meta-buffer meta-buf 'must-redraw)
1370 (defun ediff-up-meta-hierarchy ()
1371 "Go to the parent session group buffer."
1373 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1374 (ediff-show-meta-buffer
1375 ediff-parent-meta-buffer ediff-meta-session-number)
1376 (error "This session group has no parent")))
1379 ;; argument is ignored
1380 (defun ediff-redraw-registry-buffer (&optional ignore)
1381 (ediff-with-current-buffer ediff-registry-buffer
1382 (let ((point (point))
1383 elt bufAname bufBname bufCname cur-diff total-diffs pt
1384 job-name meta-list registry-list buffer-read-only)
1386 ;; delete phony overlays that used to represent sessions before the buff
1388 (if (featurep 'xemacs)
1389 (map-extents 'delete-extent)
1390 (mapc 'delete-overlay (overlays-in 1 1)))
1392 (insert "This is a registry of all active Ediff sessions.
1395 button2, `v', RET over a session record: switch to that session
1396 M over a session record: display the associated session group
1397 R in any Ediff session: display session registry
1399 p,DEL: previous session
1400 E: browse Ediff on-line manual
1404 \t\tActive Ediff Sessions:
1405 \t\t----------------------
1408 ;; purge registry list from dead buffers
1410 (if (not (ediff-buffer-live-p elt))
1411 (setq ediff-session-registry
1412 (delq elt ediff-session-registry))))
1413 ediff-session-registry)
1415 (if (null ediff-session-registry)
1416 (insert " ******* No active Ediff sessions *******\n"))
1418 (setq registry-list ediff-session-registry)
1419 (while registry-list
1420 (setq elt (car registry-list)
1421 registry-list (cdr registry-list))
1423 (if (ediff-buffer-live-p elt)
1424 (if (ediff-with-current-buffer elt
1425 (setq job-name ediff-metajob-name
1426 meta-list ediff-meta-list)
1427 (and ediff-metajob-name
1428 (not (eq ediff-metajob-name 'ediff-registry))))
1431 (insert (format " *group*\t%s: %s\n"
1433 (ediff-abbrev-jobname job-name)))
1434 (insert (format "\t\t %s %s %s\n"
1435 (ediff-abbreviate-file-name
1436 (ediff-get-group-objA meta-list))
1437 (ediff-abbreviate-file-name
1439 (ediff-get-group-objB meta-list))
1440 (ediff-get-group-objB meta-list)
1442 (ediff-abbreviate-file-name
1444 (ediff-get-group-objC meta-list))
1445 (ediff-get-group-objC meta-list)
1447 (ediff-set-meta-overlay pt (point) elt))
1449 (ediff-with-current-buffer elt
1450 (setq bufAname (if (ediff-buffer-live-p ediff-buffer-A)
1451 (buffer-name ediff-buffer-A)
1452 "!!!killed buffer!!!")
1453 bufBname (if (ediff-buffer-live-p ediff-buffer-B)
1454 (buffer-name ediff-buffer-B)
1455 "!!!killed buffer!!!")
1456 bufCname (cond ((not (ediff-3way-job))
1458 ((ediff-buffer-live-p ediff-buffer-C)
1459 (buffer-name ediff-buffer-C))
1460 (t "!!!killed buffer!!!")))
1461 (setq total-diffs (format "%-4d" ediff-number-of-differences)
1463 (cond ((= ediff-current-difference -1) " _")
1464 ((= ediff-current-difference
1465 ediff-number-of-differences)
1468 "%4d" (1+ ediff-current-difference))))
1469 job-name ediff-job-name))
1470 ;; back in the meta buf
1472 (insert cur-diff "/" total-diffs "\t"
1474 (format ": %s" (ediff-abbrev-jobname job-name)))
1476 "\n\t\t " bufAname " " bufBname " " bufCname "\n")
1477 (ediff-set-meta-overlay pt (point) elt))))
1479 (set-buffer-modified-p nil)
1483 ;; Sets overlay around a meta record with 'ediff-meta-info property PROP
1484 ;; If optional SESSION-NUMBER, make it a property of the overlay,
1485 ;; ediff-meta-session-number
1486 ;; PROP is either the ctl or meta buffer (used when we work with the registry)
1487 ;; or a session meta descriptor of the form
1488 ;; (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
1489 (defun ediff-set-meta-overlay (b e prop &optional session-number hidden)
1491 (setq overl (ediff-make-overlay b e))
1492 (if (featurep 'emacs)
1493 (ediff-overlay-put overl 'mouse-face 'highlight)
1494 (ediff-overlay-put overl 'highlight t))
1495 (ediff-overlay-put overl 'ediff-meta-info prop)
1496 (ediff-overlay-put overl 'invisible hidden)
1497 (ediff-overlay-put overl 'follow-link t)
1498 (if (numberp session-number)
1499 (ediff-overlay-put overl 'ediff-meta-session-number session-number))))
1501 (defun ediff-mark-for-hiding-at-pos (unmark)
1502 "Mark session for hiding. With prefix arg, unmark."
1504 (let* ((pos (ediff-event-point last-command-event))
1505 (meta-buf (ediff-event-buffer last-command-event))
1506 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1507 (info (ediff-get-meta-info meta-buf pos))
1508 (session-number (ediff-get-session-number-at-pos pos)))
1509 (ediff-mark-session-for-hiding info unmark)
1510 (ediff-next-meta-item 1)
1512 (ediff-update-meta-buffer meta-buf nil session-number))
1515 ;; Returns whether session was marked or unmarked
1516 (defun ediff-mark-session-for-hiding (info unmark)
1517 (let ((session-buf (ediff-get-session-buffer info))
1519 (cond ((eq unmark 'mark) (setq unmark nil))
1520 ((eq (ediff-get-session-status info) ?H) (setq unmark t))
1521 (unmark ; says unmark, but the marker is different from H
1524 (unmark (ediff-set-session-status info nil))
1525 ;;; (if (ediff-buffer-live-p session-buf)
1526 ;;; (error "Can't hide active session, %s" (buffer-name session-buf)))
1527 (t (ediff-set-session-status info ?H))))
1531 (defun ediff-mark-for-operation-at-pos (unmark)
1532 "Mark session for a group operation. With prefix arg, unmark."
1534 (let* ((pos (ediff-event-point last-command-event))
1535 (meta-buf (ediff-event-buffer last-command-event))
1536 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1537 (info (ediff-get-meta-info meta-buf pos))
1538 (session-number (ediff-get-session-number-at-pos pos)))
1539 (ediff-mark-session-for-operation info unmark)
1540 (ediff-next-meta-item 1)
1542 (ediff-update-meta-buffer meta-buf nil session-number))
1546 ;; returns whether session was unmarked.
1547 ;; remember: this is a toggle op
1548 (defun ediff-mark-session-for-operation (info unmark)
1550 (cond ((eq unmark 'mark) (setq unmark nil))
1551 ((eq (ediff-get-session-status info) ?*) (setq unmark t))
1552 (unmark ; says unmark, but the marker is different from *
1555 (unmark (ediff-set-session-status info nil))
1556 (t (ediff-set-session-status info ?*))))
1560 (defun ediff-hide-marked-sessions (unhide)
1561 "Hide marked sessions. With prefix arg, unhide."
1563 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1564 (meta-list (cdr ediff-meta-list))
1565 (from (if unhide ?I ?H))
1566 (to (if unhide ?H ?I))
1568 active-sessions-exist session-buf elt)
1570 (setq elt (car meta-list)
1571 meta-list (cdr meta-list)
1572 session-buf (ediff-get-session-buffer elt))
1574 (if (eq (ediff-get-session-status elt) from)
1576 (setq numMarked (1+ numMarked))
1577 (if (and (eq to ?I) (buffer-live-p session-buf))
1578 ;; shouldn't hide active sessions
1579 (setq active-sessions-exist t)
1580 (ediff-set-session-status elt to)))))
1582 (ediff-update-meta-buffer grp-buf 'must-redraw)
1585 (message "Nothing to reveal...")
1586 (message "Nothing to hide...")))
1587 (if active-sessions-exist
1588 (message "Note: Ediff didn't hide active sessions!"))
1591 ;; Apply OPERATION to marked sessions. Operation expects one argument of type
1592 ;; meta-list member (not the first one), i.e., a regular session description.
1593 ;; Returns number of marked sessions on which operation was performed
1594 (defun ediff-operate-on-marked-sessions (operation)
1595 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1596 (meta-list (cdr ediff-meta-list))
1600 (diff-buffer ediff-meta-diff-buffer)
1603 (setq elt (car meta-list)
1604 meta-list (cdr meta-list)
1605 sessionNum (1+ sessionNum))
1606 (cond ((eq (ediff-get-session-status elt) marksym)
1608 (setq numMarked (1+ numMarked))
1609 (funcall operation elt sessionNum)))
1610 ;; The following goes into a session represented by a subdirectory
1611 ;; and applies operation to marked sessions there
1612 ((and (ediff-meta-session-p elt)
1613 (ediff-buffer-live-p
1614 (setq session-buf (ediff-get-session-buffer elt))))
1617 (ediff-with-current-buffer session-buf
1618 ;; pass meta-diff along
1619 (setq ediff-meta-diff-buffer diff-buffer)
1620 ;; collect diffs in child group
1621 (ediff-operate-on-marked-sessions operation)))))))
1622 (ediff-update-meta-buffer grp-buf 'must-redraw) ; just in case
1626 (defun ediff-append-custom-diff (session sessionNum)
1627 (or (ediff-collect-diffs-metajob)
1628 (error "Can't compute multifile patch in this context"))
1629 (let ((session-buf (ediff-get-session-buffer session))
1630 (meta-diff-buff ediff-meta-diff-buffer)
1631 (metajob ediff-metajob-name)
1632 tmp-buf custom-diff-buf)
1633 (if (ediff-buffer-live-p session-buf)
1634 (ediff-with-current-buffer session-buf
1635 (if (eq ediff-control-buffer session-buf) ; individual session
1637 (ediff-compute-custom-diffs-maybe)
1638 (setq custom-diff-buf ediff-custom-diff-buffer)))))
1640 (or (ediff-buffer-live-p meta-diff-buff)
1641 (error "Ediff: something wrong--killed multiple diff's buffer"))
1643 (cond ((ediff-buffer-live-p custom-diff-buf)
1644 ;; for live session buffers we do them first because the user may
1645 ;; have changed them with respect to the underlying files
1647 (set-buffer meta-diff-buff)
1648 (goto-char (point-max))
1649 (insert-buffer-substring custom-diff-buf)
1651 ;; if ediff session is not live, run diff directly on the files
1652 ((memq metajob '(ediff-directories
1653 ediff-merge-directories
1654 ediff-merge-directories-with-ancestor))
1655 ;; get diffs by calling shell command on ediff-custom-diff-program
1657 (set-buffer (setq tmp-buf (get-buffer-create ediff-tmp-buffer)))
1662 (shell-quote-argument ediff-custom-diff-program)
1663 ediff-custom-diff-options
1664 (shell-quote-argument (ediff-get-session-objA-name session))
1665 (shell-quote-argument (ediff-get-session-objB-name session))
1670 (set-buffer meta-diff-buff)
1671 (goto-char (point-max))
1672 (insert-buffer-substring tmp-buf)
1675 (ediff-kill-buffer-carefully meta-diff-buff)
1676 (error "Session %d compares versions of file. Such session must be active to enable multifile patch collection" sessionNum )))
1679 (defun ediff-collect-custom-diffs ()
1680 "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'.
1681 This operation is defined only for `ediff-directories' and
1682 `ediff-directory-revisions', since its intent is to produce
1683 multifile patches. For `ediff-directory-revisions', we insist that
1684 all marked sessions must be active."
1686 (let ((coding-system-for-read ediff-coding-system-for-read))
1687 (or (ediff-buffer-live-p ediff-meta-diff-buffer)
1688 (setq ediff-meta-diff-buffer
1690 (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
1691 (ediff-with-current-buffer ediff-meta-diff-buffer
1692 (setq buffer-read-only nil)
1694 (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
1697 (display-buffer ediff-meta-diff-buffer 'not-this-window)
1698 (ediff-with-current-buffer ediff-meta-diff-buffer
1699 (set-buffer-modified-p nil)
1700 (setq buffer-read-only t))
1701 (if (fboundp 'diff-mode)
1702 (with-current-buffer ediff-meta-diff-buffer
1705 (message "No marked sessions found"))))
1707 (defun ediff-meta-show-patch ()
1708 "Show the multi-file patch associated with this group session."
1710 (let* ((pos (ediff-event-point last-command-event))
1711 (meta-buf (ediff-event-buffer last-command-event))
1712 (info (ediff-get-meta-info meta-buf pos 'noerror))
1713 (patchbuffer ediff-meta-patchbufer))
1714 (if (ediff-buffer-live-p patchbuffer)
1715 (ediff-with-current-buffer patchbuffer
1720 (ediff-get-session-objB-name info)
1721 (ediff-get-session-objC-name info)))
1722 (set-buffer (get-buffer-create ediff-tmp-buffer))
1724 (insert-buffer-substring patchbuffer)
1725 (goto-char (point-min))
1726 (display-buffer ediff-tmp-buffer 'not-this-window)
1728 (error "The patch buffer wasn't found"))))
1731 ;; This function executes in meta buffer. It knows where event happened.
1732 (defun ediff-filegroup-action ()
1733 "Execute appropriate action for a selected session."
1735 (let* ((pos (ediff-event-point last-command-event))
1736 (meta-buf (ediff-event-buffer last-command-event))
1737 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1738 (info (ediff-get-meta-info meta-buf pos))
1739 (session-buf (ediff-get-session-buffer info))
1740 (session-number (ediff-get-session-number-at-pos pos meta-buf))
1741 (default-regexp (eval ediff-default-filtering-regexp))
1742 merge-autostore-dir file1 file2 file3 regexp)
1744 (setq file1 (ediff-get-session-objA-name info)
1745 file2 (ediff-get-session-objB-name info)
1746 file3 (ediff-get-session-objC-name info))
1748 ;; make sure we don't start on hidden sessions
1749 ;; ?H means marked for hiding. ?I means invalid (hidden).
1750 (if (memq (ediff-get-session-status info) '(?I))
1753 (if (y-or-n-p "This session is marked as hidden, unmark? ")
1755 (ediff-set-session-status info nil)
1756 (ediff-update-meta-buffer meta-buf nil session-number))
1757 (error "Aborted"))))
1759 (ediff-with-current-buffer meta-buf
1760 (setq merge-autostore-dir
1761 (ediff-get-group-merge-autostore-dir ediff-meta-list))
1762 (goto-char pos) ; if the user clicked on session--move point there
1763 ;; First handle sessions involving directories (which are themselves
1765 ;; After that handle individual sessions
1766 (cond ((ediff-meta-session-p info)
1767 ;; do ediff/ediff-merge on subdirectories
1768 (if (ediff-buffer-live-p session-buf)
1769 (ediff-show-meta-buffer session-buf)
1772 (if (stringp default-regexp)
1774 "Filter through regular expression (default %s): "
1776 "Filter through regular expression: ")
1778 'ediff-filtering-regexp-history
1779 (eval ediff-default-filtering-regexp)))
1780 (ediff-directories-internal
1781 file1 file2 file3 regexp
1782 ediff-session-action-function
1784 ;; make it update (car info) after startup
1786 ;; child session group should know its parent
1787 (setq ediff-parent-meta-buffer
1788 (quote ,ediff-meta-buffer)
1789 ediff-meta-session-number
1791 ;; and parent will know its child
1792 (setcar (quote ,info) ediff-meta-buffer))))))
1794 ;; Do ediff-revision on a subdirectory
1795 ((and (ediff-one-filegroup-metajob)
1796 (ediff-revision-metajob)
1797 (file-directory-p file1))
1798 (if (ediff-buffer-live-p session-buf)
1799 (ediff-show-meta-buffer session-buf)
1800 (setq regexp (read-string "Filter through regular expression: "
1801 nil 'ediff-filtering-regexp-history))
1802 (ediff-directory-revisions-internal
1804 ediff-session-action-function ediff-metajob-name
1805 ;; make it update (car info) after startup
1807 ;; child session group should know its parent and
1809 (setq ediff-parent-meta-buffer
1810 (quote ,ediff-meta-buffer)
1811 ediff-meta-session-number
1813 ;; and parent will know its child
1814 (setcar (quote ,info) ediff-meta-buffer))))))
1816 ;; From here on---only individual session handlers
1818 ;; handle an individual session with a live control buffer
1819 ((ediff-buffer-live-p session-buf)
1820 (ediff-with-current-buffer session-buf
1821 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1822 (ediff-recenter 'no-rehighlight)))
1824 ((ediff-problematic-session-p info)
1827 "This session has no ancestor. Merge without the ancestor? ")
1830 ;; provide startup hooks
1833 'ediff-after-quit-hook-internal
1835 (if (ediff-buffer-live-p ,(current-buffer))
1836 (ediff-show-meta-buffer
1837 ,(current-buffer) ,session-number)))
1839 (setq ediff-meta-buffer ,(current-buffer)
1840 ediff-meta-session-number
1842 (setq ediff-merge-store-file
1843 ,(if (ediff-nonempty-string-p
1844 merge-autostore-dir)
1847 ediff-merge-filename-prefix
1848 (file-name-nondirectory file1))
1850 ;; make ediff-startup pass
1851 ;; ediff-control-buffer back to the meta
1854 (quote ,info) ediff-control-buffer))))
1856 ((ediff-one-filegroup-metajob) ; needs 1 file arg
1857 (funcall ediff-session-action-function
1859 ;; provide startup hooks
1862 'ediff-after-quit-hook-internal
1864 (if (ediff-buffer-live-p
1866 (ediff-show-meta-buffer
1870 (setq ediff-meta-buffer ,(current-buffer)
1871 ediff-meta-session-number
1873 (setq ediff-merge-store-file
1874 ,(if (ediff-nonempty-string-p
1875 merge-autostore-dir)
1878 ediff-merge-filename-prefix
1879 (file-name-nondirectory file1))) )
1880 ;; make ediff-startup pass
1881 ;; ediff-control-buffer back to the meta
1884 (quote ,info) ediff-control-buffer)))))
1885 ((not (ediff-metajob3)) ; need 2 file args
1886 (funcall ediff-session-action-function
1888 ;; provide startup hooks
1891 'ediff-after-quit-hook-internal
1893 (if (ediff-buffer-live-p
1895 (ediff-show-meta-buffer
1899 (setq ediff-meta-buffer ,(current-buffer)
1900 ediff-meta-session-number
1902 (setq ediff-merge-store-file
1903 ,(if (ediff-nonempty-string-p
1904 merge-autostore-dir)
1907 ediff-merge-filename-prefix
1908 (file-name-nondirectory file1))) )
1909 ;; make ediff-startup pass
1910 ;; ediff-control-buffer back to the meta
1913 (quote ,info) ediff-control-buffer)))))
1914 ((ediff-metajob3) ; need 3 file args
1915 (funcall ediff-session-action-function
1917 ;; arrange startup hooks
1920 'ediff-after-quit-hook-internal
1922 (if (ediff-buffer-live-p
1924 (ediff-show-meta-buffer
1928 (setq ediff-merge-store-file
1929 ,(if (ediff-nonempty-string-p
1930 merge-autostore-dir)
1933 ediff-merge-filename-prefix
1934 (file-name-nondirectory file1))) )
1935 (setq ediff-meta-buffer , (current-buffer)
1936 ediff-meta-session-number
1938 ;; this arranges that ediff-startup will pass
1939 ;; the value of ediff-control-buffer back to
1940 ;; the meta level, to the record in the meta
1941 ;; list containing the information about the
1942 ;; session associated with that
1943 ;; ediff-control-buffer
1945 (quote ,info) ediff-control-buffer)))))
1947 ) ; eval in meta-buf
1950 (defun ediff-registry-action ()
1951 "Switch to a selected session."
1953 (let* ((pos (ediff-event-point last-command-event))
1954 (buf (ediff-event-buffer last-command-event))
1955 (ctl-buf (ediff-get-meta-info buf pos)))
1957 (if (ediff-buffer-live-p ctl-buf)
1958 ;; check if this is ediff-control-buffer or ediff-meta-buffer
1959 (if (ediff-with-current-buffer ctl-buf
1960 (eq (key-binding "q") 'ediff-quit-meta-buffer))
1961 ;; it's a meta-buffer -- last action should just display it
1962 (ediff-show-meta-buffer ctl-buf t)
1963 ;; it's a session buffer -- invoke go back to session
1964 (ediff-with-current-buffer ctl-buf
1965 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1966 (ediff-recenter 'no-rehighlight)))
1968 (message "You've selected a stale session --- try again")
1969 (ediff-update-registry))
1970 (ediff-with-current-buffer buf
1975 ;; If session number is t, means don't update meta buffer
1976 (defun ediff-show-meta-buffer (&optional meta-buf session-number)
1977 "Show the session group buffer."
1979 (run-hooks 'ediff-before-directory-setup-hooks)
1980 (let (wind frame silent)
1981 (if meta-buf (setq silent t))
1983 (setq meta-buf (or meta-buf ediff-meta-buffer))
1984 (cond ((not (bufferp meta-buf))
1985 (error "This Ediff session is not part of a session group"))
1986 ((not (ediff-buffer-live-p meta-buf))
1988 "Can't find this session's group panel -- session itself is ok")))
1990 (cond ((numberp session-number)
1991 (ediff-update-meta-buffer meta-buf nil session-number))
1992 ;; if session-number is t, don't update
1994 (t (ediff-cleanup-meta-buffer meta-buf)))
1996 (ediff-with-current-buffer meta-buf
1998 (cond ((setq wind (ediff-get-visible-buffer-window meta-buf))
2001 "Already showing the group panel for this session"))
2002 (set-window-buffer wind meta-buf)
2003 (select-window wind))
2004 ((window-live-p (setq wind ediff-window-C)) ;in merge--merge buf
2005 (set-window-buffer ediff-window-C meta-buf)
2006 (select-window wind))
2007 ((window-live-p (setq wind ediff-window-A))
2008 (set-window-buffer ediff-window-A meta-buf)
2009 (select-window wind))
2010 ((window-live-p (setq wind ediff-window-B))
2011 (set-window-buffer ediff-window-B meta-buf)
2012 (select-window wind))
2015 (ediff-get-visible-buffer-window ediff-registry-buffer))
2016 (ediff-window-display-p))
2017 (select-window wind)
2019 (set-window-buffer (selected-window) meta-buf))
2020 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
2021 (set-window-buffer (selected-window) meta-buf)))
2023 (if (and (ediff-window-display-p)
2025 (setq wind (ediff-get-visible-buffer-window meta-buf))))
2027 (setq frame (window-frame wind))
2029 (ediff-reset-mouse frame)))
2030 (sit-for 0) ; sometimes needed to synch the display and ensure that the
2031 ; point ends up after the just completed session
2032 (run-hooks 'ediff-show-session-group-hook)
2035 (defun ediff-show-current-session-meta-buffer ()
2037 (ediff-show-meta-buffer nil ediff-meta-session-number))
2039 (defun ediff-show-meta-buff-from-registry ()
2040 "Display the session group buffer for a selected session group."
2042 (let* ((pos (ediff-event-point last-command-event))
2043 (meta-buf (ediff-event-buffer last-command-event))
2044 (info (ediff-get-meta-info meta-buf pos))
2045 (meta-or-session-buf info))
2046 (ediff-with-current-buffer meta-or-session-buf
2047 (ediff-show-meta-buffer nil t))))
2050 (defun ediff-show-registry ()
2051 "Display Ediff's registry."
2053 (ediff-update-registry)
2054 (if (not (ediff-buffer-live-p ediff-registry-buffer))
2055 (error "No active Ediff sessions or corrupted session registry"))
2057 ;; for some reason, point moves in ediff-registry-buffer, so we preserve it
2059 (ediff-with-current-buffer ediff-registry-buffer
2062 (ediff-get-visible-buffer-window ediff-registry-buffer))
2063 (message "Already showing the registry")
2064 (set-window-buffer wind ediff-registry-buffer)
2065 (select-window wind))
2066 ((window-live-p ediff-window-C)
2067 (set-window-buffer ediff-window-C ediff-registry-buffer)
2068 (select-window ediff-window-C))
2069 ((window-live-p ediff-window-A)
2070 (set-window-buffer ediff-window-A ediff-registry-buffer)
2071 (select-window ediff-window-A))
2072 ((window-live-p ediff-window-B)
2073 (set-window-buffer ediff-window-B ediff-registry-buffer)
2074 (select-window ediff-window-B))
2076 (ediff-get-visible-buffer-window ediff-meta-buffer))
2077 (ediff-window-display-p))
2078 (select-window wind)
2080 (set-window-buffer (selected-window) ediff-registry-buffer))
2081 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
2082 (set-window-buffer (selected-window) ediff-registry-buffer)))
2084 (if (ediff-window-display-p)
2088 (ediff-get-visible-buffer-window ediff-registry-buffer)))
2090 (ediff-reset-mouse frame)))
2091 (run-hooks 'ediff-show-registry-hook)
2095 (defalias 'eregistry 'ediff-show-registry)
2097 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a
2099 ;; Check if META-BUF exists before calling this function
2100 ;; Optional MUST-REDRAW, if non-nil, would force redrawal of the whole meta
2101 ;; buffer. Otherwise, it will just go over the buffer and update activity marks
2102 ;; and session status.
2103 ;; SESSION-NUMBER, if specified, says which session caused the update.
2104 (defun ediff-update-meta-buffer (meta-buf &optional must-redraw session-number)
2105 (if (ediff-buffer-live-p meta-buf)
2106 (ediff-with-current-buffer meta-buf
2108 (cond (must-redraw ; completely redraw the meta buffer
2109 (funcall ediff-meta-redraw-function ediff-meta-list))
2110 ((numberp session-number) ; redraw only for the given session
2111 (ediff-update-session-marker-in-dir-meta-buffer
2113 (t ; update what changed only, but scan the entire meta buffer
2114 (ediff-update-markers-in-dir-meta-buffer ediff-meta-list)))
2115 (setq overl (ediff-get-meta-overlay-at-pos (point)))
2116 ;; skip the invisible sessions
2117 (while (and overl (ediff-overlay-get overl 'invisible))
2118 (ediff-next-meta-item1)
2119 (setq overl (ediff-get-meta-overlay-at-pos (point))))
2122 (defun ediff-update-registry ()
2123 (ediff-with-current-buffer (current-buffer)
2124 (if (ediff-buffer-live-p ediff-registry-buffer)
2125 (ediff-redraw-registry-buffer)
2126 (ediff-prepare-meta-buffer
2127 'ediff-registry-action
2128 ediff-session-registry
2130 'ediff-redraw-registry-buffer
2134 ;; If meta-buf exists, it is redrawn along with parent.
2135 ;; Otherwise, nothing happens.
2136 (defun ediff-cleanup-meta-buffer (meta-buffer)
2137 (if (ediff-buffer-live-p meta-buffer)
2138 (ediff-with-current-buffer meta-buffer
2139 (ediff-update-meta-buffer meta-buffer)
2140 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
2141 (ediff-update-meta-buffer
2142 ediff-parent-meta-buffer nil ediff-meta-session-number)))))
2144 ;; t if no session is in progress
2145 (defun ediff-safe-to-quit (meta-buffer)
2146 (if (ediff-buffer-live-p meta-buffer)
2147 (let ((lis ediff-meta-list)
2150 ;;(ediff-update-meta-buffer meta-buffer)
2151 (ediff-with-current-buffer meta-buffer
2152 (setq lis (cdr lis)) ; discard the description part of meta-list
2153 (while (and cont lis)
2154 (if (ediff-buffer-live-p
2155 (ediff-get-group-buffer lis)) ; in progress
2157 (setq lis (cdr lis)))
2160 (defun ediff-quit-meta-buffer ()
2161 "If the group has no active session, delete the meta buffer.
2162 If no session is in progress, ask to confirm before deleting meta buffer.
2163 Otherwise, bury the meta buffer.
2164 If this is a session registry buffer then just bury it."
2166 (let* ((buf (current-buffer))
2167 (dir-diffs-buffer ediff-dir-diffs-buffer)
2168 (meta-diff-buffer ediff-meta-diff-buffer)
2169 (session-number ediff-meta-session-number)
2170 (parent-buf ediff-parent-meta-buffer)
2171 (dont-show-registry (eq buf ediff-registry-buffer)))
2172 (if dont-show-registry
2174 ;;(ediff-cleanup-meta-buffer buf)
2175 (cond ((and (ediff-safe-to-quit buf)
2176 (y-or-n-p "Quit this session group? "))
2177 (run-hooks 'ediff-quit-session-group-hook)
2179 (ediff-dispose-of-meta-buffer buf))
2180 ((ediff-safe-to-quit buf)
2184 "This session group has active sessions---cannot exit")))
2185 (ediff-update-meta-buffer parent-buf nil session-number)
2186 (ediff-kill-buffer-carefully dir-diffs-buffer)
2187 (ediff-kill-buffer-carefully meta-diff-buffer)
2188 (if (ediff-buffer-live-p parent-buf)
2190 (setq dont-show-registry t)
2191 (ediff-show-meta-buffer parent-buf session-number)))
2193 (or dont-show-registry
2194 (ediff-show-registry))))
2196 (defun ediff-dispose-of-meta-buffer (buf)
2197 (setq ediff-session-registry (delq buf ediff-session-registry))
2198 (ediff-with-current-buffer buf
2199 (if (ediff-buffer-live-p ediff-dir-diffs-buffer)
2200 (kill-buffer ediff-dir-diffs-buffer)))
2204 ;; Obtain information on a meta record where the user clicked or typed
2205 ;; BUF is the buffer where this happened and POINT is the position
2206 ;; If optional NOERROR arg is given, don't report error and return nil if no
2207 ;; meta info is found on line.
2208 (defun ediff-get-meta-info (buf point &optional noerror)
2209 (let (result olist tmp)
2210 (if (and point (ediff-buffer-live-p buf))
2211 (ediff-with-current-buffer buf
2212 (if (featurep 'xemacs)
2214 (if (setq tmp (extent-at point buf 'ediff-meta-info))
2215 (ediff-overlay-get tmp 'ediff-meta-info)))
2217 (mapcar (lambda (elt)
2218 (unless (overlay-get elt 'invisible)
2219 (overlay-get elt 'ediff-meta-info)))
2220 (overlays-at point)))
2221 (while (and olist (null (car olist)))
2222 (setq olist (cdr olist)))
2223 (setq result (car olist)))))
2226 (ediff-update-registry)
2227 (error "No session info in this line")))))
2230 (defun ediff-get-meta-overlay-at-pos (point)
2231 (if (featurep 'xemacs)
2232 (extent-at point (current-buffer) 'ediff-meta-info)
2233 (let* ((overl-list (overlays-at point))
2234 (overl (car overl-list)))
2235 (while (and overl (null (overlay-get overl 'ediff-meta-info)))
2236 (setq overl-list (cdr overl-list)
2237 overl (car overl-list)))
2240 (defsubst ediff-get-session-number-at-pos (point &optional meta-buffer)
2241 (setq meta-buffer (if (ediff-buffer-live-p meta-buffer)
2244 (ediff-with-current-buffer meta-buffer
2246 (ediff-get-meta-overlay-at-pos point) 'ediff-meta-session-number)))
2249 ;; Return location of the next meta overlay after point
2250 (defun ediff-next-meta-overlay-start (point)
2252 (goto-char (point-min))
2253 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2254 (if (featurep 'xemacs)
2257 (setq overl (next-extent overl))
2258 (setq overl (next-extent (current-buffer))))
2260 (extent-start-position overl)
2264 ;; note: end of current overlay is the beginning of the next one
2266 (next-overlay-change point))))))
2269 (defun ediff-previous-meta-overlay-start (point)
2271 (goto-char (point-max))
2272 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2273 (if (featurep 'xemacs)
2276 (setq overl (previous-extent overl))
2277 (setq overl (previous-extent (current-buffer))))
2279 (extent-start-position overl)
2281 (if overl (setq point (overlay-start overl)))
2282 ;; to get to the beginning of prev overlay
2284 ;; trick to overcome an emacs bug--doesn't always find previous
2285 ;; overlay change correctly
2286 (setq point (1- point)))
2287 (setq point (previous-overlay-change point))
2288 ;; If we are not over an overlay after subtracting 1, it means we are
2289 ;; in the description area preceding session records. In this case,
2290 ;; goto the top of the registry buffer.
2291 (or (car (overlays-at point))
2292 (setq point (point-min)))
2295 ;; this is the action invoked when the user selects a patch from the meta
2297 (defun ediff-patch-file-form-meta (file &optional startup-hooks)
2298 (let* ((pos (ediff-event-point last-command-event))
2299 (meta-buf (ediff-event-buffer last-command-event))
2300 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
2301 (info (ediff-get-meta-info meta-buf pos))
2302 (meta-patchbuf ediff-meta-patchbufer)
2303 session-buf beg-marker end-marker)
2305 (if (or (file-directory-p file) (string-match "/dev/null" file))
2306 (error "`%s' is not an ordinary file" (file-name-as-directory file)))
2307 (setq session-buf (ediff-get-session-buffer info)
2308 beg-marker (ediff-get-session-objB-name info)
2309 end-marker (ediff-get-session-objC-name info))
2311 (or (ediff-buffer-live-p session-buf) ; either an active patch session
2312 (null session-buf) ; or it is a virgin session
2314 "Patch has already been applied to this file -- can't repeat!"))
2316 (ediff-with-current-buffer meta-patchbuf
2319 (narrow-to-region beg-marker end-marker)
2320 (ediff-patch-file-internal meta-patchbuf file startup-hooks)))))
2323 (defun ediff-unmark-all-for-operation ()
2324 "Unmark all sessions marked for operation."
2326 (let ((list (cdr ediff-meta-list))
2328 (while (setq elt (car list))
2329 (ediff-mark-session-for-operation elt 'unmark)
2330 (setq list (cdr list))))
2331 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2333 (defun ediff-unmark-all-for-hiding ()
2334 "Unmark all sessions marked for hiding."
2336 (let ((list (cdr ediff-meta-list))
2338 (while (setq elt (car list))
2339 (ediff-mark-session-for-hiding elt 'unmark)
2340 (setq list (cdr list))))
2341 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2344 ;; ACTION is ?h, ?m, ?=: to mark for hiding, mark for operation, or simply
2345 ;; indicate which are equal files
2346 (defun ediff-meta-mark-equal-files (&optional action)
2347 "Run through the session list and mark identical files.
2348 This is used only for sessions that involve 2 or 3 files at the same time.
2349 ACTION is an optional argument that can be ?h, ?m, ?=, to mark for hiding, mark
2350 for operation, or simply indicate which are equal files. If it is nil, then
2351 `last-command-char' is used to decide which action to take."
2354 (setq action last-command-char))
2355 (let ((list (cdr ediff-meta-list))
2356 marked1 marked2 marked3
2357 fileinfo1 fileinfo2 fileinfo3 elt)
2358 (message "Comparing files ...")
2359 (while (setq elt (car list))
2360 (setq fileinfo1 (ediff-get-session-objA elt)
2361 fileinfo2 (ediff-get-session-objB elt)
2362 fileinfo3 (ediff-get-session-objC elt))
2363 (ediff-set-file-eqstatus fileinfo1 nil)
2364 (ediff-set-file-eqstatus fileinfo2 nil)
2365 (ediff-set-file-eqstatus fileinfo3 nil)
2370 (or (ediff-mark-if-equal fileinfo1 fileinfo2)
2372 (if (ediff-metajob3)
2374 (or (ediff-mark-if-equal fileinfo1 fileinfo3)
2376 (or (ediff-mark-if-equal fileinfo2 fileinfo3)
2377 (setq marked3 nil))))
2378 (if (and marked1 marked2 marked3)
2379 (cond ((eq action ?h)
2380 (ediff-mark-session-for-hiding elt 'mark))
2382 (ediff-mark-session-for-operation elt 'mark))
2384 (setq list (cdr list)))
2385 (message "Comparing files ... Done"))
2386 (setq ediff-recurse-to-subdirectories nil)
2387 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2389 ;; mark files 1 and 2 as equal, if they are.
2390 ;; returns t, if something was marked
2391 (defun ediff-mark-if-equal (fileinfo1 fileinfo2)
2392 (let ((f1 (car fileinfo1))
2393 (f2 (car fileinfo2)))
2394 (if (and (stringp f1) (stringp f2) (ediff-same-contents f1 f2))
2396 (ediff-set-file-eqstatus fileinfo1 t)
2397 (ediff-set-file-eqstatus fileinfo2 t)
2402 (provide 'ediff-mult)
2405 ;;; Local Variables:
2406 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
2407 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
2408 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
2411 ;;; arch-tag: c8a76898-f96f-4d9c-be9d-129134017188
2412 ;;; ediff-mult.el ends here