(dired-chown-program): Replace lignux with gnu/linux.
[emacs.git] / lisp / ediff-mult.el
blob7bfdd81e4771b1f1dbf9d513a772bb94b905548a
1 ;;; ediff-mult.el --- support for multi-file/multi-buffer processing in Ediff
3 ;; Copyright (C) 1995, 1996 Free Software Foundation, Inc.
5 ;; Author: Michael Kifer <kifer@cs.sunysb.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 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 is
66 ;; nil for jobs that involve only two files. For patch jobs, obj2 and
67 ;; obj3 are markers that specify the patch corresponding to the file
68 ;; (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 functions
88 ;; that do the layout of the meta- and differences buffers and of
89 ;; ediff-filegroup-action.
91 ;;; Code:
93 (require 'ediff-init)
95 ;; meta-buffer
96 (ediff-defvar-local ediff-meta-buffer nil "")
97 (ediff-defvar-local ediff-parent-meta-buffer nil "")
98 ;; the registry buffer
99 (defvar ediff-registry-buffer nil)
101 (defconst ediff-meta-buffer-message "This is an Ediff Session Group Panel: %s
103 Useful commands:
104 button2, `v', RET over a session line: start that Ediff session
105 `M':\tin any session invoked from here, brings back this group panel
106 `R':\tdisplay the registry of active Ediff sessions
107 `h':\tmark session for hiding (toggle)
108 `x':\thide marked sessions; with prefix arg--unhide hidden sessions
109 `m':\tmark session for a non-hiding operation (toggle)
110 SPC:\tnext session
111 DEL:\tprevious session
112 `E':\tbrowse Ediff on-line manual
113 `q':\tquit this session group
116 (ediff-defvar-local ediff-meta-buffer-map nil
117 "The keymap for the meta buffer.")
118 (defvar ediff-dir-diffs-buffer-map (make-sparse-keymap)
119 "The keymap to be installed in the buffer showing differences between
120 directories.")
122 ;; Variable specifying the action to take when the use invokes ediff in the
123 ;; meta buffer. This is usually ediff-registry-action or ediff-filegroup-action
124 (ediff-defvar-local ediff-meta-action-function nil "")
125 ;; Tells ediff-update-meta-buffer how to redraw it
126 (ediff-defvar-local ediff-meta-redraw-function nil "")
127 ;; Tells ediff-filegroup-action and similar procedures how to invoke Ediff for
128 ;; the sessions in a given session group
129 (ediff-defvar-local ediff-session-action-function nil "")
131 (ediff-defvar-local ediff-metajob-name nil "")
133 ;; buffer used to collect custom diffs from individual sessions in the group
134 (ediff-defvar-local ediff-meta-diff-buffer nil "")
136 ;; history var to use for filtering groups
137 (defvar ediff-filtering-regexp-history nil "")
139 ;; This has the form ((ctl-buf file1 file2) (stl-buf file1 file2) ...)
140 ;; If ctl-buf is nil, the file-pair wasn't processed yet. If it is
141 ;; killed-buffer object, the file pair has been processed. If it is a live
142 ;; buffer, this means ediff is still working on the pair
143 (ediff-defvar-local ediff-meta-list nil "")
146 ;; the difference list between directories in a directory session group
147 (ediff-defvar-local ediff-dir-difference-list nil "")
148 (ediff-defvar-local ediff-dir-diffs-buffer nil "")
150 ;; The registry of Ediff sessions. A list of control buffers.
151 (defvar ediff-session-registry nil)
153 (defvar ediff-registry-setup-hook nil
154 "*Hooks run just after the registry control panel is set up.")
155 (defvar ediff-session-group-setup-hook nil
156 "*Hooks run just after a meta-buffer controlling a session group, such as
157 ediff-directories, is run.")
158 (defvar ediff-show-registry-hook nil
159 "*Hooks run just after the registry buffer is shown.")
160 (defvar ediff-show-session-group-hook nil
161 "*Hooks run just after a session group buffer is shown.")
163 ;; buffer holding the multi-file patch. local to the meta buffer
164 (ediff-defvar-local ediff-meta-patchbufer nil "")
166 ;;; API for ediff-meta-list
168 ;; group buffer/regexp
169 (defun ediff-get-group-buffer (meta-list)
170 (nth 0 (car meta-list)))
171 (defun ediff-get-group-regexp (meta-list)
172 (nth 1 (car meta-list)))
173 ;; group objects
174 (defun ediff-get-group-objA (meta-list)
175 (nth 2 (car meta-list)))
176 (defun ediff-get-group-objB (meta-list)
177 (nth 3 (car meta-list)))
178 (defun ediff-get-group-objC (meta-list)
179 (nth 4 (car meta-list)))
180 ;; session buffer
181 (defun ediff-get-session-buffer (elt)
182 (nth 0 elt))
183 (defun ediff-get-session-status (elt)
184 (nth 1 elt))
185 (defun ediff-set-session-status (session-info new-status)
186 (setcar (cdr session-info) new-status))
187 ;; session objects
188 (defun ediff-get-session-objA (elt)
189 (nth 2 elt))
190 (defun ediff-get-session-objB (elt)
191 (nth 3 elt))
192 (defun ediff-get-session-objC (elt)
193 (nth 4 elt))
194 (defun ediff-get-session-objA-name (elt)
195 (car (nth 2 elt)))
196 (defun ediff-get-session-objB-name (elt)
197 (car (nth 3 elt)))
198 (defun ediff-get-session-objC-name (elt)
199 (car (nth 4 elt)))
200 ;; equality indicators
201 (defsubst ediff-get-file-eqstatus (elt)
202 (nth 1 elt))
203 (defsubst ediff-set-file-eqstatus (elt value)
204 (setcar (cdr elt) value))
206 ;; set up the keymap in the meta buffer
207 (defun ediff-setup-meta-map()
208 (setq ediff-meta-buffer-map (make-sparse-keymap))
209 (suppress-keymap ediff-meta-buffer-map)
210 (define-key ediff-meta-buffer-map "q" 'ediff-quit-meta-buffer)
211 (define-key ediff-meta-buffer-map "R" 'ediff-show-registry)
212 (define-key ediff-meta-buffer-map "E" 'ediff-documentation)
213 (define-key ediff-meta-buffer-map "v" ediff-meta-action-function)
214 (define-key ediff-meta-buffer-map "\C-m" ediff-meta-action-function)
215 (define-key ediff-meta-buffer-map " " 'ediff-next-meta-item)
216 (define-key ediff-meta-buffer-map "\C-?" 'ediff-previous-meta-item)
217 (define-key ediff-meta-buffer-map [delete] 'ediff-previous-meta-item)
218 (define-key ediff-meta-buffer-map [backspace] 'ediff-previous-meta-item)
219 (or (ediff-one-filegroup-metajob)
220 (define-key ediff-meta-buffer-map "=" 'ediff-meta-mark-equal-files))
221 (if ediff-no-emacs-help-in-control-buffer
222 (define-key ediff-meta-buffer-map "\C-h" 'ediff-previous-meta-item))
223 (if ediff-emacs-p
224 (define-key ediff-meta-buffer-map [mouse-2] ediff-meta-action-function)
225 (define-key ediff-meta-buffer-map [button2] ediff-meta-action-function))
227 (use-local-map ediff-meta-buffer-map))
229 (defun ediff-meta-mode ()
230 "This mode controls all operations on Ediff session groups.
231 It is entered through one of the following commands:
232 `ediff-directories'
233 `edirs'
234 `ediff-directories3'
235 `edirs3'
236 `ediff-merge-directories'
237 `edirs-merge'
238 `ediff-merge-directories-with-ancestor'
239 `edirs-merge-with-ancestor'
240 `ediff-directory-revisions'
241 `edir-revisions'
242 `ediff-merge-directory-revisions'
243 `edir-merge-revisions'
244 `ediff-merge-directory-revisions-with-ancestor'
245 `edir-merge-revisions-with-ancestor'
247 Commands:
248 \\{ediff-meta-buffer-map}"
249 (kill-all-local-variables)
250 (setq major-mode 'ediff-meta-mode)
251 (setq mode-name "MetaEdiff"))
254 ;; the keymap for the buffer showing directory differences
255 (suppress-keymap ediff-dir-diffs-buffer-map)
256 (define-key ediff-dir-diffs-buffer-map "q" 'ediff-bury-dir-diffs-buffer)
257 (define-key ediff-dir-diffs-buffer-map " " 'next-line)
258 (define-key ediff-dir-diffs-buffer-map "\C-?" 'previous-line)
259 (define-key ediff-dir-diffs-buffer-map [delete] 'previous-line)
260 (define-key ediff-dir-diffs-buffer-map [backspace] 'previous-line)
262 (defun ediff-next-meta-item (count)
263 "Move to the next item in Ediff registry or session group buffer.
264 Moves in circular fashion. With numeric prefix arg, skip this many items."
265 (interactive "p")
266 (or count (setq count 1))
267 (while (< 0 count)
268 (setq count (1- count))
269 (ediff-next-meta-item1)))
271 ;; Move to the next meta item
272 (defun ediff-next-meta-item1 ()
273 (let (pos)
274 (setq pos (ediff-next-meta-overlay-start (point)))
275 ;;; ;; skip deleted
276 ;;; (while (memq (ediff-get-session-status
277 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
278 ;;; '(?H ?I))
279 ;;; (setq pos (ediff-next-meta-overlay-start pos)))
281 (if pos (goto-char pos))
282 (if (eq ediff-metajob-name 'ediff-registry)
283 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
284 (search-forward "*Ediff" nil t))
285 (skip-chars-backward "a-zA-Z*"))
286 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
287 (backward-char 1)))))
290 (defun ediff-previous-meta-item (count)
291 "Move to the previous item in Ediff registry or session group buffer.
292 Moves in circular fashion. With numeric prefix arg, skip this many items."
293 (interactive "p")
294 (or count (setq count 1))
295 (while (< 0 count)
296 (setq count (1- count))
297 (ediff-previous-meta-item1)))
299 (defun ediff-previous-meta-item1 ()
300 (let (pos)
301 (setq pos (ediff-previous-meta-overlay-start (point)))
302 ;;; ;; skip deleted
303 ;;; (while (ediff-get-session-status
304 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
305 ;;; (setq pos (ediff-previous-meta-overlay-start pos)))
307 (if pos (goto-char pos))
308 (if (eq ediff-metajob-name 'ediff-registry)
309 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
310 (search-forward "*Ediff" nil t))
311 (skip-chars-backward "a-zA-Z*"))
312 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
313 (backward-char 1)))
318 ;; DIR1, DIR2, DIR3 are directories.
319 ;; REGEXP is a regexp used to filter
320 ;; files in the directories.
321 ;; If a file is a directory in dir1 but not dir2 (or vice versa), it is not
322 ;; included in the intersection. However, a regular file that is a dir in dir3
323 ;; is included, since dir3 files are supposed to be ancestors for merging.
324 ;; Returns a list of the form:
325 ;; ((dir1 dir2 dir3) (f1 f2 f3) (f1 f2 f3) ...)
326 ;; dir3, f3 can be nil if intersecting only 2 directories.
327 ;; If COMPARISON-FUNC is given, use it. Otherwise, use string=
328 ;; DIFF-VAR is contains the name of the variable in which to return the
329 ;; difference list. The diff list is of the form:
330 ;; ((dir1 dir2 dir3) (file . num) (file . num)...)
331 ;; where num encodes the set of dirs where the file is found:
332 ;; 2 - only dir1; 3 - only dir2; 5 - only dir3; 6 - dir1&2; 10 - dir1&3; etc.
333 (defun ediff-intersect-directories (jobname
334 diff-var regexp dir1 dir2
335 &optional dir3 comparison-func)
336 (setq comparison-func (or comparison-func 'string=))
337 (let (lis1 lis2 lis3 common auxdir1 auxdir2 auxdir3 difflist)
339 (setq auxdir1 (file-name-as-directory dir1)
340 lis1 (directory-files auxdir1 nil regexp)
341 auxdir2 (file-name-as-directory dir2)
342 lis2 (directory-files auxdir2 nil regexp))
344 (if (stringp dir3)
345 (setq auxdir3 (file-name-as-directory dir3)
346 lis3 (directory-files auxdir3 nil regexp)))
348 (setq lis1 (delete "." lis1)
349 lis1 (delete ".." lis1))
351 (setq common (ediff-intersection lis1 lis2 comparison-func))
352 ;; get rid of files that are directories in dir1 but not dir2
353 (mapcar (function (lambda (elt)
354 (if (Xor (file-directory-p (concat auxdir1 elt))
355 (file-directory-p (concat auxdir2 elt)))
356 (setq common (delq elt common)))))
357 common)
358 ;; intersect with the third dir
359 (if lis3 (setq common (ediff-intersection common lis3 comparison-func)))
360 (if (ediff-comparison-metajob3 jobname)
361 (mapcar (function (lambda (elt)
362 (if (Xor (file-directory-p (concat auxdir1 elt))
363 (file-directory-p (concat auxdir3 elt)))
364 (setq common (delq elt common)))))
365 common))
367 ;; copying is needed because sort sorts via side effects
368 (setq common (sort (ediff-copy-list common) 'string-lessp))
370 ;; compute difference list
371 (setq difflist (ediff-set-difference
372 (ediff-union (ediff-union lis1 lis2 comparison-func)
373 lis3
374 comparison-func)
375 common
376 comparison-func)
377 difflist (delete "." difflist)
378 ;; copying is needed because sort sorts via side effects
379 difflist (sort (ediff-copy-list (delete ".." difflist))
380 'string-lessp))
382 (setq difflist (mapcar (function (lambda (elt) (cons elt 1))) difflist))
384 ;; check for files belonging to lis1/2/3
385 (mapcar (function (lambda (elt)
386 (if (member (car elt) lis1)
387 (setcdr elt (* (cdr elt) 2)))
388 (if (member (car elt) lis2)
389 (setcdr elt (* (cdr elt) 3)))
390 (if (member (car elt) lis3)
391 (setcdr elt (* (cdr elt) 5)))
393 difflist)
394 (setq difflist (cons (list regexp auxdir1 auxdir2 auxdir3) difflist))
396 (set diff-var difflist)
398 ;; return result
399 (cons (list regexp auxdir1 auxdir2 auxdir3)
400 (mapcar (function (lambda (elt)
401 (list (concat auxdir1 elt)
402 (concat auxdir2 elt)
403 (if lis3
404 (concat auxdir3 elt)))))
405 common))
408 ;; find directory files that are under revision.
409 ;; display subdirectories, too, since we may visit them recursively.
410 (defun ediff-get-directory-files-under-revision (jobname regexp dir1)
411 (let (lis1 elt common auxdir1)
412 (setq auxdir1 (file-name-as-directory dir1)
413 lis1 (directory-files auxdir1 nil regexp))
415 (while lis1
416 (setq elt (car lis1)
417 lis1 (cdr lis1))
418 ;; take files under revision control
419 (cond ((file-directory-p (concat auxdir1 elt))
420 (setq common (cons elt common)))
421 ((file-exists-p (concat auxdir1 elt ",v"))
422 (setq common (cons elt common)))
423 ((file-exists-p (concat auxdir1 "RCS/" elt ",v"))
424 (setq common (cons elt common)))
425 ) ; cond
426 ) ; while
428 (setq common (delete "." common)
429 common (delete ".." common))
431 ;; copying is needed because sort sorts via side effects
432 (setq common (sort (ediff-copy-list common) 'string-lessp))
434 ;; return result
435 (cons (list regexp auxdir1 nil nil)
436 (mapcar (function (lambda (elt)
437 (list (concat auxdir1 elt)
438 nil nil)))
439 common))
443 ;; If file groups selected by patterns will ever be implemented, this
444 ;; comparison function might become useful.
445 ;;;; uses external variables PAT1 PAT2 to compare str1/2
446 ;;;; patterns must be of the form ???*???? where ??? are strings of chars
447 ;;;; containing no *.
448 ;;(defun ediff-pattern= (str1 str2)
449 ;; (let (pos11 pos12 pos21 pos22 len1 len2)
450 ;; (setq pos11 0
451 ;; len (length epat1)
452 ;; pos12 len)
453 ;; (while (and (< pos11 len) (not (= (aref epat1 pos11) ?*)))
454 ;; (setq pos11 (1+ pos11)))
455 ;; (while (and (> pos12 0) (not (= (aref epat1 (1- pos12)) ?*)))
456 ;; (setq pos12 (1- pos12)))
458 ;; (setq pos21 0
459 ;; len (length epat2)
460 ;; pos22 len)
461 ;; (while (and (< pos21 len) (not (= (aref epat2 pos21) ?*)))
462 ;; (setq pos21 (1+ pos21)))
463 ;; (while (and (> pos22 0) (not (= (aref epat2 (1- pos22)) ?*)))
464 ;; (setq pos22 (1- pos22)))
466 ;; (if (and (> (length str1) pos12) (>= pos12 pos11) (> pos11 -1)
467 ;; (> (length str2) pos22) (>= pos22 pos21) (> pos21 -1))
468 ;; (string= (substring str1 pos11 pos12)
469 ;; (substring str2 pos21 pos22)))
470 ;; ))
473 ;; Prepare meta-buffer in accordance with the argument-function and
474 ;; redraw-function. Must return the created meta-buffer.
475 (defun ediff-prepare-meta-buffer (action-func meta-list
476 meta-buffer-name redraw-function
477 jobname &optional startup-hooks)
478 (let* ((meta-buffer-name
479 (ediff-unique-buffer-name meta-buffer-name "*"))
480 (meta-buffer (get-buffer-create meta-buffer-name)))
481 (ediff-eval-in-buffer meta-buffer
483 ;; comes first
484 (ediff-meta-mode)
486 (setq ediff-meta-action-function action-func
487 ediff-meta-redraw-function redraw-function
488 ediff-metajob-name jobname
489 ediff-meta-buffer meta-buffer)
491 ;; comes after ediff-meta-action-function is set
492 (ediff-setup-meta-map)
494 (if (eq ediff-metajob-name 'ediff-registry)
495 (progn
496 (setq ediff-registry-buffer meta-buffer
497 ediff-meta-list meta-list)
498 ;; this func is used only from registry buffer, not from other
499 ;; meta-buffs.
500 (define-key
501 ediff-meta-buffer-map "M" 'ediff-show-meta-buff-from-registry))
502 ;; initialize the meta list -- don't do this for registry we prepend
503 ;; '(nil nil) to all elts of meta-list, except the first. The
504 ;; first nil will later be replaced by the session buffer. The second
505 ;; is reserved for session status.
506 ;; (car ediff-meta-list) gets cons'ed with the session group buffer.
507 ;; Also, session objA/B/C are turned into lists (obj eq-indicator)
508 ;; For now, the eq-indicator is used only for 2 and 3-file jobs.
509 (setq ediff-meta-list
510 (cons (cons meta-buffer (car meta-list))
511 (mapcar (function
512 (lambda (elt)
513 (cons nil
514 (cons nil
515 ;; convert each obj to (obj nil),
516 ;; where nil may later be replaced
517 ;; by =, if this file equals some
518 ;; other file in the same session
519 (mapcar (function
520 (lambda (obj)
521 (list obj nil)))
522 elt)))))
523 (cdr meta-list)))))
525 (or (eq meta-buffer ediff-registry-buffer)
526 (setq ediff-session-registry
527 (cons meta-buffer ediff-session-registry)))
529 ;; redraw-function uses ediff-meta-list
530 (funcall redraw-function ediff-meta-list)
532 ;; set read-only/non-modified
533 (setq buffer-read-only t)
534 (set-buffer-modified-p nil)
536 (run-hooks 'startup-hooks)
537 ;; arrange for showing directory contents differences
538 ;; must be after run startup-hooks, since ediff-dir-difference-list is
539 ;; set inside these hooks
540 (if (eq action-func 'ediff-filegroup-action)
541 (progn
542 ;; put meta buffer in (car ediff-dir-difference-list)
543 (setq ediff-dir-difference-list
544 (cons (cons meta-buffer (car ediff-dir-difference-list))
545 (cdr ediff-dir-difference-list)))
547 (or (ediff-one-filegroup-metajob jobname)
548 (ediff-draw-dir-diffs ediff-dir-difference-list))
549 (define-key ediff-meta-buffer-map "h" 'ediff-mark-for-hiding)
550 (define-key
551 ediff-meta-buffer-map "x" 'ediff-hide-marked-sessions)
552 (define-key ediff-meta-buffer-map "m" 'ediff-mark-for-operation)
553 (cond ((ediff-collect-diffs-metajob jobname)
554 (define-key
555 ediff-meta-buffer-map "P" 'ediff-collect-custom-diffs))
556 ((ediff-patch-metajob jobname)
557 (define-key
558 ediff-meta-buffer-map "P" 'ediff-meta-show-patch)))
559 (define-key ediff-meta-buffer-map "u" 'ediff-up-meta-hierarchy)
560 (define-key ediff-meta-buffer-map "D" 'ediff-show-dir-diffs)))
562 (if (eq ediff-metajob-name 'ediff-registry)
563 (run-hooks 'ediff-registry-setup-hook)
564 (run-hooks 'ediff-session-group-setup-hook))
565 ) ; eval in meta-buffer
566 meta-buffer))
569 ;; this is a setup function for ediff-directories
570 ;; must return meta-buffer
571 (defun ediff-redraw-directory-group-buffer (meta-list)
572 ;; extract directories
573 (let ((meta-buf (ediff-get-group-buffer meta-list))
574 (empty t)
575 (sessionNum 0)
576 regexp elt session-buf f1 f2 f3 pt
577 point tmp-list buffer-read-only)
578 (ediff-eval-in-buffer meta-buf
579 (setq point (point))
580 (erase-buffer)
581 (insert (format ediff-meta-buffer-message
582 (ediff-abbrev-jobname ediff-metajob-name)))
584 (setq regexp (ediff-get-group-regexp meta-list))
586 (cond ((ediff-collect-diffs-metajob)
587 (insert
588 " `P':\tcollect custom diffs of all marked sessions\n"))
589 ((ediff-patch-metajob)
590 (insert
591 " `P':\tshow patch appropriately for the context (session or group)\n")))
592 (insert
593 " `u':\tshow parent session group\n")
594 (or (ediff-one-filegroup-metajob)
595 (insert
596 " `D':\tshow differences among directories\n"
597 " `=':\tmark identical files in each session\n\n"))
599 (if (and (stringp regexp) (> (length regexp) 0))
600 (insert (format "Filter-through regular expression: %s\n" regexp)))
602 (insert "\n
603 Size Last modified Name
604 -----------------------------------------------------------------------
608 ;; discard info on directories and regexp
609 (setq meta-list (cdr meta-list)
610 tmp-list meta-list)
611 (while (and tmp-list empty)
612 (if (and (car tmp-list)
613 (not (eq (ediff-get-session-status (car tmp-list)) ?I)))
614 (setq empty nil))
615 (setq tmp-list (cdr tmp-list)))
617 (if empty
618 (insert
619 " ****** ****** This session group has no members\n"))
621 ;; now organize file names like this:
622 ;; use-mark sizeA dateA sizeB dateB filename
623 ;; make sure directories are displayed with a trailing slash.
624 ;; If one is a directory and another isn't, indicate this with a `?'
625 (while meta-list
626 (setq elt (car meta-list)
627 meta-list (cdr meta-list)
628 sessionNum (1+ sessionNum))
629 (if (eq (ediff-get-session-status elt) ?I)
631 (setq session-buf (ediff-get-session-buffer elt)
632 f1 (ediff-get-session-objA elt)
633 f2 (ediff-get-session-objB elt)
634 f3 (ediff-get-session-objC elt))
635 (setq pt (point))
636 ;; insert markers
637 (insert (cond ((null session-buf) " ") ; virgin session
638 ((ediff-buffer-live-p session-buf) "+") ;active session
639 (t "-"))) ; finished session
640 (insert (cond ((ediff-get-session-status elt)) ; session has status,
641 ;;; e.g., ?H, ?I
642 (t " "))) ; normal session
643 (insert " Session " (int-to-string sessionNum) ":\n")
644 (ediff-meta-insert-file-info f1)
645 (ediff-meta-insert-file-info f2)
646 (ediff-meta-insert-file-info f3)
647 (ediff-set-meta-overlay pt (point) elt)))
648 (set-buffer-modified-p nil)
649 (goto-char point)
650 meta-buf)))
652 ;; Check if this is a problematic session.
653 ;; Return nil if not. Otherwise, return symbol representing the problem
654 ;; At present, problematic sessions occur only in -with-ancestor comparisons
655 ;; when the ancestor is a directory rather than a file.
656 (defun ediff-problematic-session-p (session)
657 (let ((f1 (ediff-get-session-objA-name session))
658 (f2 (ediff-get-session-objB-name session))
659 (f3 (ediff-get-session-objC-name session)))
660 (cond ((and (stringp f1) (not (file-directory-p f1))
661 (stringp f2) (not (file-directory-p f2))
662 (stringp f3) (file-directory-p f3)
663 (ediff-ancestor-metajob))
664 ;; more may be added later
665 'ancestor-is-dir)
666 (t nil))))
668 (defun ediff-meta-insert-file-info (fileinfo)
669 (let ((file-size -1)
670 (fname (car fileinfo))
671 (feq (ediff-get-file-eqstatus fileinfo))
672 (file-modtime "*file doesn't exist*"))
674 (if (and (stringp fname) (file-exists-p fname))
675 (setq file-size (ediff-file-size fname)
676 file-modtime (ediff-file-modtime fname)))
677 (if (stringp fname)
678 (insert
679 (format
680 "%s %s %-20s %s\n"
681 (if feq "=" " ") ; equality indicator
682 (format "%10s" (if (< file-size 0)
683 "remote"
684 file-size))
685 (if (< file-size 0)
686 "file"
687 (ediff-format-date (decode-time file-modtime)))
688 ;; dir names in meta lists have no trailing `/' so insert it
689 (cond ((file-directory-p fname)
690 (file-name-as-directory (ediff-abbreviate-file-name fname)))
691 (t (ediff-abbreviate-file-name fname)))))
694 (defconst ediff-months '((1 . "Jan") (2 . "Feb") (3 . "Mar") (4 . "Apr")
695 (5 . "May") (6 . "Jun") (7 . "Jul") (8 . "Aug")
696 (9 . "Sep") (10 . "Oct") (11 . "Nov") (12 . "Dec"))
697 "Months' associative array.")
699 ;; TIME is like the output of decode-time
700 (defun ediff-format-date (time)
701 (format "%s %2d %4d %s:%s:%s"
702 (cdr (assoc (nth 4 time) ediff-months)) ; month
703 (nth 3 time) ; day
704 (nth 5 time) ; year
705 (ediff-fill-leading-zero (nth 2 time)) ; hour
706 (ediff-fill-leading-zero (nth 1 time)) ; min
707 (ediff-fill-leading-zero (nth 0 time)) ; sec
710 ;; returns 2char string
711 (defsubst ediff-fill-leading-zero (num)
712 (if (< num 10)
713 (format "0%d" num)
714 (number-to-string num)))
716 (defun ediff-draw-dir-diffs (diff-list)
717 (if (null diff-list) (error "Lost difference info on these directories"))
718 (let* ((buf-name (ediff-unique-buffer-name
719 "*Ediff File Group Differences" "*"))
720 (regexp (ediff-get-group-regexp diff-list))
721 (dir1 (ediff-abbreviate-file-name (ediff-get-group-objA diff-list)))
722 (dir2 (ediff-abbreviate-file-name (ediff-get-group-objB diff-list)))
723 (dir3 (ediff-get-group-objC diff-list))
724 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3)))
725 (meta-buf (ediff-get-group-buffer diff-list))
726 (underline (make-string 26 ?-))
727 file code
728 buffer-read-only)
729 ;; skip the directory part
730 (setq diff-list (cdr diff-list))
731 (setq ediff-dir-diffs-buffer (get-buffer-create buf-name))
732 (ediff-eval-in-buffer ediff-dir-diffs-buffer
733 (use-local-map ediff-dir-diffs-buffer-map)
734 (erase-buffer)
735 (setq ediff-meta-buffer meta-buf)
736 (insert "\t\t*** Directory Differences ***\n")
737 (insert "
738 Useful commands:
739 `q': hide this buffer
740 SPC: next line
741 DEL: previous line\n\n")
743 (if (and (stringp regexp) (> (length regexp) 0))
744 (insert (format "Filter-through regular expression: %s\n" regexp)))
745 (insert "\n")
746 (insert (format "\n%-27s%-26s"
747 (ediff-truncate-string-left
748 (ediff-abbreviate-file-name
749 (file-name-as-directory dir1))
751 (ediff-truncate-string-left
752 (ediff-abbreviate-file-name
753 (file-name-as-directory dir2))
754 25)))
755 (if dir3
756 (insert (format " %-25s\n"
757 (ediff-truncate-string-left
758 (ediff-abbreviate-file-name
759 (file-name-as-directory dir3))
760 25)))
761 (insert "\n"))
762 (insert (format "%s%s" underline underline))
763 (if (stringp dir3)
764 (insert (format "%s\n\n" underline))
765 (insert "\n\n"))
767 (if (null diff-list)
768 (insert "\n\t*** No differences ***\n"))
770 (while diff-list
771 (setq file (car (car diff-list))
772 code (cdr (car diff-list))
773 diff-list (cdr diff-list))
774 (if (= (mod code 2) 0) ; dir1
775 (insert (format "%-27s"
776 (ediff-truncate-string-left
777 (ediff-abbreviate-file-name
778 (if (file-directory-p (concat dir1 file))
779 (file-name-as-directory file)
780 file))
781 24)))
782 (insert (format "%-27s" "---")))
783 (if (= (mod code 3) 0) ; dir2
784 (insert (format "%-26s"
785 (ediff-truncate-string-left
786 (ediff-abbreviate-file-name
787 (if (file-directory-p (concat dir2 file))
788 (file-name-as-directory file)
789 file))
790 24)))
791 (insert (format "%-26s" "---")))
792 (if (stringp dir3)
793 (if (= (mod code 5) 0) ; dir3
794 (insert (format " %-25s"
795 (ediff-truncate-string-left
796 (ediff-abbreviate-file-name
797 (if (file-directory-p (concat dir3 file))
798 (file-name-as-directory file)
799 file))
800 24)))
801 (insert (format " %-25s" "---"))))
802 (insert "\n"))
803 (setq buffer-read-only t)
804 (set-buffer-modified-p nil)) ; eval in diff buffer
807 (defun ediff-bury-dir-diffs-buffer ()
808 "Bury the directory difference buffer. Display the meta buffer instead."
809 (interactive)
810 (let ((buf ediff-meta-buffer)
811 wind)
812 (bury-buffer)
813 (if (setq wind (ediff-get-visible-buffer-window buf))
814 (select-window wind)
815 (set-window-buffer (selected-window) buf))))
817 ;; executes in dir session group buffer
818 ;; show buffer differences
819 (defun ediff-show-dir-diffs ()
820 "Display differences among the directories involved in session group."
821 (interactive)
822 (if (ediff-one-filegroup-metajob)
823 (error "This command is inapplicable in the present context"))
824 (or (ediff-buffer-live-p ediff-dir-diffs-buffer)
825 (ediff-draw-dir-diffs ediff-dir-difference-list))
826 (let ((buf ediff-dir-diffs-buffer))
827 (other-window 1)
828 (set-window-buffer (selected-window) buf)
829 (goto-char (point-min))))
831 (defun ediff-up-meta-hierarchy ()
832 "Go to the parent session group buffer."
833 (interactive)
834 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
835 (ediff-show-meta-buffer ediff-parent-meta-buffer)
836 (error "This session group has no parent")))
839 ;; argument is ignored
840 (defun ediff-redraw-registry-buffer (&optional ignore)
841 (ediff-eval-in-buffer ediff-registry-buffer
842 (let ((point (point))
843 elt bufAname bufBname bufCname cur-diff total-diffs pt
844 job-name meta-list registry-list buffer-read-only)
845 (erase-buffer)
846 (insert "This is a registry of all active Ediff sessions.
848 Useful commands:
849 button2, `v', RET over a session record: switch to that session
850 `M' over a session record: display the associated session group
851 `R' in any Ediff session: display session registry
852 SPC:\tnext session
853 DEL:\tprevious session
854 `E':\tbrowse Ediff on-line manual
855 `q':\tbury registry
858 \t\tActive Ediff Sessions:
859 \t\t----------------------
862 ;; purge registry list from dead buffers
863 (mapcar (function (lambda (elt)
864 (if (not (ediff-buffer-live-p elt))
865 (setq ediff-session-registry
866 (delq elt ediff-session-registry)))))
867 ediff-session-registry)
869 (if (null ediff-session-registry)
870 (insert " ******* No active Ediff sessions *******\n"))
872 (setq registry-list ediff-session-registry)
873 (while registry-list
874 (setq elt (car registry-list)
875 registry-list (cdr registry-list))
877 (if (ediff-buffer-live-p elt)
878 (if (ediff-eval-in-buffer elt
879 (setq job-name ediff-metajob-name
880 meta-list ediff-meta-list)
881 (and ediff-metajob-name
882 (not (eq ediff-metajob-name 'ediff-registry))))
883 (progn
884 (setq pt (point))
885 (insert (format " *group*\t%s: %s\n"
886 (buffer-name elt)
887 (ediff-abbrev-jobname job-name)))
888 (insert (format "\t\t %s %s %s\n"
889 (ediff-abbreviate-file-name
890 (ediff-get-group-objA meta-list))
891 (ediff-abbreviate-file-name
892 (if (stringp
893 (ediff-get-group-objB meta-list))
894 (ediff-get-group-objB meta-list)
895 ""))
896 (ediff-abbreviate-file-name
897 (if (stringp
898 (ediff-get-group-objC meta-list))
899 (ediff-get-group-objC meta-list)
900 ""))))
901 (ediff-set-meta-overlay pt (point) elt))
902 (progn
903 (ediff-eval-in-buffer elt
904 (setq bufAname (if (ediff-buffer-live-p ediff-buffer-A)
905 (buffer-name ediff-buffer-A)
906 "!!!killed buffer!!!")
907 bufBname (if (ediff-buffer-live-p ediff-buffer-B)
908 (buffer-name ediff-buffer-B)
909 "!!!killed buffer!!!")
910 bufCname (cond ((not (ediff-3way-job))
912 ((ediff-buffer-live-p ediff-buffer-C)
913 (buffer-name ediff-buffer-C))
914 (t "!!!killed buffer!!!")))
915 (setq total-diffs (format "%-4d" ediff-number-of-differences)
916 cur-diff
917 (cond ((= ediff-current-difference -1) " _")
918 ((= ediff-current-difference
919 ediff-number-of-differences)
920 " $")
921 (t (format
922 "%4d" (1+ ediff-current-difference))))
923 job-name ediff-job-name))
924 ;; back in the meta buf
925 (setq pt (point))
926 (insert cur-diff "/" total-diffs "\t"
927 (buffer-name elt)
928 (format ": %s" (ediff-abbrev-jobname job-name)))
929 (insert
930 "\n\t\t " bufAname " " bufBname " " bufCname "\n")
931 (ediff-set-meta-overlay pt (point) elt))))
932 ) ; while
933 (set-buffer-modified-p nil)
934 (goto-char point)
937 ;; sets overlay around a meta record with 'ediff-meta-info property PROP
938 (defun ediff-set-meta-overlay (b e prop)
939 (let (overl)
940 (setq overl (ediff-make-overlay b e))
941 (if ediff-emacs-p
942 (ediff-overlay-put overl 'mouse-face 'highlight)
943 (ediff-overlay-put overl 'highlight t))
944 (ediff-overlay-put overl 'ediff-meta-info prop)))
946 (defun ediff-mark-for-hiding (unmark)
947 "Mark session for hiding. With prefix arg, unmark."
948 (interactive "P")
949 (let* ((pos (ediff-event-point last-command-event))
950 (meta-buf (ediff-event-buffer last-command-event))
951 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
952 (info (ediff-get-meta-info meta-buf pos))
953 (session-buf (ediff-get-session-buffer info)))
955 (if (eq (ediff-get-session-status info) ?H)
956 (setq unmark t))
957 (if unmark
958 (ediff-set-session-status info nil)
959 (if (ediff-buffer-live-p session-buf)
960 (error "Can't hide active session, %s" (buffer-name session-buf)))
961 (ediff-set-session-status info ?H))
962 (or unmark
963 (ediff-next-meta-item 1))
964 (ediff-update-meta-buffer meta-buf)
967 (defun ediff-mark-for-operation (unmark)
968 "Mark session for a group operation. With prefix arg, unmark."
969 (interactive "P")
970 (let* ((pos (ediff-event-point last-command-event))
971 (meta-buf (ediff-event-buffer last-command-event))
972 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
973 (info (ediff-get-meta-info meta-buf pos)))
975 (if (eq (ediff-get-session-status info) ?*)
976 (setq unmark t))
977 (if unmark
978 (ediff-set-session-status info nil)
979 (ediff-set-session-status info ?*))
980 (or unmark
981 (ediff-next-meta-item 1))
982 (ediff-update-meta-buffer meta-buf)
985 (defun ediff-hide-marked-sessions (unhide)
986 "Hide marked sessions. With prefix arg, unhide."
987 (interactive "P")
988 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
989 (meta-list (cdr ediff-meta-list))
990 (from (if unhide ?I ?H))
991 (to (if unhide ?H ?I))
992 (numMarked 0)
993 active-sessions-exist session-buf elt)
994 (while meta-list
995 (setq elt (car meta-list)
996 meta-list (cdr meta-list)
997 session-buf (ediff-get-session-buffer elt))
999 (if (eq (ediff-get-session-status elt) from)
1000 (progn
1001 (setq numMarked (1+ numMarked))
1002 (if (and (eq to ?I) (buffer-live-p session-buf))
1003 ;; shouldn't hide active sessions
1004 (setq active-sessions-exist t)
1005 (ediff-set-session-status elt to)))))
1006 (if (> numMarked 0)
1007 (ediff-update-meta-buffer grp-buf)
1008 (beep)
1009 (if unhide
1010 (message "Nothing to reveal...")
1011 (message "Nothing to hide...")))
1012 (if active-sessions-exist
1013 (message "Note: didn't hide active sessions!"))
1016 ;; Apply OPERATION to marked sessions. Operation expects one argument of type
1017 ;; meta-list member (not the first one), i.e., a regular session description.
1018 ;; Returns number of marked sessions on which operation was performed
1019 (defun ediff-operate-on-marked-sessions (operation)
1020 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1021 (meta-list (cdr ediff-meta-list))
1022 (marksym ?*)
1023 (numMarked 0)
1024 (sessionNum 0)
1025 elt)
1026 (while meta-list
1027 (setq elt (car meta-list)
1028 meta-list (cdr meta-list)
1029 sessionNum (1+ sessionNum))
1030 (if (eq (ediff-get-session-status elt) marksym)
1031 (save-excursion
1032 (setq numMarked (1+ numMarked))
1033 (funcall operation elt sessionNum))))
1034 (ediff-update-meta-buffer grp-buf) ; just in case
1035 numMarked
1038 (defun ediff-append-custom-diff (session sessionNum)
1039 (or (ediff-collect-diffs-metajob)
1040 (error "Sorry, I don't do this for everyone..."))
1041 (let ((session-buf (ediff-get-session-buffer session))
1042 (meta-diff-buff ediff-meta-diff-buffer)
1043 (metajob ediff-metajob-name)
1044 tmp-buf custom-diff-buf)
1045 (if (ediff-buffer-live-p session-buf)
1046 (ediff-eval-in-buffer session-buf
1047 (if (eq ediff-control-buffer session-buf) ; individual session
1048 (progn
1049 (ediff-compute-custom-diffs-maybe)
1050 (setq custom-diff-buf ediff-custom-diff-buffer)))))
1052 (or (ediff-buffer-live-p meta-diff-buff)
1053 (error "Ediff: something wrong--no multiple diffs buffer"))
1055 (cond ((ediff-buffer-live-p custom-diff-buf)
1056 (save-excursion
1057 (set-buffer meta-diff-buff)
1058 (goto-char (point-max))
1059 (insert-buffer custom-diff-buf)
1060 (insert "\n")))
1061 ((memq metajob '(ediff-directories
1062 ediff-merge-directories
1063 ediff-merge-directories-with-ancestor))
1064 ;; get diffs by calling shell command on ediff-custom-diff-program
1065 (save-excursion
1066 (set-buffer (setq tmp-buf (get-buffer-create ediff-tmp-buffer)))
1067 (erase-buffer)
1068 (shell-command
1069 (format "%s %s %s %s"
1070 ediff-custom-diff-program ediff-custom-diff-options
1071 (ediff-get-session-objA-name session)
1072 (ediff-get-session-objB-name session))
1074 (save-excursion
1075 (set-buffer meta-diff-buff)
1076 (goto-char (point-max))
1077 (insert-buffer tmp-buf)
1078 (insert "\n")))
1080 (error "Can't make context diff for Session %d" sessionNum )))
1083 (defun ediff-collect-custom-diffs ()
1084 "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'.
1085 This operation is defined only for `ediff-directories' and
1086 `ediff-directory-revisions', since its intent is to produce
1087 multifile patches. For `ediff-directory-revisions', we insist that
1088 all marked sessions must be active."
1089 (interactive)
1090 (or (ediff-buffer-live-p ediff-meta-diff-buffer)
1091 (setq ediff-meta-diff-buffer
1092 (get-buffer-create
1093 (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
1094 (ediff-eval-in-buffer ediff-meta-diff-buffer
1095 (erase-buffer))
1096 (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
1097 ;; did something
1098 (display-buffer ediff-meta-diff-buffer 'not-this-window)
1099 (beep)
1100 (message "No marked sessions found")))
1102 (defun ediff-meta-show-patch ()
1103 "Show the multi-file patch associated with this group session."
1104 (interactive)
1105 (let* ((pos (ediff-event-point last-command-event))
1106 (meta-buf (ediff-event-buffer last-command-event))
1107 (info (ediff-get-meta-info meta-buf pos 'noerror))
1108 (patchbuffer ediff-meta-patchbufer))
1109 (if (ediff-buffer-live-p patchbuffer)
1110 (ediff-eval-in-buffer patchbuffer
1111 (save-restriction
1112 (if (not info)
1113 (widen)
1114 (narrow-to-region
1115 (ediff-get-session-objB-name info)
1116 (ediff-get-session-objC-name info)))
1117 (set-buffer (get-buffer-create ediff-tmp-buffer))
1118 (erase-buffer)
1119 (insert-buffer patchbuffer)
1120 (display-buffer ediff-tmp-buffer 'not-this-window)
1122 (error "The patch buffer wasn't found"))))
1125 ;; This function executes in meta buffer. It knows where event happened.
1126 (defun ediff-filegroup-action ()
1127 "Execute appropriate action for the selected session."
1128 (interactive)
1129 (let* ((pos (ediff-event-point last-command-event))
1130 (meta-buf (ediff-event-buffer last-command-event))
1131 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1132 (info (ediff-get-meta-info meta-buf pos))
1133 session-buf file1 file2 file3 regexp)
1135 (setq session-buf (ediff-get-session-buffer info)
1136 file1 (ediff-get-session-objA-name info)
1137 file2 (ediff-get-session-objB-name info)
1138 file3 (ediff-get-session-objC-name info))
1140 ;; make sure we don't start on hidden sessions
1141 ;; ?H means marked for hiding. ?I means invalid (hidden).
1142 (if (memq (ediff-get-session-status info) '(?I))
1143 (progn
1144 (beep)
1145 (if (y-or-n-p "This session is marked as hidden, unmark? ")
1146 (progn
1147 (ediff-set-session-status info nil)
1148 (ediff-update-meta-buffer meta-buf))
1149 (error "Aborted"))))
1151 (ediff-eval-in-buffer meta-buf
1152 (goto-char pos) ; if the user clicked on session--move point there
1153 ;; First handle sessions involving directories (which are themselves
1154 ;; session groups)
1155 ;; After that handle individual sessions
1156 (cond ((and (file-directory-p file1)
1157 (stringp file2) (file-directory-p file2)
1158 (if (stringp file3) (file-directory-p file1) t))
1159 ;; do ediff/ediff-merge on subdirectories
1160 (if (ediff-buffer-live-p session-buf)
1161 (ediff-show-meta-buffer session-buf)
1162 (setq regexp (read-string "Filter through regular expression: "
1163 nil 'ediff-filtering-regexp-history))
1164 (ediff-directories-internal
1165 file1 file2 file3 regexp
1166 ediff-session-action-function
1167 ediff-metajob-name
1168 ;; make it update car info after startup
1169 (` (list (lambda ()
1170 ;; child session group should know its parent
1171 (setq ediff-parent-meta-buffer
1172 (quote (, ediff-meta-buffer)))
1173 ;; and parent will know its child
1174 (setcar (quote (, info)) ediff-meta-buffer)))))))
1176 ;; Do ediff-revision on a subdirectory
1177 ((and (ediff-one-filegroup-metajob)
1178 (ediff-revision-metajob)
1179 (file-directory-p file1))
1180 (if (ediff-buffer-live-p session-buf)
1181 (ediff-show-meta-buffer session-buf)
1182 (setq regexp (read-string "Filter through regular expression: "
1183 nil 'ediff-filtering-regexp-history))
1184 (ediff-directory-revisions-internal
1185 file1 regexp
1186 ediff-session-action-function ediff-metajob-name
1187 ;; make it update car info after startup
1188 (` (list (lambda ()
1189 ;; child session group should know its parent
1190 (setq ediff-parent-meta-buffer
1191 (quote (, ediff-meta-buffer)))
1192 ;; and parent will know its child
1193 (setcar (quote (, info)) ediff-meta-buffer)))))))
1195 ;; From here on---only individual session handlers
1197 ;; handle an individual session with a live control buffer
1198 ((ediff-buffer-live-p session-buf)
1199 (ediff-eval-in-buffer session-buf
1200 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1201 (ediff-recenter 'no-rehighlight)))
1203 ((ediff-problematic-session-p info)
1204 (beep)
1205 (if (y-or-n-p
1206 "This session's ancestor is a directory, merge without the ancestor? ")
1207 (ediff-merge-files
1208 file1 file2
1209 ;; provide startup hooks
1210 (` (list (lambda ()
1211 (setq ediff-meta-buffer (, (current-buffer)))
1212 ;; see below for the explanation of what this does
1213 (setcar
1214 (quote (, info)) ediff-control-buffer)))))
1215 (error "Aborted")))
1216 ((ediff-one-filegroup-metajob) ; needs 1 file arg
1217 (funcall ediff-session-action-function
1218 file1
1219 ;; provide startup hooks
1220 (` (list (lambda ()
1221 (setq ediff-meta-buffer (, (current-buffer)))
1222 ;; see below for explanation of what this does
1223 (setcar
1224 (quote (, info)) ediff-control-buffer))))))
1225 ((not (ediff-metajob3)) ; need 2 file args
1226 (funcall ediff-session-action-function
1227 file1 file2
1228 ;; provide startup hooks
1229 (` (list (lambda ()
1230 (setq ediff-meta-buffer (, (current-buffer)))
1231 ;; this makes ediff-startup pass the value of
1232 ;; ediff-control-buffer back to the meta
1233 ;; level, to the record in the meta list
1234 ;; containing the information about the
1235 ;; session associated with that
1236 ;; ediff-control-buffer
1237 (setcar
1238 (quote (, info)) ediff-control-buffer))))))
1239 ((ediff-metajob3) ; need 3 file args
1240 (funcall ediff-session-action-function
1241 file1 file2 file3
1242 ;; arrange startup hooks
1243 (` (list (lambda ()
1244 (setq ediff-meta-buffer (, (current-buffer)))
1245 (setcar
1246 (quote (, info)) ediff-control-buffer))))))
1247 ) ; cond
1248 ) ; eval in meta-buf
1251 (defun ediff-registry-action ()
1252 "Switch to a selected session."
1253 (interactive)
1254 (let* ((pos (ediff-event-point last-command-event))
1255 (buf (ediff-event-buffer last-command-event))
1256 (ctl-buf (ediff-get-meta-info buf pos)))
1258 (if (ediff-buffer-live-p ctl-buf)
1259 ;; check if this is ediff-control-buffer or ediff-meta-buffer
1260 (if (ediff-eval-in-buffer ctl-buf
1261 (eq (key-binding "q") 'ediff-quit-meta-buffer))
1262 ;; it's a meta-buffer -- last action should just display it
1263 (ediff-show-meta-buffer ctl-buf)
1264 ;; it's a session buffer -- invoke go back to session
1265 (ediff-eval-in-buffer ctl-buf
1266 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1267 (ediff-recenter 'no-rehighlight)))
1268 (beep)
1269 (message "You've selected a stale session --- try again")
1270 (ediff-update-registry))
1271 (ediff-eval-in-buffer buf
1272 (goto-char pos))
1276 (defun ediff-show-meta-buffer (&optional meta-buf)
1277 "Show the session group buffer."
1278 (interactive)
1279 (let (wind frame silent)
1280 (if meta-buf (setq silent t))
1282 (setq meta-buf (or meta-buf ediff-meta-buffer))
1283 (cond ((not (bufferp meta-buf))
1284 (error "This Ediff session is not part of a session group"))
1285 ((not (ediff-buffer-live-p meta-buf))
1286 (error
1287 "Can't find this session's group panel -- session itself is ok")))
1289 (ediff-cleanup-meta-buffer meta-buf)
1290 (ediff-eval-in-buffer meta-buf
1291 (save-excursion
1292 (cond ((setq wind (ediff-get-visible-buffer-window meta-buf))
1293 (or silent
1294 (message
1295 "Already showing the group panel for this session"))
1296 (set-window-buffer wind meta-buf)
1297 (select-window wind))
1298 ((window-live-p (setq wind ediff-window-C)) ;in merge--merge buf
1299 (set-window-buffer ediff-window-C meta-buf)
1300 (select-window wind))
1301 ((window-live-p (setq wind ediff-window-A))
1302 (set-window-buffer ediff-window-A meta-buf)
1303 (select-window wind))
1304 ((window-live-p (setq wind ediff-window-B))
1305 (set-window-buffer ediff-window-B meta-buf)
1306 (select-window wind))
1307 ((and
1308 (setq wind
1309 (ediff-get-visible-buffer-window ediff-registry-buffer))
1310 (ediff-window-display-p))
1311 (select-window wind)
1312 (other-window 1)
1313 (set-window-buffer (selected-window) meta-buf))
1314 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1315 (set-window-buffer (selected-window) meta-buf)))
1317 (if (and (ediff-window-display-p)
1318 (window-live-p
1319 (setq wind (ediff-get-visible-buffer-window meta-buf))))
1320 (progn
1321 (setq frame (window-frame wind))
1322 (raise-frame frame)
1323 (ediff-reset-mouse frame)))
1324 (run-hooks 'ediff-show-session-group-hook)
1327 (defun ediff-show-meta-buff-from-registry ()
1328 "Display the session group buffer for a selected session group."
1329 (interactive)
1330 (let* ((pos (ediff-event-point last-command-event))
1331 (meta-buf (ediff-event-buffer last-command-event))
1332 (info (ediff-get-meta-info meta-buf pos))
1333 (meta-or-session-buf info))
1334 (ediff-eval-in-buffer meta-or-session-buf
1335 (ediff-show-meta-buffer))))
1337 ;;;###autoload
1338 (defun ediff-show-registry ()
1339 "Display Ediff's registry."
1340 (interactive)
1341 (ediff-update-registry)
1342 (if (not (ediff-buffer-live-p ediff-registry-buffer))
1343 (error "No active Ediff sessions or corrupted session registry"))
1344 (let (wind frame)
1345 ;; for some reason, point moves in ediff-registry-buffer, so we preserve it
1346 ;; explicitly
1347 (ediff-eval-in-buffer ediff-registry-buffer
1348 (save-excursion
1349 (cond ((setq wind
1350 (ediff-get-visible-buffer-window ediff-registry-buffer))
1351 (message "Already showing the registry")
1352 (set-window-buffer wind ediff-registry-buffer)
1353 (select-window wind))
1354 ((window-live-p ediff-window-C)
1355 (set-window-buffer ediff-window-C ediff-registry-buffer)
1356 (select-window ediff-window-C))
1357 ((window-live-p ediff-window-A)
1358 (set-window-buffer ediff-window-A ediff-registry-buffer)
1359 (select-window ediff-window-A))
1360 ((window-live-p ediff-window-B)
1361 (set-window-buffer ediff-window-B ediff-registry-buffer)
1362 (select-window ediff-window-B))
1363 ((and (setq wind
1364 (ediff-get-visible-buffer-window ediff-meta-buffer))
1365 (ediff-window-display-p))
1366 (select-window wind)
1367 (other-window 1)
1368 (set-window-buffer (selected-window) ediff-registry-buffer))
1369 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1370 (set-window-buffer (selected-window) ediff-registry-buffer)))
1372 (if (ediff-window-display-p)
1373 (progn
1374 (setq frame
1375 (window-frame
1376 (ediff-get-visible-buffer-window ediff-registry-buffer)))
1377 (raise-frame frame)
1378 (ediff-reset-mouse frame)))
1379 (run-hooks 'ediff-show-registry-hook)
1382 ;;;###autoload
1383 (defalias 'eregistry 'ediff-show-registry)
1385 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a
1386 ;; parent meta-buf
1387 ;; Check if META-BUF exists before calling this function
1388 (defun ediff-update-meta-buffer (meta-buf)
1389 (ediff-eval-in-buffer (current-buffer)
1390 (if (ediff-buffer-live-p meta-buf)
1391 (ediff-eval-in-buffer meta-buf
1392 (funcall ediff-meta-redraw-function ediff-meta-list))
1395 (defun ediff-update-registry ()
1396 (ediff-eval-in-buffer (current-buffer)
1397 (if (ediff-buffer-live-p ediff-registry-buffer)
1398 (ediff-redraw-registry-buffer)
1399 (ediff-prepare-meta-buffer
1400 'ediff-registry-action
1401 ediff-session-registry
1402 "*Ediff Registry"
1403 'ediff-redraw-registry-buffer
1404 'ediff-registry))
1407 ;; if meta-buf exists, it is redrawn along with parent. Otherwise, nothing
1408 ;; happens
1409 (defun ediff-cleanup-meta-buffer (meta-buffer)
1410 (if (ediff-buffer-live-p meta-buffer)
1411 (ediff-eval-in-buffer meta-buffer
1412 (ediff-update-meta-buffer meta-buffer)
1413 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1414 (ediff-update-meta-buffer ediff-parent-meta-buffer)))))
1416 ;; t if no session in progress
1417 (defun ediff-safe-to-quit (meta-buffer)
1418 (if (ediff-buffer-live-p meta-buffer)
1419 (let ((lis ediff-meta-list)
1420 (cont t)
1421 buffer-read-only)
1422 (ediff-update-meta-buffer meta-buffer)
1423 (ediff-eval-in-buffer meta-buffer
1424 (setq lis (cdr lis)) ; discard the description part of meta-list
1425 (while (and cont lis)
1426 (if (ediff-buffer-live-p
1427 (ediff-get-group-buffer lis)) ; in progress
1428 (setq cont nil))
1429 (setq lis (cdr lis)))
1430 cont))))
1432 (defun ediff-quit-meta-buffer ()
1433 "If no unprocessed sessions in the group, delete the meta buffer.
1434 If no session is in progress, ask to confirm before deleting meta buffer.
1435 Otherwise, bury the meta buffer.
1436 If this is a session registry buffer then just bury it."
1437 (interactive)
1438 (let* ((buf (current-buffer))
1439 (dir-diffs-buffer ediff-dir-diffs-buffer)
1440 (meta-diff-buffer ediff-meta-diff-buffer)
1441 (parent-buf ediff-parent-meta-buffer)
1442 (dont-show-registry (eq buf ediff-registry-buffer)))
1443 (if dont-show-registry
1444 (bury-buffer)
1445 (ediff-cleanup-meta-buffer buf)
1446 (cond ((and (ediff-safe-to-quit buf)
1447 (y-or-n-p "Quit this session group? "))
1448 (message "")
1449 (ediff-dispose-of-meta-buffer buf))
1450 ((ediff-safe-to-quit buf)
1451 (bury-buffer))
1453 (error
1454 "This session group has active sessions---cannot exit")))
1455 (ediff-cleanup-meta-buffer parent-buf)
1456 (ediff-kill-buffer-carefully dir-diffs-buffer)
1457 (ediff-kill-buffer-carefully meta-diff-buffer)
1458 (if (ediff-buffer-live-p parent-buf)
1459 (progn
1460 (setq dont-show-registry t)
1461 (ediff-show-meta-buffer parent-buf)))
1463 (or dont-show-registry
1464 (ediff-show-registry))))
1466 (defun ediff-dispose-of-meta-buffer (buf)
1467 (setq ediff-session-registry (delq buf ediff-session-registry))
1468 (ediff-eval-in-buffer buf
1469 (if (ediff-buffer-live-p ediff-dir-diffs-buffer)
1470 (kill-buffer ediff-dir-diffs-buffer)))
1471 (kill-buffer buf))
1474 ;; Obtain information on a meta record where the user clicked or typed
1475 ;; BUF is the buffer where this happened and POINT is the position
1476 ;; If optional NOERROR arg is given, don't report error and return nil if no
1477 ;; meta info is found on line.
1478 (defun ediff-get-meta-info (buf point &optional noerror)
1479 (let (result olist tmp)
1480 (if (and point (ediff-buffer-live-p buf))
1481 (ediff-eval-in-buffer buf
1482 (if ediff-xemacs-p
1483 (setq result
1484 (if (setq tmp (extent-at point buf 'ediff-meta-info))
1485 (ediff-overlay-get tmp 'ediff-meta-info)))
1486 (setq olist (overlays-at point))
1487 (setq olist
1488 (mapcar (function (lambda (elt)
1489 (overlay-get elt 'ediff-meta-info)))
1490 olist))
1491 (while (and olist (null (car olist))
1492 (overlay-get (car olist) 'invisible))
1493 (setq olist (cdr olist)))
1494 (setq result (car olist)))))
1495 (if result
1496 result
1497 (if noerror
1499 (ediff-update-registry)
1500 (error "No session info in this line")))))
1502 ;; return location of the next meta overlay after point
1503 (defun ediff-next-meta-overlay-start (point)
1504 (if (eobp)
1505 (goto-char (point-min))
1506 (let (overl)
1507 (if ediff-xemacs-p
1508 (progn
1509 (setq overl (extent-at point (current-buffer) 'ediff-meta-info))
1510 (if overl
1511 (setq overl (next-extent overl))
1512 (setq overl (next-extent (current-buffer))))
1513 (if overl
1514 (extent-start-position overl)
1515 (point-max)))
1516 (setq overl (car (overlays-at point)))
1517 (if (and overl (overlay-get overl 'ediff-meta-info))
1518 ;; note: end of current overlay is the beginning of the next one
1519 (overlay-end overl)
1520 (next-overlay-change point))))
1523 (defun ediff-previous-meta-overlay-start (point)
1524 (if (bobp)
1525 (goto-char (point-max))
1526 (let (overl)
1527 (if ediff-xemacs-p
1528 (progn
1529 (setq overl (extent-at point (current-buffer) 'ediff-meta-info))
1530 (if overl
1531 (setq overl (previous-extent overl))
1532 (setq overl (previous-extent (current-buffer))))
1533 (if overl
1534 (extent-start-position overl)
1535 (point-min)))
1536 (setq overl (car (overlays-at point)))
1537 (if (and overl (overlay-get overl 'ediff-meta-info))
1538 (setq point (overlay-start overl)))
1539 ;; to get to the beginning of prev overlay
1540 (if (not (bobp))
1541 ;; trickery to overcome an emacs bug--doesn't always find previous
1542 ;; overlay change correctly
1543 (setq point (1- point)))
1544 (setq point (previous-overlay-change point))
1545 ;; If we are not over an overlay after subtracting 1, it means we are
1546 ;; in the description area preceding session records. In this case,
1547 ;; goto the top of the registry buffer.
1548 (or (car (overlays-at point))
1549 (setq point (point-min)))
1550 point
1551 ))))
1553 ;; this is the action invoked when the user selects a patch from the meta
1554 ;; buffer.
1555 (defun ediff-patch-file-form-meta (file &optional startup-hooks)
1556 (let* ((pos (ediff-event-point last-command-event))
1557 (meta-buf (ediff-event-buffer last-command-event))
1558 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1559 (info (ediff-get-meta-info meta-buf pos))
1560 (meta-patchbuf ediff-meta-patchbufer)
1561 session-buf beg-marker end-marker)
1563 (if (or (file-directory-p file) (string-match "/dev/null" file))
1564 (error "`%s' is not an ordinary file" (file-name-as-directory file)))
1565 (setq session-buf (ediff-get-session-buffer info)
1566 beg-marker (ediff-get-session-objB-name info)
1567 end-marker (ediff-get-session-objC-name info))
1569 (or (ediff-buffer-live-p session-buf) ; either an active patch session
1570 (null session-buf) ; or it is a virgin session
1571 (error
1572 "Patch has been already applied to this file--cannot be repeated!"))
1574 (ediff-eval-in-buffer meta-patchbuf
1575 (save-restriction
1576 (widen)
1577 (narrow-to-region beg-marker end-marker)
1578 (ediff-patch-file-internal meta-patchbuf file startup-hooks)))))
1581 (defun ediff-meta-mark-equal-files ()
1582 "Run though the session list and mark identical files.
1583 This is used only for sessions that involve 2 or 3 files at the same time."
1584 (interactive)
1585 (let ((list (cdr ediff-meta-list))
1586 fileinfo1 fileinfo2 fileinfo3 elt)
1587 (while (setq elt (car list))
1588 (setq fileinfo1 (ediff-get-session-objA elt)
1589 fileinfo2 (ediff-get-session-objB elt)
1590 fileinfo3 (ediff-get-session-objC elt))
1591 (ediff-set-file-eqstatus fileinfo1 nil)
1592 (ediff-set-file-eqstatus fileinfo2 nil)
1593 (ediff-set-file-eqstatus fileinfo3 nil)
1595 (ediff-mark-if-equal fileinfo1 fileinfo2)
1596 (if (ediff-metajob3)
1597 (progn
1598 (ediff-mark-if-equal fileinfo1 fileinfo3)
1599 (ediff-mark-if-equal fileinfo2 fileinfo3)))
1600 (setq list (cdr list))))
1601 (ediff-update-meta-buffer (current-buffer)))
1603 ;; mark files 1 and 2 as equal, if they are.
1604 (defun ediff-mark-if-equal (fileinfo1 fileinfo2)
1605 (get-buffer-create ediff-tmp-buffer)
1606 (or (file-directory-p (car fileinfo1))
1607 (file-directory-p (car fileinfo2))
1608 (if (= (ediff-make-diff2-buffer
1609 ediff-tmp-buffer (car fileinfo1) (car fileinfo2))
1611 (progn
1612 (ediff-set-file-eqstatus fileinfo1 t)
1613 (ediff-set-file-eqstatus fileinfo2 t)))))
1617 ;;; Local Variables:
1618 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1619 ;;; eval: (put 'ediff-eval-in-buffer 'lisp-indent-hook 1)
1620 ;;; End:
1622 (provide 'ediff-mult)
1623 (require 'ediff-util)
1625 ;;; ediff-mult.el ends here