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
171 (defvar ediff-filtering-regexp-history nil
"")
173 ;; This has the form ((meta-buf regexp dir1 dir2 dir3 merge-auto-store-dir)
174 ;; (ctl-buf session-status (file1 . eq-status) (file2 . eq-status) (file3
175 ;; . eq-status)) (ctl-buf session-status (file1 . eq-status) (file2
176 ;; . eq-status)) ...)
177 ;; If ctl-buf is nil, the file-pair hasn't processed yet. If it is
178 ;; killed-buffer object, the file pair has been processed. If it is a live
179 ;; buffer, this means ediff is still working on the pair.
180 ;; Eq-status of a file is t if the file equals some other file in the same
182 (ediff-defvar-local ediff-meta-list nil
"")
184 (ediff-defvar-local ediff-meta-session-number nil
"")
187 ;; the difference list between directories in a directory session group
188 (ediff-defvar-local ediff-dir-difference-list nil
"")
189 (ediff-defvar-local ediff-dir-diffs-buffer nil
"")
191 ;; The registry of Ediff sessions. A list of control buffers.
192 (defvar ediff-session-registry nil
)
194 (defcustom ediff-meta-truncate-filenames t
195 "*If non-nil, truncate long file names in the session group buffers.
196 This can be toggled with `ediff-toggle-filename-truncation'."
199 (defcustom ediff-registry-setup-hook nil
200 "*Hooks run just after the registry control panel is set up."
204 (defcustom ediff-before-session-group-setup-hooks nil
205 "*Hooks to run before Ediff arranges the window for group-level operations.
206 It is used by commands such as ediff-directories.
207 This hook can be used to save the previous window config, which can be restored
208 on ediff-quit, ediff-suspend, or ediff-quit-session-group-hook."
211 (defcustom ediff-after-session-group-setup-hook nil
212 "*Hooks run just after a meta-buffer controlling a session group, such as
213 ediff-directories, is run."
216 (defcustom ediff-quit-session-group-hook nil
217 "*Hooks run just before exiting a session group."
220 (defcustom ediff-show-registry-hook nil
221 "*Hooks run just after the registry buffer is shown."
224 (defcustom ediff-show-session-group-hook
'(delete-other-windows)
225 "*Hooks run just after a session group buffer is shown."
228 (defcustom ediff-meta-buffer-keymap-setup-hook nil
229 "*Hooks run just after setting up the ediff-meta-buffer-map.
230 This keymap controls key bindings in the meta buffer and is a local variable.
231 This means that you can set different bindings for different kinds of meta
236 ;; Buffer holding the multi-file patch. Local to the meta buffer
237 (ediff-defvar-local ediff-meta-patchbufer nil
"")
239 ;;; API for ediff-meta-list
241 ;; A meta-list is either ediff-meta-list, which contains a header and the list
242 ;; of ediff sessions or ediff-dir-difference-list, which is a header followed
243 ;; by the list of differences among the directories (i.e., files that are not
244 ;; in all directories). The header is the same in all meta lists, but the rest
246 ;; Structure of the meta-list:
247 ;; (HEADER SESSION1 SESSION2 ...)
248 ;; HEADER: (GROUP-BUF REGEXP OBJA OBJB OBJC SAVE-DIR COMPARISON-FUNC)
249 ;; OBJA - first directory
250 ;; OBJB - second directory
251 ;; OBJC - third directory
252 ;; SESSION1/2/... are described below
253 ;; group buffer/regexp
254 (defsubst ediff-get-group-buffer
(meta-list)
255 (nth 0 (car meta-list
)))
257 (defsubst ediff-get-group-regexp
(meta-list)
258 (nth 1 (car meta-list
)))
260 (defsubst ediff-get-group-objA
(meta-list)
261 (nth 2 (car meta-list
)))
262 (defsubst ediff-get-group-objB
(meta-list)
263 (nth 3 (car meta-list
)))
264 (defsubst ediff-get-group-objC
(meta-list)
265 (nth 4 (car meta-list
)))
266 (defsubst ediff-get-group-merge-autostore-dir
(meta-list)
267 (nth 5 (car meta-list
)))
268 (defsubst ediff-get-group-comparison-func
(meta-list)
269 (nth 6 (car meta-list
)))
271 ;; ELT is a session meta descriptor (what is being preserved as
273 ;; The structure is: (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
274 ;; STATUS is ?I (hidden or invalid), ?* (marked for operation), ?H (hidden)
276 ;; OBJA/B/C is (FILENAME EQSTATUS)
277 ;; EQSTATUS is ?= or nil (?= means that this file is equal to some other
278 ;; file in this session)
280 (defsubst ediff-get-session-buffer
(elt)
282 (defsubst ediff-get-session-status
(elt)
284 (defsubst ediff-set-session-status
(session-info new-status
)
285 (setcar (cdr session-info
) new-status
))
287 (defsubst ediff-get-session-objA
(elt)
289 (defsubst ediff-get-session-objB
(elt)
291 (defsubst ediff-get-session-objC
(elt)
293 ;; Take the "name" component of the object into acount. ObjA/C/B is of the form
294 ;; (name . equality-indicator)
295 (defsubst ediff-get-session-objA-name
(elt)
297 (defsubst ediff-get-session-objB-name
(elt)
299 (defsubst ediff-get-session-objC-name
(elt)
301 ;; equality indicators
302 (defsubst ediff-get-file-eqstatus
(elt)
304 (defsubst ediff-set-file-eqstatus
(elt value
)
305 (setcar (cdr elt
) value
))
307 ;; Create a new element for the meta list out of obj1/2/3, which usually are
310 ;; The first nil in such an element is later replaced with the session buffer.
311 ;; The second nil is reserved for session status.
313 ;; Also, session objects A/B/C are turned into lists of the form (obj nil).
314 ;; This nil is a placeholder for eq-indicator. It is either nil or =.
315 ;; If it is discovered that this file is = to some other
316 ;; file in the same session, eq-indicator is changed to `='.
317 ;; Curently, the eq-indicator is used only for 2 and 3-file jobs.
318 (defun ediff-make-new-meta-list-element (obj1 obj2 obj3
)
319 (list nil nil
(list obj1 nil
) (list obj2 nil
) (list obj3 nil
)))
321 ;; Constructs a meta list header.
322 ;; OBJA, OBJB, OBJC are usually directories involved, but can be different for
323 ;; different jobs. For instance, multifile patch has only OBJA, which is the
325 (defun ediff-make-new-meta-list-header (regexp
329 (list regexp objA objB objC merge-auto-store-dir comparison-func
))
331 ;; The activity marker is either or + (active session, i.e., ediff is currently
332 ;; run in it), or - (finished session, i.e., we've ran ediff in it and then
333 ;; exited). Return nil, if session is neither active nor finished
334 (defun ediff-get-session-activity-marker (session)
335 (let ((session-buf (ediff-get-session-buffer session
)))
336 (cond ((null session-buf
) nil
) ; virgin session
337 ((ediff-buffer-live-p session-buf
) ?
+) ;active session
340 ;; checks if the session is a meta session
341 (defun ediff-meta-session-p (session-info)
342 (and (stringp (ediff-get-session-objA-name session-info
))
343 (file-directory-p (ediff-get-session-objA-name session-info
))
344 (stringp (ediff-get-session-objB-name session-info
))
345 (file-directory-p (ediff-get-session-objB-name session-info
))
346 (if (stringp (ediff-get-session-objC-name session-info
))
347 (file-directory-p (ediff-get-session-objC-name session-info
)) t
)))
349 ;; set up the keymap in the meta buffer
350 (defun ediff-setup-meta-map()
351 (setq ediff-meta-buffer-map
(make-sparse-keymap))
352 (suppress-keymap ediff-meta-buffer-map
)
353 (define-key ediff-meta-buffer-map
"q" 'ediff-quit-meta-buffer
)
354 (define-key ediff-meta-buffer-map
"T" 'ediff-toggle-filename-truncation
)
355 (define-key ediff-meta-buffer-map
"R" 'ediff-show-registry
)
356 (define-key ediff-meta-buffer-map
"E" 'ediff-documentation
)
357 (define-key ediff-meta-buffer-map
"v" ediff-meta-action-function
)
358 (define-key ediff-meta-buffer-map
"\C-m" ediff-meta-action-function
)
359 (define-key ediff-meta-buffer-map
" " 'ediff-next-meta-item
)
360 (define-key ediff-meta-buffer-map
"n" 'ediff-next-meta-item
)
361 (define-key ediff-meta-buffer-map
"\C-?" 'ediff-previous-meta-item
)
362 (define-key ediff-meta-buffer-map
"p" 'ediff-previous-meta-item
)
363 (define-key ediff-meta-buffer-map
[delete] 'ediff-previous-meta-item)
364 (define-key ediff-meta-buffer-map [backspace] 'ediff-previous-meta-item)
365 (or (ediff-one-filegroup-metajob)
367 (define-key ediff-meta-buffer-map "=" nil)
368 (define-key ediff-meta-buffer-map "==" 'ediff-meta-mark-equal-files)
369 (define-key ediff-meta-buffer-map "=m" 'ediff-meta-mark-equal-files)
370 (define-key ediff-meta-buffer-map "=h" 'ediff-meta-mark-equal-files)))
371 (if ediff-no-emacs-help-in-control-buffer
372 (define-key ediff-meta-buffer-map "\C-h" 'ediff-previous-meta-item))
374 (define-key ediff-meta-buffer-map [mouse-2] ediff-meta-action-function)
375 (define-key ediff-meta-buffer-map [button2] ediff-meta-action-function))
377 (use-local-map ediff-meta-buffer-map)
378 ;; modify ediff-meta-buffer-map here
379 (run-hooks 'ediff-meta-buffer-keymap-setup-hook))
382 (defun ediff-meta-mode ()
383 "This mode controls all operations on Ediff session groups.
384 It is entered through one of the following commands:
389 `ediff-merge-directories'
391 `ediff-merge-directories-with-ancestor'
392 `edirs-merge-with-ancestor'
393 `ediff-directory-revisions'
395 `ediff-merge-directory-revisions'
396 `edir-merge-revisions'
397 `ediff-merge-directory-revisions-with-ancestor'
398 `edir-merge-revisions-with-ancestor'
401 \\{ediff-meta-buffer-map}"
402 (kill-all-local-variables)
403 (setq major-mode 'ediff-meta-mode)
404 (setq mode-name "MetaEdiff"))
407 ;; the keymap for the buffer showing directory differences
408 (suppress-keymap ediff-dir-diffs-buffer-map)
409 (define-key ediff-dir-diffs-buffer-map "q" 'ediff-bury-dir-diffs-buffer)
410 (define-key ediff-dir-diffs-buffer-map " " 'next-line)
411 (define-key ediff-dir-diffs-buffer-map "n" 'next-line)
412 (define-key ediff-dir-diffs-buffer-map "\C-?" 'previous-line)
413 (define-key ediff-dir-diffs-buffer-map "p" 'previous-line)
414 (define-key ediff-dir-diffs-buffer-map "C" 'ediff-dir-diff-copy-file)
416 (define-key ediff-dir-diffs-buffer-map [mouse-2] 'ediff-dir-diff-copy-file)
417 (define-key ediff-dir-diffs-buffer-map [button2] 'ediff-dir-diff-copy-file))
418 (define-key ediff-dir-diffs-buffer-map [delete] 'previous-line
)
419 (define-key ediff-dir-diffs-buffer-map
[backspace] 'previous-line)
421 (defun ediff-next-meta-item (count)
422 "Move to the next item in Ediff registry or session group buffer.
423 Moves in circular fashion. With numeric prefix arg, skip this many items."
425 (or count (setq count 1))
428 (setq count (1- count))
429 (ediff-next-meta-item1)
430 (setq overl (ediff-get-meta-overlay-at-pos (point)))
431 ;; skip invisible ones
432 (while (and overl (ediff-overlay-get overl 'invisible))
433 (ediff-next-meta-item1)
434 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
436 ;; Move to the next meta item
437 (defun ediff-next-meta-item1 ()
439 (setq pos (ediff-next-meta-overlay-start (point)))
440 (if pos (goto-char pos))
441 (if (eq ediff-metajob-name 'ediff-registry)
442 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
443 (search-forward "*Ediff" nil t))
444 (skip-chars-backward "a-zA-Z*"))
445 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
446 (backward-char 1)))))
449 (defun ediff-previous-meta-item (count)
450 "Move to the previous item in Ediff registry or session group buffer.
451 Moves in circular fashion. With numeric prefix arg, skip this many items."
453 (or count (setq count 1))
456 (setq count (1- count))
457 (ediff-previous-meta-item1)
458 (setq overl (ediff-get-meta-overlay-at-pos (point)))
459 ;; skip invisible ones
460 (while (and overl (ediff-overlay-get overl 'invisible))
461 (ediff-previous-meta-item1)
462 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
464 (defun ediff-previous-meta-item1 ()
466 (setq pos (ediff-previous-meta-overlay-start (point)))
468 ;;; (while (ediff-get-session-status
469 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
470 ;;; (setq pos (ediff-previous-meta-overlay-start pos)))
472 (if pos (goto-char pos))
473 (if (eq ediff-metajob-name 'ediff-registry)
474 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
475 (search-forward "*Ediff" nil t))
476 (skip-chars-backward "a-zA-Z*"))
477 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
481 (defsubst ediff-add-slash-if-directory (dir file)
482 (if (file-directory-p (concat dir file))
483 (file-name-as-directory file)
486 (defun ediff-toggle-filename-truncation ()
487 "Toggle truncation of long file names in session group buffers.
488 Set `ediff-meta-truncate-filenames' variable if you want to change the default
491 (setq ediff-meta-truncate-filenames (not ediff-meta-truncate-filenames))
492 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
495 ;; These are used to encode membership of files in directory1/2/3
496 ;; Membership code of a file is a product of codes for the directories where
498 (defvar ediff-membership-code1 2)
499 (defvar ediff-membership-code2 3)
500 (defvar ediff-membership-code3 5)
501 (defvar ediff-product-of-memcodes (* ediff-membership-code1
502 ediff-membership-code2
503 ediff-membership-code3))
505 ;; DIR1, DIR2, DIR3 are directories. DIR3 can be nil.
506 ;; OUTPUT-DIR is a directory for auto-storing the results of merge jobs.
508 ;; REGEXP is nil or a filter regexp; only file names that match the regexp
510 ;; If a file is a directory in dir1 but not dir2 (or vice versa), it is not
511 ;; included in the intersection. However, a regular file that is a dir in dir3
512 ;; is included, since dir3 files are supposed to be ancestors for merging.
513 ;; If COMPARISON-FUNC is given, use it. Otherwise, use string=
515 ;; Returns a list of the form:
516 ;; (COMMON-PART DIFF-LIST)
517 ;; COMMON-PART is car and DIFF-LIST is cdr.
519 ;; COMMON-PART is of the form:
520 ;; (META-HEADER (f1 f2 f3) (f1 f2 f3) ...)
521 ;; f3 can be nil if intersecting only 2 directories.
522 ;; Each triple (f1 f2 f3) represents the files to be compared in the
523 ;; corresponding ediff subsession.
525 ;; DIFF-LIST is of the form:
526 ;; (META-HEADER (file . num) (file . num)...)
527 ;; where num encodes the set of dirs where the file is found:
528 ;; 2 - only dir1; 3 - only dir2; 5 - only dir3; 6 - dir1&2; 10 - dir1&3; etc.
530 ;; Contains the meta info about this ediff operation
531 ;; (regexp dir1 dir2 dir3 merge-auto-store-dir comparison-func)
532 ;; Later the meta-buffer is prepended to this list.
534 ;; Some operations might use a different meta header. For instance,
535 ;; ediff-multifile-patch doesn't have dir2 and dir3, and regexp,
536 ;; comparison-func don't apply.
538 (defun ediff-intersect-directories (jobname
541 dir3 merge-autostore-dir comparison-func)
542 (setq comparison-func (or comparison-func 'string=))
543 (let (lis1 lis2 lis3 common auxdir1 auxdir2 auxdir3 common-part difflist)
545 (setq auxdir1 (file-name-as-directory dir1)
546 lis1 (directory-files auxdir1 nil regexp)
547 lis1 (delete "." lis1)
548 lis1 (delete ".." lis1)
551 (ediff-add-slash-if-directory auxdir1 elt))
553 auxdir2 (file-name-as-directory dir2)
556 (ediff-add-slash-if-directory auxdir2 elt))
557 (directory-files auxdir2 nil regexp)))
560 (setq auxdir3 (file-name-as-directory dir3)
563 (ediff-add-slash-if-directory auxdir3 elt))
564 (directory-files auxdir3 nil regexp))))
566 (if (ediff-nonempty-string-p merge-autostore-dir)
567 (setq merge-autostore-dir
568 (file-name-as-directory merge-autostore-dir)))
569 (setq common (ediff-intersection lis1 lis2 comparison-func))
571 ;; In merge with ancestor jobs, we don't intersect with lis3.
572 ;; If there is no ancestor, we'll offer to merge without the ancestor.
573 ;; So, we intersect with lis3 only when we are doing 3-way file comparison
574 (if (and lis3 (ediff-comparison-metajob3 jobname))
575 (setq common (ediff-intersection common lis3 comparison-func)))
577 ;; copying is needed because sort sorts via side effects
578 (setq common (sort (ediff-copy-list common) 'string-lessp))
580 ;; compute difference list
581 (setq difflist (ediff-set-difference
582 (ediff-union (ediff-union lis1 lis2 comparison-func)
587 difflist (delete "." difflist)
588 ;; copying is needed because sort sorts via side effects
589 difflist (sort (ediff-copy-list (delete ".." difflist))
592 (setq difflist (mapcar (lambda (elt) (cons elt 1)) difflist))
594 ;; check for files belonging to lis1/2/3
595 ;; Each elt is of the norm (file . number)
596 ;; Number encodes the directories to which file belongs.
597 ;; It is a product of a subset of ediff-membership-code1=2,
598 ;; ediff-membership-code2=3, and ediff-membership-code3=5.
599 ;; If file belongs to dir 1 only, the membership code is 2.
600 ;; If it is in dir1 and dir3, then the membership code is 2*5=10;
601 ;; if it is in dir1 and dir2, then the membership code is 2*3=6, etc.
602 (mapcar (lambda (elt)
603 (if (member (car elt) lis1)
604 (setcdr elt (* (cdr elt) ediff-membership-code1)))
605 (if (member (car elt) lis2)
606 (setcdr elt (* (cdr elt) ediff-membership-code2)))
607 (if (member (car elt) lis3)
608 (setcdr elt (* (cdr elt) ediff-membership-code3)))
612 ;; diff metalist header
613 (ediff-make-new-meta-list-header regexp
614 auxdir1 auxdir2 auxdir3
622 (ediff-make-new-meta-list-header regexp
623 auxdir1 auxdir2 auxdir3
628 (ediff-make-new-meta-list-element
633 ;; The following is done because: In merging with
634 ;; ancestor, we don't intersect with lis3. So, it is
635 ;; possible that elt is a file in auxdir1/2 but a
636 ;; directory in auxdir3 Or elt may not exist in auxdir3 at
637 ;; all. In the first case, we add a slash at the end. In
638 ;; the second case, we insert nil.
639 (setq elt (ediff-add-slash-if-directory auxdir3 elt))
640 (if (file-exists-p (concat auxdir3 elt))
641 (concat auxdir3 elt))))))
644 (cons common-part difflist)
647 ;; find directory files that are under revision. Include subdirectories, since
648 ;; we may visit them recursively. DIR1 is the directory to inspect.
649 ;; MERGE-AUTOSTORE-DIR is the directory where to auto-store the results of
650 ;; merges. Can be nil.
651 (defun ediff-get-directory-files-under-revision (jobname
653 &optional merge-autostore-dir)
654 (let (lis1 elt common auxdir1)
655 (setq auxdir1 (file-name-as-directory dir1)
656 lis1 (directory-files auxdir1 nil regexp))
658 (if (ediff-nonempty-string-p merge-autostore-dir)
659 (setq merge-autostore-dir
660 (file-name-as-directory merge-autostore-dir)))
665 ;; take files under revision control
666 (cond ((file-directory-p (concat auxdir1 elt))
668 (cons (ediff-add-slash-if-directory auxdir1 elt) common)))
669 ((and (featurep 'vc-hooks) (vc-backend (concat auxdir1 elt)))
670 (setq common (cons elt common)))
671 ;; The following two are needed only if vc-hooks isn't loaded.
672 ;; They won't recognize CVS files.
673 ((file-exists-p (concat auxdir1 elt ",v"))
674 (setq common (cons elt common)))
675 ((file-exists-p (concat auxdir1 "RCS/" elt ",v"))
676 (setq common (cons elt common)))
680 (setq common (delete "./" common)
681 common (delete "../" common)
682 common (delete "RCS" common)
683 common (delete "CVS" common)
686 ;; copying is needed because sort sorts via side effects
687 (setq common (sort (ediff-copy-list common) 'string-lessp))
691 ;; header -- has 6 elements. Meta buffer is prepended later by
692 ;; ediff-prepare-meta-buffer
693 (ediff-make-new-meta-list-header regexp
695 merge-autostore-dir nil)
696 (mapcar (lambda (elt) (ediff-make-new-meta-list-element
697 (concat auxdir1 elt) nil nil))
702 ;; If file groups selected by patterns will ever be implemented, this
703 ;; comparison function might become useful.
704 ;;;; uses external variables PAT1 PAT2 to compare str1/2
705 ;;;; patterns must be of the form ???*???? where ??? are strings of chars
706 ;;;; containing no *.
707 ;;(defun ediff-pattern= (str1 str2)
708 ;; (let (pos11 pos12 pos21 pos22 len1 len2)
710 ;; len (length epat1)
712 ;; (while (and (< pos11 len) (not (= (aref epat1 pos11) ?*)))
713 ;; (setq pos11 (1+ pos11)))
714 ;; (while (and (> pos12 0) (not (= (aref epat1 (1- pos12)) ?*)))
715 ;; (setq pos12 (1- pos12)))
718 ;; len (length epat2)
720 ;; (while (and (< pos21 len) (not (= (aref epat2 pos21) ?*)))
721 ;; (setq pos21 (1+ pos21)))
722 ;; (while (and (> pos22 0) (not (= (aref epat2 (1- pos22)) ?*)))
723 ;; (setq pos22 (1- pos22)))
725 ;; (if (and (> (length str1) pos12) (>= pos12 pos11) (> pos11 -1)
726 ;; (> (length str2) pos22) (>= pos22 pos21) (> pos21 -1))
727 ;; (string= (substring str1 pos11 pos12)
728 ;; (substring str2 pos21 pos22)))
732 ;; Prepare meta-buffer in accordance with the argument-function and
733 ;; redraw-function. Must return the created meta-buffer.
734 (defun ediff-prepare-meta-buffer (action-func meta-list
735 meta-buffer-name redraw-function
736 jobname &optional startup-hooks)
737 (let* ((meta-buffer-name
738 (ediff-unique-buffer-name meta-buffer-name "*"))
739 (meta-buffer (get-buffer-create meta-buffer-name)))
740 (ediff-with-current-buffer meta-buffer
745 (setq ediff-meta-action-function action-func
746 ediff-meta-redraw-function redraw-function
747 ediff-metajob-name jobname
748 ediff-meta-buffer meta-buffer)
750 ;; comes after ediff-meta-action-function is set
751 (ediff-setup-meta-map)
753 (if (eq ediff-metajob-name 'ediff-registry)
755 (setq ediff-registry-buffer meta-buffer
756 ediff-meta-list meta-list)
757 ;; this func is used only from registry buffer, not from other
760 ediff-meta-buffer-map "M" 'ediff-show-meta-buff-from-registry))
761 ;; Initialize the meta list -- we don't do this for registry.
762 (setq ediff-meta-list
763 ;; add meta-buffer to the list header
764 (cons (cons meta-buffer (car meta-list))
767 (or (eq meta-buffer ediff-registry-buffer)
768 (setq ediff-session-registry
769 (cons meta-buffer ediff-session-registry)))
771 ;; redraw-function uses ediff-meta-list
772 (funcall redraw-function ediff-meta-list)
774 ;; set read-only/non-modified
775 (setq buffer-read-only t)
776 (set-buffer-modified-p nil)
778 (run-hooks 'startup-hooks)
780 ;; Arrange to show directory contents differences
781 ;; Must be after run startup-hooks, since ediff-dir-difference-list is
782 ;; set inside these hooks
783 (if (eq action-func 'ediff-filegroup-action)
785 ;; put meta buffer in (car ediff-dir-difference-list)
786 (setq ediff-dir-difference-list
787 (cons (cons meta-buffer (car ediff-dir-difference-list))
788 (cdr ediff-dir-difference-list)))
790 (or (ediff-one-filegroup-metajob jobname)
791 (ediff-draw-dir-diffs ediff-dir-difference-list))
793 ediff-meta-buffer-map "h" 'ediff-mark-for-hiding-at-pos)
794 (define-key ediff-meta-buffer-map "x" 'ediff-hide-marked-sessions)
796 ediff-meta-buffer-map "m" 'ediff-mark-for-operation-at-pos)
797 (define-key ediff-meta-buffer-map "u" nil)
799 ediff-meta-buffer-map "um" 'ediff-unmark-all-for-operation)
801 ediff-meta-buffer-map "uh" 'ediff-unmark-all-for-hiding)
802 (cond ((ediff-collect-diffs-metajob jobname)
804 ediff-meta-buffer-map "P" 'ediff-collect-custom-diffs))
805 ((ediff-patch-metajob jobname)
807 ediff-meta-buffer-map "P" 'ediff-meta-show-patch)))
808 (define-key ediff-meta-buffer-map "^" 'ediff-up-meta-hierarchy)
809 (define-key ediff-meta-buffer-map "D" 'ediff-show-dir-diffs)))
811 (if (eq ediff-metajob-name 'ediff-registry)
812 (run-hooks 'ediff-registry-setup-hook)
813 (run-hooks 'ediff-after-session-group-setup-hook))
814 ) ; eval in meta-buffer
817 ;; Insert the activity marker for session SESSION in the meta buffer at point
818 ;; The activity marker is either SPC (untouched session), or + (active session,
819 ;; i.e., ediff is currently run in it), or - (finished session, i.e., we've ran
820 ;; ediff in it and then exited)
821 (defun ediff-insert-session-activity-marker-in-meta-buffer (session)
823 (cond ((ediff-get-session-activity-marker session))
827 ;; Insert session status at point. Status is either ?H (marked for hiding), or
828 ;; ?I (hidden or invalid), or ?* (meaning marked for an operation; currently,
829 ;; such op can only be checking for equality)), or SPC (meaning neither marked
831 (defun ediff-insert-session-status-in-meta-buffer (session)
833 (cond ((ediff-get-session-status session)) ; session has status: ?H, ?I, ?*
834 ;; normal session, no marks or hidings
837 ;; If NEW-MARKER is non-nil, use it to substitute the current activity marker
838 ;; in the meta buffer. If nil, use SPC
839 (defun ediff-replace-session-activity-marker-in-meta-buffer (point new-marker)
840 (let* ((overl (ediff-get-meta-overlay-at-pos point))
841 (session-info (ediff-overlay-get overl 'ediff-meta-info))
842 (activity-marker (ediff-get-session-activity-marker session-info))
844 (or new-marker activity-marker (setq new-marker ?\ ))
845 (goto-char (ediff-overlay-start overl))
846 (if (eq (char-after (point)) new-marker)
847 () ; if marker shown in buffer is the same as new-marker, do nothing
850 (set-buffer-modified-p nil))))
852 ;; If NEW-STATUS is non-nil, use it to substitute the current status marker in
853 ;; the meta buffer. If nil, use SPC
854 (defun ediff-replace-session-status-in-meta-buffer (point new-status)
855 (let* ((overl (ediff-get-meta-overlay-at-pos point))
856 (session-info (ediff-overlay-get overl 'ediff-meta-info))
857 (status (ediff-get-session-status session-info))
859 (setq new-status (or new-status status ?\ ))
860 (goto-char (ediff-overlay-start overl))
861 (forward-char 1) ; status is the second char in session record
862 (if (eq (char-after (point)) new-status)
863 () ; if marker shown in buffer is the same as new-marker, do nothing
866 (set-buffer-modified-p nil))))
868 ;; insert all file info in meta buffer for a given session
869 (defun ediff-insert-session-info-in-meta-buffer (session-info sessionNum)
870 (let ((f1 (ediff-get-session-objA session-info))
871 (f2 (ediff-get-session-objB session-info))
872 (f3 (ediff-get-session-objC session-info))
874 (hidden (eq (ediff-get-session-status session-info) ?I)))
875 ;; insert activity marker, i.e., SPC, - or +
876 (ediff-insert-session-activity-marker-in-meta-buffer session-info)
877 ;; insert session status, i.e., *, H
878 (ediff-insert-session-status-in-meta-buffer session-info)
879 (insert " Session " (int-to-string sessionNum) ":\n")
880 (ediff-meta-insert-file-info1 f1)
881 (ediff-meta-insert-file-info1 f2)
882 (ediff-meta-insert-file-info1 f3)
883 (ediff-set-meta-overlay pt (point) session-info sessionNum hidden)))
886 ;; this is a setup function for ediff-directories
887 ;; must return meta-buffer
888 (defun ediff-redraw-directory-group-buffer (meta-list)
889 ;; extract directories
890 (let ((meta-buf (ediff-get-group-buffer meta-list))
893 regexp elt merge-autostore-dir
894 point tmp-list buffer-read-only)
895 (ediff-with-current-buffer meta-buf
898 ;; delete phony overlays that used to represent sessions before the buff
900 (ediff-cond-compile-for-xemacs-or-emacs
901 (map-extents 'delete-extent) ; xemacs
902 (mapcar 'delete-overlay (overlays-in 1 1)) ; emacs
905 (insert (format ediff-meta-buffer-message
906 (ediff-abbrev-jobname ediff-metajob-name)))
908 (setq regexp (ediff-get-group-regexp meta-list)
910 (ediff-get-group-merge-autostore-dir meta-list))
912 (cond ((ediff-collect-diffs-metajob)
914 " P:\tcollect custom diffs of all marked sessions\n"))
915 ((ediff-patch-metajob)
917 " P:\tshow patch appropriately for the context (session or group)\n")))
919 " ^:\tshow parent session group\n")
920 (or (ediff-one-filegroup-metajob)
922 " D:\tshow differences among directories\n"
923 " ==:\tfor each session, show which files are identical\n"
924 " =h:\tlike ==, but also marks those sessions for hiding\n"
925 " =m:\tlike ==, but also marks those sessions for operation\n\n"))
928 (if (and (stringp regexp) (> (length regexp) 0))
930 (format "*** Filter-through regular expression: %s\n" regexp)))
931 (ediff-insert-dirs-in-meta-buffer meta-list)
932 (if (and ediff-autostore-merges (ediff-merge-metajob)
933 (ediff-nonempty-string-p merge-autostore-dir))
935 "\nMerge results are automatically stored in:\n\t%s\n"
936 merge-autostore-dir)))
938 Size Last modified Name
939 ----------------------------------------------
943 ;; discard info on directories and regexp
944 (setq meta-list (cdr meta-list)
946 (while (and tmp-list empty)
947 (if (and (car tmp-list)
948 (not (eq (ediff-get-session-status (car tmp-list)) ?I)))
950 (setq tmp-list (cdr tmp-list)))
954 " ****** ****** This session group has no members\n"))
956 ;; now organize file names like this:
957 ;; use-mark sizeA dateA sizeB dateB filename
958 ;; make sure directories are displayed with a trailing slash.
960 (setq elt (car meta-list)
961 meta-list (cdr meta-list)
962 sessionNum (1+ sessionNum))
963 (if (eq (ediff-get-session-status elt) ?I)
965 (ediff-insert-session-info-in-meta-buffer elt sessionNum)))
966 (set-buffer-modified-p nil)
970 (defun ediff-update-markers-in-dir-meta-buffer (meta-list)
971 (let ((meta-buf (ediff-get-group-buffer meta-list))
972 session-info point overl buffer-read-only)
973 (ediff-with-current-buffer meta-buf
975 (goto-char (point-min))
976 (ediff-next-meta-item1)
978 (setq session-info (ediff-get-meta-info meta-buf (point) 'no-error)
979 overl (ediff-get-meta-overlay-at-pos (point)))
982 (cond ((eq (ediff-get-session-status session-info) ?I)
984 (if overl (ediff-overlay-put overl 'invisible t)))
985 ((and (eq (ediff-get-session-status session-info) ?H)
986 overl (ediff-overlay-get overl 'invisible))
988 (ediff-overlay-put overl 'invisible nil))
989 (t (ediff-replace-session-activity-marker-in-meta-buffer
991 (ediff-get-session-activity-marker session-info))
992 (ediff-replace-session-status-in-meta-buffer
994 (ediff-get-session-status session-info))))))
995 (ediff-next-meta-item1) ; advance to the next item
997 (set-buffer-modified-p nil)
1001 (defun ediff-update-session-marker-in-dir-meta-buffer (session-num)
1002 (let (buffer-meta-overlays session-info overl buffer-read-only)
1004 (ediff-cond-compile-for-xemacs-or-emacs
1005 (map-extents ; xemacs
1006 (lambda (ext maparg)
1008 (ediff-overlay-get ext 'ediff-meta-info)
1009 (eq (ediff-overlay-get ext 'ediff-meta-session-number)
1012 ;; Emacs doesn't have map-extents, so try harder
1013 ;; Splice overlay lists to get all buffer overlays
1015 (setq buffer-meta-overlays (overlay-lists)
1016 buffer-meta-overlays (append (car buffer-meta-overlays)
1017 (cdr buffer-meta-overlays)))
1023 (ediff-overlay-get overl 'ediff-meta-info)
1024 (eq (ediff-overlay-get
1025 overl 'ediff-meta-session-number)
1028 buffer-meta-overlays))))
1032 "Bug in ediff-update-session-marker-in-dir-meta-buffer: no overlay with given number %S"
1034 (setq session-info (ediff-overlay-get overl 'ediff-meta-info))
1035 (goto-char (ediff-overlay-start overl))
1036 (ediff-replace-session-activity-marker-in-meta-buffer
1038 (ediff-get-session-activity-marker session-info))
1039 (ediff-replace-session-status-in-meta-buffer
1041 (ediff-get-session-status session-info)))
1042 (ediff-next-meta-item1))
1046 ;; Check if this is a problematic session.
1047 ;; Return nil if not. Otherwise, return symbol representing the problem
1048 ;; At present, problematic sessions occur only in -with-ancestor comparisons
1049 ;; when the ancestor is a directory rather than a file, or when there is no
1050 ;; suitable ancestor file in the ancestor directory
1051 (defun ediff-problematic-session-p (session)
1052 (let ((f1 (ediff-get-session-objA-name session))
1053 (f2 (ediff-get-session-objB-name session))
1054 (f3 (ediff-get-session-objC-name session)))
1055 (cond ((and (stringp f1) (not (file-directory-p f1))
1056 (stringp f2) (not (file-directory-p f2))
1057 ;; either invalid file name or a directory
1058 (or (not (stringp f3)) (file-directory-p f3))
1059 (ediff-ancestor-metajob))
1060 ;; more may be added later
1064 (defun ediff-meta-insert-file-info1 (fileinfo)
1065 (let ((fname (car fileinfo))
1066 (feq (ediff-get-file-eqstatus fileinfo))
1067 (max-filename-width (if ediff-meta-truncate-filenames
1068 (- (window-width) 41)
1070 file-modtime file-size)
1071 (cond ((not (stringp fname)) (setq file-size -2)) ; file doesn't exits
1072 ((ediff-listable-file fname)
1073 (if (file-exists-p fname)
1074 ;; set real size and modtime
1075 (setq file-size (ediff-file-size fname)
1076 file-modtime (ediff-file-modtime fname))
1077 (setq file-size -2))) ; file doesn't exist
1078 ( t (setq file-size -1))) ; remote file
1083 (if feq "=" " ") ; equality indicator
1084 (format "%10s" (cond ((= file-size -1) "--")
1085 ((< file-size -1) "--")
1087 (cond ((= file-size -1) "*remote file*")
1088 ((< file-size -1) "*file doesn't exist*")
1089 (t (ediff-format-date (decode-time file-modtime))))
1091 ;; dir names in meta lists have training slashes, so we just
1092 ;; abbreviate the file name, if file exists
1093 (if (and (not (stringp fname)) (< file-size -1))
1094 "-------" ; file doesn't exist
1095 (ediff-truncate-string-left
1096 (ediff-abbreviate-file-name fname)
1097 max-filename-width)))))))
1099 (defconst ediff-months '((1 . "Jan") (2 . "Feb") (3 . "Mar") (4 . "Apr")
1100 (5 . "May") (6 . "Jun") (7 . "Jul") (8 . "Aug")
1101 (9 . "Sep") (10 . "Oct") (11 . "Nov") (12 . "Dec"))
1102 "Months' associative array.")
1104 ;; returns 2char string
1105 (defsubst ediff-fill-leading-zero (num)
1108 (number-to-string num)))
1110 ;; TIME is like the output of decode-time
1111 (defun ediff-format-date (time)
1112 (format "%s %2d %4d %s:%s:%s"
1113 (cdr (assoc (nth 4 time) ediff-months)) ; month
1116 (ediff-fill-leading-zero (nth 2 time)) ; hour
1117 (ediff-fill-leading-zero (nth 1 time)) ; min
1118 (ediff-fill-leading-zero (nth 0 time)) ; sec
1121 ;; Draw the directories
1122 (defun ediff-insert-dirs-in-meta-buffer (meta-list)
1123 (let* ((dir1 (ediff-abbreviate-file-name (ediff-get-group-objA meta-list)))
1124 (dir2 (ediff-get-group-objB meta-list))
1125 (dir2 (if (stringp dir2) (ediff-abbreviate-file-name dir2)))
1126 (dir3 (ediff-get-group-objC meta-list))
1127 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3))))
1128 (insert "*** Directory A: " dir1 "\n")
1129 (if dir2 (insert "*** Directory B: " dir2 "\n"))
1130 (if dir3 (insert "*** Directory C: " dir3 "\n"))
1133 (defun ediff-draw-dir-diffs (diff-list &optional buf-name)
1134 (if (null diff-list) (error "Lost difference info on these directories"))
1137 (ediff-unique-buffer-name "*Ediff File Group Differences" "*")))
1138 (let* ((regexp (ediff-get-group-regexp diff-list))
1139 (dir1 (ediff-abbreviate-file-name (ediff-get-group-objA diff-list)))
1140 (dir2 (ediff-abbreviate-file-name (ediff-get-group-objB diff-list)))
1141 (dir3 (ediff-get-group-objC diff-list))
1142 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3)))
1143 (meta-buf (ediff-get-group-buffer diff-list))
1144 (underline (make-string 26 ?-))
1145 file membership-code saved-point
1147 ;; skip the directory part
1148 (setq diff-list (cdr diff-list))
1149 (setq ediff-dir-diffs-buffer (get-buffer-create buf-name))
1150 (ediff-with-current-buffer ediff-dir-diffs-buffer
1151 (setq saved-point (point))
1152 (use-local-map ediff-dir-diffs-buffer-map)
1154 (setq ediff-meta-buffer meta-buf)
1155 (insert "\t\t*** Directory Differences ***\n")
1158 C,button2: over file name -- copy this file to directory that doesn't have it
1161 p,DEL: previous line\n\n")
1163 (insert (format "\n*** Directory A: %s\n" dir1))
1164 (if dir2 (insert (format "*** Directory B: %s\n" dir2)))
1165 (if dir3 (insert (format "*** Directory C: %s\n" dir3)))
1166 (if (and (stringp regexp) (> (length regexp) 0))
1168 (format "*** Filter-through regular expression: %s\n" regexp)))
1170 (insert (format "\n%-27s%-26s" "Directory A" "Directory B"))
1172 (insert (format " %-25s\n" "Directory C"))
1174 (insert (format "%s%s" underline underline))
1176 (insert (format "%s\n\n" underline))
1179 (if (null diff-list)
1180 (insert "\n\t*** No differences ***\n"))
1183 (setq file (car (car diff-list))
1184 membership-code (cdr (car diff-list))
1185 diff-list (cdr diff-list))
1186 (if (= (mod membership-code ediff-membership-code1) 0) ; dir1
1187 (let ((beg (point)))
1188 (insert (format "%-27s"
1189 (ediff-truncate-string-left
1190 (ediff-abbreviate-file-name
1191 (if (file-directory-p (concat dir1 file))
1192 (file-name-as-directory file)
1195 ;; format of meta info in the dir-diff-buffer:
1196 ;; (filename-tail filename-full otherdir1 otherdir2 otherdir3)
1197 (ediff-set-meta-overlay
1199 (list meta-buf file (concat dir1 file) dir1 dir2 dir3)))
1200 (insert (format "%-27s" "---")))
1201 (if (= (mod membership-code ediff-membership-code2) 0) ; dir2
1202 (let ((beg (point)))
1203 (insert (format "%-26s"
1204 (ediff-truncate-string-left
1205 (ediff-abbreviate-file-name
1206 (if (file-directory-p (concat dir2 file))
1207 (file-name-as-directory file)
1210 (ediff-set-meta-overlay
1212 (list meta-buf file (concat dir2 file) dir1 dir2 dir3)))
1213 (insert (format "%-26s" "---")))
1215 (if (= (mod membership-code ediff-membership-code3) 0) ; dir3
1216 (let ((beg (point)))
1217 (insert (format " %-25s"
1218 (ediff-truncate-string-left
1219 (ediff-abbreviate-file-name
1220 (if (file-directory-p (concat dir3 file))
1221 (file-name-as-directory file)
1224 (ediff-set-meta-overlay
1226 (list meta-buf file (concat dir3 file) dir1 dir2 dir3)))
1227 (insert (format " %-25s" "---"))))
1229 (setq buffer-read-only t)
1230 (set-buffer-modified-p nil)
1231 (goto-char saved-point)) ; end eval in diff buffer
1234 (defun ediff-bury-dir-diffs-buffer ()
1235 "Bury the directory difference buffer. Display the meta buffer instead."
1237 ;; ediff-meta-buffer is set in ediff-draw-dir-diffs so the directory
1238 ;; difference buffer remembers the meta buffer
1239 (let ((buf ediff-meta-buffer)
1241 (ediff-kill-buffer-carefully ediff-dir-diffs-buffer)
1242 (if (setq wind (ediff-get-visible-buffer-window buf))
1243 (select-window wind)
1244 (set-window-buffer (selected-window) buf))))
1246 ;; executes in dir session group buffer
1247 ;; show buffer differences
1248 (defun ediff-show-dir-diffs ()
1249 "Display differences among the directories involved in session group."
1251 (if (ediff-one-filegroup-metajob)
1252 (error "This command is inapplicable in the present context"))
1253 (or (ediff-buffer-live-p ediff-dir-diffs-buffer)
1254 (ediff-draw-dir-diffs ediff-dir-difference-list))
1255 (let ((buf ediff-dir-diffs-buffer))
1257 (set-window-buffer (selected-window) buf)
1258 (goto-char (point-min))))
1260 ;; Format of meta info in dir-diff-buffer:
1261 ;; (filename-tail filename-full otherdir1 otherdir2)
1262 (defun ediff-dir-diff-copy-file ()
1263 "Copy file described at point to directories where this file is missing."
1265 (let* ((pos (ediff-event-point last-command-event))
1266 (info (ediff-get-meta-info (current-buffer) pos 'noerror))
1267 (meta-buf (car info))
1268 (file-tail (nth 1 info))
1269 (file-abs (nth 2 info))
1270 (otherdir1 (nth 3 info))
1271 (otherfile1 (if otherdir1 (concat otherdir1 file-tail)))
1272 (otherdir2 (nth 4 info))
1273 (otherfile2 (if otherdir2 (concat otherdir2 file-tail)))
1274 (otherdir3 (nth 5 info))
1275 (otherfile3 (if otherdir3 (concat otherdir3 file-tail)))
1276 meta-list dir-diff-list
1279 (error "No file suitable for copying described at this location"))
1280 (ediff-with-current-buffer meta-buf
1281 (setq meta-list ediff-meta-list
1282 dir-diff-list ediff-dir-difference-list))
1284 ;; copy file to directories where it doesn't exist, update
1285 ;; ediff-dir-difference-list and redisplay
1287 (lambda (otherfile-struct)
1288 (let ((otherfile (car otherfile-struct))
1289 (file-mem-code (cdr otherfile-struct)))
1291 (or (file-exists-p otherfile)
1293 (format "Copy %s to %s ? " file-abs otherfile))
1294 (let* ((file-diff-record (assoc file-tail dir-diff-list))
1296 (* (cdr file-diff-record) file-mem-code)))
1297 (copy-file file-abs otherfile)
1298 (setcdr file-diff-record new-mem-code)
1299 (ediff-draw-dir-diffs dir-diff-list (buffer-name))
1301 ;; if file is in all three dirs or in two dirs and only
1302 ;; two dirs are involved, delete this file's record
1303 (if (or (= new-mem-code ediff-product-of-memcodes)
1304 (and (> new-mem-code ediff-membership-code3)
1306 (delq file-diff-record dir-diff-list))
1309 ;; 2,3,5 are numbers used to encode membership of a file in
1310 ;; dir1/2/3. See ediff-intersect-directories.
1311 (list (cons otherfile1 2) (cons otherfile2 3) (cons otherfile3 5)))
1313 (if (and (file-exists-p otherfile1)
1314 (file-exists-p otherfile2)
1315 (or (not otherfile3) (file-exists-p otherfile3)))
1316 ;; update ediff-meta-list by direct modification
1318 (list (ediff-make-new-meta-list-element
1319 otherfile1 otherfile2 otherfile3)))
1321 (ediff-update-meta-buffer meta-buf 'must-redraw)
1324 (defun ediff-up-meta-hierarchy ()
1325 "Go to the parent session group buffer."
1327 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1328 (ediff-show-meta-buffer
1329 ediff-parent-meta-buffer ediff-meta-session-number)
1330 (error "This session group has no parent")))
1333 ;; argument is ignored
1334 (defun ediff-redraw-registry-buffer (&optional ignore)
1335 (ediff-with-current-buffer ediff-registry-buffer
1336 (let ((point (point))
1337 elt bufAname bufBname bufCname cur-diff total-diffs pt
1338 job-name meta-list registry-list buffer-read-only)
1340 ;; delete phony overlays that used to represent sessions before the buff
1342 (ediff-cond-compile-for-xemacs-or-emacs
1343 (map-extents 'delete-extent) ; xemacs
1344 (mapcar 'delete-overlay (overlays-in 1 1)) ; emacs
1347 (insert "This is a registry of all active Ediff sessions.
1350 button2, `v', RET over a session record: switch to that session
1351 M over a session record: display the associated session group
1352 R in any Ediff session: display session registry
1354 p,DEL: previous session
1355 E: browse Ediff on-line manual
1359 \t\tActive Ediff Sessions:
1360 \t\t----------------------
1363 ;; purge registry list from dead buffers
1364 (mapcar (lambda (elt)
1365 (if (not (ediff-buffer-live-p elt))
1366 (setq ediff-session-registry
1367 (delq elt ediff-session-registry))))
1368 ediff-session-registry)
1370 (if (null ediff-session-registry)
1371 (insert " ******* No active Ediff sessions *******\n"))
1373 (setq registry-list ediff-session-registry)
1374 (while registry-list
1375 (setq elt (car registry-list)
1376 registry-list (cdr registry-list))
1378 (if (ediff-buffer-live-p elt)
1379 (if (ediff-with-current-buffer elt
1380 (setq job-name ediff-metajob-name
1381 meta-list ediff-meta-list)
1382 (and ediff-metajob-name
1383 (not (eq ediff-metajob-name 'ediff-registry))))
1386 (insert (format " *group*\t%s: %s\n"
1388 (ediff-abbrev-jobname job-name)))
1389 (insert (format "\t\t %s %s %s\n"
1390 (ediff-abbreviate-file-name
1391 (ediff-get-group-objA meta-list))
1392 (ediff-abbreviate-file-name
1394 (ediff-get-group-objB meta-list))
1395 (ediff-get-group-objB meta-list)
1397 (ediff-abbreviate-file-name
1399 (ediff-get-group-objC meta-list))
1400 (ediff-get-group-objC meta-list)
1402 (ediff-set-meta-overlay pt (point) elt))
1404 (ediff-with-current-buffer elt
1405 (setq bufAname (if (ediff-buffer-live-p ediff-buffer-A)
1406 (buffer-name ediff-buffer-A)
1407 "!!!killed buffer!!!")
1408 bufBname (if (ediff-buffer-live-p ediff-buffer-B)
1409 (buffer-name ediff-buffer-B)
1410 "!!!killed buffer!!!")
1411 bufCname (cond ((not (ediff-3way-job))
1413 ((ediff-buffer-live-p ediff-buffer-C)
1414 (buffer-name ediff-buffer-C))
1415 (t "!!!killed buffer!!!")))
1416 (setq total-diffs (format "%-4d" ediff-number-of-differences)
1418 (cond ((= ediff-current-difference -1) " _")
1419 ((= ediff-current-difference
1420 ediff-number-of-differences)
1423 "%4d" (1+ ediff-current-difference))))
1424 job-name ediff-job-name))
1425 ;; back in the meta buf
1427 (insert cur-diff "/" total-diffs "\t"
1429 (format ": %s" (ediff-abbrev-jobname job-name)))
1431 "\n\t\t " bufAname " " bufBname " " bufCname "\n")
1432 (ediff-set-meta-overlay pt (point) elt))))
1434 (set-buffer-modified-p nil)
1438 ;; Sets overlay around a meta record with 'ediff-meta-info property PROP
1439 ;; If optional SESSION-NUMBER, make it a property of the overlay,
1440 ;; ediff-meta-session-number
1441 ;; PROP is either the ctl or meta buffer (used when we work with the registry)
1442 ;; or a session meta descriptor of the form
1443 ;; (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
1444 (defun ediff-set-meta-overlay (b e prop &optional session-number hidden)
1446 (setq overl (ediff-make-overlay b e))
1448 (ediff-overlay-put overl 'mouse-face 'highlight)
1449 (ediff-overlay-put overl 'highlight t))
1450 (ediff-overlay-put overl 'ediff-meta-info prop)
1451 (ediff-overlay-put overl 'invisible hidden)
1452 (if (numberp session-number)
1453 (ediff-overlay-put overl 'ediff-meta-session-number session-number))))
1455 (defun ediff-mark-for-hiding-at-pos (unmark)
1456 "Mark session for hiding. With prefix arg, unmark."
1458 (let* ((pos (ediff-event-point last-command-event))
1459 (meta-buf (ediff-event-buffer last-command-event))
1460 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1461 (info (ediff-get-meta-info meta-buf pos))
1462 (session-number (ediff-get-session-number-at-pos pos)))
1463 (ediff-mark-session-for-hiding info unmark)
1464 (ediff-next-meta-item 1)
1466 (ediff-update-meta-buffer meta-buf nil session-number))
1469 ;; Returns whether session was marked or unmarked
1470 (defun ediff-mark-session-for-hiding (info unmark)
1471 (let ((session-buf (ediff-get-session-buffer info))
1473 (cond ((eq unmark 'mark) (setq unmark nil))
1474 ((eq (ediff-get-session-status info) ?H) (setq unmark t))
1475 (unmark ; says unmark, but the marker is different from H
1478 (unmark (ediff-set-session-status info nil))
1479 ;;; (if (ediff-buffer-live-p session-buf)
1480 ;;; (error "Can't hide active session, %s" (buffer-name session-buf)))
1481 (t (ediff-set-session-status info ?H))))
1485 (defun ediff-mark-for-operation-at-pos (unmark)
1486 "Mark session for a group operation. With prefix arg, unmark."
1488 (let* ((pos (ediff-event-point last-command-event))
1489 (meta-buf (ediff-event-buffer last-command-event))
1490 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1491 (info (ediff-get-meta-info meta-buf pos))
1492 (session-number (ediff-get-session-number-at-pos pos)))
1493 (ediff-mark-session-for-operation info unmark)
1494 (ediff-next-meta-item 1)
1496 (ediff-update-meta-buffer meta-buf nil session-number))
1500 ;; returns whether session was unmarked.
1501 ;; remember: this is a toggle op
1502 (defun ediff-mark-session-for-operation (info unmark)
1504 (cond ((eq unmark 'mark) (setq unmark nil))
1505 ((eq (ediff-get-session-status info) ?*) (setq unmark t))
1506 (unmark ; says unmark, but the marker is different from *
1509 (unmark (ediff-set-session-status info nil))
1510 (t (ediff-set-session-status info ?*))))
1514 (defun ediff-hide-marked-sessions (unhide)
1515 "Hide marked sessions. With prefix arg, unhide."
1517 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1518 (meta-list (cdr ediff-meta-list))
1519 (from (if unhide ?I ?H))
1520 (to (if unhide ?H ?I))
1522 active-sessions-exist session-buf elt)
1524 (setq elt (car meta-list)
1525 meta-list (cdr meta-list)
1526 session-buf (ediff-get-session-buffer elt))
1528 (if (eq (ediff-get-session-status elt) from)
1530 (setq numMarked (1+ numMarked))
1531 (if (and (eq to ?I) (buffer-live-p session-buf))
1532 ;; shouldn't hide active sessions
1533 (setq active-sessions-exist t)
1534 (ediff-set-session-status elt to)))))
1536 (ediff-update-meta-buffer grp-buf 'must-redraw)
1539 (message "Nothing to reveal...")
1540 (message "Nothing to hide...")))
1541 (if active-sessions-exist
1542 (message "Note: Ediff didn't hide active sessions!"))
1545 ;; Apply OPERATION to marked sessions. Operation expects one argument of type
1546 ;; meta-list member (not the first one), i.e., a regular session description.
1547 ;; Returns number of marked sessions on which operation was performed
1548 (defun ediff-operate-on-marked-sessions (operation)
1549 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1550 (meta-list (cdr ediff-meta-list))
1554 (diff-buffer ediff-meta-diff-buffer)
1557 (setq elt (car meta-list)
1558 meta-list (cdr meta-list)
1559 sessionNum (1+ sessionNum))
1560 (cond ((eq (ediff-get-session-status elt) marksym)
1562 (setq numMarked (1+ numMarked))
1563 (funcall operation elt sessionNum)))
1564 ;; The following goes into a session represented by a subdirectory
1565 ;; and applies operation to marked sessions there
1566 ((and (ediff-meta-session-p elt)
1567 (ediff-buffer-live-p
1568 (setq session-buf (ediff-get-session-buffer elt))))
1571 (ediff-with-current-buffer session-buf
1572 ;; pass meta-diff along
1573 (setq ediff-meta-diff-buffer diff-buffer)
1574 ;; collect diffs in child group
1575 (ediff-operate-on-marked-sessions operation)))))))
1576 (ediff-update-meta-buffer grp-buf 'must-redraw) ; just in case
1580 (defun ediff-append-custom-diff (session sessionNum)
1581 (or (ediff-collect-diffs-metajob)
1582 (error "Can't compute multifile patch in this context"))
1583 (let ((session-buf (ediff-get-session-buffer session))
1584 (meta-diff-buff ediff-meta-diff-buffer)
1585 (metajob ediff-metajob-name)
1586 tmp-buf custom-diff-buf)
1587 (if (ediff-buffer-live-p session-buf)
1588 (ediff-with-current-buffer session-buf
1589 (if (eq ediff-control-buffer session-buf) ; individual session
1591 (ediff-compute-custom-diffs-maybe)
1592 (setq custom-diff-buf ediff-custom-diff-buffer)))))
1594 (or (ediff-buffer-live-p meta-diff-buff)
1595 (error "Ediff: something wrong--killed multiple diff's buffer"))
1597 (cond ((ediff-buffer-live-p custom-diff-buf)
1598 ;; for live session buffers we do them first because the user may
1599 ;; have changed them with respect to the underlying files
1601 (set-buffer meta-diff-buff)
1602 (goto-char (point-max))
1603 (insert-buffer custom-diff-buf)
1605 ;; if ediff session is not live, run diff directly on the files
1606 ((memq metajob '(ediff-directories
1607 ediff-merge-directories
1608 ediff-merge-directories-with-ancestor))
1609 ;; get diffs by calling shell command on ediff-custom-diff-program
1611 (set-buffer (setq tmp-buf (get-buffer-create ediff-tmp-buffer)))
1614 (format "%s %s %s %s"
1615 ediff-custom-diff-program ediff-custom-diff-options
1616 (ediff-get-session-objA-name session)
1617 (ediff-get-session-objB-name session))
1620 (set-buffer meta-diff-buff)
1621 (goto-char (point-max))
1622 (insert-buffer tmp-buf)
1625 (ediff-kill-buffer-carefully meta-diff-buff)
1626 (error "Session %d compares versions of file. Such session must be active to enable multifile patch collection" sessionNum )))
1629 (defun ediff-collect-custom-diffs ()
1630 "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'.
1631 This operation is defined only for `ediff-directories' and
1632 `ediff-directory-revisions', since its intent is to produce
1633 multifile patches. For `ediff-directory-revisions', we insist that
1634 all marked sessions must be active."
1636 (or (ediff-buffer-live-p ediff-meta-diff-buffer)
1637 (setq ediff-meta-diff-buffer
1639 (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
1640 (ediff-with-current-buffer ediff-meta-diff-buffer
1641 (setq buffer-read-only nil)
1643 (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
1646 (display-buffer ediff-meta-diff-buffer 'not-this-window)
1647 (ediff-with-current-buffer ediff-meta-diff-buffer
1648 (set-buffer-modified-p nil)
1649 (setq buffer-read-only t)))
1651 (message "No marked sessions found")))
1653 (defun ediff-meta-show-patch ()
1654 "Show the multi-file patch associated with this group session."
1656 (let* ((pos (ediff-event-point last-command-event))
1657 (meta-buf (ediff-event-buffer last-command-event))
1658 (info (ediff-get-meta-info meta-buf pos 'noerror))
1659 (patchbuffer ediff-meta-patchbufer))
1660 (if (ediff-buffer-live-p patchbuffer)
1661 (ediff-with-current-buffer patchbuffer
1666 (ediff-get-session-objB-name info)
1667 (ediff-get-session-objC-name info)))
1668 (set-buffer (get-buffer-create ediff-tmp-buffer))
1670 (insert-buffer patchbuffer)
1671 (display-buffer ediff-tmp-buffer 'not-this-window)
1673 (error "The patch buffer wasn't found"))))
1676 ;; This function executes in meta buffer. It knows where event happened.
1677 (defun ediff-filegroup-action ()
1678 "Execute appropriate action for a selected session."
1680 (let* ((pos (ediff-event-point last-command-event))
1681 (meta-buf (ediff-event-buffer last-command-event))
1682 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1683 (info (ediff-get-meta-info meta-buf pos))
1684 (session-buf (ediff-get-session-buffer info))
1685 (session-number (ediff-get-session-number-at-pos pos meta-buf))
1686 merge-autostore-dir file1 file2 file3 regexp)
1688 (setq file1 (ediff-get-session-objA-name info)
1689 file2 (ediff-get-session-objB-name info)
1690 file3 (ediff-get-session-objC-name info))
1692 ;; make sure we don't start on hidden sessions
1693 ;; ?H means marked for hiding. ?I means invalid (hidden).
1694 (if (memq (ediff-get-session-status info) '(?I))
1697 (if (y-or-n-p "This session is marked as hidden, unmark? ")
1699 (ediff-set-session-status info nil)
1700 (ediff-update-meta-buffer meta-buf nil session-number))
1701 (error "Aborted"))))
1703 (ediff-with-current-buffer meta-buf
1704 (setq merge-autostore-dir
1705 (ediff-get-group-merge-autostore-dir ediff-meta-list))
1706 (goto-char pos) ; if the user clicked on session--move point there
1707 ;; First handle sessions involving directories (which are themselves
1709 ;; After that handle individual sessions
1710 (cond ((ediff-meta-session-p info)
1711 ;; do ediff/ediff-merge on subdirectories
1712 (if (ediff-buffer-live-p session-buf)
1713 (ediff-show-meta-buffer session-buf)
1714 (setq regexp (read-string "Filter through regular expression: "
1715 nil 'ediff-filtering-regexp-history))
1716 (ediff-directories-internal
1717 file1 file2 file3 regexp
1718 ediff-session-action-function
1720 ;; make it update (car info) after startup
1722 ;; child session group should know its parent
1723 (setq ediff-parent-meta-buffer
1724 (quote ,ediff-meta-buffer)
1725 ediff-meta-session-number
1727 ;; and parent will know its child
1728 (setcar (quote ,info) ediff-meta-buffer))))))
1730 ;; Do ediff-revision on a subdirectory
1731 ((and (ediff-one-filegroup-metajob)
1732 (ediff-revision-metajob)
1733 (file-directory-p file1))
1734 (if (ediff-buffer-live-p session-buf)
1735 (ediff-show-meta-buffer session-buf)
1736 (setq regexp (read-string "Filter through regular expression: "
1737 nil 'ediff-filtering-regexp-history))
1738 (ediff-directory-revisions-internal
1740 ediff-session-action-function ediff-metajob-name
1741 ;; make it update (car info) after startup
1743 ;; child session group should know its parent and
1745 (setq ediff-parent-meta-buffer
1746 (quote ,ediff-meta-buffer)
1747 ediff-meta-session-number
1749 ;; and parent will know its child
1750 (setcar (quote ,info) ediff-meta-buffer))))))
1752 ;; From here on---only individual session handlers
1754 ;; handle an individual session with a live control buffer
1755 ((ediff-buffer-live-p session-buf)
1756 (ediff-with-current-buffer session-buf
1757 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1758 (ediff-recenter 'no-rehighlight)))
1760 ((ediff-problematic-session-p info)
1763 "This session has no ancestor. Merge without the ancestor? ")
1766 ;; provide startup hooks
1769 'ediff-after-quit-hook-internal
1771 (if (ediff-buffer-live-p ,(current-buffer))
1772 (ediff-show-meta-buffer
1773 ,(current-buffer) ,session-number)))
1775 (setq ediff-meta-buffer ,(current-buffer)
1776 ediff-meta-session-number
1778 (setq ediff-merge-store-file
1779 ,(if (ediff-nonempty-string-p
1780 merge-autostore-dir)
1783 ediff-merge-filename-prefix
1784 (file-name-nondirectory file1))
1786 ;; make ediff-startup pass
1787 ;; ediff-control-buffer back to the meta
1790 (quote ,info) ediff-control-buffer))))
1792 ((ediff-one-filegroup-metajob) ; needs 1 file arg
1793 (funcall ediff-session-action-function
1795 ;; provide startup hooks
1798 'ediff-after-quit-hook-internal
1800 (if (ediff-buffer-live-p
1802 (ediff-show-meta-buffer
1806 (setq ediff-meta-buffer ,(current-buffer)
1807 ediff-meta-session-number
1809 (setq ediff-merge-store-file
1810 ,(if (ediff-nonempty-string-p
1811 merge-autostore-dir)
1814 ediff-merge-filename-prefix
1815 (file-name-nondirectory file1))) )
1816 ;; make ediff-startup pass
1817 ;; ediff-control-buffer back to the meta
1820 (quote ,info) ediff-control-buffer)))))
1821 ((not (ediff-metajob3)) ; need 2 file args
1822 (funcall ediff-session-action-function
1824 ;; provide startup hooks
1827 'ediff-after-quit-hook-internal
1829 (if (ediff-buffer-live-p
1831 (ediff-show-meta-buffer
1835 (setq ediff-meta-buffer ,(current-buffer)
1836 ediff-meta-session-number
1838 (setq ediff-merge-store-file
1839 ,(if (ediff-nonempty-string-p
1840 merge-autostore-dir)
1843 ediff-merge-filename-prefix
1844 (file-name-nondirectory file1))) )
1845 ;; make ediff-startup pass
1846 ;; ediff-control-buffer back to the meta
1849 (quote ,info) ediff-control-buffer)))))
1850 ((ediff-metajob3) ; need 3 file args
1851 (funcall ediff-session-action-function
1853 ;; arrange startup hooks
1856 'ediff-after-quit-hook-internal
1858 (if (ediff-buffer-live-p
1860 (ediff-show-meta-buffer
1864 (setq ediff-merge-store-file
1865 ,(if (ediff-nonempty-string-p
1866 merge-autostore-dir)
1869 ediff-merge-filename-prefix
1870 (file-name-nondirectory file1))) )
1871 (setq ediff-meta-buffer , (current-buffer)
1872 ediff-meta-session-number
1874 ;; this arranges that ediff-startup will pass
1875 ;; the value of ediff-control-buffer back to
1876 ;; the meta level, to the record in the meta
1877 ;; list containing the information about the
1878 ;; session associated with that
1879 ;; ediff-control-buffer
1881 (quote ,info) ediff-control-buffer)))))
1883 ) ; eval in meta-buf
1886 (defun ediff-registry-action ()
1887 "Switch to a selected session."
1889 (let* ((pos (ediff-event-point last-command-event))
1890 (buf (ediff-event-buffer last-command-event))
1891 (ctl-buf (ediff-get-meta-info buf pos)))
1893 (if (ediff-buffer-live-p ctl-buf)
1894 ;; check if this is ediff-control-buffer or ediff-meta-buffer
1895 (if (ediff-with-current-buffer ctl-buf
1896 (eq (key-binding "q") 'ediff-quit-meta-buffer))
1897 ;; it's a meta-buffer -- last action should just display it
1898 (ediff-show-meta-buffer ctl-buf t)
1899 ;; it's a session buffer -- invoke go back to session
1900 (ediff-with-current-buffer ctl-buf
1901 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1902 (ediff-recenter 'no-rehighlight)))
1904 (message "You've selected a stale session --- try again")
1905 (ediff-update-registry))
1906 (ediff-with-current-buffer buf
1911 ;; If session number is t, means don't update meta buffer
1912 (defun ediff-show-meta-buffer (&optional meta-buf session-number)
1913 "Show the session group buffer."
1915 (run-hooks 'ediff-before-directory-setup-hooks)
1916 (let (wind frame silent)
1917 (if meta-buf (setq silent t))
1919 (setq meta-buf (or meta-buf ediff-meta-buffer))
1920 (cond ((not (bufferp meta-buf))
1921 (error "This Ediff session is not part of a session group"))
1922 ((not (ediff-buffer-live-p meta-buf))
1924 "Can't find this session's group panel -- session itself is ok")))
1926 (cond ((numberp session-number)
1927 (ediff-update-meta-buffer meta-buf nil session-number))
1928 ;; if session-number is t, don't update
1930 (t (ediff-cleanup-meta-buffer meta-buf)))
1932 (ediff-with-current-buffer meta-buf
1934 (cond ((setq wind (ediff-get-visible-buffer-window meta-buf))
1937 "Already showing the group panel for this session"))
1938 (set-window-buffer wind meta-buf)
1939 (select-window wind))
1940 ((window-live-p (setq wind ediff-window-C)) ;in merge--merge buf
1941 (set-window-buffer ediff-window-C meta-buf)
1942 (select-window wind))
1943 ((window-live-p (setq wind ediff-window-A))
1944 (set-window-buffer ediff-window-A meta-buf)
1945 (select-window wind))
1946 ((window-live-p (setq wind ediff-window-B))
1947 (set-window-buffer ediff-window-B meta-buf)
1948 (select-window wind))
1951 (ediff-get-visible-buffer-window ediff-registry-buffer))
1952 (ediff-window-display-p))
1953 (select-window wind)
1955 (set-window-buffer (selected-window) meta-buf))
1956 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1957 (set-window-buffer (selected-window) meta-buf)))
1959 (if (and (ediff-window-display-p)
1961 (setq wind (ediff-get-visible-buffer-window meta-buf))))
1963 (setq frame (window-frame wind))
1965 (ediff-reset-mouse frame)))
1966 (sit-for 0) ; sometimes needed to synch the display and ensure that the
1967 ; point ends up after the just completed session
1968 (run-hooks 'ediff-show-session-group-hook)
1971 (defun ediff-show-current-session-meta-buffer ()
1973 (ediff-show-meta-buffer nil ediff-meta-session-number))
1975 (defun ediff-show-meta-buff-from-registry ()
1976 "Display the session group buffer for a selected session group."
1978 (let* ((pos (ediff-event-point last-command-event))
1979 (meta-buf (ediff-event-buffer last-command-event))
1980 (info (ediff-get-meta-info meta-buf pos))
1981 (meta-or-session-buf info))
1982 (ediff-with-current-buffer meta-or-session-buf
1983 (ediff-show-meta-buffer nil t))))
1986 (defun ediff-show-registry ()
1987 "Display Ediff's registry."
1989 (ediff-update-registry)
1990 (if (not (ediff-buffer-live-p ediff-registry-buffer))
1991 (error "No active Ediff sessions or corrupted session registry"))
1993 ;; for some reason, point moves in ediff-registry-buffer, so we preserve it
1995 (ediff-with-current-buffer ediff-registry-buffer
1998 (ediff-get-visible-buffer-window ediff-registry-buffer))
1999 (message "Already showing the registry")
2000 (set-window-buffer wind ediff-registry-buffer)
2001 (select-window wind))
2002 ((window-live-p ediff-window-C)
2003 (set-window-buffer ediff-window-C ediff-registry-buffer)
2004 (select-window ediff-window-C))
2005 ((window-live-p ediff-window-A)
2006 (set-window-buffer ediff-window-A ediff-registry-buffer)
2007 (select-window ediff-window-A))
2008 ((window-live-p ediff-window-B)
2009 (set-window-buffer ediff-window-B ediff-registry-buffer)
2010 (select-window ediff-window-B))
2012 (ediff-get-visible-buffer-window ediff-meta-buffer))
2013 (ediff-window-display-p))
2014 (select-window wind)
2016 (set-window-buffer (selected-window) ediff-registry-buffer))
2017 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
2018 (set-window-buffer (selected-window) ediff-registry-buffer)))
2020 (if (ediff-window-display-p)
2024 (ediff-get-visible-buffer-window ediff-registry-buffer)))
2026 (ediff-reset-mouse frame)))
2027 (run-hooks 'ediff-show-registry-hook)
2031 (defalias 'eregistry 'ediff-show-registry)
2033 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a
2035 ;; Check if META-BUF exists before calling this function
2036 ;; Optional MUST-REDRAW, if non-nil, would force redrawal of the whole meta
2037 ;; buffer. Otherwise, it will just go over the buffer and update activity marks
2038 ;; and session status.
2039 ;; SESSION-NUMBER, if specified, says which session caused the update.
2040 (defun ediff-update-meta-buffer (meta-buf &optional must-redraw session-number)
2041 (if (ediff-buffer-live-p meta-buf)
2042 (ediff-with-current-buffer meta-buf
2044 (cond (must-redraw ; completely redraw the meta buffer
2045 (funcall ediff-meta-redraw-function ediff-meta-list))
2046 ((numberp session-number) ; redraw only for the given session
2047 (ediff-update-session-marker-in-dir-meta-buffer
2049 (t ; update what changed only, but scan the entire meta buffer
2050 (ediff-update-markers-in-dir-meta-buffer ediff-meta-list)))
2051 (setq overl (ediff-get-meta-overlay-at-pos (point)))
2052 ;; skip the invisible sessions
2053 (while (and overl (ediff-overlay-get overl 'invisible))
2054 (ediff-next-meta-item1)
2055 (setq overl (ediff-get-meta-overlay-at-pos (point))))
2058 (defun ediff-update-registry ()
2059 (ediff-with-current-buffer (current-buffer)
2060 (if (ediff-buffer-live-p ediff-registry-buffer)
2061 (ediff-redraw-registry-buffer)
2062 (ediff-prepare-meta-buffer
2063 'ediff-registry-action
2064 ediff-session-registry
2066 'ediff-redraw-registry-buffer
2070 ;; If meta-buf exists, it is redrawn along with parent.
2071 ;; Otherwise, nothing happens.
2072 (defun ediff-cleanup-meta-buffer (meta-buffer)
2073 (if (ediff-buffer-live-p meta-buffer)
2074 (ediff-with-current-buffer meta-buffer
2075 (ediff-update-meta-buffer meta-buffer)
2076 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
2077 (ediff-update-meta-buffer
2078 ediff-parent-meta-buffer nil ediff-meta-session-number)))))
2080 ;; t if no session is in progress
2081 (defun ediff-safe-to-quit (meta-buffer)
2082 (if (ediff-buffer-live-p meta-buffer)
2083 (let ((lis ediff-meta-list)
2086 ;;(ediff-update-meta-buffer meta-buffer)
2087 (ediff-with-current-buffer meta-buffer
2088 (setq lis (cdr lis)) ; discard the description part of meta-list
2089 (while (and cont lis)
2090 (if (ediff-buffer-live-p
2091 (ediff-get-group-buffer lis)) ; in progress
2093 (setq lis (cdr lis)))
2096 (defun ediff-quit-meta-buffer ()
2097 "If the group has no active session, delete the meta buffer.
2098 If no session is in progress, ask to confirm before deleting meta buffer.
2099 Otherwise, bury the meta buffer.
2100 If this is a session registry buffer then just bury it."
2102 (let* ((buf (current-buffer))
2103 (dir-diffs-buffer ediff-dir-diffs-buffer)
2104 (meta-diff-buffer ediff-meta-diff-buffer)
2105 (session-number ediff-meta-session-number)
2106 (parent-buf ediff-parent-meta-buffer)
2107 (dont-show-registry (eq buf ediff-registry-buffer)))
2108 (if dont-show-registry
2110 ;;(ediff-cleanup-meta-buffer buf)
2111 (cond ((and (ediff-safe-to-quit buf)
2112 (y-or-n-p "Quit this session group? "))
2113 (run-hooks 'ediff-quit-session-group-hook)
2115 (ediff-dispose-of-meta-buffer buf))
2116 ((ediff-safe-to-quit buf)
2120 "This session group has active sessions---cannot exit")))
2121 (ediff-update-meta-buffer parent-buf nil session-number)
2122 (ediff-kill-buffer-carefully dir-diffs-buffer)
2123 (ediff-kill-buffer-carefully meta-diff-buffer)
2124 (if (ediff-buffer-live-p parent-buf)
2126 (setq dont-show-registry t)
2127 (ediff-show-meta-buffer parent-buf session-number)))
2129 (or dont-show-registry
2130 (ediff-show-registry))))
2132 (defun ediff-dispose-of-meta-buffer (buf)
2133 (setq ediff-session-registry (delq buf ediff-session-registry))
2134 (ediff-with-current-buffer buf
2135 (if (ediff-buffer-live-p ediff-dir-diffs-buffer)
2136 (kill-buffer ediff-dir-diffs-buffer)))
2140 ;; Obtain information on a meta record where the user clicked or typed
2141 ;; BUF is the buffer where this happened and POINT is the position
2142 ;; If optional NOERROR arg is given, don't report error and return nil if no
2143 ;; meta info is found on line.
2144 (defun ediff-get-meta-info (buf point &optional noerror)
2145 (let (result olist tmp)
2146 (if (and point (ediff-buffer-live-p buf))
2147 (ediff-with-current-buffer buf
2148 (ediff-cond-compile-for-xemacs-or-emacs
2149 (setq result ; xemacs
2150 (if (setq tmp (extent-at point buf 'ediff-meta-info))
2151 (ediff-overlay-get tmp 'ediff-meta-info)))
2153 (setq olist (overlays-at point))
2155 (mapcar (lambda (elt)
2156 (unless (overlay-get elt 'invisible)
2157 (overlay-get elt 'ediff-meta-info)))
2159 (while (and olist (null (car olist)))
2160 (setq olist (cdr olist)))
2161 (setq result (car olist)))
2168 (ediff-update-registry)
2169 (error "No session info in this line")))))
2172 (defun ediff-get-meta-overlay-at-pos (point)
2173 (ediff-cond-compile-for-xemacs-or-emacs
2174 (extent-at point (current-buffer) 'ediff-meta-info) ; xemacs
2176 (let* ((overl-list (overlays-at point))
2177 (overl (car overl-list)))
2178 (while (and overl (null (overlay-get overl 'ediff-meta-info)))
2179 (setq overl-list (cdr overl-list)
2180 overl (car overl-list)))
2185 (defsubst ediff-get-session-number-at-pos (point &optional meta-buffer)
2186 (setq meta-buffer (if (ediff-buffer-live-p meta-buffer)
2189 (ediff-with-current-buffer meta-buffer
2191 (ediff-get-meta-overlay-at-pos point) 'ediff-meta-session-number)))
2194 ;; Return location of the next meta overlay after point
2195 (defun ediff-next-meta-overlay-start (point)
2197 (goto-char (point-min))
2198 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2199 (ediff-cond-compile-for-xemacs-or-emacs
2202 (setq overl (next-extent overl))
2203 (setq overl (next-extent (current-buffer))))
2205 (extent-start-position overl)
2209 ;; note: end of current overlay is the beginning of the next one
2211 (next-overlay-change point))
2217 (defun ediff-previous-meta-overlay-start (point)
2219 (goto-char (point-max))
2220 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2221 (ediff-cond-compile-for-xemacs-or-emacs
2224 (setq overl (previous-extent overl))
2225 (setq overl (previous-extent (current-buffer))))
2227 (extent-start-position overl)
2230 (if overl (setq point (overlay-start overl)))
2231 ;; to get to the beginning of prev overlay
2233 ;; trick to overcome an emacs bug--doesn't always find previous
2234 ;; overlay change correctly
2235 (setq point (1- point)))
2236 (setq point (previous-overlay-change point))
2237 ;; If we are not over an overlay after subtracting 1, it means we are
2238 ;; in the description area preceding session records. In this case,
2239 ;; goto the top of the registry buffer.
2240 (or (car (overlays-at point))
2241 (setq point (point-min)))
2246 ;; this is the action invoked when the user selects a patch from the meta
2248 (defun ediff-patch-file-form-meta (file &optional startup-hooks)
2249 (let* ((pos (ediff-event-point last-command-event))
2250 (meta-buf (ediff-event-buffer last-command-event))
2251 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
2252 (info (ediff-get-meta-info meta-buf pos))
2253 (meta-patchbuf ediff-meta-patchbufer)
2254 session-buf beg-marker end-marker)
2256 (if (or (file-directory-p file) (string-match "/dev/null" file))
2257 (error "`%s' is not an ordinary file" (file-name-as-directory file)))
2258 (setq session-buf (ediff-get-session-buffer info)
2259 beg-marker (ediff-get-session-objB-name info)
2260 end-marker (ediff-get-session-objC-name info))
2262 (or (ediff-buffer-live-p session-buf) ; either an active patch session
2263 (null session-buf) ; or it is a virgin session
2265 "Patch has already been applied to this file -- can't repeat!"))
2267 (ediff-with-current-buffer meta-patchbuf
2270 (narrow-to-region beg-marker end-marker)
2271 (ediff-patch-file-internal meta-patchbuf file startup-hooks)))))
2274 (defun ediff-unmark-all-for-operation ()
2275 "Unmark all sessions marked for operation."
2277 (let ((list (cdr ediff-meta-list))
2279 (while (setq elt (car list))
2280 (ediff-mark-session-for-operation elt 'unmark)
2281 (setq list (cdr list))))
2282 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2284 (defun ediff-unmark-all-for-hiding ()
2285 "Unmark all sessions marked for hiding."
2287 (let ((list (cdr ediff-meta-list))
2289 (while (setq elt (car list))
2290 (ediff-mark-session-for-hiding elt 'unmark)
2291 (setq list (cdr list))))
2292 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2295 ;; ACTION is ?h, ?m, ?=: to mark for hiding, mark for operation, or simply
2296 ;; indicate which are equal files
2297 (defun ediff-meta-mark-equal-files (&optional action)
2298 "Run through the session list and mark identical files.
2299 This is used only for sessions that involve 2 or 3 files at the same time.
2300 ACTION is an optional argument that can be ?h, ?m, ?=, to mark for hiding, mark
2301 for operation, or simply indicate which are equal files. If it is nil, then
2302 last-command-char is used to decide which action to take."
2305 (setq action last-command-char))
2306 (let ((list (cdr ediff-meta-list))
2307 marked1 marked2 marked3
2308 fileinfo1 fileinfo2 fileinfo3 elt)
2309 (message "Comparing files ...")
2310 (while (setq elt (car list))
2311 (setq fileinfo1 (ediff-get-session-objA elt)
2312 fileinfo2 (ediff-get-session-objB elt)
2313 fileinfo3 (ediff-get-session-objC elt))
2314 (ediff-set-file-eqstatus fileinfo1 nil)
2315 (ediff-set-file-eqstatus fileinfo2 nil)
2316 (ediff-set-file-eqstatus fileinfo3 nil)
2321 (or (ediff-mark-if-equal fileinfo1 fileinfo2)
2323 (if (ediff-metajob3)
2325 (or (ediff-mark-if-equal fileinfo1 fileinfo3)
2327 (or (ediff-mark-if-equal fileinfo2 fileinfo3)
2328 (setq marked3 nil))))
2329 (if (and marked1 marked2 marked3)
2330 (cond ((eq action ?h)
2331 (ediff-mark-session-for-hiding elt 'mark))
2333 (ediff-mark-session-for-operation elt 'mark))
2335 (setq list (cdr list)))
2336 (message "Comparing files ... Done"))
2337 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2339 ;; mark files 1 and 2 as equal, if they are.
2340 ;; returns t, if something was marked
2341 (defun ediff-mark-if-equal (fileinfo1 fileinfo2)
2342 (let ((f1 (car fileinfo1))
2343 (f2 (car fileinfo2)))
2344 (cond ((file-directory-p f1) nil)
2345 ((file-directory-p f2) nil)
2346 ((ediff-same-file-contents f1 f2)
2347 (ediff-set-file-eqstatus fileinfo1 t)
2348 (ediff-set-file-eqstatus fileinfo2 t)
2354 ;;; Local Variables:
2355 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
2356 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
2357 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
2360 ;;; ediff-mult.el ends here