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)
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.
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
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.
95 (defgroup ediff-mult nil
96 "Multi-file and multi-buffer processing in Ediff"
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
))
111 (require 'ediff-init
)
112 (require 'ediff-util
)
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
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
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
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
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'."
186 (defcustom ediff-registry-setup-hook nil
187 "*Hooks run just after the registry control panel is set up."
190 (defcustom ediff-session-group-setup-hook nil
191 "*Hooks run just after a meta-buffer controlling a session group, such as
192 ediff-directories, is run."
195 (defcustom ediff-quit-session-group-hook nil
196 "*Hooks run just before exiting a session group."
199 (defcustom ediff-show-registry-hook nil
200 "*Hooks run just after the registry buffer is shown."
203 (defcustom ediff-show-session-group-hook
'(delete-other-windows)
204 "*Hooks run just after a session group buffer is shown."
207 (defcustom ediff-meta-buffer-keymap-setup-hook nil
208 "*Hooks run just after setting up the ediff-meta-buffer-map.
209 This keymap controls key bindings in the meta buffer and is a local variable.
210 This means that you can set different bindings for different kinds of meta
215 ;; Buffer holding the multi-file patch. Local to the meta buffer
216 (ediff-defvar-local ediff-meta-patchbufer nil
"")
218 ;;; API for ediff-meta-list
220 ;; group buffer/regexp
221 (defsubst ediff-get-group-buffer
(meta-list)
222 (nth 0 (car meta-list
)))
224 (defsubst ediff-get-group-regexp
(meta-list)
225 (nth 1 (car meta-list
)))
227 (defsubst ediff-get-group-objA
(meta-list)
228 (nth 2 (car meta-list
)))
229 (defsubst ediff-get-group-objB
(meta-list)
230 (nth 3 (car meta-list
)))
231 (defsubst ediff-get-group-objC
(meta-list)
232 (nth 4 (car meta-list
)))
233 (defsubst ediff-get-group-merge-autostore-dir
(meta-list)
234 (nth 5 (car meta-list
)))
237 (defsubst ediff-get-session-buffer
(elt)
239 (defsubst ediff-get-session-status
(elt)
241 (defsubst ediff-set-session-status
(session-info new-status
)
242 (setcar (cdr session-info
) new-status
))
244 (defsubst ediff-get-session-objA
(elt)
246 (defsubst ediff-get-session-objB
(elt)
248 (defsubst ediff-get-session-objC
(elt)
250 (defsubst ediff-get-session-objA-name
(elt)
252 (defsubst ediff-get-session-objB-name
(elt)
254 (defsubst ediff-get-session-objC-name
(elt)
256 ;; equality indicators
257 (defsubst ediff-get-file-eqstatus
(elt)
259 (defsubst ediff-set-file-eqstatus
(elt value
)
260 (setcar (cdr elt
) value
))
262 ;; The activity marker is either or + (active session, i.e., ediff is currently
263 ;; run in it), or - (finished session, i.e., we've ran ediff in it and then
264 ;; exited). Return nil, if session is neither active nor finished
265 (defun ediff-get-session-activity-marker (session)
266 (let ((session-buf (ediff-get-session-buffer session
)))
267 (cond ((null session-buf
) nil
) ; virgin session
268 ((ediff-buffer-live-p session-buf
) ?
+) ;active session
271 ;; checks if the session is a meta session
272 (defun ediff-meta-session-p (session-info)
273 (and (stringp (ediff-get-session-objA-name session-info
))
274 (file-directory-p (ediff-get-session-objA-name session-info
))
275 (stringp (ediff-get-session-objB-name session-info
))
276 (file-directory-p (ediff-get-session-objB-name session-info
))
277 (if (stringp (ediff-get-session-objC-name session-info
))
278 (file-directory-p (ediff-get-session-objC-name session-info
)) t
)))
280 ;; set up the keymap in the meta buffer
281 (defun ediff-setup-meta-map()
282 (setq ediff-meta-buffer-map
(make-sparse-keymap))
283 (suppress-keymap ediff-meta-buffer-map
)
284 (define-key ediff-meta-buffer-map
"q" 'ediff-quit-meta-buffer
)
285 (define-key ediff-meta-buffer-map
"T" 'ediff-toggle-filename-truncation
)
286 (define-key ediff-meta-buffer-map
"R" 'ediff-show-registry
)
287 (define-key ediff-meta-buffer-map
"E" 'ediff-documentation
)
288 (define-key ediff-meta-buffer-map
"v" ediff-meta-action-function
)
289 (define-key ediff-meta-buffer-map
"\C-m" ediff-meta-action-function
)
290 (define-key ediff-meta-buffer-map
" " 'ediff-next-meta-item
)
291 (define-key ediff-meta-buffer-map
"n" 'ediff-next-meta-item
)
292 (define-key ediff-meta-buffer-map
"\C-?" 'ediff-previous-meta-item
)
293 (define-key ediff-meta-buffer-map
"p" 'ediff-previous-meta-item
)
294 (define-key ediff-meta-buffer-map
[delete] 'ediff-previous-meta-item)
295 (define-key ediff-meta-buffer-map [backspace] 'ediff-previous-meta-item)
296 (or (ediff-one-filegroup-metajob)
298 (define-key ediff-meta-buffer-map "=" nil)
299 (define-key ediff-meta-buffer-map "==" 'ediff-meta-mark-equal-files)
300 (define-key ediff-meta-buffer-map "=m" 'ediff-meta-mark-equal-files)
301 (define-key ediff-meta-buffer-map "=h" 'ediff-meta-mark-equal-files)))
302 (if ediff-no-emacs-help-in-control-buffer
303 (define-key ediff-meta-buffer-map "\C-h" 'ediff-previous-meta-item))
305 (define-key ediff-meta-buffer-map [mouse-2] ediff-meta-action-function)
306 (define-key ediff-meta-buffer-map [button2] ediff-meta-action-function))
308 (use-local-map ediff-meta-buffer-map)
309 ;; modify ediff-meta-buffer-map here
310 (run-hooks 'ediff-meta-buffer-keymap-setup-hook))
312 (defun ediff-meta-mode ()
313 "This mode controls all operations on Ediff session groups.
314 It is entered through one of the following commands:
319 `ediff-merge-directories'
321 `ediff-merge-directories-with-ancestor'
322 `edirs-merge-with-ancestor'
323 `ediff-directory-revisions'
325 `ediff-merge-directory-revisions'
326 `edir-merge-revisions'
327 `ediff-merge-directory-revisions-with-ancestor'
328 `edir-merge-revisions-with-ancestor'
331 \\{ediff-meta-buffer-map}"
332 (kill-all-local-variables)
333 (setq major-mode 'ediff-meta-mode)
334 (setq mode-name "MetaEdiff"))
337 ;; the keymap for the buffer showing directory differences
338 (suppress-keymap ediff-dir-diffs-buffer-map)
339 (define-key ediff-dir-diffs-buffer-map "q" 'ediff-bury-dir-diffs-buffer)
340 (define-key ediff-dir-diffs-buffer-map " " 'next-line)
341 (define-key ediff-dir-diffs-buffer-map "n" 'next-line)
342 (define-key ediff-dir-diffs-buffer-map "\C-?" 'previous-line)
343 (define-key ediff-dir-diffs-buffer-map "p" 'previous-line)
344 (define-key ediff-dir-diffs-buffer-map [delete] 'previous-line
)
345 (define-key ediff-dir-diffs-buffer-map
[backspace] 'previous-line)
347 (defun ediff-next-meta-item (count)
348 "Move to the next item in Ediff registry or session group buffer.
349 Moves in circular fashion. With numeric prefix arg, skip this many items."
351 (or count (setq count 1))
354 (setq count (1- count))
355 (ediff-next-meta-item1)
356 (setq overl (ediff-get-meta-overlay-at-pos (point)))
357 ;; skip invisible ones
358 (while (and overl (ediff-overlay-get overl 'invisible))
359 (ediff-next-meta-item1)
360 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
362 ;; Move to the next meta item
363 (defun ediff-next-meta-item1 ()
365 (setq pos (ediff-next-meta-overlay-start (point)))
366 (if pos (goto-char pos))
367 (if (eq ediff-metajob-name 'ediff-registry)
368 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
369 (search-forward "*Ediff" nil t))
370 (skip-chars-backward "a-zA-Z*"))
371 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
372 (backward-char 1)))))
375 (defun ediff-previous-meta-item (count)
376 "Move to the previous item in Ediff registry or session group buffer.
377 Moves in circular fashion. With numeric prefix arg, skip this many items."
379 (or count (setq count 1))
382 (setq count (1- count))
383 (ediff-previous-meta-item1)
384 (setq overl (ediff-get-meta-overlay-at-pos (point)))
385 ;; skip invisible ones
386 (while (and overl (ediff-overlay-get overl 'invisible))
387 (ediff-previous-meta-item1)
388 (setq overl (ediff-get-meta-overlay-at-pos (point)))))))
390 (defun ediff-previous-meta-item1 ()
392 (setq pos (ediff-previous-meta-overlay-start (point)))
394 ;;; (while (ediff-get-session-status
395 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror))
396 ;;; (setq pos (ediff-previous-meta-overlay-start pos)))
398 (if pos (goto-char pos))
399 (if (eq ediff-metajob-name 'ediff-registry)
400 (if (and (ediff-get-meta-info (current-buffer) pos 'noerror)
401 (search-forward "*Ediff" nil t))
402 (skip-chars-backward "a-zA-Z*"))
403 (if (> (skip-chars-forward "-+?H* \t0-9") 0)
407 (defsubst ediff-add-slash-if-directory (dir file)
408 (if (file-directory-p (concat dir file))
409 (file-name-as-directory file)
412 (defun ediff-toggle-filename-truncation ()
413 "Toggle truncation of long file names in session group buffers.
414 Set `ediff-meta-truncate-filenames' variable if you want to change the default
417 (setq ediff-meta-truncate-filenames (not ediff-meta-truncate-filenames))
418 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
421 ;; DIR1, DIR2, DIR3 are directories. DIR3 can be nil.
422 ;; OUTPUT-DIR is a directory for auto-storing the results of merge jobs.
424 ;; REGEXP is a regexp used to filter out files in the directories.
425 ;; If a file is a directory in dir1 but not dir2 (or vice versa), it is not
426 ;; included in the intersection. However, a regular file that is a dir in dir3
427 ;; is included, since dir3 files are supposed to be ancestors for merging.
428 ;; Returns a list of the form:
429 ;; ((dir1 dir2 dir3) (f1 f2 f3) (f1 f2 f3) ...)
430 ;; dir3, f3 can be nil if intersecting only 2 directories.
431 ;; If COMPARISON-FUNC is given, use it. Otherwise, use string=
432 ;; DIFF-VAR contains the name of the variable in which to return the
433 ;; difference list (which represents the differences among the contents of
434 ;; directories). The diff list is of the form:
435 ;; ((dir1 dir2 dir3) (file . num) (file . num)...)
436 ;; where num encodes the set of dirs where the file is found:
437 ;; 2 - only dir1; 3 - only dir2; 5 - only dir3; 6 - dir1&2; 10 - dir1&3; etc.
438 (defun ediff-intersect-directories (jobname
439 diff-var regexp dir1 dir2
441 dir3 merge-autostore-dir comparison-func)
442 (setq comparison-func (or comparison-func 'string=))
443 (let (lis1 lis2 lis3 common auxdir1 auxdir2 auxdir3 difflist)
445 (setq auxdir1 (file-name-as-directory dir1)
446 lis1 (directory-files auxdir1 nil regexp)
447 lis1 (delete "." lis1)
448 lis1 (delete ".." lis1)
451 (ediff-add-slash-if-directory auxdir1 elt))
453 auxdir2 (file-name-as-directory dir2)
456 (ediff-add-slash-if-directory auxdir2 elt))
457 (directory-files auxdir2 nil regexp)))
460 (setq auxdir3 (file-name-as-directory dir3)
463 (ediff-add-slash-if-directory auxdir3 elt))
464 (directory-files auxdir3 nil regexp))))
466 (if (ediff-nonempty-string-p merge-autostore-dir)
467 (setq merge-autostore-dir
468 (file-name-as-directory merge-autostore-dir)))
469 (setq common (ediff-intersection lis1 lis2 comparison-func))
471 ;; In merge with ancestor jobs, we don't intersect with lis3.
472 ;; If there is no ancestor, we'll offer to merge without the ancestor.
473 ;; So, we intersect with lis3 only when we are doing 3-way file comparison
474 (if (and lis3 (ediff-comparison-metajob3 jobname))
475 (setq common (ediff-intersection common lis3 comparison-func)))
477 ;; copying is needed because sort sorts via side effects
478 (setq common (sort (ediff-copy-list common) 'string-lessp))
480 ;; compute difference list
481 (setq difflist (ediff-set-difference
482 (ediff-union (ediff-union lis1 lis2 comparison-func)
487 difflist (delete "." difflist)
488 ;; copying is needed because sort sorts via side effects
489 difflist (sort (ediff-copy-list (delete ".." difflist))
492 (setq difflist (mapcar (lambda (elt) (cons elt 1)) difflist))
494 ;; check for files belonging to lis1/2/3
495 (mapcar (lambda (elt)
496 (if (member (car elt) lis1)
497 (setcdr elt (* (cdr elt) 2)))
498 (if (member (car elt) lis2)
499 (setcdr elt (* (cdr elt) 3)))
500 (if (member (car elt) lis3)
501 (setcdr elt (* (cdr elt) 5)))
504 (setq difflist (cons (list regexp auxdir1 auxdir2 auxdir3) difflist))
506 ;; return the difference list back to the calling function
507 (set diff-var difflist)
510 (cons (list regexp auxdir1 auxdir2 auxdir3 merge-autostore-dir)
513 (list (concat auxdir1 elt)
517 ;; The following is done because:
518 ;; In merging with ancestor, we don't intersect
519 ;; with lis3. So, it is possible that elt is a
520 ;; file in auxdir1/2 but a directory in auxdir3
521 ;; Or elt may not exist in auxdir3 at all.
522 ;; In the first case, we add a slash at the end.
523 ;; In the second case, we insert nil.
524 (setq elt (ediff-add-slash-if-directory auxdir3 elt))
525 (if (file-exists-p (concat auxdir3 elt))
526 (concat auxdir3 elt))))))
530 ;; find directory files that are under revision. Include subdirectories, since
531 ;; we may visit them recursively. DIR1 is the directory to inspect.
532 ;; MERGE-AUTOSTORE-DIR is the directory where to auto-store the results of
533 ;; merges. Can be nil.
534 (defun ediff-get-directory-files-under-revision (jobname
536 &optional merge-autostore-dir)
537 (let (lis1 elt common auxdir1)
538 (setq auxdir1 (file-name-as-directory dir1)
539 lis1 (directory-files auxdir1 nil regexp))
541 (if (ediff-nonempty-string-p merge-autostore-dir)
542 (setq merge-autostore-dir
543 (file-name-as-directory merge-autostore-dir)))
548 ;; take files under revision control
549 (cond ((file-directory-p (concat auxdir1 elt))
551 (cons (ediff-add-slash-if-directory auxdir1 elt) common)))
552 ((and (featurep 'vc-hooks) (vc-backend (concat auxdir1 elt)))
553 (setq common (cons elt common)))
554 ;; The following two are needed only if vc-hooks isn't loaded.
555 ;; They won't recognize CVS files.
556 ((file-exists-p (concat auxdir1 elt ",v"))
557 (setq common (cons elt common)))
558 ((file-exists-p (concat auxdir1 "RCS/" elt ",v"))
559 (setq common (cons elt common)))
563 (setq common (delete "./" common)
564 common (delete "../" common)
565 common (delete "RCS" common)
566 common (delete "CVS" common)
569 ;; copying is needed because sort sorts via side effects
570 (setq common (sort (ediff-copy-list common) 'string-lessp))
573 (cons (list regexp auxdir1 nil nil merge-autostore-dir)
574 (mapcar (lambda (elt) (list (concat auxdir1 elt) nil nil))
579 ;; If file groups selected by patterns will ever be implemented, this
580 ;; comparison function might become useful.
581 ;;;; uses external variables PAT1 PAT2 to compare str1/2
582 ;;;; patterns must be of the form ???*???? where ??? are strings of chars
583 ;;;; containing no *.
584 ;;(defun ediff-pattern= (str1 str2)
585 ;; (let (pos11 pos12 pos21 pos22 len1 len2)
587 ;; len (length epat1)
589 ;; (while (and (< pos11 len) (not (= (aref epat1 pos11) ?*)))
590 ;; (setq pos11 (1+ pos11)))
591 ;; (while (and (> pos12 0) (not (= (aref epat1 (1- pos12)) ?*)))
592 ;; (setq pos12 (1- pos12)))
595 ;; len (length epat2)
597 ;; (while (and (< pos21 len) (not (= (aref epat2 pos21) ?*)))
598 ;; (setq pos21 (1+ pos21)))
599 ;; (while (and (> pos22 0) (not (= (aref epat2 (1- pos22)) ?*)))
600 ;; (setq pos22 (1- pos22)))
602 ;; (if (and (> (length str1) pos12) (>= pos12 pos11) (> pos11 -1)
603 ;; (> (length str2) pos22) (>= pos22 pos21) (> pos21 -1))
604 ;; (string= (substring str1 pos11 pos12)
605 ;; (substring str2 pos21 pos22)))
609 ;; Prepare meta-buffer in accordance with the argument-function and
610 ;; redraw-function. Must return the created meta-buffer.
611 (defun ediff-prepare-meta-buffer (action-func meta-list
612 meta-buffer-name redraw-function
613 jobname &optional startup-hooks)
614 (let* ((meta-buffer-name
615 (ediff-unique-buffer-name meta-buffer-name "*"))
616 (meta-buffer (get-buffer-create meta-buffer-name)))
617 (ediff-with-current-buffer meta-buffer
622 (setq ediff-meta-action-function action-func
623 ediff-meta-redraw-function redraw-function
624 ediff-metajob-name jobname
625 ediff-meta-buffer meta-buffer)
627 ;; comes after ediff-meta-action-function is set
628 (ediff-setup-meta-map)
630 (if (eq ediff-metajob-name 'ediff-registry)
632 (setq ediff-registry-buffer meta-buffer
633 ediff-meta-list meta-list)
634 ;; this func is used only from registry buffer, not from other
637 ediff-meta-buffer-map "M" 'ediff-show-meta-buff-from-registry))
638 ;; Initialize the meta list -- don't do this for registry.
640 ;; We prepend '(nil nil) to all elts of meta-list, except the first.
641 ;; The first nil will later be replaced by the session buffer. The
642 ;; second is reserved for session status.
644 ;; (car ediff-meta-list) gets cons'ed with the session group buffer.
645 ;; Also, session objects A/B/C are turned into lists of the form
646 ;; (obj eq-indicator). Eq-indicator is either nil or =. Initialized to
647 ;; nil. If later it is discovered that this file is = to some other
648 ;; file in the same session, eq-indicator is changed to `='.
649 ;; For now, the eq-indicator is used only for 2 and 3-file jobs.
650 (setq ediff-meta-list
651 (cons (cons meta-buffer (car meta-list))
656 ;; convert each obj to (obj nil),
657 ;; where nil is the initial value
658 ;; for eq-indicator -- see above
659 (mapcar (lambda (obj) (list obj nil))
663 (or (eq meta-buffer ediff-registry-buffer)
664 (setq ediff-session-registry
665 (cons meta-buffer ediff-session-registry)))
667 ;; redraw-function uses ediff-meta-list
668 (funcall redraw-function ediff-meta-list)
670 ;; set read-only/non-modified
671 (setq buffer-read-only t)
672 (set-buffer-modified-p nil)
674 (run-hooks 'startup-hooks)
676 ;; Arrange to show directory contents differences
677 ;; Must be after run startup-hooks, since ediff-dir-difference-list is
678 ;; set inside these hooks
679 (if (eq action-func 'ediff-filegroup-action)
681 ;; put meta buffer in (car ediff-dir-difference-list)
682 (setq ediff-dir-difference-list
683 (cons (cons meta-buffer (car ediff-dir-difference-list))
684 (cdr ediff-dir-difference-list)))
686 (or (ediff-one-filegroup-metajob jobname)
687 (ediff-draw-dir-diffs ediff-dir-difference-list))
689 ediff-meta-buffer-map "h" 'ediff-mark-for-hiding-at-pos)
690 (define-key ediff-meta-buffer-map "x" 'ediff-hide-marked-sessions)
692 ediff-meta-buffer-map "m" 'ediff-mark-for-operation-at-pos)
693 (define-key ediff-meta-buffer-map "u" nil)
695 ediff-meta-buffer-map "um" 'ediff-unmark-all-for-operation)
697 ediff-meta-buffer-map "uh" 'ediff-unmark-all-for-hiding)
698 (cond ((ediff-collect-diffs-metajob jobname)
700 ediff-meta-buffer-map "P" 'ediff-collect-custom-diffs))
701 ((ediff-patch-metajob jobname)
703 ediff-meta-buffer-map "P" 'ediff-meta-show-patch)))
704 (define-key ediff-meta-buffer-map "^" 'ediff-up-meta-hierarchy)
705 (define-key ediff-meta-buffer-map "D" 'ediff-show-dir-diffs)))
707 (if (eq ediff-metajob-name 'ediff-registry)
708 (run-hooks 'ediff-registry-setup-hook)
709 (run-hooks 'ediff-session-group-setup-hook))
710 ) ; eval in meta-buffer
713 ;; Insert the activity marker for session SESSION in the meta buffer at point
714 ;; The activity marker is either SPC (untouched session), or + (active session,
715 ;; i.e., ediff is currently run in it), or - (finished session, i.e., we've ran
716 ;; ediff in it and then exited)
717 (defun ediff-insert-session-activity-marker-in-meta-buffer (session)
719 (cond ((ediff-get-session-activity-marker session))
723 ;; Insert session status at point. Status is either ?H (marked for hiding), or
724 ;; ?I (hidden or invalid), or ?* (meaning marked for an operation; currently,
725 ;; such op can only be checking for equality)), or SPC (meaning neither marked
727 (defun ediff-insert-session-status-in-meta-buffer (session)
729 (cond ((ediff-get-session-status session)) ; session has status: ?H, ?I, ?*
730 ;; normal session, no marks or hidings
733 ;; If NEW-MARKER is non-nil, use it to substitute the current activity marker
734 ;; in the meta buffer. If nil, use SPC
735 (defun ediff-replace-session-activity-marker-in-meta-buffer (point new-marker)
736 (let* ((overl (ediff-get-meta-overlay-at-pos point))
737 (session-info (ediff-overlay-get overl 'ediff-meta-info))
738 (activity-marker (ediff-get-session-activity-marker session-info))
740 (or new-marker activity-marker (setq new-marker ?\ ))
741 (goto-char (ediff-overlay-start overl))
742 (if (eq (char-after (point)) new-marker)
743 () ; if marker shown in buffer is the same as new-marker, do nothing
746 (set-buffer-modified-p nil))))
748 ;; If NEW-STATUS is non-nil, use it to substitute the current status marker in
749 ;; the meta buffer. If nil, use SPC
750 (defun ediff-replace-session-status-in-meta-buffer (point new-status)
751 (let* ((overl (ediff-get-meta-overlay-at-pos point))
752 (session-info (ediff-overlay-get overl 'ediff-meta-info))
753 (status (ediff-get-session-status session-info))
755 (setq new-status (or new-status status ?\ ))
756 (goto-char (ediff-overlay-start overl))
757 (forward-char 1) ; status is the second char in session record
758 (if (eq (char-after (point)) new-status)
759 () ; if marker shown in buffer is the same as new-marker, do nothing
762 (set-buffer-modified-p nil))))
764 ;; insert all file info in meta buffer for a given session
765 (defun ediff-insert-session-info-in-meta-buffer (session-info sessionNum)
766 (let ((f1 (ediff-get-session-objA session-info))
767 (f2 (ediff-get-session-objB session-info))
768 (f3 (ediff-get-session-objC session-info))
770 (hidden (eq (ediff-get-session-status session-info) ?I)))
771 ;; insert activity marker, i.e., SPC, - or +
772 (ediff-insert-session-activity-marker-in-meta-buffer session-info)
773 ;; insert session status, i.e., *, H
774 (ediff-insert-session-status-in-meta-buffer session-info)
775 (insert " Session " (int-to-string sessionNum) ":\n")
776 (ediff-meta-insert-file-info1 f1)
777 (ediff-meta-insert-file-info1 f2)
778 (ediff-meta-insert-file-info1 f3)
779 (ediff-set-meta-overlay pt (point) session-info sessionNum hidden)))
782 ;; this is a setup function for ediff-directories
783 ;; must return meta-buffer
784 (defun ediff-redraw-directory-group-buffer (meta-list)
785 ;; extract directories
786 (let ((meta-buf (ediff-get-group-buffer meta-list))
789 regexp elt merge-autostore-dir
790 point tmp-list buffer-read-only)
791 (ediff-with-current-buffer meta-buf
794 ;; delete phony overlays that used to represent sessions before the buff
797 (mapcar 'delete-overlay (overlays-in 1 1))
798 (map-extents 'delete-extent))
800 (insert (format ediff-meta-buffer-message
801 (ediff-abbrev-jobname ediff-metajob-name)))
803 (setq regexp (ediff-get-group-regexp meta-list)
805 (ediff-get-group-merge-autostore-dir meta-list))
807 (cond ((ediff-collect-diffs-metajob)
809 " P:\tcollect custom diffs of all marked sessions\n"))
810 ((ediff-patch-metajob)
812 " P:\tshow patch appropriately for the context (session or group)\n")))
814 " ^:\tshow parent session group\n")
815 (or (ediff-one-filegroup-metajob)
817 " D:\tshow differences among directories\n"
818 " ==:\tfor each session, show which files are identical\n"
819 " =h:\tlike ==, but also marks those sessions for hiding\n"
820 " =m:\tlike ==, but also marks those sessions for operation\n\n"))
823 (if (and (stringp regexp) (> (length regexp) 0))
825 (format "*** Filter-through regular expression: %s\n" regexp)))
826 (ediff-insert-dirs-in-meta-buffer meta-list)
827 (if (and ediff-autostore-merges (ediff-merge-metajob)
828 (ediff-nonempty-string-p merge-autostore-dir))
830 "\nMerge results are automatically stored in:\n\t%s\n"
831 merge-autostore-dir)))
833 Size Last modified Name
834 ----------------------------------------------
838 ;; discard info on directories and regexp
839 (setq meta-list (cdr meta-list)
841 (while (and tmp-list empty)
842 (if (and (car tmp-list)
843 (not (eq (ediff-get-session-status (car tmp-list)) ?I)))
845 (setq tmp-list (cdr tmp-list)))
849 " ****** ****** This session group has no members\n"))
851 ;; now organize file names like this:
852 ;; use-mark sizeA dateA sizeB dateB filename
853 ;; make sure directories are displayed with a trailing slash.
855 (setq elt (car meta-list)
856 meta-list (cdr meta-list)
857 sessionNum (1+ sessionNum))
858 (if (eq (ediff-get-session-status elt) ?I)
860 (ediff-insert-session-info-in-meta-buffer elt sessionNum)))
861 (set-buffer-modified-p nil)
865 (defun ediff-update-markers-in-dir-meta-buffer (meta-list)
866 (let ((meta-buf (ediff-get-group-buffer meta-list))
867 session-info point overl buffer-read-only)
868 (ediff-with-current-buffer meta-buf
870 (goto-char (point-min))
871 (ediff-next-meta-item1)
873 (setq session-info (ediff-get-meta-info meta-buf (point) 'no-error)
874 overl (ediff-get-meta-overlay-at-pos (point)))
877 (cond ((eq (ediff-get-session-status session-info) ?I)
879 (if overl (ediff-overlay-put overl 'invisible t)))
880 ((and (eq (ediff-get-session-status session-info) ?H)
881 overl (ediff-overlay-get overl 'invisible))
883 (ediff-overlay-put overl 'invisible nil))
884 (t (ediff-replace-session-activity-marker-in-meta-buffer
886 (ediff-get-session-activity-marker session-info))
887 (ediff-replace-session-status-in-meta-buffer
889 (ediff-get-session-status session-info))))))
890 (ediff-next-meta-item1) ; advance to the next item
892 (set-buffer-modified-p nil)
896 (defun ediff-update-session-marker-in-dir-meta-buffer (session-num)
897 (let (buffer-meta-overlays session-info overl buffer-read-only)
903 (ediff-overlay-get ext 'ediff-meta-info)
904 (eq (ediff-overlay-get ext 'ediff-meta-session-number)
907 ;; Emacs doesn't have map-extents, so try harder
908 ;; Splice overlay lists to get all buffer overlays
909 (setq buffer-meta-overlays (overlay-lists)
910 buffer-meta-overlays (append (car buffer-meta-overlays)
911 (cdr buffer-meta-overlays)))
917 (ediff-overlay-get overl 'ediff-meta-info)
918 (eq (ediff-overlay-get
919 overl 'ediff-meta-session-number)
922 buffer-meta-overlays)))))
925 "Bug in ediff-update-session-marker-in-dir-meta-buffer: no overlay with given number %S"
927 (setq session-info (ediff-overlay-get overl 'ediff-meta-info))
928 (goto-char (ediff-overlay-start overl))
929 (ediff-replace-session-activity-marker-in-meta-buffer
931 (ediff-get-session-activity-marker session-info))
932 (ediff-replace-session-status-in-meta-buffer
934 (ediff-get-session-status session-info)))
935 (ediff-next-meta-item1))
939 ;; Check if this is a problematic session.
940 ;; Return nil if not. Otherwise, return symbol representing the problem
941 ;; At present, problematic sessions occur only in -with-ancestor comparisons
942 ;; when the ancestor is a directory rather than a file, or when there is no
943 ;; suitable ancestor file in the ancestor directory
944 (defun ediff-problematic-session-p (session)
945 (let ((f1 (ediff-get-session-objA-name session))
946 (f2 (ediff-get-session-objB-name session))
947 (f3 (ediff-get-session-objC-name session)))
948 (cond ((and (stringp f1) (not (file-directory-p f1))
949 (stringp f2) (not (file-directory-p f2))
950 ;; either invalid file name or a directory
951 (or (not (stringp f3)) (file-directory-p f3))
952 (ediff-ancestor-metajob))
953 ;; more may be added later
957 (defun ediff-meta-insert-file-info1 (fileinfo)
958 (let ((fname (car fileinfo))
959 (feq (ediff-get-file-eqstatus fileinfo))
960 (max-filename-width (if ediff-meta-truncate-filenames
961 (- (window-width) 41)
963 file-modtime file-size)
964 (cond ((not (stringp fname)) (setq file-size -2)) ; file doesn't exits
965 ((not (ediff-file-remote-p fname))
966 (if (file-exists-p fname)
967 ;; set real size and modtime
968 (setq file-size (ediff-file-size fname)
969 file-modtime (ediff-file-modtime fname))
970 (setq file-size -2))) ; file doesn't exist
971 ( t (setq file-size -1))) ; remote file
976 (if feq "=" " ") ; equality indicator
977 (format "%10s" (cond ((= file-size -1) "--")
978 ((< file-size -1) "--")
980 (cond ((= file-size -1) "*remote file*")
981 ((< file-size -1) "*file doesn't exist*")
982 (t (ediff-format-date (decode-time file-modtime))))
984 ;; dir names in meta lists have training slashes, so we just
985 ;; abbreviate the file name, if file exists
986 (if (and (not (stringp fname)) (< file-size -1))
987 "-------" ; file doesn't exist
988 (ediff-truncate-string-left
989 (ediff-abbreviate-file-name fname)
990 max-filename-width)))))))
992 (defconst ediff-months '((1 . "Jan") (2 . "Feb") (3 . "Mar") (4 . "Apr")
993 (5 . "May") (6 . "Jun") (7 . "Jul") (8 . "Aug")
994 (9 . "Sep") (10 . "Oct") (11 . "Nov") (12 . "Dec"))
995 "Months' associative array.")
997 ;; returns 2char string
998 (defsubst ediff-fill-leading-zero (num)
1001 (number-to-string num)))
1003 ;; TIME is like the output of decode-time
1004 (defun ediff-format-date (time)
1005 (format "%s %2d %4d %s:%s:%s"
1006 (cdr (assoc (nth 4 time) ediff-months)) ; month
1009 (ediff-fill-leading-zero (nth 2 time)) ; hour
1010 (ediff-fill-leading-zero (nth 1 time)) ; min
1011 (ediff-fill-leading-zero (nth 0 time)) ; sec
1014 ;; Draw the directories
1015 (defun ediff-insert-dirs-in-meta-buffer (meta-list)
1016 (let* ((dir1 (ediff-abbreviate-file-name (ediff-get-group-objA meta-list)))
1017 (dir2 (ediff-get-group-objB meta-list))
1018 (dir2 (if (stringp dir2) (ediff-abbreviate-file-name dir2)))
1019 (dir3 (ediff-get-group-objC meta-list))
1020 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3))))
1021 (insert "*** Directory A: " dir1 "\n")
1022 (if dir2 (insert "*** Directory B: " dir2 "\n"))
1023 (if dir3 (insert "*** Directory C: " dir3 "\n"))
1026 (defun ediff-draw-dir-diffs (diff-list)
1027 (if (null diff-list) (error "Lost difference info on these directories"))
1028 (let* ((buf-name (ediff-unique-buffer-name
1029 "*Ediff File Group Differences" "*"))
1030 (regexp (ediff-get-group-regexp diff-list))
1031 (dir1 (ediff-abbreviate-file-name (ediff-get-group-objA diff-list)))
1032 (dir2 (ediff-abbreviate-file-name (ediff-get-group-objB diff-list)))
1033 (dir3 (ediff-get-group-objC diff-list))
1034 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3)))
1035 (meta-buf (ediff-get-group-buffer diff-list))
1036 (underline (make-string 26 ?-))
1039 ;; skip the directory part
1040 (setq diff-list (cdr diff-list))
1041 (setq ediff-dir-diffs-buffer (get-buffer-create buf-name))
1042 (ediff-with-current-buffer ediff-dir-diffs-buffer
1043 (use-local-map ediff-dir-diffs-buffer-map)
1045 (setq ediff-meta-buffer meta-buf)
1046 (insert "\t\t*** Directory Differences ***\n")
1049 `q': hide this buffer
1051 p,DEL: previous line\n\n")
1053 (if (and (stringp regexp) (> (length regexp) 0))
1055 (format "\n*** Filter-through regular expression: %s\n" regexp)))
1057 (insert (format "\n%-27s%-26s"
1058 (ediff-truncate-string-left
1059 (ediff-abbreviate-file-name
1060 (file-name-as-directory dir1))
1062 (ediff-truncate-string-left
1063 (ediff-abbreviate-file-name
1064 (file-name-as-directory dir2))
1067 (insert (format " %-25s\n"
1068 (ediff-truncate-string-left
1069 (ediff-abbreviate-file-name
1070 (file-name-as-directory dir3))
1073 (insert (format "%s%s" underline underline))
1075 (insert (format "%s\n\n" underline))
1078 (if (null diff-list)
1079 (insert "\n\t*** No differences ***\n"))
1082 (setq file (car (car diff-list))
1083 code (cdr (car diff-list))
1084 diff-list (cdr diff-list))
1085 (if (= (mod code 2) 0) ; dir1
1086 (insert (format "%-27s"
1087 (ediff-truncate-string-left
1088 (ediff-abbreviate-file-name
1089 (if (file-directory-p (concat dir1 file))
1090 (file-name-as-directory file)
1093 (insert (format "%-27s" "---")))
1094 (if (= (mod code 3) 0) ; dir2
1095 (insert (format "%-26s"
1096 (ediff-truncate-string-left
1097 (ediff-abbreviate-file-name
1098 (if (file-directory-p (concat dir2 file))
1099 (file-name-as-directory file)
1102 (insert (format "%-26s" "---")))
1104 (if (= (mod code 5) 0) ; dir3
1105 (insert (format " %-25s"
1106 (ediff-truncate-string-left
1107 (ediff-abbreviate-file-name
1108 (if (file-directory-p (concat dir3 file))
1109 (file-name-as-directory file)
1112 (insert (format " %-25s" "---"))))
1114 (setq buffer-read-only t)
1115 (set-buffer-modified-p nil)) ; eval in diff buffer
1118 (defun ediff-bury-dir-diffs-buffer ()
1119 "Bury the directory difference buffer. Display the meta buffer instead."
1121 (let ((buf ediff-meta-buffer)
1124 (if (setq wind (ediff-get-visible-buffer-window buf))
1125 (select-window wind)
1126 (set-window-buffer (selected-window) buf))))
1128 ;; executes in dir session group buffer
1129 ;; show buffer differences
1130 (defun ediff-show-dir-diffs ()
1131 "Display differences among the directories involved in session group."
1133 (if (ediff-one-filegroup-metajob)
1134 (error "This command is inapplicable in the present context"))
1135 (or (ediff-buffer-live-p ediff-dir-diffs-buffer)
1136 (ediff-draw-dir-diffs ediff-dir-difference-list))
1137 (let ((buf ediff-dir-diffs-buffer))
1139 (set-window-buffer (selected-window) buf)
1140 (goto-char (point-min))))
1142 (defun ediff-up-meta-hierarchy ()
1143 "Go to the parent session group buffer."
1145 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1146 (ediff-show-meta-buffer
1147 ediff-parent-meta-buffer ediff-meta-session-number)
1148 (error "This session group has no parent")))
1151 ;; argument is ignored
1152 (defun ediff-redraw-registry-buffer (&optional ignore)
1153 (ediff-with-current-buffer ediff-registry-buffer
1154 (let ((point (point))
1155 elt bufAname bufBname bufCname cur-diff total-diffs pt
1156 job-name meta-list registry-list buffer-read-only)
1158 ;; delete phony overlays that used to represent sessions before the buff
1161 (mapcar 'delete-overlay (overlays-in 1 1))
1162 (map-extents 'delete-extent))
1164 (insert "This is a registry of all active Ediff sessions.
1167 button2, `v', RET over a session record: switch to that session
1168 M over a session record: display the associated session group
1169 R in any Ediff session: display session registry
1171 p,DEL: previous session
1172 E: browse Ediff on-line manual
1176 \t\tActive Ediff Sessions:
1177 \t\t----------------------
1180 ;; purge registry list from dead buffers
1181 (mapcar (lambda (elt)
1182 (if (not (ediff-buffer-live-p elt))
1183 (setq ediff-session-registry
1184 (delq elt ediff-session-registry))))
1185 ediff-session-registry)
1187 (if (null ediff-session-registry)
1188 (insert " ******* No active Ediff sessions *******\n"))
1190 (setq registry-list ediff-session-registry)
1191 (while registry-list
1192 (setq elt (car registry-list)
1193 registry-list (cdr registry-list))
1195 (if (ediff-buffer-live-p elt)
1196 (if (ediff-with-current-buffer elt
1197 (setq job-name ediff-metajob-name
1198 meta-list ediff-meta-list)
1199 (and ediff-metajob-name
1200 (not (eq ediff-metajob-name 'ediff-registry))))
1203 (insert (format " *group*\t%s: %s\n"
1205 (ediff-abbrev-jobname job-name)))
1206 (insert (format "\t\t %s %s %s\n"
1207 (ediff-abbreviate-file-name
1208 (ediff-get-group-objA meta-list))
1209 (ediff-abbreviate-file-name
1211 (ediff-get-group-objB meta-list))
1212 (ediff-get-group-objB meta-list)
1214 (ediff-abbreviate-file-name
1216 (ediff-get-group-objC meta-list))
1217 (ediff-get-group-objC meta-list)
1219 (ediff-set-meta-overlay pt (point) elt))
1221 (ediff-with-current-buffer elt
1222 (setq bufAname (if (ediff-buffer-live-p ediff-buffer-A)
1223 (buffer-name ediff-buffer-A)
1224 "!!!killed buffer!!!")
1225 bufBname (if (ediff-buffer-live-p ediff-buffer-B)
1226 (buffer-name ediff-buffer-B)
1227 "!!!killed buffer!!!")
1228 bufCname (cond ((not (ediff-3way-job))
1230 ((ediff-buffer-live-p ediff-buffer-C)
1231 (buffer-name ediff-buffer-C))
1232 (t "!!!killed buffer!!!")))
1233 (setq total-diffs (format "%-4d" ediff-number-of-differences)
1235 (cond ((= ediff-current-difference -1) " _")
1236 ((= ediff-current-difference
1237 ediff-number-of-differences)
1240 "%4d" (1+ ediff-current-difference))))
1241 job-name ediff-job-name))
1242 ;; back in the meta buf
1244 (insert cur-diff "/" total-diffs "\t"
1246 (format ": %s" (ediff-abbrev-jobname job-name)))
1248 "\n\t\t " bufAname " " bufBname " " bufCname "\n")
1249 (ediff-set-meta-overlay pt (point) elt))))
1251 (set-buffer-modified-p nil)
1255 ;; Sets overlay around a meta record with 'ediff-meta-info property PROP
1256 ;; If optional SESSION-NUMBER, make it a property of the overlay,
1257 ;; ediff-meta-session-number
1258 (defun ediff-set-meta-overlay (b e prop &optional session-number hidden)
1260 (setq overl (ediff-make-overlay b e))
1262 (ediff-overlay-put overl 'mouse-face 'highlight)
1263 (ediff-overlay-put overl 'highlight t))
1264 (ediff-overlay-put overl 'ediff-meta-info prop)
1265 (ediff-overlay-put overl 'invisible hidden)
1266 (if (numberp session-number)
1267 (ediff-overlay-put overl 'ediff-meta-session-number session-number))))
1269 (defun ediff-mark-for-hiding-at-pos (unmark)
1270 "Mark session for hiding. With prefix arg, unmark."
1272 (let* ((pos (ediff-event-point last-command-event))
1273 (meta-buf (ediff-event-buffer last-command-event))
1274 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1275 (info (ediff-get-meta-info meta-buf pos))
1276 (session-number (ediff-get-session-number-at-pos pos)))
1277 (ediff-mark-session-for-hiding info unmark)
1278 (ediff-next-meta-item 1)
1280 (ediff-update-meta-buffer meta-buf nil session-number))
1283 ;; Returns whether session was marked or unmarked
1284 (defun ediff-mark-session-for-hiding (info unmark)
1285 (let ((session-buf (ediff-get-session-buffer info))
1287 (cond ((eq unmark 'mark) (setq unmark nil))
1288 ((eq (ediff-get-session-status info) ?H) (setq unmark t))
1289 (unmark ; says unmark, but the marker is different from H
1292 (unmark (ediff-set-session-status info nil))
1293 ;;; (if (ediff-buffer-live-p session-buf)
1294 ;;; (error "Can't hide active session, %s" (buffer-name session-buf)))
1295 (t (ediff-set-session-status info ?H))))
1299 (defun ediff-mark-for-operation-at-pos (unmark)
1300 "Mark session for a group operation. With prefix arg, unmark."
1302 (let* ((pos (ediff-event-point last-command-event))
1303 (meta-buf (ediff-event-buffer last-command-event))
1304 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1305 (info (ediff-get-meta-info meta-buf pos))
1306 (session-number (ediff-get-session-number-at-pos pos)))
1307 (ediff-mark-session-for-operation info unmark)
1308 (ediff-next-meta-item 1)
1310 (ediff-update-meta-buffer meta-buf nil session-number))
1314 ;; returns whether session was unmarked.
1315 ;; remember: this is a toggle op
1316 (defun ediff-mark-session-for-operation (info unmark)
1318 (cond ((eq unmark 'mark) (setq unmark nil))
1319 ((eq (ediff-get-session-status info) ?*) (setq unmark t))
1320 (unmark ; says unmark, but the marker is different from *
1323 (unmark (ediff-set-session-status info nil))
1324 (t (ediff-set-session-status info ?*))))
1328 (defun ediff-hide-marked-sessions (unhide)
1329 "Hide marked sessions. With prefix arg, unhide."
1331 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1332 (meta-list (cdr ediff-meta-list))
1333 (from (if unhide ?I ?H))
1334 (to (if unhide ?H ?I))
1336 active-sessions-exist session-buf elt)
1338 (setq elt (car meta-list)
1339 meta-list (cdr meta-list)
1340 session-buf (ediff-get-session-buffer elt))
1342 (if (eq (ediff-get-session-status elt) from)
1344 (setq numMarked (1+ numMarked))
1345 (if (and (eq to ?I) (buffer-live-p session-buf))
1346 ;; shouldn't hide active sessions
1347 (setq active-sessions-exist t)
1348 (ediff-set-session-status elt to)))))
1350 (ediff-update-meta-buffer grp-buf 'must-redraw)
1353 (message "Nothing to reveal...")
1354 (message "Nothing to hide...")))
1355 (if active-sessions-exist
1356 (message "Note: Ediff didn't hide active sessions!"))
1359 ;; Apply OPERATION to marked sessions. Operation expects one argument of type
1360 ;; meta-list member (not the first one), i.e., a regular session description.
1361 ;; Returns number of marked sessions on which operation was performed
1362 (defun ediff-operate-on-marked-sessions (operation)
1363 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list))
1364 (meta-list (cdr ediff-meta-list))
1368 (diff-buffer ediff-meta-diff-buffer)
1371 (setq elt (car meta-list)
1372 meta-list (cdr meta-list)
1373 sessionNum (1+ sessionNum))
1374 (cond ((eq (ediff-get-session-status elt) marksym)
1376 (setq numMarked (1+ numMarked))
1377 (funcall operation elt sessionNum)))
1378 ((and (ediff-meta-session-p elt)
1379 (ediff-buffer-live-p
1380 (setq session-buf (ediff-get-session-buffer elt))))
1383 (ediff-with-current-buffer session-buf
1384 ;; pass meta-diff along
1385 (setq ediff-meta-diff-buffer diff-buffer)
1386 ;; collect diffs in child group
1387 (ediff-operate-on-marked-sessions operation)))))))
1388 (ediff-update-meta-buffer grp-buf 'must-redraw) ; just in case
1392 (defun ediff-append-custom-diff (session sessionNum)
1393 (or (ediff-collect-diffs-metajob)
1394 (error "Hmm, I'd hate to do it to you ..."))
1395 (let ((session-buf (ediff-get-session-buffer session))
1396 (meta-diff-buff ediff-meta-diff-buffer)
1397 (metajob ediff-metajob-name)
1398 tmp-buf custom-diff-buf)
1399 (if (ediff-buffer-live-p session-buf)
1400 (ediff-with-current-buffer session-buf
1401 (if (eq ediff-control-buffer session-buf) ; individual session
1403 (ediff-compute-custom-diffs-maybe)
1404 (setq custom-diff-buf ediff-custom-diff-buffer)))))
1406 (or (ediff-buffer-live-p meta-diff-buff)
1407 (error "Ediff: something wrong--no multiple diffs buffer"))
1409 (cond ((ediff-buffer-live-p custom-diff-buf)
1411 (set-buffer meta-diff-buff)
1412 (goto-char (point-max))
1413 (insert-buffer custom-diff-buf)
1415 ((memq metajob '(ediff-directories
1416 ediff-merge-directories
1417 ediff-merge-directories-with-ancestor))
1418 ;; get diffs by calling shell command on ediff-custom-diff-program
1420 (set-buffer (setq tmp-buf (get-buffer-create ediff-tmp-buffer)))
1423 (format "%s %s %s %s"
1424 ediff-custom-diff-program ediff-custom-diff-options
1425 (ediff-get-session-objA-name session)
1426 (ediff-get-session-objB-name session))
1429 (set-buffer meta-diff-buff)
1430 (goto-char (point-max))
1431 (insert-buffer tmp-buf)
1434 (error "Can't make context diff for Session %d" sessionNum )))
1437 (defun ediff-collect-custom-diffs ()
1438 "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'.
1439 This operation is defined only for `ediff-directories' and
1440 `ediff-directory-revisions', since its intent is to produce
1441 multifile patches. For `ediff-directory-revisions', we insist that
1442 all marked sessions must be active."
1444 (or (ediff-buffer-live-p ediff-meta-diff-buffer)
1445 (setq ediff-meta-diff-buffer
1447 (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))
1448 (ediff-with-current-buffer ediff-meta-diff-buffer
1450 (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0)
1453 (display-buffer ediff-meta-diff-buffer 'not-this-window)
1454 (ediff-with-current-buffer ediff-meta-diff-buffer
1455 (set-buffer-modified-p nil)
1456 (setq buffer-read-only t)))
1458 (message "No marked sessions found")))
1460 (defun ediff-meta-show-patch ()
1461 "Show the multi-file patch associated with this group session."
1463 (let* ((pos (ediff-event-point last-command-event))
1464 (meta-buf (ediff-event-buffer last-command-event))
1465 (info (ediff-get-meta-info meta-buf pos 'noerror))
1466 (patchbuffer ediff-meta-patchbufer))
1467 (if (ediff-buffer-live-p patchbuffer)
1468 (ediff-with-current-buffer patchbuffer
1473 (ediff-get-session-objB-name info)
1474 (ediff-get-session-objC-name info)))
1475 (set-buffer (get-buffer-create ediff-tmp-buffer))
1477 (insert-buffer patchbuffer)
1478 (display-buffer ediff-tmp-buffer 'not-this-window)
1480 (error "The patch buffer wasn't found"))))
1483 ;; This function executes in meta buffer. It knows where event happened.
1484 (defun ediff-filegroup-action ()
1485 "Execute appropriate action for the selected session."
1487 (let* ((pos (ediff-event-point last-command-event))
1488 (meta-buf (ediff-event-buffer last-command-event))
1489 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
1490 (info (ediff-get-meta-info meta-buf pos))
1491 (session-buf (ediff-get-session-buffer info))
1492 (session-number (ediff-get-session-number-at-pos pos meta-buf))
1493 merge-autostore-dir file1 file2 file3 regexp)
1495 (setq file1 (ediff-get-session-objA-name info)
1496 file2 (ediff-get-session-objB-name info)
1497 file3 (ediff-get-session-objC-name info))
1499 ;; make sure we don't start on hidden sessions
1500 ;; ?H means marked for hiding. ?I means invalid (hidden).
1501 (if (memq (ediff-get-session-status info) '(?I))
1504 (if (y-or-n-p "This session is marked as hidden, unmark? ")
1506 (ediff-set-session-status info nil)
1507 (ediff-update-meta-buffer meta-buf nil session-number))
1508 (error "Aborted"))))
1510 (ediff-with-current-buffer meta-buf
1511 (setq merge-autostore-dir
1512 (ediff-get-group-merge-autostore-dir ediff-meta-list))
1513 (goto-char pos) ; if the user clicked on session--move point there
1514 ;; First handle sessions involving directories (which are themselves
1516 ;; After that handle individual sessions
1517 (cond ((ediff-meta-session-p info)
1518 ;; do ediff/ediff-merge on subdirectories
1519 (if (ediff-buffer-live-p session-buf)
1520 (ediff-show-meta-buffer session-buf)
1521 (setq regexp (read-string "Filter through regular expression: "
1522 nil 'ediff-filtering-regexp-history))
1523 (ediff-directories-internal
1524 file1 file2 file3 regexp
1525 ediff-session-action-function
1527 ;; make it update (car info) after startup
1529 ;; child session group should know its parent
1530 (setq ediff-parent-meta-buffer
1531 (quote ,ediff-meta-buffer)
1532 ediff-meta-session-number
1534 ;; and parent will know its child
1535 (setcar (quote ,info) ediff-meta-buffer))))))
1537 ;; Do ediff-revision on a subdirectory
1538 ((and (ediff-one-filegroup-metajob)
1539 (ediff-revision-metajob)
1540 (file-directory-p file1))
1541 (if (ediff-buffer-live-p session-buf)
1542 (ediff-show-meta-buffer session-buf)
1543 (setq regexp (read-string "Filter through regular expression: "
1544 nil 'ediff-filtering-regexp-history))
1545 (ediff-directory-revisions-internal
1547 ediff-session-action-function ediff-metajob-name
1548 ;; make it update (car info) after startup
1550 ;; child session group should know its parent and
1552 (setq ediff-parent-meta-buffer
1553 (quote ,ediff-meta-buffer)
1554 ediff-meta-session-number
1556 ;; and parent will know its child
1557 (setcar (quote ,info) ediff-meta-buffer))))))
1559 ;; From here on---only individual session handlers
1561 ;; handle an individual session with a live control buffer
1562 ((ediff-buffer-live-p session-buf)
1563 (ediff-with-current-buffer session-buf
1564 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1565 (ediff-recenter 'no-rehighlight)))
1567 ((ediff-problematic-session-p info)
1570 "This session has no ancestor. Merge without the ancestor? ")
1573 ;; provide startup hooks
1576 'ediff-after-quit-hook-internal
1578 (if (ediff-buffer-live-p ,(current-buffer))
1579 (ediff-show-meta-buffer
1580 ,(current-buffer) ,session-number)))
1582 (setq ediff-meta-buffer ,(current-buffer)
1583 ediff-meta-session-number
1585 (setq ediff-merge-store-file
1586 ,(if (ediff-nonempty-string-p
1587 merge-autostore-dir)
1590 ediff-merge-filename-prefix
1591 (file-name-nondirectory file1))
1593 ;; make ediff-startup pass
1594 ;; ediff-control-buffer back to the meta
1597 (quote ,info) ediff-control-buffer))))
1599 ((ediff-one-filegroup-metajob) ; needs 1 file arg
1600 (funcall ediff-session-action-function
1602 ;; provide startup hooks
1605 'ediff-after-quit-hook-internal
1607 (if (ediff-buffer-live-p
1609 (ediff-show-meta-buffer
1613 (setq ediff-meta-buffer ,(current-buffer)
1614 ediff-meta-session-number
1616 (setq ediff-merge-store-file
1617 ,(if (ediff-nonempty-string-p
1618 merge-autostore-dir)
1621 ediff-merge-filename-prefix
1622 (file-name-nondirectory file1))) )
1623 ;; make ediff-startup pass
1624 ;; ediff-control-buffer back to the meta
1627 (quote ,info) ediff-control-buffer)))))
1628 ((not (ediff-metajob3)) ; need 2 file args
1629 (funcall ediff-session-action-function
1631 ;; provide startup hooks
1634 'ediff-after-quit-hook-internal
1636 (if (ediff-buffer-live-p
1638 (ediff-show-meta-buffer
1642 (setq ediff-meta-buffer ,(current-buffer)
1643 ediff-meta-session-number
1645 (setq ediff-merge-store-file
1646 ,(if (ediff-nonempty-string-p
1647 merge-autostore-dir)
1650 ediff-merge-filename-prefix
1651 (file-name-nondirectory file1))) )
1652 ;; make ediff-startup pass
1653 ;; ediff-control-buffer back to the meta
1656 (quote ,info) ediff-control-buffer)))))
1657 ((ediff-metajob3) ; need 3 file args
1658 (funcall ediff-session-action-function
1660 ;; arrange startup hooks
1663 'ediff-after-quit-hook-internal
1665 (if (ediff-buffer-live-p
1667 (ediff-show-meta-buffer
1671 (setq ediff-merge-store-file
1672 ,(if (ediff-nonempty-string-p
1673 merge-autostore-dir)
1676 ediff-merge-filename-prefix
1677 (file-name-nondirectory file1))) )
1678 (setq ediff-meta-buffer , (current-buffer)
1679 ediff-meta-session-number
1681 ;; this arranges that ediff-startup will pass
1682 ;; the value of ediff-control-buffer back to
1683 ;; the meta level, to the record in the meta
1684 ;; list containing the information about the
1685 ;; session associated with that
1686 ;; ediff-control-buffer
1688 (quote ,info) ediff-control-buffer)))))
1690 ) ; eval in meta-buf
1693 (defun ediff-registry-action ()
1694 "Switch to a selected session."
1696 (let* ((pos (ediff-event-point last-command-event))
1697 (buf (ediff-event-buffer last-command-event))
1698 (ctl-buf (ediff-get-meta-info buf pos)))
1700 (if (ediff-buffer-live-p ctl-buf)
1701 ;; check if this is ediff-control-buffer or ediff-meta-buffer
1702 (if (ediff-with-current-buffer ctl-buf
1703 (eq (key-binding "q") 'ediff-quit-meta-buffer))
1704 ;; it's a meta-buffer -- last action should just display it
1705 (ediff-show-meta-buffer ctl-buf t)
1706 ;; it's a session buffer -- invoke go back to session
1707 (ediff-with-current-buffer ctl-buf
1708 (setq ediff-mouse-pixel-position (mouse-pixel-position))
1709 (ediff-recenter 'no-rehighlight)))
1711 (message "You've selected a stale session --- try again")
1712 (ediff-update-registry))
1713 (ediff-with-current-buffer buf
1718 ;; If session number is t, means don't update meta buffer
1719 (defun ediff-show-meta-buffer (&optional meta-buf session-number)
1720 "Show the session group buffer."
1722 (let (wind frame silent)
1723 (if meta-buf (setq silent t))
1725 (setq meta-buf (or meta-buf ediff-meta-buffer))
1726 (cond ((not (bufferp meta-buf))
1727 (error "This Ediff session is not part of a session group"))
1728 ((not (ediff-buffer-live-p meta-buf))
1730 "Can't find this session's group panel -- session itself is ok")))
1732 (cond ((numberp session-number)
1733 (ediff-update-meta-buffer meta-buf nil session-number))
1734 ;; if session-number is t, don't update
1736 (t (ediff-cleanup-meta-buffer meta-buf)))
1738 (ediff-with-current-buffer meta-buf
1740 (cond ((setq wind (ediff-get-visible-buffer-window meta-buf))
1743 "Already showing the group panel for this session"))
1744 (set-window-buffer wind meta-buf)
1745 (select-window wind))
1746 ((window-live-p (setq wind ediff-window-C)) ;in merge--merge buf
1747 (set-window-buffer ediff-window-C meta-buf)
1748 (select-window wind))
1749 ((window-live-p (setq wind ediff-window-A))
1750 (set-window-buffer ediff-window-A meta-buf)
1751 (select-window wind))
1752 ((window-live-p (setq wind ediff-window-B))
1753 (set-window-buffer ediff-window-B meta-buf)
1754 (select-window wind))
1757 (ediff-get-visible-buffer-window ediff-registry-buffer))
1758 (ediff-window-display-p))
1759 (select-window wind)
1761 (set-window-buffer (selected-window) meta-buf))
1762 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1763 (set-window-buffer (selected-window) meta-buf)))
1765 (if (and (ediff-window-display-p)
1767 (setq wind (ediff-get-visible-buffer-window meta-buf))))
1769 (setq frame (window-frame wind))
1771 (ediff-reset-mouse frame)))
1772 (run-hooks 'ediff-show-session-group-hook)
1775 (defun ediff-show-current-session-meta-buffer ()
1777 (ediff-show-meta-buffer nil ediff-meta-session-number))
1779 (defun ediff-show-meta-buff-from-registry ()
1780 "Display the session group buffer for a selected session group."
1782 (let* ((pos (ediff-event-point last-command-event))
1783 (meta-buf (ediff-event-buffer last-command-event))
1784 (info (ediff-get-meta-info meta-buf pos))
1785 (meta-or-session-buf info))
1786 (ediff-with-current-buffer meta-or-session-buf
1787 (ediff-show-meta-buffer nil t))))
1790 (defun ediff-show-registry ()
1791 "Display Ediff's registry."
1793 (ediff-update-registry)
1794 (if (not (ediff-buffer-live-p ediff-registry-buffer))
1795 (error "No active Ediff sessions or corrupted session registry"))
1797 ;; for some reason, point moves in ediff-registry-buffer, so we preserve it
1799 (ediff-with-current-buffer ediff-registry-buffer
1802 (ediff-get-visible-buffer-window ediff-registry-buffer))
1803 (message "Already showing the registry")
1804 (set-window-buffer wind ediff-registry-buffer)
1805 (select-window wind))
1806 ((window-live-p ediff-window-C)
1807 (set-window-buffer ediff-window-C ediff-registry-buffer)
1808 (select-window ediff-window-C))
1809 ((window-live-p ediff-window-A)
1810 (set-window-buffer ediff-window-A ediff-registry-buffer)
1811 (select-window ediff-window-A))
1812 ((window-live-p ediff-window-B)
1813 (set-window-buffer ediff-window-B ediff-registry-buffer)
1814 (select-window ediff-window-B))
1816 (ediff-get-visible-buffer-window ediff-meta-buffer))
1817 (ediff-window-display-p))
1818 (select-window wind)
1820 (set-window-buffer (selected-window) ediff-registry-buffer))
1821 (t (ediff-skip-unsuitable-frames 'ok-unsplittable)
1822 (set-window-buffer (selected-window) ediff-registry-buffer)))
1824 (if (ediff-window-display-p)
1828 (ediff-get-visible-buffer-window ediff-registry-buffer)))
1830 (ediff-reset-mouse frame)))
1831 (run-hooks 'ediff-show-registry-hook)
1835 (defalias 'eregistry 'ediff-show-registry)
1837 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a
1839 ;; Check if META-BUF exists before calling this function
1840 ;; Optional MUST-REDRAW, if non-nil, would force redrawal of the whole meta
1841 ;; buffer. Otherwise, it will just go over the buffer and update activity marks
1842 ;; and session status.
1843 ;; SESSION-NUMBER, if specified, says which session caused the update.
1844 (defun ediff-update-meta-buffer (meta-buf &optional must-redraw session-number)
1845 (if (ediff-buffer-live-p meta-buf)
1846 (ediff-with-current-buffer meta-buf
1848 (cond (must-redraw ; completely redraw the meta buffer
1849 (funcall ediff-meta-redraw-function ediff-meta-list))
1850 ((numberp session-number) ; redraw only for the given session
1851 (ediff-update-session-marker-in-dir-meta-buffer
1853 (t ; update what changed only, but scan the entire meta buffer
1854 (ediff-update-markers-in-dir-meta-buffer ediff-meta-list)))
1855 (setq overl (ediff-get-meta-overlay-at-pos (point)))
1856 ;; skip the invisible sessions
1857 (while (and overl (ediff-overlay-get overl 'invisible))
1858 (ediff-next-meta-item1)
1859 (setq overl (ediff-get-meta-overlay-at-pos (point))))
1862 (defun ediff-update-registry ()
1863 (ediff-with-current-buffer (current-buffer)
1864 (if (ediff-buffer-live-p ediff-registry-buffer)
1865 (ediff-redraw-registry-buffer)
1866 (ediff-prepare-meta-buffer
1867 'ediff-registry-action
1868 ediff-session-registry
1870 'ediff-redraw-registry-buffer
1874 ;; If meta-buf exists, it is redrawn along with parent.
1875 ;; Otherwise, nothing happens.
1876 (defun ediff-cleanup-meta-buffer (meta-buffer)
1877 (if (ediff-buffer-live-p meta-buffer)
1878 (ediff-with-current-buffer meta-buffer
1879 (ediff-update-meta-buffer meta-buffer)
1880 (if (ediff-buffer-live-p ediff-parent-meta-buffer)
1881 (ediff-update-meta-buffer
1882 ediff-parent-meta-buffer nil ediff-meta-session-number)))))
1884 ;; t if no session is in progress
1885 (defun ediff-safe-to-quit (meta-buffer)
1886 (if (ediff-buffer-live-p meta-buffer)
1887 (let ((lis ediff-meta-list)
1890 ;;(ediff-update-meta-buffer meta-buffer)
1891 (ediff-with-current-buffer meta-buffer
1892 (setq lis (cdr lis)) ; discard the description part of meta-list
1893 (while (and cont lis)
1894 (if (ediff-buffer-live-p
1895 (ediff-get-group-buffer lis)) ; in progress
1897 (setq lis (cdr lis)))
1900 (defun ediff-quit-meta-buffer ()
1901 "If the group has no active session, delete the meta buffer.
1902 If no session is in progress, ask to confirm before deleting meta buffer.
1903 Otherwise, bury the meta buffer.
1904 If this is a session registry buffer then just bury it."
1906 (let* ((buf (current-buffer))
1907 (dir-diffs-buffer ediff-dir-diffs-buffer)
1908 (meta-diff-buffer ediff-meta-diff-buffer)
1909 (session-number ediff-meta-session-number)
1910 (parent-buf ediff-parent-meta-buffer)
1911 (dont-show-registry (eq buf ediff-registry-buffer)))
1912 (if dont-show-registry
1914 ;;(ediff-cleanup-meta-buffer buf)
1915 (cond ((and (ediff-safe-to-quit buf)
1916 (y-or-n-p "Quit this session group? "))
1917 (run-hooks 'ediff-quit-session-group-hook)
1919 (ediff-dispose-of-meta-buffer buf))
1920 ((ediff-safe-to-quit buf)
1924 "This session group has active sessions---cannot exit")))
1925 (ediff-update-meta-buffer parent-buf nil session-number)
1926 (ediff-kill-buffer-carefully dir-diffs-buffer)
1927 (ediff-kill-buffer-carefully meta-diff-buffer)
1928 (if (ediff-buffer-live-p parent-buf)
1930 (setq dont-show-registry t)
1931 (ediff-show-meta-buffer parent-buf session-number)))
1933 (or dont-show-registry
1934 (ediff-show-registry))))
1936 (defun ediff-dispose-of-meta-buffer (buf)
1937 (setq ediff-session-registry (delq buf ediff-session-registry))
1938 (ediff-with-current-buffer buf
1939 (if (ediff-buffer-live-p ediff-dir-diffs-buffer)
1940 (kill-buffer ediff-dir-diffs-buffer)))
1944 ;; Obtain information on a meta record where the user clicked or typed
1945 ;; BUF is the buffer where this happened and POINT is the position
1946 ;; If optional NOERROR arg is given, don't report error and return nil if no
1947 ;; meta info is found on line.
1948 (defun ediff-get-meta-info (buf point &optional noerror)
1949 (let (result olist tmp)
1950 (if (and point (ediff-buffer-live-p buf))
1951 (ediff-with-current-buffer buf
1954 (if (setq tmp (extent-at point buf 'ediff-meta-info))
1955 (ediff-overlay-get tmp 'ediff-meta-info)))
1956 (setq olist (overlays-at point))
1958 (mapcar (lambda (elt) (overlay-get elt 'ediff-meta-info))
1960 (while (and olist (null (car olist))
1961 (overlay-get (car olist) 'invisible))
1962 (setq olist (cdr olist)))
1963 (setq result (car olist)))))
1968 (ediff-update-registry)
1969 (error "No session info in this line")))))
1972 (defun ediff-get-meta-overlay-at-pos (point)
1974 (extent-at point (current-buffer) 'ediff-meta-info)
1975 (let* ((overl-list (overlays-at point))
1976 (overl (car overl-list)))
1977 (while (and overl (null (overlay-get overl 'ediff-meta-info)))
1978 (setq overl-list (cdr overl-list)
1979 overl (car overl-list)))
1982 (defsubst ediff-get-session-number-at-pos (point &optional meta-buffer)
1983 (setq meta-buffer (if (ediff-buffer-live-p meta-buffer)
1986 (ediff-with-current-buffer meta-buffer
1988 (ediff-get-meta-overlay-at-pos point) 'ediff-meta-session-number)))
1991 ;; Return location of the next meta overlay after point
1992 (defun ediff-next-meta-overlay-start (point)
1994 (goto-char (point-min))
1995 (let ((overl (ediff-get-meta-overlay-at-pos point)))
1999 (setq overl (next-extent overl))
2000 (setq overl (next-extent (current-buffer))))
2002 (extent-start-position overl)
2005 ;; note: end of current overlay is the beginning of the next one
2007 (next-overlay-change point))))
2011 (defun ediff-previous-meta-overlay-start (point)
2013 (goto-char (point-max))
2014 (let ((overl (ediff-get-meta-overlay-at-pos point)))
2018 (setq overl (previous-extent overl))
2019 (setq overl (previous-extent (current-buffer))))
2021 (extent-start-position overl)
2023 (if overl (setq point (overlay-start overl)))
2024 ;; to get to the beginning of prev overlay
2026 ;; trick to overcome an emacs bug--doesn't always find previous
2027 ;; overlay change correctly
2028 (setq point (1- point)))
2029 (setq point (previous-overlay-change point))
2030 ;; If we are not over an overlay after subtracting 1, it means we are
2031 ;; in the description area preceding session records. In this case,
2032 ;; goto the top of the registry buffer.
2033 (or (car (overlays-at point))
2034 (setq point (point-min)))
2037 ;; this is the action invoked when the user selects a patch from the meta
2039 (defun ediff-patch-file-form-meta (file &optional startup-hooks)
2040 (let* ((pos (ediff-event-point last-command-event))
2041 (meta-buf (ediff-event-buffer last-command-event))
2042 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid
2043 (info (ediff-get-meta-info meta-buf pos))
2044 (meta-patchbuf ediff-meta-patchbufer)
2045 session-buf beg-marker end-marker)
2047 (if (or (file-directory-p file) (string-match "/dev/null" file))
2048 (error "`%s' is not an ordinary file" (file-name-as-directory file)))
2049 (setq session-buf (ediff-get-session-buffer info)
2050 beg-marker (ediff-get-session-objB-name info)
2051 end-marker (ediff-get-session-objC-name info))
2053 (or (ediff-buffer-live-p session-buf) ; either an active patch session
2054 (null session-buf) ; or it is a virgin session
2056 "Patch has been already applied to this file--cannot be repeated!"))
2058 (ediff-with-current-buffer meta-patchbuf
2061 (narrow-to-region beg-marker end-marker)
2062 (ediff-patch-file-internal meta-patchbuf file startup-hooks)))))
2065 (defun ediff-unmark-all-for-operation ()
2066 "Unmark all sessions marked for operation."
2068 (let ((list (cdr ediff-meta-list))
2070 (while (setq elt (car list))
2071 (ediff-mark-session-for-operation elt 'unmark)
2072 (setq list (cdr list))))
2073 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2075 (defun ediff-unmark-all-for-hiding ()
2076 "Unmark all sessions marked for hiding."
2078 (let ((list (cdr ediff-meta-list))
2080 (while (setq elt (car list))
2081 (ediff-mark-session-for-hiding elt 'unmark)
2082 (setq list (cdr list))))
2083 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2086 (defun ediff-meta-mark-equal-files ()
2087 "Run though the session list and mark identical files.
2088 This is used only for sessions that involve 2 or 3 files at the same time."
2090 (let ((list (cdr ediff-meta-list))
2091 marked1 marked2 marked3
2092 fileinfo1 fileinfo2 fileinfo3 elt)
2093 (message "Comparing files ...")
2094 (while (setq elt (car list))
2095 (setq fileinfo1 (ediff-get-session-objA elt)
2096 fileinfo2 (ediff-get-session-objB elt)
2097 fileinfo3 (ediff-get-session-objC elt))
2098 (ediff-set-file-eqstatus fileinfo1 nil)
2099 (ediff-set-file-eqstatus fileinfo2 nil)
2100 (ediff-set-file-eqstatus fileinfo3 nil)
2105 (or (ediff-mark-if-equal fileinfo1 fileinfo2)
2107 (if (ediff-metajob3)
2109 (or (ediff-mark-if-equal fileinfo1 fileinfo3)
2111 (or (ediff-mark-if-equal fileinfo2 fileinfo3)
2112 (setq marked3 nil))))
2113 (if (and marked1 marked2 marked3)
2114 (cond ((eq last-command-char ?h)
2115 (ediff-mark-session-for-hiding elt 'mark))
2116 ((eq last-command-char ?m)
2117 (ediff-mark-session-for-operation elt 'mark))
2119 (setq list (cdr list)))
2120 (message "Comparing files ... Done"))
2121 (ediff-update-meta-buffer (current-buffer) 'must-redraw))
2123 ;; mark files 1 and 2 as equal, if they are.
2124 ;; returns t, if something was marked
2125 (defun ediff-mark-if-equal (fileinfo1 fileinfo2)
2126 (let ((f1 (car fileinfo1))
2127 (f2 (car fileinfo2)))
2128 (cond ((file-directory-p f1) nil)
2129 ((file-directory-p f2) nil)
2130 ((ediff-same-file-contents f1 f2)
2131 (ediff-set-file-eqstatus fileinfo1 t)
2132 (ediff-set-file-eqstatus fileinfo2 t)
2138 ;;; Local Variables:
2139 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
2140 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
2141 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
2144 ;;; ediff-mult.el ends here