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