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