1 ;;; ediff-mult.el --- support for multi-file/multi-buffer processing in Ediff
3 ;; Copyright (C) 1995-2013 Free Software Foundation, Inc.
5 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; Users are encouraged to add functionality to this file.
26 ;; The present file contains all the infrastructure needed for that.
28 ;; Generally, to implement a new multisession capability within Ediff,
29 ;; you need to tell it
31 ;; 1. How to display the session group buffer.
32 ;; This function must indicate which Ediff sessions are active (+) and
33 ;; which are finished (-).
34 ;; See ediff-redraw-directory-group-buffer for an example.
35 ;; In all likelihood, ediff-redraw-directory-group-buffer can be used
36 ;; directly or after a small modification.
37 ;; 2. What action to take when the user clicks button 2 or types v,e, or
38 ;; RET. See ediff-filegroup-action.
39 ;; 3. Provide a list of pairs or triples of file names (or buffers,
40 ;; depending on the particular Ediff operation you want to invoke)
41 ;; in the following format:
42 ;; (HEADER (nil nil (obj1 nil) (obj2 nil) (obj3 nil))
44 ;; The function ediff-make-new-meta-list-element can be used to create
45 ;; 2nd and subsequent elements of that list (i.e., after the
46 ;; description header). See ediff-make-new-meta-list-element for the
47 ;; explanation of the two nil placeholders in such elements.
49 ;; There is API for extracting the components of the members of the
50 ;; above list. Search for `API for ediff-meta-list' for details.
52 ;; HEADER must be a list of SIX elements (nil or string):
53 ;; (regexp metaobj1 metaobj2 metaobj3 merge-save-buffer
54 ;; comparison-function)
55 ;; The function ediff-redraw-registry-buffer displays the
56 ;; 1st - 4th of these in the registry buffer.
57 ;; For some jobs some of the members of the header might be nil.
58 ;; The meaning of metaobj1, metaobj2, and metaobj3 depend on the job.
59 ;; Typically these are directories where the files to be compared are
61 ;; Also, keep in mind that the function ediff-prepare-meta-buffer
62 ;; (which see) prepends the session group buffer to the descriptor, so
63 ;; the descriptor becomes 7-long.
64 ;; Ediff expects that your function (in 2 above) will arrange to
65 ;; replace this prepended nil (via setcar) with the actual ediff
66 ;; control buffer associated with an appropriate Ediff session.
67 ;; This is arranged through internal startup hooks that can be passed
68 ;; to any of Ediff major entries (such as ediff-files, epatch, etc.).
69 ;; See how this is done in ediff-filegroup-action.
71 ;; Session descriptions are of the form
72 ;; (nil nil (obj1 . nil) (obj2 . nil) (obj3 . nil))
73 ;; which describe the objects relevant to the session.
74 ;; Use ediff-make-new-meta-list-element to create these things.
75 ;; Usually obj1/2/3 are names of files, but they may also be other
76 ;; things for some jobs. For instance, obj3 is nil for jobs that
77 ;; involve only two files. For patch jobs, obj2 and obj3 are markers
78 ;; that specify the patch corresponding to the file
79 ;; (whose name is obj1).
80 ;; The nil's are placeholders, which are used internally by ediff.
81 ;; 4. Write a function that makes a call to ediff-prepare-meta-buffer
82 ;; passing all this info.
83 ;; You may be able to use ediff-directories-internal as a template.
84 ;; 5. If you intend to add several related pieces of functionality,
85 ;; you may want to keep the function in 4 as an internal version
86 ;; and then write several top-level interactive functions that call it
87 ;; with different parameters.
88 ;; See how ediff-directories, ediff-merge-directories, and
89 ;; ediff-merge-directories-with-ancestor all use
90 ;; ediff-directories-internal.
92 ;; A useful addition here could be session groups selected by patterns
93 ;; (which are different in each directory). For instance, one may want to
94 ;; compare files of the form abc{something}.c to files old{something}.d
95 ;; which may be in the same or different directories. Or, one may want to
96 ;; compare all files of the form {something} to files of the form {something}~.
98 ;; Implementing this requires writing a collating function, which should pair
99 ;; up appropriate files. It will also require a generalization of the
100 ;; functions that do the layout of the meta- and differences buffers and of
101 ;; ediff-filegroup-action.
106 (provide 'ediff-mult
)
108 (defgroup ediff-mult nil
109 "Multi-file and multi-buffer processing in Ediff."
113 (require 'ediff-init
)
114 (require 'ediff-diff
)
115 (require 'ediff-wind
)
116 (require 'ediff-util
)
120 (ediff-defvar-local ediff-meta-buffer nil
"")
121 (ediff-defvar-local ediff-parent-meta-buffer nil
"")
122 ;; the registry buffer
123 (defvar ediff-registry-buffer nil
)
125 (defconst ediff-meta-buffer-brief-message
"Ediff Session Group Panel: %s
127 Type ? to show useful commands in this buffer
131 (defconst ediff-meta-buffer-verbose-message
"Ediff Session Group Panel: %s
133 Useful commands (type ? to hide them and free up screen):
134 button2, v, or RET over session record: start that Ediff session
135 M:\tin sessions invoked from here, brings back this group panel
136 R:\tdisplay the registry of active Ediff sessions
137 h:\tmark session for hiding (toggle)
138 x:\thide marked sessions; with prefix arg: unhide
139 m:\tmark session for a non-hiding operation (toggle)
140 uh/um:\tunmark all sessions marked for hiding/operation
142 p,DEL:\tprevious session
143 E:\tbrowse Ediff on-line manual
144 T:\ttoggle truncation of long file names
145 q:\tquit this session group
148 (ediff-defvar-local ediff-meta-buffer-map nil
149 "The keymap for the meta buffer.")
150 (defvar ediff-dir-diffs-buffer-map
(make-sparse-keymap)
151 "The keymap to be installed in the buffer showing differences between
154 ;; Variable specifying the action to take when the use invokes ediff in the
155 ;; meta buffer. This is usually ediff-registry-action or ediff-filegroup-action
156 (ediff-defvar-local ediff-meta-action-function nil
"")
157 ;; Tells ediff-update-meta-buffer how to redraw it
158 (ediff-defvar-local ediff-meta-redraw-function nil
"")
159 ;; Tells ediff-filegroup-action and similar procedures how to invoke Ediff for
160 ;; the sessions in a given session group
161 (ediff-defvar-local ediff-session-action-function nil
"")
163 (ediff-defvar-local ediff-metajob-name nil
"")
165 ;; buffer used to collect custom diffs from individual sessions in the group
166 (ediff-defvar-local ediff-meta-diff-buffer nil
"")
168 ;; t means recurse into subdirs when deciding which files have same contents
169 (ediff-defvar-local ediff-recurse-to-subdirectories nil
"")
171 ;; history var to use for filtering groups of files
172 (defvar ediff-filtering-regexp-history nil
"")
174 (defcustom ediff-default-filtering-regexp nil
175 "The default regular expression used as a filename filter in multifile comparisons.
176 Should be a sexp. For instance (car ediff-filtering-regexp-history) or nil."
180 ;; This has the form ((meta-buf regexp dir1 dir2 dir3 merge-auto-store-dir)
181 ;; (ctl-buf session-status (file1 . eq-status) (file2 . eq-status) (file3
182 ;; . eq-status)) (ctl-buf session-status (file1 . eq-status) (file2
183 ;; . eq-status)) ...)
184 ;; If ctl-buf is nil, the file-pair hasn't processed yet. If it is
185 ;; killed-buffer object, the file pair has been processed. If it is a live
186 ;; buffer, this means ediff is still working on the pair.
187 ;; Eq-status of a file is t if the file equals some other file in the same
189 (ediff-defvar-local ediff-meta-list nil
"")
191 (ediff-defvar-local ediff-meta-session-number nil
"")
194 ;; the difference list between directories in a directory session group
195 (ediff-defvar-local ediff-dir-difference-list nil
"")
196 (ediff-defvar-local ediff-dir-diffs-buffer nil
"")
198 ;; The registry of Ediff sessions. A list of control buffers.
199 (defvar ediff-session-registry nil
)
201 (defcustom ediff-meta-truncate-filenames t
202 "If non-nil, truncate long file names in the session group buffers.
203 This can be toggled with `ediff-toggle-filename-truncation'."
207 (defcustom ediff-meta-mode-hook nil
208 "Hooks run just after setting up meta mode."
212 (defcustom ediff-registry-setup-hook nil
213 "Hooks run just after the registry control panel is set up."
217 (defcustom ediff-before-session-group-setup-hooks
218 nil
;FIXME: Bad name (should be -hook or -functions) and never run??
219 "Hook run before Ediff arranges the window for group-level operations.
220 It is used by commands such as `ediff-directories'.
221 This hook can be used to save the previous window config, which can be restored
222 on `ediff-quit', `ediff-suspend', or `ediff-quit-session-group-hook'."
225 (defcustom ediff-after-session-group-setup-hook nil
226 "Hooks run just after a meta-buffer controlling a session group, such as
227 ediff-directories, is run."
230 (defcustom ediff-quit-session-group-hook nil
231 "Hooks run just before exiting a session group."
234 (defcustom ediff-show-registry-hook nil
235 "Hooks run just after the registry buffer is shown."
238 (defcustom ediff-show-session-group-hook
'(delete-other-windows)
239 "Hooks run just after a session group buffer is shown."
242 (defcustom ediff-meta-buffer-keymap-setup-hook nil
243 "Hooks run just after setting up the `ediff-meta-buffer-map'.
244 This keymap controls key bindings in the meta buffer and is a local variable.
245 This means that you can set different bindings for different kinds of meta
250 ;; Buffer holding the multi-file patch. Local to the meta buffer
251 (ediff-defvar-local ediff-meta-patchbufer nil
"")
253 ;;; API for ediff-meta-list
255 ;; A meta-list is either ediff-meta-list, which contains a header and the list
256 ;; of ediff sessions or ediff-dir-difference-list, which is a header followed
257 ;; by the list of differences among the directories (i.e., files that are not
258 ;; in all directories). The header is the same in all meta lists, but the rest
260 ;; Structure of the meta-list:
261 ;; (HEADER SESSION1 SESSION2 ...)
262 ;; HEADER: (GROUP-BUF REGEXP OBJA OBJB OBJC SAVE-DIR COMPARISON-FUNC)
263 ;; OBJA - first directory
264 ;; OBJB - second directory
265 ;; OBJC - third directory
266 ;; SESSION1/2/... are described below
267 ;; group buffer/regexp
268 (defsubst ediff-get-group-buffer
(meta-list)
269 (nth 0 (car meta-list
)))
271 (defsubst ediff-get-group-regexp
(meta-list)
272 (nth 1 (car meta-list
)))
274 (defsubst ediff-get-group-objA
(meta-list)
275 (nth 2 (car meta-list
)))
276 (defsubst ediff-get-group-objB
(meta-list)
277 (nth 3 (car meta-list
)))
278 (defsubst ediff-get-group-objC
(meta-list)
279 (nth 4 (car meta-list
)))
280 (defsubst ediff-get-group-merge-autostore-dir
(meta-list)
281 (nth 5 (car meta-list
)))
282 (defsubst ediff-get-group-comparison-func
(meta-list)
283 (nth 6 (car meta-list
)))
285 ;; ELT is a session meta descriptor (what is being preserved as
287 ;; The structure is: (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
288 ;; STATUS is ?I (hidden or invalid), ?* (marked for operation), ?H (hidden)
290 ;; OBJA/B/C is (FILENAME EQSTATUS)
291 ;; EQSTATUS is ?= or nil (?= means that this file is equal to some other
292 ;; file in this session)
294 (defsubst ediff-get-session-buffer
(elt)
296 (defsubst ediff-get-session-status
(elt)
298 (defsubst ediff-set-session-status
(session-info new-status
)
299 (setcar (cdr session-info
) new-status
))
301 (defsubst ediff-get-session-objA
(elt)
303 (defsubst ediff-get-session-objB
(elt)
305 (defsubst ediff-get-session-objC
(elt)
307 ;; Take the "name" component of the object into account. ObjA/C/B is of the form
308 ;; (name . equality-indicator)
309 (defsubst ediff-get-session-objA-name
(elt)
311 (defsubst ediff-get-session-objB-name
(elt)
313 (defsubst ediff-get-session-objC-name
(elt)
315 ;; equality indicators
316 (defsubst ediff-get-file-eqstatus
(elt)
318 (defsubst ediff-set-file-eqstatus
(elt value
)
319 (setcar (cdr elt
) value
))
321 ;; Create a new element for the meta list out of obj1/2/3, which usually are
324 ;; The first nil in such an element is later replaced with the session buffer.
325 ;; The second nil is reserved for session status.
327 ;; Also, session objects A/B/C are turned into lists of the form (obj nil).
328 ;; This nil is a placeholder for eq-indicator. It is either nil or =.
329 ;; If it is discovered that this file is = to some other
330 ;; file in the same session, eq-indicator is changed to `='.
331 ;; Currently, the eq-indicator is used only for 2 and 3-file jobs.
332 (defun ediff-make-new-meta-list-element (obj1 obj2 obj3
)
333 (list nil nil
(list obj1 nil
) (list obj2 nil
) (list obj3 nil
)))
335 ;; Constructs a meta list header.
336 ;; OBJA, OBJB, OBJC are usually directories involved, but can be different for
337 ;; different jobs. For instance, multifile patch has only OBJA, which is the
339 (defun ediff-make-new-meta-list-header (regexp
343 (list regexp objA objB objC merge-auto-store-dir comparison-func
))
345 ;; The activity marker is either or + (active session, i.e., ediff is currently
346 ;; run in it), or - (finished session, i.e., we've ran ediff in it and then
347 ;; exited). Return nil, if session is neither active nor finished
348 (defun ediff-get-session-activity-marker (session)
349 (let ((session-buf (ediff-get-session-buffer session
)))
350 (cond ((null session-buf
) nil
) ; virgin session
351 ((ediff-buffer-live-p session-buf
) ?
+) ;active session
354 ;; checks if the session is a meta session
355 (defun ediff-meta-session-p (session-info)
356 (and (stringp (ediff-get-session-objA-name session-info
))
357 (file-directory-p (ediff-get-session-objA-name session-info
))
358 (stringp (ediff-get-session-objB-name session-info
))
359 (file-directory-p (ediff-get-session-objB-name session-info
))
360 (if (stringp (ediff-get-session-objC-name session-info
))
361 (file-directory-p (ediff-get-session-objC-name session-info
)) t
)))
364 (ediff-defvar-local ediff-verbose-help-enabled nil
365 "If t, display redundant help in ediff-directories and other meta buffers.
366 Toggled by ediff-toggle-verbose-help-meta-buffer" )
368 ;; Toggle verbose help in meta-buffers
369 ;; TODO: Someone who understands all this can make it better.
370 (defun ediff-toggle-verbose-help-meta-buffer ()
371 "Toggle showing tediously verbose help in meta buffers."
373 (setq ediff-verbose-help-enabled
(not ediff-verbose-help-enabled
))
374 (ediff-update-meta-buffer (current-buffer) 'must-redraw
))
376 ;; set up the keymap in the meta buffer
377 (defun ediff-setup-meta-map ()
378 (setq ediff-meta-buffer-map
(make-sparse-keymap))
379 (suppress-keymap ediff-meta-buffer-map
)
380 (define-key ediff-meta-buffer-map
"?" 'ediff-toggle-verbose-help-meta-buffer
)
381 (define-key ediff-meta-buffer-map
"q" 'ediff-quit-meta-buffer
)
382 (define-key ediff-meta-buffer-map
"T" 'ediff-toggle-filename-truncation
)
383 (define-key ediff-meta-buffer-map
"R" 'ediff-show-registry
)
384 (define-key ediff-meta-buffer-map
"E" 'ediff-documentation
)
385 (define-key ediff-meta-buffer-map
"v" ediff-meta-action-function
)
386 (define-key ediff-meta-buffer-map
"\C-m" ediff-meta-action-function
)
387 (define-key ediff-meta-buffer-map
" " 'ediff-next-meta-item
)
388 (define-key ediff-meta-buffer-map
"n" 'ediff-next-meta-item
)
389 (define-key ediff-meta-buffer-map
"\C-?" 'ediff-previous-meta-item
)
390 (define-key ediff-meta-buffer-map
"p" 'ediff-previous-meta-item
)
391 (define-key ediff-meta-buffer-map
[delete] 'ediff-previous-meta-item)
392 (define-key ediff-meta-buffer-map [backspace] 'ediff-previous-meta-item)
394 (let ((menu-map (make-sparse-keymap "Ediff-Meta")))
395 (define-key ediff-meta-buffer-map [menu-bar ediff-meta-mode]
396 (cons "Ediff-Meta" menu-map))
397 (define-key menu-map [ediff-quit-meta-buffer]
398 '(menu-item "Quit" ediff-quit-meta-buffer
399 :help "Quit the meta buffer"))
400 (define-key menu-map [ediff-toggle-filename-truncation]
401 '(menu-item "Truncate filenames" ediff-toggle-filename-truncation
402 :help "Toggle truncation of long file names in session group buffers"
403 :button (:toggle . ediff-meta-truncate-filenames)))
404 (define-key menu-map [ediff-show-registry]
405 '(menu-item "Display Ediff Registry" ediff-show-registry
406 :help "Display Ediff's registry"))
407 (define-key menu-map [ediff-documentation]
408 '(menu-item "Show Manual" ediff-documentation
409 :help "Display Ediff's manual"))
411 (or (ediff-one-filegroup-metajob)
413 (define-key ediff-meta-buffer-map "=" nil)
414 (define-key ediff-meta-buffer-map "==" 'ediff-meta-mark-equal-files)
415 (define-key ediff-meta-buffer-map "=m" 'ediff-meta-mark-equal-files)
416 (define-key ediff-meta-buffer-map "=h" 'ediff-meta-mark-equal-files)))
419 (define-key menu-map [ediff-next-meta-item]
420 '(menu-item "Next" ediff-next-meta-item
421 :help "Move to the next item in Ediff registry or session group buffer"))
422 (define-key menu-map [ediff-previous-meta-item]
423 '(menu-item "Previous" ediff-previous-meta-item
424 :help "Move to the previous item in Ediff registry or session group buffer")))
427 (if ediff-no-emacs-help-in-control-buffer
428 (define-key ediff-meta-buffer-map "\C-h" 'ediff-previous-meta-item))
429 (if (featurep 'emacs)
430 (define-key ediff-meta-buffer-map [mouse-2] ediff-meta-action-function)
431 (define-key ediff-meta-buffer-map [button2] ediff-meta-action-function))
433 (use-local-map ediff-meta-buffer-map)
434 ;; modify ediff-meta-buffer-map here
435 (run-hooks 'ediff-meta-buffer-keymap-setup-hook))
438 (defun ediff-meta-mode ()
439 "This mode controls all operations on Ediff session groups.
440 It is entered through one of the following commands:
445 `ediff-merge-directories'
447 `ediff-merge-directories-with-ancestor'
448 `edirs-merge-with-ancestor'
449 `ediff-directory-revisions'
451 `ediff-merge-directory-revisions'
452 `edir-merge-revisions'
453 `ediff-merge-directory-revisions-with-ancestor'
454 `edir-merge-revisions-with-ancestor'
457 \\{ediff-meta-buffer-map}"
458 ;; FIXME: Use define-derived-mode.
459 (kill-all-local-variables)
460 (setq major-mode 'ediff-meta-mode)
461 (setq mode-name "MetaEdiff")
462 ;; don't use run-mode-hooks here!
463 (run-hooks 'ediff-meta-mode-hook))
466 ;; the keymap for the buffer showing directory differences
467 (suppress-keymap ediff-dir-diffs-buffer-map)
468 (define-key ediff-dir-diffs-buffer-map "q" 'ediff-bury-dir-diffs-buffer)
469 (define-key ediff-dir-diffs-buffer-map " " 'next-line)
470 (define-key ediff-dir-diffs-buffer-map "n" 'next-line)
471 (define-key ediff-dir-diffs-buffer-map "\C-?" 'previous-line)
472 (define-key ediff-dir-diffs-buffer-map "p" 'previous-line)
473 (define-key ediff-dir-diffs-buffer-map "C" 'ediff-dir-diff-copy-file)
474 (if (featurep 'emacs)
475 (define-key ediff-dir-diffs-buffer-map [mouse-2] 'ediff-dir-diff-copy-file)
476 (define-key ediff-dir-diffs-buffer-map [button2] 'ediff-dir-diff-copy-file))
477 (define-key ediff-dir-diffs-buffer-map [delete] 'previous-line
)
478 (define-key ediff-dir-diffs-buffer-map
[backspace] 'previous-line)
480 (defun ediff-next-meta-item (count)
481 "Move to the next item in Ediff registry or session group buffer.
482 Moves in circular fashion. With numeric prefix arg, skip this many items."
484 (or count (setq count 1))
487 (setq count (1- count))
488 (ediff-next-meta-item1)
489 (setq overl (ediff-get-meta-overlay-at-pos (point)))
490 ;; skip invisible ones
491 (while (and overl (ediff-overlay-get overl 'invisible))
492 (ediff-next-meta-item1)
493 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
495 ;; Move to the next meta item
496 (defun ediff-next-meta-item1 ()
498 (setq pos (ediff-next-meta-overlay-start (point)))
499 (if pos (goto-char pos))
500 (if (eq ediff-metajob-name 'ediff-registry)
501 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
502 (search-forward "*Ediff" nil t))
503 (skip-chars-backward "a-zA-Z*"))
504 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
505 (backward-char 1)))))
508 (defun ediff-previous-meta-item (count)
509 "Move to the previous item in Ediff registry or session group buffer.
510 Moves in circular fashion. With numeric prefix arg, skip this many items."
512 (or count (setq count 1))
515 (setq count (1- count))
516 (ediff-previous-meta-item1)
517 (setq overl (ediff-get-meta-overlay-at-pos (point)))
518 ;; skip invisible ones
519 (while (and overl (ediff-overlay-get overl 'invisible))
520 (ediff-previous-meta-item1)
521 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
523 (defun ediff-previous-meta-item1 ()
525 (setq pos (ediff-previous-meta-overlay-start (point)))
527 ;;; (while (ediff-get-session-status
528 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
529 ;;; (setq pos (ediff-previous-meta-overlay-start pos)))
531 (if pos (goto-char pos))
532 (if (eq ediff-metajob-name 'ediff-registry)
533 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
534 (search-forward "*Ediff" nil t))
535 (skip-chars-backward "a-zA-Z*"))
536 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
540 (defsubst ediff-add-slash-if-directory (dir file)
541 (if (file-directory-p (concat dir file))
542 (file-name-as-directory file)
545 (defun ediff-toggle-filename-truncation ()
546 "Toggle truncation of long file names in session group buffers.
547 Set `ediff-meta-truncate-filenames' variable if you want to change the default
550 (setq ediff-meta-truncate-filenames (not ediff-meta-truncate-filenames))
551 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
554 ;; These are used to encode membership of files in directory1/2/3
555 ;; Membership code of a file is a product of codes for the directories where
557 (defvar ediff-membership-code1 2)
558 (defvar ediff-membership-code2 3)
559 (defvar ediff-membership-code3 5)
560 (defvar ediff-product-of-memcodes (* ediff-membership-code1
561 ediff-membership-code2
562 ediff-membership-code3))
564 ;; DIR1, DIR2, DIR3 are directories. DIR3 can be nil.
565 ;; OUTPUT-DIR is a directory for auto-storing the results of merge jobs.
567 ;; REGEXP is nil or a filter regexp; only file names that match the regexp
569 ;; If a file is a directory in dir1 but not dir2 (or vice versa), it is not
570 ;; included in the intersection. However, a regular file that is a dir in dir3
571 ;; is included, since dir3 files are supposed to be ancestors for merging.
572 ;; If COMPARISON-FUNC is given, use it. Otherwise, use string=
574 ;; Returns a list of the form:
575 ;; (COMMON-PART DIFF-LIST)
576 ;; COMMON-PART is car and DIFF-LIST is cdr.
578 ;; COMMON-PART is of the form:
579 ;; (META-HEADER (f1 f2 f3) (f1 f2 f3) ...)
580 ;; f3 can be nil if intersecting only 2 directories.
581 ;; Each triple (f1 f2 f3) represents the files to be compared in the
582 ;; corresponding ediff subsession.
584 ;; DIFF-LIST is of the form:
585 ;; (META-HEADER (file . num) (file . num)...)
586 ;; where num encodes the set of dirs where the file is found:
587 ;; 2 - only dir1; 3 - only dir2; 5 - only dir3; 6 - dir1&2; 10 - dir1&3; etc.
589 ;; Contains the meta info about this ediff operation
590 ;; (regexp dir1 dir2 dir3 merge-auto-store-dir comparison-func)
591 ;; Later the meta-buffer is prepended to this list.
593 ;; Some operations might use a different meta header. For instance,
594 ;; ediff-multifile-patch doesn't have dir2 and dir3, and regexp,
595 ;; comparison-func don't apply.
597 (defun ediff-intersect-directories (jobname
600 dir3 merge-autostore-dir comparison-func)
601 (setq comparison-func (or comparison-func 'string=))
602 (let (lis1 lis2 lis3 common auxdir1 auxdir2 auxdir3 common-part difflist)
604 (setq auxdir1 (file-name-as-directory dir1)
605 lis1 (directory-files auxdir1 nil regexp)
606 lis1 (delete "." lis1)
607 lis1 (delete ".." lis1)
610 (ediff-add-slash-if-directory auxdir1 elt))
612 auxdir2 (file-name-as-directory dir2)
613 lis2 (directory-files auxdir2 nil regexp)
614 lis2 (delete "." lis2)
615 lis2 (delete ".." lis2)
618 (ediff-add-slash-if-directory auxdir2 elt))
622 (setq auxdir3 (file-name-as-directory dir3)
623 lis3 (directory-files auxdir3 nil regexp)
624 lis3 (delete "." lis3)
625 lis3 (delete ".." lis3)
628 (ediff-add-slash-if-directory auxdir3 elt))
631 (if (ediff-nonempty-string-p merge-autostore-dir)
632 (setq merge-autostore-dir
633 (file-name-as-directory merge-autostore-dir)))
634 (setq common (ediff-intersection lis1 lis2 comparison-func))
636 ;; In merge with ancestor jobs, we don't intersect with lis3.
637 ;; If there is no ancestor, we'll offer to merge without the ancestor.
638 ;; So, we intersect with lis3 only when we are doing 3-way file comparison
639 (if (and lis3 (ediff-comparison-metajob3 jobname))
640 (setq common (ediff-intersection common lis3 comparison-func)))
642 ;; copying is needed because sort sorts via side effects
643 (setq common (sort (ediff-copy-list common) 'string-lessp))
645 ;; compute difference list
646 (setq difflist (ediff-set-difference
647 (ediff-union (ediff-union lis1 lis2 comparison-func)
652 difflist (delete "." difflist)
653 ;; copying is needed because sort sorts via side effects
654 difflist (sort (ediff-copy-list (delete ".." difflist))
657 (setq difflist (mapcar (lambda (elt) (cons elt 1)) difflist))
659 ;; check for files belonging to lis1/2/3
660 ;; Each elt is of the norm (file . number)
661 ;; Number encodes the directories to which file belongs.
662 ;; It is a product of a subset of ediff-membership-code1=2,
663 ;; ediff-membership-code2=3, and ediff-membership-code3=5.
664 ;; If file belongs to dir 1 only, the membership code is 2.
665 ;; If it is in dir1 and dir3, then the membership code is 2*5=10;
666 ;; if it is in dir1 and dir2, then the membership code is 2*3=6, etc.
668 (if (member (car elt) lis1)
669 (setcdr elt (* (cdr elt) ediff-membership-code1)))
670 (if (member (car elt) lis2)
671 (setcdr elt (* (cdr elt) ediff-membership-code2)))
672 (if (member (car elt) lis3)
673 (setcdr elt (* (cdr elt) ediff-membership-code3)))
677 ;; diff metalist header
678 (ediff-make-new-meta-list-header regexp
679 auxdir1 auxdir2 auxdir3
687 (ediff-make-new-meta-list-header regexp
688 auxdir1 auxdir2 auxdir3
693 (ediff-make-new-meta-list-element
694 (expand-file-name (concat auxdir1 elt))
695 (expand-file-name (concat auxdir2 elt))
698 ;; The following is done because: In merging with
699 ;; ancestor, we don't intersect with lis3. So, it is
700 ;; possible that elt is a file in auxdir1/2 but a
701 ;; directory in auxdir3 Or elt may not exist in auxdir3 at
702 ;; all. In the first case, we add a slash at the end. In
703 ;; the second case, we insert nil.
704 (setq elt (ediff-add-slash-if-directory auxdir3 elt))
705 (if (file-exists-p (concat auxdir3 elt))
706 (expand-file-name (concat auxdir3 elt)))))))
709 (cons common-part difflist)
712 ;; find directory files that are under revision. Include subdirectories, since
713 ;; we may visit them recursively. DIR1 is the directory to inspect.
714 ;; MERGE-AUTOSTORE-DIR is the directory where to auto-store the results of
715 ;; merges. Can be nil.
716 (defun ediff-get-directory-files-under-revision (jobname
718 &optional merge-autostore-dir)
719 (let (lis1 elt common auxdir1)
720 (setq auxdir1 (file-name-as-directory dir1)
721 lis1 (directory-files auxdir1 nil regexp))
723 (if (ediff-nonempty-string-p merge-autostore-dir)
724 (setq merge-autostore-dir
725 (file-name-as-directory merge-autostore-dir)))
730 ;; take files under revision control
731 (cond ((file-directory-p (concat auxdir1 elt))
733 (cons (ediff-add-slash-if-directory auxdir1 elt) common)))
734 ((and (featurep 'vc-hooks) (vc-backend (concat auxdir1 elt)))
735 (setq common (cons elt common)))
736 ;; The following two are needed only if vc-hooks isn't loaded.
737 ;; They won't recognize CVS files.
738 ((file-exists-p (concat auxdir1 elt ",v"))
739 (setq common (cons elt common)))
740 ((file-exists-p (concat auxdir1 "RCS/" elt ",v"))
741 (setq common (cons elt common)))
745 (setq common (delete "./" common)
746 common (delete "../" common)
747 common (delete "RCS" common)
748 common (delete "CVS" common)
751 ;; copying is needed because sort sorts via side effects
752 (setq common (sort (ediff-copy-list common) 'string-lessp))
756 ;; header -- has 6 elements. Meta buffer is prepended later by
757 ;; ediff-prepare-meta-buffer
758 (ediff-make-new-meta-list-header regexp
760 merge-autostore-dir nil)
761 (mapcar (lambda (elt) (ediff-make-new-meta-list-element
762 (expand-file-name (concat auxdir1 elt)) nil nil))
767 ;; If file groups selected by patterns will ever be implemented, this
768 ;; comparison function might become useful.
769 ;;;; uses external variables PAT1 PAT2 to compare str1/2
770 ;;;; patterns must be of the form ???*???? where ??? are strings of chars
771 ;;;; containing no *.
772 ;;(defun ediff-pattern= (str1 str2)
773 ;; (let (pos11 pos12 pos21 pos22 len1 len2)
775 ;; len (length epat1)
777 ;; (while (and (< pos11 len) (not (= (aref epat1 pos11) ?*)))
778 ;; (setq pos11 (1+ pos11)))
779 ;; (while (and (> pos12 0) (not (= (aref epat1 (1- pos12)) ?*)))
780 ;; (setq pos12 (1- pos12)))
783 ;; len (length epat2)
785 ;; (while (and (< pos21 len) (not (= (aref epat2 pos21) ?*)))
786 ;; (setq pos21 (1+ pos21)))
787 ;; (while (and (> pos22 0) (not (= (aref epat2 (1- pos22)) ?*)))
788 ;; (setq pos22 (1- pos22)))
790 ;; (if (and (> (length str1) pos12) (>= pos12 pos11) (> pos11 -1)
791 ;; (> (length str2) pos22) (>= pos22 pos21) (> pos21 -1))
792 ;; (string= (substring str1 pos11 pos12)
793 ;; (substring str2 pos21 pos22)))
797 ;; Prepare meta-buffer in accordance with the argument-function and
798 ;; redraw-function. Must return the created meta-buffer.
799 (defun ediff-prepare-meta-buffer (action-func meta-list
800 meta-buffer-name redraw-function
801 jobname &optional startup-hooks)
802 (let* ((meta-buffer-name
803 (ediff-unique-buffer-name meta-buffer-name "*"))
804 (meta-buffer (get-buffer-create meta-buffer-name)))
805 (ediff-with-current-buffer meta-buffer
810 (setq ediff-meta-action-function action-func
811 ediff-meta-redraw-function redraw-function
812 ediff-metajob-name jobname
813 ediff-meta-buffer meta-buffer)
815 ;; comes after ediff-meta-action-function is set
816 (ediff-setup-meta-map)
818 (if (eq ediff-metajob-name 'ediff-registry)
820 (setq ediff-registry-buffer meta-buffer
821 ediff-meta-list meta-list)
822 ;; this func is used only from registry buffer, not from other
825 ediff-meta-buffer-map "M" 'ediff-show-meta-buff-from-registry))
826 ;; Initialize the meta list -- we don't do this for registry.
827 (setq ediff-meta-list
828 ;; add meta-buffer to the list header
829 (cons (cons meta-buffer (car meta-list))
832 (or (eq meta-buffer ediff-registry-buffer)
833 (setq ediff-session-registry
834 (cons meta-buffer ediff-session-registry)))
836 ;; redraw-function uses ediff-meta-list
837 (funcall redraw-function ediff-meta-list)
839 ;; set read-only/non-modified
840 (setq buffer-read-only t)
841 (set-buffer-modified-p nil)
843 (run-hooks 'startup-hooks)
845 ;; Arrange to show directory contents differences
846 ;; Must be after run startup-hooks, since ediff-dir-difference-list is
847 ;; set inside these hooks
848 (if (eq action-func 'ediff-filegroup-action)
850 ;; put meta buffer in (car ediff-dir-difference-list)
851 (setq ediff-dir-difference-list
852 (cons (cons meta-buffer (car ediff-dir-difference-list))
853 (cdr ediff-dir-difference-list)))
855 (or (ediff-one-filegroup-metajob jobname)
856 (ediff-draw-dir-diffs ediff-dir-difference-list))
858 ediff-meta-buffer-map "h" 'ediff-mark-for-hiding-at-pos)
859 (define-key ediff-meta-buffer-map "x" 'ediff-hide-marked-sessions)
861 ediff-meta-buffer-map "m" 'ediff-mark-for-operation-at-pos)
862 (define-key ediff-meta-buffer-map "u" nil)
864 ediff-meta-buffer-map "um" 'ediff-unmark-all-for-operation)
866 ediff-meta-buffer-map "uh" 'ediff-unmark-all-for-hiding)
868 (define-key ediff-meta-buffer-map
869 [menu-bar ediff-meta-mode ediff-hide-marked-sessions]
870 '(menu-item "Hide marked" ediff-hide-marked-sessions
871 :help "Hide marked sessions. With prefix arg, unhide"))
873 (define-key ediff-meta-buffer-map
874 [menu-bar ediff-meta-mode ediff-mark-for-hiding-at-pos]
875 '(menu-item "Mark for hiding" ediff-mark-for-hiding-at-pos
876 :help "Mark session for hiding. With prefix arg, unmark"))
878 (define-key ediff-meta-buffer-map
879 [menu-bar ediff-meta-mode ediff-mark-for-operation-at-pos]
880 '(menu-item "Mark for group operation" ediff-mark-for-operation-at-pos
881 :help "Mark session for a group operation. With prefix arg, unmark"))
883 (define-key ediff-meta-buffer-map
884 [menu-bar ediff-meta-mode ediff-unmark-all-for-hiding]
885 '(menu-item "Unmark all for hiding" ediff-unmark-all-for-hiding
886 :help "Unmark all sessions marked for hiding"))
888 (define-key ediff-meta-buffer-map
889 [menu-bar ediff-meta-mode ediff-unmark-all-for-operation]
890 '(menu-item "Unmark all for group operation" ediff-unmark-all-for-operation
891 :help "Unmark all sessions marked for operation"))
893 (cond ((ediff-collect-diffs-metajob jobname)
894 (define-key ediff-meta-buffer-map
895 [menu-bar ediff-meta-mode ediff-collect-custom-diffs]
896 '(menu-item "Collect diffs" ediff-collect-custom-diffs
897 :help "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'"))
899 ediff-meta-buffer-map "P" 'ediff-collect-custom-diffs))
900 ((ediff-patch-metajob jobname)
901 (define-key ediff-meta-buffer-map
902 [menu-bar ediff-meta-mode ediff-meta-show-patch]
903 '(menu-item "Show multi-file patch" ediff-meta-show-patch
904 :help "Show the multi-file patch associated with this group session"))
906 ediff-meta-buffer-map "P" 'ediff-meta-show-patch)))
907 (define-key ediff-meta-buffer-map "^" 'ediff-up-meta-hierarchy)
908 (define-key ediff-meta-buffer-map "D" 'ediff-show-dir-diffs)
910 (define-key ediff-meta-buffer-map
911 [menu-bar ediff-meta-mode ediff-up-meta-hierarchy]
912 '(menu-item "Go to parent session" ediff-up-meta-hierarchy
913 :help "Go to the parent session group buffer"))
915 (define-key ediff-meta-buffer-map
916 [menu-bar ediff-meta-mode ediff-show-dir-diffs]
917 '(menu-item "Diff directories" ediff-show-dir-diffs
918 :help "Display differences among the directories involved in session group"))))
920 (if (eq ediff-metajob-name 'ediff-registry)
921 (run-hooks 'ediff-registry-setup-hook)
922 (run-hooks 'ediff-after-session-group-setup-hook))
923 ) ; eval in meta-buffer
926 ;; Insert the activity marker for session SESSION in the meta buffer at point
927 ;; The activity marker is either SPC (untouched session), or + (active session,
928 ;; i.e., ediff is currently run in it), or - (finished session, i.e., we've ran
929 ;; ediff in it and then exited)
930 (defun ediff-insert-session-activity-marker-in-meta-buffer (session)
932 (cond ((ediff-get-session-activity-marker session))
936 ;; Insert session status at point. Status is either ?H (marked for hiding), or
937 ;; ?I (hidden or invalid), or ?* (meaning marked for an operation; currently,
938 ;; such op can only be checking for equality)), or SPC (meaning neither marked
940 (defun ediff-insert-session-status-in-meta-buffer (session)
942 (cond ((ediff-get-session-status session)) ; session has status: ?H, ?I, ?*
943 ;; normal session, no marks or hidings
946 ;; If NEW-MARKER is non-nil, use it to substitute the current activity marker
947 ;; in the meta buffer. If nil, use SPC
948 (defun ediff-replace-session-activity-marker-in-meta-buffer (point new-marker)
949 (let* ((overl (ediff-get-meta-overlay-at-pos point))
950 (session-info (ediff-overlay-get overl 'ediff-meta-info))
951 (activity-marker (ediff-get-session-activity-marker session-info))
953 (or new-marker activity-marker (setq new-marker ?\s))
954 (goto-char (ediff-overlay-start overl))
955 (if (eq (char-after (point)) new-marker)
956 () ; if marker shown in buffer is the same as new-marker, do nothing
959 (set-buffer-modified-p nil))))
961 ;; If NEW-STATUS is non-nil, use it to substitute the current status marker in
962 ;; the meta buffer. If nil, use SPC
963 (defun ediff-replace-session-status-in-meta-buffer (point new-status)
964 (let* ((overl (ediff-get-meta-overlay-at-pos point))
965 (session-info (ediff-overlay-get overl 'ediff-meta-info))
966 (status (ediff-get-session-status session-info))
968 (setq new-status (or new-status status ?\s))
969 (goto-char (ediff-overlay-start overl))
970 (forward-char 1) ; status is the second char in session record
971 (if (eq (char-after (point)) new-status)
972 () ; if marker shown in buffer is the same as new-marker, do nothing
975 (set-buffer-modified-p nil))))
977 ;; insert all file info in meta buffer for a given session
978 (defun ediff-insert-session-info-in-meta-buffer (session-info sessionNum)
979 (let ((f1 (ediff-get-session-objA session-info))
980 (f2 (ediff-get-session-objB session-info))
981 (f3 (ediff-get-session-objC session-info))
983 (hidden (eq (ediff-get-session-status session-info) ?I)))
984 ;; insert activity marker, i.e., SPC, - or +
985 (ediff-insert-session-activity-marker-in-meta-buffer session-info)
986 ;; insert session status, i.e., *, H
987 (ediff-insert-session-status-in-meta-buffer session-info)
988 (insert " Session " (int-to-string sessionNum) ":\n")
989 (ediff-meta-insert-file-info1 f1)
990 (ediff-meta-insert-file-info1 f2)
991 (ediff-meta-insert-file-info1 f3)
992 (ediff-set-meta-overlay pt (point) session-info sessionNum hidden)))
995 ;; this is a setup function for ediff-directories
996 ;; must return meta-buffer
997 (defun ediff-redraw-directory-group-buffer (meta-list)
998 ;; extract directories
999 (let ((meta-buf (ediff-get-group-buffer meta-list))
1002 regexp elt merge-autostore-dir
1003 point tmp-list buffer-read-only)
1004 (ediff-with-current-buffer meta-buf
1005 (setq point (point))
1007 ;; delete phony overlays that used to represent sessions before the buff
1009 (if (featurep 'xemacs)
1010 (map-extents 'delete-extent)
1011 (mapc 'delete-overlay (overlays-in 1 1)))
1013 (setq regexp (ediff-get-group-regexp meta-list)
1015 (ediff-get-group-merge-autostore-dir meta-list))
1017 (if ediff-verbose-help-enabled
1019 (insert (format ediff-meta-buffer-verbose-message
1020 (ediff-abbrev-jobname ediff-metajob-name)))
1022 (cond ((ediff-collect-diffs-metajob)
1024 " P:\tcollect custom diffs of all marked sessions\n"))
1025 ((ediff-patch-metajob)
1027 " P:\tshow patch appropriately for the context (session or group)\n")))
1029 " ^:\tshow parent session group\n")
1030 (or (ediff-one-filegroup-metajob)
1032 " D:\tshow differences among directories\n"
1033 " ==:\tfor each session, show which files are identical\n"
1034 " =h:\tlike ==, but also marks sessions for hiding\n"
1035 " =m:\tlike ==, but also marks sessions for operation\n\n")))
1036 (insert (format ediff-meta-buffer-brief-message
1037 (ediff-abbrev-jobname ediff-metajob-name))))
1040 (if (and (stringp regexp) (> (length regexp) 0))
1042 (format "*** Filter-through regular expression: %s\n" regexp)))
1043 (ediff-insert-dirs-in-meta-buffer meta-list)
1044 (if (and ediff-autostore-merges (ediff-merge-metajob)
1045 (ediff-nonempty-string-p merge-autostore-dir))
1047 "\nMerge results are automatically stored in:\n\t%s\n"
1048 merge-autostore-dir)))
1050 Size Last modified Name
1051 ----------------------------------------------
1055 ;; discard info on directories and regexp
1056 (setq meta-list (cdr meta-list)
1058 (while (and tmp-list empty)
1059 (if (and (car tmp-list)
1060 (not (eq (ediff-get-session-status (car tmp-list)) ?I)))
1062 (setq tmp-list (cdr tmp-list)))
1066 " ****** ****** This session group has no members\n"))
1068 ;; now organize file names like this:
1069 ;; use-mark sizeA dateA sizeB dateB filename
1070 ;; make sure directories are displayed with a trailing slash.
1072 (setq elt (car meta-list)
1073 meta-list (cdr meta-list)
1074 sessionNum (1+ sessionNum))
1075 (if (eq (ediff-get-session-status elt) ?I)
1077 (ediff-insert-session-info-in-meta-buffer elt sessionNum)))
1078 (set-buffer-modified-p nil)
1082 (defun ediff-update-markers-in-dir-meta-buffer (meta-list)
1083 (let ((meta-buf (ediff-get-group-buffer meta-list))
1084 session-info point overl buffer-read-only)
1085 (ediff-with-current-buffer meta-buf
1086 (setq point (point))
1087 (goto-char (point-min))
1088 (ediff-next-meta-item1)
1090 (setq session-info (ediff-get-meta-info meta-buf (point) 'no-error)
1091 overl (ediff-get-meta-overlay-at-pos (point)))
1094 (cond ((eq (ediff-get-session-status session-info) ?I)
1096 (if overl (ediff-overlay-put overl 'invisible t)))
1097 ((and (eq (ediff-get-session-status session-info) ?H)
1098 overl (ediff-overlay-get overl 'invisible))
1100 (ediff-overlay-put overl 'invisible nil))
1101 (t (ediff-replace-session-activity-marker-in-meta-buffer
1103 (ediff-get-session-activity-marker session-info))
1104 (ediff-replace-session-status-in-meta-buffer
1106 (ediff-get-session-status session-info))))))
1107 (ediff-next-meta-item1) ; advance to the next item
1109 (set-buffer-modified-p nil)
1113 (defun ediff-update-session-marker-in-dir-meta-buffer (session-num)
1114 (let (buffer-meta-overlays session-info overl buffer-read-only)
1116 (if (featurep 'xemacs)
1118 (lambda (ext maparg)
1120 (ediff-overlay-get ext 'ediff-meta-info)
1121 (eq (ediff-overlay-get ext 'ediff-meta-session-number)
1124 ;; Emacs doesn't have map-extents, so try harder
1125 ;; Splice overlay lists to get all buffer overlays
1126 (setq buffer-meta-overlays (overlay-lists)
1127 buffer-meta-overlays (append (car buffer-meta-overlays)
1128 (cdr buffer-meta-overlays)))
1134 (ediff-overlay-get overl 'ediff-meta-info)
1135 (eq (ediff-overlay-get
1136 overl 'ediff-meta-session-number)
1139 buffer-meta-overlays)))))
1142 "Bug in ediff-update-session-marker-in-dir-meta-buffer: no overlay with given number %S"
1144 (setq session-info (ediff-overlay-get overl 'ediff-meta-info))
1145 (goto-char (ediff-overlay-start overl))
1146 (ediff-replace-session-activity-marker-in-meta-buffer
1148 (ediff-get-session-activity-marker session-info))
1149 (ediff-replace-session-status-in-meta-buffer
1151 (ediff-get-session-status session-info)))
1152 (ediff-next-meta-item1))
1156 ;; Check if this is a problematic session.
1157 ;; Return nil if not. Otherwise, return symbol representing the problem
1158 ;; At present, problematic sessions occur only in -with-ancestor comparisons
1159 ;; when the ancestor is a directory rather than a file, or when there is no
1160 ;; suitable ancestor file in the ancestor directory
1161 (defun ediff-problematic-session-p (session)
1162 (let ((f1 (ediff-get-session-objA-name session))
1163 (f2 (ediff-get-session-objB-name session))
1164 (f3 (ediff-get-session-objC-name session)))
1165 (cond ((and (stringp f1) (not (file-directory-p f1))
1166 (stringp f2) (not (file-directory-p f2))
1167 ;; either invalid file name or a directory
1168 (or (not (stringp f3)) (file-directory-p f3))
1169 (ediff-ancestor-metajob))
1170 ;; more may be added later
1174 (defun ediff-meta-insert-file-info1 (fileinfo)
1175 (let ((fname (car fileinfo))
1176 (feq (ediff-get-file-eqstatus fileinfo))
1177 (max-filename-width (if ediff-meta-truncate-filenames
1178 (- (window-width) 41)
1180 file-modtime file-size)
1181 (cond ((not (stringp fname)) (setq file-size -2)) ; file doesn't exits
1182 ((ediff-listable-file fname)
1183 (if (file-exists-p fname)
1184 ;; set real size and modtime
1185 (setq file-size (ediff-file-size fname)
1186 file-modtime (ediff-file-modtime fname))
1187 (setq file-size -2))) ; file doesn't exist
1188 ( t (setq file-size -1))) ; remote file
1193 (if feq "=" " ") ; equality indicator
1194 (format "%10s" (cond ((= file-size -1) "--")
1195 ((< file-size -1) "--")
1197 (cond ((= file-size -1) "*remote file*")
1198 ((< file-size -1) "*file doesn't exist*")
1199 (t (ediff-format-date (decode-time file-modtime))))
1201 ;; dir names in meta lists have training slashes, so we just
1202 ;; abbreviate the file name, if file exists
1203 (if (and (not (stringp fname)) (< file-size -1))
1204 "-------" ; file doesn't exist
1205 (ediff-truncate-string-left
1206 (ediff-abbreviate-file-name fname)
1207 max-filename-width)))))))
1209 (defconst ediff-months '((1 . "Jan") (2 . "Feb") (3 . "Mar") (4 . "Apr")
1210 (5 . "May") (6 . "Jun") (7 . "Jul") (8 . "Aug")
1211 (9 . "Sep") (10 . "Oct") (11 . "Nov") (12 . "Dec"))
1212 "Months' associative array.")
1214 ;; returns 2char string
1215 (defsubst ediff-fill-leading-zero (num)
1218 (number-to-string num)))
1220 ;; TIME is like the output of decode-time
1221 (defun ediff-format-date (time)
1222 (format "%s %2d %4d %s:%s:%s"
1223 (cdr (assoc (nth 4 time) ediff-months)) ; month
1226 (ediff-fill-leading-zero (nth 2 time)) ; hour
1227 (ediff-fill-leading-zero (nth 1 time)) ; min
1228 (ediff-fill-leading-zero (nth 0 time)) ; sec
1231 ;; Draw the directories
1232 (defun ediff-insert-dirs-in-meta-buffer (meta-list)
1233 (let* ((dir1 (ediff-abbreviate-file-name (ediff-get-group-objA meta-list)))
1234 (dir2 (ediff-get-group-objB meta-list))
1235 (dir2 (if (stringp dir2) (ediff-abbreviate-file-name dir2)))
1236 (dir3 (ediff-get-group-objC meta-list))
1237 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3))))
1238 (insert "*** Directory A: " dir1 "\n")
1239 (if dir2 (insert "*** Directory B: " dir2 "\n"))
1240 (if dir3 (insert "*** Directory C: " dir3 "\n"))
1243 (defun ediff-draw-dir-diffs (diff-list &optional buf-name)
1244 (if (null diff-list) (error "Lost difference info on these directories"))
1247 (ediff-unique-buffer-name "*Ediff File Group Differences" "*")))
1248 (let* ((regexp (ediff-get-group-regexp diff-list))
1249 (dir1 (ediff-abbreviate-file-name (ediff-get-group-objA diff-list)))
1250 (dir2 (ediff-abbreviate-file-name (ediff-get-group-objB diff-list)))
1251 (dir3 (ediff-get-group-objC diff-list))
1252 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3)))
1253 (meta-buf (ediff-get-group-buffer diff-list))
1254 (underline (make-string 26 ?-))
1255 file membership-code saved-point
1257 ;; skip the directory part
1258 (setq diff-list (cdr diff-list))
1259 (setq ediff-dir-diffs-buffer (get-buffer-create buf-name))
1260 (ediff-with-current-buffer ediff-dir-diffs-buffer
1261 (setq saved-point (point))
1262 (use-local-map ediff-dir-diffs-buffer-map)
1264 (setq ediff-meta-buffer meta-buf)
1265 (insert "\t\t*** Directory Differences ***\n")
1268 C,button2: over file name -- copy this file to directory that doesn't have it
1271 p,DEL: previous line\n\n")
1273 (insert (format "\n*** Directory A: %s\n" dir1))
1274 (if dir2 (insert (format "*** Directory B: %s\n" dir2)))
1275 (if dir3 (insert (format "*** Directory C: %s\n" dir3)))
1276 (if (and (stringp regexp) (> (length regexp) 0))
1278 (format "*** Filter-through regular expression: %s\n" regexp)))
1280 (insert (format "\n%-27s%-26s" "Directory A" "Directory B"))
1282 (insert (format " %-25s\n" "Directory C"))
1284 (insert (format "%s%s" underline underline))
1286 (insert (format "%s\n\n" underline))
1289 (if (null diff-list)
1290 (insert "\n\t*** No differences ***\n"))
1293 (setq file (car (car diff-list))
1294 membership-code (cdr (car diff-list))
1295 diff-list (cdr diff-list))
1296 (if (= (mod membership-code ediff-membership-code1) 0) ; dir1
1297 (let ((beg (point)))
1298 (insert (format "%-27s"
1299 (ediff-truncate-string-left
1300 (ediff-abbreviate-file-name
1301 (if (file-directory-p (concat dir1 file))
1302 (file-name-as-directory file)
1305 ;; format of meta info in the dir-diff-buffer:
1306 ;; (filename-tail filename-full otherdir1 otherdir2 otherdir3)
1307 (ediff-set-meta-overlay
1309 (list meta-buf file (concat dir1 file) dir1 dir2 dir3)))
1310 (insert (format "%-27s" "---")))
1311 (if (= (mod membership-code ediff-membership-code2) 0) ; dir2
1312 (let ((beg (point)))
1313 (insert (format "%-26s"
1314 (ediff-truncate-string-left
1315 (ediff-abbreviate-file-name
1316 (if (file-directory-p (concat dir2 file))
1317 (file-name-as-directory file)
1320 (ediff-set-meta-overlay
1322 (list meta-buf file (concat dir2 file) dir1 dir2 dir3)))
1323 (insert (format "%-26s" "---")))
1325 (if (= (mod membership-code ediff-membership-code3) 0) ; dir3
1326 (let ((beg (point)))
1327 (insert (format " %-25s"
1328 (ediff-truncate-string-left
1329 (ediff-abbreviate-file-name
1330 (if (file-directory-p (concat dir3 file))
1331 (file-name-as-directory file)
1334 (ediff-set-meta-overlay
1336 (list meta-buf file (concat dir3 file) dir1 dir2 dir3)))
1337 (insert (format " %-25s" "---"))))
1339 (setq buffer-read-only t)
1340 (set-buffer-modified-p nil)
1341 (goto-char saved-point)) ; end eval in diff buffer
1344 (defun ediff-bury-dir-diffs-buffer ()
1345 "Bury the directory difference buffer. Display the meta buffer instead."
1347 ;; ediff-meta-buffer is set in ediff-draw-dir-diffs so the directory
1348 ;; difference buffer remembers the meta buffer
1349 (let ((buf ediff-meta-buffer)
1351 (ediff-kill-buffer-carefully ediff-dir-diffs-buffer)
1352 (if (setq wind (ediff-get-visible-buffer-window buf))
1353 (select-window wind)
1354 (set-window-buffer (selected-window) buf))))
1356 ;; executes in dir session group buffer
1357 ;; show buffer differences
1358 (defun ediff-show-dir-diffs ()
1359 "Display differences among the directories involved in session group."
1361 (if (ediff-one-filegroup-metajob)
1362 (error "This command is inapplicable in the present context"))
1363 (or (ediff-buffer-live-p ediff-dir-diffs-buffer)
1364 (ediff-draw-dir-diffs ediff-dir-difference-list))
1365 (let ((buf ediff-dir-diffs-buffer))
1367 (set-window-buffer (selected-window) buf)
1368 (goto-char (point-min))))
1370 ;; Format of meta info in dir-diff-buffer:
1371 ;; (filename-tail filename-full otherdir1 otherdir2)
1372 (defun ediff-dir-diff-copy-file ()
1373 "Copy file described at point to directories where this file is missing."
1375 (let* ((pos (ediff-event-point last-command-event))
1376 (info (ediff-get-meta-info (current-buffer) pos 'noerror))
1377 (meta-buf (car info))
1378 (file-tail (nth 1 info))
1379 (file-abs (nth 2 info))
1380 (otherdir1 (nth 3 info))
1381 (otherfile1 (if otherdir1 (concat otherdir1 file-tail)))
1382 (otherdir2 (nth 4 info))
1383 (otherfile2 (if otherdir2 (concat otherdir2 file-tail)))
1384 (otherdir3 (nth 5 info))
1385 (otherfile3 (if otherdir3 (concat otherdir3 file-tail)))
1386 meta-list dir-diff-list
1389 (error "No file suitable for copying described at this location"))
1390 (ediff-with-current-buffer meta-buf
1391 (setq meta-list ediff-meta-list
1392 dir-diff-list ediff-dir-difference-list))
1394 ;; copy file to directories where it doesn't exist, update
1395 ;; ediff-dir-difference-list and redisplay
1397 (lambda (otherfile-struct)
1398 (let ((otherfile (car otherfile-struct))
1399 (file-mem-code (cdr otherfile-struct)))
1401 (or (file-exists-p otherfile)
1403 (format "Copy %s to %s? " file-abs otherfile))
1404 (let* ((file-diff-record (assoc file-tail dir-diff-list))
1406 (* (cdr file-diff-record) file-mem-code)))
1407 (copy-file file-abs otherfile)
1408 (setcdr file-diff-record new-mem-code)
1409 (ediff-draw-dir-diffs dir-diff-list (buffer-name))
1411 ;; if file is in all three dirs or in two dirs and only
1412 ;; two dirs are involved, delete this file's record
1413 (if (or (= new-mem-code ediff-product-of-memcodes)
1414 (and (> new-mem-code ediff-membership-code3)
1416 (delq file-diff-record dir-diff-list))
1419 ;; 2,3,5 are numbers used to encode membership of a file in
1420 ;; dir1/2/3. See ediff-intersect-directories.
1421 (list (cons otherfile1 2) (cons otherfile2 3) (cons otherfile3 5)))
1423 (if (and (file-exists-p otherfile1)
1424 (file-exists-p otherfile2)
1425 (or (not otherfile3) (file-exists-p otherfile3)))
1426 ;; update ediff-meta-list by direct modification
1428 (list (ediff-make-new-meta-list-element
1429 (expand-file-name otherfile1)
1430 (expand-file-name otherfile2)
1432 (expand-file-name otherfile3)))))
1434 (ediff-update-meta-buffer meta-buf 'must-redraw)
1437 (defun ediff-up-meta-hierarchy ()
1438 "Go to the parent session group buffer."
1440 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1441 (ediff-show-meta-buffer
1442 ediff-parent-meta-buffer ediff-meta-session-number)
1443 (error "This session group has no parent")))
1446 ;; argument is ignored
1447 (defun ediff-redraw-registry-buffer (&optional ignore)
1448 (ediff-with-current-buffer ediff-registry-buffer
1449 (let ((point (point))
1450 elt bufAname bufBname bufCname cur-diff total-diffs pt
1451 job-name meta-list registry-list buffer-read-only)
1453 ;; delete phony overlays that used to represent sessions before the buff
1455 (if (featurep 'xemacs)
1456 (map-extents 'delete-extent)
1457 (mapc 'delete-overlay (overlays-in 1 1)))
1459 (insert "This is a registry of all active Ediff sessions.
1462 button2, `v', RET over a session record: switch to that session
1463 M over a session record: display the associated session group
1464 R in any Ediff session: display session registry
1466 p,DEL: previous session
1467 E: browse Ediff on-line manual
1471 \t\tActive Ediff Sessions:
1472 \t\t----------------------
1475 ;; purge registry list from dead buffers
1477 (if (not (ediff-buffer-live-p elt))
1478 (setq ediff-session-registry
1479 (delq elt ediff-session-registry))))
1480 ediff-session-registry)
1482 (if (null ediff-session-registry)
1483 (insert " ******* No active Ediff sessions *******\n"))
1485 (setq registry-list ediff-session-registry)
1486 (while registry-list
1487 (setq elt (car registry-list)
1488 registry-list (cdr registry-list))
1490 (if (ediff-buffer-live-p elt)
1491 (if (ediff-with-current-buffer elt
1492 (setq job-name ediff-metajob-name
1493 meta-list ediff-meta-list)
1494 (and ediff-metajob-name
1495 (not (eq ediff-metajob-name 'ediff-registry))))
1498 (insert (format " *group*\t%s: %s\n"
1500 (ediff-abbrev-jobname job-name)))
1501 (insert (format "\t\t %s %s %s\n"
1502 (ediff-abbreviate-file-name
1503 (ediff-get-group-objA meta-list))
1504 (ediff-abbreviate-file-name
1506 (ediff-get-group-objB meta-list))
1507 (ediff-get-group-objB meta-list)
1509 (ediff-abbreviate-file-name
1511 (ediff-get-group-objC meta-list))
1512 (ediff-get-group-objC meta-list)
1514 (ediff-set-meta-overlay pt (point) elt))
1516 (ediff-with-current-buffer elt
1517 (setq bufAname (if (ediff-buffer-live-p ediff-buffer-A)
1518 (buffer-name ediff-buffer-A)
1519 "!!!killed buffer!!!")
1520 bufBname (if (ediff-buffer-live-p ediff-buffer-B)
1521 (buffer-name ediff-buffer-B)
1522 "!!!killed buffer!!!")
1523 bufCname (cond ((not (ediff-3way-job))
1525 ((ediff-buffer-live-p ediff-buffer-C)
1526 (buffer-name ediff-buffer-C))
1527 (t "!!!killed buffer!!!")))
1528 (setq total-diffs (format "%-4d" ediff-number-of-differences)
1530 (cond ((= ediff-current-difference -1) " _")
1531 ((= ediff-current-difference
1532 ediff-number-of-differences)
1535 "%4d" (1+ ediff-current-difference))))
1536 job-name ediff-job-name))
1537 ;; back in the meta buf
1539 (insert cur-diff "/" total-diffs "\t"
1541 (format ": %s" (ediff-abbrev-jobname job-name)))
1543 "\n\t\t " bufAname " " bufBname " " bufCname "\n")
1544 (ediff-set-meta-overlay pt (point) elt))))
1546 (set-buffer-modified-p nil)
1550 ;; Sets overlay around a meta record with 'ediff-meta-info property PROP
1551 ;; If optional SESSION-NUMBER, make it a property of the overlay,
1552 ;; ediff-meta-session-number
1553 ;; PROP is either the ctl or meta buffer (used when we work with the registry)
1554 ;; or a session meta descriptor of the form
1555 ;; (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
1556 (defun ediff-set-meta-overlay (b e prop &optional session-number hidden)
1558 (setq overl (ediff-make-overlay b e))
1559 (if (featurep 'emacs)
1560 (ediff-overlay-put overl 'mouse-face 'highlight)
1561 (ediff-overlay-put overl 'highlight t))
1562 (ediff-overlay-put overl 'ediff-meta-info prop)
1563 (ediff-overlay-put overl 'invisible hidden)
1564 (ediff-overlay-put overl 'follow-link t)
1565 (if (numberp session-number)
1566 (ediff-overlay-put overl 'ediff-meta-session-number session-number))))
1568 (defun ediff-mark-for-hiding-at-pos (unmark)
1569 "Mark session for hiding. With prefix arg, unmark."
1571 (let* ((pos (ediff-event-point last-command-event))
1572 (meta-buf (ediff-event-buffer last-command-event))
1573 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1574 (info (ediff-get-meta-info meta-buf pos))
1575 (session-number (ediff-get-session-number-at-pos pos)))
1576 (ediff-mark-session-for-hiding info unmark)
1577 (ediff-next-meta-item 1)
1579 (ediff-update-meta-buffer meta-buf nil session-number))
1582 ;; Returns whether session was marked or unmarked
1583 (defun ediff-mark-session-for-hiding (info unmark)
1584 (let ((session-buf (ediff-get-session-buffer info))
1586 (cond ((eq unmark 'mark) (setq unmark nil))
1587 ((eq (ediff-get-session-status info) ?H) (setq unmark t))
1588 (unmark ; says unmark, but the marker is different from H
1591 (unmark (ediff-set-session-status info nil))
1592 ;;; (if (ediff-buffer-live-p session-buf)
1593 ;;; (error "Can't hide active session, %s" (buffer-name session-buf)))
1594 (t (ediff-set-session-status info ?H))))
1598 (defun ediff-mark-for-operation-at-pos (unmark)
1599 "Mark session for a group operation. With prefix arg, unmark."
1601 (let* ((pos (ediff-event-point last-command-event))
1602 (meta-buf (ediff-event-buffer last-command-event))
1603 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1604 (info (ediff-get-meta-info meta-buf pos))
1605 (session-number (ediff-get-session-number-at-pos pos)))
1606 (ediff-mark-session-for-operation info unmark)
1607 (ediff-next-meta-item 1)
1609 (ediff-update-meta-buffer meta-buf nil session-number))
1613 ;; returns whether session was unmarked.
1614 ;; remember: this is a toggle op
1615 (defun ediff-mark-session-for-operation (info unmark)
1617 (cond ((eq unmark 'mark) (setq unmark nil))
1618 ((eq (ediff-get-session-status info) ?*) (setq unmark t))
1619 (unmark ; says unmark, but the marker is different from *
1622 (unmark (ediff-set-session-status info nil))
1623 (t (ediff-set-session-status info ?*))))
1627 (defun ediff-hide-marked-sessions (unhide)
1628 "Hide marked sessions. With prefix arg, unhide."
1630 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1631 (meta-list (cdr ediff-meta-list))
1632 (from (if unhide ?I ?H))
1633 (to (if unhide ?H ?I))
1635 active-sessions-exist session-buf elt)
1637 (setq elt (car meta-list)
1638 meta-list (cdr meta-list)
1639 session-buf (ediff-get-session-buffer elt))
1641 (if (eq (ediff-get-session-status elt) from)
1643 (setq numMarked (1+ numMarked))
1644 (if (and (eq to ?I) (buffer-live-p session-buf))
1645 ;; shouldn't hide active sessions
1646 (setq active-sessions-exist t)
1647 (ediff-set-session-status elt to)))))
1649 (ediff-update-meta-buffer grp-buf 'must-redraw)
1652 (message "Nothing to reveal...")
1653 (message "Nothing to hide...")))
1654 (if active-sessions-exist
1655 (message "Note: Ediff didn't hide active sessions!"))
1658 ;; Apply OPERATION to marked sessions. Operation expects one argument of type
1659 ;; meta-list member (not the first one), i.e., a regular session description.
1660 ;; Returns number of marked sessions on which operation was performed
1661 (defun ediff-operate-on-marked-sessions (operation)
1662 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1663 (meta-list (cdr ediff-meta-list))
1667 (diff-buffer ediff-meta-diff-buffer)
1670 (setq elt (car meta-list)
1671 meta-list (cdr meta-list)
1672 sessionNum (1+ sessionNum))
1673 (cond ((eq (ediff-get-session-status elt) marksym)
1675 (setq numMarked (1+ numMarked))
1676 (funcall operation elt sessionNum)))
1677 ;; The following goes into a session represented by a subdirectory
1678 ;; and applies operation to marked sessions there
1679 ((and (ediff-meta-session-p elt)
1680 (ediff-buffer-live-p
1681 (setq session-buf (ediff-get-session-buffer elt))))
1684 (ediff-with-current-buffer session-buf
1685 ;; pass meta-diff along
1686 (setq ediff-meta-diff-buffer diff-buffer)
1687 ;; collect diffs in child group
1688 (ediff-operate-on-marked-sessions operation)))))))
1689 (ediff-update-meta-buffer grp-buf 'must-redraw) ; just in case
1693 (defun ediff-append-custom-diff (session sessionNum)
1694 (or (ediff-collect-diffs-metajob)
1695 (error "Can't compute multifile patch in this context"))
1696 (let ((session-buf (ediff-get-session-buffer session))
1697 (meta-diff-buff ediff-meta-diff-buffer)
1698 (metajob ediff-metajob-name)
1699 tmp-buf custom-diff-buf)
1700 (if (ediff-buffer-live-p session-buf)
1701 (ediff-with-current-buffer session-buf
1702 (if (eq ediff-control-buffer session-buf) ; individual session
1704 (ediff-compute-custom-diffs-maybe)
1705 (setq custom-diff-buf ediff-custom-diff-buffer)))))
1707 (or (ediff-buffer-live-p meta-diff-buff)
1708 (error "Ediff: something wrong--killed multiple diff's buffer"))
1710 (cond ((ediff-buffer-live-p custom-diff-buf)
1711 ;; for live session buffers we do them first because the user may
1712 ;; have changed them with respect to the underlying files
1713 (with-current-buffer meta-diff-buff
1714 (goto-char (point-max))
1715 (insert-buffer-substring custom-diff-buf)
1717 ;; if ediff session is not live, run diff directly on the files
1718 ((memq metajob '(ediff-directories
1719 ediff-merge-directories
1720 ediff-merge-directories-with-ancestor))
1721 ;; get diffs by calling shell command on ediff-custom-diff-program
1722 (with-current-buffer
1723 (setq tmp-buf (get-buffer-create ediff-tmp-buffer))
1728 (shell-quote-argument ediff-custom-diff-program)
1729 ediff-custom-diff-options
1730 (shell-quote-argument (ediff-get-session-objA-name session))
1731 (shell-quote-argument (ediff-get-session-objB-name session))
1735 (with-current-buffer meta-diff-buff
1736 (goto-char (point-max))
1737 (insert-buffer-substring tmp-buf)
1740 (ediff-kill-buffer-carefully meta-diff-buff)
1741 (error "Session %d compares versions of file. Such session must be active to enable multifile patch collection" sessionNum )))
1744 (defun ediff-collect-custom-diffs ()
1745 "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'.
1746 This operation is defined only for `ediff-directories' and
1747 `ediff-directory-revisions', since its intent is to produce
1748 multifile patches. For `ediff-directory-revisions', we insist that
1749 all marked sessions must be active."
1751 (let ((coding-system-for-read ediff-coding-system-for-read))
1752 (or (ediff-buffer-live-p ediff-meta-diff-buffer)
1753 (setq ediff-meta-diff-buffer
1755 (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
1756 (ediff-with-current-buffer ediff-meta-diff-buffer
1757 (setq buffer-read-only nil)
1759 (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
1762 (display-buffer ediff-meta-diff-buffer 'not-this-window)
1763 (ediff-with-current-buffer ediff-meta-diff-buffer
1764 (set-buffer-modified-p nil)
1765 (setq buffer-read-only t))
1766 (if (fboundp 'diff-mode)
1767 (with-current-buffer ediff-meta-diff-buffer
1770 (message "No marked sessions found"))))
1772 (defun ediff-meta-show-patch ()
1773 "Show the multi-file patch associated with this group session."
1775 (let* ((pos (ediff-event-point last-command-event))
1776 (meta-buf (ediff-event-buffer last-command-event))
1777 (info (ediff-get-meta-info meta-buf pos 'noerror))
1778 (patchbuffer ediff-meta-patchbufer))
1779 (if (ediff-buffer-live-p patchbuffer)
1780 (ediff-with-current-buffer patchbuffer
1785 (ediff-get-session-objB-name info)
1786 (ediff-get-session-objC-name info)))
1787 (set-buffer (get-buffer-create ediff-tmp-buffer))
1789 (insert-buffer-substring patchbuffer)
1790 (goto-char (point-min))
1791 (display-buffer ediff-tmp-buffer 'not-this-window)
1793 (error "The patch buffer wasn't found"))))
1795 (declare-function ediff-directories-internal "ediff"
1796 (dir1 dir2 dir3 regexp action jobname
1797 &optional startup-hooks merge-autostore-dir))
1799 (declare-function ediff-directory-revisions-internal "ediff"
1800 (dir1 regexp action jobname
1801 &optional startup-hooks merge-autostore-dir))
1804 ;; This function executes in meta buffer. It knows where event happened.
1805 (defun ediff-filegroup-action ()
1806 "Execute appropriate action for a selected session."
1808 (let* ((pos (ediff-event-point last-command-event))
1809 (meta-buf (ediff-event-buffer last-command-event))
1810 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1811 (info (ediff-get-meta-info meta-buf pos))
1812 (session-buf (ediff-get-session-buffer info))
1813 (session-number (ediff-get-session-number-at-pos pos meta-buf))
1814 (default-regexp (eval ediff-default-filtering-regexp))
1815 merge-autostore-dir file1 file2 file3 regexp)
1817 (setq file1 (ediff-get-session-objA-name info)
1818 file2 (ediff-get-session-objB-name info)
1819 file3 (ediff-get-session-objC-name info))
1821 ;; make sure we don't start on hidden sessions
1822 ;; ?H means marked for hiding. ?I means invalid (hidden).
1823 (if (memq (ediff-get-session-status info) '(?I))
1826 (if (y-or-n-p "This session is marked as hidden, unmark? ")
1828 (ediff-set-session-status info nil)
1829 (ediff-update-meta-buffer meta-buf nil session-number))
1830 (error "Aborted"))))
1832 (ediff-with-current-buffer meta-buf
1833 (setq merge-autostore-dir
1834 (ediff-get-group-merge-autostore-dir ediff-meta-list))
1835 (goto-char pos) ; if the user clicked on session--move point there
1836 ;; First handle sessions involving directories (which are themselves
1838 ;; After that handle individual sessions
1839 (cond ((ediff-meta-session-p info)
1840 ;; do ediff/ediff-merge on subdirectories
1841 (if (ediff-buffer-live-p session-buf)
1842 (ediff-show-meta-buffer session-buf)
1845 (if (stringp default-regexp)
1847 "Filter through regular expression (default %s): "
1849 "Filter through regular expression: ")
1851 'ediff-filtering-regexp-history
1852 (eval ediff-default-filtering-regexp)))
1853 (ediff-directories-internal
1854 file1 file2 file3 regexp
1855 ediff-session-action-function
1857 ;; make it update (car info) after startup
1859 ;; child session group should know its parent
1860 (setq ediff-parent-meta-buffer
1861 (quote ,ediff-meta-buffer)
1862 ediff-meta-session-number
1864 ;; and parent will know its child
1865 (setcar (quote ,info) ediff-meta-buffer))))))
1867 ;; Do ediff-revision on a subdirectory
1868 ((and (ediff-one-filegroup-metajob)
1869 (ediff-revision-metajob)
1870 (file-directory-p file1))
1871 (if (ediff-buffer-live-p session-buf)
1872 (ediff-show-meta-buffer session-buf)
1873 (setq regexp (read-string "Filter through regular expression: "
1874 nil 'ediff-filtering-regexp-history))
1875 (ediff-directory-revisions-internal
1877 ediff-session-action-function ediff-metajob-name
1878 ;; make it update (car info) after startup
1880 ;; child session group should know its parent and
1882 (setq ediff-parent-meta-buffer
1883 (quote ,ediff-meta-buffer)
1884 ediff-meta-session-number
1886 ;; and parent will know its child
1887 (setcar (quote ,info) ediff-meta-buffer))))))
1889 ;; From here on---only individual session handlers
1891 ;; handle an individual session with a live control buffer
1892 ((ediff-buffer-live-p session-buf)
1893 (ediff-with-current-buffer session-buf
1894 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1895 (ediff-recenter 'no-rehighlight)))
1897 ((ediff-problematic-session-p info)
1900 "This session has no ancestor. Merge without the ancestor? ")
1903 ;; provide startup hooks
1906 'ediff-after-quit-hook-internal
1908 (if (ediff-buffer-live-p ,(current-buffer))
1909 (ediff-show-meta-buffer
1910 ,(current-buffer) ,session-number)))
1912 (setq ediff-meta-buffer ,(current-buffer)
1913 ediff-meta-session-number
1915 (setq ediff-merge-store-file
1916 ,(if (ediff-nonempty-string-p
1917 merge-autostore-dir)
1920 ediff-merge-filename-prefix
1921 (file-name-nondirectory file1))
1923 ;; make ediff-startup pass
1924 ;; ediff-control-buffer back to the meta
1927 (quote ,info) ediff-control-buffer))))
1929 ((ediff-one-filegroup-metajob) ; needs 1 file arg
1930 (funcall ediff-session-action-function
1932 ;; provide startup hooks
1935 'ediff-after-quit-hook-internal
1937 (if (ediff-buffer-live-p
1939 (ediff-show-meta-buffer
1943 (setq ediff-meta-buffer ,(current-buffer)
1944 ediff-meta-session-number
1946 (setq ediff-merge-store-file
1947 ,(if (ediff-nonempty-string-p
1948 merge-autostore-dir)
1951 ediff-merge-filename-prefix
1952 (file-name-nondirectory file1))) )
1953 ;; make ediff-startup pass
1954 ;; ediff-control-buffer back to the meta
1957 (quote ,info) ediff-control-buffer)))))
1958 ((not (ediff-metajob3)) ; need 2 file args
1959 (funcall ediff-session-action-function
1961 ;; provide startup hooks
1964 'ediff-after-quit-hook-internal
1966 (if (ediff-buffer-live-p
1968 (ediff-show-meta-buffer
1972 (setq ediff-meta-buffer ,(current-buffer)
1973 ediff-meta-session-number
1975 (setq ediff-merge-store-file
1976 ,(if (ediff-nonempty-string-p
1977 merge-autostore-dir)
1980 ediff-merge-filename-prefix
1981 (file-name-nondirectory file1))) )
1982 ;; make ediff-startup pass
1983 ;; ediff-control-buffer back to the meta
1986 (quote ,info) ediff-control-buffer)))))
1987 ((ediff-metajob3) ; need 3 file args
1988 (funcall ediff-session-action-function
1990 ;; arrange startup hooks
1993 'ediff-after-quit-hook-internal
1995 (if (ediff-buffer-live-p
1997 (ediff-show-meta-buffer
2001 (setq ediff-merge-store-file
2002 ,(if (ediff-nonempty-string-p
2003 merge-autostore-dir)
2006 ediff-merge-filename-prefix
2007 (file-name-nondirectory file1))) )
2008 (setq ediff-meta-buffer , (current-buffer)
2009 ediff-meta-session-number
2011 ;; this arranges that ediff-startup will pass
2012 ;; the value of ediff-control-buffer back to
2013 ;; the meta level, to the record in the meta
2014 ;; list containing the information about the
2015 ;; session associated with that
2016 ;; ediff-control-buffer
2018 (quote ,info) ediff-control-buffer)))))
2020 ) ; eval in meta-buf
2023 (defun ediff-registry-action ()
2024 "Switch to a selected session."
2026 (let* ((pos (ediff-event-point last-command-event))
2027 (buf (ediff-event-buffer last-command-event))
2028 (ctl-buf (ediff-get-meta-info buf pos)))
2030 (if (ediff-buffer-live-p ctl-buf)
2031 ;; check if this is ediff-control-buffer or ediff-meta-buffer
2032 (if (ediff-with-current-buffer ctl-buf
2033 (eq (key-binding "q") 'ediff-quit-meta-buffer))
2034 ;; it's a meta-buffer -- last action should just display it
2035 (ediff-show-meta-buffer ctl-buf t)
2036 ;; it's a session buffer -- invoke go back to session
2037 (ediff-with-current-buffer ctl-buf
2038 (setq ediff-mouse-pixel-position (mouse-pixel-position))
2039 (ediff-recenter 'no-rehighlight)))
2041 (message "You've selected a stale session --- try again")
2042 (ediff-update-registry))
2043 (ediff-with-current-buffer buf
2048 ;; If session number is t, means don't update meta buffer
2049 (defun ediff-show-meta-buffer (&optional meta-buf session-number)
2050 "Show the session group buffer."
2052 (run-hooks 'ediff-before-directory-setup-hooks)
2053 (let (wind frame silent)
2054 (if meta-buf (setq silent t))
2056 (setq meta-buf (or meta-buf ediff-meta-buffer))
2057 (cond ((not (bufferp meta-buf))
2058 (error "This Ediff session is not part of a session group"))
2059 ((not (ediff-buffer-live-p meta-buf))
2061 "Can't find this session's group panel -- session itself is ok")))
2063 (cond ((numberp session-number)
2064 (ediff-update-meta-buffer meta-buf nil session-number))
2065 ;; if session-number is t, don't update
2067 (t (ediff-cleanup-meta-buffer meta-buf)))
2069 (ediff-with-current-buffer meta-buf
2071 (cond ((setq wind (ediff-get-visible-buffer-window meta-buf))
2074 "Already showing the group panel for this session"))
2075 (set-window-buffer wind meta-buf)
2076 (select-window wind))
2077 ((window-live-p (setq wind ediff-window-C)) ;in merge--merge buf
2078 (set-window-buffer ediff-window-C meta-buf)
2079 (select-window wind))
2080 ((window-live-p (setq wind ediff-window-A))
2081 (set-window-buffer ediff-window-A meta-buf)
2082 (select-window wind))
2083 ((window-live-p (setq wind ediff-window-B))
2084 (set-window-buffer ediff-window-B meta-buf)
2085 (select-window wind))
2088 (ediff-get-visible-buffer-window ediff-registry-buffer))
2089 (ediff-window-display-p))
2090 (select-window wind)
2092 (set-window-buffer (selected-window) meta-buf))
2093 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
2094 (set-window-buffer (selected-window) meta-buf)))
2096 (if (and (ediff-window-display-p)
2098 (setq wind (ediff-get-visible-buffer-window meta-buf))))
2100 (setq frame (window-frame wind))
2102 (ediff-reset-mouse frame)))
2103 (sit-for 0) ; sometimes needed to synch the display and ensure that the
2104 ; point ends up after the just completed session
2105 (run-hooks 'ediff-show-session-group-hook)
2108 (defun ediff-show-current-session-meta-buffer ()
2110 (ediff-show-meta-buffer nil ediff-meta-session-number))
2112 (defun ediff-show-meta-buff-from-registry ()
2113 "Display the session group buffer for a selected session group."
2115 (let* ((pos (ediff-event-point last-command-event))
2116 (meta-buf (ediff-event-buffer last-command-event))
2117 (info (ediff-get-meta-info meta-buf pos))
2118 (meta-or-session-buf info))
2119 (ediff-with-current-buffer meta-or-session-buf
2120 (ediff-show-meta-buffer nil t))))
2123 (defun ediff-show-registry ()
2124 "Display Ediff's registry."
2126 (ediff-update-registry)
2127 (if (not (ediff-buffer-live-p ediff-registry-buffer))
2128 (error "No active Ediff sessions or corrupted session registry"))
2130 ;; for some reason, point moves in ediff-registry-buffer, so we preserve it
2132 (ediff-with-current-buffer ediff-registry-buffer
2135 (ediff-get-visible-buffer-window ediff-registry-buffer))
2136 (message "Already showing the registry")
2137 (set-window-buffer wind ediff-registry-buffer)
2138 (select-window wind))
2139 ((window-live-p ediff-window-C)
2140 (set-window-buffer ediff-window-C ediff-registry-buffer)
2141 (select-window ediff-window-C))
2142 ((window-live-p ediff-window-A)
2143 (set-window-buffer ediff-window-A ediff-registry-buffer)
2144 (select-window ediff-window-A))
2145 ((window-live-p ediff-window-B)
2146 (set-window-buffer ediff-window-B ediff-registry-buffer)
2147 (select-window ediff-window-B))
2149 (ediff-get-visible-buffer-window ediff-meta-buffer))
2150 (ediff-window-display-p))
2151 (select-window wind)
2153 (set-window-buffer (selected-window) ediff-registry-buffer))
2154 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
2155 (set-window-buffer (selected-window) ediff-registry-buffer)))
2157 (if (ediff-window-display-p)
2161 (ediff-get-visible-buffer-window ediff-registry-buffer)))
2163 (ediff-reset-mouse frame)))
2164 (run-hooks 'ediff-show-registry-hook)
2168 (defalias 'eregistry 'ediff-show-registry)
2170 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a
2172 ;; Check if META-BUF exists before calling this function
2173 ;; Optional MUST-REDRAW, if non-nil, would force redrawing of the whole meta
2174 ;; buffer. Otherwise, it will just go over the buffer and update activity marks
2175 ;; and session status.
2176 ;; SESSION-NUMBER, if specified, says which session caused the update.
2177 (defun ediff-update-meta-buffer (meta-buf &optional must-redraw session-number)
2178 (if (ediff-buffer-live-p meta-buf)
2179 (ediff-with-current-buffer meta-buf
2181 (cond (must-redraw ; completely redraw the meta buffer
2182 (funcall ediff-meta-redraw-function ediff-meta-list))
2183 ((numberp session-number) ; redraw only for the given session
2184 (ediff-update-session-marker-in-dir-meta-buffer
2186 (t ; update what changed only, but scan the entire meta buffer
2187 (ediff-update-markers-in-dir-meta-buffer ediff-meta-list)))
2188 (setq overl (ediff-get-meta-overlay-at-pos (point)))
2189 ;; skip the invisible sessions
2190 (while (and overl (ediff-overlay-get overl 'invisible))
2191 (ediff-next-meta-item1)
2192 (setq overl (ediff-get-meta-overlay-at-pos (point))))
2195 (defun ediff-update-registry ()
2196 (ediff-with-current-buffer (current-buffer)
2197 (if (ediff-buffer-live-p ediff-registry-buffer)
2198 (ediff-redraw-registry-buffer)
2199 (ediff-prepare-meta-buffer
2200 'ediff-registry-action
2201 ediff-session-registry
2203 'ediff-redraw-registry-buffer
2207 ;; If meta-buf exists, it is redrawn along with parent.
2208 ;; Otherwise, nothing happens.
2209 (defun ediff-cleanup-meta-buffer (meta-buffer)
2210 (if (ediff-buffer-live-p meta-buffer)
2211 (ediff-with-current-buffer meta-buffer
2212 (ediff-update-meta-buffer meta-buffer)
2213 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
2214 (ediff-update-meta-buffer
2215 ediff-parent-meta-buffer nil ediff-meta-session-number)))))
2217 ;; t if no session is in progress
2218 (defun ediff-safe-to-quit (meta-buffer)
2219 (if (ediff-buffer-live-p meta-buffer)
2220 (let ((lis ediff-meta-list)
2223 ;;(ediff-update-meta-buffer meta-buffer)
2224 (ediff-with-current-buffer meta-buffer
2225 (setq lis (cdr lis)) ; discard the description part of meta-list
2226 (while (and cont lis)
2227 (if (ediff-buffer-live-p
2228 (ediff-get-group-buffer lis)) ; in progress
2230 (setq lis (cdr lis)))
2233 (defun ediff-quit-meta-buffer ()
2234 "If the group has no active session, delete the meta buffer.
2235 If no session is in progress, ask to confirm before deleting meta buffer.
2236 Otherwise, bury the meta buffer.
2237 If this is a session registry buffer then just bury it."
2239 (let* ((buf (current-buffer))
2240 (dir-diffs-buffer ediff-dir-diffs-buffer)
2241 (meta-diff-buffer ediff-meta-diff-buffer)
2242 (session-number ediff-meta-session-number)
2243 (parent-buf ediff-parent-meta-buffer)
2244 (dont-show-registry (eq buf ediff-registry-buffer)))
2245 (if dont-show-registry
2247 ;;(ediff-cleanup-meta-buffer buf)
2248 (cond ((and (ediff-safe-to-quit buf)
2249 (y-or-n-p "Quit this session group? "))
2250 (run-hooks 'ediff-quit-session-group-hook)
2252 (ediff-dispose-of-meta-buffer buf))
2253 ((ediff-safe-to-quit buf)
2257 "This session group has active sessions---cannot exit")))
2258 (ediff-update-meta-buffer parent-buf nil session-number)
2259 (ediff-kill-buffer-carefully dir-diffs-buffer)
2260 (ediff-kill-buffer-carefully meta-diff-buffer)
2261 (if (ediff-buffer-live-p parent-buf)
2263 (setq dont-show-registry t)
2264 (ediff-show-meta-buffer parent-buf session-number)))
2266 (or dont-show-registry
2267 (ediff-show-registry))))
2269 (defun ediff-dispose-of-meta-buffer (buf)
2270 (setq ediff-session-registry (delq buf ediff-session-registry))
2271 (ediff-with-current-buffer buf
2272 (if (ediff-buffer-live-p ediff-dir-diffs-buffer)
2273 (kill-buffer ediff-dir-diffs-buffer)))
2277 ;; Obtain information on a meta record where the user clicked or typed
2278 ;; BUF is the buffer where this happened and POINT is the position
2279 ;; If optional NOERROR arg is given, don't report error and return nil if no
2280 ;; meta info is found on line.
2281 (defun ediff-get-meta-info (buf point &optional noerror)
2282 (let (result olist tmp)
2283 (if (and point (ediff-buffer-live-p buf))
2284 (ediff-with-current-buffer buf
2285 (if (featurep 'xemacs)
2287 (if (setq tmp (extent-at point buf 'ediff-meta-info))
2288 (ediff-overlay-get tmp 'ediff-meta-info)))
2290 (mapcar (lambda (elt)
2291 (unless (overlay-get elt 'invisible)
2292 (overlay-get elt 'ediff-meta-info)))
2293 (overlays-at point)))
2294 (while (and olist (null (car olist)))
2295 (setq olist (cdr olist)))
2296 (setq result (car olist)))))
2299 (ediff-update-registry)
2300 (error "No session info in this line")))))
2303 (defun ediff-get-meta-overlay-at-pos (point)
2304 (if (featurep 'xemacs)
2305 (extent-at point (current-buffer) 'ediff-meta-info)
2306 (let* ((overl-list (overlays-at point))
2307 (overl (car overl-list)))
2308 (while (and overl (null (overlay-get overl 'ediff-meta-info)))
2309 (setq overl-list (cdr overl-list)
2310 overl (car overl-list)))
2313 (defun ediff-get-session-number-at-pos (point &optional meta-buffer)
2314 (setq meta-buffer (if (ediff-buffer-live-p meta-buffer)
2317 (ediff-with-current-buffer meta-buffer
2319 (ediff-get-meta-overlay-at-pos point) 'ediff-meta-session-number)))
2322 ;; Return location of the next meta overlay after point
2323 (defun ediff-next-meta-overlay-start (point)
2325 (goto-char (point-min))
2326 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2327 (if (featurep 'xemacs)
2330 (setq overl (next-extent overl))
2331 (setq overl (next-extent (current-buffer))))
2333 (extent-start-position overl)
2337 ;; note: end of current overlay is the beginning of the next one
2339 (next-overlay-change point))))))
2342 (defun ediff-previous-meta-overlay-start (point)
2344 (goto-char (point-max))
2345 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2346 (if (featurep 'xemacs)
2349 (setq overl (previous-extent overl))
2350 (setq overl (previous-extent (current-buffer))))
2352 (extent-start-position overl)
2354 (if overl (setq point (overlay-start overl)))
2355 ;; to get to the beginning of prev overlay
2357 ;; trick to overcome an emacs bug--doesn't always find previous
2358 ;; overlay change correctly
2359 (setq point (1- point)))
2360 (setq point (previous-overlay-change point))
2361 ;; If we are not over an overlay after subtracting 1, it means we are
2362 ;; in the description area preceding session records. In this case,
2363 ;; goto the top of the registry buffer.
2364 (or (car (overlays-at point))
2365 (setq point (point-min)))
2368 (autoload 'ediff-patch-file-internal "ediff-ptch")
2370 ;; this is the action invoked when the user selects a patch from the meta
2372 (defun ediff-patch-file-form-meta (file &optional startup-hooks)
2373 (let* ((pos (ediff-event-point last-command-event))
2374 (meta-buf (ediff-event-buffer last-command-event))
2375 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
2376 (info (ediff-get-meta-info meta-buf pos))
2377 (meta-patchbuf ediff-meta-patchbufer)
2378 session-buf beg-marker end-marker)
2380 (if (or (file-directory-p file) (string-match "/dev/null" file))
2381 (error "`%s' is not an ordinary file" (file-name-as-directory file)))
2382 (setq session-buf (ediff-get-session-buffer info)
2383 beg-marker (ediff-get-session-objB-name info)
2384 end-marker (ediff-get-session-objC-name info))
2386 (or (ediff-buffer-live-p session-buf) ; either an active patch session
2387 (null session-buf) ; or it is a virgin session
2389 "Patch has already been applied to this file -- can't repeat!"))
2391 (ediff-with-current-buffer meta-patchbuf
2394 (narrow-to-region beg-marker end-marker)
2395 (ediff-patch-file-internal meta-patchbuf file startup-hooks)))))
2398 (defun ediff-unmark-all-for-operation ()
2399 "Unmark all sessions marked for operation."
2401 (let ((list (cdr ediff-meta-list))
2403 (while (setq elt (car list))
2404 (ediff-mark-session-for-operation elt 'unmark)
2405 (setq list (cdr list))))
2406 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2408 (defun ediff-unmark-all-for-hiding ()
2409 "Unmark all sessions marked for hiding."
2411 (let ((list (cdr ediff-meta-list))
2413 (while (setq elt (car list))
2414 (ediff-mark-session-for-hiding elt 'unmark)
2415 (setq list (cdr list))))
2416 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2419 ;; ACTION is ?h, ?m, ?=: to mark for hiding, mark for operation, or simply
2420 ;; indicate which are equal files
2421 (defun ediff-meta-mark-equal-files (&optional action)
2422 "Run through the session list and mark identical files.
2423 This is used only for sessions that involve 2 or 3 files at the same time.
2424 ACTION is an optional argument that can be ?h, ?m, ?=, to mark for hiding, mark
2425 for operation, or simply indicate which are equal files. If it is nil, then
2426 `(ediff-last-command-char)' is used to decide which action to take."
2429 (setq action (ediff-last-command-char)))
2430 (let ((list (cdr ediff-meta-list))
2431 marked1 marked2 marked3
2432 fileinfo1 fileinfo2 fileinfo3 elt)
2433 (message "Comparing files...")
2434 (while (setq elt (car list))
2435 (setq fileinfo1 (ediff-get-session-objA elt)
2436 fileinfo2 (ediff-get-session-objB elt)
2437 fileinfo3 (ediff-get-session-objC elt))
2438 (ediff-set-file-eqstatus fileinfo1 nil)
2439 (ediff-set-file-eqstatus fileinfo2 nil)
2440 (ediff-set-file-eqstatus fileinfo3 nil)
2445 (or (ediff-mark-if-equal fileinfo1 fileinfo2)
2447 (if (ediff-metajob3)
2449 (or (ediff-mark-if-equal fileinfo1 fileinfo3)
2451 (or (ediff-mark-if-equal fileinfo2 fileinfo3)
2452 (setq marked3 nil))))
2453 (if (and marked1 marked2 marked3)
2454 (cond ((eq action ?h)
2455 (ediff-mark-session-for-hiding elt 'mark))
2457 (ediff-mark-session-for-operation elt 'mark))
2459 (setq list (cdr list)))
2460 (message "Comparing files... Done"))
2461 (setq ediff-recurse-to-subdirectories nil)
2462 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2464 ;; mark files 1 and 2 as equal, if they are.
2465 ;; returns t, if something was marked
2466 (defun ediff-mark-if-equal (fileinfo1 fileinfo2)
2467 (let ((f1 (car fileinfo1))
2468 (f2 (car fileinfo2)))
2469 (if (and (stringp f1) (stringp f2) (ediff-same-contents f1 f2))
2471 (ediff-set-file-eqstatus fileinfo1 t)
2472 (ediff-set-file-eqstatus fileinfo2 t)
2479 ;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
2480 ;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
2481 ;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
2484 ;;; ediff-mult.el ends here