(easy-mmode-define-keymap):
[emacs.git] / lisp / ediff-mult.el
blob206ef40351bb755ee2f7c4169a24f5effe102dee
1 ;;; ediff-mult.el --- support for multi-file/multi-buffer processing in Ediff
3 ;; Copyright (C) 1995, 1996, 1997 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
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 ;; group buffer/regexp
229 (defsubst ediff-get-group-buffer (meta-list)
230 (nth 0 (car meta-list)))
232 (defsubst ediff-get-group-regexp (meta-list)
233 (nth 1 (car meta-list)))
234 ;; group objects
235 (defsubst ediff-get-group-objA (meta-list)
236 (nth 2 (car meta-list)))
237 (defsubst ediff-get-group-objB (meta-list)
238 (nth 3 (car meta-list)))
239 (defsubst ediff-get-group-objC (meta-list)
240 (nth 4 (car meta-list)))
241 (defsubst ediff-get-group-merge-autostore-dir (meta-list)
242 (nth 5 (car meta-list)))
244 ;; session buffer
245 (defsubst ediff-get-session-buffer (elt)
246 (nth 0 elt))
247 (defsubst ediff-get-session-status (elt)
248 (nth 1 elt))
249 (defsubst ediff-set-session-status (session-info new-status)
250 (setcar (cdr session-info) new-status))
251 ;; session objects
252 (defsubst ediff-get-session-objA (elt)
253 (nth 2 elt))
254 (defsubst ediff-get-session-objB (elt)
255 (nth 3 elt))
256 (defsubst ediff-get-session-objC (elt)
257 (nth 4 elt))
258 (defsubst ediff-get-session-objA-name (elt)
259 (car (nth 2 elt)))
260 (defsubst ediff-get-session-objB-name (elt)
261 (car (nth 3 elt)))
262 (defsubst ediff-get-session-objC-name (elt)
263 (car (nth 4 elt)))
264 ;; equality indicators
265 (defsubst ediff-get-file-eqstatus (elt)
266 (nth 1 elt))
267 (defsubst ediff-set-file-eqstatus (elt value)
268 (setcar (cdr elt) value))
270 ;; The activity marker is either or + (active session, i.e., ediff is currently
271 ;; run in it), or - (finished session, i.e., we've ran ediff in it and then
272 ;; exited). Return nil, if session is neither active nor finished
273 (defun ediff-get-session-activity-marker (session)
274 (let ((session-buf (ediff-get-session-buffer session)))
275 (cond ((null session-buf) nil) ; virgin session
276 ((ediff-buffer-live-p session-buf) ?+) ;active session
277 (t ?-))))
279 ;; checks if the session is a meta session
280 (defun ediff-meta-session-p (session-info)
281 (and (stringp (ediff-get-session-objA-name session-info))
282 (file-directory-p (ediff-get-session-objA-name session-info))
283 (stringp (ediff-get-session-objB-name session-info))
284 (file-directory-p (ediff-get-session-objB-name session-info))
285 (if (stringp (ediff-get-session-objC-name session-info))
286 (file-directory-p (ediff-get-session-objC-name session-info)) t)))
288 ;; set up the keymap in the meta buffer
289 (defun ediff-setup-meta-map()
290 (setq ediff-meta-buffer-map (make-sparse-keymap))
291 (suppress-keymap ediff-meta-buffer-map)
292 (define-key ediff-meta-buffer-map "q" 'ediff-quit-meta-buffer)
293 (define-key ediff-meta-buffer-map "T" 'ediff-toggle-filename-truncation)
294 (define-key ediff-meta-buffer-map "R" 'ediff-show-registry)
295 (define-key ediff-meta-buffer-map "E" 'ediff-documentation)
296 (define-key ediff-meta-buffer-map "v" ediff-meta-action-function)
297 (define-key ediff-meta-buffer-map "\C-m" ediff-meta-action-function)
298 (define-key ediff-meta-buffer-map " " 'ediff-next-meta-item)
299 (define-key ediff-meta-buffer-map "n" 'ediff-next-meta-item)
300 (define-key ediff-meta-buffer-map "\C-?" 'ediff-previous-meta-item)
301 (define-key ediff-meta-buffer-map "p" 'ediff-previous-meta-item)
302 (define-key ediff-meta-buffer-map [delete] 'ediff-previous-meta-item)
303 (define-key ediff-meta-buffer-map [backspace] 'ediff-previous-meta-item)
304 (or (ediff-one-filegroup-metajob)
305 (progn
306 (define-key ediff-meta-buffer-map "=" nil)
307 (define-key ediff-meta-buffer-map "==" 'ediff-meta-mark-equal-files)
308 (define-key ediff-meta-buffer-map "=m" 'ediff-meta-mark-equal-files)
309 (define-key ediff-meta-buffer-map "=h" 'ediff-meta-mark-equal-files)))
310 (if ediff-no-emacs-help-in-control-buffer
311 (define-key ediff-meta-buffer-map "\C-h" 'ediff-previous-meta-item))
312 (if ediff-emacs-p
313 (define-key ediff-meta-buffer-map [mouse-2] ediff-meta-action-function)
314 (define-key ediff-meta-buffer-map [button2] ediff-meta-action-function))
316 (use-local-map ediff-meta-buffer-map)
317 ;; modify ediff-meta-buffer-map here
318 (run-hooks 'ediff-meta-buffer-keymap-setup-hook))
320 (defun ediff-meta-mode ()
321 "This mode controls all operations on Ediff session groups.
322 It is entered through one of the following commands:
323 `ediff-directories'
324 `edirs'
325 `ediff-directories3'
326 `edirs3'
327 `ediff-merge-directories'
328 `edirs-merge'
329 `ediff-merge-directories-with-ancestor'
330 `edirs-merge-with-ancestor'
331 `ediff-directory-revisions'
332 `edir-revisions'
333 `ediff-merge-directory-revisions'
334 `edir-merge-revisions'
335 `ediff-merge-directory-revisions-with-ancestor'
336 `edir-merge-revisions-with-ancestor'
338 Commands:
339 \\{ediff-meta-buffer-map}"
340 (kill-all-local-variables)
341 (setq major-mode 'ediff-meta-mode)
342 (setq mode-name "MetaEdiff"))
345 ;; the keymap for the buffer showing directory differences
346 (suppress-keymap ediff-dir-diffs-buffer-map)
347 (define-key ediff-dir-diffs-buffer-map "q" 'ediff-bury-dir-diffs-buffer)
348 (define-key ediff-dir-diffs-buffer-map " " 'next-line)
349 (define-key ediff-dir-diffs-buffer-map "n" 'next-line)
350 (define-key ediff-dir-diffs-buffer-map "\C-?" 'previous-line)
351 (define-key ediff-dir-diffs-buffer-map "p" 'previous-line)
352 (define-key ediff-dir-diffs-buffer-map [delete] 'previous-line)
353 (define-key ediff-dir-diffs-buffer-map [backspace] 'previous-line)
355 (defun ediff-next-meta-item (count)
356 "Move to the next item in Ediff registry or session group buffer.
357 Moves in circular fashion. With numeric prefix arg, skip this many items."
358 (interactive "p")
359 (or count (setq count 1))
360 (let (overl)
361 (while (< 0 count)
362 (setq count (1- count))
363 (ediff-next-meta-item1)
364 (setq overl (ediff-get-meta-overlay-at-pos (point)))
365 ;; skip invisible ones
366 (while (and overl (ediff-overlay-get overl 'invisible))
367 (ediff-next-meta-item1)
368 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
370 ;; Move to the next meta item
371 (defun ediff-next-meta-item1 ()
372 (let (pos)
373 (setq pos (ediff-next-meta-overlay-start (point)))
374 (if pos (goto-char pos))
375 (if (eq ediff-metajob-name 'ediff-registry)
376 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
377 (search-forward "*Ediff" nil t))
378 (skip-chars-backward "a-zA-Z*"))
379 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
380 (backward-char 1)))))
383 (defun ediff-previous-meta-item (count)
384 "Move to the previous item in Ediff registry or session group buffer.
385 Moves in circular fashion. With numeric prefix arg, skip this many items."
386 (interactive "p")
387 (or count (setq count 1))
388 (let (overl)
389 (while (< 0 count)
390 (setq count (1- count))
391 (ediff-previous-meta-item1)
392 (setq overl (ediff-get-meta-overlay-at-pos (point)))
393 ;; skip invisible ones
394 (while (and overl (ediff-overlay-get overl 'invisible))
395 (ediff-previous-meta-item1)
396 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
398 (defun ediff-previous-meta-item1 ()
399 (let (pos)
400 (setq pos (ediff-previous-meta-overlay-start (point)))
401 ;;; ;; skip deleted
402 ;;; (while (ediff-get-session-status
403 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
404 ;;; (setq pos (ediff-previous-meta-overlay-start pos)))
406 (if pos (goto-char pos))
407 (if (eq ediff-metajob-name 'ediff-registry)
408 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
409 (search-forward "*Ediff" nil t))
410 (skip-chars-backward "a-zA-Z*"))
411 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
412 (backward-char 1)))
415 (defsubst ediff-add-slash-if-directory (dir file)
416 (if (file-directory-p (concat dir file))
417 (file-name-as-directory file)
418 file))
420 (defun ediff-toggle-filename-truncation ()
421 "Toggle truncation of long file names in session group buffers.
422 Set `ediff-meta-truncate-filenames' variable if you want to change the default
423 behavior."
424 (interactive)
425 (setq ediff-meta-truncate-filenames (not ediff-meta-truncate-filenames))
426 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
429 ;; DIR1, DIR2, DIR3 are directories. DIR3 can be nil.
430 ;; OUTPUT-DIR is a directory for auto-storing the results of merge jobs.
431 ;; Can be nil.
432 ;; REGEXP is a regexp used to filter out files in the directories.
433 ;; If a file is a directory in dir1 but not dir2 (or vice versa), it is not
434 ;; included in the intersection. However, a regular file that is a dir in dir3
435 ;; is included, since dir3 files are supposed to be ancestors for merging.
436 ;; Returns a list of the form:
437 ;; ((dir1 dir2 dir3) (f1 f2 f3) (f1 f2 f3) ...)
438 ;; dir3, f3 can be nil if intersecting only 2 directories.
439 ;; If COMPARISON-FUNC is given, use it. Otherwise, use string=
440 ;; DIFF-VAR contains the name of the variable in which to return the
441 ;; difference list (which represents the differences among the contents of
442 ;; directories). The diff list is of the form:
443 ;; ((dir1 dir2 dir3) (file . num) (file . num)...)
444 ;; where num encodes the set of dirs where the file is found:
445 ;; 2 - only dir1; 3 - only dir2; 5 - only dir3; 6 - dir1&2; 10 - dir1&3; etc.
446 (defun ediff-intersect-directories (jobname
447 diff-var regexp dir1 dir2
448 &optional
449 dir3 merge-autostore-dir comparison-func)
450 (setq comparison-func (or comparison-func 'string=))
451 (let (lis1 lis2 lis3 common auxdir1 auxdir2 auxdir3 difflist)
453 (setq auxdir1 (file-name-as-directory dir1)
454 lis1 (directory-files auxdir1 nil regexp)
455 lis1 (delete "." lis1)
456 lis1 (delete ".." lis1)
457 lis1 (mapcar
458 (lambda (elt)
459 (ediff-add-slash-if-directory auxdir1 elt))
460 lis1)
461 auxdir2 (file-name-as-directory dir2)
462 lis2 (mapcar
463 (lambda (elt)
464 (ediff-add-slash-if-directory auxdir2 elt))
465 (directory-files auxdir2 nil regexp)))
467 (if (stringp dir3)
468 (setq auxdir3 (file-name-as-directory dir3)
469 lis3 (mapcar
470 (lambda (elt)
471 (ediff-add-slash-if-directory auxdir3 elt))
472 (directory-files auxdir3 nil regexp))))
474 (if (ediff-nonempty-string-p merge-autostore-dir)
475 (setq merge-autostore-dir
476 (file-name-as-directory merge-autostore-dir)))
477 (setq common (ediff-intersection lis1 lis2 comparison-func))
479 ;; In merge with ancestor jobs, we don't intersect with lis3.
480 ;; If there is no ancestor, we'll offer to merge without the ancestor.
481 ;; So, we intersect with lis3 only when we are doing 3-way file comparison
482 (if (and lis3 (ediff-comparison-metajob3 jobname))
483 (setq common (ediff-intersection common lis3 comparison-func)))
485 ;; copying is needed because sort sorts via side effects
486 (setq common (sort (ediff-copy-list common) 'string-lessp))
488 ;; compute difference list
489 (setq difflist (ediff-set-difference
490 (ediff-union (ediff-union lis1 lis2 comparison-func)
491 lis3
492 comparison-func)
493 common
494 comparison-func)
495 difflist (delete "." difflist)
496 ;; copying is needed because sort sorts via side effects
497 difflist (sort (ediff-copy-list (delete ".." difflist))
498 'string-lessp))
500 (setq difflist (mapcar (lambda (elt) (cons elt 1)) difflist))
502 ;; check for files belonging to lis1/2/3
503 (mapcar (lambda (elt)
504 (if (member (car elt) lis1)
505 (setcdr elt (* (cdr elt) 2)))
506 (if (member (car elt) lis2)
507 (setcdr elt (* (cdr elt) 3)))
508 (if (member (car elt) lis3)
509 (setcdr elt (* (cdr elt) 5)))
511 difflist)
512 (setq difflist (cons (list regexp auxdir1 auxdir2 auxdir3) difflist))
514 ;; return the difference list back to the calling function
515 (set diff-var difflist)
517 ;; return result
518 (cons (list regexp auxdir1 auxdir2 auxdir3 merge-autostore-dir)
519 (mapcar
520 (lambda (elt)
521 (list (concat auxdir1 elt)
522 (concat auxdir2 elt)
523 (if lis3
524 (progn
525 ;; The following is done because:
526 ;; In merging with ancestor, we don't intersect
527 ;; with lis3. So, it is possible that elt is a
528 ;; file in auxdir1/2 but a directory in auxdir3
529 ;; Or elt may not exist in auxdir3 at all.
530 ;; In the first case, we add a slash at the end.
531 ;; In the second case, we insert nil.
532 (setq elt (ediff-add-slash-if-directory auxdir3 elt))
533 (if (file-exists-p (concat auxdir3 elt))
534 (concat auxdir3 elt))))))
535 common))
538 ;; find directory files that are under revision. Include subdirectories, since
539 ;; we may visit them recursively. DIR1 is the directory to inspect.
540 ;; MERGE-AUTOSTORE-DIR is the directory where to auto-store the results of
541 ;; merges. Can be nil.
542 (defun ediff-get-directory-files-under-revision (jobname
543 regexp dir1
544 &optional merge-autostore-dir)
545 (let (lis1 elt common auxdir1)
546 (setq auxdir1 (file-name-as-directory dir1)
547 lis1 (directory-files auxdir1 nil regexp))
549 (if (ediff-nonempty-string-p merge-autostore-dir)
550 (setq merge-autostore-dir
551 (file-name-as-directory merge-autostore-dir)))
553 (while lis1
554 (setq elt (car lis1)
555 lis1 (cdr lis1))
556 ;; take files under revision control
557 (cond ((file-directory-p (concat auxdir1 elt))
558 (setq common
559 (cons (ediff-add-slash-if-directory auxdir1 elt) common)))
560 ((and (featurep 'vc-hooks) (vc-backend (concat auxdir1 elt)))
561 (setq common (cons elt common)))
562 ;; The following two are needed only if vc-hooks isn't loaded.
563 ;; They won't recognize CVS files.
564 ((file-exists-p (concat auxdir1 elt ",v"))
565 (setq common (cons elt common)))
566 ((file-exists-p (concat auxdir1 "RCS/" elt ",v"))
567 (setq common (cons elt common)))
568 ) ; cond
569 ) ; while
571 (setq common (delete "./" common)
572 common (delete "../" common)
573 common (delete "RCS" common)
574 common (delete "CVS" common)
577 ;; copying is needed because sort sorts via side effects
578 (setq common (sort (ediff-copy-list common) 'string-lessp))
580 ;; return result
581 (cons (list regexp auxdir1 nil nil merge-autostore-dir)
582 (mapcar (lambda (elt) (list (concat auxdir1 elt) nil nil))
583 common))
587 ;; If file groups selected by patterns will ever be implemented, this
588 ;; comparison function might become useful.
589 ;;;; uses external variables PAT1 PAT2 to compare str1/2
590 ;;;; patterns must be of the form ???*???? where ??? are strings of chars
591 ;;;; containing no *.
592 ;;(defun ediff-pattern= (str1 str2)
593 ;; (let (pos11 pos12 pos21 pos22 len1 len2)
594 ;; (setq pos11 0
595 ;; len (length epat1)
596 ;; pos12 len)
597 ;; (while (and (< pos11 len) (not (= (aref epat1 pos11) ?*)))
598 ;; (setq pos11 (1+ pos11)))
599 ;; (while (and (> pos12 0) (not (= (aref epat1 (1- pos12)) ?*)))
600 ;; (setq pos12 (1- pos12)))
602 ;; (setq pos21 0
603 ;; len (length epat2)
604 ;; pos22 len)
605 ;; (while (and (< pos21 len) (not (= (aref epat2 pos21) ?*)))
606 ;; (setq pos21 (1+ pos21)))
607 ;; (while (and (> pos22 0) (not (= (aref epat2 (1- pos22)) ?*)))
608 ;; (setq pos22 (1- pos22)))
610 ;; (if (and (> (length str1) pos12) (>= pos12 pos11) (> pos11 -1)
611 ;; (> (length str2) pos22) (>= pos22 pos21) (> pos21 -1))
612 ;; (string= (substring str1 pos11 pos12)
613 ;; (substring str2 pos21 pos22)))
614 ;; ))
617 ;; Prepare meta-buffer in accordance with the argument-function and
618 ;; redraw-function. Must return the created meta-buffer.
619 (defun ediff-prepare-meta-buffer (action-func meta-list
620 meta-buffer-name redraw-function
621 jobname &optional startup-hooks)
622 (let* ((meta-buffer-name
623 (ediff-unique-buffer-name meta-buffer-name "*"))
624 (meta-buffer (get-buffer-create meta-buffer-name)))
625 (ediff-with-current-buffer meta-buffer
627 ;; comes first
628 (ediff-meta-mode)
630 (setq ediff-meta-action-function action-func
631 ediff-meta-redraw-function redraw-function
632 ediff-metajob-name jobname
633 ediff-meta-buffer meta-buffer)
635 ;; comes after ediff-meta-action-function is set
636 (ediff-setup-meta-map)
638 (if (eq ediff-metajob-name 'ediff-registry)
639 (progn
640 (setq ediff-registry-buffer meta-buffer
641 ediff-meta-list meta-list)
642 ;; this func is used only from registry buffer, not from other
643 ;; meta-buffs.
644 (define-key
645 ediff-meta-buffer-map "M" 'ediff-show-meta-buff-from-registry))
646 ;; Initialize the meta list -- don't do this for registry.
648 ;; We prepend '(nil nil) to all elts of meta-list, except the first.
649 ;; The first nil will later be replaced by the session buffer. The
650 ;; second is reserved for session status.
652 ;; (car ediff-meta-list) gets cons'ed with the session group buffer.
653 ;; Also, session objects A/B/C are turned into lists of the form
654 ;; (obj eq-indicator). Eq-indicator is either nil or =. Initialized to
655 ;; nil. If later it is discovered that this file is = to some other
656 ;; file in the same session, eq-indicator is changed to `='.
657 ;; For now, the eq-indicator is used only for 2 and 3-file jobs.
658 (setq ediff-meta-list
659 (cons (cons meta-buffer (car meta-list))
660 (mapcar
661 (lambda (elt)
662 (cons nil
663 (cons nil
664 ;; convert each obj to (obj nil),
665 ;; where nil is the initial value
666 ;; for eq-indicator -- see above
667 (mapcar (lambda (obj) (list obj nil))
668 elt))))
669 (cdr meta-list)))))
671 (or (eq meta-buffer ediff-registry-buffer)
672 (setq ediff-session-registry
673 (cons meta-buffer ediff-session-registry)))
675 ;; redraw-function uses ediff-meta-list
676 (funcall redraw-function ediff-meta-list)
678 ;; set read-only/non-modified
679 (setq buffer-read-only t)
680 (set-buffer-modified-p nil)
682 (run-hooks 'startup-hooks)
684 ;; Arrange to show directory contents differences
685 ;; Must be after run startup-hooks, since ediff-dir-difference-list is
686 ;; set inside these hooks
687 (if (eq action-func 'ediff-filegroup-action)
688 (progn
689 ;; put meta buffer in (car ediff-dir-difference-list)
690 (setq ediff-dir-difference-list
691 (cons (cons meta-buffer (car ediff-dir-difference-list))
692 (cdr ediff-dir-difference-list)))
694 (or (ediff-one-filegroup-metajob jobname)
695 (ediff-draw-dir-diffs ediff-dir-difference-list))
696 (define-key
697 ediff-meta-buffer-map "h" 'ediff-mark-for-hiding-at-pos)
698 (define-key ediff-meta-buffer-map "x" 'ediff-hide-marked-sessions)
699 (define-key
700 ediff-meta-buffer-map "m" 'ediff-mark-for-operation-at-pos)
701 (define-key ediff-meta-buffer-map "u" nil)
702 (define-key
703 ediff-meta-buffer-map "um" 'ediff-unmark-all-for-operation)
704 (define-key
705 ediff-meta-buffer-map "uh" 'ediff-unmark-all-for-hiding)
706 (cond ((ediff-collect-diffs-metajob jobname)
707 (define-key
708 ediff-meta-buffer-map "P" 'ediff-collect-custom-diffs))
709 ((ediff-patch-metajob jobname)
710 (define-key
711 ediff-meta-buffer-map "P" 'ediff-meta-show-patch)))
712 (define-key ediff-meta-buffer-map "^" 'ediff-up-meta-hierarchy)
713 (define-key ediff-meta-buffer-map "D" 'ediff-show-dir-diffs)))
715 (if (eq ediff-metajob-name 'ediff-registry)
716 (run-hooks 'ediff-registry-setup-hook)
717 (run-hooks 'ediff-after-session-group-setup-hook))
718 ) ; eval in meta-buffer
719 meta-buffer))
721 ;; Insert the activity marker for session SESSION in the meta buffer at point
722 ;; The activity marker is either SPC (untouched session), or + (active session,
723 ;; i.e., ediff is currently run in it), or - (finished session, i.e., we've ran
724 ;; ediff in it and then exited)
725 (defun ediff-insert-session-activity-marker-in-meta-buffer (session)
726 (insert
727 (cond ((ediff-get-session-activity-marker session))
728 ;; virgin session
729 (t " "))))
731 ;; Insert session status at point. Status is either ?H (marked for hiding), or
732 ;; ?I (hidden or invalid), or ?* (meaning marked for an operation; currently,
733 ;; such op can only be checking for equality)), or SPC (meaning neither marked
734 ;; nor invalid)
735 (defun ediff-insert-session-status-in-meta-buffer (session)
736 (insert
737 (cond ((ediff-get-session-status session)) ; session has status: ?H, ?I, ?*
738 ;; normal session, no marks or hidings
739 (t " "))))
741 ;; If NEW-MARKER is non-nil, use it to substitute the current activity marker
742 ;; in the meta buffer. If nil, use SPC
743 (defun ediff-replace-session-activity-marker-in-meta-buffer (point new-marker)
744 (let* ((overl (ediff-get-meta-overlay-at-pos point))
745 (session-info (ediff-overlay-get overl 'ediff-meta-info))
746 (activity-marker (ediff-get-session-activity-marker session-info))
747 buffer-read-only)
748 (or new-marker activity-marker (setq new-marker ?\ ))
749 (goto-char (ediff-overlay-start overl))
750 (if (eq (char-after (point)) new-marker)
751 () ; if marker shown in buffer is the same as new-marker, do nothing
752 (insert new-marker)
753 (delete-char 1)
754 (set-buffer-modified-p nil))))
756 ;; If NEW-STATUS is non-nil, use it to substitute the current status marker in
757 ;; the meta buffer. If nil, use SPC
758 (defun ediff-replace-session-status-in-meta-buffer (point new-status)
759 (let* ((overl (ediff-get-meta-overlay-at-pos point))
760 (session-info (ediff-overlay-get overl 'ediff-meta-info))
761 (status (ediff-get-session-status session-info))
762 buffer-read-only)
763 (setq new-status (or new-status status ?\ ))
764 (goto-char (ediff-overlay-start overl))
765 (forward-char 1) ; status is the second char in session record
766 (if (eq (char-after (point)) new-status)
767 () ; if marker shown in buffer is the same as new-marker, do nothing
768 (insert new-status)
769 (delete-char 1)
770 (set-buffer-modified-p nil))))
772 ;; insert all file info in meta buffer for a given session
773 (defun ediff-insert-session-info-in-meta-buffer (session-info sessionNum)
774 (let ((f1 (ediff-get-session-objA session-info))
775 (f2 (ediff-get-session-objB session-info))
776 (f3 (ediff-get-session-objC session-info))
777 (pt (point))
778 (hidden (eq (ediff-get-session-status session-info) ?I)))
779 ;; insert activity marker, i.e., SPC, - or +
780 (ediff-insert-session-activity-marker-in-meta-buffer session-info)
781 ;; insert session status, i.e., *, H
782 (ediff-insert-session-status-in-meta-buffer session-info)
783 (insert " Session " (int-to-string sessionNum) ":\n")
784 (ediff-meta-insert-file-info1 f1)
785 (ediff-meta-insert-file-info1 f2)
786 (ediff-meta-insert-file-info1 f3)
787 (ediff-set-meta-overlay pt (point) session-info sessionNum hidden)))
790 ;; this is a setup function for ediff-directories
791 ;; must return meta-buffer
792 (defun ediff-redraw-directory-group-buffer (meta-list)
793 ;; extract directories
794 (let ((meta-buf (ediff-get-group-buffer meta-list))
795 (empty t)
796 (sessionNum 0)
797 regexp elt merge-autostore-dir
798 point tmp-list buffer-read-only)
799 (ediff-with-current-buffer meta-buf
800 (setq point (point))
801 (erase-buffer)
802 ;; delete phony overlays that used to represent sessions before the buff
803 ;; was redrawn
804 (if ediff-emacs-p
805 (mapcar 'delete-overlay (overlays-in 1 1))
806 (map-extents 'delete-extent))
808 (insert (format ediff-meta-buffer-message
809 (ediff-abbrev-jobname ediff-metajob-name)))
811 (setq regexp (ediff-get-group-regexp meta-list)
812 merge-autostore-dir
813 (ediff-get-group-merge-autostore-dir meta-list))
815 (cond ((ediff-collect-diffs-metajob)
816 (insert
817 " P:\tcollect custom diffs of all marked sessions\n"))
818 ((ediff-patch-metajob)
819 (insert
820 " P:\tshow patch appropriately for the context (session or group)\n")))
821 (insert
822 " ^:\tshow parent session group\n")
823 (or (ediff-one-filegroup-metajob)
824 (insert
825 " D:\tshow differences among directories\n"
826 " ==:\tfor each session, show which files are identical\n"
827 " =h:\tlike ==, but also marks those sessions for hiding\n"
828 " =m:\tlike ==, but also marks those sessions for operation\n\n"))
830 (insert "\n")
831 (if (and (stringp regexp) (> (length regexp) 0))
832 (insert
833 (format "*** Filter-through regular expression: %s\n" regexp)))
834 (ediff-insert-dirs-in-meta-buffer meta-list)
835 (if (and ediff-autostore-merges (ediff-merge-metajob)
836 (ediff-nonempty-string-p merge-autostore-dir))
837 (insert (format
838 "\nMerge results are automatically stored in:\n\t%s\n"
839 merge-autostore-dir)))
840 (insert "\n
841 Size Last modified Name
842 ----------------------------------------------
846 ;; discard info on directories and regexp
847 (setq meta-list (cdr meta-list)
848 tmp-list meta-list)
849 (while (and tmp-list empty)
850 (if (and (car tmp-list)
851 (not (eq (ediff-get-session-status (car tmp-list)) ?I)))
852 (setq empty nil))
853 (setq tmp-list (cdr tmp-list)))
855 (if empty
856 (insert
857 " ****** ****** This session group has no members\n"))
859 ;; now organize file names like this:
860 ;; use-mark sizeA dateA sizeB dateB filename
861 ;; make sure directories are displayed with a trailing slash.
862 (while meta-list
863 (setq elt (car meta-list)
864 meta-list (cdr meta-list)
865 sessionNum (1+ sessionNum))
866 (if (eq (ediff-get-session-status elt) ?I)
868 (ediff-insert-session-info-in-meta-buffer elt sessionNum)))
869 (set-buffer-modified-p nil)
870 (goto-char point)
871 meta-buf)))
873 (defun ediff-update-markers-in-dir-meta-buffer (meta-list)
874 (let ((meta-buf (ediff-get-group-buffer meta-list))
875 session-info point overl buffer-read-only)
876 (ediff-with-current-buffer meta-buf
877 (setq point (point))
878 (goto-char (point-min))
879 (ediff-next-meta-item1)
880 (while (not (bobp))
881 (setq session-info (ediff-get-meta-info meta-buf (point) 'no-error)
882 overl (ediff-get-meta-overlay-at-pos (point)))
883 (if session-info
884 (progn
885 (cond ((eq (ediff-get-session-status session-info) ?I)
886 ;; Do hiding
887 (if overl (ediff-overlay-put overl 'invisible t)))
888 ((and (eq (ediff-get-session-status session-info) ?H)
889 overl (ediff-overlay-get overl 'invisible))
890 ;; Do unhiding
891 (ediff-overlay-put overl 'invisible nil))
892 (t (ediff-replace-session-activity-marker-in-meta-buffer
893 (point)
894 (ediff-get-session-activity-marker session-info))
895 (ediff-replace-session-status-in-meta-buffer
896 (point)
897 (ediff-get-session-status session-info))))))
898 (ediff-next-meta-item1) ; advance to the next item
899 ) ; end while
900 (set-buffer-modified-p nil)
901 (goto-char point))
902 meta-buf))
904 (defun ediff-update-session-marker-in-dir-meta-buffer (session-num)
905 (let (buffer-meta-overlays session-info overl buffer-read-only)
906 (setq overl
907 (if ediff-xemacs-p
908 (map-extents
909 (lambda (ext maparg)
910 (if (and
911 (ediff-overlay-get ext 'ediff-meta-info)
912 (eq (ediff-overlay-get ext 'ediff-meta-session-number)
913 session-num))
914 ext)))
915 ;; Emacs doesn't have map-extents, so try harder
916 ;; Splice overlay lists to get all buffer overlays
917 (setq buffer-meta-overlays (overlay-lists)
918 buffer-meta-overlays (append (car buffer-meta-overlays)
919 (cdr buffer-meta-overlays)))
920 (car
921 (delq nil
922 (mapcar
923 (lambda (overl)
924 (if (and
925 (ediff-overlay-get overl 'ediff-meta-info)
926 (eq (ediff-overlay-get
927 overl 'ediff-meta-session-number)
928 session-num))
929 overl))
930 buffer-meta-overlays)))))
931 (or overl
932 (error
933 "Bug in ediff-update-session-marker-in-dir-meta-buffer: no overlay with given number %S"
934 session-num))
935 (setq session-info (ediff-overlay-get overl 'ediff-meta-info))
936 (goto-char (ediff-overlay-start overl))
937 (ediff-replace-session-activity-marker-in-meta-buffer
938 (point)
939 (ediff-get-session-activity-marker session-info))
940 (ediff-replace-session-status-in-meta-buffer
941 (point)
942 (ediff-get-session-status session-info)))
943 (ediff-next-meta-item1))
947 ;; Check if this is a problematic session.
948 ;; Return nil if not. Otherwise, return symbol representing the problem
949 ;; At present, problematic sessions occur only in -with-ancestor comparisons
950 ;; when the ancestor is a directory rather than a file, or when there is no
951 ;; suitable ancestor file in the ancestor directory
952 (defun ediff-problematic-session-p (session)
953 (let ((f1 (ediff-get-session-objA-name session))
954 (f2 (ediff-get-session-objB-name session))
955 (f3 (ediff-get-session-objC-name session)))
956 (cond ((and (stringp f1) (not (file-directory-p f1))
957 (stringp f2) (not (file-directory-p f2))
958 ;; either invalid file name or a directory
959 (or (not (stringp f3)) (file-directory-p f3))
960 (ediff-ancestor-metajob))
961 ;; more may be added later
962 'ancestor-is-dir)
963 (t nil))))
965 (defun ediff-meta-insert-file-info1 (fileinfo)
966 (let ((fname (car fileinfo))
967 (feq (ediff-get-file-eqstatus fileinfo))
968 (max-filename-width (if ediff-meta-truncate-filenames
969 (- (window-width) 41)
970 500))
971 file-modtime file-size)
972 (cond ((not (stringp fname)) (setq file-size -2)) ; file doesn't exits
973 ((not (ediff-file-remote-p fname))
974 (if (file-exists-p fname)
975 ;; set real size and modtime
976 (setq file-size (ediff-file-size fname)
977 file-modtime (ediff-file-modtime fname))
978 (setq file-size -2))) ; file doesn't exist
979 ( t (setq file-size -1))) ; remote file
980 (if (stringp fname)
981 (insert
982 (format
983 "%s %s %-20s %s\n"
984 (if feq "=" " ") ; equality indicator
985 (format "%10s" (cond ((= file-size -1) "--")
986 ((< file-size -1) "--")
987 (t file-size)))
988 (cond ((= file-size -1) "*remote file*")
989 ((< file-size -1) "*file doesn't exist*")
990 (t (ediff-format-date (decode-time file-modtime))))
992 ;; dir names in meta lists have training slashes, so we just
993 ;; abbreviate the file name, if file exists
994 (if (and (not (stringp fname)) (< file-size -1))
995 "-------" ; file doesn't exist
996 (ediff-truncate-string-left
997 (ediff-abbreviate-file-name fname)
998 max-filename-width)))))))
1000 (defconst ediff-months '((1 . "Jan") (2 . "Feb") (3 . "Mar") (4 . "Apr")
1001 (5 . "May") (6 . "Jun") (7 . "Jul") (8 . "Aug")
1002 (9 . "Sep") (10 . "Oct") (11 . "Nov") (12 . "Dec"))
1003 "Months' associative array.")
1005 ;; returns 2char string
1006 (defsubst ediff-fill-leading-zero (num)
1007 (if (< num 10)
1008 (format "0%d" num)
1009 (number-to-string num)))
1011 ;; TIME is like the output of decode-time
1012 (defun ediff-format-date (time)
1013 (format "%s %2d %4d %s:%s:%s"
1014 (cdr (assoc (nth 4 time) ediff-months)) ; month
1015 (nth 3 time) ; day
1016 (nth 5 time) ; year
1017 (ediff-fill-leading-zero (nth 2 time)) ; hour
1018 (ediff-fill-leading-zero (nth 1 time)) ; min
1019 (ediff-fill-leading-zero (nth 0 time)) ; sec
1022 ;; Draw the directories
1023 (defun ediff-insert-dirs-in-meta-buffer (meta-list)
1024 (let* ((dir1 (ediff-abbreviate-file-name (ediff-get-group-objA meta-list)))
1025 (dir2 (ediff-get-group-objB meta-list))
1026 (dir2 (if (stringp dir2) (ediff-abbreviate-file-name dir2)))
1027 (dir3 (ediff-get-group-objC meta-list))
1028 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3))))
1029 (insert "*** Directory A: " dir1 "\n")
1030 (if dir2 (insert "*** Directory B: " dir2 "\n"))
1031 (if dir3 (insert "*** Directory C: " dir3 "\n"))
1032 (insert "\n")))
1034 (defun ediff-draw-dir-diffs (diff-list)
1035 (if (null diff-list) (error "Lost difference info on these directories"))
1036 (let* ((buf-name (ediff-unique-buffer-name
1037 "*Ediff File Group Differences" "*"))
1038 (regexp (ediff-get-group-regexp diff-list))
1039 (dir1 (ediff-abbreviate-file-name (ediff-get-group-objA diff-list)))
1040 (dir2 (ediff-abbreviate-file-name (ediff-get-group-objB diff-list)))
1041 (dir3 (ediff-get-group-objC diff-list))
1042 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3)))
1043 (meta-buf (ediff-get-group-buffer diff-list))
1044 (underline (make-string 26 ?-))
1045 file code
1046 buffer-read-only)
1047 ;; skip the directory part
1048 (setq diff-list (cdr diff-list))
1049 (setq ediff-dir-diffs-buffer (get-buffer-create buf-name))
1050 (ediff-with-current-buffer ediff-dir-diffs-buffer
1051 (use-local-map ediff-dir-diffs-buffer-map)
1052 (erase-buffer)
1053 (setq ediff-meta-buffer meta-buf)
1054 (insert "\t\t*** Directory Differences ***\n")
1055 (insert "
1056 Useful commands:
1057 `q': hide this buffer
1058 n,SPC: next line
1059 p,DEL: previous line\n\n")
1061 (if (and (stringp regexp) (> (length regexp) 0))
1062 (insert
1063 (format "\n*** Filter-through regular expression: %s\n" regexp)))
1064 (insert "\n")
1065 (insert (format "\n%-27s%-26s"
1066 (ediff-truncate-string-left
1067 (ediff-abbreviate-file-name
1068 (file-name-as-directory dir1))
1070 (ediff-truncate-string-left
1071 (ediff-abbreviate-file-name
1072 (file-name-as-directory dir2))
1073 25)))
1074 (if dir3
1075 (insert (format " %-25s\n"
1076 (ediff-truncate-string-left
1077 (ediff-abbreviate-file-name
1078 (file-name-as-directory dir3))
1079 25)))
1080 (insert "\n"))
1081 (insert (format "%s%s" underline underline))
1082 (if (stringp dir3)
1083 (insert (format "%s\n\n" underline))
1084 (insert "\n\n"))
1086 (if (null diff-list)
1087 (insert "\n\t*** No differences ***\n"))
1089 (while diff-list
1090 (setq file (car (car diff-list))
1091 code (cdr (car diff-list))
1092 diff-list (cdr diff-list))
1093 (if (= (mod code 2) 0) ; dir1
1094 (insert (format "%-27s"
1095 (ediff-truncate-string-left
1096 (ediff-abbreviate-file-name
1097 (if (file-directory-p (concat dir1 file))
1098 (file-name-as-directory file)
1099 file))
1100 24)))
1101 (insert (format "%-27s" "---")))
1102 (if (= (mod code 3) 0) ; dir2
1103 (insert (format "%-26s"
1104 (ediff-truncate-string-left
1105 (ediff-abbreviate-file-name
1106 (if (file-directory-p (concat dir2 file))
1107 (file-name-as-directory file)
1108 file))
1109 24)))
1110 (insert (format "%-26s" "---")))
1111 (if (stringp dir3)
1112 (if (= (mod code 5) 0) ; dir3
1113 (insert (format " %-25s"
1114 (ediff-truncate-string-left
1115 (ediff-abbreviate-file-name
1116 (if (file-directory-p (concat dir3 file))
1117 (file-name-as-directory file)
1118 file))
1119 24)))
1120 (insert (format " %-25s" "---"))))
1121 (insert "\n"))
1122 (setq buffer-read-only t)
1123 (set-buffer-modified-p nil)) ; eval in diff buffer
1126 (defun ediff-bury-dir-diffs-buffer ()
1127 "Bury the directory difference buffer. Display the meta buffer instead."
1128 (interactive)
1129 (let ((buf ediff-meta-buffer)
1130 wind)
1131 (bury-buffer)
1132 (if (setq wind (ediff-get-visible-buffer-window buf))
1133 (select-window wind)
1134 (set-window-buffer (selected-window) buf))))
1136 ;; executes in dir session group buffer
1137 ;; show buffer differences
1138 (defun ediff-show-dir-diffs ()
1139 "Display differences among the directories involved in session group."
1140 (interactive)
1141 (if (ediff-one-filegroup-metajob)
1142 (error "This command is inapplicable in the present context"))
1143 (or (ediff-buffer-live-p ediff-dir-diffs-buffer)
1144 (ediff-draw-dir-diffs ediff-dir-difference-list))
1145 (let ((buf ediff-dir-diffs-buffer))
1146 (other-window 1)
1147 (set-window-buffer (selected-window) buf)
1148 (goto-char (point-min))))
1150 (defun ediff-up-meta-hierarchy ()
1151 "Go to the parent session group buffer."
1152 (interactive)
1153 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1154 (ediff-show-meta-buffer
1155 ediff-parent-meta-buffer ediff-meta-session-number)
1156 (error "This session group has no parent")))
1159 ;; argument is ignored
1160 (defun ediff-redraw-registry-buffer (&optional ignore)
1161 (ediff-with-current-buffer ediff-registry-buffer
1162 (let ((point (point))
1163 elt bufAname bufBname bufCname cur-diff total-diffs pt
1164 job-name meta-list registry-list buffer-read-only)
1165 (erase-buffer)
1166 ;; delete phony overlays that used to represent sessions before the buff
1167 ;; was redrawn
1168 (if ediff-emacs-p
1169 (mapcar 'delete-overlay (overlays-in 1 1))
1170 (map-extents 'delete-extent))
1172 (insert "This is a registry of all active Ediff sessions.
1174 Useful commands:
1175 button2, `v', RET over a session record: switch to that session
1176 M over a session record: display the associated session group
1177 R in any Ediff session: display session registry
1178 n,SPC: next session
1179 p,DEL: previous session
1180 E: browse Ediff on-line manual
1181 q: bury registry
1184 \t\tActive Ediff Sessions:
1185 \t\t----------------------
1188 ;; purge registry list from dead buffers
1189 (mapcar (lambda (elt)
1190 (if (not (ediff-buffer-live-p elt))
1191 (setq ediff-session-registry
1192 (delq elt ediff-session-registry))))
1193 ediff-session-registry)
1195 (if (null ediff-session-registry)
1196 (insert " ******* No active Ediff sessions *******\n"))
1198 (setq registry-list ediff-session-registry)
1199 (while registry-list
1200 (setq elt (car registry-list)
1201 registry-list (cdr registry-list))
1203 (if (ediff-buffer-live-p elt)
1204 (if (ediff-with-current-buffer elt
1205 (setq job-name ediff-metajob-name
1206 meta-list ediff-meta-list)
1207 (and ediff-metajob-name
1208 (not (eq ediff-metajob-name 'ediff-registry))))
1209 (progn
1210 (setq pt (point))
1211 (insert (format " *group*\t%s: %s\n"
1212 (buffer-name elt)
1213 (ediff-abbrev-jobname job-name)))
1214 (insert (format "\t\t %s %s %s\n"
1215 (ediff-abbreviate-file-name
1216 (ediff-get-group-objA meta-list))
1217 (ediff-abbreviate-file-name
1218 (if (stringp
1219 (ediff-get-group-objB meta-list))
1220 (ediff-get-group-objB meta-list)
1221 ""))
1222 (ediff-abbreviate-file-name
1223 (if (stringp
1224 (ediff-get-group-objC meta-list))
1225 (ediff-get-group-objC meta-list)
1226 ""))))
1227 (ediff-set-meta-overlay pt (point) elt))
1228 (progn
1229 (ediff-with-current-buffer elt
1230 (setq bufAname (if (ediff-buffer-live-p ediff-buffer-A)
1231 (buffer-name ediff-buffer-A)
1232 "!!!killed buffer!!!")
1233 bufBname (if (ediff-buffer-live-p ediff-buffer-B)
1234 (buffer-name ediff-buffer-B)
1235 "!!!killed buffer!!!")
1236 bufCname (cond ((not (ediff-3way-job))
1238 ((ediff-buffer-live-p ediff-buffer-C)
1239 (buffer-name ediff-buffer-C))
1240 (t "!!!killed buffer!!!")))
1241 (setq total-diffs (format "%-4d" ediff-number-of-differences)
1242 cur-diff
1243 (cond ((= ediff-current-difference -1) " _")
1244 ((= ediff-current-difference
1245 ediff-number-of-differences)
1246 " $")
1247 (t (format
1248 "%4d" (1+ ediff-current-difference))))
1249 job-name ediff-job-name))
1250 ;; back in the meta buf
1251 (setq pt (point))
1252 (insert cur-diff "/" total-diffs "\t"
1253 (buffer-name elt)
1254 (format ": %s" (ediff-abbrev-jobname job-name)))
1255 (insert
1256 "\n\t\t " bufAname " " bufBname " " bufCname "\n")
1257 (ediff-set-meta-overlay pt (point) elt))))
1258 ) ; while
1259 (set-buffer-modified-p nil)
1260 (goto-char point)
1263 ;; Sets overlay around a meta record with 'ediff-meta-info property PROP
1264 ;; If optional SESSION-NUMBER, make it a property of the overlay,
1265 ;; ediff-meta-session-number
1266 (defun ediff-set-meta-overlay (b e prop &optional session-number hidden)
1267 (let (overl)
1268 (setq overl (ediff-make-overlay b e))
1269 (if ediff-emacs-p
1270 (ediff-overlay-put overl 'mouse-face 'highlight)
1271 (ediff-overlay-put overl 'highlight t))
1272 (ediff-overlay-put overl 'ediff-meta-info prop)
1273 (ediff-overlay-put overl 'invisible hidden)
1274 (if (numberp session-number)
1275 (ediff-overlay-put overl 'ediff-meta-session-number session-number))))
1277 (defun ediff-mark-for-hiding-at-pos (unmark)
1278 "Mark session for hiding. With prefix arg, unmark."
1279 (interactive "P")
1280 (let* ((pos (ediff-event-point last-command-event))
1281 (meta-buf (ediff-event-buffer last-command-event))
1282 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1283 (info (ediff-get-meta-info meta-buf pos))
1284 (session-number (ediff-get-session-number-at-pos pos)))
1285 (ediff-mark-session-for-hiding info unmark)
1286 (ediff-next-meta-item 1)
1287 (save-excursion
1288 (ediff-update-meta-buffer meta-buf nil session-number))
1291 ;; Returns whether session was marked or unmarked
1292 (defun ediff-mark-session-for-hiding (info unmark)
1293 (let ((session-buf (ediff-get-session-buffer info))
1294 ignore)
1295 (cond ((eq unmark 'mark) (setq unmark nil))
1296 ((eq (ediff-get-session-status info) ?H) (setq unmark t))
1297 (unmark ; says unmark, but the marker is different from H
1298 (setq ignore t)))
1299 (cond (ignore)
1300 (unmark (ediff-set-session-status info nil))
1301 ;;; (if (ediff-buffer-live-p session-buf)
1302 ;;; (error "Can't hide active session, %s" (buffer-name session-buf)))
1303 (t (ediff-set-session-status info ?H))))
1304 unmark)
1307 (defun ediff-mark-for-operation-at-pos (unmark)
1308 "Mark session for a group operation. With prefix arg, unmark."
1309 (interactive "P")
1310 (let* ((pos (ediff-event-point last-command-event))
1311 (meta-buf (ediff-event-buffer last-command-event))
1312 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1313 (info (ediff-get-meta-info meta-buf pos))
1314 (session-number (ediff-get-session-number-at-pos pos)))
1315 (ediff-mark-session-for-operation info unmark)
1316 (ediff-next-meta-item 1)
1317 (save-excursion
1318 (ediff-update-meta-buffer meta-buf nil session-number))
1322 ;; returns whether session was unmarked.
1323 ;; remember: this is a toggle op
1324 (defun ediff-mark-session-for-operation (info unmark)
1325 (let (ignore)
1326 (cond ((eq unmark 'mark) (setq unmark nil))
1327 ((eq (ediff-get-session-status info) ?*) (setq unmark t))
1328 (unmark ; says unmark, but the marker is different from *
1329 (setq ignore t)))
1330 (cond (ignore)
1331 (unmark (ediff-set-session-status info nil))
1332 (t (ediff-set-session-status info ?*))))
1333 unmark)
1336 (defun ediff-hide-marked-sessions (unhide)
1337 "Hide marked sessions. With prefix arg, unhide."
1338 (interactive "P")
1339 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1340 (meta-list (cdr ediff-meta-list))
1341 (from (if unhide ?I ?H))
1342 (to (if unhide ?H ?I))
1343 (numMarked 0)
1344 active-sessions-exist session-buf elt)
1345 (while meta-list
1346 (setq elt (car meta-list)
1347 meta-list (cdr meta-list)
1348 session-buf (ediff-get-session-buffer elt))
1350 (if (eq (ediff-get-session-status elt) from)
1351 (progn
1352 (setq numMarked (1+ numMarked))
1353 (if (and (eq to ?I) (buffer-live-p session-buf))
1354 ;; shouldn't hide active sessions
1355 (setq active-sessions-exist t)
1356 (ediff-set-session-status elt to)))))
1357 (if (> numMarked 0)
1358 (ediff-update-meta-buffer grp-buf 'must-redraw)
1359 (beep)
1360 (if unhide
1361 (message "Nothing to reveal...")
1362 (message "Nothing to hide...")))
1363 (if active-sessions-exist
1364 (message "Note: Ediff didn't hide active sessions!"))
1367 ;; Apply OPERATION to marked sessions. Operation expects one argument of type
1368 ;; meta-list member (not the first one), i.e., a regular session description.
1369 ;; Returns number of marked sessions on which operation was performed
1370 (defun ediff-operate-on-marked-sessions (operation)
1371 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1372 (meta-list (cdr ediff-meta-list))
1373 (marksym ?*)
1374 (numMarked 0)
1375 (sessionNum 0)
1376 (diff-buffer ediff-meta-diff-buffer)
1377 session-buf elt)
1378 (while meta-list
1379 (setq elt (car meta-list)
1380 meta-list (cdr meta-list)
1381 sessionNum (1+ sessionNum))
1382 (cond ((eq (ediff-get-session-status elt) marksym)
1383 (save-excursion
1384 (setq numMarked (1+ numMarked))
1385 (funcall operation elt sessionNum)))
1386 ((and (ediff-meta-session-p elt)
1387 (ediff-buffer-live-p
1388 (setq session-buf (ediff-get-session-buffer elt))))
1389 (setq numMarked
1390 (+ numMarked
1391 (ediff-with-current-buffer session-buf
1392 ;; pass meta-diff along
1393 (setq ediff-meta-diff-buffer diff-buffer)
1394 ;; collect diffs in child group
1395 (ediff-operate-on-marked-sessions operation)))))))
1396 (ediff-update-meta-buffer grp-buf 'must-redraw) ; just in case
1397 numMarked
1400 (defun ediff-append-custom-diff (session sessionNum)
1401 (or (ediff-collect-diffs-metajob)
1402 (error "Hmm, I'd hate to do it to you ..."))
1403 (let ((session-buf (ediff-get-session-buffer session))
1404 (meta-diff-buff ediff-meta-diff-buffer)
1405 (metajob ediff-metajob-name)
1406 tmp-buf custom-diff-buf)
1407 (if (ediff-buffer-live-p session-buf)
1408 (ediff-with-current-buffer session-buf
1409 (if (eq ediff-control-buffer session-buf) ; individual session
1410 (progn
1411 (ediff-compute-custom-diffs-maybe)
1412 (setq custom-diff-buf ediff-custom-diff-buffer)))))
1414 (or (ediff-buffer-live-p meta-diff-buff)
1415 (error "Ediff: something wrong--no multiple diffs buffer"))
1417 (cond ((ediff-buffer-live-p custom-diff-buf)
1418 (save-excursion
1419 (set-buffer meta-diff-buff)
1420 (goto-char (point-max))
1421 (insert-buffer custom-diff-buf)
1422 (insert "\n")))
1423 ((memq metajob '(ediff-directories
1424 ediff-merge-directories
1425 ediff-merge-directories-with-ancestor))
1426 ;; get diffs by calling shell command on ediff-custom-diff-program
1427 (save-excursion
1428 (set-buffer (setq tmp-buf (get-buffer-create ediff-tmp-buffer)))
1429 (erase-buffer)
1430 (shell-command
1431 (format "%s %s %s %s"
1432 ediff-custom-diff-program ediff-custom-diff-options
1433 (ediff-get-session-objA-name session)
1434 (ediff-get-session-objB-name session))
1436 (save-excursion
1437 (set-buffer meta-diff-buff)
1438 (goto-char (point-max))
1439 (insert-buffer tmp-buf)
1440 (insert "\n")))
1442 (error "Can't make context diff for Session %d" sessionNum )))
1445 (defun ediff-collect-custom-diffs ()
1446 "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'.
1447 This operation is defined only for `ediff-directories' and
1448 `ediff-directory-revisions', since its intent is to produce
1449 multifile patches. For `ediff-directory-revisions', we insist that
1450 all marked sessions must be active."
1451 (interactive)
1452 (or (ediff-buffer-live-p ediff-meta-diff-buffer)
1453 (setq ediff-meta-diff-buffer
1454 (get-buffer-create
1455 (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
1456 (ediff-with-current-buffer ediff-meta-diff-buffer
1457 (erase-buffer))
1458 (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
1459 ;; did something
1460 (progn
1461 (display-buffer ediff-meta-diff-buffer 'not-this-window)
1462 (ediff-with-current-buffer ediff-meta-diff-buffer
1463 (set-buffer-modified-p nil)
1464 (setq buffer-read-only t)))
1465 (beep)
1466 (message "No marked sessions found")))
1468 (defun ediff-meta-show-patch ()
1469 "Show the multi-file patch associated with this group session."
1470 (interactive)
1471 (let* ((pos (ediff-event-point last-command-event))
1472 (meta-buf (ediff-event-buffer last-command-event))
1473 (info (ediff-get-meta-info meta-buf pos 'noerror))
1474 (patchbuffer ediff-meta-patchbufer))
1475 (if (ediff-buffer-live-p patchbuffer)
1476 (ediff-with-current-buffer patchbuffer
1477 (save-restriction
1478 (if (not info)
1479 (widen)
1480 (narrow-to-region
1481 (ediff-get-session-objB-name info)
1482 (ediff-get-session-objC-name info)))
1483 (set-buffer (get-buffer-create ediff-tmp-buffer))
1484 (erase-buffer)
1485 (insert-buffer patchbuffer)
1486 (display-buffer ediff-tmp-buffer 'not-this-window)
1488 (error "The patch buffer wasn't found"))))
1491 ;; This function executes in meta buffer. It knows where event happened.
1492 (defun ediff-filegroup-action ()
1493 "Execute appropriate action for the selected session."
1494 (interactive)
1495 (let* ((pos (ediff-event-point last-command-event))
1496 (meta-buf (ediff-event-buffer last-command-event))
1497 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1498 (info (ediff-get-meta-info meta-buf pos))
1499 (session-buf (ediff-get-session-buffer info))
1500 (session-number (ediff-get-session-number-at-pos pos meta-buf))
1501 merge-autostore-dir file1 file2 file3 regexp)
1503 (setq file1 (ediff-get-session-objA-name info)
1504 file2 (ediff-get-session-objB-name info)
1505 file3 (ediff-get-session-objC-name info))
1507 ;; make sure we don't start on hidden sessions
1508 ;; ?H means marked for hiding. ?I means invalid (hidden).
1509 (if (memq (ediff-get-session-status info) '(?I))
1510 (progn
1511 (beep)
1512 (if (y-or-n-p "This session is marked as hidden, unmark? ")
1513 (progn
1514 (ediff-set-session-status info nil)
1515 (ediff-update-meta-buffer meta-buf nil session-number))
1516 (error "Aborted"))))
1518 (ediff-with-current-buffer meta-buf
1519 (setq merge-autostore-dir
1520 (ediff-get-group-merge-autostore-dir ediff-meta-list))
1521 (goto-char pos) ; if the user clicked on session--move point there
1522 ;; First handle sessions involving directories (which are themselves
1523 ;; session groups)
1524 ;; After that handle individual sessions
1525 (cond ((ediff-meta-session-p info)
1526 ;; do ediff/ediff-merge on subdirectories
1527 (if (ediff-buffer-live-p session-buf)
1528 (ediff-show-meta-buffer session-buf)
1529 (setq regexp (read-string "Filter through regular expression: "
1530 nil 'ediff-filtering-regexp-history))
1531 (ediff-directories-internal
1532 file1 file2 file3 regexp
1533 ediff-session-action-function
1534 ediff-metajob-name
1535 ;; make it update (car info) after startup
1536 `(list (lambda ()
1537 ;; child session group should know its parent
1538 (setq ediff-parent-meta-buffer
1539 (quote ,ediff-meta-buffer)
1540 ediff-meta-session-number
1541 ,session-number)
1542 ;; and parent will know its child
1543 (setcar (quote ,info) ediff-meta-buffer))))))
1545 ;; Do ediff-revision on a subdirectory
1546 ((and (ediff-one-filegroup-metajob)
1547 (ediff-revision-metajob)
1548 (file-directory-p file1))
1549 (if (ediff-buffer-live-p session-buf)
1550 (ediff-show-meta-buffer session-buf)
1551 (setq regexp (read-string "Filter through regular expression: "
1552 nil 'ediff-filtering-regexp-history))
1553 (ediff-directory-revisions-internal
1554 file1 regexp
1555 ediff-session-action-function ediff-metajob-name
1556 ;; make it update (car info) after startup
1557 `(list (lambda ()
1558 ;; child session group should know its parent and
1559 ;; its number
1560 (setq ediff-parent-meta-buffer
1561 (quote ,ediff-meta-buffer)
1562 ediff-meta-session-number
1563 ,session-number)
1564 ;; and parent will know its child
1565 (setcar (quote ,info) ediff-meta-buffer))))))
1567 ;; From here on---only individual session handlers
1569 ;; handle an individual session with a live control buffer
1570 ((ediff-buffer-live-p session-buf)
1571 (ediff-with-current-buffer session-buf
1572 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1573 (ediff-recenter 'no-rehighlight)))
1575 ((ediff-problematic-session-p info)
1576 (beep)
1577 (if (y-or-n-p
1578 "This session has no ancestor. Merge without the ancestor? ")
1579 (ediff-merge-files
1580 file1 file2
1581 ;; provide startup hooks
1582 `(list (lambda ()
1583 (add-hook
1584 'ediff-after-quit-hook-internal
1585 (lambda ()
1586 (if (ediff-buffer-live-p ,(current-buffer))
1587 (ediff-show-meta-buffer
1588 ,(current-buffer) ,session-number)))
1589 nil 'local)
1590 (setq ediff-meta-buffer ,(current-buffer)
1591 ediff-meta-session-number
1592 ,session-number)
1593 (setq ediff-merge-store-file
1594 ,(if (ediff-nonempty-string-p
1595 merge-autostore-dir)
1596 (concat
1597 merge-autostore-dir
1598 ediff-merge-filename-prefix
1599 (file-name-nondirectory file1))
1601 ;; make ediff-startup pass
1602 ;; ediff-control-buffer back to the meta
1603 ;; level; see below
1604 (setcar
1605 (quote ,info) ediff-control-buffer))))
1606 (error "Aborted")))
1607 ((ediff-one-filegroup-metajob) ; needs 1 file arg
1608 (funcall ediff-session-action-function
1609 file1
1610 ;; provide startup hooks
1611 `(list (lambda ()
1612 (add-hook
1613 'ediff-after-quit-hook-internal
1614 (lambda ()
1615 (if (ediff-buffer-live-p
1616 ,(current-buffer))
1617 (ediff-show-meta-buffer
1618 ,(current-buffer)
1619 ,session-number)))
1620 nil 'local)
1621 (setq ediff-meta-buffer ,(current-buffer)
1622 ediff-meta-session-number
1623 ,session-number)
1624 (setq ediff-merge-store-file
1625 ,(if (ediff-nonempty-string-p
1626 merge-autostore-dir)
1627 (concat
1628 merge-autostore-dir
1629 ediff-merge-filename-prefix
1630 (file-name-nondirectory file1))) )
1631 ;; make ediff-startup pass
1632 ;; ediff-control-buffer back to the meta
1633 ;; level; see below
1634 (setcar
1635 (quote ,info) ediff-control-buffer)))))
1636 ((not (ediff-metajob3)) ; need 2 file args
1637 (funcall ediff-session-action-function
1638 file1 file2
1639 ;; provide startup hooks
1640 `(list (lambda ()
1641 (add-hook
1642 'ediff-after-quit-hook-internal
1643 (lambda ()
1644 (if (ediff-buffer-live-p
1645 ,(current-buffer))
1646 (ediff-show-meta-buffer
1647 ,(current-buffer)
1648 ,session-number)))
1649 nil 'local)
1650 (setq ediff-meta-buffer ,(current-buffer)
1651 ediff-meta-session-number
1652 ,session-number)
1653 (setq ediff-merge-store-file
1654 ,(if (ediff-nonempty-string-p
1655 merge-autostore-dir)
1656 (concat
1657 merge-autostore-dir
1658 ediff-merge-filename-prefix
1659 (file-name-nondirectory file1))) )
1660 ;; make ediff-startup pass
1661 ;; ediff-control-buffer back to the meta
1662 ;; level; see below
1663 (setcar
1664 (quote ,info) ediff-control-buffer)))))
1665 ((ediff-metajob3) ; need 3 file args
1666 (funcall ediff-session-action-function
1667 file1 file2 file3
1668 ;; arrange startup hooks
1669 `(list (lambda ()
1670 (add-hook
1671 'ediff-after-quit-hook-internal
1672 (lambda ()
1673 (if (ediff-buffer-live-p
1674 ,(current-buffer))
1675 (ediff-show-meta-buffer
1676 ,(current-buffer)
1677 ,session-number)))
1678 nil 'local)
1679 (setq ediff-merge-store-file
1680 ,(if (ediff-nonempty-string-p
1681 merge-autostore-dir)
1682 (concat
1683 merge-autostore-dir
1684 ediff-merge-filename-prefix
1685 (file-name-nondirectory file1))) )
1686 (setq ediff-meta-buffer , (current-buffer)
1687 ediff-meta-session-number
1688 ,session-number)
1689 ;; this arranges that ediff-startup will pass
1690 ;; the value of ediff-control-buffer back to
1691 ;; the meta level, to the record in the meta
1692 ;; list containing the information about the
1693 ;; session associated with that
1694 ;; ediff-control-buffer
1695 (setcar
1696 (quote ,info) ediff-control-buffer)))))
1697 ) ; cond
1698 ) ; eval in meta-buf
1701 (defun ediff-registry-action ()
1702 "Switch to a selected session."
1703 (interactive)
1704 (let* ((pos (ediff-event-point last-command-event))
1705 (buf (ediff-event-buffer last-command-event))
1706 (ctl-buf (ediff-get-meta-info buf pos)))
1708 (if (ediff-buffer-live-p ctl-buf)
1709 ;; check if this is ediff-control-buffer or ediff-meta-buffer
1710 (if (ediff-with-current-buffer ctl-buf
1711 (eq (key-binding "q") 'ediff-quit-meta-buffer))
1712 ;; it's a meta-buffer -- last action should just display it
1713 (ediff-show-meta-buffer ctl-buf t)
1714 ;; it's a session buffer -- invoke go back to session
1715 (ediff-with-current-buffer ctl-buf
1716 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1717 (ediff-recenter 'no-rehighlight)))
1718 (beep)
1719 (message "You've selected a stale session --- try again")
1720 (ediff-update-registry))
1721 (ediff-with-current-buffer buf
1722 (goto-char pos))
1726 ;; If session number is t, means don't update meta buffer
1727 (defun ediff-show-meta-buffer (&optional meta-buf session-number)
1728 "Show the session group buffer."
1729 (interactive)
1730 (run-hooks 'ediff-before-directory-setup-hooks)
1731 (let (wind frame silent)
1732 (if meta-buf (setq silent t))
1734 (setq meta-buf (or meta-buf ediff-meta-buffer))
1735 (cond ((not (bufferp meta-buf))
1736 (error "This Ediff session is not part of a session group"))
1737 ((not (ediff-buffer-live-p meta-buf))
1738 (error
1739 "Can't find this session's group panel -- session itself is ok")))
1741 (cond ((numberp session-number)
1742 (ediff-update-meta-buffer meta-buf nil session-number))
1743 ;; if session-number is t, don't update
1744 (session-number)
1745 (t (ediff-cleanup-meta-buffer meta-buf)))
1747 (ediff-with-current-buffer meta-buf
1748 (save-excursion
1749 (cond ((setq wind (ediff-get-visible-buffer-window meta-buf))
1750 (or silent
1751 (message
1752 "Already showing the group panel for this session"))
1753 (set-window-buffer wind meta-buf)
1754 (select-window wind))
1755 ((window-live-p (setq wind ediff-window-C)) ;in merge--merge buf
1756 (set-window-buffer ediff-window-C meta-buf)
1757 (select-window wind))
1758 ((window-live-p (setq wind ediff-window-A))
1759 (set-window-buffer ediff-window-A meta-buf)
1760 (select-window wind))
1761 ((window-live-p (setq wind ediff-window-B))
1762 (set-window-buffer ediff-window-B meta-buf)
1763 (select-window wind))
1764 ((and
1765 (setq wind
1766 (ediff-get-visible-buffer-window ediff-registry-buffer))
1767 (ediff-window-display-p))
1768 (select-window wind)
1769 (other-window 1)
1770 (set-window-buffer (selected-window) meta-buf))
1771 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1772 (set-window-buffer (selected-window) meta-buf)))
1774 (if (and (ediff-window-display-p)
1775 (window-live-p
1776 (setq wind (ediff-get-visible-buffer-window meta-buf))))
1777 (progn
1778 (setq frame (window-frame wind))
1779 (raise-frame frame)
1780 (ediff-reset-mouse frame)))
1781 (run-hooks 'ediff-show-session-group-hook)
1784 (defun ediff-show-current-session-meta-buffer ()
1785 (interactive)
1786 (ediff-show-meta-buffer nil ediff-meta-session-number))
1788 (defun ediff-show-meta-buff-from-registry ()
1789 "Display the session group buffer for a selected session group."
1790 (interactive)
1791 (let* ((pos (ediff-event-point last-command-event))
1792 (meta-buf (ediff-event-buffer last-command-event))
1793 (info (ediff-get-meta-info meta-buf pos))
1794 (meta-or-session-buf info))
1795 (ediff-with-current-buffer meta-or-session-buf
1796 (ediff-show-meta-buffer nil t))))
1798 ;;;###autoload
1799 (defun ediff-show-registry ()
1800 "Display Ediff's registry."
1801 (interactive)
1802 (ediff-update-registry)
1803 (if (not (ediff-buffer-live-p ediff-registry-buffer))
1804 (error "No active Ediff sessions or corrupted session registry"))
1805 (let (wind frame)
1806 ;; for some reason, point moves in ediff-registry-buffer, so we preserve it
1807 ;; explicitly
1808 (ediff-with-current-buffer ediff-registry-buffer
1809 (save-excursion
1810 (cond ((setq wind
1811 (ediff-get-visible-buffer-window ediff-registry-buffer))
1812 (message "Already showing the registry")
1813 (set-window-buffer wind ediff-registry-buffer)
1814 (select-window wind))
1815 ((window-live-p ediff-window-C)
1816 (set-window-buffer ediff-window-C ediff-registry-buffer)
1817 (select-window ediff-window-C))
1818 ((window-live-p ediff-window-A)
1819 (set-window-buffer ediff-window-A ediff-registry-buffer)
1820 (select-window ediff-window-A))
1821 ((window-live-p ediff-window-B)
1822 (set-window-buffer ediff-window-B ediff-registry-buffer)
1823 (select-window ediff-window-B))
1824 ((and (setq wind
1825 (ediff-get-visible-buffer-window ediff-meta-buffer))
1826 (ediff-window-display-p))
1827 (select-window wind)
1828 (other-window 1)
1829 (set-window-buffer (selected-window) ediff-registry-buffer))
1830 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1831 (set-window-buffer (selected-window) ediff-registry-buffer)))
1833 (if (ediff-window-display-p)
1834 (progn
1835 (setq frame
1836 (window-frame
1837 (ediff-get-visible-buffer-window ediff-registry-buffer)))
1838 (raise-frame frame)
1839 (ediff-reset-mouse frame)))
1840 (run-hooks 'ediff-show-registry-hook)
1843 ;;;###autoload
1844 (defalias 'eregistry 'ediff-show-registry)
1846 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a
1847 ;; parent meta-buf
1848 ;; Check if META-BUF exists before calling this function
1849 ;; Optional MUST-REDRAW, if non-nil, would force redrawal of the whole meta
1850 ;; buffer. Otherwise, it will just go over the buffer and update activity marks
1851 ;; and session status.
1852 ;; SESSION-NUMBER, if specified, says which session caused the update.
1853 (defun ediff-update-meta-buffer (meta-buf &optional must-redraw session-number)
1854 (if (ediff-buffer-live-p meta-buf)
1855 (ediff-with-current-buffer meta-buf
1856 (let (overl)
1857 (cond (must-redraw ; completely redraw the meta buffer
1858 (funcall ediff-meta-redraw-function ediff-meta-list))
1859 ((numberp session-number) ; redraw only for the given session
1860 (ediff-update-session-marker-in-dir-meta-buffer
1861 session-number))
1862 (t ; update what changed only, but scan the entire meta buffer
1863 (ediff-update-markers-in-dir-meta-buffer ediff-meta-list)))
1864 (setq overl (ediff-get-meta-overlay-at-pos (point)))
1865 ;; skip the invisible sessions
1866 (while (and overl (ediff-overlay-get overl 'invisible))
1867 (ediff-next-meta-item1)
1868 (setq overl (ediff-get-meta-overlay-at-pos (point))))
1869 ))))
1871 (defun ediff-update-registry ()
1872 (ediff-with-current-buffer (current-buffer)
1873 (if (ediff-buffer-live-p ediff-registry-buffer)
1874 (ediff-redraw-registry-buffer)
1875 (ediff-prepare-meta-buffer
1876 'ediff-registry-action
1877 ediff-session-registry
1878 "*Ediff Registry"
1879 'ediff-redraw-registry-buffer
1880 'ediff-registry))
1883 ;; If meta-buf exists, it is redrawn along with parent.
1884 ;; Otherwise, nothing happens.
1885 (defun ediff-cleanup-meta-buffer (meta-buffer)
1886 (if (ediff-buffer-live-p meta-buffer)
1887 (ediff-with-current-buffer meta-buffer
1888 (ediff-update-meta-buffer meta-buffer)
1889 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1890 (ediff-update-meta-buffer
1891 ediff-parent-meta-buffer nil ediff-meta-session-number)))))
1893 ;; t if no session is in progress
1894 (defun ediff-safe-to-quit (meta-buffer)
1895 (if (ediff-buffer-live-p meta-buffer)
1896 (let ((lis ediff-meta-list)
1897 (cont t)
1898 buffer-read-only)
1899 ;;(ediff-update-meta-buffer meta-buffer)
1900 (ediff-with-current-buffer meta-buffer
1901 (setq lis (cdr lis)) ; discard the description part of meta-list
1902 (while (and cont lis)
1903 (if (ediff-buffer-live-p
1904 (ediff-get-group-buffer lis)) ; in progress
1905 (setq cont nil))
1906 (setq lis (cdr lis)))
1907 cont))))
1909 (defun ediff-quit-meta-buffer ()
1910 "If the group has no active session, delete the meta buffer.
1911 If no session is in progress, ask to confirm before deleting meta buffer.
1912 Otherwise, bury the meta buffer.
1913 If this is a session registry buffer then just bury it."
1914 (interactive)
1915 (let* ((buf (current-buffer))
1916 (dir-diffs-buffer ediff-dir-diffs-buffer)
1917 (meta-diff-buffer ediff-meta-diff-buffer)
1918 (session-number ediff-meta-session-number)
1919 (parent-buf ediff-parent-meta-buffer)
1920 (dont-show-registry (eq buf ediff-registry-buffer)))
1921 (if dont-show-registry
1922 (bury-buffer)
1923 ;;(ediff-cleanup-meta-buffer buf)
1924 (cond ((and (ediff-safe-to-quit buf)
1925 (y-or-n-p "Quit this session group? "))
1926 (run-hooks 'ediff-quit-session-group-hook)
1927 (message "")
1928 (ediff-dispose-of-meta-buffer buf))
1929 ((ediff-safe-to-quit buf)
1930 (bury-buffer))
1932 (error
1933 "This session group has active sessions---cannot exit")))
1934 (ediff-update-meta-buffer parent-buf nil session-number)
1935 (ediff-kill-buffer-carefully dir-diffs-buffer)
1936 (ediff-kill-buffer-carefully meta-diff-buffer)
1937 (if (ediff-buffer-live-p parent-buf)
1938 (progn
1939 (setq dont-show-registry t)
1940 (ediff-show-meta-buffer parent-buf session-number)))
1942 (or dont-show-registry
1943 (ediff-show-registry))))
1945 (defun ediff-dispose-of-meta-buffer (buf)
1946 (setq ediff-session-registry (delq buf ediff-session-registry))
1947 (ediff-with-current-buffer buf
1948 (if (ediff-buffer-live-p ediff-dir-diffs-buffer)
1949 (kill-buffer ediff-dir-diffs-buffer)))
1950 (kill-buffer buf))
1953 ;; Obtain information on a meta record where the user clicked or typed
1954 ;; BUF is the buffer where this happened and POINT is the position
1955 ;; If optional NOERROR arg is given, don't report error and return nil if no
1956 ;; meta info is found on line.
1957 (defun ediff-get-meta-info (buf point &optional noerror)
1958 (let (result olist tmp)
1959 (if (and point (ediff-buffer-live-p buf))
1960 (ediff-with-current-buffer buf
1961 (if ediff-xemacs-p
1962 (setq result
1963 (if (setq tmp (extent-at point buf 'ediff-meta-info))
1964 (ediff-overlay-get tmp 'ediff-meta-info)))
1965 (setq olist (overlays-at point))
1966 (setq olist
1967 (mapcar (lambda (elt) (overlay-get elt 'ediff-meta-info))
1968 olist))
1969 (while (and olist (null (car olist))
1970 (overlay-get (car olist) 'invisible))
1971 (setq olist (cdr olist)))
1972 (setq result (car olist)))))
1973 (if result
1974 result
1975 (if noerror
1977 (ediff-update-registry)
1978 (error "No session info in this line")))))
1981 (defun ediff-get-meta-overlay-at-pos (point)
1982 (if ediff-xemacs-p
1983 (extent-at point (current-buffer) 'ediff-meta-info)
1984 (let* ((overl-list (overlays-at point))
1985 (overl (car overl-list)))
1986 (while (and overl (null (overlay-get overl 'ediff-meta-info)))
1987 (setq overl-list (cdr overl-list)
1988 overl (car overl-list)))
1989 overl)))
1991 (defsubst ediff-get-session-number-at-pos (point &optional meta-buffer)
1992 (setq meta-buffer (if (ediff-buffer-live-p meta-buffer)
1993 meta-buffer
1994 (current-buffer)))
1995 (ediff-with-current-buffer meta-buffer
1996 (ediff-overlay-get
1997 (ediff-get-meta-overlay-at-pos point) 'ediff-meta-session-number)))
2000 ;; Return location of the next meta overlay after point
2001 (defun ediff-next-meta-overlay-start (point)
2002 (if (eobp)
2003 (goto-char (point-min))
2004 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2005 (if ediff-xemacs-p
2006 (progn
2007 (if overl
2008 (setq overl (next-extent overl))
2009 (setq overl (next-extent (current-buffer))))
2010 (if overl
2011 (extent-start-position overl)
2012 (point-max)))
2013 (if overl
2014 ;; note: end of current overlay is the beginning of the next one
2015 (overlay-end overl)
2016 (next-overlay-change point))))
2020 (defun ediff-previous-meta-overlay-start (point)
2021 (if (bobp)
2022 (goto-char (point-max))
2023 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2024 (if ediff-xemacs-p
2025 (progn
2026 (if overl
2027 (setq overl (previous-extent overl))
2028 (setq overl (previous-extent (current-buffer))))
2029 (if overl
2030 (extent-start-position overl)
2031 (point-min)))
2032 (if overl (setq point (overlay-start overl)))
2033 ;; to get to the beginning of prev overlay
2034 (if (not (bobp))
2035 ;; trick to overcome an emacs bug--doesn't always find previous
2036 ;; overlay change correctly
2037 (setq point (1- point)))
2038 (setq point (previous-overlay-change point))
2039 ;; If we are not over an overlay after subtracting 1, it means we are
2040 ;; in the description area preceding session records. In this case,
2041 ;; goto the top of the registry buffer.
2042 (or (car (overlays-at point))
2043 (setq point (point-min)))
2044 point))))
2046 ;; this is the action invoked when the user selects a patch from the meta
2047 ;; buffer.
2048 (defun ediff-patch-file-form-meta (file &optional startup-hooks)
2049 (let* ((pos (ediff-event-point last-command-event))
2050 (meta-buf (ediff-event-buffer last-command-event))
2051 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
2052 (info (ediff-get-meta-info meta-buf pos))
2053 (meta-patchbuf ediff-meta-patchbufer)
2054 session-buf beg-marker end-marker)
2056 (if (or (file-directory-p file) (string-match "/dev/null" file))
2057 (error "`%s' is not an ordinary file" (file-name-as-directory file)))
2058 (setq session-buf (ediff-get-session-buffer info)
2059 beg-marker (ediff-get-session-objB-name info)
2060 end-marker (ediff-get-session-objC-name info))
2062 (or (ediff-buffer-live-p session-buf) ; either an active patch session
2063 (null session-buf) ; or it is a virgin session
2064 (error
2065 "Patch has been already applied to this file--cannot be repeated!"))
2067 (ediff-with-current-buffer meta-patchbuf
2068 (save-restriction
2069 (widen)
2070 (narrow-to-region beg-marker end-marker)
2071 (ediff-patch-file-internal meta-patchbuf file startup-hooks)))))
2074 (defun ediff-unmark-all-for-operation ()
2075 "Unmark all sessions marked for operation."
2076 (interactive)
2077 (let ((list (cdr ediff-meta-list))
2078 elt)
2079 (while (setq elt (car list))
2080 (ediff-mark-session-for-operation elt 'unmark)
2081 (setq list (cdr list))))
2082 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2084 (defun ediff-unmark-all-for-hiding ()
2085 "Unmark all sessions marked for hiding."
2086 (interactive)
2087 (let ((list (cdr ediff-meta-list))
2088 elt)
2089 (while (setq elt (car list))
2090 (ediff-mark-session-for-hiding elt 'unmark)
2091 (setq list (cdr list))))
2092 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2095 (defun ediff-meta-mark-equal-files ()
2096 "Run though the session list and mark identical files.
2097 This is used only for sessions that involve 2 or 3 files at the same time."
2098 (interactive)
2099 (let ((list (cdr ediff-meta-list))
2100 marked1 marked2 marked3
2101 fileinfo1 fileinfo2 fileinfo3 elt)
2102 (message "Comparing files ...")
2103 (while (setq elt (car list))
2104 (setq fileinfo1 (ediff-get-session-objA elt)
2105 fileinfo2 (ediff-get-session-objB elt)
2106 fileinfo3 (ediff-get-session-objC elt))
2107 (ediff-set-file-eqstatus fileinfo1 nil)
2108 (ediff-set-file-eqstatus fileinfo2 nil)
2109 (ediff-set-file-eqstatus fileinfo3 nil)
2111 (setq marked1 t
2112 marked2 t
2113 marked3 t)
2114 (or (ediff-mark-if-equal fileinfo1 fileinfo2)
2115 (setq marked1 nil))
2116 (if (ediff-metajob3)
2117 (progn
2118 (or (ediff-mark-if-equal fileinfo1 fileinfo3)
2119 (setq marked2 nil))
2120 (or (ediff-mark-if-equal fileinfo2 fileinfo3)
2121 (setq marked3 nil))))
2122 (if (and marked1 marked2 marked3)
2123 (cond ((eq last-command-char ?h)
2124 (ediff-mark-session-for-hiding elt 'mark))
2125 ((eq last-command-char ?m)
2126 (ediff-mark-session-for-operation elt 'mark))
2128 (setq list (cdr list)))
2129 (message "Comparing files ... Done"))
2130 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2132 ;; mark files 1 and 2 as equal, if they are.
2133 ;; returns t, if something was marked
2134 (defun ediff-mark-if-equal (fileinfo1 fileinfo2)
2135 (let ((f1 (car fileinfo1))
2136 (f2 (car fileinfo2)))
2137 (cond ((file-directory-p f1) nil)
2138 ((file-directory-p f2) nil)
2139 ((ediff-same-file-contents f1 f2)
2140 (ediff-set-file-eqstatus fileinfo1 t)
2141 (ediff-set-file-eqstatus fileinfo2 t)
2147 ;;; Local Variables:
2148 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
2149 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
2150 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
2151 ;;; End:
2153 ;;; ediff-mult.el ends here