1 ;;; ediff-mult.el --- support for multi-file/multi-buffer processing in Ediff
3 ;; Copyright (C) 1995, 96, 97, 98, 99, 2000, 01, 02, 05 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., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, 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 ;; t means recurse into subdirs when deciding which files have same contents
171 (ediff-defvar-local ediff-recurse-to-subdirectories nil
"")
173 ;; history var to use for filtering groups of files
174 (defvar ediff-filtering-regexp-history nil
"")
176 (defcustom ediff-default-filtering-regexp nil
177 "The default regular expression used as a filename filter in multifile comparisons.
178 Should be a sexp. For instance (car ediff-filtering-regexp-history) or nil."
182 ;; This has the form ((meta-buf regexp dir1 dir2 dir3 merge-auto-store-dir)
183 ;; (ctl-buf session-status (file1 . eq-status) (file2 . eq-status) (file3
184 ;; . eq-status)) (ctl-buf session-status (file1 . eq-status) (file2
185 ;; . eq-status)) ...)
186 ;; If ctl-buf is nil, the file-pair hasn't processed yet. If it is
187 ;; killed-buffer object, the file pair has been processed. If it is a live
188 ;; buffer, this means ediff is still working on the pair.
189 ;; Eq-status of a file is t if the file equals some other file in the same
191 (ediff-defvar-local ediff-meta-list nil
"")
193 (ediff-defvar-local ediff-meta-session-number nil
"")
196 ;; the difference list between directories in a directory session group
197 (ediff-defvar-local ediff-dir-difference-list nil
"")
198 (ediff-defvar-local ediff-dir-diffs-buffer nil
"")
200 ;; The registry of Ediff sessions. A list of control buffers.
201 (defvar ediff-session-registry nil
)
203 (defcustom ediff-meta-truncate-filenames t
204 "*If non-nil, truncate long file names in the session group buffers.
205 This can be toggled with `ediff-toggle-filename-truncation'."
209 (defcustom ediff-meta-mode-hook nil
210 "*Hooks run just after setting up meta mode."
214 (defcustom ediff-registry-setup-hook nil
215 "*Hooks run just after the registry control panel is set up."
219 (defcustom ediff-before-session-group-setup-hooks nil
220 "*Hooks to run before Ediff arranges the window for group-level operations.
221 It is used by commands such as ediff-directories.
222 This hook can be used to save the previous window config, which can be restored
223 on ediff-quit, ediff-suspend, or ediff-quit-session-group-hook."
226 (defcustom ediff-after-session-group-setup-hook nil
227 "*Hooks run just after a meta-buffer controlling a session group, such as
228 ediff-directories, is run."
231 (defcustom ediff-quit-session-group-hook nil
232 "*Hooks run just before exiting a session group."
235 (defcustom ediff-show-registry-hook nil
236 "*Hooks run just after the registry buffer is shown."
239 (defcustom ediff-show-session-group-hook
'(delete-other-windows)
240 "*Hooks run just after a session group buffer is shown."
243 (defcustom ediff-meta-buffer-keymap-setup-hook nil
244 "*Hooks run just after setting up the ediff-meta-buffer-map.
245 This keymap controls key bindings in the meta buffer and is a local variable.
246 This means that you can set different bindings for different kinds of meta
251 ;; Buffer holding the multi-file patch. Local to the meta buffer
252 (ediff-defvar-local ediff-meta-patchbufer nil
"")
254 ;;; API for ediff-meta-list
256 ;; A meta-list is either ediff-meta-list, which contains a header and the list
257 ;; of ediff sessions or ediff-dir-difference-list, which is a header followed
258 ;; by the list of differences among the directories (i.e., files that are not
259 ;; in all directories). The header is the same in all meta lists, but the rest
261 ;; Structure of the meta-list:
262 ;; (HEADER SESSION1 SESSION2 ...)
263 ;; HEADER: (GROUP-BUF REGEXP OBJA OBJB OBJC SAVE-DIR COMPARISON-FUNC)
264 ;; OBJA - first directory
265 ;; OBJB - second directory
266 ;; OBJC - third directory
267 ;; SESSION1/2/... are described below
268 ;; group buffer/regexp
269 (defsubst ediff-get-group-buffer
(meta-list)
270 (nth 0 (car meta-list
)))
272 (defsubst ediff-get-group-regexp
(meta-list)
273 (nth 1 (car meta-list
)))
275 (defsubst ediff-get-group-objA
(meta-list)
276 (nth 2 (car meta-list
)))
277 (defsubst ediff-get-group-objB
(meta-list)
278 (nth 3 (car meta-list
)))
279 (defsubst ediff-get-group-objC
(meta-list)
280 (nth 4 (car meta-list
)))
281 (defsubst ediff-get-group-merge-autostore-dir
(meta-list)
282 (nth 5 (car meta-list
)))
283 (defsubst ediff-get-group-comparison-func
(meta-list)
284 (nth 6 (car meta-list
)))
286 ;; ELT is a session meta descriptor (what is being preserved as
288 ;; The structure is: (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
289 ;; STATUS is ?I (hidden or invalid), ?* (marked for operation), ?H (hidden)
291 ;; OBJA/B/C is (FILENAME EQSTATUS)
292 ;; EQSTATUS is ?= or nil (?= means that this file is equal to some other
293 ;; file in this session)
295 (defsubst ediff-get-session-buffer
(elt)
297 (defsubst ediff-get-session-status
(elt)
299 (defsubst ediff-set-session-status
(session-info new-status
)
300 (setcar (cdr session-info
) new-status
))
302 (defsubst ediff-get-session-objA
(elt)
304 (defsubst ediff-get-session-objB
(elt)
306 (defsubst ediff-get-session-objC
(elt)
308 ;; Take the "name" component of the object into acount. ObjA/C/B is of the form
309 ;; (name . equality-indicator)
310 (defsubst ediff-get-session-objA-name
(elt)
312 (defsubst ediff-get-session-objB-name
(elt)
314 (defsubst ediff-get-session-objC-name
(elt)
316 ;; equality indicators
317 (defsubst ediff-get-file-eqstatus
(elt)
319 (defsubst ediff-set-file-eqstatus
(elt value
)
320 (setcar (cdr elt
) value
))
322 ;; Create a new element for the meta list out of obj1/2/3, which usually are
325 ;; The first nil in such an element is later replaced with the session buffer.
326 ;; The second nil is reserved for session status.
328 ;; Also, session objects A/B/C are turned into lists of the form (obj nil).
329 ;; This nil is a placeholder for eq-indicator. It is either nil or =.
330 ;; If it is discovered that this file is = to some other
331 ;; file in the same session, eq-indicator is changed to `='.
332 ;; Curently, the eq-indicator is used only for 2 and 3-file jobs.
333 (defun ediff-make-new-meta-list-element (obj1 obj2 obj3
)
334 (list nil nil
(list obj1 nil
) (list obj2 nil
) (list obj3 nil
)))
336 ;; Constructs a meta list header.
337 ;; OBJA, OBJB, OBJC are usually directories involved, but can be different for
338 ;; different jobs. For instance, multifile patch has only OBJA, which is the
340 (defun ediff-make-new-meta-list-header (regexp
344 (list regexp objA objB objC merge-auto-store-dir comparison-func
))
346 ;; The activity marker is either or + (active session, i.e., ediff is currently
347 ;; run in it), or - (finished session, i.e., we've ran ediff in it and then
348 ;; exited). Return nil, if session is neither active nor finished
349 (defun ediff-get-session-activity-marker (session)
350 (let ((session-buf (ediff-get-session-buffer session
)))
351 (cond ((null session-buf
) nil
) ; virgin session
352 ((ediff-buffer-live-p session-buf
) ?
+) ;active session
355 ;; checks if the session is a meta session
356 (defun ediff-meta-session-p (session-info)
357 (and (stringp (ediff-get-session-objA-name session-info
))
358 (file-directory-p (ediff-get-session-objA-name session-info
))
359 (stringp (ediff-get-session-objB-name session-info
))
360 (file-directory-p (ediff-get-session-objB-name session-info
))
361 (if (stringp (ediff-get-session-objC-name session-info
))
362 (file-directory-p (ediff-get-session-objC-name session-info
)) t
)))
364 ;; set up the keymap in the meta buffer
365 (defun ediff-setup-meta-map()
366 (setq ediff-meta-buffer-map
(make-sparse-keymap))
367 (suppress-keymap ediff-meta-buffer-map
)
368 (define-key ediff-meta-buffer-map
"q" 'ediff-quit-meta-buffer
)
369 (define-key ediff-meta-buffer-map
"T" 'ediff-toggle-filename-truncation
)
370 (define-key ediff-meta-buffer-map
"R" 'ediff-show-registry
)
371 (define-key ediff-meta-buffer-map
"E" 'ediff-documentation
)
372 (define-key ediff-meta-buffer-map
"v" ediff-meta-action-function
)
373 (define-key ediff-meta-buffer-map
"\C-m" ediff-meta-action-function
)
374 (define-key ediff-meta-buffer-map
" " 'ediff-next-meta-item
)
375 (define-key ediff-meta-buffer-map
"n" 'ediff-next-meta-item
)
376 (define-key ediff-meta-buffer-map
"\C-?" 'ediff-previous-meta-item
)
377 (define-key ediff-meta-buffer-map
"p" 'ediff-previous-meta-item
)
378 (define-key ediff-meta-buffer-map
[delete] 'ediff-previous-meta-item)
379 (define-key ediff-meta-buffer-map [backspace] 'ediff-previous-meta-item)
380 (or (ediff-one-filegroup-metajob)
382 (define-key ediff-meta-buffer-map "=" nil)
383 (define-key ediff-meta-buffer-map "==" 'ediff-meta-mark-equal-files)
384 (define-key ediff-meta-buffer-map "=m" 'ediff-meta-mark-equal-files)
385 (define-key ediff-meta-buffer-map "=h" 'ediff-meta-mark-equal-files)))
386 (if ediff-no-emacs-help-in-control-buffer
387 (define-key ediff-meta-buffer-map "\C-h" 'ediff-previous-meta-item))
389 (define-key ediff-meta-buffer-map [mouse-2] ediff-meta-action-function)
390 (define-key ediff-meta-buffer-map [button2] ediff-meta-action-function))
392 (use-local-map ediff-meta-buffer-map)
393 ;; modify ediff-meta-buffer-map here
394 (run-hooks 'ediff-meta-buffer-keymap-setup-hook))
397 (defun ediff-meta-mode ()
398 "This mode controls all operations on Ediff session groups.
399 It is entered through one of the following commands:
404 `ediff-merge-directories'
406 `ediff-merge-directories-with-ancestor'
407 `edirs-merge-with-ancestor'
408 `ediff-directory-revisions'
410 `ediff-merge-directory-revisions'
411 `edir-merge-revisions'
412 `ediff-merge-directory-revisions-with-ancestor'
413 `edir-merge-revisions-with-ancestor'
416 \\{ediff-meta-buffer-map}"
417 (kill-all-local-variables)
418 (setq major-mode 'ediff-meta-mode)
419 (setq mode-name "MetaEdiff")
420 ;; don't use run-mode-hooks here!
421 (run-hooks 'ediff-meta-mode-hook))
424 ;; the keymap for the buffer showing directory differences
425 (suppress-keymap ediff-dir-diffs-buffer-map)
426 (define-key ediff-dir-diffs-buffer-map "q" 'ediff-bury-dir-diffs-buffer)
427 (define-key ediff-dir-diffs-buffer-map " " 'next-line)
428 (define-key ediff-dir-diffs-buffer-map "n" 'next-line)
429 (define-key ediff-dir-diffs-buffer-map "\C-?" 'previous-line)
430 (define-key ediff-dir-diffs-buffer-map "p" 'previous-line)
431 (define-key ediff-dir-diffs-buffer-map "C" 'ediff-dir-diff-copy-file)
433 (define-key ediff-dir-diffs-buffer-map [mouse-2] 'ediff-dir-diff-copy-file)
434 (define-key ediff-dir-diffs-buffer-map [button2] 'ediff-dir-diff-copy-file))
435 (define-key ediff-dir-diffs-buffer-map [delete] 'previous-line
)
436 (define-key ediff-dir-diffs-buffer-map
[backspace] 'previous-line)
438 (defun ediff-next-meta-item (count)
439 "Move to the next item in Ediff registry or session group buffer.
440 Moves in circular fashion. With numeric prefix arg, skip this many items."
442 (or count (setq count 1))
445 (setq count (1- count))
446 (ediff-next-meta-item1)
447 (setq overl (ediff-get-meta-overlay-at-pos (point)))
448 ;; skip invisible ones
449 (while (and overl (ediff-overlay-get overl 'invisible))
450 (ediff-next-meta-item1)
451 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
453 ;; Move to the next meta item
454 (defun ediff-next-meta-item1 ()
456 (setq pos (ediff-next-meta-overlay-start (point)))
457 (if pos (goto-char pos))
458 (if (eq ediff-metajob-name 'ediff-registry)
459 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
460 (search-forward "*Ediff" nil t))
461 (skip-chars-backward "a-zA-Z*"))
462 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
463 (backward-char 1)))))
466 (defun ediff-previous-meta-item (count)
467 "Move to the previous item in Ediff registry or session group buffer.
468 Moves in circular fashion. With numeric prefix arg, skip this many items."
470 (or count (setq count 1))
473 (setq count (1- count))
474 (ediff-previous-meta-item1)
475 (setq overl (ediff-get-meta-overlay-at-pos (point)))
476 ;; skip invisible ones
477 (while (and overl (ediff-overlay-get overl 'invisible))
478 (ediff-previous-meta-item1)
479 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
481 (defun ediff-previous-meta-item1 ()
483 (setq pos (ediff-previous-meta-overlay-start (point)))
485 ;;; (while (ediff-get-session-status
486 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
487 ;;; (setq pos (ediff-previous-meta-overlay-start pos)))
489 (if pos (goto-char pos))
490 (if (eq ediff-metajob-name 'ediff-registry)
491 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
492 (search-forward "*Ediff" nil t))
493 (skip-chars-backward "a-zA-Z*"))
494 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
498 (defsubst ediff-add-slash-if-directory (dir file)
499 (if (file-directory-p (concat dir file))
500 (file-name-as-directory file)
503 (defun ediff-toggle-filename-truncation ()
504 "Toggle truncation of long file names in session group buffers.
505 Set `ediff-meta-truncate-filenames' variable if you want to change the default
508 (setq ediff-meta-truncate-filenames (not ediff-meta-truncate-filenames))
509 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
512 ;; These are used to encode membership of files in directory1/2/3
513 ;; Membership code of a file is a product of codes for the directories where
515 (defvar ediff-membership-code1 2)
516 (defvar ediff-membership-code2 3)
517 (defvar ediff-membership-code3 5)
518 (defvar ediff-product-of-memcodes (* ediff-membership-code1
519 ediff-membership-code2
520 ediff-membership-code3))
522 ;; DIR1, DIR2, DIR3 are directories. DIR3 can be nil.
523 ;; OUTPUT-DIR is a directory for auto-storing the results of merge jobs.
525 ;; REGEXP is nil or a filter regexp; only file names that match the regexp
527 ;; If a file is a directory in dir1 but not dir2 (or vice versa), it is not
528 ;; included in the intersection. However, a regular file that is a dir in dir3
529 ;; is included, since dir3 files are supposed to be ancestors for merging.
530 ;; If COMPARISON-FUNC is given, use it. Otherwise, use string=
532 ;; Returns a list of the form:
533 ;; (COMMON-PART DIFF-LIST)
534 ;; COMMON-PART is car and DIFF-LIST is cdr.
536 ;; COMMON-PART is of the form:
537 ;; (META-HEADER (f1 f2 f3) (f1 f2 f3) ...)
538 ;; f3 can be nil if intersecting only 2 directories.
539 ;; Each triple (f1 f2 f3) represents the files to be compared in the
540 ;; corresponding ediff subsession.
542 ;; DIFF-LIST is of the form:
543 ;; (META-HEADER (file . num) (file . num)...)
544 ;; where num encodes the set of dirs where the file is found:
545 ;; 2 - only dir1; 3 - only dir2; 5 - only dir3; 6 - dir1&2; 10 - dir1&3; etc.
547 ;; Contains the meta info about this ediff operation
548 ;; (regexp dir1 dir2 dir3 merge-auto-store-dir comparison-func)
549 ;; Later the meta-buffer is prepended to this list.
551 ;; Some operations might use a different meta header. For instance,
552 ;; ediff-multifile-patch doesn't have dir2 and dir3, and regexp,
553 ;; comparison-func don't apply.
555 (defun ediff-intersect-directories (jobname
558 dir3 merge-autostore-dir comparison-func)
559 (setq comparison-func (or comparison-func 'string=))
560 (let (lis1 lis2 lis3 common auxdir1 auxdir2 auxdir3 common-part difflist)
562 (setq auxdir1 (file-name-as-directory dir1)
563 lis1 (directory-files auxdir1 nil regexp)
564 lis1 (delete "." lis1)
565 lis1 (delete ".." lis1)
568 (ediff-add-slash-if-directory auxdir1 elt))
570 auxdir2 (file-name-as-directory dir2)
571 lis2 (directory-files auxdir2 nil regexp)
572 lis2 (delete "." lis2)
573 lis2 (delete ".." lis2)
576 (ediff-add-slash-if-directory auxdir2 elt))
580 (setq auxdir3 (file-name-as-directory dir3)
581 lis3 (directory-files auxdir3 nil regexp)
582 lis3 (delete "." lis3)
583 lis3 (delete ".." lis3)
586 (ediff-add-slash-if-directory auxdir3 elt))
589 (if (ediff-nonempty-string-p merge-autostore-dir)
590 (setq merge-autostore-dir
591 (file-name-as-directory merge-autostore-dir)))
592 (setq common (ediff-intersection lis1 lis2 comparison-func))
594 ;; In merge with ancestor jobs, we don't intersect with lis3.
595 ;; If there is no ancestor, we'll offer to merge without the ancestor.
596 ;; So, we intersect with lis3 only when we are doing 3-way file comparison
597 (if (and lis3 (ediff-comparison-metajob3 jobname))
598 (setq common (ediff-intersection common lis3 comparison-func)))
600 ;; copying is needed because sort sorts via side effects
601 (setq common (sort (ediff-copy-list common) 'string-lessp))
603 ;; compute difference list
604 (setq difflist (ediff-set-difference
605 (ediff-union (ediff-union lis1 lis2 comparison-func)
610 difflist (delete "." difflist)
611 ;; copying is needed because sort sorts via side effects
612 difflist (sort (ediff-copy-list (delete ".." difflist))
615 (setq difflist (mapcar (lambda (elt) (cons elt 1)) difflist))
617 ;; check for files belonging to lis1/2/3
618 ;; Each elt is of the norm (file . number)
619 ;; Number encodes the directories to which file belongs.
620 ;; It is a product of a subset of ediff-membership-code1=2,
621 ;; ediff-membership-code2=3, and ediff-membership-code3=5.
622 ;; If file belongs to dir 1 only, the membership code is 2.
623 ;; If it is in dir1 and dir3, then the membership code is 2*5=10;
624 ;; if it is in dir1 and dir2, then the membership code is 2*3=6, etc.
625 (mapcar (lambda (elt)
626 (if (member (car elt) lis1)
627 (setcdr elt (* (cdr elt) ediff-membership-code1)))
628 (if (member (car elt) lis2)
629 (setcdr elt (* (cdr elt) ediff-membership-code2)))
630 (if (member (car elt) lis3)
631 (setcdr elt (* (cdr elt) ediff-membership-code3)))
635 ;; diff metalist header
636 (ediff-make-new-meta-list-header regexp
637 auxdir1 auxdir2 auxdir3
645 (ediff-make-new-meta-list-header regexp
646 auxdir1 auxdir2 auxdir3
651 (ediff-make-new-meta-list-element
656 ;; The following is done because: In merging with
657 ;; ancestor, we don't intersect with lis3. So, it is
658 ;; possible that elt is a file in auxdir1/2 but a
659 ;; directory in auxdir3 Or elt may not exist in auxdir3 at
660 ;; all. In the first case, we add a slash at the end. In
661 ;; the second case, we insert nil.
662 (setq elt (ediff-add-slash-if-directory auxdir3 elt))
663 (if (file-exists-p (concat auxdir3 elt))
664 (concat auxdir3 elt))))))
667 (cons common-part difflist)
670 ;; find directory files that are under revision. Include subdirectories, since
671 ;; we may visit them recursively. DIR1 is the directory to inspect.
672 ;; MERGE-AUTOSTORE-DIR is the directory where to auto-store the results of
673 ;; merges. Can be nil.
674 (defun ediff-get-directory-files-under-revision (jobname
676 &optional merge-autostore-dir)
677 (let (lis1 elt common auxdir1)
678 (setq auxdir1 (file-name-as-directory dir1)
679 lis1 (directory-files auxdir1 nil regexp))
681 (if (ediff-nonempty-string-p merge-autostore-dir)
682 (setq merge-autostore-dir
683 (file-name-as-directory merge-autostore-dir)))
688 ;; take files under revision control
689 (cond ((file-directory-p (concat auxdir1 elt))
691 (cons (ediff-add-slash-if-directory auxdir1 elt) common)))
692 ((and (featurep 'vc-hooks) (vc-backend (concat auxdir1 elt)))
693 (setq common (cons elt common)))
694 ;; The following two are needed only if vc-hooks isn't loaded.
695 ;; They won't recognize CVS files.
696 ((file-exists-p (concat auxdir1 elt ",v"))
697 (setq common (cons elt common)))
698 ((file-exists-p (concat auxdir1 "RCS/" elt ",v"))
699 (setq common (cons elt common)))
703 (setq common (delete "./" common)
704 common (delete "../" common)
705 common (delete "RCS" common)
706 common (delete "CVS" common)
709 ;; copying is needed because sort sorts via side effects
710 (setq common (sort (ediff-copy-list common) 'string-lessp))
714 ;; header -- has 6 elements. Meta buffer is prepended later by
715 ;; ediff-prepare-meta-buffer
716 (ediff-make-new-meta-list-header regexp
718 merge-autostore-dir nil)
719 (mapcar (lambda (elt) (ediff-make-new-meta-list-element
720 (concat auxdir1 elt) nil nil))
725 ;; If file groups selected by patterns will ever be implemented, this
726 ;; comparison function might become useful.
727 ;;;; uses external variables PAT1 PAT2 to compare str1/2
728 ;;;; patterns must be of the form ???*???? where ??? are strings of chars
729 ;;;; containing no *.
730 ;;(defun ediff-pattern= (str1 str2)
731 ;; (let (pos11 pos12 pos21 pos22 len1 len2)
733 ;; len (length epat1)
735 ;; (while (and (< pos11 len) (not (= (aref epat1 pos11) ?*)))
736 ;; (setq pos11 (1+ pos11)))
737 ;; (while (and (> pos12 0) (not (= (aref epat1 (1- pos12)) ?*)))
738 ;; (setq pos12 (1- pos12)))
741 ;; len (length epat2)
743 ;; (while (and (< pos21 len) (not (= (aref epat2 pos21) ?*)))
744 ;; (setq pos21 (1+ pos21)))
745 ;; (while (and (> pos22 0) (not (= (aref epat2 (1- pos22)) ?*)))
746 ;; (setq pos22 (1- pos22)))
748 ;; (if (and (> (length str1) pos12) (>= pos12 pos11) (> pos11 -1)
749 ;; (> (length str2) pos22) (>= pos22 pos21) (> pos21 -1))
750 ;; (string= (substring str1 pos11 pos12)
751 ;; (substring str2 pos21 pos22)))
755 ;; Prepare meta-buffer in accordance with the argument-function and
756 ;; redraw-function. Must return the created meta-buffer.
757 (defun ediff-prepare-meta-buffer (action-func meta-list
758 meta-buffer-name redraw-function
759 jobname &optional startup-hooks)
760 (let* ((meta-buffer-name
761 (ediff-unique-buffer-name meta-buffer-name "*"))
762 (meta-buffer (get-buffer-create meta-buffer-name)))
763 (ediff-with-current-buffer meta-buffer
768 (setq ediff-meta-action-function action-func
769 ediff-meta-redraw-function redraw-function
770 ediff-metajob-name jobname
771 ediff-meta-buffer meta-buffer)
773 ;; comes after ediff-meta-action-function is set
774 (ediff-setup-meta-map)
776 (if (eq ediff-metajob-name 'ediff-registry)
778 (setq ediff-registry-buffer meta-buffer
779 ediff-meta-list meta-list)
780 ;; this func is used only from registry buffer, not from other
783 ediff-meta-buffer-map "M" 'ediff-show-meta-buff-from-registry))
784 ;; Initialize the meta list -- we don't do this for registry.
785 (setq ediff-meta-list
786 ;; add meta-buffer to the list header
787 (cons (cons meta-buffer (car meta-list))
790 (or (eq meta-buffer ediff-registry-buffer)
791 (setq ediff-session-registry
792 (cons meta-buffer ediff-session-registry)))
794 ;; redraw-function uses ediff-meta-list
795 (funcall redraw-function ediff-meta-list)
797 ;; set read-only/non-modified
798 (setq buffer-read-only t)
799 (set-buffer-modified-p nil)
801 (run-hooks 'startup-hooks)
803 ;; Arrange to show directory contents differences
804 ;; Must be after run startup-hooks, since ediff-dir-difference-list is
805 ;; set inside these hooks
806 (if (eq action-func 'ediff-filegroup-action)
808 ;; put meta buffer in (car ediff-dir-difference-list)
809 (setq ediff-dir-difference-list
810 (cons (cons meta-buffer (car ediff-dir-difference-list))
811 (cdr ediff-dir-difference-list)))
813 (or (ediff-one-filegroup-metajob jobname)
814 (ediff-draw-dir-diffs ediff-dir-difference-list))
816 ediff-meta-buffer-map "h" 'ediff-mark-for-hiding-at-pos)
817 (define-key ediff-meta-buffer-map "x" 'ediff-hide-marked-sessions)
819 ediff-meta-buffer-map "m" 'ediff-mark-for-operation-at-pos)
820 (define-key ediff-meta-buffer-map "u" nil)
822 ediff-meta-buffer-map "um" 'ediff-unmark-all-for-operation)
824 ediff-meta-buffer-map "uh" 'ediff-unmark-all-for-hiding)
825 (cond ((ediff-collect-diffs-metajob jobname)
827 ediff-meta-buffer-map "P" 'ediff-collect-custom-diffs))
828 ((ediff-patch-metajob jobname)
830 ediff-meta-buffer-map "P" 'ediff-meta-show-patch)))
831 (define-key ediff-meta-buffer-map "^" 'ediff-up-meta-hierarchy)
832 (define-key ediff-meta-buffer-map "D" 'ediff-show-dir-diffs)))
834 (if (eq ediff-metajob-name 'ediff-registry)
835 (run-hooks 'ediff-registry-setup-hook)
836 (run-hooks 'ediff-after-session-group-setup-hook))
837 ) ; eval in meta-buffer
840 ;; Insert the activity marker for session SESSION in the meta buffer at point
841 ;; The activity marker is either SPC (untouched session), or + (active session,
842 ;; i.e., ediff is currently run in it), or - (finished session, i.e., we've ran
843 ;; ediff in it and then exited)
844 (defun ediff-insert-session-activity-marker-in-meta-buffer (session)
846 (cond ((ediff-get-session-activity-marker session))
850 ;; Insert session status at point. Status is either ?H (marked for hiding), or
851 ;; ?I (hidden or invalid), or ?* (meaning marked for an operation; currently,
852 ;; such op can only be checking for equality)), or SPC (meaning neither marked
854 (defun ediff-insert-session-status-in-meta-buffer (session)
856 (cond ((ediff-get-session-status session)) ; session has status: ?H, ?I, ?*
857 ;; normal session, no marks or hidings
860 ;; If NEW-MARKER is non-nil, use it to substitute the current activity marker
861 ;; in the meta buffer. If nil, use SPC
862 (defun ediff-replace-session-activity-marker-in-meta-buffer (point new-marker)
863 (let* ((overl (ediff-get-meta-overlay-at-pos point))
864 (session-info (ediff-overlay-get overl 'ediff-meta-info))
865 (activity-marker (ediff-get-session-activity-marker session-info))
867 (or new-marker activity-marker (setq new-marker ?\s))
868 (goto-char (ediff-overlay-start overl))
869 (if (eq (char-after (point)) new-marker)
870 () ; if marker shown in buffer is the same as new-marker, do nothing
873 (set-buffer-modified-p nil))))
875 ;; If NEW-STATUS is non-nil, use it to substitute the current status marker in
876 ;; the meta buffer. If nil, use SPC
877 (defun ediff-replace-session-status-in-meta-buffer (point new-status)
878 (let* ((overl (ediff-get-meta-overlay-at-pos point))
879 (session-info (ediff-overlay-get overl 'ediff-meta-info))
880 (status (ediff-get-session-status session-info))
882 (setq new-status (or new-status status ?\s))
883 (goto-char (ediff-overlay-start overl))
884 (forward-char 1) ; status is the second char in session record
885 (if (eq (char-after (point)) new-status)
886 () ; if marker shown in buffer is the same as new-marker, do nothing
889 (set-buffer-modified-p nil))))
891 ;; insert all file info in meta buffer for a given session
892 (defun ediff-insert-session-info-in-meta-buffer (session-info sessionNum)
893 (let ((f1 (ediff-get-session-objA session-info))
894 (f2 (ediff-get-session-objB session-info))
895 (f3 (ediff-get-session-objC session-info))
897 (hidden (eq (ediff-get-session-status session-info) ?I)))
898 ;; insert activity marker, i.e., SPC, - or +
899 (ediff-insert-session-activity-marker-in-meta-buffer session-info)
900 ;; insert session status, i.e., *, H
901 (ediff-insert-session-status-in-meta-buffer session-info)
902 (insert " Session " (int-to-string sessionNum) ":\n")
903 (ediff-meta-insert-file-info1 f1)
904 (ediff-meta-insert-file-info1 f2)
905 (ediff-meta-insert-file-info1 f3)
906 (ediff-set-meta-overlay pt (point) session-info sessionNum hidden)))
909 ;; this is a setup function for ediff-directories
910 ;; must return meta-buffer
911 (defun ediff-redraw-directory-group-buffer (meta-list)
912 ;; extract directories
913 (let ((meta-buf (ediff-get-group-buffer meta-list))
916 regexp elt merge-autostore-dir
917 point tmp-list buffer-read-only)
918 (ediff-with-current-buffer meta-buf
921 ;; delete phony overlays that used to represent sessions before the buff
923 (ediff-cond-compile-for-xemacs-or-emacs
924 (map-extents 'delete-extent) ; xemacs
925 (mapcar 'delete-overlay (overlays-in 1 1)) ; emacs
928 (insert (format ediff-meta-buffer-message
929 (ediff-abbrev-jobname ediff-metajob-name)))
931 (setq regexp (ediff-get-group-regexp meta-list)
933 (ediff-get-group-merge-autostore-dir meta-list))
935 (cond ((ediff-collect-diffs-metajob)
937 " P:\tcollect custom diffs of all marked sessions\n"))
938 ((ediff-patch-metajob)
940 " P:\tshow patch appropriately for the context (session or group)\n")))
942 " ^:\tshow parent session group\n")
943 (or (ediff-one-filegroup-metajob)
945 " D:\tshow differences among directories\n"
946 " ==:\tfor each session, show which files are identical\n"
947 " =h:\tlike ==, but also marks those sessions for hiding\n"
948 " =m:\tlike ==, but also marks those sessions for operation\n\n"))
951 (if (and (stringp regexp) (> (length regexp) 0))
953 (format "*** Filter-through regular expression: %s\n" regexp)))
954 (ediff-insert-dirs-in-meta-buffer meta-list)
955 (if (and ediff-autostore-merges (ediff-merge-metajob)
956 (ediff-nonempty-string-p merge-autostore-dir))
958 "\nMerge results are automatically stored in:\n\t%s\n"
959 merge-autostore-dir)))
961 Size Last modified Name
962 ----------------------------------------------
966 ;; discard info on directories and regexp
967 (setq meta-list (cdr meta-list)
969 (while (and tmp-list empty)
970 (if (and (car tmp-list)
971 (not (eq (ediff-get-session-status (car tmp-list)) ?I)))
973 (setq tmp-list (cdr tmp-list)))
977 " ****** ****** This session group has no members\n"))
979 ;; now organize file names like this:
980 ;; use-mark sizeA dateA sizeB dateB filename
981 ;; make sure directories are displayed with a trailing slash.
983 (setq elt (car meta-list)
984 meta-list (cdr meta-list)
985 sessionNum (1+ sessionNum))
986 (if (eq (ediff-get-session-status elt) ?I)
988 (ediff-insert-session-info-in-meta-buffer elt sessionNum)))
989 (set-buffer-modified-p nil)
993 (defun ediff-update-markers-in-dir-meta-buffer (meta-list)
994 (let ((meta-buf (ediff-get-group-buffer meta-list))
995 session-info point overl buffer-read-only)
996 (ediff-with-current-buffer meta-buf
998 (goto-char (point-min))
999 (ediff-next-meta-item1)
1001 (setq session-info (ediff-get-meta-info meta-buf (point) 'no-error)
1002 overl (ediff-get-meta-overlay-at-pos (point)))
1005 (cond ((eq (ediff-get-session-status session-info) ?I)
1007 (if overl (ediff-overlay-put overl 'invisible t)))
1008 ((and (eq (ediff-get-session-status session-info) ?H)
1009 overl (ediff-overlay-get overl 'invisible))
1011 (ediff-overlay-put overl 'invisible nil))
1012 (t (ediff-replace-session-activity-marker-in-meta-buffer
1014 (ediff-get-session-activity-marker session-info))
1015 (ediff-replace-session-status-in-meta-buffer
1017 (ediff-get-session-status session-info))))))
1018 (ediff-next-meta-item1) ; advance to the next item
1020 (set-buffer-modified-p nil)
1024 (defun ediff-update-session-marker-in-dir-meta-buffer (session-num)
1025 (let (buffer-meta-overlays session-info overl buffer-read-only)
1027 (ediff-cond-compile-for-xemacs-or-emacs
1028 (map-extents ; xemacs
1029 (lambda (ext maparg)
1031 (ediff-overlay-get ext 'ediff-meta-info)
1032 (eq (ediff-overlay-get ext 'ediff-meta-session-number)
1035 ;; Emacs doesn't have map-extents, so try harder
1036 ;; Splice overlay lists to get all buffer overlays
1038 (setq buffer-meta-overlays (overlay-lists)
1039 buffer-meta-overlays (append (car buffer-meta-overlays)
1040 (cdr buffer-meta-overlays)))
1046 (ediff-overlay-get overl 'ediff-meta-info)
1047 (eq (ediff-overlay-get
1048 overl 'ediff-meta-session-number)
1051 buffer-meta-overlays))))
1055 "Bug in ediff-update-session-marker-in-dir-meta-buffer: no overlay with given number %S"
1057 (setq session-info (ediff-overlay-get overl 'ediff-meta-info))
1058 (goto-char (ediff-overlay-start overl))
1059 (ediff-replace-session-activity-marker-in-meta-buffer
1061 (ediff-get-session-activity-marker session-info))
1062 (ediff-replace-session-status-in-meta-buffer
1064 (ediff-get-session-status session-info)))
1065 (ediff-next-meta-item1))
1069 ;; Check if this is a problematic session.
1070 ;; Return nil if not. Otherwise, return symbol representing the problem
1071 ;; At present, problematic sessions occur only in -with-ancestor comparisons
1072 ;; when the ancestor is a directory rather than a file, or when there is no
1073 ;; suitable ancestor file in the ancestor directory
1074 (defun ediff-problematic-session-p (session)
1075 (let ((f1 (ediff-get-session-objA-name session))
1076 (f2 (ediff-get-session-objB-name session))
1077 (f3 (ediff-get-session-objC-name session)))
1078 (cond ((and (stringp f1) (not (file-directory-p f1))
1079 (stringp f2) (not (file-directory-p f2))
1080 ;; either invalid file name or a directory
1081 (or (not (stringp f3)) (file-directory-p f3))
1082 (ediff-ancestor-metajob))
1083 ;; more may be added later
1087 (defun ediff-meta-insert-file-info1 (fileinfo)
1088 (let ((fname (car fileinfo))
1089 (feq (ediff-get-file-eqstatus fileinfo))
1090 (max-filename-width (if ediff-meta-truncate-filenames
1091 (- (window-width) 41)
1093 file-modtime file-size)
1094 (cond ((not (stringp fname)) (setq file-size -2)) ; file doesn't exits
1095 ((ediff-listable-file fname)
1096 (if (file-exists-p fname)
1097 ;; set real size and modtime
1098 (setq file-size (ediff-file-size fname)
1099 file-modtime (ediff-file-modtime fname))
1100 (setq file-size -2))) ; file doesn't exist
1101 ( t (setq file-size -1))) ; remote file
1106 (if feq "=" " ") ; equality indicator
1107 (format "%10s" (cond ((= file-size -1) "--")
1108 ((< file-size -1) "--")
1110 (cond ((= file-size -1) "*remote file*")
1111 ((< file-size -1) "*file doesn't exist*")
1112 (t (ediff-format-date (decode-time file-modtime))))
1114 ;; dir names in meta lists have training slashes, so we just
1115 ;; abbreviate the file name, if file exists
1116 (if (and (not (stringp fname)) (< file-size -1))
1117 "-------" ; file doesn't exist
1118 (ediff-truncate-string-left
1119 (ediff-abbreviate-file-name fname)
1120 max-filename-width)))))))
1122 (defconst ediff-months '((1 . "Jan") (2 . "Feb") (3 . "Mar") (4 . "Apr")
1123 (5 . "May") (6 . "Jun") (7 . "Jul") (8 . "Aug")
1124 (9 . "Sep") (10 . "Oct") (11 . "Nov") (12 . "Dec"))
1125 "Months' associative array.")
1127 ;; returns 2char string
1128 (defsubst ediff-fill-leading-zero (num)
1131 (number-to-string num)))
1133 ;; TIME is like the output of decode-time
1134 (defun ediff-format-date (time)
1135 (format "%s %2d %4d %s:%s:%s"
1136 (cdr (assoc (nth 4 time) ediff-months)) ; month
1139 (ediff-fill-leading-zero (nth 2 time)) ; hour
1140 (ediff-fill-leading-zero (nth 1 time)) ; min
1141 (ediff-fill-leading-zero (nth 0 time)) ; sec
1144 ;; Draw the directories
1145 (defun ediff-insert-dirs-in-meta-buffer (meta-list)
1146 (let* ((dir1 (ediff-abbreviate-file-name (ediff-get-group-objA meta-list)))
1147 (dir2 (ediff-get-group-objB meta-list))
1148 (dir2 (if (stringp dir2) (ediff-abbreviate-file-name dir2)))
1149 (dir3 (ediff-get-group-objC meta-list))
1150 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3))))
1151 (insert "*** Directory A: " dir1 "\n")
1152 (if dir2 (insert "*** Directory B: " dir2 "\n"))
1153 (if dir3 (insert "*** Directory C: " dir3 "\n"))
1156 (defun ediff-draw-dir-diffs (diff-list &optional buf-name)
1157 (if (null diff-list) (error "Lost difference info on these directories"))
1160 (ediff-unique-buffer-name "*Ediff File Group Differences" "*")))
1161 (let* ((regexp (ediff-get-group-regexp diff-list))
1162 (dir1 (ediff-abbreviate-file-name (ediff-get-group-objA diff-list)))
1163 (dir2 (ediff-abbreviate-file-name (ediff-get-group-objB diff-list)))
1164 (dir3 (ediff-get-group-objC diff-list))
1165 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3)))
1166 (meta-buf (ediff-get-group-buffer diff-list))
1167 (underline (make-string 26 ?-))
1168 file membership-code saved-point
1170 ;; skip the directory part
1171 (setq diff-list (cdr diff-list))
1172 (setq ediff-dir-diffs-buffer (get-buffer-create buf-name))
1173 (ediff-with-current-buffer ediff-dir-diffs-buffer
1174 (setq saved-point (point))
1175 (use-local-map ediff-dir-diffs-buffer-map)
1177 (setq ediff-meta-buffer meta-buf)
1178 (insert "\t\t*** Directory Differences ***\n")
1181 C,button2: over file name -- copy this file to directory that doesn't have it
1184 p,DEL: previous line\n\n")
1186 (insert (format "\n*** Directory A: %s\n" dir1))
1187 (if dir2 (insert (format "*** Directory B: %s\n" dir2)))
1188 (if dir3 (insert (format "*** Directory C: %s\n" dir3)))
1189 (if (and (stringp regexp) (> (length regexp) 0))
1191 (format "*** Filter-through regular expression: %s\n" regexp)))
1193 (insert (format "\n%-27s%-26s" "Directory A" "Directory B"))
1195 (insert (format " %-25s\n" "Directory C"))
1197 (insert (format "%s%s" underline underline))
1199 (insert (format "%s\n\n" underline))
1202 (if (null diff-list)
1203 (insert "\n\t*** No differences ***\n"))
1206 (setq file (car (car diff-list))
1207 membership-code (cdr (car diff-list))
1208 diff-list (cdr diff-list))
1209 (if (= (mod membership-code ediff-membership-code1) 0) ; dir1
1210 (let ((beg (point)))
1211 (insert (format "%-27s"
1212 (ediff-truncate-string-left
1213 (ediff-abbreviate-file-name
1214 (if (file-directory-p (concat dir1 file))
1215 (file-name-as-directory file)
1218 ;; format of meta info in the dir-diff-buffer:
1219 ;; (filename-tail filename-full otherdir1 otherdir2 otherdir3)
1220 (ediff-set-meta-overlay
1222 (list meta-buf file (concat dir1 file) dir1 dir2 dir3)))
1223 (insert (format "%-27s" "---")))
1224 (if (= (mod membership-code ediff-membership-code2) 0) ; dir2
1225 (let ((beg (point)))
1226 (insert (format "%-26s"
1227 (ediff-truncate-string-left
1228 (ediff-abbreviate-file-name
1229 (if (file-directory-p (concat dir2 file))
1230 (file-name-as-directory file)
1233 (ediff-set-meta-overlay
1235 (list meta-buf file (concat dir2 file) dir1 dir2 dir3)))
1236 (insert (format "%-26s" "---")))
1238 (if (= (mod membership-code ediff-membership-code3) 0) ; dir3
1239 (let ((beg (point)))
1240 (insert (format " %-25s"
1241 (ediff-truncate-string-left
1242 (ediff-abbreviate-file-name
1243 (if (file-directory-p (concat dir3 file))
1244 (file-name-as-directory file)
1247 (ediff-set-meta-overlay
1249 (list meta-buf file (concat dir3 file) dir1 dir2 dir3)))
1250 (insert (format " %-25s" "---"))))
1252 (setq buffer-read-only t)
1253 (set-buffer-modified-p nil)
1254 (goto-char saved-point)) ; end eval in diff buffer
1257 (defun ediff-bury-dir-diffs-buffer ()
1258 "Bury the directory difference buffer. Display the meta buffer instead."
1260 ;; ediff-meta-buffer is set in ediff-draw-dir-diffs so the directory
1261 ;; difference buffer remembers the meta buffer
1262 (let ((buf ediff-meta-buffer)
1264 (ediff-kill-buffer-carefully ediff-dir-diffs-buffer)
1265 (if (setq wind (ediff-get-visible-buffer-window buf))
1266 (select-window wind)
1267 (set-window-buffer (selected-window) buf))))
1269 ;; executes in dir session group buffer
1270 ;; show buffer differences
1271 (defun ediff-show-dir-diffs ()
1272 "Display differences among the directories involved in session group."
1274 (if (ediff-one-filegroup-metajob)
1275 (error "This command is inapplicable in the present context"))
1276 (or (ediff-buffer-live-p ediff-dir-diffs-buffer)
1277 (ediff-draw-dir-diffs ediff-dir-difference-list))
1278 (let ((buf ediff-dir-diffs-buffer))
1280 (set-window-buffer (selected-window) buf)
1281 (goto-char (point-min))))
1283 ;; Format of meta info in dir-diff-buffer:
1284 ;; (filename-tail filename-full otherdir1 otherdir2)
1285 (defun ediff-dir-diff-copy-file ()
1286 "Copy file described at point to directories where this file is missing."
1288 (let* ((pos (ediff-event-point last-command-event))
1289 (info (ediff-get-meta-info (current-buffer) pos 'noerror))
1290 (meta-buf (car info))
1291 (file-tail (nth 1 info))
1292 (file-abs (nth 2 info))
1293 (otherdir1 (nth 3 info))
1294 (otherfile1 (if otherdir1 (concat otherdir1 file-tail)))
1295 (otherdir2 (nth 4 info))
1296 (otherfile2 (if otherdir2 (concat otherdir2 file-tail)))
1297 (otherdir3 (nth 5 info))
1298 (otherfile3 (if otherdir3 (concat otherdir3 file-tail)))
1299 meta-list dir-diff-list
1302 (error "No file suitable for copying described at this location"))
1303 (ediff-with-current-buffer meta-buf
1304 (setq meta-list ediff-meta-list
1305 dir-diff-list ediff-dir-difference-list))
1307 ;; copy file to directories where it doesn't exist, update
1308 ;; ediff-dir-difference-list and redisplay
1310 (lambda (otherfile-struct)
1311 (let ((otherfile (car otherfile-struct))
1312 (file-mem-code (cdr otherfile-struct)))
1314 (or (file-exists-p otherfile)
1316 (format "Copy %s to %s ? " file-abs otherfile))
1317 (let* ((file-diff-record (assoc file-tail dir-diff-list))
1319 (* (cdr file-diff-record) file-mem-code)))
1320 (copy-file file-abs otherfile)
1321 (setcdr file-diff-record new-mem-code)
1322 (ediff-draw-dir-diffs dir-diff-list (buffer-name))
1324 ;; if file is in all three dirs or in two dirs and only
1325 ;; two dirs are involved, delete this file's record
1326 (if (or (= new-mem-code ediff-product-of-memcodes)
1327 (and (> new-mem-code ediff-membership-code3)
1329 (delq file-diff-record dir-diff-list))
1332 ;; 2,3,5 are numbers used to encode membership of a file in
1333 ;; dir1/2/3. See ediff-intersect-directories.
1334 (list (cons otherfile1 2) (cons otherfile2 3) (cons otherfile3 5)))
1336 (if (and (file-exists-p otherfile1)
1337 (file-exists-p otherfile2)
1338 (or (not otherfile3) (file-exists-p otherfile3)))
1339 ;; update ediff-meta-list by direct modification
1341 (list (ediff-make-new-meta-list-element
1342 otherfile1 otherfile2 otherfile3)))
1344 (ediff-update-meta-buffer meta-buf 'must-redraw)
1347 (defun ediff-up-meta-hierarchy ()
1348 "Go to the parent session group buffer."
1350 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1351 (ediff-show-meta-buffer
1352 ediff-parent-meta-buffer ediff-meta-session-number)
1353 (error "This session group has no parent")))
1356 ;; argument is ignored
1357 (defun ediff-redraw-registry-buffer (&optional ignore)
1358 (ediff-with-current-buffer ediff-registry-buffer
1359 (let ((point (point))
1360 elt bufAname bufBname bufCname cur-diff total-diffs pt
1361 job-name meta-list registry-list buffer-read-only)
1363 ;; delete phony overlays that used to represent sessions before the buff
1365 (ediff-cond-compile-for-xemacs-or-emacs
1366 (map-extents 'delete-extent) ; xemacs
1367 (mapcar 'delete-overlay (overlays-in 1 1)) ; emacs
1370 (insert "This is a registry of all active Ediff sessions.
1373 button2, `v', RET over a session record: switch to that session
1374 M over a session record: display the associated session group
1375 R in any Ediff session: display session registry
1377 p,DEL: previous session
1378 E: browse Ediff on-line manual
1382 \t\tActive Ediff Sessions:
1383 \t\t----------------------
1386 ;; purge registry list from dead buffers
1387 (mapcar (lambda (elt)
1388 (if (not (ediff-buffer-live-p elt))
1389 (setq ediff-session-registry
1390 (delq elt ediff-session-registry))))
1391 ediff-session-registry)
1393 (if (null ediff-session-registry)
1394 (insert " ******* No active Ediff sessions *******\n"))
1396 (setq registry-list ediff-session-registry)
1397 (while registry-list
1398 (setq elt (car registry-list)
1399 registry-list (cdr registry-list))
1401 (if (ediff-buffer-live-p elt)
1402 (if (ediff-with-current-buffer elt
1403 (setq job-name ediff-metajob-name
1404 meta-list ediff-meta-list)
1405 (and ediff-metajob-name
1406 (not (eq ediff-metajob-name 'ediff-registry))))
1409 (insert (format " *group*\t%s: %s\n"
1411 (ediff-abbrev-jobname job-name)))
1412 (insert (format "\t\t %s %s %s\n"
1413 (ediff-abbreviate-file-name
1414 (ediff-get-group-objA meta-list))
1415 (ediff-abbreviate-file-name
1417 (ediff-get-group-objB meta-list))
1418 (ediff-get-group-objB meta-list)
1420 (ediff-abbreviate-file-name
1422 (ediff-get-group-objC meta-list))
1423 (ediff-get-group-objC meta-list)
1425 (ediff-set-meta-overlay pt (point) elt))
1427 (ediff-with-current-buffer elt
1428 (setq bufAname (if (ediff-buffer-live-p ediff-buffer-A)
1429 (buffer-name ediff-buffer-A)
1430 "!!!killed buffer!!!")
1431 bufBname (if (ediff-buffer-live-p ediff-buffer-B)
1432 (buffer-name ediff-buffer-B)
1433 "!!!killed buffer!!!")
1434 bufCname (cond ((not (ediff-3way-job))
1436 ((ediff-buffer-live-p ediff-buffer-C)
1437 (buffer-name ediff-buffer-C))
1438 (t "!!!killed buffer!!!")))
1439 (setq total-diffs (format "%-4d" ediff-number-of-differences)
1441 (cond ((= ediff-current-difference -1) " _")
1442 ((= ediff-current-difference
1443 ediff-number-of-differences)
1446 "%4d" (1+ ediff-current-difference))))
1447 job-name ediff-job-name))
1448 ;; back in the meta buf
1450 (insert cur-diff "/" total-diffs "\t"
1452 (format ": %s" (ediff-abbrev-jobname job-name)))
1454 "\n\t\t " bufAname " " bufBname " " bufCname "\n")
1455 (ediff-set-meta-overlay pt (point) elt))))
1457 (set-buffer-modified-p nil)
1461 ;; Sets overlay around a meta record with 'ediff-meta-info property PROP
1462 ;; If optional SESSION-NUMBER, make it a property of the overlay,
1463 ;; ediff-meta-session-number
1464 ;; PROP is either the ctl or meta buffer (used when we work with the registry)
1465 ;; or a session meta descriptor of the form
1466 ;; (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
1467 (defun ediff-set-meta-overlay (b e prop &optional session-number hidden)
1469 (setq overl (ediff-make-overlay b e))
1471 (ediff-overlay-put overl 'mouse-face 'highlight)
1472 (ediff-overlay-put overl 'highlight t))
1473 (ediff-overlay-put overl 'ediff-meta-info prop)
1474 (ediff-overlay-put overl 'invisible hidden)
1475 (if (numberp session-number)
1476 (ediff-overlay-put overl 'ediff-meta-session-number session-number))))
1478 (defun ediff-mark-for-hiding-at-pos (unmark)
1479 "Mark session for hiding. With prefix arg, unmark."
1481 (let* ((pos (ediff-event-point last-command-event))
1482 (meta-buf (ediff-event-buffer last-command-event))
1483 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1484 (info (ediff-get-meta-info meta-buf pos))
1485 (session-number (ediff-get-session-number-at-pos pos)))
1486 (ediff-mark-session-for-hiding info unmark)
1487 (ediff-next-meta-item 1)
1489 (ediff-update-meta-buffer meta-buf nil session-number))
1492 ;; Returns whether session was marked or unmarked
1493 (defun ediff-mark-session-for-hiding (info unmark)
1494 (let ((session-buf (ediff-get-session-buffer info))
1496 (cond ((eq unmark 'mark) (setq unmark nil))
1497 ((eq (ediff-get-session-status info) ?H) (setq unmark t))
1498 (unmark ; says unmark, but the marker is different from H
1501 (unmark (ediff-set-session-status info nil))
1502 ;;; (if (ediff-buffer-live-p session-buf)
1503 ;;; (error "Can't hide active session, %s" (buffer-name session-buf)))
1504 (t (ediff-set-session-status info ?H))))
1508 (defun ediff-mark-for-operation-at-pos (unmark)
1509 "Mark session for a group operation. With prefix arg, unmark."
1511 (let* ((pos (ediff-event-point last-command-event))
1512 (meta-buf (ediff-event-buffer last-command-event))
1513 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1514 (info (ediff-get-meta-info meta-buf pos))
1515 (session-number (ediff-get-session-number-at-pos pos)))
1516 (ediff-mark-session-for-operation info unmark)
1517 (ediff-next-meta-item 1)
1519 (ediff-update-meta-buffer meta-buf nil session-number))
1523 ;; returns whether session was unmarked.
1524 ;; remember: this is a toggle op
1525 (defun ediff-mark-session-for-operation (info unmark)
1527 (cond ((eq unmark 'mark) (setq unmark nil))
1528 ((eq (ediff-get-session-status info) ?*) (setq unmark t))
1529 (unmark ; says unmark, but the marker is different from *
1532 (unmark (ediff-set-session-status info nil))
1533 (t (ediff-set-session-status info ?*))))
1537 (defun ediff-hide-marked-sessions (unhide)
1538 "Hide marked sessions. With prefix arg, unhide."
1540 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1541 (meta-list (cdr ediff-meta-list))
1542 (from (if unhide ?I ?H))
1543 (to (if unhide ?H ?I))
1545 active-sessions-exist session-buf elt)
1547 (setq elt (car meta-list)
1548 meta-list (cdr meta-list)
1549 session-buf (ediff-get-session-buffer elt))
1551 (if (eq (ediff-get-session-status elt) from)
1553 (setq numMarked (1+ numMarked))
1554 (if (and (eq to ?I) (buffer-live-p session-buf))
1555 ;; shouldn't hide active sessions
1556 (setq active-sessions-exist t)
1557 (ediff-set-session-status elt to)))))
1559 (ediff-update-meta-buffer grp-buf 'must-redraw)
1562 (message "Nothing to reveal...")
1563 (message "Nothing to hide...")))
1564 (if active-sessions-exist
1565 (message "Note: Ediff didn't hide active sessions!"))
1568 ;; Apply OPERATION to marked sessions. Operation expects one argument of type
1569 ;; meta-list member (not the first one), i.e., a regular session description.
1570 ;; Returns number of marked sessions on which operation was performed
1571 (defun ediff-operate-on-marked-sessions (operation)
1572 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1573 (meta-list (cdr ediff-meta-list))
1577 (diff-buffer ediff-meta-diff-buffer)
1580 (setq elt (car meta-list)
1581 meta-list (cdr meta-list)
1582 sessionNum (1+ sessionNum))
1583 (cond ((eq (ediff-get-session-status elt) marksym)
1585 (setq numMarked (1+ numMarked))
1586 (funcall operation elt sessionNum)))
1587 ;; The following goes into a session represented by a subdirectory
1588 ;; and applies operation to marked sessions there
1589 ((and (ediff-meta-session-p elt)
1590 (ediff-buffer-live-p
1591 (setq session-buf (ediff-get-session-buffer elt))))
1594 (ediff-with-current-buffer session-buf
1595 ;; pass meta-diff along
1596 (setq ediff-meta-diff-buffer diff-buffer)
1597 ;; collect diffs in child group
1598 (ediff-operate-on-marked-sessions operation)))))))
1599 (ediff-update-meta-buffer grp-buf 'must-redraw) ; just in case
1603 (defun ediff-append-custom-diff (session sessionNum)
1604 (or (ediff-collect-diffs-metajob)
1605 (error "Can't compute multifile patch in this context"))
1606 (let ((session-buf (ediff-get-session-buffer session))
1607 (meta-diff-buff ediff-meta-diff-buffer)
1608 (metajob ediff-metajob-name)
1609 tmp-buf custom-diff-buf)
1610 (if (ediff-buffer-live-p session-buf)
1611 (ediff-with-current-buffer session-buf
1612 (if (eq ediff-control-buffer session-buf) ; individual session
1614 (ediff-compute-custom-diffs-maybe)
1615 (setq custom-diff-buf ediff-custom-diff-buffer)))))
1617 (or (ediff-buffer-live-p meta-diff-buff)
1618 (error "Ediff: something wrong--killed multiple diff's buffer"))
1620 (cond ((ediff-buffer-live-p custom-diff-buf)
1621 ;; for live session buffers we do them first because the user may
1622 ;; have changed them with respect to the underlying files
1624 (set-buffer meta-diff-buff)
1625 (goto-char (point-max))
1626 (insert-buffer custom-diff-buf)
1628 ;; if ediff session is not live, run diff directly on the files
1629 ((memq metajob '(ediff-directories
1630 ediff-merge-directories
1631 ediff-merge-directories-with-ancestor))
1632 ;; get diffs by calling shell command on ediff-custom-diff-program
1634 (set-buffer (setq tmp-buf (get-buffer-create ediff-tmp-buffer)))
1637 (format "%s %s %s %s"
1638 ediff-custom-diff-program ediff-custom-diff-options
1639 (ediff-get-session-objA-name session)
1640 (ediff-get-session-objB-name session))
1643 (set-buffer meta-diff-buff)
1644 (goto-char (point-max))
1645 (insert-buffer tmp-buf)
1648 (ediff-kill-buffer-carefully meta-diff-buff)
1649 (error "Session %d compares versions of file. Such session must be active to enable multifile patch collection" sessionNum )))
1652 (defun ediff-collect-custom-diffs ()
1653 "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'.
1654 This operation is defined only for `ediff-directories' and
1655 `ediff-directory-revisions', since its intent is to produce
1656 multifile patches. For `ediff-directory-revisions', we insist that
1657 all marked sessions must be active."
1659 (or (ediff-buffer-live-p ediff-meta-diff-buffer)
1660 (setq ediff-meta-diff-buffer
1662 (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
1663 (ediff-with-current-buffer ediff-meta-diff-buffer
1664 (setq buffer-read-only nil)
1666 (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
1669 (display-buffer ediff-meta-diff-buffer 'not-this-window)
1670 (ediff-with-current-buffer ediff-meta-diff-buffer
1671 (set-buffer-modified-p nil)
1672 (setq buffer-read-only t)))
1674 (message "No marked sessions found")))
1676 (defun ediff-meta-show-patch ()
1677 "Show the multi-file patch associated with this group session."
1679 (let* ((pos (ediff-event-point last-command-event))
1680 (meta-buf (ediff-event-buffer last-command-event))
1681 (info (ediff-get-meta-info meta-buf pos 'noerror))
1682 (patchbuffer ediff-meta-patchbufer))
1683 (if (ediff-buffer-live-p patchbuffer)
1684 (ediff-with-current-buffer patchbuffer
1689 (ediff-get-session-objB-name info)
1690 (ediff-get-session-objC-name info)))
1691 (set-buffer (get-buffer-create ediff-tmp-buffer))
1693 (insert-buffer patchbuffer)
1694 (display-buffer ediff-tmp-buffer 'not-this-window)
1696 (error "The patch buffer wasn't found"))))
1699 ;; This function executes in meta buffer. It knows where event happened.
1700 (defun ediff-filegroup-action ()
1701 "Execute appropriate action for a selected session."
1703 (let* ((pos (ediff-event-point last-command-event))
1704 (meta-buf (ediff-event-buffer last-command-event))
1705 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1706 (info (ediff-get-meta-info meta-buf pos))
1707 (session-buf (ediff-get-session-buffer info))
1708 (session-number (ediff-get-session-number-at-pos pos meta-buf))
1709 (default-regexp (eval ediff-default-filtering-regexp))
1710 merge-autostore-dir file1 file2 file3 regexp)
1712 (setq file1 (ediff-get-session-objA-name info)
1713 file2 (ediff-get-session-objB-name info)
1714 file3 (ediff-get-session-objC-name info))
1716 ;; make sure we don't start on hidden sessions
1717 ;; ?H means marked for hiding. ?I means invalid (hidden).
1718 (if (memq (ediff-get-session-status info) '(?I))
1721 (if (y-or-n-p "This session is marked as hidden, unmark? ")
1723 (ediff-set-session-status info nil)
1724 (ediff-update-meta-buffer meta-buf nil session-number))
1725 (error "Aborted"))))
1727 (ediff-with-current-buffer meta-buf
1728 (setq merge-autostore-dir
1729 (ediff-get-group-merge-autostore-dir ediff-meta-list))
1730 (goto-char pos) ; if the user clicked on session--move point there
1731 ;; First handle sessions involving directories (which are themselves
1733 ;; After that handle individual sessions
1734 (cond ((ediff-meta-session-p info)
1735 ;; do ediff/ediff-merge on subdirectories
1736 (if (ediff-buffer-live-p session-buf)
1737 (ediff-show-meta-buffer session-buf)
1740 (if (stringp default-regexp)
1742 "Filter through regular expression (default %s): "
1744 "Filter through regular expression: ")
1746 'ediff-filtering-regexp-history
1747 (eval ediff-default-filtering-regexp)))
1748 (ediff-directories-internal
1749 file1 file2 file3 regexp
1750 ediff-session-action-function
1752 ;; make it update (car info) after startup
1754 ;; child session group should know its parent
1755 (setq ediff-parent-meta-buffer
1756 (quote ,ediff-meta-buffer)
1757 ediff-meta-session-number
1759 ;; and parent will know its child
1760 (setcar (quote ,info) ediff-meta-buffer))))))
1762 ;; Do ediff-revision on a subdirectory
1763 ((and (ediff-one-filegroup-metajob)
1764 (ediff-revision-metajob)
1765 (file-directory-p file1))
1766 (if (ediff-buffer-live-p session-buf)
1767 (ediff-show-meta-buffer session-buf)
1768 (setq regexp (read-string "Filter through regular expression: "
1769 nil 'ediff-filtering-regexp-history))
1770 (ediff-directory-revisions-internal
1772 ediff-session-action-function ediff-metajob-name
1773 ;; make it update (car info) after startup
1775 ;; child session group should know its parent and
1777 (setq ediff-parent-meta-buffer
1778 (quote ,ediff-meta-buffer)
1779 ediff-meta-session-number
1781 ;; and parent will know its child
1782 (setcar (quote ,info) ediff-meta-buffer))))))
1784 ;; From here on---only individual session handlers
1786 ;; handle an individual session with a live control buffer
1787 ((ediff-buffer-live-p session-buf)
1788 (ediff-with-current-buffer session-buf
1789 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1790 (ediff-recenter 'no-rehighlight)))
1792 ((ediff-problematic-session-p info)
1795 "This session has no ancestor. Merge without the ancestor? ")
1798 ;; provide startup hooks
1801 'ediff-after-quit-hook-internal
1803 (if (ediff-buffer-live-p ,(current-buffer))
1804 (ediff-show-meta-buffer
1805 ,(current-buffer) ,session-number)))
1807 (setq ediff-meta-buffer ,(current-buffer)
1808 ediff-meta-session-number
1810 (setq ediff-merge-store-file
1811 ,(if (ediff-nonempty-string-p
1812 merge-autostore-dir)
1815 ediff-merge-filename-prefix
1816 (file-name-nondirectory file1))
1818 ;; make ediff-startup pass
1819 ;; ediff-control-buffer back to the meta
1822 (quote ,info) ediff-control-buffer))))
1824 ((ediff-one-filegroup-metajob) ; needs 1 file arg
1825 (funcall ediff-session-action-function
1827 ;; provide startup hooks
1830 'ediff-after-quit-hook-internal
1832 (if (ediff-buffer-live-p
1834 (ediff-show-meta-buffer
1838 (setq ediff-meta-buffer ,(current-buffer)
1839 ediff-meta-session-number
1841 (setq ediff-merge-store-file
1842 ,(if (ediff-nonempty-string-p
1843 merge-autostore-dir)
1846 ediff-merge-filename-prefix
1847 (file-name-nondirectory file1))) )
1848 ;; make ediff-startup pass
1849 ;; ediff-control-buffer back to the meta
1852 (quote ,info) ediff-control-buffer)))))
1853 ((not (ediff-metajob3)) ; need 2 file args
1854 (funcall ediff-session-action-function
1856 ;; provide startup hooks
1859 'ediff-after-quit-hook-internal
1861 (if (ediff-buffer-live-p
1863 (ediff-show-meta-buffer
1867 (setq ediff-meta-buffer ,(current-buffer)
1868 ediff-meta-session-number
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 ;; make ediff-startup pass
1878 ;; ediff-control-buffer back to the meta
1881 (quote ,info) ediff-control-buffer)))))
1882 ((ediff-metajob3) ; need 3 file args
1883 (funcall ediff-session-action-function
1885 ;; arrange startup hooks
1888 'ediff-after-quit-hook-internal
1890 (if (ediff-buffer-live-p
1892 (ediff-show-meta-buffer
1896 (setq ediff-merge-store-file
1897 ,(if (ediff-nonempty-string-p
1898 merge-autostore-dir)
1901 ediff-merge-filename-prefix
1902 (file-name-nondirectory file1))) )
1903 (setq ediff-meta-buffer , (current-buffer)
1904 ediff-meta-session-number
1906 ;; this arranges that ediff-startup will pass
1907 ;; the value of ediff-control-buffer back to
1908 ;; the meta level, to the record in the meta
1909 ;; list containing the information about the
1910 ;; session associated with that
1911 ;; ediff-control-buffer
1913 (quote ,info) ediff-control-buffer)))))
1915 ) ; eval in meta-buf
1918 (defun ediff-registry-action ()
1919 "Switch to a selected session."
1921 (let* ((pos (ediff-event-point last-command-event))
1922 (buf (ediff-event-buffer last-command-event))
1923 (ctl-buf (ediff-get-meta-info buf pos)))
1925 (if (ediff-buffer-live-p ctl-buf)
1926 ;; check if this is ediff-control-buffer or ediff-meta-buffer
1927 (if (ediff-with-current-buffer ctl-buf
1928 (eq (key-binding "q") 'ediff-quit-meta-buffer))
1929 ;; it's a meta-buffer -- last action should just display it
1930 (ediff-show-meta-buffer ctl-buf t)
1931 ;; it's a session buffer -- invoke go back to session
1932 (ediff-with-current-buffer ctl-buf
1933 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1934 (ediff-recenter 'no-rehighlight)))
1936 (message "You've selected a stale session --- try again")
1937 (ediff-update-registry))
1938 (ediff-with-current-buffer buf
1943 ;; If session number is t, means don't update meta buffer
1944 (defun ediff-show-meta-buffer (&optional meta-buf session-number)
1945 "Show the session group buffer."
1947 (run-hooks 'ediff-before-directory-setup-hooks)
1948 (let (wind frame silent)
1949 (if meta-buf (setq silent t))
1951 (setq meta-buf (or meta-buf ediff-meta-buffer))
1952 (cond ((not (bufferp meta-buf))
1953 (error "This Ediff session is not part of a session group"))
1954 ((not (ediff-buffer-live-p meta-buf))
1956 "Can't find this session's group panel -- session itself is ok")))
1958 (cond ((numberp session-number)
1959 (ediff-update-meta-buffer meta-buf nil session-number))
1960 ;; if session-number is t, don't update
1962 (t (ediff-cleanup-meta-buffer meta-buf)))
1964 (ediff-with-current-buffer meta-buf
1966 (cond ((setq wind (ediff-get-visible-buffer-window meta-buf))
1969 "Already showing the group panel for this session"))
1970 (set-window-buffer wind meta-buf)
1971 (select-window wind))
1972 ((window-live-p (setq wind ediff-window-C)) ;in merge--merge buf
1973 (set-window-buffer ediff-window-C meta-buf)
1974 (select-window wind))
1975 ((window-live-p (setq wind ediff-window-A))
1976 (set-window-buffer ediff-window-A meta-buf)
1977 (select-window wind))
1978 ((window-live-p (setq wind ediff-window-B))
1979 (set-window-buffer ediff-window-B meta-buf)
1980 (select-window wind))
1983 (ediff-get-visible-buffer-window ediff-registry-buffer))
1984 (ediff-window-display-p))
1985 (select-window wind)
1987 (set-window-buffer (selected-window) meta-buf))
1988 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1989 (set-window-buffer (selected-window) meta-buf)))
1991 (if (and (ediff-window-display-p)
1993 (setq wind (ediff-get-visible-buffer-window meta-buf))))
1995 (setq frame (window-frame wind))
1997 (ediff-reset-mouse frame)))
1998 (sit-for 0) ; sometimes needed to synch the display and ensure that the
1999 ; point ends up after the just completed session
2000 (run-hooks 'ediff-show-session-group-hook)
2003 (defun ediff-show-current-session-meta-buffer ()
2005 (ediff-show-meta-buffer nil ediff-meta-session-number))
2007 (defun ediff-show-meta-buff-from-registry ()
2008 "Display the session group buffer for a selected session group."
2010 (let* ((pos (ediff-event-point last-command-event))
2011 (meta-buf (ediff-event-buffer last-command-event))
2012 (info (ediff-get-meta-info meta-buf pos))
2013 (meta-or-session-buf info))
2014 (ediff-with-current-buffer meta-or-session-buf
2015 (ediff-show-meta-buffer nil t))))
2018 (defun ediff-show-registry ()
2019 "Display Ediff's registry."
2021 (ediff-update-registry)
2022 (if (not (ediff-buffer-live-p ediff-registry-buffer))
2023 (error "No active Ediff sessions or corrupted session registry"))
2025 ;; for some reason, point moves in ediff-registry-buffer, so we preserve it
2027 (ediff-with-current-buffer ediff-registry-buffer
2030 (ediff-get-visible-buffer-window ediff-registry-buffer))
2031 (message "Already showing the registry")
2032 (set-window-buffer wind ediff-registry-buffer)
2033 (select-window wind))
2034 ((window-live-p ediff-window-C)
2035 (set-window-buffer ediff-window-C ediff-registry-buffer)
2036 (select-window ediff-window-C))
2037 ((window-live-p ediff-window-A)
2038 (set-window-buffer ediff-window-A ediff-registry-buffer)
2039 (select-window ediff-window-A))
2040 ((window-live-p ediff-window-B)
2041 (set-window-buffer ediff-window-B ediff-registry-buffer)
2042 (select-window ediff-window-B))
2044 (ediff-get-visible-buffer-window ediff-meta-buffer))
2045 (ediff-window-display-p))
2046 (select-window wind)
2048 (set-window-buffer (selected-window) ediff-registry-buffer))
2049 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
2050 (set-window-buffer (selected-window) ediff-registry-buffer)))
2052 (if (ediff-window-display-p)
2056 (ediff-get-visible-buffer-window ediff-registry-buffer)))
2058 (ediff-reset-mouse frame)))
2059 (run-hooks 'ediff-show-registry-hook)
2063 (defalias 'eregistry 'ediff-show-registry)
2065 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a
2067 ;; Check if META-BUF exists before calling this function
2068 ;; Optional MUST-REDRAW, if non-nil, would force redrawal of the whole meta
2069 ;; buffer. Otherwise, it will just go over the buffer and update activity marks
2070 ;; and session status.
2071 ;; SESSION-NUMBER, if specified, says which session caused the update.
2072 (defun ediff-update-meta-buffer (meta-buf &optional must-redraw session-number)
2073 (if (ediff-buffer-live-p meta-buf)
2074 (ediff-with-current-buffer meta-buf
2076 (cond (must-redraw ; completely redraw the meta buffer
2077 (funcall ediff-meta-redraw-function ediff-meta-list))
2078 ((numberp session-number) ; redraw only for the given session
2079 (ediff-update-session-marker-in-dir-meta-buffer
2081 (t ; update what changed only, but scan the entire meta buffer
2082 (ediff-update-markers-in-dir-meta-buffer ediff-meta-list)))
2083 (setq overl (ediff-get-meta-overlay-at-pos (point)))
2084 ;; skip the invisible sessions
2085 (while (and overl (ediff-overlay-get overl 'invisible))
2086 (ediff-next-meta-item1)
2087 (setq overl (ediff-get-meta-overlay-at-pos (point))))
2090 (defun ediff-update-registry ()
2091 (ediff-with-current-buffer (current-buffer)
2092 (if (ediff-buffer-live-p ediff-registry-buffer)
2093 (ediff-redraw-registry-buffer)
2094 (ediff-prepare-meta-buffer
2095 'ediff-registry-action
2096 ediff-session-registry
2098 'ediff-redraw-registry-buffer
2102 ;; If meta-buf exists, it is redrawn along with parent.
2103 ;; Otherwise, nothing happens.
2104 (defun ediff-cleanup-meta-buffer (meta-buffer)
2105 (if (ediff-buffer-live-p meta-buffer)
2106 (ediff-with-current-buffer meta-buffer
2107 (ediff-update-meta-buffer meta-buffer)
2108 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
2109 (ediff-update-meta-buffer
2110 ediff-parent-meta-buffer nil ediff-meta-session-number)))))
2112 ;; t if no session is in progress
2113 (defun ediff-safe-to-quit (meta-buffer)
2114 (if (ediff-buffer-live-p meta-buffer)
2115 (let ((lis ediff-meta-list)
2118 ;;(ediff-update-meta-buffer meta-buffer)
2119 (ediff-with-current-buffer meta-buffer
2120 (setq lis (cdr lis)) ; discard the description part of meta-list
2121 (while (and cont lis)
2122 (if (ediff-buffer-live-p
2123 (ediff-get-group-buffer lis)) ; in progress
2125 (setq lis (cdr lis)))
2128 (defun ediff-quit-meta-buffer ()
2129 "If the group has no active session, delete the meta buffer.
2130 If no session is in progress, ask to confirm before deleting meta buffer.
2131 Otherwise, bury the meta buffer.
2132 If this is a session registry buffer then just bury it."
2134 (let* ((buf (current-buffer))
2135 (dir-diffs-buffer ediff-dir-diffs-buffer)
2136 (meta-diff-buffer ediff-meta-diff-buffer)
2137 (session-number ediff-meta-session-number)
2138 (parent-buf ediff-parent-meta-buffer)
2139 (dont-show-registry (eq buf ediff-registry-buffer)))
2140 (if dont-show-registry
2142 ;;(ediff-cleanup-meta-buffer buf)
2143 (cond ((and (ediff-safe-to-quit buf)
2144 (y-or-n-p "Quit this session group? "))
2145 (run-hooks 'ediff-quit-session-group-hook)
2147 (ediff-dispose-of-meta-buffer buf))
2148 ((ediff-safe-to-quit buf)
2152 "This session group has active sessions---cannot exit")))
2153 (ediff-update-meta-buffer parent-buf nil session-number)
2154 (ediff-kill-buffer-carefully dir-diffs-buffer)
2155 (ediff-kill-buffer-carefully meta-diff-buffer)
2156 (if (ediff-buffer-live-p parent-buf)
2158 (setq dont-show-registry t)
2159 (ediff-show-meta-buffer parent-buf session-number)))
2161 (or dont-show-registry
2162 (ediff-show-registry))))
2164 (defun ediff-dispose-of-meta-buffer (buf)
2165 (setq ediff-session-registry (delq buf ediff-session-registry))
2166 (ediff-with-current-buffer buf
2167 (if (ediff-buffer-live-p ediff-dir-diffs-buffer)
2168 (kill-buffer ediff-dir-diffs-buffer)))
2172 ;; Obtain information on a meta record where the user clicked or typed
2173 ;; BUF is the buffer where this happened and POINT is the position
2174 ;; If optional NOERROR arg is given, don't report error and return nil if no
2175 ;; meta info is found on line.
2176 (defun ediff-get-meta-info (buf point &optional noerror)
2177 (let (result olist tmp)
2178 (if (and point (ediff-buffer-live-p buf))
2179 (ediff-with-current-buffer buf
2180 (ediff-cond-compile-for-xemacs-or-emacs
2181 (setq result ; xemacs
2182 (if (setq tmp (extent-at point buf 'ediff-meta-info))
2183 (ediff-overlay-get tmp 'ediff-meta-info)))
2185 (setq olist (overlays-at point))
2187 (mapcar (lambda (elt)
2188 (unless (overlay-get elt 'invisible)
2189 (overlay-get elt 'ediff-meta-info)))
2191 (while (and olist (null (car olist)))
2192 (setq olist (cdr olist)))
2193 (setq result (car olist)))
2200 (ediff-update-registry)
2201 (error "No session info in this line")))))
2204 (defun ediff-get-meta-overlay-at-pos (point)
2205 (ediff-cond-compile-for-xemacs-or-emacs
2206 (extent-at point (current-buffer) 'ediff-meta-info) ; xemacs
2208 (let* ((overl-list (overlays-at point))
2209 (overl (car overl-list)))
2210 (while (and overl (null (overlay-get overl 'ediff-meta-info)))
2211 (setq overl-list (cdr overl-list)
2212 overl (car overl-list)))
2217 (defsubst ediff-get-session-number-at-pos (point &optional meta-buffer)
2218 (setq meta-buffer (if (ediff-buffer-live-p meta-buffer)
2221 (ediff-with-current-buffer meta-buffer
2223 (ediff-get-meta-overlay-at-pos point) 'ediff-meta-session-number)))
2226 ;; Return location of the next meta overlay after point
2227 (defun ediff-next-meta-overlay-start (point)
2229 (goto-char (point-min))
2230 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2231 (ediff-cond-compile-for-xemacs-or-emacs
2234 (setq overl (next-extent overl))
2235 (setq overl (next-extent (current-buffer))))
2237 (extent-start-position overl)
2241 ;; note: end of current overlay is the beginning of the next one
2243 (next-overlay-change point))
2249 (defun ediff-previous-meta-overlay-start (point)
2251 (goto-char (point-max))
2252 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2253 (ediff-cond-compile-for-xemacs-or-emacs
2256 (setq overl (previous-extent overl))
2257 (setq overl (previous-extent (current-buffer))))
2259 (extent-start-position overl)
2262 (if overl (setq point (overlay-start overl)))
2263 ;; to get to the beginning of prev overlay
2265 ;; trick to overcome an emacs bug--doesn't always find previous
2266 ;; overlay change correctly
2267 (setq point (1- point)))
2268 (setq point (previous-overlay-change point))
2269 ;; If we are not over an overlay after subtracting 1, it means we are
2270 ;; in the description area preceding session records. In this case,
2271 ;; goto the top of the registry buffer.
2272 (or (car (overlays-at point))
2273 (setq point (point-min)))
2278 ;; this is the action invoked when the user selects a patch from the meta
2280 (defun ediff-patch-file-form-meta (file &optional startup-hooks)
2281 (let* ((pos (ediff-event-point last-command-event))
2282 (meta-buf (ediff-event-buffer last-command-event))
2283 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
2284 (info (ediff-get-meta-info meta-buf pos))
2285 (meta-patchbuf ediff-meta-patchbufer)
2286 session-buf beg-marker end-marker)
2288 (if (or (file-directory-p file) (string-match "/dev/null" file))
2289 (error "`%s' is not an ordinary file" (file-name-as-directory file)))
2290 (setq session-buf (ediff-get-session-buffer info)
2291 beg-marker (ediff-get-session-objB-name info)
2292 end-marker (ediff-get-session-objC-name info))
2294 (or (ediff-buffer-live-p session-buf) ; either an active patch session
2295 (null session-buf) ; or it is a virgin session
2297 "Patch has already been applied to this file -- can't repeat!"))
2299 (ediff-with-current-buffer meta-patchbuf
2302 (narrow-to-region beg-marker end-marker)
2303 (ediff-patch-file-internal meta-patchbuf file startup-hooks)))))
2306 (defun ediff-unmark-all-for-operation ()
2307 "Unmark all sessions marked for operation."
2309 (let ((list (cdr ediff-meta-list))
2311 (while (setq elt (car list))
2312 (ediff-mark-session-for-operation elt 'unmark)
2313 (setq list (cdr list))))
2314 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2316 (defun ediff-unmark-all-for-hiding ()
2317 "Unmark all sessions marked for hiding."
2319 (let ((list (cdr ediff-meta-list))
2321 (while (setq elt (car list))
2322 (ediff-mark-session-for-hiding elt 'unmark)
2323 (setq list (cdr list))))
2324 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2327 ;; ACTION is ?h, ?m, ?=: to mark for hiding, mark for operation, or simply
2328 ;; indicate which are equal files
2329 (defun ediff-meta-mark-equal-files (&optional action)
2330 "Run through the session list and mark identical files.
2331 This is used only for sessions that involve 2 or 3 files at the same time.
2332 ACTION is an optional argument that can be ?h, ?m, ?=, to mark for hiding, mark
2333 for operation, or simply indicate which are equal files. If it is nil, then
2334 last-command-char is used to decide which action to take."
2337 (setq action last-command-char))
2338 (let ((list (cdr ediff-meta-list))
2339 marked1 marked2 marked3
2340 fileinfo1 fileinfo2 fileinfo3 elt)
2341 (message "Comparing files ...")
2342 (while (setq elt (car list))
2343 (setq fileinfo1 (ediff-get-session-objA elt)
2344 fileinfo2 (ediff-get-session-objB elt)
2345 fileinfo3 (ediff-get-session-objC elt))
2346 (ediff-set-file-eqstatus fileinfo1 nil)
2347 (ediff-set-file-eqstatus fileinfo2 nil)
2348 (ediff-set-file-eqstatus fileinfo3 nil)
2353 (or (ediff-mark-if-equal fileinfo1 fileinfo2)
2355 (if (ediff-metajob3)
2357 (or (ediff-mark-if-equal fileinfo1 fileinfo3)
2359 (or (ediff-mark-if-equal fileinfo2 fileinfo3)
2360 (setq marked3 nil))))
2361 (if (and marked1 marked2 marked3)
2362 (cond ((eq action ?h)
2363 (ediff-mark-session-for-hiding elt 'mark))
2365 (ediff-mark-session-for-operation elt 'mark))
2367 (setq list (cdr list)))
2368 (message "Comparing files ... Done"))
2369 (setq ediff-recurse-to-subdirectories nil)
2370 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2372 ;; mark files 1 and 2 as equal, if they are.
2373 ;; returns t, if something was marked
2374 (defun ediff-mark-if-equal (fileinfo1 fileinfo2)
2375 (let ((f1 (car fileinfo1))
2376 (f2 (car fileinfo2)))
2377 (if (and (stringp f1) (stringp f2) (ediff-same-contents f1 f2))
2379 (ediff-set-file-eqstatus fileinfo1 t)
2380 (ediff-set-file-eqstatus fileinfo2 t)
2386 ;;; Local Variables:
2387 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
2388 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
2389 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
2392 ;;; arch-tag: c8a76898-f96f-4d9c-be9d-129134017188
2393 ;;; ediff-mult.el ends here