(allout-layout, allout-passphrase-verifier-string)
[emacs.git] / lisp / ediff-mult.el
blob0bbd3298c7a0538a33f67473fdc8c5112eaaf3c0
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 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 2, 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 (concat auxdir1 elt)
652 (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 (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 (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 otherfile1 otherfile2 otherfile3)))
1343 (ediff-update-meta-buffer meta-buf 'must-redraw)
1346 (defun ediff-up-meta-hierarchy ()
1347 "Go to the parent session group buffer."
1348 (interactive)
1349 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1350 (ediff-show-meta-buffer
1351 ediff-parent-meta-buffer ediff-meta-session-number)
1352 (error "This session group has no parent")))
1355 ;; argument is ignored
1356 (defun ediff-redraw-registry-buffer (&optional ignore)
1357 (ediff-with-current-buffer ediff-registry-buffer
1358 (let ((point (point))
1359 elt bufAname bufBname bufCname cur-diff total-diffs pt
1360 job-name meta-list registry-list buffer-read-only)
1361 (erase-buffer)
1362 ;; delete phony overlays that used to represent sessions before the buff
1363 ;; was redrawn
1364 (ediff-cond-compile-for-xemacs-or-emacs
1365 (map-extents 'delete-extent) ; xemacs
1366 (mapcar 'delete-overlay (overlays-in 1 1)) ; emacs
1369 (insert "This is a registry of all active Ediff sessions.
1371 Useful commands:
1372 button2, `v', RET over a session record: switch to that session
1373 M over a session record: display the associated session group
1374 R in any Ediff session: display session registry
1375 n,SPC: next session
1376 p,DEL: previous session
1377 E: browse Ediff on-line manual
1378 q: bury registry
1381 \t\tActive Ediff Sessions:
1382 \t\t----------------------
1385 ;; purge registry list from dead buffers
1386 (mapcar (lambda (elt)
1387 (if (not (ediff-buffer-live-p elt))
1388 (setq ediff-session-registry
1389 (delq elt ediff-session-registry))))
1390 ediff-session-registry)
1392 (if (null ediff-session-registry)
1393 (insert " ******* No active Ediff sessions *******\n"))
1395 (setq registry-list ediff-session-registry)
1396 (while registry-list
1397 (setq elt (car registry-list)
1398 registry-list (cdr registry-list))
1400 (if (ediff-buffer-live-p elt)
1401 (if (ediff-with-current-buffer elt
1402 (setq job-name ediff-metajob-name
1403 meta-list ediff-meta-list)
1404 (and ediff-metajob-name
1405 (not (eq ediff-metajob-name 'ediff-registry))))
1406 (progn
1407 (setq pt (point))
1408 (insert (format " *group*\t%s: %s\n"
1409 (buffer-name elt)
1410 (ediff-abbrev-jobname job-name)))
1411 (insert (format "\t\t %s %s %s\n"
1412 (ediff-abbreviate-file-name
1413 (ediff-get-group-objA meta-list))
1414 (ediff-abbreviate-file-name
1415 (if (stringp
1416 (ediff-get-group-objB meta-list))
1417 (ediff-get-group-objB meta-list)
1418 ""))
1419 (ediff-abbreviate-file-name
1420 (if (stringp
1421 (ediff-get-group-objC meta-list))
1422 (ediff-get-group-objC meta-list)
1423 ""))))
1424 (ediff-set-meta-overlay pt (point) elt))
1425 (progn
1426 (ediff-with-current-buffer elt
1427 (setq bufAname (if (ediff-buffer-live-p ediff-buffer-A)
1428 (buffer-name ediff-buffer-A)
1429 "!!!killed buffer!!!")
1430 bufBname (if (ediff-buffer-live-p ediff-buffer-B)
1431 (buffer-name ediff-buffer-B)
1432 "!!!killed buffer!!!")
1433 bufCname (cond ((not (ediff-3way-job))
1435 ((ediff-buffer-live-p ediff-buffer-C)
1436 (buffer-name ediff-buffer-C))
1437 (t "!!!killed buffer!!!")))
1438 (setq total-diffs (format "%-4d" ediff-number-of-differences)
1439 cur-diff
1440 (cond ((= ediff-current-difference -1) " _")
1441 ((= ediff-current-difference
1442 ediff-number-of-differences)
1443 " $")
1444 (t (format
1445 "%4d" (1+ ediff-current-difference))))
1446 job-name ediff-job-name))
1447 ;; back in the meta buf
1448 (setq pt (point))
1449 (insert cur-diff "/" total-diffs "\t"
1450 (buffer-name elt)
1451 (format ": %s" (ediff-abbrev-jobname job-name)))
1452 (insert
1453 "\n\t\t " bufAname " " bufBname " " bufCname "\n")
1454 (ediff-set-meta-overlay pt (point) elt))))
1455 ) ; while
1456 (set-buffer-modified-p nil)
1457 (goto-char point)
1460 ;; Sets overlay around a meta record with 'ediff-meta-info property PROP
1461 ;; If optional SESSION-NUMBER, make it a property of the overlay,
1462 ;; ediff-meta-session-number
1463 ;; PROP is either the ctl or meta buffer (used when we work with the registry)
1464 ;; or a session meta descriptor of the form
1465 ;; (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
1466 (defun ediff-set-meta-overlay (b e prop &optional session-number hidden)
1467 (let (overl)
1468 (setq overl (ediff-make-overlay b e))
1469 (if ediff-emacs-p
1470 (ediff-overlay-put overl 'mouse-face 'highlight)
1471 (ediff-overlay-put overl 'highlight t))
1472 (ediff-overlay-put overl 'ediff-meta-info prop)
1473 (ediff-overlay-put overl 'invisible hidden)
1474 (ediff-overlay-put overl 'follow-link t)
1475 (if (numberp session-number)
1476 (ediff-overlay-put overl 'ediff-meta-session-number session-number))))
1478 (defun ediff-mark-for-hiding-at-pos (unmark)
1479 "Mark session for hiding. With prefix arg, unmark."
1480 (interactive "P")
1481 (let* ((pos (ediff-event-point last-command-event))
1482 (meta-buf (ediff-event-buffer last-command-event))
1483 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1484 (info (ediff-get-meta-info meta-buf pos))
1485 (session-number (ediff-get-session-number-at-pos pos)))
1486 (ediff-mark-session-for-hiding info unmark)
1487 (ediff-next-meta-item 1)
1488 (save-excursion
1489 (ediff-update-meta-buffer meta-buf nil session-number))
1492 ;; Returns whether session was marked or unmarked
1493 (defun ediff-mark-session-for-hiding (info unmark)
1494 (let ((session-buf (ediff-get-session-buffer info))
1495 ignore)
1496 (cond ((eq unmark 'mark) (setq unmark nil))
1497 ((eq (ediff-get-session-status info) ?H) (setq unmark t))
1498 (unmark ; says unmark, but the marker is different from H
1499 (setq ignore t)))
1500 (cond (ignore)
1501 (unmark (ediff-set-session-status info nil))
1502 ;;; (if (ediff-buffer-live-p session-buf)
1503 ;;; (error "Can't hide active session, %s" (buffer-name session-buf)))
1504 (t (ediff-set-session-status info ?H))))
1505 unmark)
1508 (defun ediff-mark-for-operation-at-pos (unmark)
1509 "Mark session for a group operation. With prefix arg, unmark."
1510 (interactive "P")
1511 (let* ((pos (ediff-event-point last-command-event))
1512 (meta-buf (ediff-event-buffer last-command-event))
1513 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1514 (info (ediff-get-meta-info meta-buf pos))
1515 (session-number (ediff-get-session-number-at-pos pos)))
1516 (ediff-mark-session-for-operation info unmark)
1517 (ediff-next-meta-item 1)
1518 (save-excursion
1519 (ediff-update-meta-buffer meta-buf nil session-number))
1523 ;; returns whether session was unmarked.
1524 ;; remember: this is a toggle op
1525 (defun ediff-mark-session-for-operation (info unmark)
1526 (let (ignore)
1527 (cond ((eq unmark 'mark) (setq unmark nil))
1528 ((eq (ediff-get-session-status info) ?*) (setq unmark t))
1529 (unmark ; says unmark, but the marker is different from *
1530 (setq ignore t)))
1531 (cond (ignore)
1532 (unmark (ediff-set-session-status info nil))
1533 (t (ediff-set-session-status info ?*))))
1534 unmark)
1537 (defun ediff-hide-marked-sessions (unhide)
1538 "Hide marked sessions. With prefix arg, unhide."
1539 (interactive "P")
1540 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1541 (meta-list (cdr ediff-meta-list))
1542 (from (if unhide ?I ?H))
1543 (to (if unhide ?H ?I))
1544 (numMarked 0)
1545 active-sessions-exist session-buf elt)
1546 (while meta-list
1547 (setq elt (car meta-list)
1548 meta-list (cdr meta-list)
1549 session-buf (ediff-get-session-buffer elt))
1551 (if (eq (ediff-get-session-status elt) from)
1552 (progn
1553 (setq numMarked (1+ numMarked))
1554 (if (and (eq to ?I) (buffer-live-p session-buf))
1555 ;; shouldn't hide active sessions
1556 (setq active-sessions-exist t)
1557 (ediff-set-session-status elt to)))))
1558 (if (> numMarked 0)
1559 (ediff-update-meta-buffer grp-buf 'must-redraw)
1560 (beep)
1561 (if unhide
1562 (message "Nothing to reveal...")
1563 (message "Nothing to hide...")))
1564 (if active-sessions-exist
1565 (message "Note: Ediff didn't hide active sessions!"))
1568 ;; Apply OPERATION to marked sessions. Operation expects one argument of type
1569 ;; meta-list member (not the first one), i.e., a regular session description.
1570 ;; Returns number of marked sessions on which operation was performed
1571 (defun ediff-operate-on-marked-sessions (operation)
1572 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1573 (meta-list (cdr ediff-meta-list))
1574 (marksym ?*)
1575 (numMarked 0)
1576 (sessionNum 0)
1577 (diff-buffer ediff-meta-diff-buffer)
1578 session-buf elt)
1579 (while meta-list
1580 (setq elt (car meta-list)
1581 meta-list (cdr meta-list)
1582 sessionNum (1+ sessionNum))
1583 (cond ((eq (ediff-get-session-status elt) marksym)
1584 (save-excursion
1585 (setq numMarked (1+ numMarked))
1586 (funcall operation elt sessionNum)))
1587 ;; The following goes into a session represented by a subdirectory
1588 ;; and applies operation to marked sessions there
1589 ((and (ediff-meta-session-p elt)
1590 (ediff-buffer-live-p
1591 (setq session-buf (ediff-get-session-buffer elt))))
1592 (setq numMarked
1593 (+ numMarked
1594 (ediff-with-current-buffer session-buf
1595 ;; pass meta-diff along
1596 (setq ediff-meta-diff-buffer diff-buffer)
1597 ;; collect diffs in child group
1598 (ediff-operate-on-marked-sessions operation)))))))
1599 (ediff-update-meta-buffer grp-buf 'must-redraw) ; just in case
1600 numMarked
1603 (defun ediff-append-custom-diff (session sessionNum)
1604 (or (ediff-collect-diffs-metajob)
1605 (error "Can't compute multifile patch in this context"))
1606 (let ((session-buf (ediff-get-session-buffer session))
1607 (meta-diff-buff ediff-meta-diff-buffer)
1608 (metajob ediff-metajob-name)
1609 tmp-buf custom-diff-buf)
1610 (if (ediff-buffer-live-p session-buf)
1611 (ediff-with-current-buffer session-buf
1612 (if (eq ediff-control-buffer session-buf) ; individual session
1613 (progn
1614 (ediff-compute-custom-diffs-maybe)
1615 (setq custom-diff-buf ediff-custom-diff-buffer)))))
1617 (or (ediff-buffer-live-p meta-diff-buff)
1618 (error "Ediff: something wrong--killed multiple diff's buffer"))
1620 (cond ((ediff-buffer-live-p custom-diff-buf)
1621 ;; for live session buffers we do them first because the user may
1622 ;; have changed them with respect to the underlying files
1623 (save-excursion
1624 (set-buffer meta-diff-buff)
1625 (goto-char (point-max))
1626 (insert-buffer-substring custom-diff-buf)
1627 (insert "\n")))
1628 ;; if ediff session is not live, run diff directly on the files
1629 ((memq metajob '(ediff-directories
1630 ediff-merge-directories
1631 ediff-merge-directories-with-ancestor))
1632 ;; get diffs by calling shell command on ediff-custom-diff-program
1633 (save-excursion
1634 (set-buffer (setq tmp-buf (get-buffer-create ediff-tmp-buffer)))
1635 (erase-buffer)
1636 (shell-command
1637 (format "%s %s %s %s"
1638 ediff-custom-diff-program ediff-custom-diff-options
1639 (ediff-get-session-objA-name session)
1640 (ediff-get-session-objB-name session))
1642 (save-excursion
1643 (set-buffer meta-diff-buff)
1644 (goto-char (point-max))
1645 (insert-buffer-substring tmp-buf)
1646 (insert "\n")))
1648 (ediff-kill-buffer-carefully meta-diff-buff)
1649 (error "Session %d compares versions of file. Such session must be active to enable multifile patch collection" sessionNum )))
1652 (defun ediff-collect-custom-diffs ()
1653 "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'.
1654 This operation is defined only for `ediff-directories' and
1655 `ediff-directory-revisions', since its intent is to produce
1656 multifile patches. For `ediff-directory-revisions', we insist that
1657 all marked sessions must be active."
1658 (interactive)
1659 (or (ediff-buffer-live-p ediff-meta-diff-buffer)
1660 (setq ediff-meta-diff-buffer
1661 (get-buffer-create
1662 (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
1663 (ediff-with-current-buffer ediff-meta-diff-buffer
1664 (setq buffer-read-only nil)
1665 (erase-buffer))
1666 (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
1667 ;; did something
1668 (progn
1669 (display-buffer ediff-meta-diff-buffer 'not-this-window)
1670 (ediff-with-current-buffer ediff-meta-diff-buffer
1671 (set-buffer-modified-p nil)
1672 (setq buffer-read-only t)))
1673 (beep)
1674 (message "No marked sessions found")))
1676 (defun ediff-meta-show-patch ()
1677 "Show the multi-file patch associated with this group session."
1678 (interactive)
1679 (let* ((pos (ediff-event-point last-command-event))
1680 (meta-buf (ediff-event-buffer last-command-event))
1681 (info (ediff-get-meta-info meta-buf pos 'noerror))
1682 (patchbuffer ediff-meta-patchbufer))
1683 (if (ediff-buffer-live-p patchbuffer)
1684 (ediff-with-current-buffer patchbuffer
1685 (save-restriction
1686 (if (not info)
1687 (widen)
1688 (narrow-to-region
1689 (ediff-get-session-objB-name info)
1690 (ediff-get-session-objC-name info)))
1691 (set-buffer (get-buffer-create ediff-tmp-buffer))
1692 (erase-buffer)
1693 (insert-buffer-substring patchbuffer)
1694 (goto-char (point-min))
1695 (display-buffer ediff-tmp-buffer 'not-this-window)
1697 (error "The patch buffer wasn't found"))))
1700 ;; This function executes in meta buffer. It knows where event happened.
1701 (defun ediff-filegroup-action ()
1702 "Execute appropriate action for a selected session."
1703 (interactive)
1704 (let* ((pos (ediff-event-point last-command-event))
1705 (meta-buf (ediff-event-buffer last-command-event))
1706 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1707 (info (ediff-get-meta-info meta-buf pos))
1708 (session-buf (ediff-get-session-buffer info))
1709 (session-number (ediff-get-session-number-at-pos pos meta-buf))
1710 (default-regexp (eval ediff-default-filtering-regexp))
1711 merge-autostore-dir file1 file2 file3 regexp)
1713 (setq file1 (ediff-get-session-objA-name info)
1714 file2 (ediff-get-session-objB-name info)
1715 file3 (ediff-get-session-objC-name info))
1717 ;; make sure we don't start on hidden sessions
1718 ;; ?H means marked for hiding. ?I means invalid (hidden).
1719 (if (memq (ediff-get-session-status info) '(?I))
1720 (progn
1721 (beep)
1722 (if (y-or-n-p "This session is marked as hidden, unmark? ")
1723 (progn
1724 (ediff-set-session-status info nil)
1725 (ediff-update-meta-buffer meta-buf nil session-number))
1726 (error "Aborted"))))
1728 (ediff-with-current-buffer meta-buf
1729 (setq merge-autostore-dir
1730 (ediff-get-group-merge-autostore-dir ediff-meta-list))
1731 (goto-char pos) ; if the user clicked on session--move point there
1732 ;; First handle sessions involving directories (which are themselves
1733 ;; session groups)
1734 ;; After that handle individual sessions
1735 (cond ((ediff-meta-session-p info)
1736 ;; do ediff/ediff-merge on subdirectories
1737 (if (ediff-buffer-live-p session-buf)
1738 (ediff-show-meta-buffer session-buf)
1739 (setq regexp
1740 (read-string
1741 (if (stringp default-regexp)
1742 (format
1743 "Filter through regular expression (default %s): "
1744 default-regexp)
1745 "Filter through regular expression: ")
1747 'ediff-filtering-regexp-history
1748 (eval ediff-default-filtering-regexp)))
1749 (ediff-directories-internal
1750 file1 file2 file3 regexp
1751 ediff-session-action-function
1752 ediff-metajob-name
1753 ;; make it update (car info) after startup
1754 `(list (lambda ()
1755 ;; child session group should know its parent
1756 (setq ediff-parent-meta-buffer
1757 (quote ,ediff-meta-buffer)
1758 ediff-meta-session-number
1759 ,session-number)
1760 ;; and parent will know its child
1761 (setcar (quote ,info) ediff-meta-buffer))))))
1763 ;; Do ediff-revision on a subdirectory
1764 ((and (ediff-one-filegroup-metajob)
1765 (ediff-revision-metajob)
1766 (file-directory-p file1))
1767 (if (ediff-buffer-live-p session-buf)
1768 (ediff-show-meta-buffer session-buf)
1769 (setq regexp (read-string "Filter through regular expression: "
1770 nil 'ediff-filtering-regexp-history))
1771 (ediff-directory-revisions-internal
1772 file1 regexp
1773 ediff-session-action-function ediff-metajob-name
1774 ;; make it update (car info) after startup
1775 `(list (lambda ()
1776 ;; child session group should know its parent and
1777 ;; its number
1778 (setq ediff-parent-meta-buffer
1779 (quote ,ediff-meta-buffer)
1780 ediff-meta-session-number
1781 ,session-number)
1782 ;; and parent will know its child
1783 (setcar (quote ,info) ediff-meta-buffer))))))
1785 ;; From here on---only individual session handlers
1787 ;; handle an individual session with a live control buffer
1788 ((ediff-buffer-live-p session-buf)
1789 (ediff-with-current-buffer session-buf
1790 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1791 (ediff-recenter 'no-rehighlight)))
1793 ((ediff-problematic-session-p info)
1794 (beep)
1795 (if (y-or-n-p
1796 "This session has no ancestor. Merge without the ancestor? ")
1797 (ediff-merge-files
1798 file1 file2
1799 ;; provide startup hooks
1800 `(list (lambda ()
1801 (add-hook
1802 'ediff-after-quit-hook-internal
1803 (lambda ()
1804 (if (ediff-buffer-live-p ,(current-buffer))
1805 (ediff-show-meta-buffer
1806 ,(current-buffer) ,session-number)))
1807 nil 'local)
1808 (setq ediff-meta-buffer ,(current-buffer)
1809 ediff-meta-session-number
1810 ,session-number)
1811 (setq ediff-merge-store-file
1812 ,(if (ediff-nonempty-string-p
1813 merge-autostore-dir)
1814 (concat
1815 merge-autostore-dir
1816 ediff-merge-filename-prefix
1817 (file-name-nondirectory file1))
1819 ;; make ediff-startup pass
1820 ;; ediff-control-buffer back to the meta
1821 ;; level; see below
1822 (setcar
1823 (quote ,info) ediff-control-buffer))))
1824 (error "Aborted")))
1825 ((ediff-one-filegroup-metajob) ; needs 1 file arg
1826 (funcall ediff-session-action-function
1827 file1
1828 ;; provide startup hooks
1829 `(list (lambda ()
1830 (add-hook
1831 'ediff-after-quit-hook-internal
1832 (lambda ()
1833 (if (ediff-buffer-live-p
1834 ,(current-buffer))
1835 (ediff-show-meta-buffer
1836 ,(current-buffer)
1837 ,session-number)))
1838 nil 'local)
1839 (setq ediff-meta-buffer ,(current-buffer)
1840 ediff-meta-session-number
1841 ,session-number)
1842 (setq ediff-merge-store-file
1843 ,(if (ediff-nonempty-string-p
1844 merge-autostore-dir)
1845 (concat
1846 merge-autostore-dir
1847 ediff-merge-filename-prefix
1848 (file-name-nondirectory file1))) )
1849 ;; make ediff-startup pass
1850 ;; ediff-control-buffer back to the meta
1851 ;; level; see below
1852 (setcar
1853 (quote ,info) ediff-control-buffer)))))
1854 ((not (ediff-metajob3)) ; need 2 file args
1855 (funcall ediff-session-action-function
1856 file1 file2
1857 ;; provide startup hooks
1858 `(list (lambda ()
1859 (add-hook
1860 'ediff-after-quit-hook-internal
1861 (lambda ()
1862 (if (ediff-buffer-live-p
1863 ,(current-buffer))
1864 (ediff-show-meta-buffer
1865 ,(current-buffer)
1866 ,session-number)))
1867 nil 'local)
1868 (setq ediff-meta-buffer ,(current-buffer)
1869 ediff-meta-session-number
1870 ,session-number)
1871 (setq ediff-merge-store-file
1872 ,(if (ediff-nonempty-string-p
1873 merge-autostore-dir)
1874 (concat
1875 merge-autostore-dir
1876 ediff-merge-filename-prefix
1877 (file-name-nondirectory file1))) )
1878 ;; make ediff-startup pass
1879 ;; ediff-control-buffer back to the meta
1880 ;; level; see below
1881 (setcar
1882 (quote ,info) ediff-control-buffer)))))
1883 ((ediff-metajob3) ; need 3 file args
1884 (funcall ediff-session-action-function
1885 file1 file2 file3
1886 ;; arrange startup hooks
1887 `(list (lambda ()
1888 (add-hook
1889 'ediff-after-quit-hook-internal
1890 (lambda ()
1891 (if (ediff-buffer-live-p
1892 ,(current-buffer))
1893 (ediff-show-meta-buffer
1894 ,(current-buffer)
1895 ,session-number)))
1896 nil 'local)
1897 (setq ediff-merge-store-file
1898 ,(if (ediff-nonempty-string-p
1899 merge-autostore-dir)
1900 (concat
1901 merge-autostore-dir
1902 ediff-merge-filename-prefix
1903 (file-name-nondirectory file1))) )
1904 (setq ediff-meta-buffer , (current-buffer)
1905 ediff-meta-session-number
1906 ,session-number)
1907 ;; this arranges that ediff-startup will pass
1908 ;; the value of ediff-control-buffer back to
1909 ;; the meta level, to the record in the meta
1910 ;; list containing the information about the
1911 ;; session associated with that
1912 ;; ediff-control-buffer
1913 (setcar
1914 (quote ,info) ediff-control-buffer)))))
1915 ) ; cond
1916 ) ; eval in meta-buf
1919 (defun ediff-registry-action ()
1920 "Switch to a selected session."
1921 (interactive)
1922 (let* ((pos (ediff-event-point last-command-event))
1923 (buf (ediff-event-buffer last-command-event))
1924 (ctl-buf (ediff-get-meta-info buf pos)))
1926 (if (ediff-buffer-live-p ctl-buf)
1927 ;; check if this is ediff-control-buffer or ediff-meta-buffer
1928 (if (ediff-with-current-buffer ctl-buf
1929 (eq (key-binding "q") 'ediff-quit-meta-buffer))
1930 ;; it's a meta-buffer -- last action should just display it
1931 (ediff-show-meta-buffer ctl-buf t)
1932 ;; it's a session buffer -- invoke go back to session
1933 (ediff-with-current-buffer ctl-buf
1934 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1935 (ediff-recenter 'no-rehighlight)))
1936 (beep)
1937 (message "You've selected a stale session --- try again")
1938 (ediff-update-registry))
1939 (ediff-with-current-buffer buf
1940 (goto-char pos))
1944 ;; If session number is t, means don't update meta buffer
1945 (defun ediff-show-meta-buffer (&optional meta-buf session-number)
1946 "Show the session group buffer."
1947 (interactive)
1948 (run-hooks 'ediff-before-directory-setup-hooks)
1949 (let (wind frame silent)
1950 (if meta-buf (setq silent t))
1952 (setq meta-buf (or meta-buf ediff-meta-buffer))
1953 (cond ((not (bufferp meta-buf))
1954 (error "This Ediff session is not part of a session group"))
1955 ((not (ediff-buffer-live-p meta-buf))
1956 (error
1957 "Can't find this session's group panel -- session itself is ok")))
1959 (cond ((numberp session-number)
1960 (ediff-update-meta-buffer meta-buf nil session-number))
1961 ;; if session-number is t, don't update
1962 (session-number)
1963 (t (ediff-cleanup-meta-buffer meta-buf)))
1965 (ediff-with-current-buffer meta-buf
1966 (save-excursion
1967 (cond ((setq wind (ediff-get-visible-buffer-window meta-buf))
1968 (or silent
1969 (message
1970 "Already showing the group panel for this session"))
1971 (set-window-buffer wind meta-buf)
1972 (select-window wind))
1973 ((window-live-p (setq wind ediff-window-C)) ;in merge--merge buf
1974 (set-window-buffer ediff-window-C meta-buf)
1975 (select-window wind))
1976 ((window-live-p (setq wind ediff-window-A))
1977 (set-window-buffer ediff-window-A meta-buf)
1978 (select-window wind))
1979 ((window-live-p (setq wind ediff-window-B))
1980 (set-window-buffer ediff-window-B meta-buf)
1981 (select-window wind))
1982 ((and
1983 (setq wind
1984 (ediff-get-visible-buffer-window ediff-registry-buffer))
1985 (ediff-window-display-p))
1986 (select-window wind)
1987 (other-window 1)
1988 (set-window-buffer (selected-window) meta-buf))
1989 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1990 (set-window-buffer (selected-window) meta-buf)))
1992 (if (and (ediff-window-display-p)
1993 (window-live-p
1994 (setq wind (ediff-get-visible-buffer-window meta-buf))))
1995 (progn
1996 (setq frame (window-frame wind))
1997 (raise-frame frame)
1998 (ediff-reset-mouse frame)))
1999 (sit-for 0) ; sometimes needed to synch the display and ensure that the
2000 ; point ends up after the just completed session
2001 (run-hooks 'ediff-show-session-group-hook)
2004 (defun ediff-show-current-session-meta-buffer ()
2005 (interactive)
2006 (ediff-show-meta-buffer nil ediff-meta-session-number))
2008 (defun ediff-show-meta-buff-from-registry ()
2009 "Display the session group buffer for a selected session group."
2010 (interactive)
2011 (let* ((pos (ediff-event-point last-command-event))
2012 (meta-buf (ediff-event-buffer last-command-event))
2013 (info (ediff-get-meta-info meta-buf pos))
2014 (meta-or-session-buf info))
2015 (ediff-with-current-buffer meta-or-session-buf
2016 (ediff-show-meta-buffer nil t))))
2018 ;;;###autoload
2019 (defun ediff-show-registry ()
2020 "Display Ediff's registry."
2021 (interactive)
2022 (ediff-update-registry)
2023 (if (not (ediff-buffer-live-p ediff-registry-buffer))
2024 (error "No active Ediff sessions or corrupted session registry"))
2025 (let (wind frame)
2026 ;; for some reason, point moves in ediff-registry-buffer, so we preserve it
2027 ;; explicitly
2028 (ediff-with-current-buffer ediff-registry-buffer
2029 (save-excursion
2030 (cond ((setq wind
2031 (ediff-get-visible-buffer-window ediff-registry-buffer))
2032 (message "Already showing the registry")
2033 (set-window-buffer wind ediff-registry-buffer)
2034 (select-window wind))
2035 ((window-live-p ediff-window-C)
2036 (set-window-buffer ediff-window-C ediff-registry-buffer)
2037 (select-window ediff-window-C))
2038 ((window-live-p ediff-window-A)
2039 (set-window-buffer ediff-window-A ediff-registry-buffer)
2040 (select-window ediff-window-A))
2041 ((window-live-p ediff-window-B)
2042 (set-window-buffer ediff-window-B ediff-registry-buffer)
2043 (select-window ediff-window-B))
2044 ((and (setq wind
2045 (ediff-get-visible-buffer-window ediff-meta-buffer))
2046 (ediff-window-display-p))
2047 (select-window wind)
2048 (other-window 1)
2049 (set-window-buffer (selected-window) ediff-registry-buffer))
2050 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
2051 (set-window-buffer (selected-window) ediff-registry-buffer)))
2053 (if (ediff-window-display-p)
2054 (progn
2055 (setq frame
2056 (window-frame
2057 (ediff-get-visible-buffer-window ediff-registry-buffer)))
2058 (raise-frame frame)
2059 (ediff-reset-mouse frame)))
2060 (run-hooks 'ediff-show-registry-hook)
2063 ;;;###autoload
2064 (defalias 'eregistry 'ediff-show-registry)
2066 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a
2067 ;; parent meta-buf
2068 ;; Check if META-BUF exists before calling this function
2069 ;; Optional MUST-REDRAW, if non-nil, would force redrawal of the whole meta
2070 ;; buffer. Otherwise, it will just go over the buffer and update activity marks
2071 ;; and session status.
2072 ;; SESSION-NUMBER, if specified, says which session caused the update.
2073 (defun ediff-update-meta-buffer (meta-buf &optional must-redraw session-number)
2074 (if (ediff-buffer-live-p meta-buf)
2075 (ediff-with-current-buffer meta-buf
2076 (let (overl)
2077 (cond (must-redraw ; completely redraw the meta buffer
2078 (funcall ediff-meta-redraw-function ediff-meta-list))
2079 ((numberp session-number) ; redraw only for the given session
2080 (ediff-update-session-marker-in-dir-meta-buffer
2081 session-number))
2082 (t ; update what changed only, but scan the entire meta buffer
2083 (ediff-update-markers-in-dir-meta-buffer ediff-meta-list)))
2084 (setq overl (ediff-get-meta-overlay-at-pos (point)))
2085 ;; skip the invisible sessions
2086 (while (and overl (ediff-overlay-get overl 'invisible))
2087 (ediff-next-meta-item1)
2088 (setq overl (ediff-get-meta-overlay-at-pos (point))))
2089 ))))
2091 (defun ediff-update-registry ()
2092 (ediff-with-current-buffer (current-buffer)
2093 (if (ediff-buffer-live-p ediff-registry-buffer)
2094 (ediff-redraw-registry-buffer)
2095 (ediff-prepare-meta-buffer
2096 'ediff-registry-action
2097 ediff-session-registry
2098 "*Ediff Registry"
2099 'ediff-redraw-registry-buffer
2100 'ediff-registry))
2103 ;; If meta-buf exists, it is redrawn along with parent.
2104 ;; Otherwise, nothing happens.
2105 (defun ediff-cleanup-meta-buffer (meta-buffer)
2106 (if (ediff-buffer-live-p meta-buffer)
2107 (ediff-with-current-buffer meta-buffer
2108 (ediff-update-meta-buffer meta-buffer)
2109 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
2110 (ediff-update-meta-buffer
2111 ediff-parent-meta-buffer nil ediff-meta-session-number)))))
2113 ;; t if no session is in progress
2114 (defun ediff-safe-to-quit (meta-buffer)
2115 (if (ediff-buffer-live-p meta-buffer)
2116 (let ((lis ediff-meta-list)
2117 (cont t)
2118 buffer-read-only)
2119 ;;(ediff-update-meta-buffer meta-buffer)
2120 (ediff-with-current-buffer meta-buffer
2121 (setq lis (cdr lis)) ; discard the description part of meta-list
2122 (while (and cont lis)
2123 (if (ediff-buffer-live-p
2124 (ediff-get-group-buffer lis)) ; in progress
2125 (setq cont nil))
2126 (setq lis (cdr lis)))
2127 cont))))
2129 (defun ediff-quit-meta-buffer ()
2130 "If the group has no active session, delete the meta buffer.
2131 If no session is in progress, ask to confirm before deleting meta buffer.
2132 Otherwise, bury the meta buffer.
2133 If this is a session registry buffer then just bury it."
2134 (interactive)
2135 (let* ((buf (current-buffer))
2136 (dir-diffs-buffer ediff-dir-diffs-buffer)
2137 (meta-diff-buffer ediff-meta-diff-buffer)
2138 (session-number ediff-meta-session-number)
2139 (parent-buf ediff-parent-meta-buffer)
2140 (dont-show-registry (eq buf ediff-registry-buffer)))
2141 (if dont-show-registry
2142 (bury-buffer)
2143 ;;(ediff-cleanup-meta-buffer buf)
2144 (cond ((and (ediff-safe-to-quit buf)
2145 (y-or-n-p "Quit this session group? "))
2146 (run-hooks 'ediff-quit-session-group-hook)
2147 (message "")
2148 (ediff-dispose-of-meta-buffer buf))
2149 ((ediff-safe-to-quit buf)
2150 (bury-buffer))
2152 (error
2153 "This session group has active sessions---cannot exit")))
2154 (ediff-update-meta-buffer parent-buf nil session-number)
2155 (ediff-kill-buffer-carefully dir-diffs-buffer)
2156 (ediff-kill-buffer-carefully meta-diff-buffer)
2157 (if (ediff-buffer-live-p parent-buf)
2158 (progn
2159 (setq dont-show-registry t)
2160 (ediff-show-meta-buffer parent-buf session-number)))
2162 (or dont-show-registry
2163 (ediff-show-registry))))
2165 (defun ediff-dispose-of-meta-buffer (buf)
2166 (setq ediff-session-registry (delq buf ediff-session-registry))
2167 (ediff-with-current-buffer buf
2168 (if (ediff-buffer-live-p ediff-dir-diffs-buffer)
2169 (kill-buffer ediff-dir-diffs-buffer)))
2170 (kill-buffer buf))
2173 ;; Obtain information on a meta record where the user clicked or typed
2174 ;; BUF is the buffer where this happened and POINT is the position
2175 ;; If optional NOERROR arg is given, don't report error and return nil if no
2176 ;; meta info is found on line.
2177 (defun ediff-get-meta-info (buf point &optional noerror)
2178 (let (result olist tmp)
2179 (if (and point (ediff-buffer-live-p buf))
2180 (ediff-with-current-buffer buf
2181 (ediff-cond-compile-for-xemacs-or-emacs
2182 (setq result ; xemacs
2183 (if (setq tmp (extent-at point buf 'ediff-meta-info))
2184 (ediff-overlay-get tmp 'ediff-meta-info)))
2185 (progn ; emacs
2186 (setq olist (overlays-at point))
2187 (setq olist
2188 (mapcar (lambda (elt)
2189 (unless (overlay-get elt 'invisible)
2190 (overlay-get elt 'ediff-meta-info)))
2191 olist))
2192 (while (and olist (null (car olist)))
2193 (setq olist (cdr olist)))
2194 (setq result (car olist)))
2197 (if result
2198 result
2199 (if noerror
2201 (ediff-update-registry)
2202 (error "No session info in this line")))))
2205 (defun ediff-get-meta-overlay-at-pos (point)
2206 (ediff-cond-compile-for-xemacs-or-emacs
2207 (extent-at point (current-buffer) 'ediff-meta-info) ; xemacs
2208 ;; emacs
2209 (let* ((overl-list (overlays-at point))
2210 (overl (car overl-list)))
2211 (while (and overl (null (overlay-get overl 'ediff-meta-info)))
2212 (setq overl-list (cdr overl-list)
2213 overl (car overl-list)))
2214 overl)
2218 (defsubst ediff-get-session-number-at-pos (point &optional meta-buffer)
2219 (setq meta-buffer (if (ediff-buffer-live-p meta-buffer)
2220 meta-buffer
2221 (current-buffer)))
2222 (ediff-with-current-buffer meta-buffer
2223 (ediff-overlay-get
2224 (ediff-get-meta-overlay-at-pos point) 'ediff-meta-session-number)))
2227 ;; Return location of the next meta overlay after point
2228 (defun ediff-next-meta-overlay-start (point)
2229 (if (eobp)
2230 (goto-char (point-min))
2231 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2232 (ediff-cond-compile-for-xemacs-or-emacs
2233 (progn ; xemacs
2234 (if overl
2235 (setq overl (next-extent overl))
2236 (setq overl (next-extent (current-buffer))))
2237 (if overl
2238 (extent-start-position overl)
2239 (point-max)))
2240 ;; emacs
2241 (if overl
2242 ;; note: end of current overlay is the beginning of the next one
2243 (overlay-end overl)
2244 (next-overlay-change point))
2250 (defun ediff-previous-meta-overlay-start (point)
2251 (if (bobp)
2252 (goto-char (point-max))
2253 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2254 (ediff-cond-compile-for-xemacs-or-emacs
2255 (progn
2256 (if overl
2257 (setq overl (previous-extent overl))
2258 (setq overl (previous-extent (current-buffer))))
2259 (if overl
2260 (extent-start-position overl)
2261 (point-min)))
2262 (progn
2263 (if overl (setq point (overlay-start overl)))
2264 ;; to get to the beginning of prev overlay
2265 (if (not (bobp))
2266 ;; trick to overcome an emacs bug--doesn't always find previous
2267 ;; overlay change correctly
2268 (setq point (1- point)))
2269 (setq point (previous-overlay-change point))
2270 ;; If we are not over an overlay after subtracting 1, it means we are
2271 ;; in the description area preceding session records. In this case,
2272 ;; goto the top of the registry buffer.
2273 (or (car (overlays-at point))
2274 (setq point (point-min)))
2275 point)
2279 ;; this is the action invoked when the user selects a patch from the meta
2280 ;; buffer.
2281 (defun ediff-patch-file-form-meta (file &optional startup-hooks)
2282 (let* ((pos (ediff-event-point last-command-event))
2283 (meta-buf (ediff-event-buffer last-command-event))
2284 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
2285 (info (ediff-get-meta-info meta-buf pos))
2286 (meta-patchbuf ediff-meta-patchbufer)
2287 session-buf beg-marker end-marker)
2289 (if (or (file-directory-p file) (string-match "/dev/null" file))
2290 (error "`%s' is not an ordinary file" (file-name-as-directory file)))
2291 (setq session-buf (ediff-get-session-buffer info)
2292 beg-marker (ediff-get-session-objB-name info)
2293 end-marker (ediff-get-session-objC-name info))
2295 (or (ediff-buffer-live-p session-buf) ; either an active patch session
2296 (null session-buf) ; or it is a virgin session
2297 (error
2298 "Patch has already been applied to this file -- can't repeat!"))
2300 (ediff-with-current-buffer meta-patchbuf
2301 (save-restriction
2302 (widen)
2303 (narrow-to-region beg-marker end-marker)
2304 (ediff-patch-file-internal meta-patchbuf file startup-hooks)))))
2307 (defun ediff-unmark-all-for-operation ()
2308 "Unmark all sessions marked for operation."
2309 (interactive)
2310 (let ((list (cdr ediff-meta-list))
2311 elt)
2312 (while (setq elt (car list))
2313 (ediff-mark-session-for-operation elt 'unmark)
2314 (setq list (cdr list))))
2315 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2317 (defun ediff-unmark-all-for-hiding ()
2318 "Unmark all sessions marked for hiding."
2319 (interactive)
2320 (let ((list (cdr ediff-meta-list))
2321 elt)
2322 (while (setq elt (car list))
2323 (ediff-mark-session-for-hiding elt 'unmark)
2324 (setq list (cdr list))))
2325 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2328 ;; ACTION is ?h, ?m, ?=: to mark for hiding, mark for operation, or simply
2329 ;; indicate which are equal files
2330 (defun ediff-meta-mark-equal-files (&optional action)
2331 "Run through the session list and mark identical files.
2332 This is used only for sessions that involve 2 or 3 files at the same time.
2333 ACTION is an optional argument that can be ?h, ?m, ?=, to mark for hiding, mark
2334 for operation, or simply indicate which are equal files. If it is nil, then
2335 `last-command-char' is used to decide which action to take."
2336 (interactive)
2337 (if (null action)
2338 (setq action last-command-char))
2339 (let ((list (cdr ediff-meta-list))
2340 marked1 marked2 marked3
2341 fileinfo1 fileinfo2 fileinfo3 elt)
2342 (message "Comparing files ...")
2343 (while (setq elt (car list))
2344 (setq fileinfo1 (ediff-get-session-objA elt)
2345 fileinfo2 (ediff-get-session-objB elt)
2346 fileinfo3 (ediff-get-session-objC elt))
2347 (ediff-set-file-eqstatus fileinfo1 nil)
2348 (ediff-set-file-eqstatus fileinfo2 nil)
2349 (ediff-set-file-eqstatus fileinfo3 nil)
2351 (setq marked1 t
2352 marked2 t
2353 marked3 t)
2354 (or (ediff-mark-if-equal fileinfo1 fileinfo2)
2355 (setq marked1 nil))
2356 (if (ediff-metajob3)
2357 (progn
2358 (or (ediff-mark-if-equal fileinfo1 fileinfo3)
2359 (setq marked2 nil))
2360 (or (ediff-mark-if-equal fileinfo2 fileinfo3)
2361 (setq marked3 nil))))
2362 (if (and marked1 marked2 marked3)
2363 (cond ((eq action ?h)
2364 (ediff-mark-session-for-hiding elt 'mark))
2365 ((eq action ?m)
2366 (ediff-mark-session-for-operation elt 'mark))
2368 (setq list (cdr list)))
2369 (message "Comparing files ... Done"))
2370 (setq ediff-recurse-to-subdirectories nil)
2371 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2373 ;; mark files 1 and 2 as equal, if they are.
2374 ;; returns t, if something was marked
2375 (defun ediff-mark-if-equal (fileinfo1 fileinfo2)
2376 (let ((f1 (car fileinfo1))
2377 (f2 (car fileinfo2)))
2378 (if (and (stringp f1) (stringp f2) (ediff-same-contents f1 f2))
2379 (progn
2380 (ediff-set-file-eqstatus fileinfo1 t)
2381 (ediff-set-file-eqstatus fileinfo2 t)
2386 (provide 'ediff-mult)
2389 ;;; Local Variables:
2390 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
2391 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
2392 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
2393 ;;; End:
2395 ;;; arch-tag: c8a76898-f96f-4d9c-be9d-129134017188
2396 ;;; ediff-mult.el ends here