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