Doc fixes. Remove redundant
[emacs.git] / lisp / ediff-mult.el
blobb8e576d72b76872ffa68700edcc341b7eedfb6ef
1 ;;; ediff-mult.el --- support for multi-file/multi-buffer processing in Ediff
3 ;; Copyright (C) 1995, 96, 97, 98, 99, 2000, 01, 02 Free Software Foundation, Inc.
5 ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
24 ;;; Commentary:
26 ;; Users are encouraged to add functionality to this file.
27 ;; The present file contains all the infrastructure needed for that.
29 ;; Generally, to implement a new multisession capability within Ediff,
30 ;; you need to tell it
32 ;; 1. How to display the session group buffer.
33 ;; This function must indicate which Ediff sessions are active (+) and
34 ;; which are finished (-).
35 ;; See ediff-redraw-directory-group-buffer for an example.
36 ;; In all likelihood, ediff-redraw-directory-group-buffer can be used
37 ;; directly or after a small modification.
38 ;; 2. What action to take when the user clicks button 2 or types v,e, or
39 ;; RET. See ediff-filegroup-action.
40 ;; 3. Provide a list of pairs or triples of file names (or buffers,
41 ;; depending on the particular Ediff operation you want to invoke)
42 ;; in the following format:
43 ;; (descriptor (obj1 obj2 obj3) (...) ...)
44 ;; Actually, the format of this list is pretty much up to the
45 ;; developer. The only thing is that it must be a list of lists,
46 ;; and the first list must describe the meta session, and subsequent
47 ;; elements must describe individual sessions.
48 ;; This descriptor must be a list of two, three, or four elements (nil
49 ;; or string). The function ediff-redraw-registry-buffer displays the
50 ;; second through last of these in the registry buffer.
51 ;; Also, keep in mind that the function ediff-prepare-meta-buffer
52 ;; (which see) prepends the session group buffer to the descriptor, and
53 ;; nil in front of each subsequent list (i.e., the above list
54 ;; will become
55 ;; ((meta-buf descriptor) (nil obj1 obj2 obj3) (nil ...) ...)
56 ;; Ediff expects that your function (in 2 above) will arrange to
57 ;; replace this prepended nil (via setcar) with the actual ediff
58 ;; control buffer associated with an appropriate Ediff session.
59 ;; This is arranged through internal startup hooks that can be passed
60 ;; to any of Ediff major entries (such as ediff-files, epatch, etc.).
61 ;; See how this is done in ediff-filegroup-action.
63 ;; Session descriptions are of the form (obj1 obj2 obj3), which
64 ;; describe objects relevant to the session. Usually they are names of
65 ;; files, but sometimes they may be other things. For instance, obj3
66 ;; is nil for jobs that involve only two files. For patch jobs, obj2
67 ;; and obj3 are markers that specify the patch corresponding to the
68 ;; file (whose name is obj1).
69 ;; 4. Write a function that makes a call to ediff-prepare-meta-buffer
70 ;; passing all this info.
71 ;; You may be able to use ediff-directories-internal as a template.
72 ;; 5. If you intend to add several related pieces of functionality,
73 ;; you may want to keep the function in 4 as an internal version
74 ;; and then write several top-level interactive functions that call it
75 ;; with different parameters.
76 ;; See how ediff-directories, ediff-merge-directories, and
77 ;; ediff-merge-directories-with-ancestor all use
78 ;; ediff-directories-internal.
80 ;; A useful addition here could be session groups selected by patterns
81 ;; (which are different in each directory). For instance, one may want to
82 ;; compare files of the form abc{something}.c to files old{something}.d
83 ;; which may be in the same or different directories. Or, one may want to
84 ;; compare all files of the form {something} to files of the form {something}~.
86 ;; Implementing this requires writing an collating function, which should pair
87 ;; up appropriate files. It will also require a generalization of the
88 ;; functions that do the layout of the meta- and differences buffers and of
89 ;; ediff-filegroup-action.
91 ;;; Code:
93 (provide 'ediff-mult)
95 (defgroup ediff-mult nil
96 "Multi-file and multi-buffer processing in Ediff"
97 :prefix "ediff-"
98 :group 'ediff)
101 ;; compiler pacifier
102 (eval-when-compile
103 (let ((load-path (cons (expand-file-name ".") load-path)))
104 (or (featurep 'ediff-init)
105 (load "ediff-init.el" nil nil 'nosuffix))
106 (or (featurep 'ediff-util)
107 (load "ediff-util.el" nil nil 'nosuffix))
109 ;; end pacifier
111 (require 'ediff-init)
112 (require 'ediff-util)
114 ;; meta-buffer
115 (ediff-defvar-local ediff-meta-buffer nil "")
116 (ediff-defvar-local ediff-parent-meta-buffer nil "")
117 ;; the registry buffer
118 (defvar ediff-registry-buffer nil)
120 (defconst ediff-meta-buffer-message "This is an Ediff Session Group Panel: %s
122 Useful commands:
123 button2, v, or RET over session record: start that Ediff session
124 M:\tin sessions invoked from here, brings back this group panel
125 R:\tdisplay the registry of active Ediff sessions
126 h:\tmark session for hiding (toggle)
127 x:\thide marked sessions; with prefix arg: unhide
128 m:\tmark session for a non-hiding operation (toggle)
129 uh/um:\tunmark all sessions marked for hiding/operation
130 n,SPC:\tnext session
131 p,DEL:\tprevious session
132 E:\tbrowse Ediff on-line manual
133 T:\ttoggle truncation of long file names
134 q:\tquit this session group
137 (ediff-defvar-local ediff-meta-buffer-map nil
138 "The keymap for the meta buffer.")
139 (defvar ediff-dir-diffs-buffer-map (make-sparse-keymap)
140 "The keymap to be installed in the buffer showing differences between
141 directories.")
143 ;; Variable specifying the action to take when the use invokes ediff in the
144 ;; meta buffer. This is usually ediff-registry-action or ediff-filegroup-action
145 (ediff-defvar-local ediff-meta-action-function nil "")
146 ;; Tells ediff-update-meta-buffer how to redraw it
147 (ediff-defvar-local ediff-meta-redraw-function nil "")
148 ;; Tells ediff-filegroup-action and similar procedures how to invoke Ediff for
149 ;; the sessions in a given session group
150 (ediff-defvar-local ediff-session-action-function nil "")
152 (ediff-defvar-local ediff-metajob-name nil "")
154 ;; buffer used to collect custom diffs from individual sessions in the group
155 (ediff-defvar-local ediff-meta-diff-buffer nil "")
157 ;; history var to use for filtering groups
158 (defvar ediff-filtering-regexp-history nil "")
160 ;; This has the form ((meta-buf regexp dir1 dir2 dir3 merge-auto-store-dir)
161 ;; (ctl-buf session-status (file1 . eq-status) (file2 . eq-status) (file3
162 ;; . eq-status)) (ctl-buf session-status (file1 . eq-status) (file2
163 ;; . eq-status)) ...)
164 ;; If ctl-buf is nil, the file-pair hasn't processed yet. If it is
165 ;; killed-buffer object, the file pair has been processed. If it is a live
166 ;; buffer, this means ediff is still working on the pair.
167 ;; Eq-status of a file is t if the file equals some other file in the same
168 ;; group.
169 (ediff-defvar-local ediff-meta-list nil "")
171 (ediff-defvar-local ediff-meta-session-number nil "")
174 ;; the difference list between directories in a directory session group
175 (ediff-defvar-local ediff-dir-difference-list nil "")
176 (ediff-defvar-local ediff-dir-diffs-buffer nil "")
178 ;; The registry of Ediff sessions. A list of control buffers.
179 (defvar ediff-session-registry nil)
181 (defcustom ediff-meta-truncate-filenames t
182 "*If non-nil, truncate long file names in the session group buffers.
183 This can be toggled with `ediff-toggle-filename-truncation'."
184 :type 'hook
185 :group 'ediff-mult)
186 (defcustom ediff-registry-setup-hook nil
187 "*Hooks run just after the registry control panel is set up."
188 :type 'hook
189 :group 'ediff-mult)
191 (defcustom ediff-before-session-group-setup-hooks nil
192 "*Hooks to run before Ediff arranges the window for group-level operations.
193 It is used by commands such as ediff-directories.
194 This hook can be used to save the previous window config, which can be restored
195 on ediff-quit, ediff-suspend, or ediff-quit-session-group-hook."
196 :type 'hook
197 :group 'ediff-hook)
198 (defcustom ediff-after-session-group-setup-hook nil
199 "*Hooks run just after a meta-buffer controlling a session group, such as
200 ediff-directories, is run."
201 :type 'hook
202 :group 'ediff-mult)
203 (defcustom ediff-quit-session-group-hook nil
204 "*Hooks run just before exiting a session group."
205 :type 'hook
206 :group 'ediff-mult)
207 (defcustom ediff-show-registry-hook nil
208 "*Hooks run just after the registry buffer is shown."
209 :type 'hook
210 :group 'ediff-mult)
211 (defcustom ediff-show-session-group-hook '(delete-other-windows)
212 "*Hooks run just after a session group buffer is shown."
213 :type 'hook
214 :group 'ediff-mult)
215 (defcustom ediff-meta-buffer-keymap-setup-hook nil
216 "*Hooks run just after setting up the ediff-meta-buffer-map.
217 This keymap controls key bindings in the meta buffer and is a local variable.
218 This means that you can set different bindings for different kinds of meta
219 buffers."
220 :type 'hook
221 :group 'ediff-mult)
223 ;; Buffer holding the multi-file patch. Local to the meta buffer
224 (ediff-defvar-local ediff-meta-patchbufer nil "")
226 ;;; API for ediff-meta-list
228 ;; Structure of the meta-list:
229 ;; (HEADER SESSION1 SESSION2 ...)
230 ;; HEADER: (GROUP-BUF REGEXP OBJA OBJB OBJC SAVE-DIR)
231 ;; OBJA - first directory
232 ;; OBJB - second directory
233 ;; OBJC - third directory
234 ;; SESSION1/2/... are described below
235 ;; group buffer/regexp
236 (defsubst ediff-get-group-buffer (meta-list)
237 (nth 0 (car meta-list)))
239 (defsubst ediff-get-group-regexp (meta-list)
240 (nth 1 (car meta-list)))
241 ;; group objects
242 (defsubst ediff-get-group-objA (meta-list)
243 (nth 2 (car meta-list)))
244 (defsubst ediff-get-group-objB (meta-list)
245 (nth 3 (car meta-list)))
246 (defsubst ediff-get-group-objC (meta-list)
247 (nth 4 (car meta-list)))
248 (defsubst ediff-get-group-merge-autostore-dir (meta-list)
249 (nth 5 (car meta-list)))
251 ;; ELT is a session meta descriptor (what is being preserved as
252 ;; 'ediff-meta-info)
253 ;; The structure is: (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
254 ;; STATUS is ?I, ?*, ?H
255 ;; OBJA/B/C is (FILENAME EQSTATUS)
256 ;; EQSTATUS is ?= or nil (?= means that this file is equal to some other
257 ;; file in this session)
258 ;; session buffer
259 (defsubst ediff-get-session-buffer (elt)
260 (nth 0 elt))
261 (defsubst ediff-get-session-status (elt)
262 (nth 1 elt))
263 (defsubst ediff-set-session-status (session-info new-status)
264 (setcar (cdr session-info) new-status))
265 ;; session objects
266 (defsubst ediff-get-session-objA (elt)
267 (nth 2 elt))
268 (defsubst ediff-get-session-objB (elt)
269 (nth 3 elt))
270 (defsubst ediff-get-session-objC (elt)
271 (nth 4 elt))
272 (defsubst ediff-get-session-objA-name (elt)
273 (car (nth 2 elt)))
274 (defsubst ediff-get-session-objB-name (elt)
275 (car (nth 3 elt)))
276 (defsubst ediff-get-session-objC-name (elt)
277 (car (nth 4 elt)))
278 ;; equality indicators
279 (defsubst ediff-get-file-eqstatus (elt)
280 (nth 1 elt))
281 (defsubst ediff-set-file-eqstatus (elt value)
282 (setcar (cdr elt) value))
284 ;; The activity marker is either or + (active session, i.e., ediff is currently
285 ;; run in it), or - (finished session, i.e., we've ran ediff in it and then
286 ;; exited). Return nil, if session is neither active nor finished
287 (defun ediff-get-session-activity-marker (session)
288 (let ((session-buf (ediff-get-session-buffer session)))
289 (cond ((null session-buf) nil) ; virgin session
290 ((ediff-buffer-live-p session-buf) ?+) ;active session
291 (t ?-))))
293 ;; checks if the session is a meta session
294 (defun ediff-meta-session-p (session-info)
295 (and (stringp (ediff-get-session-objA-name session-info))
296 (file-directory-p (ediff-get-session-objA-name session-info))
297 (stringp (ediff-get-session-objB-name session-info))
298 (file-directory-p (ediff-get-session-objB-name session-info))
299 (if (stringp (ediff-get-session-objC-name session-info))
300 (file-directory-p (ediff-get-session-objC-name session-info)) t)))
302 ;; set up the keymap in the meta buffer
303 (defun ediff-setup-meta-map()
304 (setq ediff-meta-buffer-map (make-sparse-keymap))
305 (suppress-keymap ediff-meta-buffer-map)
306 (define-key ediff-meta-buffer-map "q" 'ediff-quit-meta-buffer)
307 (define-key ediff-meta-buffer-map "T" 'ediff-toggle-filename-truncation)
308 (define-key ediff-meta-buffer-map "R" 'ediff-show-registry)
309 (define-key ediff-meta-buffer-map "E" 'ediff-documentation)
310 (define-key ediff-meta-buffer-map "v" ediff-meta-action-function)
311 (define-key ediff-meta-buffer-map "\C-m" ediff-meta-action-function)
312 (define-key ediff-meta-buffer-map " " 'ediff-next-meta-item)
313 (define-key ediff-meta-buffer-map "n" 'ediff-next-meta-item)
314 (define-key ediff-meta-buffer-map "\C-?" 'ediff-previous-meta-item)
315 (define-key ediff-meta-buffer-map "p" 'ediff-previous-meta-item)
316 (define-key ediff-meta-buffer-map [delete] 'ediff-previous-meta-item)
317 (define-key ediff-meta-buffer-map [backspace] 'ediff-previous-meta-item)
318 (or (ediff-one-filegroup-metajob)
319 (progn
320 (define-key ediff-meta-buffer-map "=" nil)
321 (define-key ediff-meta-buffer-map "==" 'ediff-meta-mark-equal-files)
322 (define-key ediff-meta-buffer-map "=m" 'ediff-meta-mark-equal-files)
323 (define-key ediff-meta-buffer-map "=h" 'ediff-meta-mark-equal-files)))
324 (if ediff-no-emacs-help-in-control-buffer
325 (define-key ediff-meta-buffer-map "\C-h" 'ediff-previous-meta-item))
326 (if ediff-emacs-p
327 (define-key ediff-meta-buffer-map [mouse-2] ediff-meta-action-function)
328 (define-key ediff-meta-buffer-map [button2] ediff-meta-action-function))
330 (use-local-map ediff-meta-buffer-map)
331 ;; modify ediff-meta-buffer-map here
332 (run-hooks 'ediff-meta-buffer-keymap-setup-hook))
334 (defun ediff-meta-mode ()
335 "This mode controls all operations on Ediff session groups.
336 It is entered through one of the following commands:
337 `ediff-directories'
338 `edirs'
339 `ediff-directories3'
340 `edirs3'
341 `ediff-merge-directories'
342 `edirs-merge'
343 `ediff-merge-directories-with-ancestor'
344 `edirs-merge-with-ancestor'
345 `ediff-directory-revisions'
346 `edir-revisions'
347 `ediff-merge-directory-revisions'
348 `edir-merge-revisions'
349 `ediff-merge-directory-revisions-with-ancestor'
350 `edir-merge-revisions-with-ancestor'
352 Commands:
353 \\{ediff-meta-buffer-map}"
354 (kill-all-local-variables)
355 (setq major-mode 'ediff-meta-mode)
356 (setq mode-name "MetaEdiff"))
359 ;; the keymap for the buffer showing directory differences
360 (suppress-keymap ediff-dir-diffs-buffer-map)
361 (define-key ediff-dir-diffs-buffer-map "q" 'ediff-bury-dir-diffs-buffer)
362 (define-key ediff-dir-diffs-buffer-map " " 'next-line)
363 (define-key ediff-dir-diffs-buffer-map "n" 'next-line)
364 (define-key ediff-dir-diffs-buffer-map "\C-?" 'previous-line)
365 (define-key ediff-dir-diffs-buffer-map "p" 'previous-line)
366 (define-key ediff-dir-diffs-buffer-map [delete] 'previous-line)
367 (define-key ediff-dir-diffs-buffer-map [backspace] 'previous-line)
369 (defun ediff-next-meta-item (count)
370 "Move to the next item in Ediff registry or session group buffer.
371 Moves in circular fashion. With numeric prefix arg, skip this many items."
372 (interactive "p")
373 (or count (setq count 1))
374 (let (overl)
375 (while (< 0 count)
376 (setq count (1- count))
377 (ediff-next-meta-item1)
378 (setq overl (ediff-get-meta-overlay-at-pos (point)))
379 ;; skip invisible ones
380 (while (and overl (ediff-overlay-get overl 'invisible))
381 (ediff-next-meta-item1)
382 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
384 ;; Move to the next meta item
385 (defun ediff-next-meta-item1 ()
386 (let (pos)
387 (setq pos (ediff-next-meta-overlay-start (point)))
388 (if pos (goto-char pos))
389 (if (eq ediff-metajob-name 'ediff-registry)
390 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
391 (search-forward "*Ediff" nil t))
392 (skip-chars-backward "a-zA-Z*"))
393 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
394 (backward-char 1)))))
397 (defun ediff-previous-meta-item (count)
398 "Move to the previous item in Ediff registry or session group buffer.
399 Moves in circular fashion. With numeric prefix arg, skip this many items."
400 (interactive "p")
401 (or count (setq count 1))
402 (let (overl)
403 (while (< 0 count)
404 (setq count (1- count))
405 (ediff-previous-meta-item1)
406 (setq overl (ediff-get-meta-overlay-at-pos (point)))
407 ;; skip invisible ones
408 (while (and overl (ediff-overlay-get overl 'invisible))
409 (ediff-previous-meta-item1)
410 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
412 (defun ediff-previous-meta-item1 ()
413 (let (pos)
414 (setq pos (ediff-previous-meta-overlay-start (point)))
415 ;;; ;; skip deleted
416 ;;; (while (ediff-get-session-status
417 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
418 ;;; (setq pos (ediff-previous-meta-overlay-start pos)))
420 (if pos (goto-char pos))
421 (if (eq ediff-metajob-name 'ediff-registry)
422 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
423 (search-forward "*Ediff" nil t))
424 (skip-chars-backward "a-zA-Z*"))
425 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
426 (backward-char 1)))
429 (defsubst ediff-add-slash-if-directory (dir file)
430 (if (file-directory-p (concat dir file))
431 (file-name-as-directory file)
432 file))
434 (defun ediff-toggle-filename-truncation ()
435 "Toggle truncation of long file names in session group buffers.
436 Set `ediff-meta-truncate-filenames' variable if you want to change the default
437 behavior."
438 (interactive)
439 (setq ediff-meta-truncate-filenames (not ediff-meta-truncate-filenames))
440 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
443 ;; DIR1, DIR2, DIR3 are directories. DIR3 can be nil.
444 ;; OUTPUT-DIR is a directory for auto-storing the results of merge jobs.
445 ;; Can be nil.
446 ;; REGEXP is a regexp used to filter out files in the directories.
447 ;; If a file is a directory in dir1 but not dir2 (or vice versa), it is not
448 ;; included in the intersection. However, a regular file that is a dir in dir3
449 ;; is included, since dir3 files are supposed to be ancestors for merging.
450 ;; Returns a list of the form:
451 ;; ((dir1 dir2 dir3) (f1 f2 f3) (f1 f2 f3) ...)
452 ;; dir3, f3 can be nil if intersecting only 2 directories.
453 ;; If COMPARISON-FUNC is given, use it. Otherwise, use string=
454 ;; DIFF-VAR contains the name of the variable in which to return the
455 ;; difference list (which represents the differences among the contents of
456 ;; directories). The diff list is of the form:
457 ;; ((dir1 dir2 dir3) (file . num) (file . num)...)
458 ;; where num encodes the set of dirs where the file is found:
459 ;; 2 - only dir1; 3 - only dir2; 5 - only dir3; 6 - dir1&2; 10 - dir1&3; etc.
460 (defun ediff-intersect-directories (jobname
461 diff-var regexp dir1 dir2
462 &optional
463 dir3 merge-autostore-dir comparison-func)
464 (setq comparison-func (or comparison-func 'string=))
465 (let (lis1 lis2 lis3 common auxdir1 auxdir2 auxdir3 difflist)
467 (setq auxdir1 (file-name-as-directory dir1)
468 lis1 (directory-files auxdir1 nil regexp)
469 lis1 (delete "." lis1)
470 lis1 (delete ".." lis1)
471 lis1 (mapcar
472 (lambda (elt)
473 (ediff-add-slash-if-directory auxdir1 elt))
474 lis1)
475 auxdir2 (file-name-as-directory dir2)
476 lis2 (mapcar
477 (lambda (elt)
478 (ediff-add-slash-if-directory auxdir2 elt))
479 (directory-files auxdir2 nil regexp)))
481 (if (stringp dir3)
482 (setq auxdir3 (file-name-as-directory dir3)
483 lis3 (mapcar
484 (lambda (elt)
485 (ediff-add-slash-if-directory auxdir3 elt))
486 (directory-files auxdir3 nil regexp))))
488 (if (ediff-nonempty-string-p merge-autostore-dir)
489 (setq merge-autostore-dir
490 (file-name-as-directory merge-autostore-dir)))
491 (setq common (ediff-intersection lis1 lis2 comparison-func))
493 ;; In merge with ancestor jobs, we don't intersect with lis3.
494 ;; If there is no ancestor, we'll offer to merge without the ancestor.
495 ;; So, we intersect with lis3 only when we are doing 3-way file comparison
496 (if (and lis3 (ediff-comparison-metajob3 jobname))
497 (setq common (ediff-intersection common lis3 comparison-func)))
499 ;; copying is needed because sort sorts via side effects
500 (setq common (sort (ediff-copy-list common) 'string-lessp))
502 ;; compute difference list
503 (setq difflist (ediff-set-difference
504 (ediff-union (ediff-union lis1 lis2 comparison-func)
505 lis3
506 comparison-func)
507 common
508 comparison-func)
509 difflist (delete "." difflist)
510 ;; copying is needed because sort sorts via side effects
511 difflist (sort (ediff-copy-list (delete ".." difflist))
512 'string-lessp))
514 (setq difflist (mapcar (lambda (elt) (cons elt 1)) difflist))
516 ;; check for files belonging to lis1/2/3
517 (mapcar (lambda (elt)
518 (if (member (car elt) lis1)
519 (setcdr elt (* (cdr elt) 2)))
520 (if (member (car elt) lis2)
521 (setcdr elt (* (cdr elt) 3)))
522 (if (member (car elt) lis3)
523 (setcdr elt (* (cdr elt) 5)))
525 difflist)
526 (setq difflist (cons (list regexp auxdir1 auxdir2 auxdir3) difflist))
528 ;; return the difference list back to the calling function
529 (set diff-var difflist)
531 ;; return result
532 (cons (list regexp auxdir1 auxdir2 auxdir3 merge-autostore-dir)
533 (mapcar
534 (lambda (elt)
535 (list (concat auxdir1 elt)
536 (concat auxdir2 elt)
537 (if lis3
538 (progn
539 ;; The following is done because:
540 ;; In merging with ancestor, we don't intersect
541 ;; with lis3. So, it is possible that elt is a
542 ;; file in auxdir1/2 but a directory in auxdir3
543 ;; Or elt may not exist in auxdir3 at all.
544 ;; In the first case, we add a slash at the end.
545 ;; In the second case, we insert nil.
546 (setq elt (ediff-add-slash-if-directory auxdir3 elt))
547 (if (file-exists-p (concat auxdir3 elt))
548 (concat auxdir3 elt))))))
549 common))
552 ;; find directory files that are under revision. Include subdirectories, since
553 ;; we may visit them recursively. DIR1 is the directory to inspect.
554 ;; MERGE-AUTOSTORE-DIR is the directory where to auto-store the results of
555 ;; merges. Can be nil.
556 (defun ediff-get-directory-files-under-revision (jobname
557 regexp dir1
558 &optional merge-autostore-dir)
559 (let (lis1 elt common auxdir1)
560 (setq auxdir1 (file-name-as-directory dir1)
561 lis1 (directory-files auxdir1 nil regexp))
563 (if (ediff-nonempty-string-p merge-autostore-dir)
564 (setq merge-autostore-dir
565 (file-name-as-directory merge-autostore-dir)))
567 (while lis1
568 (setq elt (car lis1)
569 lis1 (cdr lis1))
570 ;; take files under revision control
571 (cond ((file-directory-p (concat auxdir1 elt))
572 (setq common
573 (cons (ediff-add-slash-if-directory auxdir1 elt) common)))
574 ((and (featurep 'vc-hooks) (vc-backend (concat auxdir1 elt)))
575 (setq common (cons elt common)))
576 ;; The following two are needed only if vc-hooks isn't loaded.
577 ;; They won't recognize CVS files.
578 ((file-exists-p (concat auxdir1 elt ",v"))
579 (setq common (cons elt common)))
580 ((file-exists-p (concat auxdir1 "RCS/" elt ",v"))
581 (setq common (cons elt common)))
582 ) ; cond
583 ) ; while
585 (setq common (delete "./" common)
586 common (delete "../" common)
587 common (delete "RCS" common)
588 common (delete "CVS" common)
591 ;; copying is needed because sort sorts via side effects
592 (setq common (sort (ediff-copy-list common) 'string-lessp))
594 ;; return result
595 (cons (list regexp auxdir1 nil nil merge-autostore-dir)
596 (mapcar (lambda (elt) (list (concat auxdir1 elt) nil nil))
597 common))
601 ;; If file groups selected by patterns will ever be implemented, this
602 ;; comparison function might become useful.
603 ;;;; uses external variables PAT1 PAT2 to compare str1/2
604 ;;;; patterns must be of the form ???*???? where ??? are strings of chars
605 ;;;; containing no *.
606 ;;(defun ediff-pattern= (str1 str2)
607 ;; (let (pos11 pos12 pos21 pos22 len1 len2)
608 ;; (setq pos11 0
609 ;; len (length epat1)
610 ;; pos12 len)
611 ;; (while (and (< pos11 len) (not (= (aref epat1 pos11) ?*)))
612 ;; (setq pos11 (1+ pos11)))
613 ;; (while (and (> pos12 0) (not (= (aref epat1 (1- pos12)) ?*)))
614 ;; (setq pos12 (1- pos12)))
616 ;; (setq pos21 0
617 ;; len (length epat2)
618 ;; pos22 len)
619 ;; (while (and (< pos21 len) (not (= (aref epat2 pos21) ?*)))
620 ;; (setq pos21 (1+ pos21)))
621 ;; (while (and (> pos22 0) (not (= (aref epat2 (1- pos22)) ?*)))
622 ;; (setq pos22 (1- pos22)))
624 ;; (if (and (> (length str1) pos12) (>= pos12 pos11) (> pos11 -1)
625 ;; (> (length str2) pos22) (>= pos22 pos21) (> pos21 -1))
626 ;; (string= (substring str1 pos11 pos12)
627 ;; (substring str2 pos21 pos22)))
628 ;; ))
631 ;; Prepare meta-buffer in accordance with the argument-function and
632 ;; redraw-function. Must return the created meta-buffer.
633 (defun ediff-prepare-meta-buffer (action-func meta-list
634 meta-buffer-name redraw-function
635 jobname &optional startup-hooks)
636 (let* ((meta-buffer-name
637 (ediff-unique-buffer-name meta-buffer-name "*"))
638 (meta-buffer (get-buffer-create meta-buffer-name)))
639 (ediff-with-current-buffer meta-buffer
641 ;; comes first
642 (ediff-meta-mode)
644 (setq ediff-meta-action-function action-func
645 ediff-meta-redraw-function redraw-function
646 ediff-metajob-name jobname
647 ediff-meta-buffer meta-buffer)
649 ;; comes after ediff-meta-action-function is set
650 (ediff-setup-meta-map)
652 (if (eq ediff-metajob-name 'ediff-registry)
653 (progn
654 (setq ediff-registry-buffer meta-buffer
655 ediff-meta-list meta-list)
656 ;; this func is used only from registry buffer, not from other
657 ;; meta-buffs.
658 (define-key
659 ediff-meta-buffer-map "M" 'ediff-show-meta-buff-from-registry))
660 ;; Initialize the meta list -- don't do this for registry.
662 ;; We prepend '(nil nil) to all elts of meta-list, except the first.
663 ;; The first nil will later be replaced by the session buffer. The
664 ;; second is reserved for session status.
666 ;; (car ediff-meta-list) gets cons'ed with the session group buffer.
667 ;; Also, session objects A/B/C are turned into lists of the form
668 ;; (obj eq-indicator). Eq-indicator is either nil or =. Initialized to
669 ;; nil. If later it is discovered that this file is = to some other
670 ;; file in the same session, eq-indicator is changed to `='.
671 ;; For now, the eq-indicator is used only for 2 and 3-file jobs.
672 (setq ediff-meta-list
673 (cons (cons meta-buffer (car meta-list))
674 (mapcar
675 (lambda (elt)
676 (cons nil
677 (cons nil
678 ;; convert each obj to (obj nil),
679 ;; where nil is the initial value
680 ;; for eq-indicator -- see above
681 (mapcar (lambda (obj) (list obj nil))
682 elt))))
683 (cdr meta-list)))))
685 (or (eq meta-buffer ediff-registry-buffer)
686 (setq ediff-session-registry
687 (cons meta-buffer ediff-session-registry)))
689 ;; redraw-function uses ediff-meta-list
690 (funcall redraw-function ediff-meta-list)
692 ;; set read-only/non-modified
693 (setq buffer-read-only t)
694 (set-buffer-modified-p nil)
696 (run-hooks 'startup-hooks)
698 ;; Arrange to show directory contents differences
699 ;; Must be after run startup-hooks, since ediff-dir-difference-list is
700 ;; set inside these hooks
701 (if (eq action-func 'ediff-filegroup-action)
702 (progn
703 ;; put meta buffer in (car ediff-dir-difference-list)
704 (setq ediff-dir-difference-list
705 (cons (cons meta-buffer (car ediff-dir-difference-list))
706 (cdr ediff-dir-difference-list)))
708 (or (ediff-one-filegroup-metajob jobname)
709 (ediff-draw-dir-diffs ediff-dir-difference-list))
710 (define-key
711 ediff-meta-buffer-map "h" 'ediff-mark-for-hiding-at-pos)
712 (define-key ediff-meta-buffer-map "x" 'ediff-hide-marked-sessions)
713 (define-key
714 ediff-meta-buffer-map "m" 'ediff-mark-for-operation-at-pos)
715 (define-key ediff-meta-buffer-map "u" nil)
716 (define-key
717 ediff-meta-buffer-map "um" 'ediff-unmark-all-for-operation)
718 (define-key
719 ediff-meta-buffer-map "uh" 'ediff-unmark-all-for-hiding)
720 (cond ((ediff-collect-diffs-metajob jobname)
721 (define-key
722 ediff-meta-buffer-map "P" 'ediff-collect-custom-diffs))
723 ((ediff-patch-metajob jobname)
724 (define-key
725 ediff-meta-buffer-map "P" 'ediff-meta-show-patch)))
726 (define-key ediff-meta-buffer-map "^" 'ediff-up-meta-hierarchy)
727 (define-key ediff-meta-buffer-map "D" 'ediff-show-dir-diffs)))
729 (if (eq ediff-metajob-name 'ediff-registry)
730 (run-hooks 'ediff-registry-setup-hook)
731 (run-hooks 'ediff-after-session-group-setup-hook))
732 ) ; eval in meta-buffer
733 meta-buffer))
735 ;; Insert the activity marker for session SESSION in the meta buffer at point
736 ;; The activity marker is either SPC (untouched session), or + (active session,
737 ;; i.e., ediff is currently run in it), or - (finished session, i.e., we've ran
738 ;; ediff in it and then exited)
739 (defun ediff-insert-session-activity-marker-in-meta-buffer (session)
740 (insert
741 (cond ((ediff-get-session-activity-marker session))
742 ;; virgin session
743 (t " "))))
745 ;; Insert session status at point. Status is either ?H (marked for hiding), or
746 ;; ?I (hidden or invalid), or ?* (meaning marked for an operation; currently,
747 ;; such op can only be checking for equality)), or SPC (meaning neither marked
748 ;; nor invalid)
749 (defun ediff-insert-session-status-in-meta-buffer (session)
750 (insert
751 (cond ((ediff-get-session-status session)) ; session has status: ?H, ?I, ?*
752 ;; normal session, no marks or hidings
753 (t " "))))
755 ;; If NEW-MARKER is non-nil, use it to substitute the current activity marker
756 ;; in the meta buffer. If nil, use SPC
757 (defun ediff-replace-session-activity-marker-in-meta-buffer (point new-marker)
758 (let* ((overl (ediff-get-meta-overlay-at-pos point))
759 (session-info (ediff-overlay-get overl 'ediff-meta-info))
760 (activity-marker (ediff-get-session-activity-marker session-info))
761 buffer-read-only)
762 (or new-marker activity-marker (setq new-marker ?\ ))
763 (goto-char (ediff-overlay-start overl))
764 (if (eq (char-after (point)) new-marker)
765 () ; if marker shown in buffer is the same as new-marker, do nothing
766 (insert new-marker)
767 (delete-char 1)
768 (set-buffer-modified-p nil))))
770 ;; If NEW-STATUS is non-nil, use it to substitute the current status marker in
771 ;; the meta buffer. If nil, use SPC
772 (defun ediff-replace-session-status-in-meta-buffer (point new-status)
773 (let* ((overl (ediff-get-meta-overlay-at-pos point))
774 (session-info (ediff-overlay-get overl 'ediff-meta-info))
775 (status (ediff-get-session-status session-info))
776 buffer-read-only)
777 (setq new-status (or new-status status ?\ ))
778 (goto-char (ediff-overlay-start overl))
779 (forward-char 1) ; status is the second char in session record
780 (if (eq (char-after (point)) new-status)
781 () ; if marker shown in buffer is the same as new-marker, do nothing
782 (insert new-status)
783 (delete-char 1)
784 (set-buffer-modified-p nil))))
786 ;; insert all file info in meta buffer for a given session
787 (defun ediff-insert-session-info-in-meta-buffer (session-info sessionNum)
788 (let ((f1 (ediff-get-session-objA session-info))
789 (f2 (ediff-get-session-objB session-info))
790 (f3 (ediff-get-session-objC session-info))
791 (pt (point))
792 (hidden (eq (ediff-get-session-status session-info) ?I)))
793 ;; insert activity marker, i.e., SPC, - or +
794 (ediff-insert-session-activity-marker-in-meta-buffer session-info)
795 ;; insert session status, i.e., *, H
796 (ediff-insert-session-status-in-meta-buffer session-info)
797 (insert " Session " (int-to-string sessionNum) ":\n")
798 (ediff-meta-insert-file-info1 f1)
799 (ediff-meta-insert-file-info1 f2)
800 (ediff-meta-insert-file-info1 f3)
801 (ediff-set-meta-overlay pt (point) session-info sessionNum hidden)))
804 ;; this is a setup function for ediff-directories
805 ;; must return meta-buffer
806 (defun ediff-redraw-directory-group-buffer (meta-list)
807 ;; extract directories
808 (let ((meta-buf (ediff-get-group-buffer meta-list))
809 (empty t)
810 (sessionNum 0)
811 regexp elt merge-autostore-dir
812 point tmp-list buffer-read-only)
813 (ediff-with-current-buffer meta-buf
814 (setq point (point))
815 (erase-buffer)
816 ;; delete phony overlays that used to represent sessions before the buff
817 ;; was redrawn
818 (ediff-cond-compile-for-xemacs-or-emacs
819 (map-extents 'delete-extent) ; xemacs
820 (mapcar 'delete-overlay (overlays-in 1 1)) ; emacs
823 (insert (format ediff-meta-buffer-message
824 (ediff-abbrev-jobname ediff-metajob-name)))
826 (setq regexp (ediff-get-group-regexp meta-list)
827 merge-autostore-dir
828 (ediff-get-group-merge-autostore-dir meta-list))
830 (cond ((ediff-collect-diffs-metajob)
831 (insert
832 " P:\tcollect custom diffs of all marked sessions\n"))
833 ((ediff-patch-metajob)
834 (insert
835 " P:\tshow patch appropriately for the context (session or group)\n")))
836 (insert
837 " ^:\tshow parent session group\n")
838 (or (ediff-one-filegroup-metajob)
839 (insert
840 " D:\tshow differences among directories\n"
841 " ==:\tfor each session, show which files are identical\n"
842 " =h:\tlike ==, but also marks those sessions for hiding\n"
843 " =m:\tlike ==, but also marks those sessions for operation\n\n"))
845 (insert "\n")
846 (if (and (stringp regexp) (> (length regexp) 0))
847 (insert
848 (format "*** Filter-through regular expression: %s\n" regexp)))
849 (ediff-insert-dirs-in-meta-buffer meta-list)
850 (if (and ediff-autostore-merges (ediff-merge-metajob)
851 (ediff-nonempty-string-p merge-autostore-dir))
852 (insert (format
853 "\nMerge results are automatically stored in:\n\t%s\n"
854 merge-autostore-dir)))
855 (insert "\n
856 Size Last modified Name
857 ----------------------------------------------
861 ;; discard info on directories and regexp
862 (setq meta-list (cdr meta-list)
863 tmp-list meta-list)
864 (while (and tmp-list empty)
865 (if (and (car tmp-list)
866 (not (eq (ediff-get-session-status (car tmp-list)) ?I)))
867 (setq empty nil))
868 (setq tmp-list (cdr tmp-list)))
870 (if empty
871 (insert
872 " ****** ****** This session group has no members\n"))
874 ;; now organize file names like this:
875 ;; use-mark sizeA dateA sizeB dateB filename
876 ;; make sure directories are displayed with a trailing slash.
877 (while meta-list
878 (setq elt (car meta-list)
879 meta-list (cdr meta-list)
880 sessionNum (1+ sessionNum))
881 (if (eq (ediff-get-session-status elt) ?I)
883 (ediff-insert-session-info-in-meta-buffer elt sessionNum)))
884 (set-buffer-modified-p nil)
885 (goto-char point)
886 meta-buf)))
888 (defun ediff-update-markers-in-dir-meta-buffer (meta-list)
889 (let ((meta-buf (ediff-get-group-buffer meta-list))
890 session-info point overl buffer-read-only)
891 (ediff-with-current-buffer meta-buf
892 (setq point (point))
893 (goto-char (point-min))
894 (ediff-next-meta-item1)
895 (while (not (bobp))
896 (setq session-info (ediff-get-meta-info meta-buf (point) 'no-error)
897 overl (ediff-get-meta-overlay-at-pos (point)))
898 (if session-info
899 (progn
900 (cond ((eq (ediff-get-session-status session-info) ?I)
901 ;; Do hiding
902 (if overl (ediff-overlay-put overl 'invisible t)))
903 ((and (eq (ediff-get-session-status session-info) ?H)
904 overl (ediff-overlay-get overl 'invisible))
905 ;; Do unhiding
906 (ediff-overlay-put overl 'invisible nil))
907 (t (ediff-replace-session-activity-marker-in-meta-buffer
908 (point)
909 (ediff-get-session-activity-marker session-info))
910 (ediff-replace-session-status-in-meta-buffer
911 (point)
912 (ediff-get-session-status session-info))))))
913 (ediff-next-meta-item1) ; advance to the next item
914 ) ; end while
915 (set-buffer-modified-p nil)
916 (goto-char point))
917 meta-buf))
919 (defun ediff-update-session-marker-in-dir-meta-buffer (session-num)
920 (let (buffer-meta-overlays session-info overl buffer-read-only)
921 (setq overl
922 (ediff-cond-compile-for-xemacs-or-emacs
923 (map-extents ; xemacs
924 (lambda (ext maparg)
925 (if (and
926 (ediff-overlay-get ext 'ediff-meta-info)
927 (eq (ediff-overlay-get ext 'ediff-meta-session-number)
928 session-num))
929 ext)))
930 ;; Emacs doesn't have map-extents, so try harder
931 ;; Splice overlay lists to get all buffer overlays
932 (progn
933 (setq buffer-meta-overlays (overlay-lists)
934 buffer-meta-overlays (append (car buffer-meta-overlays)
935 (cdr buffer-meta-overlays)))
936 (car
937 (delq nil
938 (mapcar
939 (lambda (overl)
940 (if (and
941 (ediff-overlay-get overl 'ediff-meta-info)
942 (eq (ediff-overlay-get
943 overl 'ediff-meta-session-number)
944 session-num))
945 overl))
946 buffer-meta-overlays))))
948 (or overl
949 (error
950 "Bug in ediff-update-session-marker-in-dir-meta-buffer: no overlay with given number %S"
951 session-num))
952 (setq session-info (ediff-overlay-get overl 'ediff-meta-info))
953 (goto-char (ediff-overlay-start overl))
954 (ediff-replace-session-activity-marker-in-meta-buffer
955 (point)
956 (ediff-get-session-activity-marker session-info))
957 (ediff-replace-session-status-in-meta-buffer
958 (point)
959 (ediff-get-session-status session-info)))
960 (ediff-next-meta-item1))
964 ;; Check if this is a problematic session.
965 ;; Return nil if not. Otherwise, return symbol representing the problem
966 ;; At present, problematic sessions occur only in -with-ancestor comparisons
967 ;; when the ancestor is a directory rather than a file, or when there is no
968 ;; suitable ancestor file in the ancestor directory
969 (defun ediff-problematic-session-p (session)
970 (let ((f1 (ediff-get-session-objA-name session))
971 (f2 (ediff-get-session-objB-name session))
972 (f3 (ediff-get-session-objC-name session)))
973 (cond ((and (stringp f1) (not (file-directory-p f1))
974 (stringp f2) (not (file-directory-p f2))
975 ;; either invalid file name or a directory
976 (or (not (stringp f3)) (file-directory-p f3))
977 (ediff-ancestor-metajob))
978 ;; more may be added later
979 'ancestor-is-dir)
980 (t nil))))
982 (defun ediff-meta-insert-file-info1 (fileinfo)
983 (let ((fname (car fileinfo))
984 (feq (ediff-get-file-eqstatus fileinfo))
985 (max-filename-width (if ediff-meta-truncate-filenames
986 (- (window-width) 41)
987 500))
988 file-modtime file-size)
989 (cond ((not (stringp fname)) (setq file-size -2)) ; file doesn't exits
990 ((ediff-listable-file fname)
991 (if (file-exists-p fname)
992 ;; set real size and modtime
993 (setq file-size (ediff-file-size fname)
994 file-modtime (ediff-file-modtime fname))
995 (setq file-size -2))) ; file doesn't exist
996 ( t (setq file-size -1))) ; remote file
997 (if (stringp fname)
998 (insert
999 (format
1000 "%s %s %-20s %s\n"
1001 (if feq "=" " ") ; equality indicator
1002 (format "%10s" (cond ((= file-size -1) "--")
1003 ((< file-size -1) "--")
1004 (t file-size)))
1005 (cond ((= file-size -1) "*remote file*")
1006 ((< file-size -1) "*file doesn't exist*")
1007 (t (ediff-format-date (decode-time file-modtime))))
1009 ;; dir names in meta lists have training slashes, so we just
1010 ;; abbreviate the file name, if file exists
1011 (if (and (not (stringp fname)) (< file-size -1))
1012 "-------" ; file doesn't exist
1013 (ediff-truncate-string-left
1014 (ediff-abbreviate-file-name fname)
1015 max-filename-width)))))))
1017 (defconst ediff-months '((1 . "Jan") (2 . "Feb") (3 . "Mar") (4 . "Apr")
1018 (5 . "May") (6 . "Jun") (7 . "Jul") (8 . "Aug")
1019 (9 . "Sep") (10 . "Oct") (11 . "Nov") (12 . "Dec"))
1020 "Months' associative array.")
1022 ;; returns 2char string
1023 (defsubst ediff-fill-leading-zero (num)
1024 (if (< num 10)
1025 (format "0%d" num)
1026 (number-to-string num)))
1028 ;; TIME is like the output of decode-time
1029 (defun ediff-format-date (time)
1030 (format "%s %2d %4d %s:%s:%s"
1031 (cdr (assoc (nth 4 time) ediff-months)) ; month
1032 (nth 3 time) ; day
1033 (nth 5 time) ; year
1034 (ediff-fill-leading-zero (nth 2 time)) ; hour
1035 (ediff-fill-leading-zero (nth 1 time)) ; min
1036 (ediff-fill-leading-zero (nth 0 time)) ; sec
1039 ;; Draw the directories
1040 (defun ediff-insert-dirs-in-meta-buffer (meta-list)
1041 (let* ((dir1 (ediff-abbreviate-file-name (ediff-get-group-objA meta-list)))
1042 (dir2 (ediff-get-group-objB meta-list))
1043 (dir2 (if (stringp dir2) (ediff-abbreviate-file-name dir2)))
1044 (dir3 (ediff-get-group-objC meta-list))
1045 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3))))
1046 (insert "*** Directory A: " dir1 "\n")
1047 (if dir2 (insert "*** Directory B: " dir2 "\n"))
1048 (if dir3 (insert "*** Directory C: " dir3 "\n"))
1049 (insert "\n")))
1051 (defun ediff-draw-dir-diffs (diff-list)
1052 (if (null diff-list) (error "Lost difference info on these directories"))
1053 (let* ((buf-name (ediff-unique-buffer-name
1054 "*Ediff File Group Differences" "*"))
1055 (regexp (ediff-get-group-regexp diff-list))
1056 (dir1 (ediff-abbreviate-file-name (ediff-get-group-objA diff-list)))
1057 (dir2 (ediff-abbreviate-file-name (ediff-get-group-objB diff-list)))
1058 (dir3 (ediff-get-group-objC diff-list))
1059 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3)))
1060 (meta-buf (ediff-get-group-buffer diff-list))
1061 (underline (make-string 26 ?-))
1062 file code
1063 buffer-read-only)
1064 ;; skip the directory part
1065 (setq diff-list (cdr diff-list))
1066 (setq ediff-dir-diffs-buffer (get-buffer-create buf-name))
1067 (ediff-with-current-buffer ediff-dir-diffs-buffer
1068 (use-local-map ediff-dir-diffs-buffer-map)
1069 (erase-buffer)
1070 (setq ediff-meta-buffer meta-buf)
1071 (insert "\t\t*** Directory Differences ***\n")
1072 (insert "
1073 Useful commands:
1074 `q': hide this buffer
1075 n,SPC: next line
1076 p,DEL: previous line\n\n")
1078 (if (and (stringp regexp) (> (length regexp) 0))
1079 (insert
1080 (format "\n*** Filter-through regular expression: %s\n" regexp)))
1081 (insert "\n")
1082 (insert (format "\n%-27s%-26s"
1083 (ediff-truncate-string-left
1084 (ediff-abbreviate-file-name
1085 (file-name-as-directory dir1))
1087 (ediff-truncate-string-left
1088 (ediff-abbreviate-file-name
1089 (file-name-as-directory dir2))
1090 25)))
1091 (if dir3
1092 (insert (format " %-25s\n"
1093 (ediff-truncate-string-left
1094 (ediff-abbreviate-file-name
1095 (file-name-as-directory dir3))
1096 25)))
1097 (insert "\n"))
1098 (insert (format "%s%s" underline underline))
1099 (if (stringp dir3)
1100 (insert (format "%s\n\n" underline))
1101 (insert "\n\n"))
1103 (if (null diff-list)
1104 (insert "\n\t*** No differences ***\n"))
1106 (while diff-list
1107 (setq file (car (car diff-list))
1108 code (cdr (car diff-list))
1109 diff-list (cdr diff-list))
1110 (if (= (mod code 2) 0) ; dir1
1111 (insert (format "%-27s"
1112 (ediff-truncate-string-left
1113 (ediff-abbreviate-file-name
1114 (if (file-directory-p (concat dir1 file))
1115 (file-name-as-directory file)
1116 file))
1117 24)))
1118 (insert (format "%-27s" "---")))
1119 (if (= (mod code 3) 0) ; dir2
1120 (insert (format "%-26s"
1121 (ediff-truncate-string-left
1122 (ediff-abbreviate-file-name
1123 (if (file-directory-p (concat dir2 file))
1124 (file-name-as-directory file)
1125 file))
1126 24)))
1127 (insert (format "%-26s" "---")))
1128 (if (stringp dir3)
1129 (if (= (mod code 5) 0) ; dir3
1130 (insert (format " %-25s"
1131 (ediff-truncate-string-left
1132 (ediff-abbreviate-file-name
1133 (if (file-directory-p (concat dir3 file))
1134 (file-name-as-directory file)
1135 file))
1136 24)))
1137 (insert (format " %-25s" "---"))))
1138 (insert "\n"))
1139 (setq buffer-read-only t)
1140 (set-buffer-modified-p nil)) ; eval in diff buffer
1143 (defun ediff-bury-dir-diffs-buffer ()
1144 "Bury the directory difference buffer. Display the meta buffer instead."
1145 (interactive)
1146 (let ((buf ediff-meta-buffer)
1147 wind)
1148 (bury-buffer)
1149 (if (setq wind (ediff-get-visible-buffer-window buf))
1150 (select-window wind)
1151 (set-window-buffer (selected-window) buf))))
1153 ;; executes in dir session group buffer
1154 ;; show buffer differences
1155 (defun ediff-show-dir-diffs ()
1156 "Display differences among the directories involved in session group."
1157 (interactive)
1158 (if (ediff-one-filegroup-metajob)
1159 (error "This command is inapplicable in the present context"))
1160 (or (ediff-buffer-live-p ediff-dir-diffs-buffer)
1161 (ediff-draw-dir-diffs ediff-dir-difference-list))
1162 (let ((buf ediff-dir-diffs-buffer))
1163 (other-window 1)
1164 (set-window-buffer (selected-window) buf)
1165 (goto-char (point-min))))
1167 (defun ediff-up-meta-hierarchy ()
1168 "Go to the parent session group buffer."
1169 (interactive)
1170 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1171 (ediff-show-meta-buffer
1172 ediff-parent-meta-buffer ediff-meta-session-number)
1173 (error "This session group has no parent")))
1176 ;; argument is ignored
1177 (defun ediff-redraw-registry-buffer (&optional ignore)
1178 (ediff-with-current-buffer ediff-registry-buffer
1179 (let ((point (point))
1180 elt bufAname bufBname bufCname cur-diff total-diffs pt
1181 job-name meta-list registry-list buffer-read-only)
1182 (erase-buffer)
1183 ;; delete phony overlays that used to represent sessions before the buff
1184 ;; was redrawn
1185 (ediff-cond-compile-for-xemacs-or-emacs
1186 (map-extents 'delete-extent) ; xemacs
1187 (mapcar 'delete-overlay (overlays-in 1 1)) ; emacs
1190 (insert "This is a registry of all active Ediff sessions.
1192 Useful commands:
1193 button2, `v', RET over a session record: switch to that session
1194 M over a session record: display the associated session group
1195 R in any Ediff session: display session registry
1196 n,SPC: next session
1197 p,DEL: previous session
1198 E: browse Ediff on-line manual
1199 q: bury registry
1202 \t\tActive Ediff Sessions:
1203 \t\t----------------------
1206 ;; purge registry list from dead buffers
1207 (mapcar (lambda (elt)
1208 (if (not (ediff-buffer-live-p elt))
1209 (setq ediff-session-registry
1210 (delq elt ediff-session-registry))))
1211 ediff-session-registry)
1213 (if (null ediff-session-registry)
1214 (insert " ******* No active Ediff sessions *******\n"))
1216 (setq registry-list ediff-session-registry)
1217 (while registry-list
1218 (setq elt (car registry-list)
1219 registry-list (cdr registry-list))
1221 (if (ediff-buffer-live-p elt)
1222 (if (ediff-with-current-buffer elt
1223 (setq job-name ediff-metajob-name
1224 meta-list ediff-meta-list)
1225 (and ediff-metajob-name
1226 (not (eq ediff-metajob-name 'ediff-registry))))
1227 (progn
1228 (setq pt (point))
1229 (insert (format " *group*\t%s: %s\n"
1230 (buffer-name elt)
1231 (ediff-abbrev-jobname job-name)))
1232 (insert (format "\t\t %s %s %s\n"
1233 (ediff-abbreviate-file-name
1234 (ediff-get-group-objA meta-list))
1235 (ediff-abbreviate-file-name
1236 (if (stringp
1237 (ediff-get-group-objB meta-list))
1238 (ediff-get-group-objB meta-list)
1239 ""))
1240 (ediff-abbreviate-file-name
1241 (if (stringp
1242 (ediff-get-group-objC meta-list))
1243 (ediff-get-group-objC meta-list)
1244 ""))))
1245 (ediff-set-meta-overlay pt (point) elt))
1246 (progn
1247 (ediff-with-current-buffer elt
1248 (setq bufAname (if (ediff-buffer-live-p ediff-buffer-A)
1249 (buffer-name ediff-buffer-A)
1250 "!!!killed buffer!!!")
1251 bufBname (if (ediff-buffer-live-p ediff-buffer-B)
1252 (buffer-name ediff-buffer-B)
1253 "!!!killed buffer!!!")
1254 bufCname (cond ((not (ediff-3way-job))
1256 ((ediff-buffer-live-p ediff-buffer-C)
1257 (buffer-name ediff-buffer-C))
1258 (t "!!!killed buffer!!!")))
1259 (setq total-diffs (format "%-4d" ediff-number-of-differences)
1260 cur-diff
1261 (cond ((= ediff-current-difference -1) " _")
1262 ((= ediff-current-difference
1263 ediff-number-of-differences)
1264 " $")
1265 (t (format
1266 "%4d" (1+ ediff-current-difference))))
1267 job-name ediff-job-name))
1268 ;; back in the meta buf
1269 (setq pt (point))
1270 (insert cur-diff "/" total-diffs "\t"
1271 (buffer-name elt)
1272 (format ": %s" (ediff-abbrev-jobname job-name)))
1273 (insert
1274 "\n\t\t " bufAname " " bufBname " " bufCname "\n")
1275 (ediff-set-meta-overlay pt (point) elt))))
1276 ) ; while
1277 (set-buffer-modified-p nil)
1278 (goto-char point)
1281 ;; Sets overlay around a meta record with 'ediff-meta-info property PROP
1282 ;; If optional SESSION-NUMBER, make it a property of the overlay,
1283 ;; ediff-meta-session-number
1284 ;; PROP is either the ctl or meta buffer (used when we work with the registry)
1285 ;; or a session meta descriptor of the form
1286 ;; (SESSION-CTL-BUFFER STATUS OBJA OBJB OBJC)
1287 (defun ediff-set-meta-overlay (b e prop &optional session-number hidden)
1288 (let (overl)
1289 (setq overl (ediff-make-overlay b e))
1290 (if ediff-emacs-p
1291 (ediff-overlay-put overl 'mouse-face 'highlight)
1292 (ediff-overlay-put overl 'highlight t))
1293 (ediff-overlay-put overl 'ediff-meta-info prop)
1294 (ediff-overlay-put overl 'invisible hidden)
1295 (if (numberp session-number)
1296 (ediff-overlay-put overl 'ediff-meta-session-number session-number))))
1298 (defun ediff-mark-for-hiding-at-pos (unmark)
1299 "Mark session for hiding. With prefix arg, unmark."
1300 (interactive "P")
1301 (let* ((pos (ediff-event-point last-command-event))
1302 (meta-buf (ediff-event-buffer last-command-event))
1303 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1304 (info (ediff-get-meta-info meta-buf pos))
1305 (session-number (ediff-get-session-number-at-pos pos)))
1306 (ediff-mark-session-for-hiding info unmark)
1307 (ediff-next-meta-item 1)
1308 (save-excursion
1309 (ediff-update-meta-buffer meta-buf nil session-number))
1312 ;; Returns whether session was marked or unmarked
1313 (defun ediff-mark-session-for-hiding (info unmark)
1314 (let ((session-buf (ediff-get-session-buffer info))
1315 ignore)
1316 (cond ((eq unmark 'mark) (setq unmark nil))
1317 ((eq (ediff-get-session-status info) ?H) (setq unmark t))
1318 (unmark ; says unmark, but the marker is different from H
1319 (setq ignore t)))
1320 (cond (ignore)
1321 (unmark (ediff-set-session-status info nil))
1322 ;;; (if (ediff-buffer-live-p session-buf)
1323 ;;; (error "Can't hide active session, %s" (buffer-name session-buf)))
1324 (t (ediff-set-session-status info ?H))))
1325 unmark)
1328 (defun ediff-mark-for-operation-at-pos (unmark)
1329 "Mark session for a group operation. With prefix arg, unmark."
1330 (interactive "P")
1331 (let* ((pos (ediff-event-point last-command-event))
1332 (meta-buf (ediff-event-buffer last-command-event))
1333 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1334 (info (ediff-get-meta-info meta-buf pos))
1335 (session-number (ediff-get-session-number-at-pos pos)))
1336 (ediff-mark-session-for-operation info unmark)
1337 (ediff-next-meta-item 1)
1338 (save-excursion
1339 (ediff-update-meta-buffer meta-buf nil session-number))
1343 ;; returns whether session was unmarked.
1344 ;; remember: this is a toggle op
1345 (defun ediff-mark-session-for-operation (info unmark)
1346 (let (ignore)
1347 (cond ((eq unmark 'mark) (setq unmark nil))
1348 ((eq (ediff-get-session-status info) ?*) (setq unmark t))
1349 (unmark ; says unmark, but the marker is different from *
1350 (setq ignore t)))
1351 (cond (ignore)
1352 (unmark (ediff-set-session-status info nil))
1353 (t (ediff-set-session-status info ?*))))
1354 unmark)
1357 (defun ediff-hide-marked-sessions (unhide)
1358 "Hide marked sessions. With prefix arg, unhide."
1359 (interactive "P")
1360 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1361 (meta-list (cdr ediff-meta-list))
1362 (from (if unhide ?I ?H))
1363 (to (if unhide ?H ?I))
1364 (numMarked 0)
1365 active-sessions-exist session-buf elt)
1366 (while meta-list
1367 (setq elt (car meta-list)
1368 meta-list (cdr meta-list)
1369 session-buf (ediff-get-session-buffer elt))
1371 (if (eq (ediff-get-session-status elt) from)
1372 (progn
1373 (setq numMarked (1+ numMarked))
1374 (if (and (eq to ?I) (buffer-live-p session-buf))
1375 ;; shouldn't hide active sessions
1376 (setq active-sessions-exist t)
1377 (ediff-set-session-status elt to)))))
1378 (if (> numMarked 0)
1379 (ediff-update-meta-buffer grp-buf 'must-redraw)
1380 (beep)
1381 (if unhide
1382 (message "Nothing to reveal...")
1383 (message "Nothing to hide...")))
1384 (if active-sessions-exist
1385 (message "Note: Ediff didn't hide active sessions!"))
1388 ;; Apply OPERATION to marked sessions. Operation expects one argument of type
1389 ;; meta-list member (not the first one), i.e., a regular session description.
1390 ;; Returns number of marked sessions on which operation was performed
1391 (defun ediff-operate-on-marked-sessions (operation)
1392 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1393 (meta-list (cdr ediff-meta-list))
1394 (marksym ?*)
1395 (numMarked 0)
1396 (sessionNum 0)
1397 (diff-buffer ediff-meta-diff-buffer)
1398 session-buf elt)
1399 (while meta-list
1400 (setq elt (car meta-list)
1401 meta-list (cdr meta-list)
1402 sessionNum (1+ sessionNum))
1403 (cond ((eq (ediff-get-session-status elt) marksym)
1404 (save-excursion
1405 (setq numMarked (1+ numMarked))
1406 (funcall operation elt sessionNum)))
1407 ((and (ediff-meta-session-p elt)
1408 (ediff-buffer-live-p
1409 (setq session-buf (ediff-get-session-buffer elt))))
1410 (setq numMarked
1411 (+ numMarked
1412 (ediff-with-current-buffer session-buf
1413 ;; pass meta-diff along
1414 (setq ediff-meta-diff-buffer diff-buffer)
1415 ;; collect diffs in child group
1416 (ediff-operate-on-marked-sessions operation)))))))
1417 (ediff-update-meta-buffer grp-buf 'must-redraw) ; just in case
1418 numMarked
1421 (defun ediff-append-custom-diff (session sessionNum)
1422 (or (ediff-collect-diffs-metajob)
1423 (error "Hmm, I'd hate to do it to you ..."))
1424 (let ((session-buf (ediff-get-session-buffer session))
1425 (meta-diff-buff ediff-meta-diff-buffer)
1426 (metajob ediff-metajob-name)
1427 tmp-buf custom-diff-buf)
1428 (if (ediff-buffer-live-p session-buf)
1429 (ediff-with-current-buffer session-buf
1430 (if (eq ediff-control-buffer session-buf) ; individual session
1431 (progn
1432 (ediff-compute-custom-diffs-maybe)
1433 (setq custom-diff-buf ediff-custom-diff-buffer)))))
1435 (or (ediff-buffer-live-p meta-diff-buff)
1436 (error "Ediff: something wrong--no multiple diffs buffer"))
1438 (cond ((ediff-buffer-live-p custom-diff-buf)
1439 (save-excursion
1440 (set-buffer meta-diff-buff)
1441 (goto-char (point-max))
1442 (insert-buffer custom-diff-buf)
1443 (insert "\n")))
1444 ((memq metajob '(ediff-directories
1445 ediff-merge-directories
1446 ediff-merge-directories-with-ancestor))
1447 ;; get diffs by calling shell command on ediff-custom-diff-program
1448 (save-excursion
1449 (set-buffer (setq tmp-buf (get-buffer-create ediff-tmp-buffer)))
1450 (erase-buffer)
1451 (shell-command
1452 (format "%s %s %s %s"
1453 ediff-custom-diff-program ediff-custom-diff-options
1454 (ediff-get-session-objA-name session)
1455 (ediff-get-session-objB-name session))
1457 (save-excursion
1458 (set-buffer meta-diff-buff)
1459 (goto-char (point-max))
1460 (insert-buffer tmp-buf)
1461 (insert "\n")))
1463 (error "Can't make context diff for Session %d" sessionNum )))
1466 (defun ediff-collect-custom-diffs ()
1467 "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'.
1468 This operation is defined only for `ediff-directories' and
1469 `ediff-directory-revisions', since its intent is to produce
1470 multifile patches. For `ediff-directory-revisions', we insist that
1471 all marked sessions must be active."
1472 (interactive)
1473 (or (ediff-buffer-live-p ediff-meta-diff-buffer)
1474 (setq ediff-meta-diff-buffer
1475 (get-buffer-create
1476 (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
1477 (ediff-with-current-buffer ediff-meta-diff-buffer
1478 (erase-buffer))
1479 (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
1480 ;; did something
1481 (progn
1482 (display-buffer ediff-meta-diff-buffer 'not-this-window)
1483 (ediff-with-current-buffer ediff-meta-diff-buffer
1484 (set-buffer-modified-p nil)
1485 (setq buffer-read-only t)))
1486 (beep)
1487 (message "No marked sessions found")))
1489 (defun ediff-meta-show-patch ()
1490 "Show the multi-file patch associated with this group session."
1491 (interactive)
1492 (let* ((pos (ediff-event-point last-command-event))
1493 (meta-buf (ediff-event-buffer last-command-event))
1494 (info (ediff-get-meta-info meta-buf pos 'noerror))
1495 (patchbuffer ediff-meta-patchbufer))
1496 (if (ediff-buffer-live-p patchbuffer)
1497 (ediff-with-current-buffer patchbuffer
1498 (save-restriction
1499 (if (not info)
1500 (widen)
1501 (narrow-to-region
1502 (ediff-get-session-objB-name info)
1503 (ediff-get-session-objC-name info)))
1504 (set-buffer (get-buffer-create ediff-tmp-buffer))
1505 (erase-buffer)
1506 (insert-buffer patchbuffer)
1507 (display-buffer ediff-tmp-buffer 'not-this-window)
1509 (error "The patch buffer wasn't found"))))
1512 ;; This function executes in meta buffer. It knows where event happened.
1513 (defun ediff-filegroup-action ()
1514 "Execute appropriate action for a selected session."
1515 (interactive)
1516 (let* ((pos (ediff-event-point last-command-event))
1517 (meta-buf (ediff-event-buffer last-command-event))
1518 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1519 (info (ediff-get-meta-info meta-buf pos))
1520 (session-buf (ediff-get-session-buffer info))
1521 (session-number (ediff-get-session-number-at-pos pos meta-buf))
1522 merge-autostore-dir file1 file2 file3 regexp)
1524 (setq file1 (ediff-get-session-objA-name info)
1525 file2 (ediff-get-session-objB-name info)
1526 file3 (ediff-get-session-objC-name info))
1528 ;; make sure we don't start on hidden sessions
1529 ;; ?H means marked for hiding. ?I means invalid (hidden).
1530 (if (memq (ediff-get-session-status info) '(?I))
1531 (progn
1532 (beep)
1533 (if (y-or-n-p "This session is marked as hidden, unmark? ")
1534 (progn
1535 (ediff-set-session-status info nil)
1536 (ediff-update-meta-buffer meta-buf nil session-number))
1537 (error "Aborted"))))
1539 (ediff-with-current-buffer meta-buf
1540 (setq merge-autostore-dir
1541 (ediff-get-group-merge-autostore-dir ediff-meta-list))
1542 (goto-char pos) ; if the user clicked on session--move point there
1543 ;; First handle sessions involving directories (which are themselves
1544 ;; session groups)
1545 ;; After that handle individual sessions
1546 (cond ((ediff-meta-session-p info)
1547 ;; do ediff/ediff-merge on subdirectories
1548 (if (ediff-buffer-live-p session-buf)
1549 (ediff-show-meta-buffer session-buf)
1550 (setq regexp (read-string "Filter through regular expression: "
1551 nil 'ediff-filtering-regexp-history))
1552 (ediff-directories-internal
1553 file1 file2 file3 regexp
1554 ediff-session-action-function
1555 ediff-metajob-name
1556 ;; make it update (car info) after startup
1557 `(list (lambda ()
1558 ;; child session group should know its parent
1559 (setq ediff-parent-meta-buffer
1560 (quote ,ediff-meta-buffer)
1561 ediff-meta-session-number
1562 ,session-number)
1563 ;; and parent will know its child
1564 (setcar (quote ,info) ediff-meta-buffer))))))
1566 ;; Do ediff-revision on a subdirectory
1567 ((and (ediff-one-filegroup-metajob)
1568 (ediff-revision-metajob)
1569 (file-directory-p file1))
1570 (if (ediff-buffer-live-p session-buf)
1571 (ediff-show-meta-buffer session-buf)
1572 (setq regexp (read-string "Filter through regular expression: "
1573 nil 'ediff-filtering-regexp-history))
1574 (ediff-directory-revisions-internal
1575 file1 regexp
1576 ediff-session-action-function ediff-metajob-name
1577 ;; make it update (car info) after startup
1578 `(list (lambda ()
1579 ;; child session group should know its parent and
1580 ;; its number
1581 (setq ediff-parent-meta-buffer
1582 (quote ,ediff-meta-buffer)
1583 ediff-meta-session-number
1584 ,session-number)
1585 ;; and parent will know its child
1586 (setcar (quote ,info) ediff-meta-buffer))))))
1588 ;; From here on---only individual session handlers
1590 ;; handle an individual session with a live control buffer
1591 ((ediff-buffer-live-p session-buf)
1592 (ediff-with-current-buffer session-buf
1593 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1594 (ediff-recenter 'no-rehighlight)))
1596 ((ediff-problematic-session-p info)
1597 (beep)
1598 (if (y-or-n-p
1599 "This session has no ancestor. Merge without the ancestor? ")
1600 (ediff-merge-files
1601 file1 file2
1602 ;; provide startup hooks
1603 `(list (lambda ()
1604 (add-hook
1605 'ediff-after-quit-hook-internal
1606 (lambda ()
1607 (if (ediff-buffer-live-p ,(current-buffer))
1608 (ediff-show-meta-buffer
1609 ,(current-buffer) ,session-number)))
1610 nil 'local)
1611 (setq ediff-meta-buffer ,(current-buffer)
1612 ediff-meta-session-number
1613 ,session-number)
1614 (setq ediff-merge-store-file
1615 ,(if (ediff-nonempty-string-p
1616 merge-autostore-dir)
1617 (concat
1618 merge-autostore-dir
1619 ediff-merge-filename-prefix
1620 (file-name-nondirectory file1))
1622 ;; make ediff-startup pass
1623 ;; ediff-control-buffer back to the meta
1624 ;; level; see below
1625 (setcar
1626 (quote ,info) ediff-control-buffer))))
1627 (error "Aborted")))
1628 ((ediff-one-filegroup-metajob) ; needs 1 file arg
1629 (funcall ediff-session-action-function
1630 file1
1631 ;; provide startup hooks
1632 `(list (lambda ()
1633 (add-hook
1634 'ediff-after-quit-hook-internal
1635 (lambda ()
1636 (if (ediff-buffer-live-p
1637 ,(current-buffer))
1638 (ediff-show-meta-buffer
1639 ,(current-buffer)
1640 ,session-number)))
1641 nil 'local)
1642 (setq ediff-meta-buffer ,(current-buffer)
1643 ediff-meta-session-number
1644 ,session-number)
1645 (setq ediff-merge-store-file
1646 ,(if (ediff-nonempty-string-p
1647 merge-autostore-dir)
1648 (concat
1649 merge-autostore-dir
1650 ediff-merge-filename-prefix
1651 (file-name-nondirectory file1))) )
1652 ;; make ediff-startup pass
1653 ;; ediff-control-buffer back to the meta
1654 ;; level; see below
1655 (setcar
1656 (quote ,info) ediff-control-buffer)))))
1657 ((not (ediff-metajob3)) ; need 2 file args
1658 (funcall ediff-session-action-function
1659 file1 file2
1660 ;; provide startup hooks
1661 `(list (lambda ()
1662 (add-hook
1663 'ediff-after-quit-hook-internal
1664 (lambda ()
1665 (if (ediff-buffer-live-p
1666 ,(current-buffer))
1667 (ediff-show-meta-buffer
1668 ,(current-buffer)
1669 ,session-number)))
1670 nil 'local)
1671 (setq ediff-meta-buffer ,(current-buffer)
1672 ediff-meta-session-number
1673 ,session-number)
1674 (setq ediff-merge-store-file
1675 ,(if (ediff-nonempty-string-p
1676 merge-autostore-dir)
1677 (concat
1678 merge-autostore-dir
1679 ediff-merge-filename-prefix
1680 (file-name-nondirectory file1))) )
1681 ;; make ediff-startup pass
1682 ;; ediff-control-buffer back to the meta
1683 ;; level; see below
1684 (setcar
1685 (quote ,info) ediff-control-buffer)))))
1686 ((ediff-metajob3) ; need 3 file args
1687 (funcall ediff-session-action-function
1688 file1 file2 file3
1689 ;; arrange startup hooks
1690 `(list (lambda ()
1691 (add-hook
1692 'ediff-after-quit-hook-internal
1693 (lambda ()
1694 (if (ediff-buffer-live-p
1695 ,(current-buffer))
1696 (ediff-show-meta-buffer
1697 ,(current-buffer)
1698 ,session-number)))
1699 nil 'local)
1700 (setq ediff-merge-store-file
1701 ,(if (ediff-nonempty-string-p
1702 merge-autostore-dir)
1703 (concat
1704 merge-autostore-dir
1705 ediff-merge-filename-prefix
1706 (file-name-nondirectory file1))) )
1707 (setq ediff-meta-buffer , (current-buffer)
1708 ediff-meta-session-number
1709 ,session-number)
1710 ;; this arranges that ediff-startup will pass
1711 ;; the value of ediff-control-buffer back to
1712 ;; the meta level, to the record in the meta
1713 ;; list containing the information about the
1714 ;; session associated with that
1715 ;; ediff-control-buffer
1716 (setcar
1717 (quote ,info) ediff-control-buffer)))))
1718 ) ; cond
1719 ) ; eval in meta-buf
1722 (defun ediff-registry-action ()
1723 "Switch to a selected session."
1724 (interactive)
1725 (let* ((pos (ediff-event-point last-command-event))
1726 (buf (ediff-event-buffer last-command-event))
1727 (ctl-buf (ediff-get-meta-info buf pos)))
1729 (if (ediff-buffer-live-p ctl-buf)
1730 ;; check if this is ediff-control-buffer or ediff-meta-buffer
1731 (if (ediff-with-current-buffer ctl-buf
1732 (eq (key-binding "q") 'ediff-quit-meta-buffer))
1733 ;; it's a meta-buffer -- last action should just display it
1734 (ediff-show-meta-buffer ctl-buf t)
1735 ;; it's a session buffer -- invoke go back to session
1736 (ediff-with-current-buffer ctl-buf
1737 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1738 (ediff-recenter 'no-rehighlight)))
1739 (beep)
1740 (message "You've selected a stale session --- try again")
1741 (ediff-update-registry))
1742 (ediff-with-current-buffer buf
1743 (goto-char pos))
1747 ;; If session number is t, means don't update meta buffer
1748 (defun ediff-show-meta-buffer (&optional meta-buf session-number)
1749 "Show the session group buffer."
1750 (interactive)
1751 (run-hooks 'ediff-before-directory-setup-hooks)
1752 (let (wind frame silent)
1753 (if meta-buf (setq silent t))
1755 (setq meta-buf (or meta-buf ediff-meta-buffer))
1756 (cond ((not (bufferp meta-buf))
1757 (error "This Ediff session is not part of a session group"))
1758 ((not (ediff-buffer-live-p meta-buf))
1759 (error
1760 "Can't find this session's group panel -- session itself is ok")))
1762 (cond ((numberp session-number)
1763 (ediff-update-meta-buffer meta-buf nil session-number))
1764 ;; if session-number is t, don't update
1765 (session-number)
1766 (t (ediff-cleanup-meta-buffer meta-buf)))
1768 (ediff-with-current-buffer meta-buf
1769 (save-excursion
1770 (cond ((setq wind (ediff-get-visible-buffer-window meta-buf))
1771 (or silent
1772 (message
1773 "Already showing the group panel for this session"))
1774 (set-window-buffer wind meta-buf)
1775 (select-window wind))
1776 ((window-live-p (setq wind ediff-window-C)) ;in merge--merge buf
1777 (set-window-buffer ediff-window-C meta-buf)
1778 (select-window wind))
1779 ((window-live-p (setq wind ediff-window-A))
1780 (set-window-buffer ediff-window-A meta-buf)
1781 (select-window wind))
1782 ((window-live-p (setq wind ediff-window-B))
1783 (set-window-buffer ediff-window-B meta-buf)
1784 (select-window wind))
1785 ((and
1786 (setq wind
1787 (ediff-get-visible-buffer-window ediff-registry-buffer))
1788 (ediff-window-display-p))
1789 (select-window wind)
1790 (other-window 1)
1791 (set-window-buffer (selected-window) meta-buf))
1792 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1793 (set-window-buffer (selected-window) meta-buf)))
1795 (if (and (ediff-window-display-p)
1796 (window-live-p
1797 (setq wind (ediff-get-visible-buffer-window meta-buf))))
1798 (progn
1799 (setq frame (window-frame wind))
1800 (raise-frame frame)
1801 (ediff-reset-mouse frame)))
1802 (sit-for 0) ; sometimes needed to synch the display and ensure that the
1803 ; point ends up after the just completed session
1804 (run-hooks 'ediff-show-session-group-hook)
1807 (defun ediff-show-current-session-meta-buffer ()
1808 (interactive)
1809 (ediff-show-meta-buffer nil ediff-meta-session-number))
1811 (defun ediff-show-meta-buff-from-registry ()
1812 "Display the session group buffer for a selected session group."
1813 (interactive)
1814 (let* ((pos (ediff-event-point last-command-event))
1815 (meta-buf (ediff-event-buffer last-command-event))
1816 (info (ediff-get-meta-info meta-buf pos))
1817 (meta-or-session-buf info))
1818 (ediff-with-current-buffer meta-or-session-buf
1819 (ediff-show-meta-buffer nil t))))
1821 ;;;###autoload
1822 (defun ediff-show-registry ()
1823 "Display Ediff's registry."
1824 (interactive)
1825 (ediff-update-registry)
1826 (if (not (ediff-buffer-live-p ediff-registry-buffer))
1827 (error "No active Ediff sessions or corrupted session registry"))
1828 (let (wind frame)
1829 ;; for some reason, point moves in ediff-registry-buffer, so we preserve it
1830 ;; explicitly
1831 (ediff-with-current-buffer ediff-registry-buffer
1832 (save-excursion
1833 (cond ((setq wind
1834 (ediff-get-visible-buffer-window ediff-registry-buffer))
1835 (message "Already showing the registry")
1836 (set-window-buffer wind ediff-registry-buffer)
1837 (select-window wind))
1838 ((window-live-p ediff-window-C)
1839 (set-window-buffer ediff-window-C ediff-registry-buffer)
1840 (select-window ediff-window-C))
1841 ((window-live-p ediff-window-A)
1842 (set-window-buffer ediff-window-A ediff-registry-buffer)
1843 (select-window ediff-window-A))
1844 ((window-live-p ediff-window-B)
1845 (set-window-buffer ediff-window-B ediff-registry-buffer)
1846 (select-window ediff-window-B))
1847 ((and (setq wind
1848 (ediff-get-visible-buffer-window ediff-meta-buffer))
1849 (ediff-window-display-p))
1850 (select-window wind)
1851 (other-window 1)
1852 (set-window-buffer (selected-window) ediff-registry-buffer))
1853 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1854 (set-window-buffer (selected-window) ediff-registry-buffer)))
1856 (if (ediff-window-display-p)
1857 (progn
1858 (setq frame
1859 (window-frame
1860 (ediff-get-visible-buffer-window ediff-registry-buffer)))
1861 (raise-frame frame)
1862 (ediff-reset-mouse frame)))
1863 (run-hooks 'ediff-show-registry-hook)
1866 ;;;###autoload
1867 (defalias 'eregistry 'ediff-show-registry)
1869 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a
1870 ;; parent meta-buf
1871 ;; Check if META-BUF exists before calling this function
1872 ;; Optional MUST-REDRAW, if non-nil, would force redrawal of the whole meta
1873 ;; buffer. Otherwise, it will just go over the buffer and update activity marks
1874 ;; and session status.
1875 ;; SESSION-NUMBER, if specified, says which session caused the update.
1876 (defun ediff-update-meta-buffer (meta-buf &optional must-redraw session-number)
1877 (if (ediff-buffer-live-p meta-buf)
1878 (ediff-with-current-buffer meta-buf
1879 (let (overl)
1880 (cond (must-redraw ; completely redraw the meta buffer
1881 (funcall ediff-meta-redraw-function ediff-meta-list))
1882 ((numberp session-number) ; redraw only for the given session
1883 (ediff-update-session-marker-in-dir-meta-buffer
1884 session-number))
1885 (t ; update what changed only, but scan the entire meta buffer
1886 (ediff-update-markers-in-dir-meta-buffer ediff-meta-list)))
1887 (setq overl (ediff-get-meta-overlay-at-pos (point)))
1888 ;; skip the invisible sessions
1889 (while (and overl (ediff-overlay-get overl 'invisible))
1890 (ediff-next-meta-item1)
1891 (setq overl (ediff-get-meta-overlay-at-pos (point))))
1892 ))))
1894 (defun ediff-update-registry ()
1895 (ediff-with-current-buffer (current-buffer)
1896 (if (ediff-buffer-live-p ediff-registry-buffer)
1897 (ediff-redraw-registry-buffer)
1898 (ediff-prepare-meta-buffer
1899 'ediff-registry-action
1900 ediff-session-registry
1901 "*Ediff Registry"
1902 'ediff-redraw-registry-buffer
1903 'ediff-registry))
1906 ;; If meta-buf exists, it is redrawn along with parent.
1907 ;; Otherwise, nothing happens.
1908 (defun ediff-cleanup-meta-buffer (meta-buffer)
1909 (if (ediff-buffer-live-p meta-buffer)
1910 (ediff-with-current-buffer meta-buffer
1911 (ediff-update-meta-buffer meta-buffer)
1912 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1913 (ediff-update-meta-buffer
1914 ediff-parent-meta-buffer nil ediff-meta-session-number)))))
1916 ;; t if no session is in progress
1917 (defun ediff-safe-to-quit (meta-buffer)
1918 (if (ediff-buffer-live-p meta-buffer)
1919 (let ((lis ediff-meta-list)
1920 (cont t)
1921 buffer-read-only)
1922 ;;(ediff-update-meta-buffer meta-buffer)
1923 (ediff-with-current-buffer meta-buffer
1924 (setq lis (cdr lis)) ; discard the description part of meta-list
1925 (while (and cont lis)
1926 (if (ediff-buffer-live-p
1927 (ediff-get-group-buffer lis)) ; in progress
1928 (setq cont nil))
1929 (setq lis (cdr lis)))
1930 cont))))
1932 (defun ediff-quit-meta-buffer ()
1933 "If the group has no active session, delete the meta buffer.
1934 If no session is in progress, ask to confirm before deleting meta buffer.
1935 Otherwise, bury the meta buffer.
1936 If this is a session registry buffer then just bury it."
1937 (interactive)
1938 (let* ((buf (current-buffer))
1939 (dir-diffs-buffer ediff-dir-diffs-buffer)
1940 (meta-diff-buffer ediff-meta-diff-buffer)
1941 (session-number ediff-meta-session-number)
1942 (parent-buf ediff-parent-meta-buffer)
1943 (dont-show-registry (eq buf ediff-registry-buffer)))
1944 (if dont-show-registry
1945 (bury-buffer)
1946 ;;(ediff-cleanup-meta-buffer buf)
1947 (cond ((and (ediff-safe-to-quit buf)
1948 (y-or-n-p "Quit this session group? "))
1949 (run-hooks 'ediff-quit-session-group-hook)
1950 (message "")
1951 (ediff-dispose-of-meta-buffer buf))
1952 ((ediff-safe-to-quit buf)
1953 (bury-buffer))
1955 (error
1956 "This session group has active sessions---cannot exit")))
1957 (ediff-update-meta-buffer parent-buf nil session-number)
1958 (ediff-kill-buffer-carefully dir-diffs-buffer)
1959 (ediff-kill-buffer-carefully meta-diff-buffer)
1960 (if (ediff-buffer-live-p parent-buf)
1961 (progn
1962 (setq dont-show-registry t)
1963 (ediff-show-meta-buffer parent-buf session-number)))
1965 (or dont-show-registry
1966 (ediff-show-registry))))
1968 (defun ediff-dispose-of-meta-buffer (buf)
1969 (setq ediff-session-registry (delq buf ediff-session-registry))
1970 (ediff-with-current-buffer buf
1971 (if (ediff-buffer-live-p ediff-dir-diffs-buffer)
1972 (kill-buffer ediff-dir-diffs-buffer)))
1973 (kill-buffer buf))
1976 ;; Obtain information on a meta record where the user clicked or typed
1977 ;; BUF is the buffer where this happened and POINT is the position
1978 ;; If optional NOERROR arg is given, don't report error and return nil if no
1979 ;; meta info is found on line.
1980 (defun ediff-get-meta-info (buf point &optional noerror)
1981 (let (result olist tmp)
1982 (if (and point (ediff-buffer-live-p buf))
1983 (ediff-with-current-buffer buf
1984 (ediff-cond-compile-for-xemacs-or-emacs
1985 (setq result ; xemacs
1986 (if (setq tmp (extent-at point buf 'ediff-meta-info))
1987 (ediff-overlay-get tmp 'ediff-meta-info)))
1988 (progn ; emacs
1989 (setq olist (overlays-at point))
1990 (setq olist
1991 (mapcar (lambda (elt)
1992 (unless (overlay-get elt 'invisible)
1993 (overlay-get elt 'ediff-meta-info)))
1994 olist))
1995 (while (and olist (null (car olist)))
1996 (setq olist (cdr olist)))
1997 (setq result (car olist)))
2000 (if result
2001 result
2002 (if noerror
2004 (ediff-update-registry)
2005 (error "No session info in this line")))))
2008 (defun ediff-get-meta-overlay-at-pos (point)
2009 (ediff-cond-compile-for-xemacs-or-emacs
2010 (extent-at point (current-buffer) 'ediff-meta-info) ; xemacs
2011 ;; emacs
2012 (let* ((overl-list (overlays-at point))
2013 (overl (car overl-list)))
2014 (while (and overl (null (overlay-get overl 'ediff-meta-info)))
2015 (setq overl-list (cdr overl-list)
2016 overl (car overl-list)))
2017 overl)
2021 (defsubst ediff-get-session-number-at-pos (point &optional meta-buffer)
2022 (setq meta-buffer (if (ediff-buffer-live-p meta-buffer)
2023 meta-buffer
2024 (current-buffer)))
2025 (ediff-with-current-buffer meta-buffer
2026 (ediff-overlay-get
2027 (ediff-get-meta-overlay-at-pos point) 'ediff-meta-session-number)))
2030 ;; Return location of the next meta overlay after point
2031 (defun ediff-next-meta-overlay-start (point)
2032 (if (eobp)
2033 (goto-char (point-min))
2034 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2035 (ediff-cond-compile-for-xemacs-or-emacs
2036 (progn ; xemacs
2037 (if overl
2038 (setq overl (next-extent overl))
2039 (setq overl (next-extent (current-buffer))))
2040 (if overl
2041 (extent-start-position overl)
2042 (point-max)))
2043 ;; emacs
2044 (if overl
2045 ;; note: end of current overlay is the beginning of the next one
2046 (overlay-end overl)
2047 (next-overlay-change point))
2053 (defun ediff-previous-meta-overlay-start (point)
2054 (if (bobp)
2055 (goto-char (point-max))
2056 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2057 (ediff-cond-compile-for-xemacs-or-emacs
2058 (progn
2059 (if overl
2060 (setq overl (previous-extent overl))
2061 (setq overl (previous-extent (current-buffer))))
2062 (if overl
2063 (extent-start-position overl)
2064 (point-min)))
2065 (progn
2066 (if overl (setq point (overlay-start overl)))
2067 ;; to get to the beginning of prev overlay
2068 (if (not (bobp))
2069 ;; trick to overcome an emacs bug--doesn't always find previous
2070 ;; overlay change correctly
2071 (setq point (1- point)))
2072 (setq point (previous-overlay-change point))
2073 ;; If we are not over an overlay after subtracting 1, it means we are
2074 ;; in the description area preceding session records. In this case,
2075 ;; goto the top of the registry buffer.
2076 (or (car (overlays-at point))
2077 (setq point (point-min)))
2078 point)
2082 ;; this is the action invoked when the user selects a patch from the meta
2083 ;; buffer.
2084 (defun ediff-patch-file-form-meta (file &optional startup-hooks)
2085 (let* ((pos (ediff-event-point last-command-event))
2086 (meta-buf (ediff-event-buffer last-command-event))
2087 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
2088 (info (ediff-get-meta-info meta-buf pos))
2089 (meta-patchbuf ediff-meta-patchbufer)
2090 session-buf beg-marker end-marker)
2092 (if (or (file-directory-p file) (string-match "/dev/null" file))
2093 (error "`%s' is not an ordinary file" (file-name-as-directory file)))
2094 (setq session-buf (ediff-get-session-buffer info)
2095 beg-marker (ediff-get-session-objB-name info)
2096 end-marker (ediff-get-session-objC-name info))
2098 (or (ediff-buffer-live-p session-buf) ; either an active patch session
2099 (null session-buf) ; or it is a virgin session
2100 (error
2101 "Patch has been already applied to this file--cannot be repeated!"))
2103 (ediff-with-current-buffer meta-patchbuf
2104 (save-restriction
2105 (widen)
2106 (narrow-to-region beg-marker end-marker)
2107 (ediff-patch-file-internal meta-patchbuf file startup-hooks)))))
2110 (defun ediff-unmark-all-for-operation ()
2111 "Unmark all sessions marked for operation."
2112 (interactive)
2113 (let ((list (cdr ediff-meta-list))
2114 elt)
2115 (while (setq elt (car list))
2116 (ediff-mark-session-for-operation elt 'unmark)
2117 (setq list (cdr list))))
2118 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2120 (defun ediff-unmark-all-for-hiding ()
2121 "Unmark all sessions marked for hiding."
2122 (interactive)
2123 (let ((list (cdr ediff-meta-list))
2124 elt)
2125 (while (setq elt (car list))
2126 (ediff-mark-session-for-hiding elt 'unmark)
2127 (setq list (cdr list))))
2128 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2131 ;; ACTION is ?h, ?m, ?=: to mark for hiding, mark for operation, or simply
2132 ;; indicate which are equal files
2133 (defun ediff-meta-mark-equal-files (&optional action)
2134 "Run through the session list and mark identical files.
2135 This is used only for sessions that involve 2 or 3 files at the same time.
2136 ACTION is an optional argument that can be ?h, ?m, ?=, to mark for hiding, mark
2137 for operation, or simply indicate which are equal files. If it is nil, then
2138 last-command-char is used to decide which action to take."
2139 (interactive)
2140 (if (null action)
2141 (setq action last-command-char))
2142 (let ((list (cdr ediff-meta-list))
2143 marked1 marked2 marked3
2144 fileinfo1 fileinfo2 fileinfo3 elt)
2145 (message "Comparing files ...")
2146 (while (setq elt (car list))
2147 (setq fileinfo1 (ediff-get-session-objA elt)
2148 fileinfo2 (ediff-get-session-objB elt)
2149 fileinfo3 (ediff-get-session-objC elt))
2150 (ediff-set-file-eqstatus fileinfo1 nil)
2151 (ediff-set-file-eqstatus fileinfo2 nil)
2152 (ediff-set-file-eqstatus fileinfo3 nil)
2154 (setq marked1 t
2155 marked2 t
2156 marked3 t)
2157 (or (ediff-mark-if-equal fileinfo1 fileinfo2)
2158 (setq marked1 nil))
2159 (if (ediff-metajob3)
2160 (progn
2161 (or (ediff-mark-if-equal fileinfo1 fileinfo3)
2162 (setq marked2 nil))
2163 (or (ediff-mark-if-equal fileinfo2 fileinfo3)
2164 (setq marked3 nil))))
2165 (if (and marked1 marked2 marked3)
2166 (cond ((eq action ?h)
2167 (ediff-mark-session-for-hiding elt 'mark))
2168 ((eq action ?m)
2169 (ediff-mark-session-for-operation elt 'mark))
2171 (setq list (cdr list)))
2172 (message "Comparing files ... Done"))
2173 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2175 ;; mark files 1 and 2 as equal, if they are.
2176 ;; returns t, if something was marked
2177 (defun ediff-mark-if-equal (fileinfo1 fileinfo2)
2178 (let ((f1 (car fileinfo1))
2179 (f2 (car fileinfo2)))
2180 (cond ((file-directory-p f1) nil)
2181 ((file-directory-p f2) nil)
2182 ((ediff-same-file-contents f1 f2)
2183 (ediff-set-file-eqstatus fileinfo1 t)
2184 (ediff-set-file-eqstatus fileinfo2 t)
2190 ;;; Local Variables:
2191 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
2192 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
2193 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
2194 ;;; End:
2196 ;;; ediff-mult.el ends here