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