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