Crunch some deleted functions.
[emacs.git] / lisp / ediff-mult.el
blobebbfb1ce1c74d2122aa5061e49b97f006ef52a12
1 ;;; ediff-mult.el --- support for multi-file/multi-buffer processing in Ediff
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
4 ;; 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6 ;; 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/>.
23 ;;; Commentary:
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))
43 ;; (...) ...)
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
60 ;; found.
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.
103 ;;; Code:
106 (provide 'ediff-mult)
108 (defgroup ediff-mult nil
109 "Multi-file and multi-buffer processing in Ediff."
110 :prefix "ediff-"
111 :group 'ediff)
114 ;; compiler pacifier
115 (eval-when-compile
116 (require 'ediff-ptch)
117 (require 'ediff))
118 ;; end pacifier
120 (require 'ediff-init)
122 ;; meta-buffer
123 (ediff-defvar-local ediff-meta-buffer nil "")
124 (ediff-defvar-local ediff-parent-meta-buffer nil "")
125 ;; the registry buffer
126 (defvar ediff-registry-buffer nil)
128 (defconst ediff-meta-buffer-brief-message "Ediff Session Group Panel: %s
130 Type ? to show useful commands in this buffer
134 (defconst ediff-meta-buffer-verbose-message "Ediff Session Group Panel: %s
136 Useful commands (type ? to hide them and free up screen):
137 button2, v, or RET over session record: start that Ediff session
138 M:\tin sessions invoked from here, brings back this group panel
139 R:\tdisplay the registry of active Ediff sessions
140 h:\tmark session for hiding (toggle)
141 x:\thide marked sessions; with prefix arg: unhide
142 m:\tmark session for a non-hiding operation (toggle)
143 uh/um:\tunmark all sessions marked for hiding/operation
144 n,SPC:\tnext session
145 p,DEL:\tprevious session
146 E:\tbrowse Ediff on-line manual
147 T:\ttoggle truncation of long file names
148 q:\tquit this session group
151 (ediff-defvar-local ediff-meta-buffer-map nil
152 "The keymap for the meta buffer.")
153 (defvar ediff-dir-diffs-buffer-map (make-sparse-keymap)
154 "The keymap to be installed in the buffer showing differences between
155 directories.")
157 ;; Variable specifying the action to take when the use invokes ediff in the
158 ;; meta buffer. This is usually ediff-registry-action or ediff-filegroup-action
159 (ediff-defvar-local ediff-meta-action-function nil "")
160 ;; Tells ediff-update-meta-buffer how to redraw it
161 (ediff-defvar-local ediff-meta-redraw-function nil "")
162 ;; Tells ediff-filegroup-action and similar procedures how to invoke Ediff for
163 ;; the sessions in a given session group
164 (ediff-defvar-local ediff-session-action-function nil "")
166 (ediff-defvar-local ediff-metajob-name nil "")
168 ;; buffer used to collect custom diffs from individual sessions in the group
169 (ediff-defvar-local ediff-meta-diff-buffer nil "")
171 ;; t means recurse into subdirs when deciding which files have same contents
172 (ediff-defvar-local ediff-recurse-to-subdirectories nil "")
174 ;; history var to use for filtering groups of files
175 (defvar ediff-filtering-regexp-history nil "")
177 (defcustom ediff-default-filtering-regexp nil
178 "The default regular expression used as a filename filter in multifile comparisons.
179 Should be a sexp. For instance (car ediff-filtering-regexp-history) or nil."
180 :type 'sexp
181 :group 'ediff-mult)
183 ;; This has the form ((meta-buf regexp dir1 dir2 dir3 merge-auto-store-dir)
184 ;; (ctl-buf session-status (file1 . eq-status) (file2 . eq-status) (file3
185 ;; . eq-status)) (ctl-buf session-status (file1 . eq-status) (file2
186 ;; . eq-status)) ...)
187 ;; If ctl-buf is nil, the file-pair hasn't processed yet. If it is
188 ;; killed-buffer object, the file pair has been processed. If it is a live
189 ;; buffer, this means ediff is still working on the pair.
190 ;; Eq-status of a file is t if the file equals some other file in the same
191 ;; group.
192 (ediff-defvar-local ediff-meta-list nil "")
194 (ediff-defvar-local ediff-meta-session-number nil "")
197 ;; the difference list between directories in a directory session group
198 (ediff-defvar-local ediff-dir-difference-list nil "")
199 (ediff-defvar-local ediff-dir-diffs-buffer nil "")
201 ;; The registry of Ediff sessions. A list of control buffers.
202 (defvar ediff-session-registry nil)
204 (defcustom ediff-meta-truncate-filenames t
205 "If non-nil, truncate long file names in the session group buffers.
206 This can be toggled with `ediff-toggle-filename-truncation'."
207 :type 'boolean
208 :group 'ediff-mult)
210 (defcustom ediff-meta-mode-hook nil
211 "Hooks run just after setting up meta mode."
212 :type 'hook
213 :group 'ediff-mult)
215 (defcustom ediff-registry-setup-hook nil
216 "Hooks run just after the registry control panel is set up."
217 :type 'hook
218 :group 'ediff-mult)
220 (defcustom ediff-before-session-group-setup-hooks nil
221 "Hooks to run before Ediff arranges the window for group-level operations.
222 It is used by commands such as `ediff-directories'.
223 This hook can be used to save the previous window config, which can be restored
224 on `ediff-quit', `ediff-suspend', or `ediff-quit-session-group-hook'."
225 :type 'hook
226 :group 'ediff-hook)
227 (defcustom ediff-after-session-group-setup-hook nil
228 "Hooks run just after a meta-buffer controlling a session group, such as
229 ediff-directories, is run."
230 :type 'hook
231 :group 'ediff-mult)
232 (defcustom ediff-quit-session-group-hook nil
233 "Hooks run just before exiting a session group."
234 :type 'hook
235 :group 'ediff-mult)
236 (defcustom ediff-show-registry-hook nil
237 "Hooks run just after the registry buffer is shown."
238 :type 'hook
239 :group 'ediff-mult)
240 (defcustom ediff-show-session-group-hook '(delete-other-windows)
241 "Hooks run just after a session group buffer is shown."
242 :type 'hook
243 :group 'ediff-mult)
244 (defcustom ediff-meta-buffer-keymap-setup-hook nil
245 "Hooks run just after setting up the `ediff-meta-buffer-map'.
246 This keymap controls key bindings in the meta buffer and is a local variable.
247 This means that you can set different bindings for different kinds of meta
248 buffers."
249 :type 'hook
250 :group 'ediff-mult)
252 ;; Buffer holding the multi-file patch. Local to the meta buffer
253 (ediff-defvar-local ediff-meta-patchbufer nil "")
255 ;;; API for ediff-meta-list
257 ;; A meta-list is either ediff-meta-list, which contains a header and the list
258 ;; of ediff sessions or ediff-dir-difference-list, which is a header followed
259 ;; by the list of differences among the directories (i.e., files that are not
260 ;; in all directories). The header is the same in all meta lists, but the rest
261 ;; is different.
262 ;; Structure of the meta-list:
263 ;; (HEADER SESSION1 SESSION2 ...)
264 ;; HEADER: (GROUP-BUF REGEXP OBJA OBJB OBJC SAVE-DIR COMPARISON-FUNC)
265 ;; OBJA - first directory
266 ;; OBJB - second directory
267 ;; OBJC - third directory
268 ;; SESSION1/2/... are described below
269 ;; group buffer/regexp
270 (defsubst ediff-get-group-buffer (meta-list)
271 (nth 0 (car meta-list)))
273 (defsubst ediff-get-group-regexp (meta-list)
274 (nth 1 (car meta-list)))
275 ;; group objects
276 (defsubst ediff-get-group-objA (meta-list)
277 (nth 2 (car meta-list)))
278 (defsubst ediff-get-group-objB (meta-list)
279 (nth 3 (car meta-list)))
280 (defsubst ediff-get-group-objC (meta-list)
281 (nth 4 (car meta-list)))
282 (defsubst ediff-get-group-merge-autostore-dir (meta-list)
283 (nth 5 (car meta-list)))
284 (defsubst ediff-get-group-comparison-func (meta-list)
285 (nth 6 (car meta-list)))
287 ;; ELT is a session meta descriptor (what is being preserved as
288 ;; 'ediff-meta-info)
289 ;; The structure is: (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
290 ;; STATUS is ?I (hidden or invalid), ?* (marked for operation), ?H (hidden)
291 ;; nil (nothing)
292 ;; OBJA/B/C is (FILENAME EQSTATUS)
293 ;; EQSTATUS is ?= or nil (?= means that this file is equal to some other
294 ;; file in this session)
295 ;; session buffer
296 (defsubst ediff-get-session-buffer (elt)
297 (nth 0 elt))
298 (defsubst ediff-get-session-status (elt)
299 (nth 1 elt))
300 (defsubst ediff-set-session-status (session-info new-status)
301 (setcar (cdr session-info) new-status))
302 ;; session objects
303 (defsubst ediff-get-session-objA (elt)
304 (nth 2 elt))
305 (defsubst ediff-get-session-objB (elt)
306 (nth 3 elt))
307 (defsubst ediff-get-session-objC (elt)
308 (nth 4 elt))
309 ;; Take the "name" component of the object into acount. ObjA/C/B is of the form
310 ;; (name . equality-indicator)
311 (defsubst ediff-get-session-objA-name (elt)
312 (car (nth 2 elt)))
313 (defsubst ediff-get-session-objB-name (elt)
314 (car (nth 3 elt)))
315 (defsubst ediff-get-session-objC-name (elt)
316 (car (nth 4 elt)))
317 ;; equality indicators
318 (defsubst ediff-get-file-eqstatus (elt)
319 (nth 1 elt))
320 (defsubst ediff-set-file-eqstatus (elt value)
321 (setcar (cdr elt) value))
323 ;; Create a new element for the meta list out of obj1/2/3, which usually are
324 ;; files
326 ;; The first nil in such an element is later replaced with the session buffer.
327 ;; The second nil is reserved for session status.
329 ;; Also, session objects A/B/C are turned into lists of the form (obj nil).
330 ;; This nil is a placeholder for eq-indicator. It is either nil or =.
331 ;; If it is discovered that this file is = to some other
332 ;; file in the same session, eq-indicator is changed to `='.
333 ;; Curently, the eq-indicator is used only for 2 and 3-file jobs.
334 (defun ediff-make-new-meta-list-element (obj1 obj2 obj3)
335 (list nil nil (list obj1 nil) (list obj2 nil) (list obj3 nil)))
337 ;; Constructs a meta list header.
338 ;; OBJA, OBJB, OBJC are usually directories involved, but can be different for
339 ;; different jobs. For instance, multifile patch has only OBJA, which is the
340 ;; patch buffer.
341 (defun ediff-make-new-meta-list-header (regexp
342 objA objB objC
343 merge-auto-store-dir
344 comparison-func)
345 (list regexp objA objB objC merge-auto-store-dir comparison-func))
347 ;; The activity marker is either or + (active session, i.e., ediff is currently
348 ;; run in it), or - (finished session, i.e., we've ran ediff in it and then
349 ;; exited). Return nil, if session is neither active nor finished
350 (defun ediff-get-session-activity-marker (session)
351 (let ((session-buf (ediff-get-session-buffer session)))
352 (cond ((null session-buf) nil) ; virgin session
353 ((ediff-buffer-live-p session-buf) ?+) ;active session
354 (t ?-))))
356 ;; checks if the session is a meta session
357 (defun ediff-meta-session-p (session-info)
358 (and (stringp (ediff-get-session-objA-name session-info))
359 (file-directory-p (ediff-get-session-objA-name session-info))
360 (stringp (ediff-get-session-objB-name session-info))
361 (file-directory-p (ediff-get-session-objB-name session-info))
362 (if (stringp (ediff-get-session-objC-name session-info))
363 (file-directory-p (ediff-get-session-objC-name session-info)) t)))
366 (ediff-defvar-local ediff-verbose-help-enabled nil
367 "If t, display redundant help in ediff-directories and other meta buffers.
368 Toggled by ediff-toggle-verbose-help-meta-buffer" )
370 ;; Toggle verbose help in meta-buffers
371 ;; TODO: Someone who understands all this can make it better.
372 (defun ediff-toggle-verbose-help-meta-buffer ()
373 "Toggle showing tediously verbose help in meta buffers."
374 (interactive)
375 (setq ediff-verbose-help-enabled (not ediff-verbose-help-enabled))
376 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
378 ;; set up the keymap in the meta buffer
379 (defun ediff-setup-meta-map ()
380 (setq ediff-meta-buffer-map (make-sparse-keymap))
381 (suppress-keymap ediff-meta-buffer-map)
382 (define-key ediff-meta-buffer-map "?" 'ediff-toggle-verbose-help-meta-buffer)
383 (define-key ediff-meta-buffer-map "q" 'ediff-quit-meta-buffer)
384 (define-key ediff-meta-buffer-map "T" 'ediff-toggle-filename-truncation)
385 (define-key ediff-meta-buffer-map "R" 'ediff-show-registry)
386 (define-key ediff-meta-buffer-map "E" 'ediff-documentation)
387 (define-key ediff-meta-buffer-map "v" ediff-meta-action-function)
388 (define-key ediff-meta-buffer-map "\C-m" ediff-meta-action-function)
389 (define-key ediff-meta-buffer-map " " 'ediff-next-meta-item)
390 (define-key ediff-meta-buffer-map "n" 'ediff-next-meta-item)
391 (define-key ediff-meta-buffer-map "\C-?" 'ediff-previous-meta-item)
392 (define-key ediff-meta-buffer-map "p" 'ediff-previous-meta-item)
393 (define-key ediff-meta-buffer-map [delete] 'ediff-previous-meta-item)
394 (define-key ediff-meta-buffer-map [backspace] 'ediff-previous-meta-item)
395 (or (ediff-one-filegroup-metajob)
396 (progn
397 (define-key ediff-meta-buffer-map "=" nil)
398 (define-key ediff-meta-buffer-map "==" 'ediff-meta-mark-equal-files)
399 (define-key ediff-meta-buffer-map "=m" 'ediff-meta-mark-equal-files)
400 (define-key ediff-meta-buffer-map "=h" 'ediff-meta-mark-equal-files)))
401 (if ediff-no-emacs-help-in-control-buffer
402 (define-key ediff-meta-buffer-map "\C-h" 'ediff-previous-meta-item))
403 (if (featurep 'emacs)
404 (define-key ediff-meta-buffer-map [mouse-2] ediff-meta-action-function)
405 (define-key ediff-meta-buffer-map [button2] ediff-meta-action-function))
407 (use-local-map ediff-meta-buffer-map)
408 ;; modify ediff-meta-buffer-map here
409 (run-hooks 'ediff-meta-buffer-keymap-setup-hook))
412 (defun ediff-meta-mode ()
413 "This mode controls all operations on Ediff session groups.
414 It is entered through one of the following commands:
415 `ediff-directories'
416 `edirs'
417 `ediff-directories3'
418 `edirs3'
419 `ediff-merge-directories'
420 `edirs-merge'
421 `ediff-merge-directories-with-ancestor'
422 `edirs-merge-with-ancestor'
423 `ediff-directory-revisions'
424 `edir-revisions'
425 `ediff-merge-directory-revisions'
426 `edir-merge-revisions'
427 `ediff-merge-directory-revisions-with-ancestor'
428 `edir-merge-revisions-with-ancestor'
430 Commands:
431 \\{ediff-meta-buffer-map}"
432 (kill-all-local-variables)
433 (setq major-mode 'ediff-meta-mode)
434 (setq mode-name "MetaEdiff")
435 ;; don't use run-mode-hooks here!
436 (run-hooks 'ediff-meta-mode-hook))
439 ;; the keymap for the buffer showing directory differences
440 (suppress-keymap ediff-dir-diffs-buffer-map)
441 (define-key ediff-dir-diffs-buffer-map "q" 'ediff-bury-dir-diffs-buffer)
442 (define-key ediff-dir-diffs-buffer-map " " 'next-line)
443 (define-key ediff-dir-diffs-buffer-map "n" 'next-line)
444 (define-key ediff-dir-diffs-buffer-map "\C-?" 'previous-line)
445 (define-key ediff-dir-diffs-buffer-map "p" 'previous-line)
446 (define-key ediff-dir-diffs-buffer-map "C" 'ediff-dir-diff-copy-file)
447 (if (featurep 'emacs)
448 (define-key ediff-dir-diffs-buffer-map [mouse-2] 'ediff-dir-diff-copy-file)
449 (define-key ediff-dir-diffs-buffer-map [button2] 'ediff-dir-diff-copy-file))
450 (define-key ediff-dir-diffs-buffer-map [delete] 'previous-line)
451 (define-key ediff-dir-diffs-buffer-map [backspace] 'previous-line)
453 (defun ediff-next-meta-item (count)
454 "Move to the next item in Ediff registry or session group buffer.
455 Moves in circular fashion. With numeric prefix arg, skip this many items."
456 (interactive "p")
457 (or count (setq count 1))
458 (let (overl)
459 (while (< 0 count)
460 (setq count (1- count))
461 (ediff-next-meta-item1)
462 (setq overl (ediff-get-meta-overlay-at-pos (point)))
463 ;; skip invisible ones
464 (while (and overl (ediff-overlay-get overl 'invisible))
465 (ediff-next-meta-item1)
466 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
468 ;; Move to the next meta item
469 (defun ediff-next-meta-item1 ()
470 (let (pos)
471 (setq pos (ediff-next-meta-overlay-start (point)))
472 (if pos (goto-char pos))
473 (if (eq ediff-metajob-name 'ediff-registry)
474 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
475 (search-forward "*Ediff" nil t))
476 (skip-chars-backward "a-zA-Z*"))
477 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
478 (backward-char 1)))))
481 (defun ediff-previous-meta-item (count)
482 "Move to the previous item in Ediff registry or session group buffer.
483 Moves in circular fashion. With numeric prefix arg, skip this many items."
484 (interactive "p")
485 (or count (setq count 1))
486 (let (overl)
487 (while (< 0 count)
488 (setq count (1- count))
489 (ediff-previous-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-previous-meta-item1)
494 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
496 (defun ediff-previous-meta-item1 ()
497 (let (pos)
498 (setq pos (ediff-previous-meta-overlay-start (point)))
499 ;;; ;; skip deleted
500 ;;; (while (ediff-get-session-status
501 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
502 ;;; (setq pos (ediff-previous-meta-overlay-start pos)))
504 (if pos (goto-char pos))
505 (if (eq ediff-metajob-name 'ediff-registry)
506 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
507 (search-forward "*Ediff" nil t))
508 (skip-chars-backward "a-zA-Z*"))
509 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
510 (backward-char 1)))
513 (defsubst ediff-add-slash-if-directory (dir file)
514 (if (file-directory-p (concat dir file))
515 (file-name-as-directory file)
516 file))
518 (defun ediff-toggle-filename-truncation ()
519 "Toggle truncation of long file names in session group buffers.
520 Set `ediff-meta-truncate-filenames' variable if you want to change the default
521 behavior."
522 (interactive)
523 (setq ediff-meta-truncate-filenames (not ediff-meta-truncate-filenames))
524 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
527 ;; These are used to encode membership of files in directory1/2/3
528 ;; Membership code of a file is a product of codes for the directories where
529 ;; this file is in
530 (defvar ediff-membership-code1 2)
531 (defvar ediff-membership-code2 3)
532 (defvar ediff-membership-code3 5)
533 (defvar ediff-product-of-memcodes (* ediff-membership-code1
534 ediff-membership-code2
535 ediff-membership-code3))
537 ;; DIR1, DIR2, DIR3 are directories. DIR3 can be nil.
538 ;; OUTPUT-DIR is a directory for auto-storing the results of merge jobs.
539 ;; Can be nil.
540 ;; REGEXP is nil or a filter regexp; only file names that match the regexp
541 ;; are considered.
542 ;; If a file is a directory in dir1 but not dir2 (or vice versa), it is not
543 ;; included in the intersection. However, a regular file that is a dir in dir3
544 ;; is included, since dir3 files are supposed to be ancestors for merging.
545 ;; If COMPARISON-FUNC is given, use it. Otherwise, use string=
547 ;; Returns a list of the form:
548 ;; (COMMON-PART DIFF-LIST)
549 ;; COMMON-PART is car and DIFF-LIST is cdr.
551 ;; COMMON-PART is of the form:
552 ;; (META-HEADER (f1 f2 f3) (f1 f2 f3) ...)
553 ;; f3 can be nil if intersecting only 2 directories.
554 ;; Each triple (f1 f2 f3) represents the files to be compared in the
555 ;; corresponding ediff subsession.
557 ;; DIFF-LIST is of the form:
558 ;; (META-HEADER (file . num) (file . num)...)
559 ;; where num encodes the set of dirs where the file is found:
560 ;; 2 - only dir1; 3 - only dir2; 5 - only dir3; 6 - dir1&2; 10 - dir1&3; etc.
561 ;; META-HEADER:
562 ;; Contains the meta info about this ediff operation
563 ;; (regexp dir1 dir2 dir3 merge-auto-store-dir comparison-func)
564 ;; Later the meta-buffer is prepended to this list.
566 ;; Some operations might use a different meta header. For instance,
567 ;; ediff-multifile-patch doesn't have dir2 and dir3, and regexp,
568 ;; comparison-func don't apply.
570 (defun ediff-intersect-directories (jobname
571 regexp dir1 dir2
572 &optional
573 dir3 merge-autostore-dir comparison-func)
574 (setq comparison-func (or comparison-func 'string=))
575 (let (lis1 lis2 lis3 common auxdir1 auxdir2 auxdir3 common-part difflist)
577 (setq auxdir1 (file-name-as-directory dir1)
578 lis1 (directory-files auxdir1 nil regexp)
579 lis1 (delete "." lis1)
580 lis1 (delete ".." lis1)
581 lis1 (mapcar
582 (lambda (elt)
583 (ediff-add-slash-if-directory auxdir1 elt))
584 lis1)
585 auxdir2 (file-name-as-directory dir2)
586 lis2 (directory-files auxdir2 nil regexp)
587 lis2 (delete "." lis2)
588 lis2 (delete ".." lis2)
589 lis2 (mapcar
590 (lambda (elt)
591 (ediff-add-slash-if-directory auxdir2 elt))
592 lis2))
594 (if (stringp dir3)
595 (setq auxdir3 (file-name-as-directory dir3)
596 lis3 (directory-files auxdir3 nil regexp)
597 lis3 (delete "." lis3)
598 lis3 (delete ".." lis3)
599 lis3 (mapcar
600 (lambda (elt)
601 (ediff-add-slash-if-directory auxdir3 elt))
602 lis3)))
604 (if (ediff-nonempty-string-p merge-autostore-dir)
605 (setq merge-autostore-dir
606 (file-name-as-directory merge-autostore-dir)))
607 (setq common (ediff-intersection lis1 lis2 comparison-func))
609 ;; In merge with ancestor jobs, we don't intersect with lis3.
610 ;; If there is no ancestor, we'll offer to merge without the ancestor.
611 ;; So, we intersect with lis3 only when we are doing 3-way file comparison
612 (if (and lis3 (ediff-comparison-metajob3 jobname))
613 (setq common (ediff-intersection common lis3 comparison-func)))
615 ;; copying is needed because sort sorts via side effects
616 (setq common (sort (ediff-copy-list common) 'string-lessp))
618 ;; compute difference list
619 (setq difflist (ediff-set-difference
620 (ediff-union (ediff-union lis1 lis2 comparison-func)
621 lis3
622 comparison-func)
623 common
624 comparison-func)
625 difflist (delete "." difflist)
626 ;; copying is needed because sort sorts via side effects
627 difflist (sort (ediff-copy-list (delete ".." difflist))
628 'string-lessp))
630 (setq difflist (mapcar (lambda (elt) (cons elt 1)) difflist))
632 ;; check for files belonging to lis1/2/3
633 ;; Each elt is of the norm (file . number)
634 ;; Number encodes the directories to which file belongs.
635 ;; It is a product of a subset of ediff-membership-code1=2,
636 ;; ediff-membership-code2=3, and ediff-membership-code3=5.
637 ;; If file belongs to dir 1 only, the membership code is 2.
638 ;; If it is in dir1 and dir3, then the membership code is 2*5=10;
639 ;; if it is in dir1 and dir2, then the membership code is 2*3=6, etc.
640 (mapc (lambda (elt)
641 (if (member (car elt) lis1)
642 (setcdr elt (* (cdr elt) ediff-membership-code1)))
643 (if (member (car elt) lis2)
644 (setcdr elt (* (cdr elt) ediff-membership-code2)))
645 (if (member (car elt) lis3)
646 (setcdr elt (* (cdr elt) ediff-membership-code3)))
648 difflist)
649 (setq difflist (cons
650 ;; diff metalist header
651 (ediff-make-new-meta-list-header regexp
652 auxdir1 auxdir2 auxdir3
653 merge-autostore-dir
654 comparison-func)
655 difflist))
657 (setq common-part
658 (cons
659 ;; metalist header
660 (ediff-make-new-meta-list-header regexp
661 auxdir1 auxdir2 auxdir3
662 merge-autostore-dir
663 comparison-func)
664 (mapcar
665 (lambda (elt)
666 (ediff-make-new-meta-list-element
667 (expand-file-name (concat auxdir1 elt))
668 (expand-file-name (concat auxdir2 elt))
669 (if lis3
670 (progn
671 ;; The following is done because: In merging with
672 ;; ancestor, we don't intersect with lis3. So, it is
673 ;; possible that elt is a file in auxdir1/2 but a
674 ;; directory in auxdir3 Or elt may not exist in auxdir3 at
675 ;; all. In the first case, we add a slash at the end. In
676 ;; the second case, we insert nil.
677 (setq elt (ediff-add-slash-if-directory auxdir3 elt))
678 (if (file-exists-p (concat auxdir3 elt))
679 (expand-file-name (concat auxdir3 elt)))))))
680 common)))
681 ;; return result
682 (cons common-part difflist)
685 ;; find directory files that are under revision. Include subdirectories, since
686 ;; we may visit them recursively. DIR1 is the directory to inspect.
687 ;; MERGE-AUTOSTORE-DIR is the directory where to auto-store the results of
688 ;; merges. Can be nil.
689 (defun ediff-get-directory-files-under-revision (jobname
690 regexp dir1
691 &optional merge-autostore-dir)
692 (let (lis1 elt common auxdir1)
693 (setq auxdir1 (file-name-as-directory dir1)
694 lis1 (directory-files auxdir1 nil regexp))
696 (if (ediff-nonempty-string-p merge-autostore-dir)
697 (setq merge-autostore-dir
698 (file-name-as-directory merge-autostore-dir)))
700 (while lis1
701 (setq elt (car lis1)
702 lis1 (cdr lis1))
703 ;; take files under revision control
704 (cond ((file-directory-p (concat auxdir1 elt))
705 (setq common
706 (cons (ediff-add-slash-if-directory auxdir1 elt) common)))
707 ((and (featurep 'vc-hooks) (vc-backend (concat auxdir1 elt)))
708 (setq common (cons elt common)))
709 ;; The following two are needed only if vc-hooks isn't loaded.
710 ;; They won't recognize CVS files.
711 ((file-exists-p (concat auxdir1 elt ",v"))
712 (setq common (cons elt common)))
713 ((file-exists-p (concat auxdir1 "RCS/" elt ",v"))
714 (setq common (cons elt common)))
715 ) ; cond
716 ) ; while
718 (setq common (delete "./" common)
719 common (delete "../" common)
720 common (delete "RCS" common)
721 common (delete "CVS" common)
724 ;; copying is needed because sort sorts via side effects
725 (setq common (sort (ediff-copy-list common) 'string-lessp))
727 ;; return result
728 (cons
729 ;; header -- has 6 elements. Meta buffer is prepended later by
730 ;; ediff-prepare-meta-buffer
731 (ediff-make-new-meta-list-header regexp
732 auxdir1 nil nil
733 merge-autostore-dir nil)
734 (mapcar (lambda (elt) (ediff-make-new-meta-list-element
735 (expand-file-name (concat auxdir1 elt)) nil nil))
736 common))
740 ;; If file groups selected by patterns will ever be implemented, this
741 ;; comparison function might become useful.
742 ;;;; uses external variables PAT1 PAT2 to compare str1/2
743 ;;;; patterns must be of the form ???*???? where ??? are strings of chars
744 ;;;; containing no *.
745 ;;(defun ediff-pattern= (str1 str2)
746 ;; (let (pos11 pos12 pos21 pos22 len1 len2)
747 ;; (setq pos11 0
748 ;; len (length epat1)
749 ;; pos12 len)
750 ;; (while (and (< pos11 len) (not (= (aref epat1 pos11) ?*)))
751 ;; (setq pos11 (1+ pos11)))
752 ;; (while (and (> pos12 0) (not (= (aref epat1 (1- pos12)) ?*)))
753 ;; (setq pos12 (1- pos12)))
755 ;; (setq pos21 0
756 ;; len (length epat2)
757 ;; pos22 len)
758 ;; (while (and (< pos21 len) (not (= (aref epat2 pos21) ?*)))
759 ;; (setq pos21 (1+ pos21)))
760 ;; (while (and (> pos22 0) (not (= (aref epat2 (1- pos22)) ?*)))
761 ;; (setq pos22 (1- pos22)))
763 ;; (if (and (> (length str1) pos12) (>= pos12 pos11) (> pos11 -1)
764 ;; (> (length str2) pos22) (>= pos22 pos21) (> pos21 -1))
765 ;; (string= (substring str1 pos11 pos12)
766 ;; (substring str2 pos21 pos22)))
767 ;; ))
770 ;; Prepare meta-buffer in accordance with the argument-function and
771 ;; redraw-function. Must return the created meta-buffer.
772 (defun ediff-prepare-meta-buffer (action-func meta-list
773 meta-buffer-name redraw-function
774 jobname &optional startup-hooks)
775 (let* ((meta-buffer-name
776 (ediff-unique-buffer-name meta-buffer-name "*"))
777 (meta-buffer (get-buffer-create meta-buffer-name)))
778 (ediff-with-current-buffer meta-buffer
780 ;; comes first
781 (ediff-meta-mode)
783 (setq ediff-meta-action-function action-func
784 ediff-meta-redraw-function redraw-function
785 ediff-metajob-name jobname
786 ediff-meta-buffer meta-buffer)
788 ;; comes after ediff-meta-action-function is set
789 (ediff-setup-meta-map)
791 (if (eq ediff-metajob-name 'ediff-registry)
792 (progn
793 (setq ediff-registry-buffer meta-buffer
794 ediff-meta-list meta-list)
795 ;; this func is used only from registry buffer, not from other
796 ;; meta-buffs.
797 (define-key
798 ediff-meta-buffer-map "M" 'ediff-show-meta-buff-from-registry))
799 ;; Initialize the meta list -- we don't do this for registry.
800 (setq ediff-meta-list
801 ;; add meta-buffer to the list header
802 (cons (cons meta-buffer (car meta-list))
803 (cdr meta-list))))
805 (or (eq meta-buffer ediff-registry-buffer)
806 (setq ediff-session-registry
807 (cons meta-buffer ediff-session-registry)))
809 ;; redraw-function uses ediff-meta-list
810 (funcall redraw-function ediff-meta-list)
812 ;; set read-only/non-modified
813 (setq buffer-read-only t)
814 (set-buffer-modified-p nil)
816 (run-hooks 'startup-hooks)
818 ;; Arrange to show directory contents differences
819 ;; Must be after run startup-hooks, since ediff-dir-difference-list is
820 ;; set inside these hooks
821 (if (eq action-func 'ediff-filegroup-action)
822 (progn
823 ;; put meta buffer in (car ediff-dir-difference-list)
824 (setq ediff-dir-difference-list
825 (cons (cons meta-buffer (car ediff-dir-difference-list))
826 (cdr ediff-dir-difference-list)))
828 (or (ediff-one-filegroup-metajob jobname)
829 (ediff-draw-dir-diffs ediff-dir-difference-list))
830 (define-key
831 ediff-meta-buffer-map "h" 'ediff-mark-for-hiding-at-pos)
832 (define-key ediff-meta-buffer-map "x" 'ediff-hide-marked-sessions)
833 (define-key
834 ediff-meta-buffer-map "m" 'ediff-mark-for-operation-at-pos)
835 (define-key ediff-meta-buffer-map "u" nil)
836 (define-key
837 ediff-meta-buffer-map "um" 'ediff-unmark-all-for-operation)
838 (define-key
839 ediff-meta-buffer-map "uh" 'ediff-unmark-all-for-hiding)
840 (cond ((ediff-collect-diffs-metajob jobname)
841 (define-key
842 ediff-meta-buffer-map "P" 'ediff-collect-custom-diffs))
843 ((ediff-patch-metajob jobname)
844 (define-key
845 ediff-meta-buffer-map "P" 'ediff-meta-show-patch)))
846 (define-key ediff-meta-buffer-map "^" 'ediff-up-meta-hierarchy)
847 (define-key ediff-meta-buffer-map "D" 'ediff-show-dir-diffs)))
849 (if (eq ediff-metajob-name 'ediff-registry)
850 (run-hooks 'ediff-registry-setup-hook)
851 (run-hooks 'ediff-after-session-group-setup-hook))
852 ) ; eval in meta-buffer
853 meta-buffer))
855 ;; Insert the activity marker for session SESSION in the meta buffer at point
856 ;; The activity marker is either SPC (untouched session), or + (active session,
857 ;; i.e., ediff is currently run in it), or - (finished session, i.e., we've ran
858 ;; ediff in it and then exited)
859 (defun ediff-insert-session-activity-marker-in-meta-buffer (session)
860 (insert
861 (cond ((ediff-get-session-activity-marker session))
862 ;; virgin session
863 (t " "))))
865 ;; Insert session status at point. Status is either ?H (marked for hiding), or
866 ;; ?I (hidden or invalid), or ?* (meaning marked for an operation; currently,
867 ;; such op can only be checking for equality)), or SPC (meaning neither marked
868 ;; nor invalid)
869 (defun ediff-insert-session-status-in-meta-buffer (session)
870 (insert
871 (cond ((ediff-get-session-status session)) ; session has status: ?H, ?I, ?*
872 ;; normal session, no marks or hidings
873 (t " "))))
875 ;; If NEW-MARKER is non-nil, use it to substitute the current activity marker
876 ;; in the meta buffer. If nil, use SPC
877 (defun ediff-replace-session-activity-marker-in-meta-buffer (point new-marker)
878 (let* ((overl (ediff-get-meta-overlay-at-pos point))
879 (session-info (ediff-overlay-get overl 'ediff-meta-info))
880 (activity-marker (ediff-get-session-activity-marker session-info))
881 buffer-read-only)
882 (or new-marker activity-marker (setq new-marker ?\s))
883 (goto-char (ediff-overlay-start overl))
884 (if (eq (char-after (point)) new-marker)
885 () ; if marker shown in buffer is the same as new-marker, do nothing
886 (insert new-marker)
887 (delete-char 1)
888 (set-buffer-modified-p nil))))
890 ;; If NEW-STATUS is non-nil, use it to substitute the current status marker in
891 ;; the meta buffer. If nil, use SPC
892 (defun ediff-replace-session-status-in-meta-buffer (point new-status)
893 (let* ((overl (ediff-get-meta-overlay-at-pos point))
894 (session-info (ediff-overlay-get overl 'ediff-meta-info))
895 (status (ediff-get-session-status session-info))
896 buffer-read-only)
897 (setq new-status (or new-status status ?\s))
898 (goto-char (ediff-overlay-start overl))
899 (forward-char 1) ; status is the second char in session record
900 (if (eq (char-after (point)) new-status)
901 () ; if marker shown in buffer is the same as new-marker, do nothing
902 (insert new-status)
903 (delete-char 1)
904 (set-buffer-modified-p nil))))
906 ;; insert all file info in meta buffer for a given session
907 (defun ediff-insert-session-info-in-meta-buffer (session-info sessionNum)
908 (let ((f1 (ediff-get-session-objA session-info))
909 (f2 (ediff-get-session-objB session-info))
910 (f3 (ediff-get-session-objC session-info))
911 (pt (point))
912 (hidden (eq (ediff-get-session-status session-info) ?I)))
913 ;; insert activity marker, i.e., SPC, - or +
914 (ediff-insert-session-activity-marker-in-meta-buffer session-info)
915 ;; insert session status, i.e., *, H
916 (ediff-insert-session-status-in-meta-buffer session-info)
917 (insert " Session " (int-to-string sessionNum) ":\n")
918 (ediff-meta-insert-file-info1 f1)
919 (ediff-meta-insert-file-info1 f2)
920 (ediff-meta-insert-file-info1 f3)
921 (ediff-set-meta-overlay pt (point) session-info sessionNum hidden)))
924 ;; this is a setup function for ediff-directories
925 ;; must return meta-buffer
926 (defun ediff-redraw-directory-group-buffer (meta-list)
927 ;; extract directories
928 (let ((meta-buf (ediff-get-group-buffer meta-list))
929 (empty t)
930 (sessionNum 0)
931 regexp elt merge-autostore-dir
932 point tmp-list buffer-read-only)
933 (ediff-with-current-buffer meta-buf
934 (setq point (point))
935 (erase-buffer)
936 ;; delete phony overlays that used to represent sessions before the buff
937 ;; was redrawn
938 (if (featurep 'xemacs)
939 (map-extents 'delete-extent)
940 (mapc 'delete-overlay (overlays-in 1 1)))
942 (setq regexp (ediff-get-group-regexp meta-list)
943 merge-autostore-dir
944 (ediff-get-group-merge-autostore-dir meta-list))
946 (if ediff-verbose-help-enabled
947 (progn
948 (insert (format ediff-meta-buffer-verbose-message
949 (ediff-abbrev-jobname ediff-metajob-name)))
951 (cond ((ediff-collect-diffs-metajob)
952 (insert
953 " P:\tcollect custom diffs of all marked sessions\n"))
954 ((ediff-patch-metajob)
955 (insert
956 " P:\tshow patch appropriately for the context (session or group)\n")))
957 (insert
958 " ^:\tshow parent session group\n")
959 (or (ediff-one-filegroup-metajob)
960 (insert
961 " D:\tshow differences among directories\n"
962 " ==:\tfor each session, show which files are identical\n"
963 " =h:\tlike ==, but also marks sessions for hiding\n"
964 " =m:\tlike ==, but also marks sessions for operation\n\n")))
965 (insert (format ediff-meta-buffer-brief-message
966 (ediff-abbrev-jobname ediff-metajob-name))))
968 (insert "\n")
969 (if (and (stringp regexp) (> (length regexp) 0))
970 (insert
971 (format "*** Filter-through regular expression: %s\n" regexp)))
972 (ediff-insert-dirs-in-meta-buffer meta-list)
973 (if (and ediff-autostore-merges (ediff-merge-metajob)
974 (ediff-nonempty-string-p merge-autostore-dir))
975 (insert (format
976 "\nMerge results are automatically stored in:\n\t%s\n"
977 merge-autostore-dir)))
978 (insert "\n
979 Size Last modified Name
980 ----------------------------------------------
984 ;; discard info on directories and regexp
985 (setq meta-list (cdr meta-list)
986 tmp-list meta-list)
987 (while (and tmp-list empty)
988 (if (and (car tmp-list)
989 (not (eq (ediff-get-session-status (car tmp-list)) ?I)))
990 (setq empty nil))
991 (setq tmp-list (cdr tmp-list)))
993 (if empty
994 (insert
995 " ****** ****** This session group has no members\n"))
997 ;; now organize file names like this:
998 ;; use-mark sizeA dateA sizeB dateB filename
999 ;; make sure directories are displayed with a trailing slash.
1000 (while meta-list
1001 (setq elt (car meta-list)
1002 meta-list (cdr meta-list)
1003 sessionNum (1+ sessionNum))
1004 (if (eq (ediff-get-session-status elt) ?I)
1006 (ediff-insert-session-info-in-meta-buffer elt sessionNum)))
1007 (set-buffer-modified-p nil)
1008 (goto-char point)
1009 meta-buf)))
1011 (defun ediff-update-markers-in-dir-meta-buffer (meta-list)
1012 (let ((meta-buf (ediff-get-group-buffer meta-list))
1013 session-info point overl buffer-read-only)
1014 (ediff-with-current-buffer meta-buf
1015 (setq point (point))
1016 (goto-char (point-min))
1017 (ediff-next-meta-item1)
1018 (while (not (bobp))
1019 (setq session-info (ediff-get-meta-info meta-buf (point) 'no-error)
1020 overl (ediff-get-meta-overlay-at-pos (point)))
1021 (if session-info
1022 (progn
1023 (cond ((eq (ediff-get-session-status session-info) ?I)
1024 ;; Do hiding
1025 (if overl (ediff-overlay-put overl 'invisible t)))
1026 ((and (eq (ediff-get-session-status session-info) ?H)
1027 overl (ediff-overlay-get overl 'invisible))
1028 ;; Do unhiding
1029 (ediff-overlay-put overl 'invisible nil))
1030 (t (ediff-replace-session-activity-marker-in-meta-buffer
1031 (point)
1032 (ediff-get-session-activity-marker session-info))
1033 (ediff-replace-session-status-in-meta-buffer
1034 (point)
1035 (ediff-get-session-status session-info))))))
1036 (ediff-next-meta-item1) ; advance to the next item
1037 ) ; end while
1038 (set-buffer-modified-p nil)
1039 (goto-char point))
1040 meta-buf))
1042 (defun ediff-update-session-marker-in-dir-meta-buffer (session-num)
1043 (let (buffer-meta-overlays session-info overl buffer-read-only)
1044 (setq overl
1045 (if (featurep 'xemacs)
1046 (map-extents
1047 (lambda (ext maparg)
1048 (if (and
1049 (ediff-overlay-get ext 'ediff-meta-info)
1050 (eq (ediff-overlay-get ext 'ediff-meta-session-number)
1051 session-num))
1052 ext)))
1053 ;; Emacs doesn't have map-extents, so try harder
1054 ;; Splice overlay lists to get all buffer overlays
1055 (setq buffer-meta-overlays (overlay-lists)
1056 buffer-meta-overlays (append (car buffer-meta-overlays)
1057 (cdr buffer-meta-overlays)))
1058 (car
1059 (delq nil
1060 (mapcar
1061 (lambda (overl)
1062 (if (and
1063 (ediff-overlay-get overl 'ediff-meta-info)
1064 (eq (ediff-overlay-get
1065 overl 'ediff-meta-session-number)
1066 session-num))
1067 overl))
1068 buffer-meta-overlays)))))
1069 (or overl
1070 (error
1071 "Bug in ediff-update-session-marker-in-dir-meta-buffer: no overlay with given number %S"
1072 session-num))
1073 (setq session-info (ediff-overlay-get overl 'ediff-meta-info))
1074 (goto-char (ediff-overlay-start overl))
1075 (ediff-replace-session-activity-marker-in-meta-buffer
1076 (point)
1077 (ediff-get-session-activity-marker session-info))
1078 (ediff-replace-session-status-in-meta-buffer
1079 (point)
1080 (ediff-get-session-status session-info)))
1081 (ediff-next-meta-item1))
1085 ;; Check if this is a problematic session.
1086 ;; Return nil if not. Otherwise, return symbol representing the problem
1087 ;; At present, problematic sessions occur only in -with-ancestor comparisons
1088 ;; when the ancestor is a directory rather than a file, or when there is no
1089 ;; suitable ancestor file in the ancestor directory
1090 (defun ediff-problematic-session-p (session)
1091 (let ((f1 (ediff-get-session-objA-name session))
1092 (f2 (ediff-get-session-objB-name session))
1093 (f3 (ediff-get-session-objC-name session)))
1094 (cond ((and (stringp f1) (not (file-directory-p f1))
1095 (stringp f2) (not (file-directory-p f2))
1096 ;; either invalid file name or a directory
1097 (or (not (stringp f3)) (file-directory-p f3))
1098 (ediff-ancestor-metajob))
1099 ;; more may be added later
1100 'ancestor-is-dir)
1101 (t nil))))
1103 (defun ediff-meta-insert-file-info1 (fileinfo)
1104 (let ((fname (car fileinfo))
1105 (feq (ediff-get-file-eqstatus fileinfo))
1106 (max-filename-width (if ediff-meta-truncate-filenames
1107 (- (window-width) 41)
1108 500))
1109 file-modtime file-size)
1110 (cond ((not (stringp fname)) (setq file-size -2)) ; file doesn't exits
1111 ((ediff-listable-file fname)
1112 (if (file-exists-p fname)
1113 ;; set real size and modtime
1114 (setq file-size (ediff-file-size fname)
1115 file-modtime (ediff-file-modtime fname))
1116 (setq file-size -2))) ; file doesn't exist
1117 ( t (setq file-size -1))) ; remote file
1118 (if (stringp fname)
1119 (insert
1120 (format
1121 "%s %s %-20s %s\n"
1122 (if feq "=" " ") ; equality indicator
1123 (format "%10s" (cond ((= file-size -1) "--")
1124 ((< file-size -1) "--")
1125 (t file-size)))
1126 (cond ((= file-size -1) "*remote file*")
1127 ((< file-size -1) "*file doesn't exist*")
1128 (t (ediff-format-date (decode-time file-modtime))))
1130 ;; dir names in meta lists have training slashes, so we just
1131 ;; abbreviate the file name, if file exists
1132 (if (and (not (stringp fname)) (< file-size -1))
1133 "-------" ; file doesn't exist
1134 (ediff-truncate-string-left
1135 (ediff-abbreviate-file-name fname)
1136 max-filename-width)))))))
1138 (defconst ediff-months '((1 . "Jan") (2 . "Feb") (3 . "Mar") (4 . "Apr")
1139 (5 . "May") (6 . "Jun") (7 . "Jul") (8 . "Aug")
1140 (9 . "Sep") (10 . "Oct") (11 . "Nov") (12 . "Dec"))
1141 "Months' associative array.")
1143 ;; returns 2char string
1144 (defsubst ediff-fill-leading-zero (num)
1145 (if (< num 10)
1146 (format "0%d" num)
1147 (number-to-string num)))
1149 ;; TIME is like the output of decode-time
1150 (defun ediff-format-date (time)
1151 (format "%s %2d %4d %s:%s:%s"
1152 (cdr (assoc (nth 4 time) ediff-months)) ; month
1153 (nth 3 time) ; day
1154 (nth 5 time) ; year
1155 (ediff-fill-leading-zero (nth 2 time)) ; hour
1156 (ediff-fill-leading-zero (nth 1 time)) ; min
1157 (ediff-fill-leading-zero (nth 0 time)) ; sec
1160 ;; Draw the directories
1161 (defun ediff-insert-dirs-in-meta-buffer (meta-list)
1162 (let* ((dir1 (ediff-abbreviate-file-name (ediff-get-group-objA meta-list)))
1163 (dir2 (ediff-get-group-objB meta-list))
1164 (dir2 (if (stringp dir2) (ediff-abbreviate-file-name dir2)))
1165 (dir3 (ediff-get-group-objC meta-list))
1166 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3))))
1167 (insert "*** Directory A: " dir1 "\n")
1168 (if dir2 (insert "*** Directory B: " dir2 "\n"))
1169 (if dir3 (insert "*** Directory C: " dir3 "\n"))
1170 (insert "\n")))
1172 (defun ediff-draw-dir-diffs (diff-list &optional buf-name)
1173 (if (null diff-list) (error "Lost difference info on these directories"))
1174 (setq buf-name
1175 (or buf-name
1176 (ediff-unique-buffer-name "*Ediff File Group Differences" "*")))
1177 (let* ((regexp (ediff-get-group-regexp diff-list))
1178 (dir1 (ediff-abbreviate-file-name (ediff-get-group-objA diff-list)))
1179 (dir2 (ediff-abbreviate-file-name (ediff-get-group-objB diff-list)))
1180 (dir3 (ediff-get-group-objC diff-list))
1181 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3)))
1182 (meta-buf (ediff-get-group-buffer diff-list))
1183 (underline (make-string 26 ?-))
1184 file membership-code saved-point
1185 buffer-read-only)
1186 ;; skip the directory part
1187 (setq diff-list (cdr diff-list))
1188 (setq ediff-dir-diffs-buffer (get-buffer-create buf-name))
1189 (ediff-with-current-buffer ediff-dir-diffs-buffer
1190 (setq saved-point (point))
1191 (use-local-map ediff-dir-diffs-buffer-map)
1192 (erase-buffer)
1193 (setq ediff-meta-buffer meta-buf)
1194 (insert "\t\t*** Directory Differences ***\n")
1195 (insert "
1196 Useful commands:
1197 C,button2: over file name -- copy this file to directory that doesn't have it
1198 q: hide this buffer
1199 n,SPC: next line
1200 p,DEL: previous line\n\n")
1202 (insert (format "\n*** Directory A: %s\n" dir1))
1203 (if dir2 (insert (format "*** Directory B: %s\n" dir2)))
1204 (if dir3 (insert (format "*** Directory C: %s\n" dir3)))
1205 (if (and (stringp regexp) (> (length regexp) 0))
1206 (insert
1207 (format "*** Filter-through regular expression: %s\n" regexp)))
1208 (insert "\n")
1209 (insert (format "\n%-27s%-26s" "Directory A" "Directory B"))
1210 (if dir3
1211 (insert (format " %-25s\n" "Directory C"))
1212 (insert "\n"))
1213 (insert (format "%s%s" underline underline))
1214 (if (stringp dir3)
1215 (insert (format "%s\n\n" underline))
1216 (insert "\n\n"))
1218 (if (null diff-list)
1219 (insert "\n\t*** No differences ***\n"))
1221 (while diff-list
1222 (setq file (car (car diff-list))
1223 membership-code (cdr (car diff-list))
1224 diff-list (cdr diff-list))
1225 (if (= (mod membership-code ediff-membership-code1) 0) ; dir1
1226 (let ((beg (point)))
1227 (insert (format "%-27s"
1228 (ediff-truncate-string-left
1229 (ediff-abbreviate-file-name
1230 (if (file-directory-p (concat dir1 file))
1231 (file-name-as-directory file)
1232 file))
1233 24)))
1234 ;; format of meta info in the dir-diff-buffer:
1235 ;; (filename-tail filename-full otherdir1 otherdir2 otherdir3)
1236 (ediff-set-meta-overlay
1237 beg (point)
1238 (list meta-buf file (concat dir1 file) dir1 dir2 dir3)))
1239 (insert (format "%-27s" "---")))
1240 (if (= (mod membership-code ediff-membership-code2) 0) ; dir2
1241 (let ((beg (point)))
1242 (insert (format "%-26s"
1243 (ediff-truncate-string-left
1244 (ediff-abbreviate-file-name
1245 (if (file-directory-p (concat dir2 file))
1246 (file-name-as-directory file)
1247 file))
1248 24)))
1249 (ediff-set-meta-overlay
1250 beg (point)
1251 (list meta-buf file (concat dir2 file) dir1 dir2 dir3)))
1252 (insert (format "%-26s" "---")))
1253 (if (stringp dir3)
1254 (if (= (mod membership-code ediff-membership-code3) 0) ; dir3
1255 (let ((beg (point)))
1256 (insert (format " %-25s"
1257 (ediff-truncate-string-left
1258 (ediff-abbreviate-file-name
1259 (if (file-directory-p (concat dir3 file))
1260 (file-name-as-directory file)
1261 file))
1262 24)))
1263 (ediff-set-meta-overlay
1264 beg (point)
1265 (list meta-buf file (concat dir3 file) dir1 dir2 dir3)))
1266 (insert (format " %-25s" "---"))))
1267 (insert "\n"))
1268 (setq buffer-read-only t)
1269 (set-buffer-modified-p nil)
1270 (goto-char saved-point)) ; end eval in diff buffer
1273 (defun ediff-bury-dir-diffs-buffer ()
1274 "Bury the directory difference buffer. Display the meta buffer instead."
1275 (interactive)
1276 ;; ediff-meta-buffer is set in ediff-draw-dir-diffs so the directory
1277 ;; difference buffer remembers the meta buffer
1278 (let ((buf ediff-meta-buffer)
1279 wind)
1280 (ediff-kill-buffer-carefully ediff-dir-diffs-buffer)
1281 (if (setq wind (ediff-get-visible-buffer-window buf))
1282 (select-window wind)
1283 (set-window-buffer (selected-window) buf))))
1285 ;; executes in dir session group buffer
1286 ;; show buffer differences
1287 (defun ediff-show-dir-diffs ()
1288 "Display differences among the directories involved in session group."
1289 (interactive)
1290 (if (ediff-one-filegroup-metajob)
1291 (error "This command is inapplicable in the present context"))
1292 (or (ediff-buffer-live-p ediff-dir-diffs-buffer)
1293 (ediff-draw-dir-diffs ediff-dir-difference-list))
1294 (let ((buf ediff-dir-diffs-buffer))
1295 (other-window 1)
1296 (set-window-buffer (selected-window) buf)
1297 (goto-char (point-min))))
1299 ;; Format of meta info in dir-diff-buffer:
1300 ;; (filename-tail filename-full otherdir1 otherdir2)
1301 (defun ediff-dir-diff-copy-file ()
1302 "Copy file described at point to directories where this file is missing."
1303 (interactive)
1304 (let* ((pos (ediff-event-point last-command-event))
1305 (info (ediff-get-meta-info (current-buffer) pos 'noerror))
1306 (meta-buf (car info))
1307 (file-tail (nth 1 info))
1308 (file-abs (nth 2 info))
1309 (otherdir1 (nth 3 info))
1310 (otherfile1 (if otherdir1 (concat otherdir1 file-tail)))
1311 (otherdir2 (nth 4 info))
1312 (otherfile2 (if otherdir2 (concat otherdir2 file-tail)))
1313 (otherdir3 (nth 5 info))
1314 (otherfile3 (if otherdir3 (concat otherdir3 file-tail)))
1315 meta-list dir-diff-list
1317 (if (null info)
1318 (error "No file suitable for copying described at this location"))
1319 (ediff-with-current-buffer meta-buf
1320 (setq meta-list ediff-meta-list
1321 dir-diff-list ediff-dir-difference-list))
1323 ;; copy file to directories where it doesn't exist, update
1324 ;; ediff-dir-difference-list and redisplay
1325 (mapc
1326 (lambda (otherfile-struct)
1327 (let ((otherfile (car otherfile-struct))
1328 (file-mem-code (cdr otherfile-struct)))
1329 (if otherfile
1330 (or (file-exists-p otherfile)
1331 (if (y-or-n-p
1332 (format "Copy %s to %s? " file-abs otherfile))
1333 (let* ((file-diff-record (assoc file-tail dir-diff-list))
1334 (new-mem-code
1335 (* (cdr file-diff-record) file-mem-code)))
1336 (copy-file file-abs otherfile)
1337 (setcdr file-diff-record new-mem-code)
1338 (ediff-draw-dir-diffs dir-diff-list (buffer-name))
1339 (sit-for 0)
1340 ;; if file is in all three dirs or in two dirs and only
1341 ;; two dirs are involved, delete this file's record
1342 (if (or (= new-mem-code ediff-product-of-memcodes)
1343 (and (> new-mem-code ediff-membership-code3)
1344 (null otherfile3)))
1345 (delq file-diff-record dir-diff-list))
1346 ))))
1348 ;; 2,3,5 are numbers used to encode membership of a file in
1349 ;; dir1/2/3. See ediff-intersect-directories.
1350 (list (cons otherfile1 2) (cons otherfile2 3) (cons otherfile3 5)))
1352 (if (and (file-exists-p otherfile1)
1353 (file-exists-p otherfile2)
1354 (or (not otherfile3) (file-exists-p otherfile3)))
1355 ;; update ediff-meta-list by direct modification
1356 (nconc meta-list
1357 (list (ediff-make-new-meta-list-element
1358 (expand-file-name otherfile1)
1359 (expand-file-name otherfile2)
1360 (if otherfile3
1361 (expand-file-name otherfile3)))))
1363 (ediff-update-meta-buffer meta-buf 'must-redraw)
1366 (defun ediff-up-meta-hierarchy ()
1367 "Go to the parent session group buffer."
1368 (interactive)
1369 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1370 (ediff-show-meta-buffer
1371 ediff-parent-meta-buffer ediff-meta-session-number)
1372 (error "This session group has no parent")))
1375 ;; argument is ignored
1376 (defun ediff-redraw-registry-buffer (&optional ignore)
1377 (ediff-with-current-buffer ediff-registry-buffer
1378 (let ((point (point))
1379 elt bufAname bufBname bufCname cur-diff total-diffs pt
1380 job-name meta-list registry-list buffer-read-only)
1381 (erase-buffer)
1382 ;; delete phony overlays that used to represent sessions before the buff
1383 ;; was redrawn
1384 (if (featurep 'xemacs)
1385 (map-extents 'delete-extent)
1386 (mapc 'delete-overlay (overlays-in 1 1)))
1388 (insert "This is a registry of all active Ediff sessions.
1390 Useful commands:
1391 button2, `v', RET over a session record: switch to that session
1392 M over a session record: display the associated session group
1393 R in any Ediff session: display session registry
1394 n,SPC: next session
1395 p,DEL: previous session
1396 E: browse Ediff on-line manual
1397 q: bury registry
1400 \t\tActive Ediff Sessions:
1401 \t\t----------------------
1404 ;; purge registry list from dead buffers
1405 (mapc (lambda (elt)
1406 (if (not (ediff-buffer-live-p elt))
1407 (setq ediff-session-registry
1408 (delq elt ediff-session-registry))))
1409 ediff-session-registry)
1411 (if (null ediff-session-registry)
1412 (insert " ******* No active Ediff sessions *******\n"))
1414 (setq registry-list ediff-session-registry)
1415 (while registry-list
1416 (setq elt (car registry-list)
1417 registry-list (cdr registry-list))
1419 (if (ediff-buffer-live-p elt)
1420 (if (ediff-with-current-buffer elt
1421 (setq job-name ediff-metajob-name
1422 meta-list ediff-meta-list)
1423 (and ediff-metajob-name
1424 (not (eq ediff-metajob-name 'ediff-registry))))
1425 (progn
1426 (setq pt (point))
1427 (insert (format " *group*\t%s: %s\n"
1428 (buffer-name elt)
1429 (ediff-abbrev-jobname job-name)))
1430 (insert (format "\t\t %s %s %s\n"
1431 (ediff-abbreviate-file-name
1432 (ediff-get-group-objA meta-list))
1433 (ediff-abbreviate-file-name
1434 (if (stringp
1435 (ediff-get-group-objB meta-list))
1436 (ediff-get-group-objB meta-list)
1437 ""))
1438 (ediff-abbreviate-file-name
1439 (if (stringp
1440 (ediff-get-group-objC meta-list))
1441 (ediff-get-group-objC meta-list)
1442 ""))))
1443 (ediff-set-meta-overlay pt (point) elt))
1444 (progn
1445 (ediff-with-current-buffer elt
1446 (setq bufAname (if (ediff-buffer-live-p ediff-buffer-A)
1447 (buffer-name ediff-buffer-A)
1448 "!!!killed buffer!!!")
1449 bufBname (if (ediff-buffer-live-p ediff-buffer-B)
1450 (buffer-name ediff-buffer-B)
1451 "!!!killed buffer!!!")
1452 bufCname (cond ((not (ediff-3way-job))
1454 ((ediff-buffer-live-p ediff-buffer-C)
1455 (buffer-name ediff-buffer-C))
1456 (t "!!!killed buffer!!!")))
1457 (setq total-diffs (format "%-4d" ediff-number-of-differences)
1458 cur-diff
1459 (cond ((= ediff-current-difference -1) " _")
1460 ((= ediff-current-difference
1461 ediff-number-of-differences)
1462 " $")
1463 (t (format
1464 "%4d" (1+ ediff-current-difference))))
1465 job-name ediff-job-name))
1466 ;; back in the meta buf
1467 (setq pt (point))
1468 (insert cur-diff "/" total-diffs "\t"
1469 (buffer-name elt)
1470 (format ": %s" (ediff-abbrev-jobname job-name)))
1471 (insert
1472 "\n\t\t " bufAname " " bufBname " " bufCname "\n")
1473 (ediff-set-meta-overlay pt (point) elt))))
1474 ) ; while
1475 (set-buffer-modified-p nil)
1476 (goto-char point)
1479 ;; Sets overlay around a meta record with 'ediff-meta-info property PROP
1480 ;; If optional SESSION-NUMBER, make it a property of the overlay,
1481 ;; ediff-meta-session-number
1482 ;; PROP is either the ctl or meta buffer (used when we work with the registry)
1483 ;; or a session meta descriptor of the form
1484 ;; (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
1485 (defun ediff-set-meta-overlay (b e prop &optional session-number hidden)
1486 (let (overl)
1487 (setq overl (ediff-make-overlay b e))
1488 (if (featurep 'emacs)
1489 (ediff-overlay-put overl 'mouse-face 'highlight)
1490 (ediff-overlay-put overl 'highlight t))
1491 (ediff-overlay-put overl 'ediff-meta-info prop)
1492 (ediff-overlay-put overl 'invisible hidden)
1493 (ediff-overlay-put overl 'follow-link t)
1494 (if (numberp session-number)
1495 (ediff-overlay-put overl 'ediff-meta-session-number session-number))))
1497 (defun ediff-mark-for-hiding-at-pos (unmark)
1498 "Mark session for hiding. With prefix arg, unmark."
1499 (interactive "P")
1500 (let* ((pos (ediff-event-point last-command-event))
1501 (meta-buf (ediff-event-buffer last-command-event))
1502 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1503 (info (ediff-get-meta-info meta-buf pos))
1504 (session-number (ediff-get-session-number-at-pos pos)))
1505 (ediff-mark-session-for-hiding info unmark)
1506 (ediff-next-meta-item 1)
1507 (save-excursion
1508 (ediff-update-meta-buffer meta-buf nil session-number))
1511 ;; Returns whether session was marked or unmarked
1512 (defun ediff-mark-session-for-hiding (info unmark)
1513 (let ((session-buf (ediff-get-session-buffer info))
1514 ignore)
1515 (cond ((eq unmark 'mark) (setq unmark nil))
1516 ((eq (ediff-get-session-status info) ?H) (setq unmark t))
1517 (unmark ; says unmark, but the marker is different from H
1518 (setq ignore t)))
1519 (cond (ignore)
1520 (unmark (ediff-set-session-status info nil))
1521 ;;; (if (ediff-buffer-live-p session-buf)
1522 ;;; (error "Can't hide active session, %s" (buffer-name session-buf)))
1523 (t (ediff-set-session-status info ?H))))
1524 unmark)
1527 (defun ediff-mark-for-operation-at-pos (unmark)
1528 "Mark session for a group operation. With prefix arg, unmark."
1529 (interactive "P")
1530 (let* ((pos (ediff-event-point last-command-event))
1531 (meta-buf (ediff-event-buffer last-command-event))
1532 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1533 (info (ediff-get-meta-info meta-buf pos))
1534 (session-number (ediff-get-session-number-at-pos pos)))
1535 (ediff-mark-session-for-operation info unmark)
1536 (ediff-next-meta-item 1)
1537 (save-excursion
1538 (ediff-update-meta-buffer meta-buf nil session-number))
1542 ;; returns whether session was unmarked.
1543 ;; remember: this is a toggle op
1544 (defun ediff-mark-session-for-operation (info unmark)
1545 (let (ignore)
1546 (cond ((eq unmark 'mark) (setq unmark nil))
1547 ((eq (ediff-get-session-status info) ?*) (setq unmark t))
1548 (unmark ; says unmark, but the marker is different from *
1549 (setq ignore t)))
1550 (cond (ignore)
1551 (unmark (ediff-set-session-status info nil))
1552 (t (ediff-set-session-status info ?*))))
1553 unmark)
1556 (defun ediff-hide-marked-sessions (unhide)
1557 "Hide marked sessions. With prefix arg, unhide."
1558 (interactive "P")
1559 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1560 (meta-list (cdr ediff-meta-list))
1561 (from (if unhide ?I ?H))
1562 (to (if unhide ?H ?I))
1563 (numMarked 0)
1564 active-sessions-exist session-buf elt)
1565 (while meta-list
1566 (setq elt (car meta-list)
1567 meta-list (cdr meta-list)
1568 session-buf (ediff-get-session-buffer elt))
1570 (if (eq (ediff-get-session-status elt) from)
1571 (progn
1572 (setq numMarked (1+ numMarked))
1573 (if (and (eq to ?I) (buffer-live-p session-buf))
1574 ;; shouldn't hide active sessions
1575 (setq active-sessions-exist t)
1576 (ediff-set-session-status elt to)))))
1577 (if (> numMarked 0)
1578 (ediff-update-meta-buffer grp-buf 'must-redraw)
1579 (beep)
1580 (if unhide
1581 (message "Nothing to reveal...")
1582 (message "Nothing to hide...")))
1583 (if active-sessions-exist
1584 (message "Note: Ediff didn't hide active sessions!"))
1587 ;; Apply OPERATION to marked sessions. Operation expects one argument of type
1588 ;; meta-list member (not the first one), i.e., a regular session description.
1589 ;; Returns number of marked sessions on which operation was performed
1590 (defun ediff-operate-on-marked-sessions (operation)
1591 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1592 (meta-list (cdr ediff-meta-list))
1593 (marksym ?*)
1594 (numMarked 0)
1595 (sessionNum 0)
1596 (diff-buffer ediff-meta-diff-buffer)
1597 session-buf elt)
1598 (while meta-list
1599 (setq elt (car meta-list)
1600 meta-list (cdr meta-list)
1601 sessionNum (1+ sessionNum))
1602 (cond ((eq (ediff-get-session-status elt) marksym)
1603 (save-excursion
1604 (setq numMarked (1+ numMarked))
1605 (funcall operation elt sessionNum)))
1606 ;; The following goes into a session represented by a subdirectory
1607 ;; and applies operation to marked sessions there
1608 ((and (ediff-meta-session-p elt)
1609 (ediff-buffer-live-p
1610 (setq session-buf (ediff-get-session-buffer elt))))
1611 (setq numMarked
1612 (+ numMarked
1613 (ediff-with-current-buffer session-buf
1614 ;; pass meta-diff along
1615 (setq ediff-meta-diff-buffer diff-buffer)
1616 ;; collect diffs in child group
1617 (ediff-operate-on-marked-sessions operation)))))))
1618 (ediff-update-meta-buffer grp-buf 'must-redraw) ; just in case
1619 numMarked
1622 (defun ediff-append-custom-diff (session sessionNum)
1623 (or (ediff-collect-diffs-metajob)
1624 (error "Can't compute multifile patch in this context"))
1625 (let ((session-buf (ediff-get-session-buffer session))
1626 (meta-diff-buff ediff-meta-diff-buffer)
1627 (metajob ediff-metajob-name)
1628 tmp-buf custom-diff-buf)
1629 (if (ediff-buffer-live-p session-buf)
1630 (ediff-with-current-buffer session-buf
1631 (if (eq ediff-control-buffer session-buf) ; individual session
1632 (progn
1633 (ediff-compute-custom-diffs-maybe)
1634 (setq custom-diff-buf ediff-custom-diff-buffer)))))
1636 (or (ediff-buffer-live-p meta-diff-buff)
1637 (error "Ediff: something wrong--killed multiple diff's buffer"))
1639 (cond ((ediff-buffer-live-p custom-diff-buf)
1640 ;; for live session buffers we do them first because the user may
1641 ;; have changed them with respect to the underlying files
1642 (save-excursion
1643 (set-buffer meta-diff-buff)
1644 (goto-char (point-max))
1645 (insert-buffer-substring custom-diff-buf)
1646 (insert "\n")))
1647 ;; if ediff session is not live, run diff directly on the files
1648 ((memq metajob '(ediff-directories
1649 ediff-merge-directories
1650 ediff-merge-directories-with-ancestor))
1651 ;; get diffs by calling shell command on ediff-custom-diff-program
1652 (save-excursion
1653 (set-buffer (setq tmp-buf (get-buffer-create ediff-tmp-buffer)))
1654 (erase-buffer)
1655 (shell-command
1656 (format
1657 "%s %s %s %s"
1658 (shell-quote-argument ediff-custom-diff-program)
1659 ediff-custom-diff-options
1660 (shell-quote-argument (ediff-get-session-objA-name session))
1661 (shell-quote-argument (ediff-get-session-objB-name session))
1665 (save-excursion
1666 (set-buffer meta-diff-buff)
1667 (goto-char (point-max))
1668 (insert-buffer-substring tmp-buf)
1669 (insert "\n")))
1671 (ediff-kill-buffer-carefully meta-diff-buff)
1672 (error "Session %d compares versions of file. Such session must be active to enable multifile patch collection" sessionNum )))
1675 (defun ediff-collect-custom-diffs ()
1676 "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'.
1677 This operation is defined only for `ediff-directories' and
1678 `ediff-directory-revisions', since its intent is to produce
1679 multifile patches. For `ediff-directory-revisions', we insist that
1680 all marked sessions must be active."
1681 (interactive)
1682 (let ((coding-system-for-read ediff-coding-system-for-read))
1683 (or (ediff-buffer-live-p ediff-meta-diff-buffer)
1684 (setq ediff-meta-diff-buffer
1685 (get-buffer-create
1686 (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
1687 (ediff-with-current-buffer ediff-meta-diff-buffer
1688 (setq buffer-read-only nil)
1689 (erase-buffer))
1690 (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
1691 ;; did something
1692 (progn
1693 (display-buffer ediff-meta-diff-buffer 'not-this-window)
1694 (ediff-with-current-buffer ediff-meta-diff-buffer
1695 (set-buffer-modified-p nil)
1696 (setq buffer-read-only t))
1697 (if (fboundp 'diff-mode)
1698 (with-current-buffer ediff-meta-diff-buffer
1699 (diff-mode))))
1700 (beep)
1701 (message "No marked sessions found"))))
1703 (defun ediff-meta-show-patch ()
1704 "Show the multi-file patch associated with this group session."
1705 (interactive)
1706 (let* ((pos (ediff-event-point last-command-event))
1707 (meta-buf (ediff-event-buffer last-command-event))
1708 (info (ediff-get-meta-info meta-buf pos 'noerror))
1709 (patchbuffer ediff-meta-patchbufer))
1710 (if (ediff-buffer-live-p patchbuffer)
1711 (ediff-with-current-buffer patchbuffer
1712 (save-restriction
1713 (if (not info)
1714 (widen)
1715 (narrow-to-region
1716 (ediff-get-session-objB-name info)
1717 (ediff-get-session-objC-name info)))
1718 (set-buffer (get-buffer-create ediff-tmp-buffer))
1719 (erase-buffer)
1720 (insert-buffer-substring patchbuffer)
1721 (goto-char (point-min))
1722 (display-buffer ediff-tmp-buffer 'not-this-window)
1724 (error "The patch buffer wasn't found"))))
1727 ;; This function executes in meta buffer. It knows where event happened.
1728 (defun ediff-filegroup-action ()
1729 "Execute appropriate action for a selected session."
1730 (interactive)
1731 (let* ((pos (ediff-event-point last-command-event))
1732 (meta-buf (ediff-event-buffer last-command-event))
1733 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1734 (info (ediff-get-meta-info meta-buf pos))
1735 (session-buf (ediff-get-session-buffer info))
1736 (session-number (ediff-get-session-number-at-pos pos meta-buf))
1737 (default-regexp (eval ediff-default-filtering-regexp))
1738 merge-autostore-dir file1 file2 file3 regexp)
1740 (setq file1 (ediff-get-session-objA-name info)
1741 file2 (ediff-get-session-objB-name info)
1742 file3 (ediff-get-session-objC-name info))
1744 ;; make sure we don't start on hidden sessions
1745 ;; ?H means marked for hiding. ?I means invalid (hidden).
1746 (if (memq (ediff-get-session-status info) '(?I))
1747 (progn
1748 (beep)
1749 (if (y-or-n-p "This session is marked as hidden, unmark? ")
1750 (progn
1751 (ediff-set-session-status info nil)
1752 (ediff-update-meta-buffer meta-buf nil session-number))
1753 (error "Aborted"))))
1755 (ediff-with-current-buffer meta-buf
1756 (setq merge-autostore-dir
1757 (ediff-get-group-merge-autostore-dir ediff-meta-list))
1758 (goto-char pos) ; if the user clicked on session--move point there
1759 ;; First handle sessions involving directories (which are themselves
1760 ;; session groups)
1761 ;; After that handle individual sessions
1762 (cond ((ediff-meta-session-p info)
1763 ;; do ediff/ediff-merge on subdirectories
1764 (if (ediff-buffer-live-p session-buf)
1765 (ediff-show-meta-buffer session-buf)
1766 (setq regexp
1767 (read-string
1768 (if (stringp default-regexp)
1769 (format
1770 "Filter through regular expression (default %s): "
1771 default-regexp)
1772 "Filter through regular expression: ")
1774 'ediff-filtering-regexp-history
1775 (eval ediff-default-filtering-regexp)))
1776 (ediff-directories-internal
1777 file1 file2 file3 regexp
1778 ediff-session-action-function
1779 ediff-metajob-name
1780 ;; make it update (car info) after startup
1781 `(list (lambda ()
1782 ;; child session group should know its parent
1783 (setq ediff-parent-meta-buffer
1784 (quote ,ediff-meta-buffer)
1785 ediff-meta-session-number
1786 ,session-number)
1787 ;; and parent will know its child
1788 (setcar (quote ,info) ediff-meta-buffer))))))
1790 ;; Do ediff-revision on a subdirectory
1791 ((and (ediff-one-filegroup-metajob)
1792 (ediff-revision-metajob)
1793 (file-directory-p file1))
1794 (if (ediff-buffer-live-p session-buf)
1795 (ediff-show-meta-buffer session-buf)
1796 (setq regexp (read-string "Filter through regular expression: "
1797 nil 'ediff-filtering-regexp-history))
1798 (ediff-directory-revisions-internal
1799 file1 regexp
1800 ediff-session-action-function ediff-metajob-name
1801 ;; make it update (car info) after startup
1802 `(list (lambda ()
1803 ;; child session group should know its parent and
1804 ;; its number
1805 (setq ediff-parent-meta-buffer
1806 (quote ,ediff-meta-buffer)
1807 ediff-meta-session-number
1808 ,session-number)
1809 ;; and parent will know its child
1810 (setcar (quote ,info) ediff-meta-buffer))))))
1812 ;; From here on---only individual session handlers
1814 ;; handle an individual session with a live control buffer
1815 ((ediff-buffer-live-p session-buf)
1816 (ediff-with-current-buffer session-buf
1817 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1818 (ediff-recenter 'no-rehighlight)))
1820 ((ediff-problematic-session-p info)
1821 (beep)
1822 (if (y-or-n-p
1823 "This session has no ancestor. Merge without the ancestor? ")
1824 (ediff-merge-files
1825 file1 file2
1826 ;; provide startup hooks
1827 `(list (lambda ()
1828 (add-hook
1829 'ediff-after-quit-hook-internal
1830 (lambda ()
1831 (if (ediff-buffer-live-p ,(current-buffer))
1832 (ediff-show-meta-buffer
1833 ,(current-buffer) ,session-number)))
1834 nil 'local)
1835 (setq ediff-meta-buffer ,(current-buffer)
1836 ediff-meta-session-number
1837 ,session-number)
1838 (setq ediff-merge-store-file
1839 ,(if (ediff-nonempty-string-p
1840 merge-autostore-dir)
1841 (concat
1842 merge-autostore-dir
1843 ediff-merge-filename-prefix
1844 (file-name-nondirectory file1))
1846 ;; make ediff-startup pass
1847 ;; ediff-control-buffer back to the meta
1848 ;; level; see below
1849 (setcar
1850 (quote ,info) ediff-control-buffer))))
1851 (error "Aborted")))
1852 ((ediff-one-filegroup-metajob) ; needs 1 file arg
1853 (funcall ediff-session-action-function
1854 file1
1855 ;; provide startup hooks
1856 `(list (lambda ()
1857 (add-hook
1858 'ediff-after-quit-hook-internal
1859 (lambda ()
1860 (if (ediff-buffer-live-p
1861 ,(current-buffer))
1862 (ediff-show-meta-buffer
1863 ,(current-buffer)
1864 ,session-number)))
1865 nil 'local)
1866 (setq ediff-meta-buffer ,(current-buffer)
1867 ediff-meta-session-number
1868 ,session-number)
1869 (setq ediff-merge-store-file
1870 ,(if (ediff-nonempty-string-p
1871 merge-autostore-dir)
1872 (concat
1873 merge-autostore-dir
1874 ediff-merge-filename-prefix
1875 (file-name-nondirectory file1))) )
1876 ;; make ediff-startup pass
1877 ;; ediff-control-buffer back to the meta
1878 ;; level; see below
1879 (setcar
1880 (quote ,info) ediff-control-buffer)))))
1881 ((not (ediff-metajob3)) ; need 2 file args
1882 (funcall ediff-session-action-function
1883 file1 file2
1884 ;; provide startup hooks
1885 `(list (lambda ()
1886 (add-hook
1887 'ediff-after-quit-hook-internal
1888 (lambda ()
1889 (if (ediff-buffer-live-p
1890 ,(current-buffer))
1891 (ediff-show-meta-buffer
1892 ,(current-buffer)
1893 ,session-number)))
1894 nil 'local)
1895 (setq ediff-meta-buffer ,(current-buffer)
1896 ediff-meta-session-number
1897 ,session-number)
1898 (setq ediff-merge-store-file
1899 ,(if (ediff-nonempty-string-p
1900 merge-autostore-dir)
1901 (concat
1902 merge-autostore-dir
1903 ediff-merge-filename-prefix
1904 (file-name-nondirectory file1))) )
1905 ;; make ediff-startup pass
1906 ;; ediff-control-buffer back to the meta
1907 ;; level; see below
1908 (setcar
1909 (quote ,info) ediff-control-buffer)))))
1910 ((ediff-metajob3) ; need 3 file args
1911 (funcall ediff-session-action-function
1912 file1 file2 file3
1913 ;; arrange startup hooks
1914 `(list (lambda ()
1915 (add-hook
1916 'ediff-after-quit-hook-internal
1917 (lambda ()
1918 (if (ediff-buffer-live-p
1919 ,(current-buffer))
1920 (ediff-show-meta-buffer
1921 ,(current-buffer)
1922 ,session-number)))
1923 nil 'local)
1924 (setq ediff-merge-store-file
1925 ,(if (ediff-nonempty-string-p
1926 merge-autostore-dir)
1927 (concat
1928 merge-autostore-dir
1929 ediff-merge-filename-prefix
1930 (file-name-nondirectory file1))) )
1931 (setq ediff-meta-buffer , (current-buffer)
1932 ediff-meta-session-number
1933 ,session-number)
1934 ;; this arranges that ediff-startup will pass
1935 ;; the value of ediff-control-buffer back to
1936 ;; the meta level, to the record in the meta
1937 ;; list containing the information about the
1938 ;; session associated with that
1939 ;; ediff-control-buffer
1940 (setcar
1941 (quote ,info) ediff-control-buffer)))))
1942 ) ; cond
1943 ) ; eval in meta-buf
1946 (defun ediff-registry-action ()
1947 "Switch to a selected session."
1948 (interactive)
1949 (let* ((pos (ediff-event-point last-command-event))
1950 (buf (ediff-event-buffer last-command-event))
1951 (ctl-buf (ediff-get-meta-info buf pos)))
1953 (if (ediff-buffer-live-p ctl-buf)
1954 ;; check if this is ediff-control-buffer or ediff-meta-buffer
1955 (if (ediff-with-current-buffer ctl-buf
1956 (eq (key-binding "q") 'ediff-quit-meta-buffer))
1957 ;; it's a meta-buffer -- last action should just display it
1958 (ediff-show-meta-buffer ctl-buf t)
1959 ;; it's a session buffer -- invoke go back to session
1960 (ediff-with-current-buffer ctl-buf
1961 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1962 (ediff-recenter 'no-rehighlight)))
1963 (beep)
1964 (message "You've selected a stale session --- try again")
1965 (ediff-update-registry))
1966 (ediff-with-current-buffer buf
1967 (goto-char pos))
1971 ;; If session number is t, means don't update meta buffer
1972 (defun ediff-show-meta-buffer (&optional meta-buf session-number)
1973 "Show the session group buffer."
1974 (interactive)
1975 (run-hooks 'ediff-before-directory-setup-hooks)
1976 (let (wind frame silent)
1977 (if meta-buf (setq silent t))
1979 (setq meta-buf (or meta-buf ediff-meta-buffer))
1980 (cond ((not (bufferp meta-buf))
1981 (error "This Ediff session is not part of a session group"))
1982 ((not (ediff-buffer-live-p meta-buf))
1983 (error
1984 "Can't find this session's group panel -- session itself is ok")))
1986 (cond ((numberp session-number)
1987 (ediff-update-meta-buffer meta-buf nil session-number))
1988 ;; if session-number is t, don't update
1989 (session-number)
1990 (t (ediff-cleanup-meta-buffer meta-buf)))
1992 (ediff-with-current-buffer meta-buf
1993 (save-excursion
1994 (cond ((setq wind (ediff-get-visible-buffer-window meta-buf))
1995 (or silent
1996 (message
1997 "Already showing the group panel for this session"))
1998 (set-window-buffer wind meta-buf)
1999 (select-window wind))
2000 ((window-live-p (setq wind ediff-window-C)) ;in merge--merge buf
2001 (set-window-buffer ediff-window-C meta-buf)
2002 (select-window wind))
2003 ((window-live-p (setq wind ediff-window-A))
2004 (set-window-buffer ediff-window-A meta-buf)
2005 (select-window wind))
2006 ((window-live-p (setq wind ediff-window-B))
2007 (set-window-buffer ediff-window-B meta-buf)
2008 (select-window wind))
2009 ((and
2010 (setq wind
2011 (ediff-get-visible-buffer-window ediff-registry-buffer))
2012 (ediff-window-display-p))
2013 (select-window wind)
2014 (other-window 1)
2015 (set-window-buffer (selected-window) meta-buf))
2016 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
2017 (set-window-buffer (selected-window) meta-buf)))
2019 (if (and (ediff-window-display-p)
2020 (window-live-p
2021 (setq wind (ediff-get-visible-buffer-window meta-buf))))
2022 (progn
2023 (setq frame (window-frame wind))
2024 (raise-frame frame)
2025 (ediff-reset-mouse frame)))
2026 (sit-for 0) ; sometimes needed to synch the display and ensure that the
2027 ; point ends up after the just completed session
2028 (run-hooks 'ediff-show-session-group-hook)
2031 (defun ediff-show-current-session-meta-buffer ()
2032 (interactive)
2033 (ediff-show-meta-buffer nil ediff-meta-session-number))
2035 (defun ediff-show-meta-buff-from-registry ()
2036 "Display the session group buffer for a selected session group."
2037 (interactive)
2038 (let* ((pos (ediff-event-point last-command-event))
2039 (meta-buf (ediff-event-buffer last-command-event))
2040 (info (ediff-get-meta-info meta-buf pos))
2041 (meta-or-session-buf info))
2042 (ediff-with-current-buffer meta-or-session-buf
2043 (ediff-show-meta-buffer nil t))))
2045 ;;;###autoload
2046 (defun ediff-show-registry ()
2047 "Display Ediff's registry."
2048 (interactive)
2049 (ediff-update-registry)
2050 (if (not (ediff-buffer-live-p ediff-registry-buffer))
2051 (error "No active Ediff sessions or corrupted session registry"))
2052 (let (wind frame)
2053 ;; for some reason, point moves in ediff-registry-buffer, so we preserve it
2054 ;; explicitly
2055 (ediff-with-current-buffer ediff-registry-buffer
2056 (save-excursion
2057 (cond ((setq wind
2058 (ediff-get-visible-buffer-window ediff-registry-buffer))
2059 (message "Already showing the registry")
2060 (set-window-buffer wind ediff-registry-buffer)
2061 (select-window wind))
2062 ((window-live-p ediff-window-C)
2063 (set-window-buffer ediff-window-C ediff-registry-buffer)
2064 (select-window ediff-window-C))
2065 ((window-live-p ediff-window-A)
2066 (set-window-buffer ediff-window-A ediff-registry-buffer)
2067 (select-window ediff-window-A))
2068 ((window-live-p ediff-window-B)
2069 (set-window-buffer ediff-window-B ediff-registry-buffer)
2070 (select-window ediff-window-B))
2071 ((and (setq wind
2072 (ediff-get-visible-buffer-window ediff-meta-buffer))
2073 (ediff-window-display-p))
2074 (select-window wind)
2075 (other-window 1)
2076 (set-window-buffer (selected-window) ediff-registry-buffer))
2077 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
2078 (set-window-buffer (selected-window) ediff-registry-buffer)))
2080 (if (ediff-window-display-p)
2081 (progn
2082 (setq frame
2083 (window-frame
2084 (ediff-get-visible-buffer-window ediff-registry-buffer)))
2085 (raise-frame frame)
2086 (ediff-reset-mouse frame)))
2087 (run-hooks 'ediff-show-registry-hook)
2090 ;;;###autoload
2091 (defalias 'eregistry 'ediff-show-registry)
2093 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a
2094 ;; parent meta-buf
2095 ;; Check if META-BUF exists before calling this function
2096 ;; Optional MUST-REDRAW, if non-nil, would force redrawal of the whole meta
2097 ;; buffer. Otherwise, it will just go over the buffer and update activity marks
2098 ;; and session status.
2099 ;; SESSION-NUMBER, if specified, says which session caused the update.
2100 (defun ediff-update-meta-buffer (meta-buf &optional must-redraw session-number)
2101 (if (ediff-buffer-live-p meta-buf)
2102 (ediff-with-current-buffer meta-buf
2103 (let (overl)
2104 (cond (must-redraw ; completely redraw the meta buffer
2105 (funcall ediff-meta-redraw-function ediff-meta-list))
2106 ((numberp session-number) ; redraw only for the given session
2107 (ediff-update-session-marker-in-dir-meta-buffer
2108 session-number))
2109 (t ; update what changed only, but scan the entire meta buffer
2110 (ediff-update-markers-in-dir-meta-buffer ediff-meta-list)))
2111 (setq overl (ediff-get-meta-overlay-at-pos (point)))
2112 ;; skip the invisible sessions
2113 (while (and overl (ediff-overlay-get overl 'invisible))
2114 (ediff-next-meta-item1)
2115 (setq overl (ediff-get-meta-overlay-at-pos (point))))
2116 ))))
2118 (defun ediff-update-registry ()
2119 (ediff-with-current-buffer (current-buffer)
2120 (if (ediff-buffer-live-p ediff-registry-buffer)
2121 (ediff-redraw-registry-buffer)
2122 (ediff-prepare-meta-buffer
2123 'ediff-registry-action
2124 ediff-session-registry
2125 "*Ediff Registry"
2126 'ediff-redraw-registry-buffer
2127 'ediff-registry))
2130 ;; If meta-buf exists, it is redrawn along with parent.
2131 ;; Otherwise, nothing happens.
2132 (defun ediff-cleanup-meta-buffer (meta-buffer)
2133 (if (ediff-buffer-live-p meta-buffer)
2134 (ediff-with-current-buffer meta-buffer
2135 (ediff-update-meta-buffer meta-buffer)
2136 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
2137 (ediff-update-meta-buffer
2138 ediff-parent-meta-buffer nil ediff-meta-session-number)))))
2140 ;; t if no session is in progress
2141 (defun ediff-safe-to-quit (meta-buffer)
2142 (if (ediff-buffer-live-p meta-buffer)
2143 (let ((lis ediff-meta-list)
2144 (cont t)
2145 buffer-read-only)
2146 ;;(ediff-update-meta-buffer meta-buffer)
2147 (ediff-with-current-buffer meta-buffer
2148 (setq lis (cdr lis)) ; discard the description part of meta-list
2149 (while (and cont lis)
2150 (if (ediff-buffer-live-p
2151 (ediff-get-group-buffer lis)) ; in progress
2152 (setq cont nil))
2153 (setq lis (cdr lis)))
2154 cont))))
2156 (defun ediff-quit-meta-buffer ()
2157 "If the group has no active session, delete the meta buffer.
2158 If no session is in progress, ask to confirm before deleting meta buffer.
2159 Otherwise, bury the meta buffer.
2160 If this is a session registry buffer then just bury it."
2161 (interactive)
2162 (let* ((buf (current-buffer))
2163 (dir-diffs-buffer ediff-dir-diffs-buffer)
2164 (meta-diff-buffer ediff-meta-diff-buffer)
2165 (session-number ediff-meta-session-number)
2166 (parent-buf ediff-parent-meta-buffer)
2167 (dont-show-registry (eq buf ediff-registry-buffer)))
2168 (if dont-show-registry
2169 (bury-buffer)
2170 ;;(ediff-cleanup-meta-buffer buf)
2171 (cond ((and (ediff-safe-to-quit buf)
2172 (y-or-n-p "Quit this session group? "))
2173 (run-hooks 'ediff-quit-session-group-hook)
2174 (message "")
2175 (ediff-dispose-of-meta-buffer buf))
2176 ((ediff-safe-to-quit buf)
2177 (bury-buffer))
2179 (error
2180 "This session group has active sessions---cannot exit")))
2181 (ediff-update-meta-buffer parent-buf nil session-number)
2182 (ediff-kill-buffer-carefully dir-diffs-buffer)
2183 (ediff-kill-buffer-carefully meta-diff-buffer)
2184 (if (ediff-buffer-live-p parent-buf)
2185 (progn
2186 (setq dont-show-registry t)
2187 (ediff-show-meta-buffer parent-buf session-number)))
2189 (or dont-show-registry
2190 (ediff-show-registry))))
2192 (defun ediff-dispose-of-meta-buffer (buf)
2193 (setq ediff-session-registry (delq buf ediff-session-registry))
2194 (ediff-with-current-buffer buf
2195 (if (ediff-buffer-live-p ediff-dir-diffs-buffer)
2196 (kill-buffer ediff-dir-diffs-buffer)))
2197 (kill-buffer buf))
2200 ;; Obtain information on a meta record where the user clicked or typed
2201 ;; BUF is the buffer where this happened and POINT is the position
2202 ;; If optional NOERROR arg is given, don't report error and return nil if no
2203 ;; meta info is found on line.
2204 (defun ediff-get-meta-info (buf point &optional noerror)
2205 (let (result olist tmp)
2206 (if (and point (ediff-buffer-live-p buf))
2207 (ediff-with-current-buffer buf
2208 (if (featurep 'xemacs)
2209 (setq result
2210 (if (setq tmp (extent-at point buf 'ediff-meta-info))
2211 (ediff-overlay-get tmp 'ediff-meta-info)))
2212 (setq olist
2213 (mapcar (lambda (elt)
2214 (unless (overlay-get elt 'invisible)
2215 (overlay-get elt 'ediff-meta-info)))
2216 (overlays-at point)))
2217 (while (and olist (null (car olist)))
2218 (setq olist (cdr olist)))
2219 (setq result (car olist)))))
2220 (or result
2221 (unless noerror
2222 (ediff-update-registry)
2223 (error "No session info in this line")))))
2226 (defun ediff-get-meta-overlay-at-pos (point)
2227 (if (featurep 'xemacs)
2228 (extent-at point (current-buffer) 'ediff-meta-info)
2229 (let* ((overl-list (overlays-at point))
2230 (overl (car overl-list)))
2231 (while (and overl (null (overlay-get overl 'ediff-meta-info)))
2232 (setq overl-list (cdr overl-list)
2233 overl (car overl-list)))
2234 overl)))
2236 (defun ediff-get-session-number-at-pos (point &optional meta-buffer)
2237 (setq meta-buffer (if (ediff-buffer-live-p meta-buffer)
2238 meta-buffer
2239 (current-buffer)))
2240 (ediff-with-current-buffer meta-buffer
2241 (ediff-overlay-get
2242 (ediff-get-meta-overlay-at-pos point) 'ediff-meta-session-number)))
2245 ;; Return location of the next meta overlay after point
2246 (defun ediff-next-meta-overlay-start (point)
2247 (if (eobp)
2248 (goto-char (point-min))
2249 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2250 (if (featurep 'xemacs)
2251 (progn ; xemacs
2252 (if overl
2253 (setq overl (next-extent overl))
2254 (setq overl (next-extent (current-buffer))))
2255 (if overl
2256 (extent-start-position overl)
2257 (point-max)))
2258 ;; emacs
2259 (if overl
2260 ;; note: end of current overlay is the beginning of the next one
2261 (overlay-end overl)
2262 (next-overlay-change point))))))
2265 (defun ediff-previous-meta-overlay-start (point)
2266 (if (bobp)
2267 (goto-char (point-max))
2268 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2269 (if (featurep 'xemacs)
2270 (progn
2271 (if overl
2272 (setq overl (previous-extent overl))
2273 (setq overl (previous-extent (current-buffer))))
2274 (if overl
2275 (extent-start-position overl)
2276 (point-min)))
2277 (if overl (setq point (overlay-start overl)))
2278 ;; to get to the beginning of prev overlay
2279 (if (not (bobp))
2280 ;; trick to overcome an emacs bug--doesn't always find previous
2281 ;; overlay change correctly
2282 (setq point (1- point)))
2283 (setq point (previous-overlay-change point))
2284 ;; If we are not over an overlay after subtracting 1, it means we are
2285 ;; in the description area preceding session records. In this case,
2286 ;; goto the top of the registry buffer.
2287 (or (car (overlays-at point))
2288 (setq point (point-min)))
2289 point))))
2291 ;; this is the action invoked when the user selects a patch from the meta
2292 ;; buffer.
2293 (defun ediff-patch-file-form-meta (file &optional startup-hooks)
2294 (let* ((pos (ediff-event-point last-command-event))
2295 (meta-buf (ediff-event-buffer last-command-event))
2296 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
2297 (info (ediff-get-meta-info meta-buf pos))
2298 (meta-patchbuf ediff-meta-patchbufer)
2299 session-buf beg-marker end-marker)
2301 (if (or (file-directory-p file) (string-match "/dev/null" file))
2302 (error "`%s' is not an ordinary file" (file-name-as-directory file)))
2303 (setq session-buf (ediff-get-session-buffer info)
2304 beg-marker (ediff-get-session-objB-name info)
2305 end-marker (ediff-get-session-objC-name info))
2307 (or (ediff-buffer-live-p session-buf) ; either an active patch session
2308 (null session-buf) ; or it is a virgin session
2309 (error
2310 "Patch has already been applied to this file -- can't repeat!"))
2312 (ediff-with-current-buffer meta-patchbuf
2313 (save-restriction
2314 (widen)
2315 (narrow-to-region beg-marker end-marker)
2316 (ediff-patch-file-internal meta-patchbuf file startup-hooks)))))
2319 (defun ediff-unmark-all-for-operation ()
2320 "Unmark all sessions marked for operation."
2321 (interactive)
2322 (let ((list (cdr ediff-meta-list))
2323 elt)
2324 (while (setq elt (car list))
2325 (ediff-mark-session-for-operation elt 'unmark)
2326 (setq list (cdr list))))
2327 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2329 (defun ediff-unmark-all-for-hiding ()
2330 "Unmark all sessions marked for hiding."
2331 (interactive)
2332 (let ((list (cdr ediff-meta-list))
2333 elt)
2334 (while (setq elt (car list))
2335 (ediff-mark-session-for-hiding elt 'unmark)
2336 (setq list (cdr list))))
2337 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2340 ;; ACTION is ?h, ?m, ?=: to mark for hiding, mark for operation, or simply
2341 ;; indicate which are equal files
2342 (defun ediff-meta-mark-equal-files (&optional action)
2343 "Run through the session list and mark identical files.
2344 This is used only for sessions that involve 2 or 3 files at the same time.
2345 ACTION is an optional argument that can be ?h, ?m, ?=, to mark for hiding, mark
2346 for operation, or simply indicate which are equal files. If it is nil, then
2347 `last-command-event' is used to decide which action to take."
2348 (interactive)
2349 (if (null action)
2350 (setq action last-command-event))
2351 (let ((list (cdr ediff-meta-list))
2352 marked1 marked2 marked3
2353 fileinfo1 fileinfo2 fileinfo3 elt)
2354 (message "Comparing files ...")
2355 (while (setq elt (car list))
2356 (setq fileinfo1 (ediff-get-session-objA elt)
2357 fileinfo2 (ediff-get-session-objB elt)
2358 fileinfo3 (ediff-get-session-objC elt))
2359 (ediff-set-file-eqstatus fileinfo1 nil)
2360 (ediff-set-file-eqstatus fileinfo2 nil)
2361 (ediff-set-file-eqstatus fileinfo3 nil)
2363 (setq marked1 t
2364 marked2 t
2365 marked3 t)
2366 (or (ediff-mark-if-equal fileinfo1 fileinfo2)
2367 (setq marked1 nil))
2368 (if (ediff-metajob3)
2369 (progn
2370 (or (ediff-mark-if-equal fileinfo1 fileinfo3)
2371 (setq marked2 nil))
2372 (or (ediff-mark-if-equal fileinfo2 fileinfo3)
2373 (setq marked3 nil))))
2374 (if (and marked1 marked2 marked3)
2375 (cond ((eq action ?h)
2376 (ediff-mark-session-for-hiding elt 'mark))
2377 ((eq action ?m)
2378 (ediff-mark-session-for-operation elt 'mark))
2380 (setq list (cdr list)))
2381 (message "Comparing files ... Done"))
2382 (setq ediff-recurse-to-subdirectories nil)
2383 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2385 ;; mark files 1 and 2 as equal, if they are.
2386 ;; returns t, if something was marked
2387 (defun ediff-mark-if-equal (fileinfo1 fileinfo2)
2388 (let ((f1 (car fileinfo1))
2389 (f2 (car fileinfo2)))
2390 (if (and (stringp f1) (stringp f2) (ediff-same-contents f1 f2))
2391 (progn
2392 (ediff-set-file-eqstatus fileinfo1 t)
2393 (ediff-set-file-eqstatus fileinfo2 t)
2399 ;;; Local Variables:
2400 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
2401 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
2402 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
2403 ;;; End:
2405 ;; arch-tag: c8a76898-f96f-4d9c-be9d-129134017188
2406 ;;; ediff-mult.el ends here