1 ;;; ediff-mult.el --- support for multi-file/multi-buffer processing in Ediff
3 ;; Copyright (C) 1995-2016 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 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."
177 :type
'sexp
; yuck - why not just a regexp?
181 ;; This has the form ((meta-buf regexp dir1 dir2 dir3 merge-auto-store-dir)
182 ;; (ctl-buf session-status (file1 . eq-status) (file2 . eq-status) (file3
183 ;; . eq-status)) (ctl-buf session-status (file1 . eq-status) (file2
184 ;; . eq-status)) ...)
185 ;; If ctl-buf is nil, the file-pair hasn't processed yet. If it is
186 ;; killed-buffer object, the file pair has been processed. If it is a live
187 ;; buffer, this means ediff is still working on the pair.
188 ;; Eq-status of a file is t if the file equals some other file in the same
190 (ediff-defvar-local ediff-meta-list nil
"")
192 (ediff-defvar-local ediff-meta-session-number nil
"")
195 ;; the difference list between directories in a directory session group
196 (ediff-defvar-local ediff-dir-difference-list nil
"")
197 (ediff-defvar-local ediff-dir-diffs-buffer nil
"")
199 ;; The registry of Ediff sessions. A list of control buffers.
200 (defvar ediff-session-registry nil
)
202 (defcustom ediff-meta-truncate-filenames t
203 "If non-nil, truncate long file names in the session group buffers.
204 This can be toggled with `ediff-toggle-filename-truncation'."
208 (defcustom ediff-meta-mode-hook nil
209 "Hooks run just after setting up meta mode."
213 (defcustom ediff-registry-setup-hook nil
214 "Hooks run just after the registry control panel is set up."
218 (defcustom ediff-before-session-group-setup-hooks
219 nil
;FIXME: Bad name (should be -hook or -functions) and never run??
220 "Hook 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 account. 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 ;; Currently, 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
)))
365 (ediff-defvar-local ediff-verbose-help-enabled nil
366 "If t, display redundant help in ediff-directories and other meta buffers.
367 Toggled by ediff-toggle-verbose-help-meta-buffer" )
369 ;; Toggle verbose help in meta-buffers
370 ;; TODO: Someone who understands all this can make it better.
371 (defun ediff-toggle-verbose-help-meta-buffer ()
372 "Toggle showing tediously verbose help in meta buffers."
374 (setq ediff-verbose-help-enabled
(not ediff-verbose-help-enabled
))
375 (ediff-update-meta-buffer (current-buffer) 'must-redraw
))
377 ;; set up the keymap in the meta buffer
378 (defun ediff-setup-meta-map ()
379 (setq ediff-meta-buffer-map
(make-sparse-keymap))
380 (suppress-keymap ediff-meta-buffer-map
)
381 (define-key ediff-meta-buffer-map
"?" 'ediff-toggle-verbose-help-meta-buffer
)
382 (define-key ediff-meta-buffer-map
"q" 'ediff-quit-meta-buffer
)
383 (define-key ediff-meta-buffer-map
"T" 'ediff-toggle-filename-truncation
)
384 (define-key ediff-meta-buffer-map
"R" 'ediff-show-registry
)
385 (define-key ediff-meta-buffer-map
"E" 'ediff-documentation
)
386 (define-key ediff-meta-buffer-map
"v" ediff-meta-action-function
)
387 (define-key ediff-meta-buffer-map
"\C-m" ediff-meta-action-function
)
388 (define-key ediff-meta-buffer-map
" " 'ediff-next-meta-item
)
389 (define-key ediff-meta-buffer-map
"n" 'ediff-next-meta-item
)
390 (define-key ediff-meta-buffer-map
"\C-?" 'ediff-previous-meta-item
)
391 (define-key ediff-meta-buffer-map
"p" 'ediff-previous-meta-item
)
392 (define-key ediff-meta-buffer-map
[delete] 'ediff-previous-meta-item)
393 (define-key ediff-meta-buffer-map [backspace] 'ediff-previous-meta-item)
395 (let ((menu-map (make-sparse-keymap "Ediff-Meta")))
396 (define-key ediff-meta-buffer-map [menu-bar ediff-meta-mode]
397 (cons "Ediff-Meta" menu-map))
398 (define-key menu-map [ediff-quit-meta-buffer]
399 '(menu-item "Quit" ediff-quit-meta-buffer
400 :help "Quit the meta buffer"))
401 (define-key menu-map [ediff-toggle-filename-truncation]
402 '(menu-item "Truncate filenames" ediff-toggle-filename-truncation
403 :help "Toggle truncation of long file names in session group buffers"
404 :button (:toggle . ediff-meta-truncate-filenames)))
405 (define-key menu-map [ediff-show-registry]
406 '(menu-item "Display Ediff Registry" ediff-show-registry
407 :help "Display Ediff's registry"))
408 (define-key menu-map [ediff-documentation]
409 '(menu-item "Show Manual" ediff-documentation
410 :help "Display Ediff's manual"))
412 (or (ediff-one-filegroup-metajob)
414 (define-key ediff-meta-buffer-map "=" nil)
415 (define-key ediff-meta-buffer-map "==" 'ediff-meta-mark-equal-files)
416 (define-key ediff-meta-buffer-map "=m" 'ediff-meta-mark-equal-files)
417 (define-key ediff-meta-buffer-map "=h" 'ediff-meta-mark-equal-files)))
420 (define-key menu-map [ediff-next-meta-item]
421 '(menu-item "Next" ediff-next-meta-item
422 :help "Move to the next item in Ediff registry or session group buffer"))
423 (define-key menu-map [ediff-previous-meta-item]
424 '(menu-item "Previous" ediff-previous-meta-item
425 :help "Move to the previous item in Ediff registry or session group buffer")))
428 (if ediff-no-emacs-help-in-control-buffer
429 (define-key ediff-meta-buffer-map "\C-h" 'ediff-previous-meta-item))
430 (if (featurep 'emacs)
431 (define-key ediff-meta-buffer-map [mouse-2] ediff-meta-action-function)
432 (define-key ediff-meta-buffer-map [button2] ediff-meta-action-function))
434 (use-local-map ediff-meta-buffer-map)
435 ;; modify ediff-meta-buffer-map here
436 (run-hooks 'ediff-meta-buffer-keymap-setup-hook))
439 (defun ediff-meta-mode ()
440 "This mode controls all operations on Ediff session groups.
441 It is entered through one of the following commands:
446 `ediff-merge-directories'
448 `ediff-merge-directories-with-ancestor'
449 `edirs-merge-with-ancestor'
450 `ediff-directory-revisions'
452 `ediff-merge-directory-revisions'
453 `edir-merge-revisions'
454 `ediff-merge-directory-revisions-with-ancestor'
455 `edir-merge-revisions-with-ancestor'
458 \\{ediff-meta-buffer-map}"
459 ;; FIXME: Use define-derived-mode.
460 (kill-all-local-variables)
461 (setq major-mode 'ediff-meta-mode)
462 (setq mode-name "MetaEdiff")
463 ;; don't use run-mode-hooks here!
464 (run-hooks 'ediff-meta-mode-hook))
467 ;; the keymap for the buffer showing directory differences
468 (suppress-keymap ediff-dir-diffs-buffer-map)
469 (define-key ediff-dir-diffs-buffer-map "q" 'ediff-bury-dir-diffs-buffer)
470 (define-key ediff-dir-diffs-buffer-map " " 'next-line)
471 (define-key ediff-dir-diffs-buffer-map "n" 'next-line)
472 (define-key ediff-dir-diffs-buffer-map "\C-?" 'previous-line)
473 (define-key ediff-dir-diffs-buffer-map "p" 'previous-line)
474 (define-key ediff-dir-diffs-buffer-map "C" 'ediff-dir-diff-copy-file)
475 (if (featurep 'emacs)
476 (define-key ediff-dir-diffs-buffer-map [mouse-2] 'ediff-dir-diff-copy-file)
477 (define-key ediff-dir-diffs-buffer-map [button2] 'ediff-dir-diff-copy-file))
478 (define-key ediff-dir-diffs-buffer-map [delete] 'previous-line
)
479 (define-key ediff-dir-diffs-buffer-map
[backspace] 'previous-line)
481 (defun ediff-next-meta-item (count)
482 "Move to the next item in Ediff registry or session group buffer.
483 Moves in circular fashion. With numeric prefix arg, skip this many items."
485 (or count (setq count 1))
488 (setq count (1- count))
489 (ediff-next-meta-item1)
490 (setq overl (ediff-get-meta-overlay-at-pos (point)))
491 ;; skip invisible ones
492 (while (and overl (ediff-overlay-get overl 'invisible))
493 (ediff-next-meta-item1)
494 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
496 ;; Move to the next meta item
497 (defun ediff-next-meta-item1 ()
499 (setq pos (ediff-next-meta-overlay-start (point)))
500 (if pos (goto-char pos))
501 (if (eq ediff-metajob-name 'ediff-registry)
502 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
503 (search-forward "*Ediff" nil t))
504 (skip-chars-backward "a-zA-Z*"))
505 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
506 (backward-char 1)))))
509 (defun ediff-previous-meta-item (count)
510 "Move to the previous item in Ediff registry or session group buffer.
511 Moves in circular fashion. With numeric prefix arg, skip this many items."
513 (or count (setq count 1))
516 (setq count (1- count))
517 (ediff-previous-meta-item1)
518 (setq overl (ediff-get-meta-overlay-at-pos (point)))
519 ;; skip invisible ones
520 (while (and overl (ediff-overlay-get overl 'invisible))
521 (ediff-previous-meta-item1)
522 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
524 (defun ediff-previous-meta-item1 ()
526 (setq pos (ediff-previous-meta-overlay-start (point)))
528 ;;; (while (ediff-get-session-status
529 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
530 ;;; (setq pos (ediff-previous-meta-overlay-start pos)))
532 (if pos (goto-char pos))
533 (if (eq ediff-metajob-name 'ediff-registry)
534 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
535 (search-forward "*Ediff" nil t))
536 (skip-chars-backward "a-zA-Z*"))
537 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
541 (defsubst ediff-add-slash-if-directory (dir file)
542 (if (file-directory-p (concat dir file))
543 (file-name-as-directory file)
546 (defun ediff-toggle-filename-truncation ()
547 "Toggle truncation of long file names in session group buffers.
548 Set `ediff-meta-truncate-filenames' variable if you want to change the default
551 (setq ediff-meta-truncate-filenames (not ediff-meta-truncate-filenames))
552 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
555 ;; These are used to encode membership of files in directory1/2/3
556 ;; Membership code of a file is a product of codes for the directories where
558 (defvar ediff-membership-code1 2)
559 (defvar ediff-membership-code2 3)
560 (defvar ediff-membership-code3 5)
561 (defvar ediff-product-of-memcodes (* ediff-membership-code1
562 ediff-membership-code2
563 ediff-membership-code3))
565 ;; DIR1, DIR2, DIR3 are directories. DIR3 can be nil.
566 ;; OUTPUT-DIR is a directory for auto-storing the results of merge jobs.
568 ;; REGEXP is nil or a filter regexp; only file names that match the regexp
570 ;; If a file is a directory in dir1 but not dir2 (or vice versa), it is not
571 ;; included in the intersection. However, a regular file that is a dir in dir3
572 ;; is included, since dir3 files are supposed to be ancestors for merging.
573 ;; If COMPARISON-FUNC is given, use it. Otherwise, use string=
575 ;; Returns a list of the form:
576 ;; (COMMON-PART DIFF-LIST)
577 ;; COMMON-PART is car and DIFF-LIST is cdr.
579 ;; COMMON-PART is of the form:
580 ;; (META-HEADER (f1 f2 f3) (f1 f2 f3) ...)
581 ;; f3 can be nil if intersecting only 2 directories.
582 ;; Each triple (f1 f2 f3) represents the files to be compared in the
583 ;; corresponding ediff subsession.
585 ;; DIFF-LIST is of the form:
586 ;; (META-HEADER (file . num) (file . num)...)
587 ;; where num encodes the set of dirs where the file is found:
588 ;; 2 - only dir1; 3 - only dir2; 5 - only dir3; 6 - dir1&2; 10 - dir1&3; etc.
590 ;; Contains the meta info about this ediff operation
591 ;; (regexp dir1 dir2 dir3 merge-auto-store-dir comparison-func)
592 ;; Later the meta-buffer is prepended to this list.
594 ;; Some operations might use a different meta header. For instance,
595 ;; ediff-multifile-patch doesn't have dir2 and dir3, and regexp,
596 ;; comparison-func don't apply.
598 (defun ediff-intersect-directories (jobname
601 dir3 merge-autostore-dir comparison-func)
602 (setq comparison-func (or comparison-func 'string=))
603 (let (lis1 lis2 lis3 common auxdir1 auxdir2 auxdir3 common-part difflist)
605 (setq auxdir1 (file-name-as-directory dir1)
606 lis1 (directory-files auxdir1 nil regexp)
607 lis1 (delete "." lis1)
608 lis1 (delete ".." lis1)
611 (ediff-add-slash-if-directory auxdir1 elt))
613 auxdir2 (file-name-as-directory dir2)
614 lis2 (directory-files auxdir2 nil regexp)
615 lis2 (delete "." lis2)
616 lis2 (delete ".." lis2)
619 (ediff-add-slash-if-directory auxdir2 elt))
623 (setq auxdir3 (file-name-as-directory dir3)
624 lis3 (directory-files auxdir3 nil regexp)
625 lis3 (delete "." lis3)
626 lis3 (delete ".." lis3)
629 (ediff-add-slash-if-directory auxdir3 elt))
632 (if (ediff-nonempty-string-p merge-autostore-dir)
633 (setq merge-autostore-dir
634 (file-name-as-directory merge-autostore-dir)))
635 (setq common (ediff-intersection lis1 lis2 comparison-func))
637 ;; In merge with ancestor jobs, we don't intersect with lis3.
638 ;; If there is no ancestor, we'll offer to merge without the ancestor.
639 ;; So, we intersect with lis3 only when we are doing 3-way file comparison
640 (if (and lis3 (ediff-comparison-metajob3 jobname))
641 (setq common (ediff-intersection common lis3 comparison-func)))
643 ;; copying is needed because sort sorts via side effects
644 (setq common (sort (ediff-copy-list common) 'string-lessp))
646 ;; compute difference list
647 (setq difflist (ediff-set-difference
648 (ediff-union (ediff-union lis1 lis2 comparison-func)
653 difflist (delete "." difflist)
654 ;; copying is needed because sort sorts via side effects
655 difflist (sort (ediff-copy-list (delete ".." difflist))
658 (setq difflist (mapcar (lambda (elt) (cons elt 1)) difflist))
660 ;; check for files belonging to lis1/2/3
661 ;; Each elt is of the norm (file . number)
662 ;; Number encodes the directories to which file belongs.
663 ;; It is a product of a subset of ediff-membership-code1=2,
664 ;; ediff-membership-code2=3, and ediff-membership-code3=5.
665 ;; If file belongs to dir 1 only, the membership code is 2.
666 ;; If it is in dir1 and dir3, then the membership code is 2*5=10;
667 ;; if it is in dir1 and dir2, then the membership code is 2*3=6, etc.
669 (if (member (car elt) lis1)
670 (setcdr elt (* (cdr elt) ediff-membership-code1)))
671 (if (member (car elt) lis2)
672 (setcdr elt (* (cdr elt) ediff-membership-code2)))
673 (if (member (car elt) lis3)
674 (setcdr elt (* (cdr elt) ediff-membership-code3)))
678 ;; diff metalist header
679 (ediff-make-new-meta-list-header regexp
680 auxdir1 auxdir2 auxdir3
688 (ediff-make-new-meta-list-header regexp
689 auxdir1 auxdir2 auxdir3
694 (ediff-make-new-meta-list-element
695 (expand-file-name (concat auxdir1 elt))
696 (expand-file-name (concat auxdir2 elt))
699 ;; The following is done because: In merging with
700 ;; ancestor, we don't intersect with lis3. So, it is
701 ;; possible that elt is a file in auxdir1/2 but a
702 ;; directory in auxdir3 Or elt may not exist in auxdir3 at
703 ;; all. In the first case, we add a slash at the end. In
704 ;; the second case, we insert nil.
705 (setq elt (ediff-add-slash-if-directory auxdir3 elt))
706 (if (file-exists-p (concat auxdir3 elt))
707 (expand-file-name (concat auxdir3 elt)))))))
710 (cons common-part difflist)
713 ;; find directory files that are under revision. Include subdirectories, since
714 ;; we may visit them recursively. DIR1 is the directory to inspect.
715 ;; MERGE-AUTOSTORE-DIR is the directory where to auto-store the results of
716 ;; merges. Can be nil.
717 (defun ediff-get-directory-files-under-revision (jobname
719 &optional merge-autostore-dir)
720 (let (lis1 elt common auxdir1)
721 (setq auxdir1 (file-name-as-directory dir1)
722 lis1 (directory-files auxdir1 nil regexp))
724 (if (ediff-nonempty-string-p merge-autostore-dir)
725 (setq merge-autostore-dir
726 (file-name-as-directory merge-autostore-dir)))
731 ;; take files under revision control
732 (cond ((file-directory-p (concat auxdir1 elt))
734 (cons (ediff-add-slash-if-directory auxdir1 elt) common)))
735 ((and (featurep 'vc-hooks) (vc-backend (concat auxdir1 elt)))
736 (setq common (cons elt common)))
737 ;; The following two are needed only if vc-hooks isn't loaded.
738 ;; They won't recognize CVS files.
739 ((file-exists-p (concat auxdir1 elt ",v"))
740 (setq common (cons elt common)))
741 ((file-exists-p (concat auxdir1 "RCS/" elt ",v"))
742 (setq common (cons elt common)))
746 (setq common (delete "./" common)
747 common (delete "../" common)
748 common (delete "RCS" common)
749 common (delete "CVS" common)
752 ;; copying is needed because sort sorts via side effects
753 (setq common (sort (ediff-copy-list common) 'string-lessp))
757 ;; header -- has 6 elements. Meta buffer is prepended later by
758 ;; ediff-prepare-meta-buffer
759 (ediff-make-new-meta-list-header regexp
761 merge-autostore-dir nil)
762 (mapcar (lambda (elt) (ediff-make-new-meta-list-element
763 (expand-file-name (concat auxdir1 elt)) nil nil))
768 ;; If file groups selected by patterns will ever be implemented, this
769 ;; comparison function might become useful.
770 ;;;; uses external variables PAT1 PAT2 to compare str1/2
771 ;;;; patterns must be of the form ???*???? where ??? are strings of chars
772 ;;;; containing no *.
773 ;;(defun ediff-pattern= (str1 str2)
774 ;; (let (pos11 pos12 pos21 pos22 len1 len2)
776 ;; len (length epat1)
778 ;; (while (and (< pos11 len) (not (= (aref epat1 pos11) ?*)))
779 ;; (setq pos11 (1+ pos11)))
780 ;; (while (and (> pos12 0) (not (= (aref epat1 (1- pos12)) ?*)))
781 ;; (setq pos12 (1- pos12)))
784 ;; len (length epat2)
786 ;; (while (and (< pos21 len) (not (= (aref epat2 pos21) ?*)))
787 ;; (setq pos21 (1+ pos21)))
788 ;; (while (and (> pos22 0) (not (= (aref epat2 (1- pos22)) ?*)))
789 ;; (setq pos22 (1- pos22)))
791 ;; (if (and (> (length str1) pos12) (>= pos12 pos11) (> pos11 -1)
792 ;; (> (length str2) pos22) (>= pos22 pos21) (> pos21 -1))
793 ;; (string= (substring str1 pos11 pos12)
794 ;; (substring str2 pos21 pos22)))
798 ;; Prepare meta-buffer in accordance with the argument-function and
799 ;; redraw-function. Must return the created meta-buffer.
800 (defun ediff-prepare-meta-buffer (action-func meta-list
801 meta-buffer-name redraw-function
802 jobname &optional startup-hooks)
803 (let* ((meta-buffer-name
804 (ediff-unique-buffer-name meta-buffer-name "*"))
805 (meta-buffer (get-buffer-create meta-buffer-name)))
806 (ediff-with-current-buffer meta-buffer
811 (setq ediff-meta-action-function action-func
812 ediff-meta-redraw-function redraw-function
813 ediff-metajob-name jobname
814 ediff-meta-buffer meta-buffer)
816 ;; comes after ediff-meta-action-function is set
817 (ediff-setup-meta-map)
819 (if (eq ediff-metajob-name 'ediff-registry)
821 (setq ediff-registry-buffer meta-buffer
822 ediff-meta-list meta-list)
823 ;; this func is used only from registry buffer, not from other
826 ediff-meta-buffer-map "M" 'ediff-show-meta-buff-from-registry))
827 ;; Initialize the meta list -- we don't do this for registry.
828 (setq ediff-meta-list
829 ;; add meta-buffer to the list header
830 (cons (cons meta-buffer (car meta-list))
833 (or (eq meta-buffer ediff-registry-buffer)
834 (setq ediff-session-registry
835 (cons meta-buffer ediff-session-registry)))
837 ;; redraw-function uses ediff-meta-list
838 (funcall redraw-function ediff-meta-list)
840 ;; set read-only/non-modified
841 (setq buffer-read-only t)
842 (set-buffer-modified-p nil)
844 (run-hooks 'startup-hooks)
846 ;; Arrange to show directory contents differences
847 ;; Must be after run startup-hooks, since ediff-dir-difference-list is
848 ;; set inside these hooks
849 (if (eq action-func 'ediff-filegroup-action)
851 ;; put meta buffer in (car ediff-dir-difference-list)
852 (setq ediff-dir-difference-list
853 (cons (cons meta-buffer (car ediff-dir-difference-list))
854 (cdr ediff-dir-difference-list)))
856 (or (ediff-one-filegroup-metajob jobname)
857 (ediff-draw-dir-diffs ediff-dir-difference-list))
859 ediff-meta-buffer-map "h" 'ediff-mark-for-hiding-at-pos)
860 (define-key ediff-meta-buffer-map "x" 'ediff-hide-marked-sessions)
862 ediff-meta-buffer-map "m" 'ediff-mark-for-operation-at-pos)
863 (define-key ediff-meta-buffer-map "u" nil)
865 ediff-meta-buffer-map "um" 'ediff-unmark-all-for-operation)
867 ediff-meta-buffer-map "uh" 'ediff-unmark-all-for-hiding)
869 (define-key ediff-meta-buffer-map
870 [menu-bar ediff-meta-mode ediff-hide-marked-sessions]
871 '(menu-item "Hide marked" ediff-hide-marked-sessions
872 :help "Hide marked sessions. With prefix arg, unhide"))
874 (define-key ediff-meta-buffer-map
875 [menu-bar ediff-meta-mode ediff-mark-for-hiding-at-pos]
876 '(menu-item "Mark for hiding" ediff-mark-for-hiding-at-pos
877 :help "Mark session for hiding. With prefix arg, unmark"))
879 (define-key ediff-meta-buffer-map
880 [menu-bar ediff-meta-mode ediff-mark-for-operation-at-pos]
881 '(menu-item "Mark for group operation" ediff-mark-for-operation-at-pos
882 :help "Mark session for a group operation. With prefix arg, unmark"))
884 (define-key ediff-meta-buffer-map
885 [menu-bar ediff-meta-mode ediff-unmark-all-for-hiding]
886 '(menu-item "Unmark all for hiding" ediff-unmark-all-for-hiding
887 :help "Unmark all sessions marked for hiding"))
889 (define-key ediff-meta-buffer-map
890 [menu-bar ediff-meta-mode ediff-unmark-all-for-operation]
891 '(menu-item "Unmark all for group operation" ediff-unmark-all-for-operation
892 :help "Unmark all sessions marked for operation"))
894 (cond ((ediff-collect-diffs-metajob jobname)
895 (define-key ediff-meta-buffer-map
896 [menu-bar ediff-meta-mode ediff-collect-custom-diffs]
897 '(menu-item "Collect diffs" ediff-collect-custom-diffs
898 :help "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'"))
900 ediff-meta-buffer-map "P" 'ediff-collect-custom-diffs))
901 ((ediff-patch-metajob jobname)
902 (define-key ediff-meta-buffer-map
903 [menu-bar ediff-meta-mode ediff-meta-show-patch]
904 '(menu-item "Show multi-file patch" ediff-meta-show-patch
905 :help "Show the multi-file patch associated with this group session"))
907 ediff-meta-buffer-map "P" 'ediff-meta-show-patch)))
908 (define-key ediff-meta-buffer-map "^" 'ediff-up-meta-hierarchy)
909 (define-key ediff-meta-buffer-map "D" 'ediff-show-dir-diffs)
911 (define-key ediff-meta-buffer-map
912 [menu-bar ediff-meta-mode ediff-up-meta-hierarchy]
913 '(menu-item "Go to parent session" ediff-up-meta-hierarchy
914 :help "Go to the parent session group buffer"))
916 (define-key ediff-meta-buffer-map
917 [menu-bar ediff-meta-mode ediff-show-dir-diffs]
918 '(menu-item "Diff directories" ediff-show-dir-diffs
919 :help "Display differences among the directories involved in session group"))))
921 (if (eq ediff-metajob-name 'ediff-registry)
922 (run-hooks 'ediff-registry-setup-hook)
923 (run-hooks 'ediff-after-session-group-setup-hook))
924 ) ; eval in meta-buffer
927 ;; Insert the activity marker for session SESSION in the meta buffer at point
928 ;; The activity marker is either SPC (untouched session), or + (active session,
929 ;; i.e., ediff is currently run in it), or - (finished session, i.e., we've ran
930 ;; ediff in it and then exited)
931 (defun ediff-insert-session-activity-marker-in-meta-buffer (session)
933 (cond ((ediff-get-session-activity-marker session))
937 ;; Insert session status at point. Status is either ?H (marked for hiding), or
938 ;; ?I (hidden or invalid), or ?* (meaning marked for an operation; currently,
939 ;; such op can only be checking for equality)), or SPC (meaning neither marked
941 (defun ediff-insert-session-status-in-meta-buffer (session)
943 (cond ((ediff-get-session-status session)) ; session has status: ?H, ?I, ?*
944 ;; normal session, no marks or hidings
947 ;; If NEW-MARKER is non-nil, use it to substitute the current activity marker
948 ;; in the meta buffer. If nil, use SPC
949 (defun ediff-replace-session-activity-marker-in-meta-buffer (point new-marker)
950 (let* ((overl (ediff-get-meta-overlay-at-pos point))
951 (session-info (ediff-overlay-get overl 'ediff-meta-info))
952 (activity-marker (ediff-get-session-activity-marker session-info))
954 (or new-marker activity-marker (setq new-marker ?\s))
955 (goto-char (ediff-overlay-start overl))
956 (if (eq (char-after (point)) new-marker)
957 () ; if marker shown in buffer is the same as new-marker, do nothing
960 (set-buffer-modified-p nil))))
962 ;; If NEW-STATUS is non-nil, use it to substitute the current status marker in
963 ;; the meta buffer. If nil, use SPC
964 (defun ediff-replace-session-status-in-meta-buffer (point new-status)
965 (let* ((overl (ediff-get-meta-overlay-at-pos point))
966 (session-info (ediff-overlay-get overl 'ediff-meta-info))
967 (status (ediff-get-session-status session-info))
969 (setq new-status (or new-status status ?\s))
970 (goto-char (ediff-overlay-start overl))
971 (forward-char 1) ; status is the second char in session record
972 (if (eq (char-after (point)) new-status)
973 () ; if marker shown in buffer is the same as new-marker, do nothing
976 (set-buffer-modified-p nil))))
978 ;; insert all file info in meta buffer for a given session
979 (defun ediff-insert-session-info-in-meta-buffer (session-info sessionNum)
980 (let ((f1 (ediff-get-session-objA session-info))
981 (f2 (ediff-get-session-objB session-info))
982 (f3 (ediff-get-session-objC session-info))
984 (hidden (eq (ediff-get-session-status session-info) ?I)))
985 ;; insert activity marker, i.e., SPC, - or +
986 (ediff-insert-session-activity-marker-in-meta-buffer session-info)
987 ;; insert session status, i.e., *, H
988 (ediff-insert-session-status-in-meta-buffer session-info)
989 (insert " Session " (int-to-string sessionNum) ":\n")
990 (ediff-meta-insert-file-info1 f1)
991 (ediff-meta-insert-file-info1 f2)
992 (ediff-meta-insert-file-info1 f3)
993 (ediff-set-meta-overlay pt (point) session-info sessionNum hidden)))
996 ;; this is a setup function for ediff-directories
997 ;; must return meta-buffer
998 (defun ediff-redraw-directory-group-buffer (meta-list)
999 ;; extract directories
1000 (let ((meta-buf (ediff-get-group-buffer meta-list))
1003 regexp elt merge-autostore-dir
1004 point tmp-list buffer-read-only)
1005 (ediff-with-current-buffer meta-buf
1006 (setq point (point))
1008 ;; delete phony overlays that used to represent sessions before the buff
1010 (if (featurep 'xemacs)
1011 (map-extents 'delete-extent)
1012 (mapc 'delete-overlay (overlays-in 1 1)))
1014 (setq regexp (ediff-get-group-regexp meta-list)
1016 (ediff-get-group-merge-autostore-dir meta-list))
1018 (if ediff-verbose-help-enabled
1020 (insert (format ediff-meta-buffer-verbose-message
1021 (ediff-abbrev-jobname ediff-metajob-name)))
1023 (cond ((ediff-collect-diffs-metajob)
1025 " P:\tcollect custom diffs of all marked sessions\n"))
1026 ((ediff-patch-metajob)
1028 " P:\tshow patch appropriately for the context (session or group)\n")))
1030 " ^:\tshow parent session group\n")
1031 (or (ediff-one-filegroup-metajob)
1033 " D:\tshow differences among directories\n"
1034 " ==:\tfor each session, show which files are identical\n"
1035 " =h:\tlike ==, but also marks sessions for hiding\n"
1036 " =m:\tlike ==, but also marks sessions for operation\n\n")))
1037 (insert (format ediff-meta-buffer-brief-message
1038 (ediff-abbrev-jobname ediff-metajob-name))))
1041 (if (and (stringp regexp) (> (length regexp) 0))
1043 (format "*** Filter-through regular expression: %s\n" regexp)))
1044 (ediff-insert-dirs-in-meta-buffer meta-list)
1045 (if (and ediff-autostore-merges (ediff-merge-metajob)
1046 (ediff-nonempty-string-p merge-autostore-dir))
1048 "\nMerge results are automatically stored in:\n\t%s\n"
1049 merge-autostore-dir)))
1051 Size Last modified Name
1052 ----------------------------------------------
1056 ;; discard info on directories and regexp
1057 (setq meta-list (cdr meta-list)
1059 (while (and tmp-list empty)
1060 (if (and (car tmp-list)
1061 (not (eq (ediff-get-session-status (car tmp-list)) ?I)))
1063 (setq tmp-list (cdr tmp-list)))
1067 " ****** ****** This session group has no members\n"))
1069 ;; now organize file names like this:
1070 ;; use-mark sizeA dateA sizeB dateB filename
1071 ;; make sure directories are displayed with a trailing slash.
1073 (setq elt (car meta-list)
1074 meta-list (cdr meta-list)
1075 sessionNum (1+ sessionNum))
1076 (if (eq (ediff-get-session-status elt) ?I)
1078 (ediff-insert-session-info-in-meta-buffer elt sessionNum)))
1079 (set-buffer-modified-p nil)
1083 (defun ediff-update-markers-in-dir-meta-buffer (meta-list)
1084 (let ((meta-buf (ediff-get-group-buffer meta-list))
1085 session-info point overl buffer-read-only)
1086 (ediff-with-current-buffer meta-buf
1087 (setq point (point))
1088 (goto-char (point-min))
1089 (ediff-next-meta-item1)
1091 (setq session-info (ediff-get-meta-info meta-buf (point) 'no-error)
1092 overl (ediff-get-meta-overlay-at-pos (point)))
1095 (cond ((eq (ediff-get-session-status session-info) ?I)
1097 (if overl (ediff-overlay-put overl 'invisible t)))
1098 ((and (eq (ediff-get-session-status session-info) ?H)
1099 overl (ediff-overlay-get overl 'invisible))
1101 (ediff-overlay-put overl 'invisible nil))
1102 (t (ediff-replace-session-activity-marker-in-meta-buffer
1104 (ediff-get-session-activity-marker session-info))
1105 (ediff-replace-session-status-in-meta-buffer
1107 (ediff-get-session-status session-info))))))
1108 (ediff-next-meta-item1) ; advance to the next item
1110 (set-buffer-modified-p nil)
1114 (defun ediff-update-session-marker-in-dir-meta-buffer (session-num)
1115 (let (buffer-meta-overlays session-info overl buffer-read-only)
1117 (if (featurep 'xemacs)
1119 (lambda (ext _maparg)
1121 (ediff-overlay-get ext 'ediff-meta-info)
1122 (eq (ediff-overlay-get ext 'ediff-meta-session-number)
1125 ;; Emacs doesn't have map-extents, so try harder
1126 ;; Splice overlay lists to get all buffer overlays
1127 (setq buffer-meta-overlays (overlay-lists)
1128 buffer-meta-overlays (append (car buffer-meta-overlays)
1129 (cdr buffer-meta-overlays)))
1135 (ediff-overlay-get overl 'ediff-meta-info)
1136 (eq (ediff-overlay-get
1137 overl 'ediff-meta-session-number)
1140 buffer-meta-overlays)))))
1143 "Bug in ediff-update-session-marker-in-dir-meta-buffer: no overlay with given number %S"
1145 (setq session-info (ediff-overlay-get overl 'ediff-meta-info))
1146 (goto-char (ediff-overlay-start overl))
1147 (ediff-replace-session-activity-marker-in-meta-buffer
1149 (ediff-get-session-activity-marker session-info))
1150 (ediff-replace-session-status-in-meta-buffer
1152 (ediff-get-session-status session-info)))
1153 (ediff-next-meta-item1))
1157 ;; Check if this is a problematic session.
1158 ;; Return nil if not. Otherwise, return symbol representing the problem
1159 ;; At present, problematic sessions occur only in -with-ancestor comparisons
1160 ;; when the ancestor is a directory rather than a file, or when there is no
1161 ;; suitable ancestor file in the ancestor directory
1162 (defun ediff-problematic-session-p (session)
1163 (let ((f1 (ediff-get-session-objA-name session))
1164 (f2 (ediff-get-session-objB-name session))
1165 (f3 (ediff-get-session-objC-name session)))
1166 (cond ((and (stringp f1) (not (file-directory-p f1))
1167 (stringp f2) (not (file-directory-p f2))
1168 ;; either invalid file name or a directory
1169 (or (not (stringp f3)) (file-directory-p f3))
1170 (ediff-ancestor-metajob))
1171 ;; more may be added later
1175 (defun ediff-meta-insert-file-info1 (fileinfo)
1176 (let ((fname (car fileinfo))
1177 (feq (ediff-get-file-eqstatus fileinfo))
1178 (max-filename-width (if ediff-meta-truncate-filenames
1179 (- (window-width) 41)
1181 file-modtime file-size)
1182 (cond ((not (stringp fname)) (setq file-size -2)) ; file doesn't exits
1183 ((ediff-listable-file fname)
1184 (if (file-exists-p fname)
1185 ;; set real size and modtime
1186 (setq file-size (ediff-file-size fname)
1187 file-modtime (ediff-file-modtime fname))
1188 (setq file-size -2))) ; file doesn't exist
1189 ( t (setq file-size -1))) ; remote file
1194 (if feq "=" " ") ; equality indicator
1195 (format "%10s" (cond ((= file-size -1) "--")
1196 ((< file-size -1) "--")
1198 (cond ((= file-size -1) "*remote file*")
1199 ((< file-size -1) "*file doesn't exist*")
1200 (t (ediff-format-date (decode-time file-modtime))))
1202 ;; dir names in meta lists have training slashes, so we just
1203 ;; abbreviate the file name, if file exists
1204 (if (and (not (stringp fname)) (< file-size -1))
1205 "-------" ; file doesn't exist
1206 (ediff-truncate-string-left
1207 (ediff-abbreviate-file-name fname)
1208 max-filename-width)))))))
1210 (defconst ediff-months '((1 . "Jan") (2 . "Feb") (3 . "Mar") (4 . "Apr")
1211 (5 . "May") (6 . "Jun") (7 . "Jul") (8 . "Aug")
1212 (9 . "Sep") (10 . "Oct") (11 . "Nov") (12 . "Dec"))
1213 "Months' associative array.")
1215 ;; returns 2char string
1216 (defsubst ediff-fill-leading-zero (num)
1219 (number-to-string num)))
1221 ;; TIME is like the output of decode-time
1222 (defun ediff-format-date (time)
1223 (format "%s %2d %4d %s:%s:%s"
1224 (cdr (assoc (nth 4 time) ediff-months)) ; month
1227 (ediff-fill-leading-zero (nth 2 time)) ; hour
1228 (ediff-fill-leading-zero (nth 1 time)) ; min
1229 (ediff-fill-leading-zero (nth 0 time)) ; sec
1232 ;; Draw the directories
1233 (defun ediff-insert-dirs-in-meta-buffer (meta-list)
1234 (let* ((dir1 (ediff-abbreviate-file-name (ediff-get-group-objA meta-list)))
1235 (dir2 (ediff-get-group-objB meta-list))
1236 (dir2 (if (stringp dir2) (ediff-abbreviate-file-name dir2)))
1237 (dir3 (ediff-get-group-objC meta-list))
1238 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3))))
1239 (insert "*** Directory A: " dir1 "\n")
1240 (if dir2 (insert "*** Directory B: " dir2 "\n"))
1241 (if dir3 (insert "*** Directory C: " dir3 "\n"))
1244 (defun ediff-draw-dir-diffs (diff-list &optional buf-name)
1245 (if (null diff-list) (error "Lost difference info on these directories"))
1248 (ediff-unique-buffer-name "*Ediff File Group Differences" "*")))
1249 (let* ((regexp (ediff-get-group-regexp diff-list))
1250 (dir1 (ediff-abbreviate-file-name (ediff-get-group-objA diff-list)))
1251 (dir2 (ediff-abbreviate-file-name (ediff-get-group-objB diff-list)))
1252 (dir3 (ediff-get-group-objC diff-list))
1253 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3)))
1254 (meta-buf (ediff-get-group-buffer diff-list))
1255 (underline (make-string 26 ?-))
1256 file membership-code saved-point
1258 ;; skip the directory part
1259 (setq diff-list (cdr diff-list))
1260 (setq ediff-dir-diffs-buffer (get-buffer-create buf-name))
1261 (ediff-with-current-buffer ediff-dir-diffs-buffer
1262 (setq saved-point (point))
1263 (use-local-map ediff-dir-diffs-buffer-map)
1265 (setq ediff-meta-buffer meta-buf)
1266 (insert "\t\t*** Directory Differences ***\n")
1269 C,button2: over file name -- copy this file to directory that doesn't have it
1272 p,DEL: previous line\n\n")
1274 (insert (format "\n*** Directory A: %s\n" dir1))
1275 (if dir2 (insert (format "*** Directory B: %s\n" dir2)))
1276 (if dir3 (insert (format "*** Directory C: %s\n" dir3)))
1277 (if (and (stringp regexp) (> (length regexp) 0))
1279 (format "*** Filter-through regular expression: %s\n" regexp)))
1281 (insert (format "\n%-27s%-26s" "Directory A" "Directory B"))
1283 (insert (format " %-25s\n" "Directory C"))
1285 (insert (format "%s%s" underline underline))
1287 (insert (format "%s\n\n" underline))
1290 (if (null diff-list)
1291 (insert "\n\t*** No differences ***\n"))
1294 (setq file (car (car diff-list))
1295 membership-code (cdr (car diff-list))
1296 diff-list (cdr diff-list))
1297 (if (= (mod membership-code ediff-membership-code1) 0) ; dir1
1298 (let ((beg (point)))
1299 (insert (format "%-27s"
1300 (ediff-truncate-string-left
1301 (ediff-abbreviate-file-name
1302 (if (file-directory-p (concat dir1 file))
1303 (file-name-as-directory file)
1306 ;; format of meta info in the dir-diff-buffer:
1307 ;; (filename-tail filename-full otherdir1 otherdir2 otherdir3)
1308 (ediff-set-meta-overlay
1310 (list meta-buf file (concat dir1 file) dir1 dir2 dir3)))
1311 (insert (format "%-27s" "---")))
1312 (if (= (mod membership-code ediff-membership-code2) 0) ; dir2
1313 (let ((beg (point)))
1314 (insert (format "%-26s"
1315 (ediff-truncate-string-left
1316 (ediff-abbreviate-file-name
1317 (if (file-directory-p (concat dir2 file))
1318 (file-name-as-directory file)
1321 (ediff-set-meta-overlay
1323 (list meta-buf file (concat dir2 file) dir1 dir2 dir3)))
1324 (insert (format "%-26s" "---")))
1326 (if (= (mod membership-code ediff-membership-code3) 0) ; dir3
1327 (let ((beg (point)))
1328 (insert (format " %-25s"
1329 (ediff-truncate-string-left
1330 (ediff-abbreviate-file-name
1331 (if (file-directory-p (concat dir3 file))
1332 (file-name-as-directory file)
1335 (ediff-set-meta-overlay
1337 (list meta-buf file (concat dir3 file) dir1 dir2 dir3)))
1338 (insert (format " %-25s" "---"))))
1340 (setq buffer-read-only t)
1341 (set-buffer-modified-p nil)
1342 (goto-char saved-point)) ; end eval in diff buffer
1345 (defun ediff-bury-dir-diffs-buffer ()
1346 "Bury the directory difference buffer. Display the meta buffer instead."
1348 ;; ediff-meta-buffer is set in ediff-draw-dir-diffs so the directory
1349 ;; difference buffer remembers the meta buffer
1350 (let ((buf ediff-meta-buffer)
1352 (ediff-kill-buffer-carefully ediff-dir-diffs-buffer)
1353 (if (setq wind (ediff-get-visible-buffer-window buf))
1354 (select-window wind)
1355 (set-window-buffer (selected-window) buf))))
1357 ;; executes in dir session group buffer
1358 ;; show buffer differences
1359 (defun ediff-show-dir-diffs ()
1360 "Display differences among the directories involved in session group."
1362 (if (ediff-one-filegroup-metajob)
1363 (error "This command is inapplicable in the present context"))
1364 (or (ediff-buffer-live-p ediff-dir-diffs-buffer)
1365 (ediff-draw-dir-diffs ediff-dir-difference-list))
1366 (let ((buf ediff-dir-diffs-buffer))
1368 (set-window-buffer (selected-window) buf)
1369 (goto-char (point-min))))
1371 ;; Format of meta info in dir-diff-buffer:
1372 ;; (filename-tail filename-full otherdir1 otherdir2)
1373 (defun ediff-dir-diff-copy-file ()
1374 "Copy file described at point to directories where this file is missing."
1376 (let* ((pos (ediff-event-point last-command-event))
1377 (info (ediff-get-meta-info (current-buffer) pos 'noerror))
1378 (meta-buf (car info))
1379 (file-tail (nth 1 info))
1380 (file-abs (nth 2 info))
1381 (otherdir1 (nth 3 info))
1382 (otherfile1 (if otherdir1 (concat otherdir1 file-tail)))
1383 (otherdir2 (nth 4 info))
1384 (otherfile2 (if otherdir2 (concat otherdir2 file-tail)))
1385 (otherdir3 (nth 5 info))
1386 (otherfile3 (if otherdir3 (concat otherdir3 file-tail)))
1387 meta-list dir-diff-list
1390 (error "No file suitable for copying described at this location"))
1391 (ediff-with-current-buffer meta-buf
1392 (setq meta-list ediff-meta-list
1393 dir-diff-list ediff-dir-difference-list))
1395 ;; copy file to directories where it doesn't exist, update
1396 ;; ediff-dir-difference-list and redisplay
1398 (lambda (otherfile-struct)
1399 (let ((otherfile (car otherfile-struct))
1400 (file-mem-code (cdr otherfile-struct)))
1402 (or (file-exists-p otherfile)
1404 (format "Copy %s to %s? " file-abs otherfile))
1405 (let* ((file-diff-record (assoc file-tail dir-diff-list))
1407 (* (cdr file-diff-record) file-mem-code)))
1408 (copy-file file-abs otherfile)
1409 (setcdr file-diff-record new-mem-code)
1410 (ediff-draw-dir-diffs dir-diff-list (buffer-name))
1412 ;; if file is in all three dirs or in two dirs and only
1413 ;; two dirs are involved, delete this file's record
1414 (if (or (= new-mem-code ediff-product-of-memcodes)
1415 (and (> new-mem-code ediff-membership-code3)
1417 (delq file-diff-record dir-diff-list))
1420 ;; 2,3,5 are numbers used to encode membership of a file in
1421 ;; dir1/2/3. See ediff-intersect-directories.
1422 (list (cons otherfile1 2) (cons otherfile2 3) (cons otherfile3 5)))
1424 (if (and (file-exists-p otherfile1)
1425 (file-exists-p otherfile2)
1426 (or (not otherfile3) (file-exists-p otherfile3)))
1427 ;; update ediff-meta-list by direct modification
1429 (list (ediff-make-new-meta-list-element
1430 (expand-file-name otherfile1)
1431 (expand-file-name otherfile2)
1433 (expand-file-name otherfile3)))))
1435 (ediff-update-meta-buffer meta-buf 'must-redraw)
1438 (defun ediff-up-meta-hierarchy ()
1439 "Go to the parent session group buffer."
1441 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1442 (ediff-show-meta-buffer
1443 ediff-parent-meta-buffer ediff-meta-session-number)
1444 (error "This session group has no parent")))
1447 ;; argument is ignored
1448 (defun ediff-redraw-registry-buffer (&optional _ignore)
1449 (ediff-with-current-buffer ediff-registry-buffer
1450 (let ((point (point))
1451 elt bufAname bufBname bufCname cur-diff total-diffs pt
1452 job-name meta-list registry-list buffer-read-only)
1454 ;; delete phony overlays that used to represent sessions before the buff
1456 (if (featurep 'xemacs)
1457 (map-extents 'delete-extent)
1458 (mapc 'delete-overlay (overlays-in 1 1)))
1460 (insert (substitute-command-keys "\
1461 This is a registry of all active Ediff sessions.
1464 button2, `v', RET over a session record: switch to that session
1465 M over a session record: display the associated session group
1466 R in any Ediff session: display session registry
1468 p,DEL: previous session
1469 E: browse Ediff manual
1473 \t\tActive Ediff Sessions:
1474 \t\t----------------------
1477 ;; purge registry list from dead buffers
1479 (if (not (ediff-buffer-live-p elt))
1480 (setq ediff-session-registry
1481 (delq elt ediff-session-registry))))
1482 ediff-session-registry)
1484 (if (null ediff-session-registry)
1485 (insert " ******* No active Ediff sessions *******\n"))
1487 (setq registry-list ediff-session-registry)
1488 (while registry-list
1489 (setq elt (car registry-list)
1490 registry-list (cdr registry-list))
1492 (if (ediff-buffer-live-p elt)
1493 (if (ediff-with-current-buffer elt
1494 (setq job-name ediff-metajob-name
1495 meta-list ediff-meta-list)
1496 (and ediff-metajob-name
1497 (not (eq ediff-metajob-name 'ediff-registry))))
1500 (insert (format " *group*\t%s: %s\n"
1502 (ediff-abbrev-jobname job-name)))
1503 (insert (format "\t\t %s %s %s\n"
1504 (ediff-abbreviate-file-name
1505 (ediff-get-group-objA meta-list))
1506 (ediff-abbreviate-file-name
1508 (ediff-get-group-objB meta-list))
1509 (ediff-get-group-objB meta-list)
1511 (ediff-abbreviate-file-name
1513 (ediff-get-group-objC meta-list))
1514 (ediff-get-group-objC meta-list)
1516 (ediff-set-meta-overlay pt (point) elt))
1518 (ediff-with-current-buffer elt
1519 (setq bufAname (if (ediff-buffer-live-p ediff-buffer-A)
1520 (buffer-name ediff-buffer-A)
1521 "!!!killed buffer!!!")
1522 bufBname (if (ediff-buffer-live-p ediff-buffer-B)
1523 (buffer-name ediff-buffer-B)
1524 "!!!killed buffer!!!")
1525 bufCname (cond ((not (ediff-3way-job))
1527 ((ediff-buffer-live-p ediff-buffer-C)
1528 (buffer-name ediff-buffer-C))
1529 (t "!!!killed buffer!!!")))
1530 (setq total-diffs (format "%-4d" ediff-number-of-differences)
1532 (cond ((= ediff-current-difference -1) " _")
1533 ((= ediff-current-difference
1534 ediff-number-of-differences)
1537 "%4d" (1+ ediff-current-difference))))
1538 job-name ediff-job-name))
1539 ;; back in the meta buf
1541 (insert cur-diff "/" total-diffs "\t"
1543 (format ": %s" (ediff-abbrev-jobname job-name)))
1545 "\n\t\t " bufAname " " bufBname " " bufCname "\n")
1546 (ediff-set-meta-overlay pt (point) elt))))
1548 (set-buffer-modified-p nil)
1552 ;; Sets overlay around a meta record with 'ediff-meta-info property PROP
1553 ;; If optional SESSION-NUMBER, make it a property of the overlay,
1554 ;; ediff-meta-session-number
1555 ;; PROP is either the ctl or meta buffer (used when we work with the registry)
1556 ;; or a session meta descriptor of the form
1557 ;; (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
1558 (defun ediff-set-meta-overlay (b e prop &optional session-number hidden)
1560 (setq overl (ediff-make-overlay b e))
1561 (if (featurep 'emacs)
1562 (ediff-overlay-put overl 'mouse-face 'highlight)
1563 (ediff-overlay-put overl 'highlight t))
1564 (ediff-overlay-put overl 'ediff-meta-info prop)
1565 (ediff-overlay-put overl 'invisible hidden)
1566 (ediff-overlay-put overl 'follow-link t)
1567 (if (numberp session-number)
1568 (ediff-overlay-put overl 'ediff-meta-session-number session-number))))
1570 (defun ediff-mark-for-hiding-at-pos (unmark)
1571 "Mark session for hiding. With prefix arg, unmark."
1573 (let* ((pos (ediff-event-point last-command-event))
1574 (meta-buf (ediff-event-buffer last-command-event))
1575 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1576 (info (ediff-get-meta-info meta-buf pos))
1577 (session-number (ediff-get-session-number-at-pos pos)))
1578 (ediff-mark-session-for-hiding info unmark)
1579 (ediff-next-meta-item 1)
1581 (ediff-update-meta-buffer meta-buf nil session-number))
1584 ;; Returns whether session was marked or unmarked
1585 (defun ediff-mark-session-for-hiding (info unmark)
1586 (let ((session-buf (ediff-get-session-buffer info))
1588 (cond ((eq unmark 'mark) (setq unmark nil))
1589 ((eq (ediff-get-session-status info) ?H) (setq unmark t))
1590 (unmark ; says unmark, but the marker is different from H
1593 (unmark (ediff-set-session-status info nil))
1594 ;;; (if (ediff-buffer-live-p session-buf)
1595 ;;; (error "Can't hide active session, %s" (buffer-name session-buf)))
1596 (t (ediff-set-session-status info ?H))))
1600 (defun ediff-mark-for-operation-at-pos (unmark)
1601 "Mark session for a group operation. With prefix arg, unmark."
1603 (let* ((pos (ediff-event-point last-command-event))
1604 (meta-buf (ediff-event-buffer last-command-event))
1605 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1606 (info (ediff-get-meta-info meta-buf pos))
1607 (session-number (ediff-get-session-number-at-pos pos)))
1608 (ediff-mark-session-for-operation info unmark)
1609 (ediff-next-meta-item 1)
1611 (ediff-update-meta-buffer meta-buf nil session-number))
1615 ;; returns whether session was unmarked.
1616 ;; remember: this is a toggle op
1617 (defun ediff-mark-session-for-operation (info unmark)
1619 (cond ((eq unmark 'mark) (setq unmark nil))
1620 ((eq (ediff-get-session-status info) ?*) (setq unmark t))
1621 (unmark ; says unmark, but the marker is different from *
1624 (unmark (ediff-set-session-status info nil))
1625 (t (ediff-set-session-status info ?*))))
1629 (defun ediff-hide-marked-sessions (unhide)
1630 "Hide marked sessions. With prefix arg, unhide."
1632 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1633 (meta-list (cdr ediff-meta-list))
1634 (from (if unhide ?I ?H))
1635 (to (if unhide ?H ?I))
1637 active-sessions-exist session-buf elt)
1639 (setq elt (car meta-list)
1640 meta-list (cdr meta-list)
1641 session-buf (ediff-get-session-buffer elt))
1643 (if (eq (ediff-get-session-status elt) from)
1645 (setq numMarked (1+ numMarked))
1646 (if (and (eq to ?I) (buffer-live-p session-buf))
1647 ;; shouldn't hide active sessions
1648 (setq active-sessions-exist t)
1649 (ediff-set-session-status elt to)))))
1651 (ediff-update-meta-buffer grp-buf 'must-redraw)
1654 (message "Nothing to reveal...")
1655 (message "Nothing to hide...")))
1656 (if active-sessions-exist
1657 (message "Note: Ediff didn't hide active sessions!"))
1660 ;; Apply OPERATION to marked sessions. Operation expects one argument of type
1661 ;; meta-list member (not the first one), i.e., a regular session description.
1662 ;; Returns number of marked sessions on which operation was performed
1663 (defun ediff-operate-on-marked-sessions (operation)
1664 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1665 (meta-list (cdr ediff-meta-list))
1669 (diff-buffer ediff-meta-diff-buffer)
1672 (setq elt (car meta-list)
1673 meta-list (cdr meta-list)
1674 sessionNum (1+ sessionNum))
1675 (cond ((eq (ediff-get-session-status elt) marksym)
1677 (setq numMarked (1+ numMarked))
1678 (funcall operation elt sessionNum)))
1679 ;; The following goes into a session represented by a subdirectory
1680 ;; and applies operation to marked sessions there
1681 ((and (ediff-meta-session-p elt)
1682 (ediff-buffer-live-p
1683 (setq session-buf (ediff-get-session-buffer elt))))
1686 (ediff-with-current-buffer session-buf
1687 ;; pass meta-diff along
1688 (setq ediff-meta-diff-buffer diff-buffer)
1689 ;; collect diffs in child group
1690 (ediff-operate-on-marked-sessions operation)))))))
1691 (ediff-update-meta-buffer grp-buf 'must-redraw) ; just in case
1695 (defun ediff-append-custom-diff (session sessionNum)
1696 (or (ediff-collect-diffs-metajob)
1697 (error "Can't compute multifile patch in this context"))
1698 (let ((session-buf (ediff-get-session-buffer session))
1699 (meta-diff-buff ediff-meta-diff-buffer)
1700 (metajob ediff-metajob-name)
1701 tmp-buf custom-diff-buf)
1702 (if (ediff-buffer-live-p session-buf)
1703 (ediff-with-current-buffer session-buf
1704 (if (eq ediff-control-buffer session-buf) ; individual session
1706 (ediff-compute-custom-diffs-maybe)
1707 (setq custom-diff-buf ediff-custom-diff-buffer)))))
1709 (or (ediff-buffer-live-p meta-diff-buff)
1710 (error "Ediff: something wrong--killed multiple diff's buffer"))
1712 (cond ((ediff-buffer-live-p custom-diff-buf)
1713 ;; for live session buffers we do them first because the user may
1714 ;; have changed them with respect to the underlying files
1715 (with-current-buffer meta-diff-buff
1716 (goto-char (point-max))
1717 (insert-buffer-substring custom-diff-buf)
1719 ;; if ediff session is not live, run diff directly on the files
1720 ((memq metajob '(ediff-directories
1721 ediff-merge-directories
1722 ediff-merge-directories-with-ancestor))
1723 ;; get diffs by calling shell command on ediff-custom-diff-program
1724 (with-current-buffer
1725 (setq tmp-buf (get-buffer-create ediff-tmp-buffer))
1730 (shell-quote-argument ediff-custom-diff-program)
1731 ediff-custom-diff-options
1732 (shell-quote-argument (ediff-get-session-objA-name session))
1733 (shell-quote-argument (ediff-get-session-objB-name session))
1737 (with-current-buffer meta-diff-buff
1738 (goto-char (point-max))
1739 (insert-buffer-substring tmp-buf)
1742 (ediff-kill-buffer-carefully meta-diff-buff)
1743 (error "Session %d compares versions of file. Such session must be active to enable multifile patch collection" sessionNum )))
1746 (defun ediff-collect-custom-diffs ()
1747 "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'.
1748 This operation is defined only for `ediff-directories' and
1749 `ediff-directory-revisions', since its intent is to produce
1750 multifile patches. For `ediff-directory-revisions', we insist that
1751 all marked sessions must be active."
1753 (let ((coding-system-for-read ediff-coding-system-for-read))
1754 (or (ediff-buffer-live-p ediff-meta-diff-buffer)
1755 (setq ediff-meta-diff-buffer
1757 (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
1758 (ediff-with-current-buffer ediff-meta-diff-buffer
1759 (setq buffer-read-only nil)
1761 (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
1764 (display-buffer ediff-meta-diff-buffer 'not-this-window)
1765 (ediff-with-current-buffer ediff-meta-diff-buffer
1766 (set-buffer-modified-p nil)
1767 (setq buffer-read-only t))
1768 (if (fboundp 'diff-mode)
1769 (with-current-buffer ediff-meta-diff-buffer
1772 (message "No marked sessions found"))))
1774 (defun ediff-meta-show-patch ()
1775 "Show the multi-file patch associated with this group session."
1777 (let* ((pos (ediff-event-point last-command-event))
1778 (meta-buf (ediff-event-buffer last-command-event))
1779 (info (ediff-get-meta-info meta-buf pos 'noerror))
1780 (patchbuffer ediff-meta-patchbufer))
1781 (if (ediff-buffer-live-p patchbuffer)
1782 (ediff-with-current-buffer patchbuffer
1787 (ediff-get-session-objB-name info)
1788 (ediff-get-session-objC-name info)))
1789 (set-buffer (get-buffer-create ediff-tmp-buffer))
1791 (insert-buffer-substring patchbuffer)
1792 (goto-char (point-min))
1793 (display-buffer ediff-tmp-buffer 'not-this-window)
1795 (error "The patch buffer wasn't found"))))
1797 (declare-function ediff-directories-internal "ediff"
1798 (dir1 dir2 dir3 regexp action jobname
1799 &optional startup-hooks merge-autostore-dir))
1801 (declare-function ediff-directory-revisions-internal "ediff"
1802 (dir1 regexp action jobname
1803 &optional startup-hooks merge-autostore-dir))
1806 ;; This function executes in meta buffer. It knows where event happened.
1807 (defun ediff-filegroup-action ()
1808 "Execute appropriate action for a selected session."
1810 (let* ((pos (ediff-event-point last-command-event))
1811 (meta-buf (ediff-event-buffer last-command-event))
1812 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1813 (info (ediff-get-meta-info meta-buf pos))
1814 (session-buf (ediff-get-session-buffer info))
1815 (session-number (ediff-get-session-number-at-pos pos meta-buf))
1816 (default-regexp (eval ediff-default-filtering-regexp))
1817 merge-autostore-dir file1 file2 file3 regexp)
1819 (setq file1 (ediff-get-session-objA-name info)
1820 file2 (ediff-get-session-objB-name info)
1821 file3 (ediff-get-session-objC-name info))
1823 ;; make sure we don't start on hidden sessions
1824 ;; ?H means marked for hiding. ?I means invalid (hidden).
1825 (if (memq (ediff-get-session-status info) '(?I))
1828 (if (y-or-n-p "This session is marked as hidden, unmark? ")
1830 (ediff-set-session-status info nil)
1831 (ediff-update-meta-buffer meta-buf nil session-number))
1832 (error "Aborted"))))
1834 (ediff-with-current-buffer meta-buf
1835 (setq merge-autostore-dir
1836 (ediff-get-group-merge-autostore-dir ediff-meta-list))
1837 (goto-char pos) ; if the user clicked on session--move point there
1838 ;; First handle sessions involving directories (which are themselves
1840 ;; After that handle individual sessions
1841 (cond ((ediff-meta-session-p info)
1842 ;; do ediff/ediff-merge on subdirectories
1843 (if (ediff-buffer-live-p session-buf)
1844 (ediff-show-meta-buffer session-buf)
1847 (if (stringp default-regexp)
1849 "Filter through regular expression (default %s): "
1851 "Filter through regular expression: ")
1853 'ediff-filtering-regexp-history
1854 (eval ediff-default-filtering-regexp)))
1855 (ediff-directories-internal
1856 file1 file2 file3 regexp
1857 ediff-session-action-function
1859 ;; make it update (car info) after startup
1861 ;; child session group should know its parent
1862 (setq ediff-parent-meta-buffer
1863 (quote ,ediff-meta-buffer)
1864 ediff-meta-session-number
1866 ;; and parent will know its child
1867 (setcar (quote ,info) ediff-meta-buffer))))))
1869 ;; Do ediff-revision on a subdirectory
1870 ((and (ediff-one-filegroup-metajob)
1871 (ediff-revision-metajob)
1872 (file-directory-p file1))
1873 (if (ediff-buffer-live-p session-buf)
1874 (ediff-show-meta-buffer session-buf)
1875 (setq regexp (read-string "Filter through regular expression: "
1876 nil 'ediff-filtering-regexp-history))
1877 (ediff-directory-revisions-internal
1879 ediff-session-action-function ediff-metajob-name
1880 ;; make it update (car info) after startup
1882 ;; child session group should know its parent and
1884 (setq ediff-parent-meta-buffer
1885 (quote ,ediff-meta-buffer)
1886 ediff-meta-session-number
1888 ;; and parent will know its child
1889 (setcar (quote ,info) ediff-meta-buffer))))))
1891 ;; From here on---only individual session handlers
1893 ;; handle an individual session with a live control buffer
1894 ((ediff-buffer-live-p session-buf)
1895 (ediff-with-current-buffer session-buf
1896 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1897 (ediff-recenter 'no-rehighlight)))
1899 ((ediff-problematic-session-p info)
1902 "This session has no ancestor. Merge without the ancestor? ")
1905 ;; provide startup hooks
1908 'ediff-after-quit-hook-internal
1910 (if (ediff-buffer-live-p ,(current-buffer))
1911 (ediff-show-meta-buffer
1912 ,(current-buffer) ,session-number)))
1914 (setq ediff-meta-buffer ,(current-buffer)
1915 ediff-meta-session-number
1917 (setq ediff-merge-store-file
1918 ,(if (ediff-nonempty-string-p
1919 merge-autostore-dir)
1922 ediff-merge-filename-prefix
1923 (file-name-nondirectory file1))
1925 ;; make ediff-startup pass
1926 ;; ediff-control-buffer back to the meta
1929 (quote ,info) ediff-control-buffer))))
1931 ((ediff-one-filegroup-metajob) ; needs 1 file arg
1932 (funcall ediff-session-action-function
1934 ;; provide startup hooks
1937 'ediff-after-quit-hook-internal
1939 (if (ediff-buffer-live-p
1941 (ediff-show-meta-buffer
1945 (setq ediff-meta-buffer ,(current-buffer)
1946 ediff-meta-session-number
1948 (setq ediff-merge-store-file
1949 ,(if (ediff-nonempty-string-p
1950 merge-autostore-dir)
1953 ediff-merge-filename-prefix
1954 (file-name-nondirectory file1))) )
1955 ;; make ediff-startup pass
1956 ;; ediff-control-buffer back to the meta
1959 (quote ,info) ediff-control-buffer)))))
1960 ((not (ediff-metajob3)) ; need 2 file args
1961 (funcall ediff-session-action-function
1963 ;; provide startup hooks
1966 'ediff-after-quit-hook-internal
1968 (if (ediff-buffer-live-p
1970 (ediff-show-meta-buffer
1974 (setq ediff-meta-buffer ,(current-buffer)
1975 ediff-meta-session-number
1977 (setq ediff-merge-store-file
1978 ,(if (ediff-nonempty-string-p
1979 merge-autostore-dir)
1982 ediff-merge-filename-prefix
1983 (file-name-nondirectory file1))) )
1984 ;; make ediff-startup pass
1985 ;; ediff-control-buffer back to the meta
1988 (quote ,info) ediff-control-buffer)))))
1989 ((ediff-metajob3) ; need 3 file args
1990 (funcall ediff-session-action-function
1992 ;; arrange startup hooks
1995 'ediff-after-quit-hook-internal
1997 (if (ediff-buffer-live-p
1999 (ediff-show-meta-buffer
2003 (setq ediff-merge-store-file
2004 ,(if (ediff-nonempty-string-p
2005 merge-autostore-dir)
2008 ediff-merge-filename-prefix
2009 (file-name-nondirectory file1))) )
2010 (setq ediff-meta-buffer , (current-buffer)
2011 ediff-meta-session-number
2013 ;; this arranges that ediff-startup will pass
2014 ;; the value of ediff-control-buffer back to
2015 ;; the meta level, to the record in the meta
2016 ;; list containing the information about the
2017 ;; session associated with that
2018 ;; ediff-control-buffer
2020 (quote ,info) ediff-control-buffer)))))
2022 ) ; eval in meta-buf
2025 (defun ediff-registry-action ()
2026 "Switch to a selected session."
2028 (let* ((pos (ediff-event-point last-command-event))
2029 (buf (ediff-event-buffer last-command-event))
2030 (ctl-buf (ediff-get-meta-info buf pos)))
2032 (if (ediff-buffer-live-p ctl-buf)
2033 ;; check if this is ediff-control-buffer or ediff-meta-buffer
2034 (if (ediff-with-current-buffer ctl-buf
2035 (eq (key-binding "q") 'ediff-quit-meta-buffer))
2036 ;; it's a meta-buffer -- last action should just display it
2037 (ediff-show-meta-buffer ctl-buf t)
2038 ;; it's a session buffer -- invoke go back to session
2039 (ediff-with-current-buffer ctl-buf
2040 (setq ediff-mouse-pixel-position (mouse-pixel-position))
2041 (ediff-recenter 'no-rehighlight)))
2043 (message "You've selected a stale session --- try again")
2044 (ediff-update-registry))
2045 (ediff-with-current-buffer buf
2050 ;; If session number is t, means don't update meta buffer
2051 (defun ediff-show-meta-buffer (&optional meta-buf session-number)
2052 "Show the session group buffer."
2054 (run-hooks 'ediff-before-directory-setup-hooks)
2055 (let (wind frame silent)
2056 (if meta-buf (setq silent t))
2058 (setq meta-buf (or meta-buf ediff-meta-buffer))
2059 (cond ((not (bufferp meta-buf))
2060 (error "This Ediff session is not part of a session group"))
2061 ((not (ediff-buffer-live-p meta-buf))
2063 "Can't find this session's group panel -- session itself is ok")))
2065 (cond ((numberp session-number)
2066 (ediff-update-meta-buffer meta-buf nil session-number))
2067 ;; if session-number is t, don't update
2069 (t (ediff-cleanup-meta-buffer meta-buf)))
2071 (ediff-with-current-buffer meta-buf
2073 (cond ((setq wind (ediff-get-visible-buffer-window meta-buf))
2076 "Already showing the group panel for this session"))
2077 (set-window-buffer wind meta-buf)
2078 (select-window wind))
2079 ((window-live-p (setq wind ediff-window-C)) ;in merge--merge buf
2080 (set-window-buffer ediff-window-C meta-buf)
2081 (select-window wind))
2082 ((window-live-p (setq wind ediff-window-A))
2083 (set-window-buffer ediff-window-A meta-buf)
2084 (select-window wind))
2085 ((window-live-p (setq wind ediff-window-B))
2086 (set-window-buffer ediff-window-B meta-buf)
2087 (select-window wind))
2090 (ediff-get-visible-buffer-window ediff-registry-buffer))
2091 (ediff-window-display-p))
2092 (select-window wind)
2094 (set-window-buffer (selected-window) meta-buf))
2095 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
2096 (set-window-buffer (selected-window) meta-buf)))
2098 (if (and (ediff-window-display-p)
2100 (setq wind (ediff-get-visible-buffer-window meta-buf))))
2102 (setq frame (window-frame wind))
2104 (ediff-reset-mouse frame)))
2105 (sit-for 0) ; sometimes needed to synch the display and ensure that the
2106 ; point ends up after the just completed session
2107 (run-hooks 'ediff-show-session-group-hook)
2110 (defun ediff-show-current-session-meta-buffer ()
2112 (ediff-show-meta-buffer nil ediff-meta-session-number))
2114 (defun ediff-show-meta-buff-from-registry ()
2115 "Display the session group buffer for a selected session group."
2117 (let* ((pos (ediff-event-point last-command-event))
2118 (meta-buf (ediff-event-buffer last-command-event))
2119 (info (ediff-get-meta-info meta-buf pos))
2120 (meta-or-session-buf info))
2121 (ediff-with-current-buffer meta-or-session-buf
2122 (ediff-show-meta-buffer nil t))))
2125 (defun ediff-show-registry ()
2126 "Display Ediff's registry."
2128 (ediff-update-registry)
2129 (if (not (ediff-buffer-live-p ediff-registry-buffer))
2130 (error "No active Ediff sessions or corrupted session registry"))
2132 ;; for some reason, point moves in ediff-registry-buffer, so we preserve it
2134 (ediff-with-current-buffer ediff-registry-buffer
2137 (ediff-get-visible-buffer-window ediff-registry-buffer))
2138 (message "Already showing the registry")
2139 (set-window-buffer wind ediff-registry-buffer)
2140 (select-window wind))
2141 ((window-live-p ediff-window-C)
2142 (set-window-buffer ediff-window-C ediff-registry-buffer)
2143 (select-window ediff-window-C))
2144 ((window-live-p ediff-window-A)
2145 (set-window-buffer ediff-window-A ediff-registry-buffer)
2146 (select-window ediff-window-A))
2147 ((window-live-p ediff-window-B)
2148 (set-window-buffer ediff-window-B ediff-registry-buffer)
2149 (select-window ediff-window-B))
2151 (ediff-get-visible-buffer-window ediff-meta-buffer))
2152 (ediff-window-display-p))
2153 (select-window wind)
2155 (set-window-buffer (selected-window) ediff-registry-buffer))
2156 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
2157 (set-window-buffer (selected-window) ediff-registry-buffer)))
2159 (if (ediff-window-display-p)
2163 (ediff-get-visible-buffer-window ediff-registry-buffer)))
2165 (ediff-reset-mouse frame)))
2166 (run-hooks 'ediff-show-registry-hook)
2170 (defalias 'eregistry 'ediff-show-registry)
2172 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a
2174 ;; Check if META-BUF exists before calling this function
2175 ;; Optional MUST-REDRAW, if non-nil, would force redrawing of the whole meta
2176 ;; buffer. Otherwise, it will just go over the buffer and update activity marks
2177 ;; and session status.
2178 ;; SESSION-NUMBER, if specified, says which session caused the update.
2179 (defun ediff-update-meta-buffer (meta-buf &optional must-redraw session-number)
2180 (if (ediff-buffer-live-p meta-buf)
2181 (ediff-with-current-buffer meta-buf
2183 (cond (must-redraw ; completely redraw the meta buffer
2184 (funcall ediff-meta-redraw-function ediff-meta-list))
2185 ((numberp session-number) ; redraw only for the given session
2186 (ediff-update-session-marker-in-dir-meta-buffer
2188 (t ; update what changed only, but scan the entire meta buffer
2189 (ediff-update-markers-in-dir-meta-buffer ediff-meta-list)))
2190 (setq overl (ediff-get-meta-overlay-at-pos (point)))
2191 ;; skip the invisible sessions
2192 (while (and overl (ediff-overlay-get overl 'invisible))
2193 (ediff-next-meta-item1)
2194 (setq overl (ediff-get-meta-overlay-at-pos (point))))
2197 (defun ediff-update-registry ()
2198 (ediff-with-current-buffer (current-buffer)
2199 (if (ediff-buffer-live-p ediff-registry-buffer)
2200 (ediff-redraw-registry-buffer)
2201 (ediff-prepare-meta-buffer
2202 'ediff-registry-action
2203 ediff-session-registry
2205 'ediff-redraw-registry-buffer
2209 ;; If meta-buf exists, it is redrawn along with parent.
2210 ;; Otherwise, nothing happens.
2211 (defun ediff-cleanup-meta-buffer (meta-buffer)
2212 (if (ediff-buffer-live-p meta-buffer)
2213 (ediff-with-current-buffer meta-buffer
2214 (ediff-update-meta-buffer meta-buffer)
2215 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
2216 (ediff-update-meta-buffer
2217 ediff-parent-meta-buffer nil ediff-meta-session-number)))))
2219 ;; t if no session is in progress
2220 (defun ediff-safe-to-quit (meta-buffer)
2221 (if (ediff-buffer-live-p meta-buffer)
2222 (let ((lis ediff-meta-list)
2225 ;;(ediff-update-meta-buffer meta-buffer)
2226 (ediff-with-current-buffer meta-buffer
2227 (setq lis (cdr lis)) ; discard the description part of meta-list
2228 (while (and cont lis)
2229 (if (ediff-buffer-live-p
2230 (ediff-get-group-buffer lis)) ; in progress
2232 (setq lis (cdr lis)))
2235 (defun ediff-quit-meta-buffer ()
2236 "If the group has no active session, delete the meta buffer.
2237 If no session is in progress, ask to confirm before deleting meta buffer.
2238 Otherwise, bury the meta buffer.
2239 If this is a session registry buffer then just bury it."
2241 (let* ((buf (current-buffer))
2242 (dir-diffs-buffer ediff-dir-diffs-buffer)
2243 (meta-diff-buffer ediff-meta-diff-buffer)
2244 (session-number ediff-meta-session-number)
2245 (parent-buf ediff-parent-meta-buffer)
2246 (dont-show-registry (eq buf ediff-registry-buffer)))
2247 (if dont-show-registry
2249 ;;(ediff-cleanup-meta-buffer buf)
2250 (cond ((and (ediff-safe-to-quit buf)
2251 (y-or-n-p "Quit this session group? "))
2252 (run-hooks 'ediff-quit-session-group-hook)
2254 (ediff-dispose-of-meta-buffer buf))
2255 ((ediff-safe-to-quit buf)
2259 "This session group has active sessions---cannot exit")))
2260 (ediff-update-meta-buffer parent-buf nil session-number)
2261 (ediff-kill-buffer-carefully dir-diffs-buffer)
2262 (ediff-kill-buffer-carefully meta-diff-buffer)
2263 (if (ediff-buffer-live-p parent-buf)
2265 (setq dont-show-registry t)
2266 (ediff-show-meta-buffer parent-buf session-number)))
2268 (or dont-show-registry
2269 (ediff-show-registry))))
2271 (defun ediff-dispose-of-meta-buffer (buf)
2272 (setq ediff-session-registry (delq buf ediff-session-registry))
2273 (ediff-with-current-buffer buf
2274 (if (ediff-buffer-live-p ediff-dir-diffs-buffer)
2275 (kill-buffer ediff-dir-diffs-buffer)))
2279 ;; Obtain information on a meta record where the user clicked or typed
2280 ;; BUF is the buffer where this happened and POINT is the position
2281 ;; If optional NOERROR arg is given, don't report error and return nil if no
2282 ;; meta info is found on line.
2283 (defun ediff-get-meta-info (buf point &optional noerror)
2284 (let (result olist tmp)
2285 (if (and point (ediff-buffer-live-p buf))
2286 (ediff-with-current-buffer buf
2287 (if (featurep 'xemacs)
2289 (if (setq tmp (extent-at point buf 'ediff-meta-info))
2290 (ediff-overlay-get tmp 'ediff-meta-info)))
2292 (mapcar (lambda (elt)
2293 (unless (overlay-get elt 'invisible)
2294 (overlay-get elt 'ediff-meta-info)))
2295 (overlays-at point)))
2296 (while (and olist (null (car olist)))
2297 (setq olist (cdr olist)))
2298 (setq result (car olist)))))
2301 (ediff-update-registry)
2302 (error "No session info in this line")))))
2305 (defun ediff-get-meta-overlay-at-pos (point)
2306 (if (featurep 'xemacs)
2307 (extent-at point (current-buffer) 'ediff-meta-info)
2308 (let* ((overl-list (overlays-at point))
2309 (overl (car overl-list)))
2310 (while (and overl (null (overlay-get overl 'ediff-meta-info)))
2311 (setq overl-list (cdr overl-list)
2312 overl (car overl-list)))
2315 (defun ediff-get-session-number-at-pos (point &optional meta-buffer)
2316 (setq meta-buffer (if (ediff-buffer-live-p meta-buffer)
2319 (ediff-with-current-buffer meta-buffer
2321 (ediff-get-meta-overlay-at-pos point) 'ediff-meta-session-number)))
2324 ;; Return location of the next meta overlay after point
2325 (defun ediff-next-meta-overlay-start (point)
2327 (goto-char (point-min))
2328 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2329 (if (featurep 'xemacs)
2332 (setq overl (next-extent overl))
2333 (setq overl (next-extent (current-buffer))))
2335 (extent-start-position overl)
2339 ;; note: end of current overlay is the beginning of the next one
2341 (next-overlay-change point))))))
2344 (defun ediff-previous-meta-overlay-start (point)
2346 (goto-char (point-max))
2347 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2348 (if (featurep 'xemacs)
2351 (setq overl (previous-extent overl))
2352 (setq overl (previous-extent (current-buffer))))
2354 (extent-start-position overl)
2356 (if overl (setq point (overlay-start overl)))
2357 ;; to get to the beginning of prev overlay
2359 ;; trick to overcome an emacs bug--doesn't always find previous
2360 ;; overlay change correctly
2361 (setq point (1- point)))
2362 (setq point (previous-overlay-change point))
2363 ;; If we are not over an overlay after subtracting 1, it means we are
2364 ;; in the description area preceding session records. In this case,
2365 ;; goto the top of the registry buffer.
2366 (or (car (overlays-at point))
2367 (setq point (point-min)))
2370 (autoload 'ediff-patch-file-internal "ediff-ptch")
2372 ;; this is the action invoked when the user selects a patch from the meta
2374 (defun ediff-patch-file-form-meta (file &optional startup-hooks)
2375 (let* ((pos (ediff-event-point last-command-event))
2376 (meta-buf (ediff-event-buffer last-command-event))
2377 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
2378 (info (ediff-get-meta-info meta-buf pos))
2379 (meta-patchbuf ediff-meta-patchbufer)
2380 session-buf beg-marker end-marker)
2382 (if (or (file-directory-p file) (string-match "/dev/null" file))
2383 (error "`%s' is not an ordinary file" (file-name-as-directory file)))
2384 (setq session-buf (ediff-get-session-buffer info)
2385 beg-marker (ediff-get-session-objB-name info)
2386 end-marker (ediff-get-session-objC-name info))
2388 (or (ediff-buffer-live-p session-buf) ; either an active patch session
2389 (null session-buf) ; or it is a virgin session
2391 "Patch has already been applied to this file -- can't repeat!"))
2393 (ediff-with-current-buffer meta-patchbuf
2396 (narrow-to-region beg-marker end-marker)
2397 (ediff-patch-file-internal meta-patchbuf file startup-hooks)))))
2400 (defun ediff-unmark-all-for-operation ()
2401 "Unmark all sessions marked for operation."
2403 (let ((list (cdr ediff-meta-list))
2405 (while (setq elt (car list))
2406 (ediff-mark-session-for-operation elt 'unmark)
2407 (setq list (cdr list))))
2408 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2410 (defun ediff-unmark-all-for-hiding ()
2411 "Unmark all sessions marked for hiding."
2413 (let ((list (cdr ediff-meta-list))
2415 (while (setq elt (car list))
2416 (ediff-mark-session-for-hiding elt 'unmark)
2417 (setq list (cdr list))))
2418 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2421 ;; ACTION is ?h, ?m, ?=: to mark for hiding, mark for operation, or simply
2422 ;; indicate which are equal files
2423 (defun ediff-meta-mark-equal-files (&optional action)
2424 "Run through the session list and mark identical files.
2425 This is used only for sessions that involve 2 or 3 files at the same time.
2426 ACTION is an optional argument that can be ?h, ?m, ?=, to mark for hiding, mark
2427 for operation, or simply indicate which are equal files. If it is nil, then
2428 `(ediff-last-command-char)' is used to decide which action to take."
2431 (setq action (ediff-last-command-char)))
2432 (let ((list (cdr ediff-meta-list))
2433 marked1 marked2 marked3
2434 fileinfo1 fileinfo2 fileinfo3 elt)
2435 (message "Comparing files...")
2436 (while (setq elt (car list))
2437 (setq fileinfo1 (ediff-get-session-objA elt)
2438 fileinfo2 (ediff-get-session-objB elt)
2439 fileinfo3 (ediff-get-session-objC elt))
2440 (ediff-set-file-eqstatus fileinfo1 nil)
2441 (ediff-set-file-eqstatus fileinfo2 nil)
2442 (ediff-set-file-eqstatus fileinfo3 nil)
2447 (or (ediff-mark-if-equal fileinfo1 fileinfo2)
2449 (if (ediff-metajob3)
2451 (or (ediff-mark-if-equal fileinfo1 fileinfo3)
2453 (or (ediff-mark-if-equal fileinfo2 fileinfo3)
2454 (setq marked3 nil))))
2455 (if (and marked1 marked2 marked3)
2456 (cond ((eq action ?h)
2457 (ediff-mark-session-for-hiding elt 'mark))
2459 (ediff-mark-session-for-operation elt 'mark))
2461 (setq list (cdr list)))
2462 (message "Comparing files... Done"))
2463 (setq ediff-recurse-to-subdirectories nil)
2464 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2466 ;; mark files 1 and 2 as equal, if they are.
2467 ;; returns t, if something was marked
2468 (defun ediff-mark-if-equal (fileinfo1 fileinfo2)
2469 (let ((f1 (car fileinfo1))
2470 (f2 (car fileinfo2)))
2471 (if (and (stringp f1) (stringp f2) (ediff-same-contents f1 f2))
2473 (ediff-set-file-eqstatus fileinfo1 t)
2474 (ediff-set-file-eqstatus fileinfo2 t)
2481 ;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
2482 ;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
2483 ;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
2486 ;;; ediff-mult.el ends here