1 ;;; ediff-mult.el --- support for multi-file/multi-buffer processing in Ediff
3 ;; Copyright (C) 1995, 96, 97, 98, 99, 2000, 01, 02 Free Software Foundation, Inc.
5 ;; Author: Michael Kifer <kifer@cs.stonybrook.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 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 ;; (HEADER (nil nil (obj1 nil) (obj2 nil) (obj3 nil))
45 ;; The function ediff-make-new-meta-list-element can be used to create
46 ;; 2nd and subsequent elements of that list (i.e., after the
47 ;; description header). See ediff-make-new-meta-list-element for the
48 ;; explanation of the two nil placeholders in such elements.
50 ;; There is API for extracting the components of the members of the
51 ;; above list. Search for `API for ediff-meta-list' for details.
53 ;; HEADER must be a list of SIX elements (nil or string):
54 ;; (regexp metaobj1 metaobj2 metaobj3 merge-save-buffer
55 ;; comparison-function)
56 ;; The function ediff-redraw-registry-buffer displays the
57 ;; 1st - 4th of these in the registry buffer.
58 ;; For some jobs some of the members of the header might be nil.
59 ;; The meaning of metaobj1, metaobj2, and metaobj3 depend on the job.
60 ;; Typically these are directories where the files to be compared are
62 ;; Also, keep in mind that the function ediff-prepare-meta-buffer
63 ;; (which see) prepends the session group buffer to the descriptor, so
64 ;; the descriptor becomes 7-long.
65 ;; Ediff expects that your function (in 2 above) will arrange to
66 ;; replace this prepended nil (via setcar) with the actual ediff
67 ;; control buffer associated with an appropriate Ediff session.
68 ;; This is arranged through internal startup hooks that can be passed
69 ;; to any of Ediff major entries (such as ediff-files, epatch, etc.).
70 ;; See how this is done in ediff-filegroup-action.
72 ;; Session descriptions are of the form
73 ;; (nil nil (obj1 . nil) (obj2 . nil) (obj3 . nil))
74 ;; which describe the objects relevant to the session.
75 ;; Use ediff-make-new-meta-list-element to create these things.
76 ;; Usually obj1/2/3 are names of files, but they may also be other
77 ;; things for some jobs. For instance, obj3 is nil for jobs that
78 ;; involve only two files. For patch jobs, obj2 and obj3 are markers
79 ;; that specify the patch corresponding to the file
80 ;; (whose name is obj1).
81 ;; The nil's are placeholders, which are used internally by ediff.
82 ;; 4. Write a function that makes a call to ediff-prepare-meta-buffer
83 ;; passing all this info.
84 ;; You may be able to use ediff-directories-internal as a template.
85 ;; 5. If you intend to add several related pieces of functionality,
86 ;; you may want to keep the function in 4 as an internal version
87 ;; and then write several top-level interactive functions that call it
88 ;; with different parameters.
89 ;; See how ediff-directories, ediff-merge-directories, and
90 ;; ediff-merge-directories-with-ancestor all use
91 ;; ediff-directories-internal.
93 ;; A useful addition here could be session groups selected by patterns
94 ;; (which are different in each directory). For instance, one may want to
95 ;; compare files of the form abc{something}.c to files old{something}.d
96 ;; which may be in the same or different directories. Or, one may want to
97 ;; compare all files of the form {something} to files of the form {something}~.
99 ;; Implementing this requires writing a collating function, which should pair
100 ;; up appropriate files. It will also require a generalization of the
101 ;; functions that do the layout of the meta- and differences buffers and of
102 ;; ediff-filegroup-action.
106 (provide 'ediff-mult
)
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 nil
'nosuffix
))
119 (or (featurep 'ediff-util
)
120 (load "ediff-util.el" nil nil
'nosuffix
))
124 (require 'ediff-init
)
125 (require 'ediff-util
)
128 (ediff-defvar-local ediff-meta-buffer nil
"")
129 (ediff-defvar-local ediff-parent-meta-buffer nil
"")
130 ;; the registry buffer
131 (defvar ediff-registry-buffer nil
)
133 (defconst ediff-meta-buffer-message
"This is an Ediff Session Group Panel: %s
136 button2, v, or RET over session record: start that Ediff session
137 M:\tin sessions invoked from here, brings back this group panel
138 R:\tdisplay the registry of active Ediff sessions
139 h:\tmark session for hiding (toggle)
140 x:\thide marked sessions; with prefix arg: unhide
141 m:\tmark session for a non-hiding operation (toggle)
142 uh/um:\tunmark all sessions marked for hiding/operation
144 p,DEL:\tprevious session
145 E:\tbrowse Ediff on-line manual
146 T:\ttoggle truncation of long file names
147 q:\tquit this session group
150 (ediff-defvar-local ediff-meta-buffer-map nil
151 "The keymap for the meta buffer.")
152 (defvar ediff-dir-diffs-buffer-map
(make-sparse-keymap)
153 "The keymap to be installed in the buffer showing differences between
156 ;; Variable specifying the action to take when the use invokes ediff in the
157 ;; meta buffer. This is usually ediff-registry-action or ediff-filegroup-action
158 (ediff-defvar-local ediff-meta-action-function nil
"")
159 ;; Tells ediff-update-meta-buffer how to redraw it
160 (ediff-defvar-local ediff-meta-redraw-function nil
"")
161 ;; Tells ediff-filegroup-action and similar procedures how to invoke Ediff for
162 ;; the sessions in a given session group
163 (ediff-defvar-local ediff-session-action-function nil
"")
165 (ediff-defvar-local ediff-metajob-name nil
"")
167 ;; buffer used to collect custom diffs from individual sessions in the group
168 (ediff-defvar-local ediff-meta-diff-buffer nil
"")
170 ;; history var to use for filtering groups of files
171 (defvar ediff-filtering-regexp-history nil
"")
173 (defcustom ediff-default-filtering-regexp nil
174 "The default regular expression used as a filename filter in multifile comparisons.
175 Should be a sexp. For instance (car ediff-filtering-regexp-history) or nil."
179 ;; This has the form ((meta-buf regexp dir1 dir2 dir3 merge-auto-store-dir)
180 ;; (ctl-buf session-status (file1 . eq-status) (file2 . eq-status) (file3
181 ;; . eq-status)) (ctl-buf session-status (file1 . eq-status) (file2
182 ;; . eq-status)) ...)
183 ;; If ctl-buf is nil, the file-pair hasn't processed yet. If it is
184 ;; killed-buffer object, the file pair has been processed. If it is a live
185 ;; buffer, this means ediff is still working on the pair.
186 ;; Eq-status of a file is t if the file equals some other file in the same
188 (ediff-defvar-local ediff-meta-list nil
"")
190 (ediff-defvar-local ediff-meta-session-number nil
"")
193 ;; the difference list between directories in a directory session group
194 (ediff-defvar-local ediff-dir-difference-list nil
"")
195 (ediff-defvar-local ediff-dir-diffs-buffer nil
"")
197 ;; The registry of Ediff sessions. A list of control buffers.
198 (defvar ediff-session-registry nil
)
200 (defcustom ediff-meta-truncate-filenames t
201 "*If non-nil, truncate long file names in the session group buffers.
202 This can be toggled with `ediff-toggle-filename-truncation'."
205 (defcustom ediff-registry-setup-hook nil
206 "*Hooks run just after the registry control panel is set up."
210 (defcustom ediff-before-session-group-setup-hooks nil
211 "*Hooks to run before Ediff arranges the window for group-level operations.
212 It is used by commands such as ediff-directories.
213 This hook can be used to save the previous window config, which can be restored
214 on ediff-quit, ediff-suspend, or ediff-quit-session-group-hook."
217 (defcustom ediff-after-session-group-setup-hook nil
218 "*Hooks run just after a meta-buffer controlling a session group, such as
219 ediff-directories, is run."
222 (defcustom ediff-quit-session-group-hook nil
223 "*Hooks run just before exiting a session group."
226 (defcustom ediff-show-registry-hook nil
227 "*Hooks run just after the registry buffer is shown."
230 (defcustom ediff-show-session-group-hook
'(delete-other-windows)
231 "*Hooks run just after a session group buffer is shown."
234 (defcustom ediff-meta-buffer-keymap-setup-hook nil
235 "*Hooks run just after setting up the ediff-meta-buffer-map.
236 This keymap controls key bindings in the meta buffer and is a local variable.
237 This means that you can set different bindings for different kinds of meta
242 ;; Buffer holding the multi-file patch. Local to the meta buffer
243 (ediff-defvar-local ediff-meta-patchbufer nil
"")
245 ;;; API for ediff-meta-list
247 ;; A meta-list is either ediff-meta-list, which contains a header and the list
248 ;; of ediff sessions or ediff-dir-difference-list, which is a header followed
249 ;; by the list of differences among the directories (i.e., files that are not
250 ;; in all directories). The header is the same in all meta lists, but the rest
252 ;; Structure of the meta-list:
253 ;; (HEADER SESSION1 SESSION2 ...)
254 ;; HEADER: (GROUP-BUF REGEXP OBJA OBJB OBJC SAVE-DIR COMPARISON-FUNC)
255 ;; OBJA - first directory
256 ;; OBJB - second directory
257 ;; OBJC - third directory
258 ;; SESSION1/2/... are described below
259 ;; group buffer/regexp
260 (defsubst ediff-get-group-buffer
(meta-list)
261 (nth 0 (car meta-list
)))
263 (defsubst ediff-get-group-regexp
(meta-list)
264 (nth 1 (car meta-list
)))
266 (defsubst ediff-get-group-objA
(meta-list)
267 (nth 2 (car meta-list
)))
268 (defsubst ediff-get-group-objB
(meta-list)
269 (nth 3 (car meta-list
)))
270 (defsubst ediff-get-group-objC
(meta-list)
271 (nth 4 (car meta-list
)))
272 (defsubst ediff-get-group-merge-autostore-dir
(meta-list)
273 (nth 5 (car meta-list
)))
274 (defsubst ediff-get-group-comparison-func
(meta-list)
275 (nth 6 (car meta-list
)))
277 ;; ELT is a session meta descriptor (what is being preserved as
279 ;; The structure is: (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
280 ;; STATUS is ?I (hidden or invalid), ?* (marked for operation), ?H (hidden)
282 ;; OBJA/B/C is (FILENAME EQSTATUS)
283 ;; EQSTATUS is ?= or nil (?= means that this file is equal to some other
284 ;; file in this session)
286 (defsubst ediff-get-session-buffer
(elt)
288 (defsubst ediff-get-session-status
(elt)
290 (defsubst ediff-set-session-status
(session-info new-status
)
291 (setcar (cdr session-info
) new-status
))
293 (defsubst ediff-get-session-objA
(elt)
295 (defsubst ediff-get-session-objB
(elt)
297 (defsubst ediff-get-session-objC
(elt)
299 ;; Take the "name" component of the object into acount. ObjA/C/B is of the form
300 ;; (name . equality-indicator)
301 (defsubst ediff-get-session-objA-name
(elt)
303 (defsubst ediff-get-session-objB-name
(elt)
305 (defsubst ediff-get-session-objC-name
(elt)
307 ;; equality indicators
308 (defsubst ediff-get-file-eqstatus
(elt)
310 (defsubst ediff-set-file-eqstatus
(elt value
)
311 (setcar (cdr elt
) value
))
313 ;; Create a new element for the meta list out of obj1/2/3, which usually are
316 ;; The first nil in such an element is later replaced with the session buffer.
317 ;; The second nil is reserved for session status.
319 ;; Also, session objects A/B/C are turned into lists of the form (obj nil).
320 ;; This nil is a placeholder for eq-indicator. It is either nil or =.
321 ;; If it is discovered that this file is = to some other
322 ;; file in the same session, eq-indicator is changed to `='.
323 ;; Curently, the eq-indicator is used only for 2 and 3-file jobs.
324 (defun ediff-make-new-meta-list-element (obj1 obj2 obj3
)
325 (list nil nil
(list obj1 nil
) (list obj2 nil
) (list obj3 nil
)))
327 ;; Constructs a meta list header.
328 ;; OBJA, OBJB, OBJC are usually directories involved, but can be different for
329 ;; different jobs. For instance, multifile patch has only OBJA, which is the
331 (defun ediff-make-new-meta-list-header (regexp
335 (list regexp objA objB objC merge-auto-store-dir comparison-func
))
337 ;; The activity marker is either or + (active session, i.e., ediff is currently
338 ;; run in it), or - (finished session, i.e., we've ran ediff in it and then
339 ;; exited). Return nil, if session is neither active nor finished
340 (defun ediff-get-session-activity-marker (session)
341 (let ((session-buf (ediff-get-session-buffer session
)))
342 (cond ((null session-buf
) nil
) ; virgin session
343 ((ediff-buffer-live-p session-buf
) ?
+) ;active session
346 ;; checks if the session is a meta session
347 (defun ediff-meta-session-p (session-info)
348 (and (stringp (ediff-get-session-objA-name session-info
))
349 (file-directory-p (ediff-get-session-objA-name session-info
))
350 (stringp (ediff-get-session-objB-name session-info
))
351 (file-directory-p (ediff-get-session-objB-name session-info
))
352 (if (stringp (ediff-get-session-objC-name session-info
))
353 (file-directory-p (ediff-get-session-objC-name session-info
)) t
)))
355 ;; set up the keymap in the meta buffer
356 (defun ediff-setup-meta-map()
357 (setq ediff-meta-buffer-map
(make-sparse-keymap))
358 (suppress-keymap ediff-meta-buffer-map
)
359 (define-key ediff-meta-buffer-map
"q" 'ediff-quit-meta-buffer
)
360 (define-key ediff-meta-buffer-map
"T" 'ediff-toggle-filename-truncation
)
361 (define-key ediff-meta-buffer-map
"R" 'ediff-show-registry
)
362 (define-key ediff-meta-buffer-map
"E" 'ediff-documentation
)
363 (define-key ediff-meta-buffer-map
"v" ediff-meta-action-function
)
364 (define-key ediff-meta-buffer-map
"\C-m" ediff-meta-action-function
)
365 (define-key ediff-meta-buffer-map
" " 'ediff-next-meta-item
)
366 (define-key ediff-meta-buffer-map
"n" 'ediff-next-meta-item
)
367 (define-key ediff-meta-buffer-map
"\C-?" 'ediff-previous-meta-item
)
368 (define-key ediff-meta-buffer-map
"p" 'ediff-previous-meta-item
)
369 (define-key ediff-meta-buffer-map
[delete] 'ediff-previous-meta-item)
370 (define-key ediff-meta-buffer-map [backspace] 'ediff-previous-meta-item)
371 (or (ediff-one-filegroup-metajob)
373 (define-key ediff-meta-buffer-map "=" nil)
374 (define-key ediff-meta-buffer-map "==" 'ediff-meta-mark-equal-files)
375 (define-key ediff-meta-buffer-map "=m" 'ediff-meta-mark-equal-files)
376 (define-key ediff-meta-buffer-map "=h" 'ediff-meta-mark-equal-files)))
377 (if ediff-no-emacs-help-in-control-buffer
378 (define-key ediff-meta-buffer-map "\C-h" 'ediff-previous-meta-item))
380 (define-key ediff-meta-buffer-map [mouse-2] ediff-meta-action-function)
381 (define-key ediff-meta-buffer-map [button2] ediff-meta-action-function))
383 (use-local-map ediff-meta-buffer-map)
384 ;; modify ediff-meta-buffer-map here
385 (run-hooks 'ediff-meta-buffer-keymap-setup-hook))
388 (defun ediff-meta-mode ()
389 "This mode controls all operations on Ediff session groups.
390 It is entered through one of the following commands:
395 `ediff-merge-directories'
397 `ediff-merge-directories-with-ancestor'
398 `edirs-merge-with-ancestor'
399 `ediff-directory-revisions'
401 `ediff-merge-directory-revisions'
402 `edir-merge-revisions'
403 `ediff-merge-directory-revisions-with-ancestor'
404 `edir-merge-revisions-with-ancestor'
407 \\{ediff-meta-buffer-map}"
408 (kill-all-local-variables)
409 (setq major-mode 'ediff-meta-mode)
410 (setq mode-name "MetaEdiff"))
413 ;; the keymap for the buffer showing directory differences
414 (suppress-keymap ediff-dir-diffs-buffer-map)
415 (define-key ediff-dir-diffs-buffer-map "q" 'ediff-bury-dir-diffs-buffer)
416 (define-key ediff-dir-diffs-buffer-map " " 'next-line)
417 (define-key ediff-dir-diffs-buffer-map "n" 'next-line)
418 (define-key ediff-dir-diffs-buffer-map "\C-?" 'previous-line)
419 (define-key ediff-dir-diffs-buffer-map "p" 'previous-line)
420 (define-key ediff-dir-diffs-buffer-map "C" 'ediff-dir-diff-copy-file)
422 (define-key ediff-dir-diffs-buffer-map [mouse-2] 'ediff-dir-diff-copy-file)
423 (define-key ediff-dir-diffs-buffer-map [button2] 'ediff-dir-diff-copy-file))
424 (define-key ediff-dir-diffs-buffer-map [delete] 'previous-line
)
425 (define-key ediff-dir-diffs-buffer-map
[backspace] 'previous-line)
427 (defun ediff-next-meta-item (count)
428 "Move to the next item in Ediff registry or session group buffer.
429 Moves in circular fashion. With numeric prefix arg, skip this many items."
431 (or count (setq count 1))
434 (setq count (1- count))
435 (ediff-next-meta-item1)
436 (setq overl (ediff-get-meta-overlay-at-pos (point)))
437 ;; skip invisible ones
438 (while (and overl (ediff-overlay-get overl 'invisible))
439 (ediff-next-meta-item1)
440 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
442 ;; Move to the next meta item
443 (defun ediff-next-meta-item1 ()
445 (setq pos (ediff-next-meta-overlay-start (point)))
446 (if pos (goto-char pos))
447 (if (eq ediff-metajob-name 'ediff-registry)
448 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
449 (search-forward "*Ediff" nil t))
450 (skip-chars-backward "a-zA-Z*"))
451 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
452 (backward-char 1)))))
455 (defun ediff-previous-meta-item (count)
456 "Move to the previous item in Ediff registry or session group buffer.
457 Moves in circular fashion. With numeric prefix arg, skip this many items."
459 (or count (setq count 1))
462 (setq count (1- count))
463 (ediff-previous-meta-item1)
464 (setq overl (ediff-get-meta-overlay-at-pos (point)))
465 ;; skip invisible ones
466 (while (and overl (ediff-overlay-get overl 'invisible))
467 (ediff-previous-meta-item1)
468 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
470 (defun ediff-previous-meta-item1 ()
472 (setq pos (ediff-previous-meta-overlay-start (point)))
474 ;;; (while (ediff-get-session-status
475 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
476 ;;; (setq pos (ediff-previous-meta-overlay-start pos)))
478 (if pos (goto-char pos))
479 (if (eq ediff-metajob-name 'ediff-registry)
480 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
481 (search-forward "*Ediff" nil t))
482 (skip-chars-backward "a-zA-Z*"))
483 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
487 (defsubst ediff-add-slash-if-directory (dir file)
488 (if (file-directory-p (concat dir file))
489 (file-name-as-directory file)
492 (defun ediff-toggle-filename-truncation ()
493 "Toggle truncation of long file names in session group buffers.
494 Set `ediff-meta-truncate-filenames' variable if you want to change the default
497 (setq ediff-meta-truncate-filenames (not ediff-meta-truncate-filenames))
498 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
501 ;; These are used to encode membership of files in directory1/2/3
502 ;; Membership code of a file is a product of codes for the directories where
504 (defvar ediff-membership-code1 2)
505 (defvar ediff-membership-code2 3)
506 (defvar ediff-membership-code3 5)
507 (defvar ediff-product-of-memcodes (* ediff-membership-code1
508 ediff-membership-code2
509 ediff-membership-code3))
511 ;; DIR1, DIR2, DIR3 are directories. DIR3 can be nil.
512 ;; OUTPUT-DIR is a directory for auto-storing the results of merge jobs.
514 ;; REGEXP is nil or a filter regexp; only file names that match the regexp
516 ;; If a file is a directory in dir1 but not dir2 (or vice versa), it is not
517 ;; included in the intersection. However, a regular file that is a dir in dir3
518 ;; is included, since dir3 files are supposed to be ancestors for merging.
519 ;; If COMPARISON-FUNC is given, use it. Otherwise, use string=
521 ;; Returns a list of the form:
522 ;; (COMMON-PART DIFF-LIST)
523 ;; COMMON-PART is car and DIFF-LIST is cdr.
525 ;; COMMON-PART is of the form:
526 ;; (META-HEADER (f1 f2 f3) (f1 f2 f3) ...)
527 ;; f3 can be nil if intersecting only 2 directories.
528 ;; Each triple (f1 f2 f3) represents the files to be compared in the
529 ;; corresponding ediff subsession.
531 ;; DIFF-LIST is of the form:
532 ;; (META-HEADER (file . num) (file . num)...)
533 ;; where num encodes the set of dirs where the file is found:
534 ;; 2 - only dir1; 3 - only dir2; 5 - only dir3; 6 - dir1&2; 10 - dir1&3; etc.
536 ;; Contains the meta info about this ediff operation
537 ;; (regexp dir1 dir2 dir3 merge-auto-store-dir comparison-func)
538 ;; Later the meta-buffer is prepended to this list.
540 ;; Some operations might use a different meta header. For instance,
541 ;; ediff-multifile-patch doesn't have dir2 and dir3, and regexp,
542 ;; comparison-func don't apply.
544 (defun ediff-intersect-directories (jobname
547 dir3 merge-autostore-dir comparison-func)
548 (setq comparison-func (or comparison-func 'string=))
549 (let (lis1 lis2 lis3 common auxdir1 auxdir2 auxdir3 common-part difflist)
551 (setq auxdir1 (file-name-as-directory dir1)
552 lis1 (directory-files auxdir1 nil regexp)
553 lis1 (delete "." lis1)
554 lis1 (delete ".." lis1)
557 (ediff-add-slash-if-directory auxdir1 elt))
559 auxdir2 (file-name-as-directory dir2)
562 (ediff-add-slash-if-directory auxdir2 elt))
563 (directory-files auxdir2 nil regexp)))
566 (setq auxdir3 (file-name-as-directory dir3)
569 (ediff-add-slash-if-directory auxdir3 elt))
570 (directory-files auxdir3 nil regexp))))
572 (if (ediff-nonempty-string-p merge-autostore-dir)
573 (setq merge-autostore-dir
574 (file-name-as-directory merge-autostore-dir)))
575 (setq common (ediff-intersection lis1 lis2 comparison-func))
577 ;; In merge with ancestor jobs, we don't intersect with lis3.
578 ;; If there is no ancestor, we'll offer to merge without the ancestor.
579 ;; So, we intersect with lis3 only when we are doing 3-way file comparison
580 (if (and lis3 (ediff-comparison-metajob3 jobname))
581 (setq common (ediff-intersection common lis3 comparison-func)))
583 ;; copying is needed because sort sorts via side effects
584 (setq common (sort (ediff-copy-list common) 'string-lessp))
586 ;; compute difference list
587 (setq difflist (ediff-set-difference
588 (ediff-union (ediff-union lis1 lis2 comparison-func)
593 difflist (delete "." difflist)
594 ;; copying is needed because sort sorts via side effects
595 difflist (sort (ediff-copy-list (delete ".." difflist))
598 (setq difflist (mapcar (lambda (elt) (cons elt 1)) difflist))
600 ;; check for files belonging to lis1/2/3
601 ;; Each elt is of the norm (file . number)
602 ;; Number encodes the directories to which file belongs.
603 ;; It is a product of a subset of ediff-membership-code1=2,
604 ;; ediff-membership-code2=3, and ediff-membership-code3=5.
605 ;; If file belongs to dir 1 only, the membership code is 2.
606 ;; If it is in dir1 and dir3, then the membership code is 2*5=10;
607 ;; if it is in dir1 and dir2, then the membership code is 2*3=6, etc.
608 (mapcar (lambda (elt)
609 (if (member (car elt) lis1)
610 (setcdr elt (* (cdr elt) ediff-membership-code1)))
611 (if (member (car elt) lis2)
612 (setcdr elt (* (cdr elt) ediff-membership-code2)))
613 (if (member (car elt) lis3)
614 (setcdr elt (* (cdr elt) ediff-membership-code3)))
618 ;; diff metalist header
619 (ediff-make-new-meta-list-header regexp
620 auxdir1 auxdir2 auxdir3
628 (ediff-make-new-meta-list-header regexp
629 auxdir1 auxdir2 auxdir3
634 (ediff-make-new-meta-list-element
639 ;; The following is done because: In merging with
640 ;; ancestor, we don't intersect with lis3. So, it is
641 ;; possible that elt is a file in auxdir1/2 but a
642 ;; directory in auxdir3 Or elt may not exist in auxdir3 at
643 ;; all. In the first case, we add a slash at the end. In
644 ;; the second case, we insert nil.
645 (setq elt (ediff-add-slash-if-directory auxdir3 elt))
646 (if (file-exists-p (concat auxdir3 elt))
647 (concat auxdir3 elt))))))
650 (cons common-part difflist)
653 ;; find directory files that are under revision. Include subdirectories, since
654 ;; we may visit them recursively. DIR1 is the directory to inspect.
655 ;; MERGE-AUTOSTORE-DIR is the directory where to auto-store the results of
656 ;; merges. Can be nil.
657 (defun ediff-get-directory-files-under-revision (jobname
659 &optional merge-autostore-dir)
660 (let (lis1 elt common auxdir1)
661 (setq auxdir1 (file-name-as-directory dir1)
662 lis1 (directory-files auxdir1 nil regexp))
664 (if (ediff-nonempty-string-p merge-autostore-dir)
665 (setq merge-autostore-dir
666 (file-name-as-directory merge-autostore-dir)))
671 ;; take files under revision control
672 (cond ((file-directory-p (concat auxdir1 elt))
674 (cons (ediff-add-slash-if-directory auxdir1 elt) common)))
675 ((and (featurep 'vc-hooks) (vc-backend (concat auxdir1 elt)))
676 (setq common (cons elt common)))
677 ;; The following two are needed only if vc-hooks isn't loaded.
678 ;; They won't recognize CVS files.
679 ((file-exists-p (concat auxdir1 elt ",v"))
680 (setq common (cons elt common)))
681 ((file-exists-p (concat auxdir1 "RCS/" elt ",v"))
682 (setq common (cons elt common)))
686 (setq common (delete "./" common)
687 common (delete "../" common)
688 common (delete "RCS" common)
689 common (delete "CVS" common)
692 ;; copying is needed because sort sorts via side effects
693 (setq common (sort (ediff-copy-list common) 'string-lessp))
697 ;; header -- has 6 elements. Meta buffer is prepended later by
698 ;; ediff-prepare-meta-buffer
699 (ediff-make-new-meta-list-header regexp
701 merge-autostore-dir nil)
702 (mapcar (lambda (elt) (ediff-make-new-meta-list-element
703 (concat auxdir1 elt) nil nil))
708 ;; If file groups selected by patterns will ever be implemented, this
709 ;; comparison function might become useful.
710 ;;;; uses external variables PAT1 PAT2 to compare str1/2
711 ;;;; patterns must be of the form ???*???? where ??? are strings of chars
712 ;;;; containing no *.
713 ;;(defun ediff-pattern= (str1 str2)
714 ;; (let (pos11 pos12 pos21 pos22 len1 len2)
716 ;; len (length epat1)
718 ;; (while (and (< pos11 len) (not (= (aref epat1 pos11) ?*)))
719 ;; (setq pos11 (1+ pos11)))
720 ;; (while (and (> pos12 0) (not (= (aref epat1 (1- pos12)) ?*)))
721 ;; (setq pos12 (1- pos12)))
724 ;; len (length epat2)
726 ;; (while (and (< pos21 len) (not (= (aref epat2 pos21) ?*)))
727 ;; (setq pos21 (1+ pos21)))
728 ;; (while (and (> pos22 0) (not (= (aref epat2 (1- pos22)) ?*)))
729 ;; (setq pos22 (1- pos22)))
731 ;; (if (and (> (length str1) pos12) (>= pos12 pos11) (> pos11 -1)
732 ;; (> (length str2) pos22) (>= pos22 pos21) (> pos21 -1))
733 ;; (string= (substring str1 pos11 pos12)
734 ;; (substring str2 pos21 pos22)))
738 ;; Prepare meta-buffer in accordance with the argument-function and
739 ;; redraw-function. Must return the created meta-buffer.
740 (defun ediff-prepare-meta-buffer (action-func meta-list
741 meta-buffer-name redraw-function
742 jobname &optional startup-hooks)
743 (let* ((meta-buffer-name
744 (ediff-unique-buffer-name meta-buffer-name "*"))
745 (meta-buffer (get-buffer-create meta-buffer-name)))
746 (ediff-with-current-buffer meta-buffer
751 (setq ediff-meta-action-function action-func
752 ediff-meta-redraw-function redraw-function
753 ediff-metajob-name jobname
754 ediff-meta-buffer meta-buffer)
756 ;; comes after ediff-meta-action-function is set
757 (ediff-setup-meta-map)
759 (if (eq ediff-metajob-name 'ediff-registry)
761 (setq ediff-registry-buffer meta-buffer
762 ediff-meta-list meta-list)
763 ;; this func is used only from registry buffer, not from other
766 ediff-meta-buffer-map "M" 'ediff-show-meta-buff-from-registry))
767 ;; Initialize the meta list -- we don't do this for registry.
768 (setq ediff-meta-list
769 ;; add meta-buffer to the list header
770 (cons (cons meta-buffer (car meta-list))
773 (or (eq meta-buffer ediff-registry-buffer)
774 (setq ediff-session-registry
775 (cons meta-buffer ediff-session-registry)))
777 ;; redraw-function uses ediff-meta-list
778 (funcall redraw-function ediff-meta-list)
780 ;; set read-only/non-modified
781 (setq buffer-read-only t)
782 (set-buffer-modified-p nil)
784 (run-hooks 'startup-hooks)
786 ;; Arrange to show directory contents differences
787 ;; Must be after run startup-hooks, since ediff-dir-difference-list is
788 ;; set inside these hooks
789 (if (eq action-func 'ediff-filegroup-action)
791 ;; put meta buffer in (car ediff-dir-difference-list)
792 (setq ediff-dir-difference-list
793 (cons (cons meta-buffer (car ediff-dir-difference-list))
794 (cdr ediff-dir-difference-list)))
796 (or (ediff-one-filegroup-metajob jobname)
797 (ediff-draw-dir-diffs ediff-dir-difference-list))
799 ediff-meta-buffer-map "h" 'ediff-mark-for-hiding-at-pos)
800 (define-key ediff-meta-buffer-map "x" 'ediff-hide-marked-sessions)
802 ediff-meta-buffer-map "m" 'ediff-mark-for-operation-at-pos)
803 (define-key ediff-meta-buffer-map "u" nil)
805 ediff-meta-buffer-map "um" 'ediff-unmark-all-for-operation)
807 ediff-meta-buffer-map "uh" 'ediff-unmark-all-for-hiding)
808 (cond ((ediff-collect-diffs-metajob jobname)
810 ediff-meta-buffer-map "P" 'ediff-collect-custom-diffs))
811 ((ediff-patch-metajob jobname)
813 ediff-meta-buffer-map "P" 'ediff-meta-show-patch)))
814 (define-key ediff-meta-buffer-map "^" 'ediff-up-meta-hierarchy)
815 (define-key ediff-meta-buffer-map "D" 'ediff-show-dir-diffs)))
817 (if (eq ediff-metajob-name 'ediff-registry)
818 (run-hooks 'ediff-registry-setup-hook)
819 (run-hooks 'ediff-after-session-group-setup-hook))
820 ) ; eval in meta-buffer
823 ;; Insert the activity marker for session SESSION in the meta buffer at point
824 ;; The activity marker is either SPC (untouched session), or + (active session,
825 ;; i.e., ediff is currently run in it), or - (finished session, i.e., we've ran
826 ;; ediff in it and then exited)
827 (defun ediff-insert-session-activity-marker-in-meta-buffer (session)
829 (cond ((ediff-get-session-activity-marker session))
833 ;; Insert session status at point. Status is either ?H (marked for hiding), or
834 ;; ?I (hidden or invalid), or ?* (meaning marked for an operation; currently,
835 ;; such op can only be checking for equality)), or SPC (meaning neither marked
837 (defun ediff-insert-session-status-in-meta-buffer (session)
839 (cond ((ediff-get-session-status session)) ; session has status: ?H, ?I, ?*
840 ;; normal session, no marks or hidings
843 ;; If NEW-MARKER is non-nil, use it to substitute the current activity marker
844 ;; in the meta buffer. If nil, use SPC
845 (defun ediff-replace-session-activity-marker-in-meta-buffer (point new-marker)
846 (let* ((overl (ediff-get-meta-overlay-at-pos point))
847 (session-info (ediff-overlay-get overl 'ediff-meta-info))
848 (activity-marker (ediff-get-session-activity-marker session-info))
850 (or new-marker activity-marker (setq new-marker ?\ ))
851 (goto-char (ediff-overlay-start overl))
852 (if (eq (char-after (point)) new-marker)
853 () ; if marker shown in buffer is the same as new-marker, do nothing
856 (set-buffer-modified-p nil))))
858 ;; If NEW-STATUS is non-nil, use it to substitute the current status marker in
859 ;; the meta buffer. If nil, use SPC
860 (defun ediff-replace-session-status-in-meta-buffer (point new-status)
861 (let* ((overl (ediff-get-meta-overlay-at-pos point))
862 (session-info (ediff-overlay-get overl 'ediff-meta-info))
863 (status (ediff-get-session-status session-info))
865 (setq new-status (or new-status status ?\ ))
866 (goto-char (ediff-overlay-start overl))
867 (forward-char 1) ; status is the second char in session record
868 (if (eq (char-after (point)) new-status)
869 () ; if marker shown in buffer is the same as new-marker, do nothing
872 (set-buffer-modified-p nil))))
874 ;; insert all file info in meta buffer for a given session
875 (defun ediff-insert-session-info-in-meta-buffer (session-info sessionNum)
876 (let ((f1 (ediff-get-session-objA session-info))
877 (f2 (ediff-get-session-objB session-info))
878 (f3 (ediff-get-session-objC session-info))
880 (hidden (eq (ediff-get-session-status session-info) ?I)))
881 ;; insert activity marker, i.e., SPC, - or +
882 (ediff-insert-session-activity-marker-in-meta-buffer session-info)
883 ;; insert session status, i.e., *, H
884 (ediff-insert-session-status-in-meta-buffer session-info)
885 (insert " Session " (int-to-string sessionNum) ":\n")
886 (ediff-meta-insert-file-info1 f1)
887 (ediff-meta-insert-file-info1 f2)
888 (ediff-meta-insert-file-info1 f3)
889 (ediff-set-meta-overlay pt (point) session-info sessionNum hidden)))
892 ;; this is a setup function for ediff-directories
893 ;; must return meta-buffer
894 (defun ediff-redraw-directory-group-buffer (meta-list)
895 ;; extract directories
896 (let ((meta-buf (ediff-get-group-buffer meta-list))
899 regexp elt merge-autostore-dir
900 point tmp-list buffer-read-only)
901 (ediff-with-current-buffer meta-buf
904 ;; delete phony overlays that used to represent sessions before the buff
906 (ediff-cond-compile-for-xemacs-or-emacs
907 (map-extents 'delete-extent) ; xemacs
908 (mapcar 'delete-overlay (overlays-in 1 1)) ; emacs
911 (insert (format ediff-meta-buffer-message
912 (ediff-abbrev-jobname ediff-metajob-name)))
914 (setq regexp (ediff-get-group-regexp meta-list)
916 (ediff-get-group-merge-autostore-dir meta-list))
918 (cond ((ediff-collect-diffs-metajob)
920 " P:\tcollect custom diffs of all marked sessions\n"))
921 ((ediff-patch-metajob)
923 " P:\tshow patch appropriately for the context (session or group)\n")))
925 " ^:\tshow parent session group\n")
926 (or (ediff-one-filegroup-metajob)
928 " D:\tshow differences among directories\n"
929 " ==:\tfor each session, show which files are identical\n"
930 " =h:\tlike ==, but also marks those sessions for hiding\n"
931 " =m:\tlike ==, but also marks those sessions for operation\n\n"))
934 (if (and (stringp regexp) (> (length regexp) 0))
936 (format "*** Filter-through regular expression: %s\n" regexp)))
937 (ediff-insert-dirs-in-meta-buffer meta-list)
938 (if (and ediff-autostore-merges (ediff-merge-metajob)
939 (ediff-nonempty-string-p merge-autostore-dir))
941 "\nMerge results are automatically stored in:\n\t%s\n"
942 merge-autostore-dir)))
944 Size Last modified Name
945 ----------------------------------------------
949 ;; discard info on directories and regexp
950 (setq meta-list (cdr meta-list)
952 (while (and tmp-list empty)
953 (if (and (car tmp-list)
954 (not (eq (ediff-get-session-status (car tmp-list)) ?I)))
956 (setq tmp-list (cdr tmp-list)))
960 " ****** ****** This session group has no members\n"))
962 ;; now organize file names like this:
963 ;; use-mark sizeA dateA sizeB dateB filename
964 ;; make sure directories are displayed with a trailing slash.
966 (setq elt (car meta-list)
967 meta-list (cdr meta-list)
968 sessionNum (1+ sessionNum))
969 (if (eq (ediff-get-session-status elt) ?I)
971 (ediff-insert-session-info-in-meta-buffer elt sessionNum)))
972 (set-buffer-modified-p nil)
976 (defun ediff-update-markers-in-dir-meta-buffer (meta-list)
977 (let ((meta-buf (ediff-get-group-buffer meta-list))
978 session-info point overl buffer-read-only)
979 (ediff-with-current-buffer meta-buf
981 (goto-char (point-min))
982 (ediff-next-meta-item1)
984 (setq session-info (ediff-get-meta-info meta-buf (point) 'no-error)
985 overl (ediff-get-meta-overlay-at-pos (point)))
988 (cond ((eq (ediff-get-session-status session-info) ?I)
990 (if overl (ediff-overlay-put overl 'invisible t)))
991 ((and (eq (ediff-get-session-status session-info) ?H)
992 overl (ediff-overlay-get overl 'invisible))
994 (ediff-overlay-put overl 'invisible nil))
995 (t (ediff-replace-session-activity-marker-in-meta-buffer
997 (ediff-get-session-activity-marker session-info))
998 (ediff-replace-session-status-in-meta-buffer
1000 (ediff-get-session-status session-info))))))
1001 (ediff-next-meta-item1) ; advance to the next item
1003 (set-buffer-modified-p nil)
1007 (defun ediff-update-session-marker-in-dir-meta-buffer (session-num)
1008 (let (buffer-meta-overlays session-info overl buffer-read-only)
1010 (ediff-cond-compile-for-xemacs-or-emacs
1011 (map-extents ; xemacs
1012 (lambda (ext maparg)
1014 (ediff-overlay-get ext 'ediff-meta-info)
1015 (eq (ediff-overlay-get ext 'ediff-meta-session-number)
1018 ;; Emacs doesn't have map-extents, so try harder
1019 ;; Splice overlay lists to get all buffer overlays
1021 (setq buffer-meta-overlays (overlay-lists)
1022 buffer-meta-overlays (append (car buffer-meta-overlays)
1023 (cdr buffer-meta-overlays)))
1029 (ediff-overlay-get overl 'ediff-meta-info)
1030 (eq (ediff-overlay-get
1031 overl 'ediff-meta-session-number)
1034 buffer-meta-overlays))))
1038 "Bug in ediff-update-session-marker-in-dir-meta-buffer: no overlay with given number %S"
1040 (setq session-info (ediff-overlay-get overl 'ediff-meta-info))
1041 (goto-char (ediff-overlay-start overl))
1042 (ediff-replace-session-activity-marker-in-meta-buffer
1044 (ediff-get-session-activity-marker session-info))
1045 (ediff-replace-session-status-in-meta-buffer
1047 (ediff-get-session-status session-info)))
1048 (ediff-next-meta-item1))
1052 ;; Check if this is a problematic session.
1053 ;; Return nil if not. Otherwise, return symbol representing the problem
1054 ;; At present, problematic sessions occur only in -with-ancestor comparisons
1055 ;; when the ancestor is a directory rather than a file, or when there is no
1056 ;; suitable ancestor file in the ancestor directory
1057 (defun ediff-problematic-session-p (session)
1058 (let ((f1 (ediff-get-session-objA-name session))
1059 (f2 (ediff-get-session-objB-name session))
1060 (f3 (ediff-get-session-objC-name session)))
1061 (cond ((and (stringp f1) (not (file-directory-p f1))
1062 (stringp f2) (not (file-directory-p f2))
1063 ;; either invalid file name or a directory
1064 (or (not (stringp f3)) (file-directory-p f3))
1065 (ediff-ancestor-metajob))
1066 ;; more may be added later
1070 (defun ediff-meta-insert-file-info1 (fileinfo)
1071 (let ((fname (car fileinfo))
1072 (feq (ediff-get-file-eqstatus fileinfo))
1073 (max-filename-width (if ediff-meta-truncate-filenames
1074 (- (window-width) 41)
1076 file-modtime file-size)
1077 (cond ((not (stringp fname)) (setq file-size -2)) ; file doesn't exits
1078 ((ediff-listable-file fname)
1079 (if (file-exists-p fname)
1080 ;; set real size and modtime
1081 (setq file-size (ediff-file-size fname)
1082 file-modtime (ediff-file-modtime fname))
1083 (setq file-size -2))) ; file doesn't exist
1084 ( t (setq file-size -1))) ; remote file
1089 (if feq "=" " ") ; equality indicator
1090 (format "%10s" (cond ((= file-size -1) "--")
1091 ((< file-size -1) "--")
1093 (cond ((= file-size -1) "*remote file*")
1094 ((< file-size -1) "*file doesn't exist*")
1095 (t (ediff-format-date (decode-time file-modtime))))
1097 ;; dir names in meta lists have training slashes, so we just
1098 ;; abbreviate the file name, if file exists
1099 (if (and (not (stringp fname)) (< file-size -1))
1100 "-------" ; file doesn't exist
1101 (ediff-truncate-string-left
1102 (ediff-abbreviate-file-name fname)
1103 max-filename-width)))))))
1105 (defconst ediff-months '((1 . "Jan") (2 . "Feb") (3 . "Mar") (4 . "Apr")
1106 (5 . "May") (6 . "Jun") (7 . "Jul") (8 . "Aug")
1107 (9 . "Sep") (10 . "Oct") (11 . "Nov") (12 . "Dec"))
1108 "Months' associative array.")
1110 ;; returns 2char string
1111 (defsubst ediff-fill-leading-zero (num)
1114 (number-to-string num)))
1116 ;; TIME is like the output of decode-time
1117 (defun ediff-format-date (time)
1118 (format "%s %2d %4d %s:%s:%s"
1119 (cdr (assoc (nth 4 time) ediff-months)) ; month
1122 (ediff-fill-leading-zero (nth 2 time)) ; hour
1123 (ediff-fill-leading-zero (nth 1 time)) ; min
1124 (ediff-fill-leading-zero (nth 0 time)) ; sec
1127 ;; Draw the directories
1128 (defun ediff-insert-dirs-in-meta-buffer (meta-list)
1129 (let* ((dir1 (ediff-abbreviate-file-name (ediff-get-group-objA meta-list)))
1130 (dir2 (ediff-get-group-objB meta-list))
1131 (dir2 (if (stringp dir2) (ediff-abbreviate-file-name dir2)))
1132 (dir3 (ediff-get-group-objC meta-list))
1133 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3))))
1134 (insert "*** Directory A: " dir1 "\n")
1135 (if dir2 (insert "*** Directory B: " dir2 "\n"))
1136 (if dir3 (insert "*** Directory C: " dir3 "\n"))
1139 (defun ediff-draw-dir-diffs (diff-list &optional buf-name)
1140 (if (null diff-list) (error "Lost difference info on these directories"))
1143 (ediff-unique-buffer-name "*Ediff File Group Differences" "*")))
1144 (let* ((regexp (ediff-get-group-regexp diff-list))
1145 (dir1 (ediff-abbreviate-file-name (ediff-get-group-objA diff-list)))
1146 (dir2 (ediff-abbreviate-file-name (ediff-get-group-objB diff-list)))
1147 (dir3 (ediff-get-group-objC diff-list))
1148 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3)))
1149 (meta-buf (ediff-get-group-buffer diff-list))
1150 (underline (make-string 26 ?-))
1151 file membership-code saved-point
1153 ;; skip the directory part
1154 (setq diff-list (cdr diff-list))
1155 (setq ediff-dir-diffs-buffer (get-buffer-create buf-name))
1156 (ediff-with-current-buffer ediff-dir-diffs-buffer
1157 (setq saved-point (point))
1158 (use-local-map ediff-dir-diffs-buffer-map)
1160 (setq ediff-meta-buffer meta-buf)
1161 (insert "\t\t*** Directory Differences ***\n")
1164 C,button2: over file name -- copy this file to directory that doesn't have it
1167 p,DEL: previous line\n\n")
1169 (insert (format "\n*** Directory A: %s\n" dir1))
1170 (if dir2 (insert (format "*** Directory B: %s\n" dir2)))
1171 (if dir3 (insert (format "*** Directory C: %s\n" dir3)))
1172 (if (and (stringp regexp) (> (length regexp) 0))
1174 (format "*** Filter-through regular expression: %s\n" regexp)))
1176 (insert (format "\n%-27s%-26s" "Directory A" "Directory B"))
1178 (insert (format " %-25s\n" "Directory C"))
1180 (insert (format "%s%s" underline underline))
1182 (insert (format "%s\n\n" underline))
1185 (if (null diff-list)
1186 (insert "\n\t*** No differences ***\n"))
1189 (setq file (car (car diff-list))
1190 membership-code (cdr (car diff-list))
1191 diff-list (cdr diff-list))
1192 (if (= (mod membership-code ediff-membership-code1) 0) ; dir1
1193 (let ((beg (point)))
1194 (insert (format "%-27s"
1195 (ediff-truncate-string-left
1196 (ediff-abbreviate-file-name
1197 (if (file-directory-p (concat dir1 file))
1198 (file-name-as-directory file)
1201 ;; format of meta info in the dir-diff-buffer:
1202 ;; (filename-tail filename-full otherdir1 otherdir2 otherdir3)
1203 (ediff-set-meta-overlay
1205 (list meta-buf file (concat dir1 file) dir1 dir2 dir3)))
1206 (insert (format "%-27s" "---")))
1207 (if (= (mod membership-code ediff-membership-code2) 0) ; dir2
1208 (let ((beg (point)))
1209 (insert (format "%-26s"
1210 (ediff-truncate-string-left
1211 (ediff-abbreviate-file-name
1212 (if (file-directory-p (concat dir2 file))
1213 (file-name-as-directory file)
1216 (ediff-set-meta-overlay
1218 (list meta-buf file (concat dir2 file) dir1 dir2 dir3)))
1219 (insert (format "%-26s" "---")))
1221 (if (= (mod membership-code ediff-membership-code3) 0) ; dir3
1222 (let ((beg (point)))
1223 (insert (format " %-25s"
1224 (ediff-truncate-string-left
1225 (ediff-abbreviate-file-name
1226 (if (file-directory-p (concat dir3 file))
1227 (file-name-as-directory file)
1230 (ediff-set-meta-overlay
1232 (list meta-buf file (concat dir3 file) dir1 dir2 dir3)))
1233 (insert (format " %-25s" "---"))))
1235 (setq buffer-read-only t)
1236 (set-buffer-modified-p nil)
1237 (goto-char saved-point)) ; end eval in diff buffer
1240 (defun ediff-bury-dir-diffs-buffer ()
1241 "Bury the directory difference buffer. Display the meta buffer instead."
1243 ;; ediff-meta-buffer is set in ediff-draw-dir-diffs so the directory
1244 ;; difference buffer remembers the meta buffer
1245 (let ((buf ediff-meta-buffer)
1247 (ediff-kill-buffer-carefully ediff-dir-diffs-buffer)
1248 (if (setq wind (ediff-get-visible-buffer-window buf))
1249 (select-window wind)
1250 (set-window-buffer (selected-window) buf))))
1252 ;; executes in dir session group buffer
1253 ;; show buffer differences
1254 (defun ediff-show-dir-diffs ()
1255 "Display differences among the directories involved in session group."
1257 (if (ediff-one-filegroup-metajob)
1258 (error "This command is inapplicable in the present context"))
1259 (or (ediff-buffer-live-p ediff-dir-diffs-buffer)
1260 (ediff-draw-dir-diffs ediff-dir-difference-list))
1261 (let ((buf ediff-dir-diffs-buffer))
1263 (set-window-buffer (selected-window) buf)
1264 (goto-char (point-min))))
1266 ;; Format of meta info in dir-diff-buffer:
1267 ;; (filename-tail filename-full otherdir1 otherdir2)
1268 (defun ediff-dir-diff-copy-file ()
1269 "Copy file described at point to directories where this file is missing."
1271 (let* ((pos (ediff-event-point last-command-event))
1272 (info (ediff-get-meta-info (current-buffer) pos 'noerror))
1273 (meta-buf (car info))
1274 (file-tail (nth 1 info))
1275 (file-abs (nth 2 info))
1276 (otherdir1 (nth 3 info))
1277 (otherfile1 (if otherdir1 (concat otherdir1 file-tail)))
1278 (otherdir2 (nth 4 info))
1279 (otherfile2 (if otherdir2 (concat otherdir2 file-tail)))
1280 (otherdir3 (nth 5 info))
1281 (otherfile3 (if otherdir3 (concat otherdir3 file-tail)))
1282 meta-list dir-diff-list
1285 (error "No file suitable for copying described at this location"))
1286 (ediff-with-current-buffer meta-buf
1287 (setq meta-list ediff-meta-list
1288 dir-diff-list ediff-dir-difference-list))
1290 ;; copy file to directories where it doesn't exist, update
1291 ;; ediff-dir-difference-list and redisplay
1293 (lambda (otherfile-struct)
1294 (let ((otherfile (car otherfile-struct))
1295 (file-mem-code (cdr otherfile-struct)))
1297 (or (file-exists-p otherfile)
1299 (format "Copy %s to %s ? " file-abs otherfile))
1300 (let* ((file-diff-record (assoc file-tail dir-diff-list))
1302 (* (cdr file-diff-record) file-mem-code)))
1303 (copy-file file-abs otherfile)
1304 (setcdr file-diff-record new-mem-code)
1305 (ediff-draw-dir-diffs dir-diff-list (buffer-name))
1307 ;; if file is in all three dirs or in two dirs and only
1308 ;; two dirs are involved, delete this file's record
1309 (if (or (= new-mem-code ediff-product-of-memcodes)
1310 (and (> new-mem-code ediff-membership-code3)
1312 (delq file-diff-record dir-diff-list))
1315 ;; 2,3,5 are numbers used to encode membership of a file in
1316 ;; dir1/2/3. See ediff-intersect-directories.
1317 (list (cons otherfile1 2) (cons otherfile2 3) (cons otherfile3 5)))
1319 (if (and (file-exists-p otherfile1)
1320 (file-exists-p otherfile2)
1321 (or (not otherfile3) (file-exists-p otherfile3)))
1322 ;; update ediff-meta-list by direct modification
1324 (list (ediff-make-new-meta-list-element
1325 otherfile1 otherfile2 otherfile3)))
1327 (ediff-update-meta-buffer meta-buf 'must-redraw)
1330 (defun ediff-up-meta-hierarchy ()
1331 "Go to the parent session group buffer."
1333 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1334 (ediff-show-meta-buffer
1335 ediff-parent-meta-buffer ediff-meta-session-number)
1336 (error "This session group has no parent")))
1339 ;; argument is ignored
1340 (defun ediff-redraw-registry-buffer (&optional ignore)
1341 (ediff-with-current-buffer ediff-registry-buffer
1342 (let ((point (point))
1343 elt bufAname bufBname bufCname cur-diff total-diffs pt
1344 job-name meta-list registry-list buffer-read-only)
1346 ;; delete phony overlays that used to represent sessions before the buff
1348 (ediff-cond-compile-for-xemacs-or-emacs
1349 (map-extents 'delete-extent) ; xemacs
1350 (mapcar 'delete-overlay (overlays-in 1 1)) ; emacs
1353 (insert "This is a registry of all active Ediff sessions.
1356 button2, `v', RET over a session record: switch to that session
1357 M over a session record: display the associated session group
1358 R in any Ediff session: display session registry
1360 p,DEL: previous session
1361 E: browse Ediff on-line manual
1365 \t\tActive Ediff Sessions:
1366 \t\t----------------------
1369 ;; purge registry list from dead buffers
1370 (mapcar (lambda (elt)
1371 (if (not (ediff-buffer-live-p elt))
1372 (setq ediff-session-registry
1373 (delq elt ediff-session-registry))))
1374 ediff-session-registry)
1376 (if (null ediff-session-registry)
1377 (insert " ******* No active Ediff sessions *******\n"))
1379 (setq registry-list ediff-session-registry)
1380 (while registry-list
1381 (setq elt (car registry-list)
1382 registry-list (cdr registry-list))
1384 (if (ediff-buffer-live-p elt)
1385 (if (ediff-with-current-buffer elt
1386 (setq job-name ediff-metajob-name
1387 meta-list ediff-meta-list)
1388 (and ediff-metajob-name
1389 (not (eq ediff-metajob-name 'ediff-registry))))
1392 (insert (format " *group*\t%s: %s\n"
1394 (ediff-abbrev-jobname job-name)))
1395 (insert (format "\t\t %s %s %s\n"
1396 (ediff-abbreviate-file-name
1397 (ediff-get-group-objA meta-list))
1398 (ediff-abbreviate-file-name
1400 (ediff-get-group-objB meta-list))
1401 (ediff-get-group-objB meta-list)
1403 (ediff-abbreviate-file-name
1405 (ediff-get-group-objC meta-list))
1406 (ediff-get-group-objC meta-list)
1408 (ediff-set-meta-overlay pt (point) elt))
1410 (ediff-with-current-buffer elt
1411 (setq bufAname (if (ediff-buffer-live-p ediff-buffer-A)
1412 (buffer-name ediff-buffer-A)
1413 "!!!killed buffer!!!")
1414 bufBname (if (ediff-buffer-live-p ediff-buffer-B)
1415 (buffer-name ediff-buffer-B)
1416 "!!!killed buffer!!!")
1417 bufCname (cond ((not (ediff-3way-job))
1419 ((ediff-buffer-live-p ediff-buffer-C)
1420 (buffer-name ediff-buffer-C))
1421 (t "!!!killed buffer!!!")))
1422 (setq total-diffs (format "%-4d" ediff-number-of-differences)
1424 (cond ((= ediff-current-difference -1) " _")
1425 ((= ediff-current-difference
1426 ediff-number-of-differences)
1429 "%4d" (1+ ediff-current-difference))))
1430 job-name ediff-job-name))
1431 ;; back in the meta buf
1433 (insert cur-diff "/" total-diffs "\t"
1435 (format ": %s" (ediff-abbrev-jobname job-name)))
1437 "\n\t\t " bufAname " " bufBname " " bufCname "\n")
1438 (ediff-set-meta-overlay pt (point) elt))))
1440 (set-buffer-modified-p nil)
1444 ;; Sets overlay around a meta record with 'ediff-meta-info property PROP
1445 ;; If optional SESSION-NUMBER, make it a property of the overlay,
1446 ;; ediff-meta-session-number
1447 ;; PROP is either the ctl or meta buffer (used when we work with the registry)
1448 ;; or a session meta descriptor of the form
1449 ;; (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
1450 (defun ediff-set-meta-overlay (b e prop &optional session-number hidden)
1452 (setq overl (ediff-make-overlay b e))
1454 (ediff-overlay-put overl 'mouse-face 'highlight)
1455 (ediff-overlay-put overl 'highlight t))
1456 (ediff-overlay-put overl 'ediff-meta-info prop)
1457 (ediff-overlay-put overl 'invisible hidden)
1458 (if (numberp session-number)
1459 (ediff-overlay-put overl 'ediff-meta-session-number session-number))))
1461 (defun ediff-mark-for-hiding-at-pos (unmark)
1462 "Mark session for hiding. With prefix arg, unmark."
1464 (let* ((pos (ediff-event-point last-command-event))
1465 (meta-buf (ediff-event-buffer last-command-event))
1466 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1467 (info (ediff-get-meta-info meta-buf pos))
1468 (session-number (ediff-get-session-number-at-pos pos)))
1469 (ediff-mark-session-for-hiding info unmark)
1470 (ediff-next-meta-item 1)
1472 (ediff-update-meta-buffer meta-buf nil session-number))
1475 ;; Returns whether session was marked or unmarked
1476 (defun ediff-mark-session-for-hiding (info unmark)
1477 (let ((session-buf (ediff-get-session-buffer info))
1479 (cond ((eq unmark 'mark) (setq unmark nil))
1480 ((eq (ediff-get-session-status info) ?H) (setq unmark t))
1481 (unmark ; says unmark, but the marker is different from H
1484 (unmark (ediff-set-session-status info nil))
1485 ;;; (if (ediff-buffer-live-p session-buf)
1486 ;;; (error "Can't hide active session, %s" (buffer-name session-buf)))
1487 (t (ediff-set-session-status info ?H))))
1491 (defun ediff-mark-for-operation-at-pos (unmark)
1492 "Mark session for a group operation. With prefix arg, unmark."
1494 (let* ((pos (ediff-event-point last-command-event))
1495 (meta-buf (ediff-event-buffer last-command-event))
1496 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1497 (info (ediff-get-meta-info meta-buf pos))
1498 (session-number (ediff-get-session-number-at-pos pos)))
1499 (ediff-mark-session-for-operation info unmark)
1500 (ediff-next-meta-item 1)
1502 (ediff-update-meta-buffer meta-buf nil session-number))
1506 ;; returns whether session was unmarked.
1507 ;; remember: this is a toggle op
1508 (defun ediff-mark-session-for-operation (info unmark)
1510 (cond ((eq unmark 'mark) (setq unmark nil))
1511 ((eq (ediff-get-session-status info) ?*) (setq unmark t))
1512 (unmark ; says unmark, but the marker is different from *
1515 (unmark (ediff-set-session-status info nil))
1516 (t (ediff-set-session-status info ?*))))
1520 (defun ediff-hide-marked-sessions (unhide)
1521 "Hide marked sessions. With prefix arg, unhide."
1523 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1524 (meta-list (cdr ediff-meta-list))
1525 (from (if unhide ?I ?H))
1526 (to (if unhide ?H ?I))
1528 active-sessions-exist session-buf elt)
1530 (setq elt (car meta-list)
1531 meta-list (cdr meta-list)
1532 session-buf (ediff-get-session-buffer elt))
1534 (if (eq (ediff-get-session-status elt) from)
1536 (setq numMarked (1+ numMarked))
1537 (if (and (eq to ?I) (buffer-live-p session-buf))
1538 ;; shouldn't hide active sessions
1539 (setq active-sessions-exist t)
1540 (ediff-set-session-status elt to)))))
1542 (ediff-update-meta-buffer grp-buf 'must-redraw)
1545 (message "Nothing to reveal...")
1546 (message "Nothing to hide...")))
1547 (if active-sessions-exist
1548 (message "Note: Ediff didn't hide active sessions!"))
1551 ;; Apply OPERATION to marked sessions. Operation expects one argument of type
1552 ;; meta-list member (not the first one), i.e., a regular session description.
1553 ;; Returns number of marked sessions on which operation was performed
1554 (defun ediff-operate-on-marked-sessions (operation)
1555 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1556 (meta-list (cdr ediff-meta-list))
1560 (diff-buffer ediff-meta-diff-buffer)
1563 (setq elt (car meta-list)
1564 meta-list (cdr meta-list)
1565 sessionNum (1+ sessionNum))
1566 (cond ((eq (ediff-get-session-status elt) marksym)
1568 (setq numMarked (1+ numMarked))
1569 (funcall operation elt sessionNum)))
1570 ;; The following goes into a session represented by a subdirectory
1571 ;; and applies operation to marked sessions there
1572 ((and (ediff-meta-session-p elt)
1573 (ediff-buffer-live-p
1574 (setq session-buf (ediff-get-session-buffer elt))))
1577 (ediff-with-current-buffer session-buf
1578 ;; pass meta-diff along
1579 (setq ediff-meta-diff-buffer diff-buffer)
1580 ;; collect diffs in child group
1581 (ediff-operate-on-marked-sessions operation)))))))
1582 (ediff-update-meta-buffer grp-buf 'must-redraw) ; just in case
1586 (defun ediff-append-custom-diff (session sessionNum)
1587 (or (ediff-collect-diffs-metajob)
1588 (error "Can't compute multifile patch in this context"))
1589 (let ((session-buf (ediff-get-session-buffer session))
1590 (meta-diff-buff ediff-meta-diff-buffer)
1591 (metajob ediff-metajob-name)
1592 tmp-buf custom-diff-buf)
1593 (if (ediff-buffer-live-p session-buf)
1594 (ediff-with-current-buffer session-buf
1595 (if (eq ediff-control-buffer session-buf) ; individual session
1597 (ediff-compute-custom-diffs-maybe)
1598 (setq custom-diff-buf ediff-custom-diff-buffer)))))
1600 (or (ediff-buffer-live-p meta-diff-buff)
1601 (error "Ediff: something wrong--killed multiple diff's buffer"))
1603 (cond ((ediff-buffer-live-p custom-diff-buf)
1604 ;; for live session buffers we do them first because the user may
1605 ;; have changed them with respect to the underlying files
1607 (set-buffer meta-diff-buff)
1608 (goto-char (point-max))
1609 (insert-buffer custom-diff-buf)
1611 ;; if ediff session is not live, run diff directly on the files
1612 ((memq metajob '(ediff-directories
1613 ediff-merge-directories
1614 ediff-merge-directories-with-ancestor))
1615 ;; get diffs by calling shell command on ediff-custom-diff-program
1617 (set-buffer (setq tmp-buf (get-buffer-create ediff-tmp-buffer)))
1620 (format "%s %s %s %s"
1621 ediff-custom-diff-program ediff-custom-diff-options
1622 (ediff-get-session-objA-name session)
1623 (ediff-get-session-objB-name session))
1626 (set-buffer meta-diff-buff)
1627 (goto-char (point-max))
1628 (insert-buffer tmp-buf)
1631 (ediff-kill-buffer-carefully meta-diff-buff)
1632 (error "Session %d compares versions of file. Such session must be active to enable multifile patch collection" sessionNum )))
1635 (defun ediff-collect-custom-diffs ()
1636 "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'.
1637 This operation is defined only for `ediff-directories' and
1638 `ediff-directory-revisions', since its intent is to produce
1639 multifile patches. For `ediff-directory-revisions', we insist that
1640 all marked sessions must be active."
1642 (or (ediff-buffer-live-p ediff-meta-diff-buffer)
1643 (setq ediff-meta-diff-buffer
1645 (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
1646 (ediff-with-current-buffer ediff-meta-diff-buffer
1647 (setq buffer-read-only nil)
1649 (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
1652 (display-buffer ediff-meta-diff-buffer 'not-this-window)
1653 (ediff-with-current-buffer ediff-meta-diff-buffer
1654 (set-buffer-modified-p nil)
1655 (setq buffer-read-only t)))
1657 (message "No marked sessions found")))
1659 (defun ediff-meta-show-patch ()
1660 "Show the multi-file patch associated with this group session."
1662 (let* ((pos (ediff-event-point last-command-event))
1663 (meta-buf (ediff-event-buffer last-command-event))
1664 (info (ediff-get-meta-info meta-buf pos 'noerror))
1665 (patchbuffer ediff-meta-patchbufer))
1666 (if (ediff-buffer-live-p patchbuffer)
1667 (ediff-with-current-buffer patchbuffer
1672 (ediff-get-session-objB-name info)
1673 (ediff-get-session-objC-name info)))
1674 (set-buffer (get-buffer-create ediff-tmp-buffer))
1676 (insert-buffer patchbuffer)
1677 (display-buffer ediff-tmp-buffer 'not-this-window)
1679 (error "The patch buffer wasn't found"))))
1682 ;; This function executes in meta buffer. It knows where event happened.
1683 (defun ediff-filegroup-action ()
1684 "Execute appropriate action for a selected session."
1686 (let* ((pos (ediff-event-point last-command-event))
1687 (meta-buf (ediff-event-buffer last-command-event))
1688 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1689 (info (ediff-get-meta-info meta-buf pos))
1690 (session-buf (ediff-get-session-buffer info))
1691 (session-number (ediff-get-session-number-at-pos pos meta-buf))
1692 merge-autostore-dir file1 file2 file3 regexp)
1694 (setq file1 (ediff-get-session-objA-name info)
1695 file2 (ediff-get-session-objB-name info)
1696 file3 (ediff-get-session-objC-name info))
1698 ;; make sure we don't start on hidden sessions
1699 ;; ?H means marked for hiding. ?I means invalid (hidden).
1700 (if (memq (ediff-get-session-status info) '(?I))
1703 (if (y-or-n-p "This session is marked as hidden, unmark? ")
1705 (ediff-set-session-status info nil)
1706 (ediff-update-meta-buffer meta-buf nil session-number))
1707 (error "Aborted"))))
1709 (ediff-with-current-buffer meta-buf
1710 (setq merge-autostore-dir
1711 (ediff-get-group-merge-autostore-dir ediff-meta-list))
1712 (goto-char pos) ; if the user clicked on session--move point there
1713 ;; First handle sessions involving directories (which are themselves
1715 ;; After that handle individual sessions
1716 (cond ((ediff-meta-session-p info)
1717 ;; do ediff/ediff-merge on subdirectories
1718 (if (ediff-buffer-live-p session-buf)
1719 (ediff-show-meta-buffer session-buf)
1720 (setq regexp (read-string "Filter through regular expression: "
1721 nil 'ediff-filtering-regexp-history))
1722 (ediff-directories-internal
1723 file1 file2 file3 regexp
1724 ediff-session-action-function
1726 ;; make it update (car info) after startup
1728 ;; child session group should know its parent
1729 (setq ediff-parent-meta-buffer
1730 (quote ,ediff-meta-buffer)
1731 ediff-meta-session-number
1733 ;; and parent will know its child
1734 (setcar (quote ,info) ediff-meta-buffer))))))
1736 ;; Do ediff-revision on a subdirectory
1737 ((and (ediff-one-filegroup-metajob)
1738 (ediff-revision-metajob)
1739 (file-directory-p file1))
1740 (if (ediff-buffer-live-p session-buf)
1741 (ediff-show-meta-buffer session-buf)
1742 (setq regexp (read-string "Filter through regular expression: "
1743 nil 'ediff-filtering-regexp-history))
1744 (ediff-directory-revisions-internal
1746 ediff-session-action-function ediff-metajob-name
1747 ;; make it update (car info) after startup
1749 ;; child session group should know its parent and
1751 (setq ediff-parent-meta-buffer
1752 (quote ,ediff-meta-buffer)
1753 ediff-meta-session-number
1755 ;; and parent will know its child
1756 (setcar (quote ,info) ediff-meta-buffer))))))
1758 ;; From here on---only individual session handlers
1760 ;; handle an individual session with a live control buffer
1761 ((ediff-buffer-live-p session-buf)
1762 (ediff-with-current-buffer session-buf
1763 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1764 (ediff-recenter 'no-rehighlight)))
1766 ((ediff-problematic-session-p info)
1769 "This session has no ancestor. Merge without the ancestor? ")
1772 ;; provide startup hooks
1775 'ediff-after-quit-hook-internal
1777 (if (ediff-buffer-live-p ,(current-buffer))
1778 (ediff-show-meta-buffer
1779 ,(current-buffer) ,session-number)))
1781 (setq ediff-meta-buffer ,(current-buffer)
1782 ediff-meta-session-number
1784 (setq ediff-merge-store-file
1785 ,(if (ediff-nonempty-string-p
1786 merge-autostore-dir)
1789 ediff-merge-filename-prefix
1790 (file-name-nondirectory file1))
1792 ;; make ediff-startup pass
1793 ;; ediff-control-buffer back to the meta
1796 (quote ,info) ediff-control-buffer))))
1798 ((ediff-one-filegroup-metajob) ; needs 1 file arg
1799 (funcall ediff-session-action-function
1801 ;; provide startup hooks
1804 'ediff-after-quit-hook-internal
1806 (if (ediff-buffer-live-p
1808 (ediff-show-meta-buffer
1812 (setq ediff-meta-buffer ,(current-buffer)
1813 ediff-meta-session-number
1815 (setq ediff-merge-store-file
1816 ,(if (ediff-nonempty-string-p
1817 merge-autostore-dir)
1820 ediff-merge-filename-prefix
1821 (file-name-nondirectory file1))) )
1822 ;; make ediff-startup pass
1823 ;; ediff-control-buffer back to the meta
1826 (quote ,info) ediff-control-buffer)))))
1827 ((not (ediff-metajob3)) ; need 2 file args
1828 (funcall ediff-session-action-function
1830 ;; provide startup hooks
1833 'ediff-after-quit-hook-internal
1835 (if (ediff-buffer-live-p
1837 (ediff-show-meta-buffer
1841 (setq ediff-meta-buffer ,(current-buffer)
1842 ediff-meta-session-number
1844 (setq ediff-merge-store-file
1845 ,(if (ediff-nonempty-string-p
1846 merge-autostore-dir)
1849 ediff-merge-filename-prefix
1850 (file-name-nondirectory file1))) )
1851 ;; make ediff-startup pass
1852 ;; ediff-control-buffer back to the meta
1855 (quote ,info) ediff-control-buffer)))))
1856 ((ediff-metajob3) ; need 3 file args
1857 (funcall ediff-session-action-function
1859 ;; arrange startup hooks
1862 'ediff-after-quit-hook-internal
1864 (if (ediff-buffer-live-p
1866 (ediff-show-meta-buffer
1870 (setq ediff-merge-store-file
1871 ,(if (ediff-nonempty-string-p
1872 merge-autostore-dir)
1875 ediff-merge-filename-prefix
1876 (file-name-nondirectory file1))) )
1877 (setq ediff-meta-buffer , (current-buffer)
1878 ediff-meta-session-number
1880 ;; this arranges that ediff-startup will pass
1881 ;; the value of ediff-control-buffer back to
1882 ;; the meta level, to the record in the meta
1883 ;; list containing the information about the
1884 ;; session associated with that
1885 ;; ediff-control-buffer
1887 (quote ,info) ediff-control-buffer)))))
1889 ) ; eval in meta-buf
1892 (defun ediff-registry-action ()
1893 "Switch to a selected session."
1895 (let* ((pos (ediff-event-point last-command-event))
1896 (buf (ediff-event-buffer last-command-event))
1897 (ctl-buf (ediff-get-meta-info buf pos)))
1899 (if (ediff-buffer-live-p ctl-buf)
1900 ;; check if this is ediff-control-buffer or ediff-meta-buffer
1901 (if (ediff-with-current-buffer ctl-buf
1902 (eq (key-binding "q") 'ediff-quit-meta-buffer))
1903 ;; it's a meta-buffer -- last action should just display it
1904 (ediff-show-meta-buffer ctl-buf t)
1905 ;; it's a session buffer -- invoke go back to session
1906 (ediff-with-current-buffer ctl-buf
1907 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1908 (ediff-recenter 'no-rehighlight)))
1910 (message "You've selected a stale session --- try again")
1911 (ediff-update-registry))
1912 (ediff-with-current-buffer buf
1917 ;; If session number is t, means don't update meta buffer
1918 (defun ediff-show-meta-buffer (&optional meta-buf session-number)
1919 "Show the session group buffer."
1921 (run-hooks 'ediff-before-directory-setup-hooks)
1922 (let (wind frame silent)
1923 (if meta-buf (setq silent t))
1925 (setq meta-buf (or meta-buf ediff-meta-buffer))
1926 (cond ((not (bufferp meta-buf))
1927 (error "This Ediff session is not part of a session group"))
1928 ((not (ediff-buffer-live-p meta-buf))
1930 "Can't find this session's group panel -- session itself is ok")))
1932 (cond ((numberp session-number)
1933 (ediff-update-meta-buffer meta-buf nil session-number))
1934 ;; if session-number is t, don't update
1936 (t (ediff-cleanup-meta-buffer meta-buf)))
1938 (ediff-with-current-buffer meta-buf
1940 (cond ((setq wind (ediff-get-visible-buffer-window meta-buf))
1943 "Already showing the group panel for this session"))
1944 (set-window-buffer wind meta-buf)
1945 (select-window wind))
1946 ((window-live-p (setq wind ediff-window-C)) ;in merge--merge buf
1947 (set-window-buffer ediff-window-C meta-buf)
1948 (select-window wind))
1949 ((window-live-p (setq wind ediff-window-A))
1950 (set-window-buffer ediff-window-A meta-buf)
1951 (select-window wind))
1952 ((window-live-p (setq wind ediff-window-B))
1953 (set-window-buffer ediff-window-B meta-buf)
1954 (select-window wind))
1957 (ediff-get-visible-buffer-window ediff-registry-buffer))
1958 (ediff-window-display-p))
1959 (select-window wind)
1961 (set-window-buffer (selected-window) meta-buf))
1962 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1963 (set-window-buffer (selected-window) meta-buf)))
1965 (if (and (ediff-window-display-p)
1967 (setq wind (ediff-get-visible-buffer-window meta-buf))))
1969 (setq frame (window-frame wind))
1971 (ediff-reset-mouse frame)))
1972 (sit-for 0) ; sometimes needed to synch the display and ensure that the
1973 ; point ends up after the just completed session
1974 (run-hooks 'ediff-show-session-group-hook)
1977 (defun ediff-show-current-session-meta-buffer ()
1979 (ediff-show-meta-buffer nil ediff-meta-session-number))
1981 (defun ediff-show-meta-buff-from-registry ()
1982 "Display the session group buffer for a selected session group."
1984 (let* ((pos (ediff-event-point last-command-event))
1985 (meta-buf (ediff-event-buffer last-command-event))
1986 (info (ediff-get-meta-info meta-buf pos))
1987 (meta-or-session-buf info))
1988 (ediff-with-current-buffer meta-or-session-buf
1989 (ediff-show-meta-buffer nil t))))
1992 (defun ediff-show-registry ()
1993 "Display Ediff's registry."
1995 (ediff-update-registry)
1996 (if (not (ediff-buffer-live-p ediff-registry-buffer))
1997 (error "No active Ediff sessions or corrupted session registry"))
1999 ;; for some reason, point moves in ediff-registry-buffer, so we preserve it
2001 (ediff-with-current-buffer ediff-registry-buffer
2004 (ediff-get-visible-buffer-window ediff-registry-buffer))
2005 (message "Already showing the registry")
2006 (set-window-buffer wind ediff-registry-buffer)
2007 (select-window wind))
2008 ((window-live-p ediff-window-C)
2009 (set-window-buffer ediff-window-C ediff-registry-buffer)
2010 (select-window ediff-window-C))
2011 ((window-live-p ediff-window-A)
2012 (set-window-buffer ediff-window-A ediff-registry-buffer)
2013 (select-window ediff-window-A))
2014 ((window-live-p ediff-window-B)
2015 (set-window-buffer ediff-window-B ediff-registry-buffer)
2016 (select-window ediff-window-B))
2018 (ediff-get-visible-buffer-window ediff-meta-buffer))
2019 (ediff-window-display-p))
2020 (select-window wind)
2022 (set-window-buffer (selected-window) ediff-registry-buffer))
2023 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
2024 (set-window-buffer (selected-window) ediff-registry-buffer)))
2026 (if (ediff-window-display-p)
2030 (ediff-get-visible-buffer-window ediff-registry-buffer)))
2032 (ediff-reset-mouse frame)))
2033 (run-hooks 'ediff-show-registry-hook)
2037 (defalias 'eregistry 'ediff-show-registry)
2039 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a
2041 ;; Check if META-BUF exists before calling this function
2042 ;; Optional MUST-REDRAW, if non-nil, would force redrawal of the whole meta
2043 ;; buffer. Otherwise, it will just go over the buffer and update activity marks
2044 ;; and session status.
2045 ;; SESSION-NUMBER, if specified, says which session caused the update.
2046 (defun ediff-update-meta-buffer (meta-buf &optional must-redraw session-number)
2047 (if (ediff-buffer-live-p meta-buf)
2048 (ediff-with-current-buffer meta-buf
2050 (cond (must-redraw ; completely redraw the meta buffer
2051 (funcall ediff-meta-redraw-function ediff-meta-list))
2052 ((numberp session-number) ; redraw only for the given session
2053 (ediff-update-session-marker-in-dir-meta-buffer
2055 (t ; update what changed only, but scan the entire meta buffer
2056 (ediff-update-markers-in-dir-meta-buffer ediff-meta-list)))
2057 (setq overl (ediff-get-meta-overlay-at-pos (point)))
2058 ;; skip the invisible sessions
2059 (while (and overl (ediff-overlay-get overl 'invisible))
2060 (ediff-next-meta-item1)
2061 (setq overl (ediff-get-meta-overlay-at-pos (point))))
2064 (defun ediff-update-registry ()
2065 (ediff-with-current-buffer (current-buffer)
2066 (if (ediff-buffer-live-p ediff-registry-buffer)
2067 (ediff-redraw-registry-buffer)
2068 (ediff-prepare-meta-buffer
2069 'ediff-registry-action
2070 ediff-session-registry
2072 'ediff-redraw-registry-buffer
2076 ;; If meta-buf exists, it is redrawn along with parent.
2077 ;; Otherwise, nothing happens.
2078 (defun ediff-cleanup-meta-buffer (meta-buffer)
2079 (if (ediff-buffer-live-p meta-buffer)
2080 (ediff-with-current-buffer meta-buffer
2081 (ediff-update-meta-buffer meta-buffer)
2082 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
2083 (ediff-update-meta-buffer
2084 ediff-parent-meta-buffer nil ediff-meta-session-number)))))
2086 ;; t if no session is in progress
2087 (defun ediff-safe-to-quit (meta-buffer)
2088 (if (ediff-buffer-live-p meta-buffer)
2089 (let ((lis ediff-meta-list)
2092 ;;(ediff-update-meta-buffer meta-buffer)
2093 (ediff-with-current-buffer meta-buffer
2094 (setq lis (cdr lis)) ; discard the description part of meta-list
2095 (while (and cont lis)
2096 (if (ediff-buffer-live-p
2097 (ediff-get-group-buffer lis)) ; in progress
2099 (setq lis (cdr lis)))
2102 (defun ediff-quit-meta-buffer ()
2103 "If the group has no active session, delete the meta buffer.
2104 If no session is in progress, ask to confirm before deleting meta buffer.
2105 Otherwise, bury the meta buffer.
2106 If this is a session registry buffer then just bury it."
2108 (let* ((buf (current-buffer))
2109 (dir-diffs-buffer ediff-dir-diffs-buffer)
2110 (meta-diff-buffer ediff-meta-diff-buffer)
2111 (session-number ediff-meta-session-number)
2112 (parent-buf ediff-parent-meta-buffer)
2113 (dont-show-registry (eq buf ediff-registry-buffer)))
2114 (if dont-show-registry
2116 ;;(ediff-cleanup-meta-buffer buf)
2117 (cond ((and (ediff-safe-to-quit buf)
2118 (y-or-n-p "Quit this session group? "))
2119 (run-hooks 'ediff-quit-session-group-hook)
2121 (ediff-dispose-of-meta-buffer buf))
2122 ((ediff-safe-to-quit buf)
2126 "This session group has active sessions---cannot exit")))
2127 (ediff-update-meta-buffer parent-buf nil session-number)
2128 (ediff-kill-buffer-carefully dir-diffs-buffer)
2129 (ediff-kill-buffer-carefully meta-diff-buffer)
2130 (if (ediff-buffer-live-p parent-buf)
2132 (setq dont-show-registry t)
2133 (ediff-show-meta-buffer parent-buf session-number)))
2135 (or dont-show-registry
2136 (ediff-show-registry))))
2138 (defun ediff-dispose-of-meta-buffer (buf)
2139 (setq ediff-session-registry (delq buf ediff-session-registry))
2140 (ediff-with-current-buffer buf
2141 (if (ediff-buffer-live-p ediff-dir-diffs-buffer)
2142 (kill-buffer ediff-dir-diffs-buffer)))
2146 ;; Obtain information on a meta record where the user clicked or typed
2147 ;; BUF is the buffer where this happened and POINT is the position
2148 ;; If optional NOERROR arg is given, don't report error and return nil if no
2149 ;; meta info is found on line.
2150 (defun ediff-get-meta-info (buf point &optional noerror)
2151 (let (result olist tmp)
2152 (if (and point (ediff-buffer-live-p buf))
2153 (ediff-with-current-buffer buf
2154 (ediff-cond-compile-for-xemacs-or-emacs
2155 (setq result ; xemacs
2156 (if (setq tmp (extent-at point buf 'ediff-meta-info))
2157 (ediff-overlay-get tmp 'ediff-meta-info)))
2159 (setq olist (overlays-at point))
2161 (mapcar (lambda (elt)
2162 (unless (overlay-get elt 'invisible)
2163 (overlay-get elt 'ediff-meta-info)))
2165 (while (and olist (null (car olist)))
2166 (setq olist (cdr olist)))
2167 (setq result (car olist)))
2174 (ediff-update-registry)
2175 (error "No session info in this line")))))
2178 (defun ediff-get-meta-overlay-at-pos (point)
2179 (ediff-cond-compile-for-xemacs-or-emacs
2180 (extent-at point (current-buffer) 'ediff-meta-info) ; xemacs
2182 (let* ((overl-list (overlays-at point))
2183 (overl (car overl-list)))
2184 (while (and overl (null (overlay-get overl 'ediff-meta-info)))
2185 (setq overl-list (cdr overl-list)
2186 overl (car overl-list)))
2191 (defsubst ediff-get-session-number-at-pos (point &optional meta-buffer)
2192 (setq meta-buffer (if (ediff-buffer-live-p meta-buffer)
2195 (ediff-with-current-buffer meta-buffer
2197 (ediff-get-meta-overlay-at-pos point) 'ediff-meta-session-number)))
2200 ;; Return location of the next meta overlay after point
2201 (defun ediff-next-meta-overlay-start (point)
2203 (goto-char (point-min))
2204 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2205 (ediff-cond-compile-for-xemacs-or-emacs
2208 (setq overl (next-extent overl))
2209 (setq overl (next-extent (current-buffer))))
2211 (extent-start-position overl)
2215 ;; note: end of current overlay is the beginning of the next one
2217 (next-overlay-change point))
2223 (defun ediff-previous-meta-overlay-start (point)
2225 (goto-char (point-max))
2226 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2227 (ediff-cond-compile-for-xemacs-or-emacs
2230 (setq overl (previous-extent overl))
2231 (setq overl (previous-extent (current-buffer))))
2233 (extent-start-position overl)
2236 (if overl (setq point (overlay-start overl)))
2237 ;; to get to the beginning of prev overlay
2239 ;; trick to overcome an emacs bug--doesn't always find previous
2240 ;; overlay change correctly
2241 (setq point (1- point)))
2242 (setq point (previous-overlay-change point))
2243 ;; If we are not over an overlay after subtracting 1, it means we are
2244 ;; in the description area preceding session records. In this case,
2245 ;; goto the top of the registry buffer.
2246 (or (car (overlays-at point))
2247 (setq point (point-min)))
2252 ;; this is the action invoked when the user selects a patch from the meta
2254 (defun ediff-patch-file-form-meta (file &optional startup-hooks)
2255 (let* ((pos (ediff-event-point last-command-event))
2256 (meta-buf (ediff-event-buffer last-command-event))
2257 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
2258 (info (ediff-get-meta-info meta-buf pos))
2259 (meta-patchbuf ediff-meta-patchbufer)
2260 session-buf beg-marker end-marker)
2262 (if (or (file-directory-p file) (string-match "/dev/null" file))
2263 (error "`%s' is not an ordinary file" (file-name-as-directory file)))
2264 (setq session-buf (ediff-get-session-buffer info)
2265 beg-marker (ediff-get-session-objB-name info)
2266 end-marker (ediff-get-session-objC-name info))
2268 (or (ediff-buffer-live-p session-buf) ; either an active patch session
2269 (null session-buf) ; or it is a virgin session
2271 "Patch has already been applied to this file -- can't repeat!"))
2273 (ediff-with-current-buffer meta-patchbuf
2276 (narrow-to-region beg-marker end-marker)
2277 (ediff-patch-file-internal meta-patchbuf file startup-hooks)))))
2280 (defun ediff-unmark-all-for-operation ()
2281 "Unmark all sessions marked for operation."
2283 (let ((list (cdr ediff-meta-list))
2285 (while (setq elt (car list))
2286 (ediff-mark-session-for-operation elt 'unmark)
2287 (setq list (cdr list))))
2288 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2290 (defun ediff-unmark-all-for-hiding ()
2291 "Unmark all sessions marked for hiding."
2293 (let ((list (cdr ediff-meta-list))
2295 (while (setq elt (car list))
2296 (ediff-mark-session-for-hiding elt 'unmark)
2297 (setq list (cdr list))))
2298 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2301 ;; ACTION is ?h, ?m, ?=: to mark for hiding, mark for operation, or simply
2302 ;; indicate which are equal files
2303 (defun ediff-meta-mark-equal-files (&optional action)
2304 "Run through the session list and mark identical files.
2305 This is used only for sessions that involve 2 or 3 files at the same time.
2306 ACTION is an optional argument that can be ?h, ?m, ?=, to mark for hiding, mark
2307 for operation, or simply indicate which are equal files. If it is nil, then
2308 last-command-char is used to decide which action to take."
2311 (setq action last-command-char))
2312 (let ((list (cdr ediff-meta-list))
2313 marked1 marked2 marked3
2314 fileinfo1 fileinfo2 fileinfo3 elt)
2315 (message "Comparing files ...")
2316 (while (setq elt (car list))
2317 (setq fileinfo1 (ediff-get-session-objA elt)
2318 fileinfo2 (ediff-get-session-objB elt)
2319 fileinfo3 (ediff-get-session-objC elt))
2320 (ediff-set-file-eqstatus fileinfo1 nil)
2321 (ediff-set-file-eqstatus fileinfo2 nil)
2322 (ediff-set-file-eqstatus fileinfo3 nil)
2327 (or (ediff-mark-if-equal fileinfo1 fileinfo2)
2329 (if (ediff-metajob3)
2331 (or (ediff-mark-if-equal fileinfo1 fileinfo3)
2333 (or (ediff-mark-if-equal fileinfo2 fileinfo3)
2334 (setq marked3 nil))))
2335 (if (and marked1 marked2 marked3)
2336 (cond ((eq action ?h)
2337 (ediff-mark-session-for-hiding elt 'mark))
2339 (ediff-mark-session-for-operation elt 'mark))
2341 (setq list (cdr list)))
2342 (message "Comparing files ... Done"))
2343 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2345 ;; mark files 1 and 2 as equal, if they are.
2346 ;; returns t, if something was marked
2347 (defun ediff-mark-if-equal (fileinfo1 fileinfo2)
2348 (let ((f1 (car fileinfo1))
2349 (f2 (car fileinfo2)))
2350 (cond ((file-directory-p f1) nil)
2351 ((file-directory-p f2) nil)
2352 ((ediff-same-file-contents f1 f2)
2353 (ediff-set-file-eqstatus fileinfo1 t)
2354 (ediff-set-file-eqstatus fileinfo2 t)
2360 ;;; Local Variables:
2361 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
2362 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
2363 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
2366 ;;; ediff-mult.el ends here