Mercurial > emacs
annotate lisp/ediff-mult.el @ 14417:2b2e0cef30d5
(cpp-parse-error): Fix error format string.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Mon, 29 Jan 1996 23:11:17 +0000 |
parents | 83f275dcd93a |
children | c768f6d7daaa |
rev | line source |
---|---|
13607
71a4a349d998
Renamed from ediff-meta.el. Changed provide.
Richard M. Stallman <rms@gnu.org>
parents:
13216
diff
changeset
|
1 ;;; ediff-mult.el --- support for multi-file/multi-buffer processing in Ediff |
14169 | 2 |
3 ;; Copyright (C) 1995 Free Software Foundation, Inc. | |
13130 | 4 |
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu> | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
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. | |
13 | |
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. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
14169 | 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. | |
13130 | 23 |
14169 | 24 ;;; Commentary: |
25 | |
13130 | 26 ;; Users are strongly encourage to add functionality to this file. |
27 ;; In particular, epatch needs to be enhanced to work with multi-file | |
28 ;; patches. The present file contains all the infrastructure needed for that. | |
29 ;; | |
30 ;; Generally, to to implement a new multisession capability within Ediff, | |
31 ;; you need to tell it | |
32 ;; | |
33 ;; 1. How to display the session group buffer. | |
34 ;; This function must indicate which Ediff sessions are active (+) and | |
35 ;; which are finished (-). | |
36 ;; See ediff-redraw-directory-group-buffer for an example. | |
37 ;; In all likelihood, ediff-redraw-directory-group-buffer can be used | |
38 ;; directly or after a small modification. | |
39 ;; 2. What action to take when the user clicks button 2 or types v,e, or | |
40 ;; RET. See ediff-dir-action. | |
41 ;; 3. Provide a list of pairs or triples of file names (or buffers, | |
42 ;; depending on the particular Ediff operation you want to invoke) | |
43 ;; in the following format: | |
44 ;; ((obj1 obj2 [optional obj3]) (...) ...) | |
45 ;; Actually, the format of this list is pretty much up to the | |
46 ;; developer. The only thing is that it must be a list of lists. | |
47 ;; Also, keep in mind that the function ediff-prepare-meta-buffer | |
14040 | 48 ;; (which see) prepends nil in front of each list (i.e., the above list |
13130 | 49 ;; will become ((nil obj1 obj2 ...) (nil ...) ...). |
50 ;; Ediff expects that your function (in 2 above) will arrange to | |
51 ;; replace this prepended nil (via setcar) with the actual ediff | |
52 ;; control buffer associated with an appropriate Ediff session. | |
53 ;; This is arranged through internal startup hooks that can be passed | |
54 ;; to any of Ediff major entries (such as ediff-files, epatch, etc.). | |
55 ;; See how this is done in ediff-dir-action. | |
56 ;; 4. Write a function that makes a call to ediff-prepare-meta-buffer | |
57 ;; passing all this info. | |
58 ;; You may be able to use ediff-directories-internal as a template. | |
59 ;; 5. If you intend to add several related pieces of functionality, | |
60 ;; you may want to keep the function in 4 as an internal version | |
61 ;; and then write several top-level interactive functions that call it | |
62 ;; with different parameters. | |
63 ;; See how ediff-directories, ediff-merge-directories, and | |
64 ;; ediff-merge-directories-with-ancestor all use | |
65 ;; ediff-directories-internal. | |
66 ;; | |
67 ;; In case of multifile patching, the easiest thing is to first apply the patch | |
68 ;; and then find out which files were patched (using the algorithm utilized by | |
69 ;; Unix patch and by parsing the patch file). The procedure ediff-patch-file | |
70 ;; works for single-file patches only. However, it can deal with remote and | |
71 ;; compressed files. Check out ediff-patch-file for details. | |
72 ;; | |
73 ;; Another useful addition here could be session groups selected by patterns | |
74 ;; (which are different in each directory). For instance, one may want to | |
75 ;; compare files of the form abc{something}.c to files old{something}.d | |
76 ;; which may be in the same or different directories. Or, one may want to | |
77 ;; compare all files of the form {something} to files of the form {something}~. | |
78 ;; | |
13216
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13130
diff
changeset
|
79 ;; Implementing this requires writing an collating function, which should pair |
b9dc8cc658d5
Moved defsubsts up.
Michael Kifer <kifer@cs.stonybrook.edu>
parents:
13130
diff
changeset
|
80 ;; up appropriate files. It will also require a generalization of the functions |
13130 | 81 ;; that do the layout of the meta- and differences buffers and of |
82 ;; ediff-dir-action. | |
83 | |
14169 | 84 ;;; Code: |
85 | |
13130 | 86 (require 'ediff-init) |
87 | |
88 ;; meta-buffer | |
89 (ediff-defvar-local ediff-meta-buffer nil "") | |
90 (ediff-defvar-local ediff-parent-meta-buffer nil "") | |
91 ;; the registry buffer | |
92 (defvar ediff-registry-buffer nil) | |
93 | |
94 (defconst ediff-meta-buffer-message "This is an Ediff Session Group Panel: %s | |
95 | |
96 Useful commands: | |
97 button2, `v', RET over a session line: start that Ediff session | |
98 `M' in any session invoked from here: bring back this buffer | |
99 `R':\tdisplay the registry of active Ediff sessions | |
100 `h':\tmark session for hiding; with prefix arg--unmark | |
101 `x':\thide marked sessions; with prefix arg--unhide hidden sessions | |
102 `m':\tmark session for non-hiding operation; with prefix arg--unmark | |
103 SPC:\tnext session | |
104 DEL:\tprevious session | |
105 `E':\tbrowse Ediff on-line manual | |
106 `q':\tquit this session group | |
107 ") | |
108 | |
109 (ediff-defvar-local ediff-meta-buffer-map nil | |
110 "The keymap for the meta buffer.") | |
111 (defvar ediff-dir-diffs-buffer-map (make-sparse-keymap) | |
112 "The keymap to be installed in the buffer showing differences between | |
113 directories.") | |
114 | |
115 ;; Variable specifying the action to take when the use invokes ediff in the | |
116 ;; meta buffer. This is usually ediff-registry-action or ediff-dir-action | |
117 (ediff-defvar-local ediff-meta-action-function nil "") | |
118 ;; Tells ediff-update-meta-buffer how to redraw it | |
119 (ediff-defvar-local ediff-meta-redraw-function nil "") | |
120 ;; Tells ediff-dir-action and similar procedures how to invoke Ediff for the | |
121 ;; sessions in a given session group | |
122 (ediff-defvar-local ediff-session-action-function nil "") | |
123 | |
124 (ediff-defvar-local ediff-metajob-name nil "") | |
125 | |
126 ;; buffer used to collect custom diffs from individual sessions in the group | |
127 (ediff-defvar-local ediff-meta-diff-buffer nil "") | |
128 | |
129 ;; history var to use for filtering groups | |
130 (defvar ediff-filtering-regexp-history nil "") | |
131 | |
132 ;; This has the form ((ctl-buf file1 file2) (stl-buf file1 file2) ...) | |
133 ;; If ctl-buf is nil, the file-pare wasn't processed yet. If it is | |
134 ;; killed-buffer object, the file pair has been processed. If it is a live | |
135 ;; buffer, this means ediff is still working on the pair | |
136 (ediff-defvar-local ediff-meta-list nil "") | |
137 | |
138 | |
139 ;; the difference list between directories in a directory session group | |
140 (ediff-defvar-local ediff-dir-difference-list nil "") | |
141 (ediff-defvar-local ediff-dir-diffs-buffer nil "") | |
142 | |
143 ;; The registry of Ediff sessions. A list of control buffers. | |
144 (defvar ediff-session-registry nil) | |
145 | |
146 (defvar ediff-registry-setup-hook nil | |
147 "*Hooks run just after the registry control panel is set up.") | |
148 (defvar ediff-session-group-setup-hook nil | |
149 "*Hooks run just after a meta-buffer controlling a session group, such as | |
150 ediff-directories, is run.") | |
151 (defvar ediff-show-registry-hook nil | |
152 "*Hooks run just after the registry buffer is shown.") | |
153 (defvar ediff-show-session-group-hook nil | |
154 "*Hooks run just after a session group buffer is shown.") | |
155 | |
156 ;;; API | |
157 | |
158 (defun ediff-get-group-buffer (meta-list) | |
159 (nth 0 (car meta-list))) | |
160 (defun ediff-get-group-regexp (meta-list) | |
161 (nth 1 (car meta-list))) | |
162 (defun ediff-get-group-objA (meta-list) | |
163 (nth 2 (car meta-list))) | |
164 (defun ediff-get-group-objB (meta-list) | |
165 (nth 3 (car meta-list))) | |
166 (defun ediff-get-group-objC (meta-list) | |
167 (nth 4 (car meta-list))) | |
168 (defun ediff-get-session-buffer (elt) | |
169 (nth 0 elt)) | |
170 (defun ediff-get-session-status (elt) | |
171 (nth 1 elt)) | |
172 (defun ediff-get-session-objA (elt) | |
173 (nth 2 elt)) | |
174 (defun ediff-get-session-objB (elt) | |
175 (nth 3 elt)) | |
176 (defun ediff-get-session-objC (elt) | |
177 (nth 4 elt)) | |
178 (defun ediff-set-session-status (session-info new-status) | |
179 (setcar (cdr session-info) new-status)) | |
180 | |
181 ;; set up the keymap in the meta buffer | |
182 (defun ediff-setup-meta-map() | |
183 (setq ediff-meta-buffer-map (make-sparse-keymap)) | |
184 (suppress-keymap ediff-meta-buffer-map) | |
185 (define-key ediff-meta-buffer-map "q" 'ediff-quit-meta-buffer) | |
186 (define-key ediff-meta-buffer-map "R" 'ediff-show-registry) | |
187 (define-key ediff-meta-buffer-map "E" 'ediff-documentation) | |
188 (define-key ediff-meta-buffer-map "v" ediff-meta-action-function) | |
189 (define-key ediff-meta-buffer-map "\C-m" ediff-meta-action-function) | |
190 (define-key ediff-meta-buffer-map " " 'ediff-next-meta-item) | |
191 (define-key ediff-meta-buffer-map "\C-?" 'ediff-previous-meta-item) | |
192 (define-key ediff-meta-buffer-map [delete] 'ediff-previous-meta-item) | |
193 (define-key ediff-meta-buffer-map [backspace] 'ediff-previous-meta-item) | |
194 (if ediff-no-emacs-help-in-control-buffer | |
195 (define-key ediff-meta-buffer-map "\C-h" 'ediff-previous-meta-item)) | |
196 (if ediff-emacs-p | |
197 (define-key ediff-meta-buffer-map [mouse-2] ediff-meta-action-function) | |
198 (define-key ediff-meta-buffer-map [button2] ediff-meta-action-function)) | |
199 | |
200 (use-local-map ediff-meta-buffer-map)) | |
201 | |
202 (defun ediff-meta-mode () | |
203 "This mode controls all operations on Ediff session groups. | |
204 It is entered through one of the following commands: | |
205 `ediff-directories' | |
206 `edirs' | |
207 `ediff-directories3' | |
208 `edirs3' | |
209 `ediff-merge-directories' | |
210 `edirs-merge' | |
211 `ediff-merge-directories-with-ancestor' | |
212 `edirs-merge-with-ancestor' | |
213 `ediff-directory-revisions' | |
214 `edir-revisions' | |
215 `ediff-merge-directory-revisions' | |
216 `edir-merge-revisions' | |
217 `ediff-merge-directory-revisions-with-ancestor' | |
218 `edir-merge-revisions-with-ancestor' | |
219 | |
220 Commands: | |
221 \\{ediff-meta-buffer-map}" | |
222 (kill-all-local-variables) | |
223 (setq major-mode 'ediff-meta-mode) | |
224 (setq mode-name "MetaEdiff")) | |
225 | |
226 | |
227 ;; the keymap for the buffer showing directory differences | |
228 (suppress-keymap ediff-dir-diffs-buffer-map) | |
229 (define-key ediff-dir-diffs-buffer-map "q" 'ediff-bury-dir-diffs-buffer) | |
230 (define-key ediff-dir-diffs-buffer-map " " 'next-line) | |
231 (define-key ediff-dir-diffs-buffer-map "\C-?" 'previous-line) | |
232 (define-key ediff-dir-diffs-buffer-map [delete] 'previous-line) | |
233 (define-key ediff-dir-diffs-buffer-map [backspace] 'previous-line) | |
234 | |
235 (defun ediff-next-meta-item (count) | |
236 "Move to the next item in Ediff registry or session group buffer. | |
237 Moves in circular fashion. With numeric prefix arg, skip this many items." | |
238 (interactive "p") | |
239 (or count (setq count 1)) | |
240 (while (< 0 count) | |
241 (setq count (1- count)) | |
242 (ediff-next-meta-item1))) | |
243 | |
244 ;; Move to the next meta item | |
245 (defun ediff-next-meta-item1 () | |
246 (let (pos) | |
247 (setq pos (ediff-next-meta-overlay-start (point))) | |
248 ;;; ;; skip deleted | |
249 ;;; (while (memq (ediff-get-session-status | |
250 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror)) | |
251 ;;; '(?H ?I)) | |
252 ;;; (setq pos (ediff-next-meta-overlay-start pos))) | |
253 | |
254 (if pos (goto-char pos)) | |
255 (if (eq ediff-metajob-name 'ediff-registry) | |
256 (if (search-forward "*Ediff" nil t) | |
257 (skip-chars-backward "a-zA-Z*")) | |
258 (if (> (skip-chars-forward "-+?H* \t0-9") 0) | |
259 (backward-char 1))))) | |
260 | |
261 | |
262 (defun ediff-previous-meta-item (count) | |
263 "Move to the previous item in Ediff registry or session group buffer. | |
264 Moves in circular fashion. With numeric prefix arg, skip this many items." | |
265 (interactive "p") | |
266 (or count (setq count 1)) | |
267 (while (< 0 count) | |
268 (setq count (1- count)) | |
269 (ediff-previous-meta-item1))) | |
270 | |
271 (defun ediff-previous-meta-item1 () | |
272 (let (pos) | |
273 (setq pos (ediff-previous-meta-overlay-start (point))) | |
274 ;;; ;; skip deleted | |
275 ;;; (while (ediff-get-session-status | |
276 ;;; (ediff-get-meta-info (current-buffer) pos 'noerror)) | |
277 ;;; (setq pos (ediff-previous-meta-overlay-start pos))) | |
278 | |
279 (if pos (goto-char pos)) | |
280 (if (eq ediff-metajob-name 'ediff-registry) | |
281 (if (search-forward "*Ediff" nil t) | |
282 (skip-chars-backward "a-zA-Z*")) | |
283 (if (> (skip-chars-forward "-+?H* \t0-9") 0) | |
284 (backward-char 1))))) | |
285 | |
286 | |
287 | |
288 ;; DIR1, DIR2, DIR3 are directories. | |
289 ;; REGEXP is a regexp used to filter | |
290 ;; files in the directories. | |
291 ;; If a file is a directory in dir1 but not dir2 (or vice versa), it is not | |
292 ;; included in the intersection. However, a regular file that is a dir in dir3 | |
293 ;; is included, since dir3 files are supposed to be ancestors for merging. | |
294 ;; Returns a list of the form: | |
295 ;; ((dir1 dir2 dir3) (f1 f2 f3) (f1 f2 f3) ...) | |
296 ;; dir3, f3 can be nil if intersecting only 2 directories. | |
297 ;; If COMPARISON-FUNC is given, use it. Otherwise, use string= | |
298 ;; DIFF-VAR is contains the name of the variable in which to return the | |
299 ;; difference list. The diff list is of the form: | |
300 ;; ((dir1 dir2 dir3) (file . num) (file . num)...) | |
301 ;; where num encodes the set of dirs where the file is found: | |
302 ;; 2 - only dir1; 3 - only dir2; 5 - only dir3; 6 - dir1&2; 10 - dir1&3; etc. | |
303 (defun ediff-intersect-directories (jobname diff-var regexp dir1 dir2 | |
304 &optional dir3 comparison-func) | |
305 (require 'cl) | |
306 (setq comparison-func (or comparison-func 'string=)) | |
307 (let (lis1 lis2 lis3 common auxdir1 auxdir2 auxdir3 difflist) | |
308 | |
309 (setq auxdir1 (file-name-as-directory dir1) | |
310 lis1 (directory-files auxdir1 nil regexp) | |
311 auxdir2 (file-name-as-directory dir2) | |
312 lis2 (directory-files auxdir2 nil regexp)) | |
313 | |
314 (if (stringp dir3) | |
315 (setq auxdir3 (file-name-as-directory dir3) | |
316 lis3 (directory-files auxdir3 nil regexp))) | |
317 | |
318 (setq lis1 (delete "." lis1) | |
319 lis1 (delete ".." lis1)) | |
320 | |
13637
0b081d93ee6c
(ediff-intersect-directories): Quote symbols starting with `:'.
Richard M. Stallman <rms@gnu.org>
parents:
13607
diff
changeset
|
321 (setq common (intersection lis1 lis2 ':test comparison-func)) |
13130 | 322 ;; get rid of files that are directories in dir1 but not dir2 |
323 (mapcar (function (lambda (elt) | |
324 (if (Xor (file-directory-p (concat auxdir1 elt)) | |
325 (file-directory-p (concat auxdir2 elt))) | |
326 (setq common (delq elt common))))) | |
327 common) | |
328 ;; intersect with the third dir | |
13637
0b081d93ee6c
(ediff-intersect-directories): Quote symbols starting with `:'.
Richard M. Stallman <rms@gnu.org>
parents:
13607
diff
changeset
|
329 (if lis3 (setq common (intersection common lis3 ':test comparison-func))) |
13130 | 330 (if (ediff-comparison-metajob3 jobname) |
331 (mapcar (function (lambda (elt) | |
332 (if (Xor (file-directory-p (concat auxdir1 elt)) | |
333 (file-directory-p (concat auxdir3 elt))) | |
334 (setq common (delq elt common))))) | |
335 common)) | |
336 | |
337 ;; trying to avoid side effects of sorting | |
338 (setq common (sort (copy-list common) 'string-lessp)) | |
339 | |
340 ;; compute difference list | |
341 (setq difflist (set-difference | |
13637
0b081d93ee6c
(ediff-intersect-directories): Quote symbols starting with `:'.
Richard M. Stallman <rms@gnu.org>
parents:
13607
diff
changeset
|
342 (union (union lis1 lis2 ':test comparison-func) |
13130 | 343 lis3 |
13637
0b081d93ee6c
(ediff-intersect-directories): Quote symbols starting with `:'.
Richard M. Stallman <rms@gnu.org>
parents:
13607
diff
changeset
|
344 ':test comparison-func) |
13130 | 345 common |
13637
0b081d93ee6c
(ediff-intersect-directories): Quote symbols starting with `:'.
Richard M. Stallman <rms@gnu.org>
parents:
13607
diff
changeset
|
346 ':test comparison-func) |
13130 | 347 difflist (delete "." difflist) |
348 ;; copy-list needed because sort sorts it by side effects | |
349 difflist (sort (copy-list (delete ".." difflist)) 'string-lessp)) | |
350 | |
351 (setq difflist (mapcar (function (lambda (elt) (cons elt 1))) difflist)) | |
352 | |
353 ;; check for files belonging to lis1/2/3 | |
354 (mapcar (function (lambda (elt) | |
355 (if (member (car elt) lis1) | |
356 (setcdr elt (* (cdr elt) 2))) | |
357 (if (member (car elt) lis2) | |
358 (setcdr elt (* (cdr elt) 3))) | |
359 (if (member (car elt) lis3) | |
360 (setcdr elt (* (cdr elt) 5))) | |
361 )) | |
362 difflist) | |
363 (setq difflist (cons (list regexp auxdir1 auxdir2 auxdir3) difflist)) | |
364 | |
365 (set diff-var difflist) | |
366 | |
367 ;; return result | |
368 (cons (list regexp auxdir1 auxdir2 auxdir3) | |
369 (mapcar (function (lambda (elt) | |
370 (list (concat auxdir1 elt) | |
371 (concat auxdir2 elt) | |
372 (if lis3 | |
373 (concat auxdir3 elt))))) | |
374 common)) | |
375 )) | |
376 | |
377 ;; find directory files that are under revision. | |
378 ;; display subdirectories, too, since we may visit them recursively. | |
379 (defun ediff-get-directory-files-under-revision (jobname regexp dir1) | |
380 (require 'cl) | |
381 (let (lis1 elt common auxdir1) | |
382 (setq auxdir1 (file-name-as-directory dir1) | |
383 lis1 (directory-files auxdir1 nil regexp)) | |
384 | |
385 (while lis1 | |
386 (setq elt (car lis1) | |
387 lis1 (cdr lis1)) | |
388 ;; take files under revision control | |
389 (cond ((file-directory-p (concat auxdir1 elt)) | |
390 (setq common (cons elt common))) | |
391 ((file-exists-p (concat auxdir1 elt ",v")) | |
392 (setq common (cons elt common)))) | |
393 ) ; while | |
394 | |
395 (setq common (delete "." common) | |
396 common (delete ".." common)) | |
397 | |
398 ;; trying to avoid side effects of sorting | |
399 (setq common (sort (copy-list common) 'string-lessp)) | |
400 | |
401 ;; return result | |
402 (cons (list regexp auxdir1 nil nil) | |
403 (mapcar (function (lambda (elt) | |
404 (list (concat auxdir1 elt) | |
405 nil nil))) | |
406 common)) | |
407 )) | |
408 | |
409 | |
410 ;; If file groups selected by patterns will ever be implemented, this | |
411 ;; comparison function might become useful. | |
412 ;;;; uses external variables PAT1 PAT2 to compare str1/2 | |
413 ;;;; patterns must be of the form ???*???? where ??? are strings of chars | |
414 ;;;; containing no *. | |
415 ;;(defun ediff-pattern= (str1 str2) | |
416 ;; (let (pos11 pos12 pos21 pos22 len1 len2) | |
417 ;; (setq pos11 0 | |
418 ;; len (length epat1) | |
419 ;; pos12 len) | |
420 ;; (while (and (< pos11 len) (not (= (aref epat1 pos11) ?*))) | |
421 ;; (setq pos11 (1+ pos11))) | |
422 ;; (while (and (> pos12 0) (not (= (aref epat1 (1- pos12)) ?*))) | |
423 ;; (setq pos12 (1- pos12))) | |
424 ;; | |
425 ;; (setq pos21 0 | |
426 ;; len (length epat2) | |
427 ;; pos22 len) | |
428 ;; (while (and (< pos21 len) (not (= (aref epat2 pos21) ?*))) | |
429 ;; (setq pos21 (1+ pos21))) | |
430 ;; (while (and (> pos22 0) (not (= (aref epat2 (1- pos22)) ?*))) | |
431 ;; (setq pos22 (1- pos22))) | |
432 ;; | |
433 ;; (if (and (> (length str1) pos12) (>= pos12 pos11) (> pos11 -1) | |
434 ;; (> (length str2) pos22) (>= pos22 pos21) (> pos21 -1)) | |
435 ;; (string= (substring str1 pos11 pos12) | |
436 ;; (substring str2 pos21 pos22))) | |
437 ;; )) | |
438 | |
439 | |
440 ;; Prepare meta-buffer in accordance with the argument-function and | |
441 ;; redraw-function. Must return the created meta-buffer. | |
442 (defun ediff-prepare-meta-buffer (action-func meta-list | |
443 meta-buffer-name redraw-function | |
444 jobname &optional startup-hooks) | |
445 (let* ((meta-buffer-name | |
446 (ediff-unique-buffer-name meta-buffer-name "*")) | |
447 (meta-buffer (get-buffer-create meta-buffer-name))) | |
448 (ediff-eval-in-buffer meta-buffer | |
449 | |
450 ;; comes first | |
451 (ediff-meta-mode) | |
452 | |
453 (setq ediff-meta-action-function action-func | |
454 ediff-meta-redraw-function redraw-function | |
455 ediff-metajob-name jobname | |
456 ediff-meta-buffer meta-buffer) | |
457 | |
458 ;; comes after ediff-meta-action-function is set | |
459 (ediff-setup-meta-map) | |
460 | |
461 (if (eq ediff-metajob-name 'ediff-registry) | |
462 (progn | |
463 (setq ediff-registry-buffer meta-buffer | |
464 ediff-meta-list meta-list) | |
465 ;; this func is used only from registry buffer, not from other | |
466 ;; meta-buffs. | |
467 (define-key | |
468 ediff-meta-buffer-map "M" 'ediff-show-meta-buff-from-registry)) | |
469 ;; initialize the meta list -- don't do this for registry we prepend | |
470 ;; '(nil nil) nil to all elts of meta-list, except the first. The | |
471 ;; first nil will later be replaced by the session buffer. The second | |
472 ;; is reserved for session status. | |
473 ;; (car ediff-meta-list) gets cons'ed with the session group buffer. | |
474 (setq ediff-meta-list | |
475 (cons (cons meta-buffer (car meta-list)) | |
476 (mapcar (function | |
477 (lambda (elt) | |
478 (cons nil (cons nil elt)))) | |
479 (cdr meta-list))))) | |
480 | |
481 (or (eq meta-buffer ediff-registry-buffer) | |
482 (setq ediff-session-registry | |
483 (cons meta-buffer ediff-session-registry))) | |
484 | |
485 ;; redraw-function uses ediff-meta-list | |
486 (funcall redraw-function ediff-meta-list) | |
487 | |
488 ;; set read-only/non-modified | |
489 (setq buffer-read-only t) | |
490 (set-buffer-modified-p nil) | |
491 | |
492 (run-hooks 'startup-hooks) | |
493 ;; arrange for showing directory contents differences | |
494 ;; must be after run startup-hooks, since ediff-dir-difference-list is | |
495 ;; set inside these hooks | |
496 (if (eq action-func 'ediff-dir-action) | |
497 (progn | |
498 ;; put meta buffer in (car ediff-dir-difference-list) | |
499 (setq ediff-dir-difference-list | |
500 (cons (cons meta-buffer (car ediff-dir-difference-list)) | |
501 (cdr ediff-dir-difference-list))) | |
502 | |
503 (or (ediff-dir1-metajob jobname) | |
504 (ediff-draw-dir-diffs ediff-dir-difference-list)) | |
505 (define-key ediff-meta-buffer-map "h" 'ediff-mark-for-hiding) | |
506 (define-key | |
507 ediff-meta-buffer-map "x" 'ediff-hide-marked-sessions) | |
508 (define-key ediff-meta-buffer-map "m" 'ediff-mark-for-operation) | |
509 (if (ediff-collect-diffs-metajob jobname) | |
510 (define-key | |
511 ediff-meta-buffer-map "P" 'ediff-collect-custom-diffs)) | |
512 (define-key ediff-meta-buffer-map "u" 'ediff-up-meta-hierarchy) | |
513 (define-key ediff-meta-buffer-map "D" 'ediff-show-dir-diffs))) | |
514 | |
515 (if (eq ediff-metajob-name 'ediff-registry) | |
516 (run-hooks 'ediff-registry-setup-hook) | |
517 (run-hooks 'ediff-session-group-setup-hook)) | |
518 ) ; eval in meta-buffer | |
519 meta-buffer)) | |
520 | |
521 | |
522 ;; this is a setup function for ediff-directories | |
523 ;; must return meta-buffer | |
524 (defun ediff-redraw-directory-group-buffer (meta-list) | |
525 ;; extract directories | |
526 (let ((meta-buf (ediff-get-group-buffer meta-list)) | |
527 (empty t) | |
528 (sessionNum 0) | |
529 regexp elt session-buf f1 f2 f3 pt | |
530 point tmp-list buffer-read-only) | |
531 (ediff-eval-in-buffer meta-buf | |
532 (setq point (point)) | |
533 (erase-buffer) | |
534 (insert (format ediff-meta-buffer-message | |
535 (ediff-abbrev-jobname ediff-metajob-name))) | |
536 | |
537 (setq regexp (ediff-get-group-regexp meta-list)) | |
538 | |
539 (if (ediff-collect-diffs-metajob) | |
540 (insert | |
541 " `P':\tcollect custom diffs of all marked sessions\n")) | |
542 (insert | |
543 " `u':\tshow parent session group | |
544 `D':\tdisplay differences among the contents of directories\n\n") | |
545 | |
546 (if (and (stringp regexp) (> (length regexp) 0)) | |
547 (insert (format "Filter-through regular expression: %s\n" regexp))) | |
548 | |
549 (insert "\n | |
550 Size Name | |
551 ----------------------------------------------------------------------- | |
552 | |
553 ") | |
554 | |
555 ;; discard info on directories and regexp | |
556 (setq meta-list (cdr meta-list) | |
557 tmp-list meta-list) | |
558 (while (and tmp-list empty) | |
559 (if (and (car tmp-list) | |
560 (not (eq (ediff-get-session-status (car tmp-list)) ?I))) | |
561 (setq empty nil)) | |
562 (setq tmp-list (cdr tmp-list))) | |
563 | |
564 (if empty | |
565 (insert | |
566 " ****** ****** This session group has no members\n")) | |
567 | |
568 ;; now organize file names like this: | |
569 ;; preferred format: | |
570 ;; use-mark sizeA dateA sizeB dateB filename | |
571 ;; I don't have time to mess up with calculating last modtimes | |
572 ;; (XEmacs has no decode-time function), so | |
573 ;; the actual format is: | |
574 ;; use-mark Size filename | |
575 ;; make sure directories are displayed with a trailing slash. | |
576 ;; If one is a directory and another isn't, indicate this with a `?' | |
577 (while meta-list | |
578 (setq elt (car meta-list) | |
579 meta-list (cdr meta-list) | |
580 sessionNum (1+ sessionNum)) | |
581 (if (eq (ediff-get-session-status elt) ?I) | |
582 () | |
583 (setq session-buf (ediff-get-session-buffer elt) | |
584 f1 (ediff-get-session-objA elt) | |
585 f2 (ediff-get-session-objB elt) | |
586 f3 (ediff-get-session-objC elt)) | |
587 (setq pt (point)) | |
588 ;; insert markers | |
589 (insert (cond ((null session-buf) " ") ; virgin session | |
590 ((ediff-buffer-live-p session-buf) "+") ;active session | |
591 (t "-"))) ; finished session | |
592 (insert (cond ((ediff-get-session-status elt)) ; session has status, | |
593 ;;; e.g., ?H, ?I | |
594 (t " "))) ; normal session | |
595 (insert " Session " (int-to-string sessionNum) ":\n") | |
596 (ediff-meta-insert-file-info f1) | |
597 (ediff-meta-insert-file-info f2) | |
598 (ediff-meta-insert-file-info f3) | |
599 (ediff-set-meta-overlay pt (point) elt))) | |
600 (set-buffer-modified-p nil) | |
601 (goto-char point) | |
602 meta-buf))) | |
603 | |
604 ;; Check if this is a problematic session. | |
605 ;; Return nil if not. Otherwise, return symbol representing the problem | |
606 ;; At present, problematic sessions occur only in -with-ancestor comparisons | |
607 ;; when the ancestor is a directory rather than a file. | |
608 (defun ediff-problematic-session-p (session) | |
609 (let ((f1 (ediff-get-session-objA session)) | |
610 (f2 (ediff-get-session-objB session)) | |
611 (f3 (ediff-get-session-objC session))) | |
612 (cond ((and (stringp f1) (not (file-directory-p f1)) | |
613 (stringp f2) (not (file-directory-p f2)) | |
614 (stringp f3) (file-directory-p f3) | |
615 (ediff-ancestor-metajob)) | |
616 ;; more may be added later | |
617 'ancestor-is-dir) | |
618 (t nil)))) | |
619 | |
620 (defun ediff-meta-insert-file-info (file) | |
621 (if (stringp file) | |
622 (insert | |
623 (format | |
624 " %10d %s\n" | |
625 (nth 7 (file-attributes file)) | |
626 ;; dir names in meta lists have no trailing `/' so insert it | |
627 (cond ((file-directory-p file) | |
628 (file-name-as-directory (ediff-abbreviate-file-name file))) | |
629 (t (ediff-abbreviate-file-name file))))) | |
630 )) | |
631 | |
632 | |
633 | |
634 (defun ediff-draw-dir-diffs (diff-list) | |
635 (if (null diff-list) (error "Lost difference info on these directories")) | |
636 (let* ((buf-name (ediff-unique-buffer-name | |
637 "*Ediff File Group Differences" "*")) | |
638 (regexp (ediff-get-group-regexp diff-list)) | |
639 (dir1 (ediff-abbreviate-file-name (ediff-get-group-objA diff-list))) | |
640 (dir2 (ediff-abbreviate-file-name (ediff-get-group-objB diff-list))) | |
641 (dir3 (ediff-get-group-objC diff-list)) | |
642 (dir3 (if (stringp dir3) (ediff-abbreviate-file-name dir3))) | |
643 (meta-buf (ediff-get-group-buffer diff-list)) | |
644 (underline (make-string 26 ?-)) | |
645 file code | |
646 buffer-read-only) | |
647 ;; skip the directory part | |
648 (setq diff-list (cdr diff-list)) | |
649 (setq ediff-dir-diffs-buffer (get-buffer-create buf-name)) | |
650 (ediff-eval-in-buffer ediff-dir-diffs-buffer | |
651 (use-local-map ediff-dir-diffs-buffer-map) | |
652 (erase-buffer) | |
653 (setq ediff-meta-buffer meta-buf) | |
654 (insert "\t\t*** Directory Differences ***\n") | |
655 (insert " | |
656 Useful commands: | |
657 `q': hide this buffer | |
658 SPC: next line | |
659 DEL: previous line\n\n") | |
660 | |
661 (if (and (stringp regexp) (> (length regexp) 0)) | |
662 (insert (format "Filter-through regular expression: %s\n" regexp))) | |
663 (insert "\n") | |
664 (insert (format "\n%-27s%-26s" | |
665 (ediff-truncate-string-left | |
666 (ediff-abbreviate-file-name | |
667 (file-name-as-directory dir1)) | |
668 25) | |
669 (ediff-truncate-string-left | |
670 (ediff-abbreviate-file-name | |
671 (file-name-as-directory dir2)) | |
672 25))) | |
673 (if dir3 | |
674 (insert (format " %-25s\n" | |
675 (ediff-truncate-string-left | |
676 (ediff-abbreviate-file-name | |
677 (file-name-as-directory dir3)) | |
678 25))) | |
679 (insert "\n")) | |
680 (insert (format "%s%s" underline underline)) | |
681 (if (stringp dir3) | |
682 (insert (format "%s\n\n" underline)) | |
683 (insert "\n\n")) | |
684 | |
685 (if (null diff-list) | |
686 (insert "\n\t*** No differences ***\n")) | |
687 | |
688 (while diff-list | |
689 (setq file (car (car diff-list)) | |
690 code (cdr (car diff-list)) | |
691 diff-list (cdr diff-list)) | |
692 (if (= (mod code 2) 0) ; dir1 | |
693 (insert (format "%-27s" | |
694 (ediff-truncate-string-left | |
695 (ediff-abbreviate-file-name | |
696 (if (file-directory-p (concat dir1 file)) | |
697 (file-name-as-directory file) | |
698 file)) | |
699 24))) | |
700 (insert (format "%-27s" "---"))) | |
701 (if (= (mod code 3) 0) ; dir2 | |
702 (insert (format "%-26s" | |
703 (ediff-truncate-string-left | |
704 (ediff-abbreviate-file-name | |
705 (if (file-directory-p (concat dir2 file)) | |
706 (file-name-as-directory file) | |
707 file)) | |
708 24))) | |
709 (insert (format "%-26s" "---"))) | |
710 (if (stringp dir3) | |
711 (if (= (mod code 5) 0) ; dir3 | |
712 (insert (format " %-25s" | |
713 (ediff-truncate-string-left | |
714 (ediff-abbreviate-file-name | |
715 (if (file-directory-p (concat dir3 file)) | |
716 (file-name-as-directory file) | |
717 file)) | |
718 24))) | |
719 (insert (format " %-25s" "---")))) | |
720 (insert "\n")) | |
721 (setq buffer-read-only t) | |
722 (set-buffer-modified-p nil)) ; eval in diff buffer | |
723 )) | |
724 | |
725 (defun ediff-bury-dir-diffs-buffer () | |
726 "Bury the directory difference buffer. Display the meta buffer instead." | |
727 (interactive) | |
728 (let ((buf ediff-meta-buffer) | |
729 wind) | |
730 (bury-buffer) | |
731 (if (setq wind (ediff-get-visible-buffer-window buf)) | |
732 (select-window wind) | |
733 (set-window-buffer (selected-window) buf)))) | |
734 | |
735 ;; executes in dir session group buffer | |
736 ;; show buffer differences | |
737 (defun ediff-show-dir-diffs () | |
738 "Display differences among the directories involved in session group." | |
739 (interactive) | |
740 (if (ediff-dir1-metajob) | |
741 (error "This command is inapplicable in the present context")) | |
742 (or (ediff-buffer-live-p ediff-dir-diffs-buffer) | |
743 (ediff-draw-dir-diffs ediff-dir-difference-list)) | |
744 (let ((buf ediff-dir-diffs-buffer)) | |
745 (other-window 1) | |
746 (set-window-buffer (selected-window) buf) | |
747 (goto-char (point-min)))) | |
748 | |
749 (defun ediff-up-meta-hierarchy () | |
750 "Go to the parent session group buffer." | |
751 (interactive) | |
752 (if (ediff-buffer-live-p ediff-parent-meta-buffer) | |
753 (ediff-show-meta-buffer ediff-parent-meta-buffer) | |
754 (error "This session group has no parent"))) | |
755 | |
756 | |
757 ;; argument is ignored | |
758 (defun ediff-redraw-registry-buffer (&optional ignore) | |
759 (ediff-eval-in-buffer ediff-registry-buffer | |
760 (let ((point (point)) | |
761 elt bufAname bufBname bufCname cur-diff total-diffs pt | |
762 job-name meta-list registry-list buffer-read-only) | |
763 (erase-buffer) | |
764 (insert "This is a registry of all active Ediff sessions. | |
765 | |
766 Useful commands: | |
767 button2, `v', RET over a session record: switch to that session | |
768 `M' over a session record: display the associated session group | |
769 `R' in any Ediff session: display session registry | |
770 SPC:\tnext session | |
771 DEL:\tprevious session | |
772 `E':\tbrowse Ediff on-line manual | |
773 `q':\tbury registry | |
774 | |
775 | |
776 \t\tActive Ediff Sessions: | |
777 \t\t---------------------- | |
778 | |
779 ") | |
780 ;; purge registry list from dead buffers | |
781 (mapcar (function (lambda (elt) | |
782 (if (not (ediff-buffer-live-p elt)) | |
783 (setq ediff-session-registry | |
784 (delq elt ediff-session-registry))))) | |
785 ediff-session-registry) | |
786 | |
787 (if (null ediff-session-registry) | |
788 (insert " ******* No active Ediff sessions *******\n")) | |
789 | |
790 (setq registry-list ediff-session-registry) | |
791 (while registry-list | |
792 (setq elt (car registry-list) | |
793 registry-list (cdr registry-list)) | |
794 | |
795 (if (ediff-buffer-live-p elt) | |
796 (if (ediff-eval-in-buffer elt | |
797 (setq job-name ediff-metajob-name | |
798 meta-list ediff-meta-list) | |
799 (and ediff-metajob-name | |
800 (not (eq ediff-metajob-name 'ediff-registry)))) | |
801 (progn | |
802 (setq pt (point)) | |
803 (insert (format " *group*\t%s: %s\n" | |
804 (buffer-name elt) | |
805 (ediff-abbrev-jobname job-name))) | |
806 (insert (format "\t\t %s %s %s\n" | |
807 (ediff-abbreviate-file-name | |
808 (ediff-get-group-objA meta-list)) | |
809 (ediff-abbreviate-file-name | |
810 (or (ediff-get-group-objB meta-list) "")) | |
811 (ediff-abbreviate-file-name | |
812 (or (ediff-get-group-objC meta-list) "")))) | |
813 (ediff-set-meta-overlay pt (point) elt)) | |
814 (progn | |
815 (ediff-eval-in-buffer elt | |
816 (setq bufAname (if (ediff-buffer-live-p ediff-buffer-A) | |
817 (buffer-name ediff-buffer-A) | |
818 "!!!killed buffer!!!") | |
819 bufBname (if (ediff-buffer-live-p ediff-buffer-B) | |
820 (buffer-name ediff-buffer-B) | |
821 "!!!killed buffer!!!") | |
822 bufCname (cond ((not (ediff-3way-job)) | |
823 "") | |
824 ((ediff-buffer-live-p ediff-buffer-C) | |
825 (buffer-name ediff-buffer-C)) | |
826 (t "!!!killed buffer!!!"))) | |
827 (setq total-diffs (format "%-4d" ediff-number-of-differences) | |
828 cur-diff | |
829 (cond ((= ediff-current-difference -1) " _") | |
830 ((= ediff-current-difference | |
831 ediff-number-of-differences) | |
832 " $") | |
833 (t (format | |
834 "%4d" (1+ ediff-current-difference)))) | |
835 job-name ediff-job-name)) | |
836 ;; back in the meta buf | |
837 (setq pt (point)) | |
838 (insert cur-diff "/" total-diffs "\t" | |
839 (buffer-name elt) | |
840 (format ": %s" (ediff-abbrev-jobname job-name))) | |
841 (insert | |
842 "\n\t\t " bufAname " " bufBname " " bufCname "\n") | |
843 (ediff-set-meta-overlay pt (point) elt)))) | |
844 ) ; while | |
845 (set-buffer-modified-p nil) | |
846 (goto-char point) | |
847 ))) | |
848 | |
849 ;; sets overlay around a meta record with 'ediff-meta-info property PROP | |
850 (defun ediff-set-meta-overlay (b e prop) | |
851 (let (overl) | |
852 (setq overl (ediff-make-overlay b e)) | |
853 (if ediff-emacs-p | |
854 (ediff-overlay-put overl 'mouse-face 'highlight) | |
855 (ediff-overlay-put overl 'highlight t)) | |
856 (ediff-overlay-put overl 'ediff-meta-info prop))) | |
857 | |
858 (defun ediff-mark-for-hiding (unmark) | |
859 "Mark session for hiding. With prefix arg, unmark." | |
860 (interactive "P") | |
861 (let* ((pos (ediff-event-point last-command-event)) | |
862 (meta-buf (ediff-event-buffer last-command-event)) | |
863 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid | |
864 (info (ediff-get-meta-info meta-buf pos)) | |
865 (session-buf (ediff-get-session-buffer info))) | |
866 | |
867 (if unmark | |
868 (ediff-set-session-status info nil) | |
869 (if (ediff-buffer-live-p session-buf) | |
870 (error "Can't hide active session, %s" (buffer-name session-buf))) | |
871 (ediff-set-session-status info ?H)) | |
872 (ediff-update-meta-buffer meta-buf) | |
873 )) | |
874 | |
875 (defun ediff-mark-for-operation (unmark) | |
876 "Mark session for a group operation. With prefix arg, unmark." | |
877 (interactive "P") | |
878 (let* ((pos (ediff-event-point last-command-event)) | |
879 (meta-buf (ediff-event-buffer last-command-event)) | |
880 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid | |
881 (info (ediff-get-meta-info meta-buf pos))) | |
882 | |
883 (if unmark | |
884 (ediff-set-session-status info nil) | |
885 (ediff-set-session-status info ?*)) | |
886 (ediff-update-meta-buffer meta-buf) | |
887 )) | |
888 | |
889 (defun ediff-hide-marked-sessions (unhide) | |
890 "Hide marked sessions. With prefix arg, unhide." | |
891 (interactive "P") | |
892 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list)) | |
893 (meta-list (cdr ediff-meta-list)) | |
894 (from (if unhide ?I ?H)) | |
895 (to (if unhide ?H ?I)) | |
896 (numMarked 0) | |
897 elt) | |
898 (while meta-list | |
899 (setq elt (car meta-list) | |
900 meta-list (cdr meta-list)) | |
901 (if (eq (ediff-get-session-status elt) from) | |
902 (progn | |
903 (setq numMarked (1+ numMarked)) | |
904 (ediff-set-session-status elt to)))) | |
905 (if (> numMarked 0) | |
906 (ediff-update-meta-buffer grp-buf) | |
907 (beep) | |
908 (if unhide | |
909 (message "Nothing to reveal...") | |
910 (message "Nothing to hide..."))) | |
911 )) | |
912 | |
913 ;; Apply OPERATION to marked sessions. Operation expects one argument of type | |
914 ;; meta-list member (not the first one), i.e., a regular session description. | |
915 ;; Returns number of marked sessions on which operation was performed | |
916 (defun ediff-operate-on-marked-sessions (operation) | |
917 (let ((grp-buf (ediff-get-group-buffer ediff-meta-list)) | |
918 (meta-list (cdr ediff-meta-list)) | |
919 (marksym ?*) | |
920 (numMarked 0) | |
921 (sessionNum 0) | |
922 elt) | |
923 (while meta-list | |
924 (setq elt (car meta-list) | |
925 meta-list (cdr meta-list) | |
926 sessionNum (1+ sessionNum)) | |
927 (if (eq (ediff-get-session-status elt) marksym) | |
928 (save-excursion | |
929 (setq numMarked (1+ numMarked)) | |
930 (funcall operation elt sessionNum)))) | |
931 (ediff-update-meta-buffer grp-buf) ; just in case | |
932 numMarked | |
933 )) | |
934 | |
935 (defun ediff-append-custom-diff (session sessionNum) | |
936 (or (ediff-collect-diffs-metajob) | |
937 (error "Sorry, I don't do this for everyone...")) | |
938 (let ((session-buf (ediff-get-session-buffer session)) | |
939 (meta-diff-buff ediff-meta-diff-buffer) | |
940 (metajob ediff-metajob-name) | |
941 tmp-buf custom-diff-buf) | |
942 (if (ediff-buffer-live-p session-buf) | |
943 (ediff-eval-in-buffer session-buf | |
944 (if (eq ediff-control-buffer session-buf) ; individual session | |
945 (setq custom-diff-buf ediff-custom-diff-buffer)))) | |
946 | |
947 (or (ediff-buffer-live-p meta-diff-buff) | |
948 (error "Ediff: something wrong--no multiple diffs buffer")) | |
949 | |
950 (cond ((ediff-buffer-live-p custom-diff-buf) | |
951 (save-excursion | |
952 (set-buffer meta-diff-buff) | |
953 (goto-char (point-max)) | |
954 (insert-buffer custom-diff-buf) | |
955 (insert "\n"))) | |
956 ((eq metajob 'ediff-directories) | |
957 ;; get diffs by calling shell command on ediff-custom-diff-program | |
958 (save-excursion | |
959 (set-buffer (setq tmp-buf (get-buffer-create ediff-tmp-buffer))) | |
960 (erase-buffer) | |
961 (shell-command | |
962 (format "%s %s %s %s" | |
963 ediff-custom-diff-program ediff-custom-diff-options | |
964 (ediff-get-session-objA session) | |
965 (ediff-get-session-objB session)) | |
966 t)) | |
967 (save-excursion | |
968 (set-buffer meta-diff-buff) | |
969 (goto-char (point-max)) | |
970 (insert-buffer tmp-buf) | |
971 (insert "\n"))) | |
972 (t | |
973 (error | |
974 "Session %d is marked but inactive--can't make its diff" | |
975 sessionNum))) | |
976 )) | |
977 | |
978 (defun ediff-collect-custom-diffs () | |
979 "Collect custom diffs of marked sessions in buffer `*Ediff Multifile Diffs*'. | |
980 This operation is defined only for `ediff-directories' and | |
981 `ediff-directory-revisions', since its intent is to produce | |
982 multifile patches. For `ediff-directory-revisions', we insist that | |
983 all marked sessions must be active." | |
984 (interactive) | |
985 (or (ediff-buffer-live-p ediff-meta-diff-buffer) | |
986 (setq ediff-meta-diff-buffer | |
987 (get-buffer-create | |
988 (ediff-unique-buffer-name "*Ediff Multifile Diffs" "*")))) | |
989 (ediff-eval-in-buffer ediff-meta-diff-buffer | |
990 (erase-buffer)) | |
991 (if (> (ediff-operate-on-marked-sessions 'ediff-append-custom-diff) 0) | |
992 ;; did something | |
993 (display-buffer ediff-meta-diff-buffer 'not-this-window) | |
994 (beep) | |
995 (message "No marked sessions found"))) | |
996 | |
997 | |
998 ;; This function executes in meta buffer. It knows where event happened. | |
999 (defun ediff-dir-action () | |
1000 "Execute appropriate action for the selected session." | |
1001 (interactive) | |
1002 (let* ((pos (ediff-event-point last-command-event)) | |
1003 (meta-buf (ediff-event-buffer last-command-event)) | |
1004 ;; ediff-get-meta-info gives error if meta-buf or pos are invalid | |
1005 (info (ediff-get-meta-info meta-buf pos)) | |
1006 session-buf file1 file2 file3 regexp) | |
1007 | |
1008 (setq session-buf (ediff-get-session-buffer info) | |
1009 file1 (ediff-get-session-objA info) | |
1010 file2 (ediff-get-session-objB info) | |
1011 file3 (ediff-get-session-objC info)) | |
1012 | |
1013 ;; make sure we don't start on hidden sessions | |
1014 ;; ?H means marked for hiding. ?I means invalid (hidden). | |
1015 (if (memq (ediff-get-session-status info) '(?H ?I)) | |
1016 (progn | |
1017 (beep) | |
1018 (if (y-or-n-p "This session is marked as hidden, unmark? ") | |
1019 (progn | |
1020 (ediff-set-session-status info nil) | |
1021 (ediff-update-meta-buffer meta-buf)) | |
1022 (error "Aborted")))) | |
1023 | |
1024 (ediff-eval-in-buffer meta-buf | |
1025 (goto-char pos) ; if the user clicked on session--move point there | |
1026 ;; First handle sessions involving directories (which are themselves | |
1027 ;; session groups) | |
1028 ;; After that handle individual sessions | |
1029 (cond ((and (file-directory-p file1) | |
1030 (stringp file2) (file-directory-p file2) | |
1031 (if (stringp file3) (file-directory-p file1) t)) | |
1032 ;; do ediff/ediff-merge on subdirectories | |
1033 (if (ediff-buffer-live-p session-buf) | |
1034 (ediff-show-meta-buffer session-buf) | |
1035 (setq regexp (read-string "Filter through regular expression: " | |
1036 nil 'ediff-filtering-regexp-history)) | |
1037 (ediff-directories-internal | |
1038 file1 file2 file3 regexp | |
1039 ediff-session-action-function | |
1040 ediff-metajob-name | |
1041 ;; make it update car info after startup | |
1042 (` (list (lambda () | |
1043 ;; child session group should know its parent | |
1044 (setq ediff-parent-meta-buffer | |
1045 (quote (, ediff-meta-buffer))) | |
1046 ;; and parent will know its child | |
1047 (setcar (quote (, info)) ediff-meta-buffer))))))) | |
1048 | |
1049 ;; Do ediff-revision on a subdirectory | |
1050 ((and (ediff-dir1-metajob) (file-directory-p file1)) | |
1051 (if (ediff-buffer-live-p session-buf) | |
1052 (ediff-show-meta-buffer session-buf) | |
1053 (setq regexp (read-string "Filter through regular expression: " | |
1054 nil 'ediff-filtering-regexp-history)) | |
1055 (ediff-directory-revisions-internal | |
1056 file1 regexp | |
1057 ediff-session-action-function ediff-metajob-name | |
1058 ;; make it update car info after startup | |
1059 (` (list (lambda () | |
1060 ;; child session group should know its parent | |
1061 (setq ediff-parent-meta-buffer | |
1062 (quote (, ediff-meta-buffer))) | |
1063 ;; and parent will know its child | |
1064 (setcar (quote (, info)) ediff-meta-buffer))))))) | |
1065 | |
1066 ;; From here on---only individual session handlers | |
1067 | |
1068 ;; handle an individual session with live control buffer | |
1069 ((ediff-buffer-live-p session-buf) | |
1070 (ediff-eval-in-buffer session-buf | |
1071 (setq ediff-mouse-pixel-position (mouse-pixel-position)) | |
1072 (ediff-recenter 'no-rehighlight))) | |
1073 | |
1074 ((ediff-problematic-session-p info) | |
1075 (beep) | |
1076 (if (y-or-n-p | |
1077 "This session's ancestor is a directory, merge without the ancestor? ") | |
1078 (ediff-merge-files | |
1079 file1 file2 | |
1080 ;; arrange startup hooks | |
1081 (` (list (lambda () | |
1082 (setq ediff-meta-buffer (, (current-buffer))) | |
1083 ;; see below for the explanation of what this does | |
1084 (setcar | |
1085 (quote (, info)) ediff-control-buffer))))) | |
1086 (error "Aborted"))) | |
1087 ((ediff-dir1-metajob) ; needs 1 file arg | |
1088 (funcall ediff-session-action-function | |
1089 file1 | |
1090 ;; arrange startup hooks | |
1091 (` (list (lambda () | |
1092 (setq ediff-meta-buffer (, (current-buffer))) | |
1093 ;; see below for explanation of what this does | |
1094 (setcar | |
1095 (quote (, info)) ediff-control-buffer)))))) | |
1096 ((not (ediff-metajob3)) ; need 2 file args | |
1097 (funcall ediff-session-action-function | |
1098 file1 file2 | |
1099 ;; arrange startup hooks | |
1100 (` (list (lambda () | |
1101 (setq ediff-meta-buffer (, (current-buffer))) | |
1102 ;; this makes ediff-startup pass the value of | |
1103 ;; ediff-control-buffer back to the meta | |
1104 ;; level, to the record in the meta list | |
1105 ;; containing the information about the | |
1106 ;; session associated with that | |
1107 ;; ediff-control-buffer | |
1108 (setcar | |
1109 (quote (, info)) ediff-control-buffer)))))) | |
1110 ((ediff-metajob3) ; need 3 file args | |
1111 (funcall ediff-session-action-function | |
1112 file1 file2 file3 | |
1113 ;; arrange startup hooks | |
1114 (` (list (lambda () | |
1115 (setq ediff-meta-buffer (, (current-buffer))) | |
1116 (setcar | |
1117 (quote (, info)) ediff-control-buffer)))))) | |
1118 ) ; cond | |
1119 ) ; eval in meta-buf | |
1120 )) | |
1121 | |
1122 (defun ediff-registry-action () | |
1123 "Switch to a selected session." | |
1124 (interactive) | |
1125 (let* ((pos (ediff-event-point last-command-event)) | |
1126 (buf (ediff-event-buffer last-command-event)) | |
1127 (ctl-buf (ediff-get-meta-info buf pos))) | |
1128 | |
1129 (if (ediff-buffer-live-p ctl-buf) | |
1130 ;; check if this is ediff-control-buffer or ediff-meta-buffer | |
1131 (if (ediff-eval-in-buffer ctl-buf | |
1132 (eq (key-binding "q") 'ediff-quit-meta-buffer)) | |
1133 ;; it's a meta-buffer -- last action should just display it | |
1134 (ediff-show-meta-buffer ctl-buf) | |
1135 ;; it's a session buffer -- invoke go back to session | |
1136 (ediff-eval-in-buffer ctl-buf | |
1137 (setq ediff-mouse-pixel-position (mouse-pixel-position)) | |
1138 (ediff-recenter 'no-rehighlight))) | |
1139 (beep) | |
1140 (message "You've selected a stale session --- try again") | |
1141 (ediff-update-registry)) | |
1142 (ediff-eval-in-buffer buf | |
1143 (goto-char pos)) | |
1144 )) | |
1145 | |
1146 | |
1147 (defun ediff-show-meta-buffer (&optional meta-buf) | |
1148 "Show the session group buffer." | |
1149 (interactive) | |
1150 (let (wind frame silent) | |
1151 (if meta-buf (setq silent t)) | |
1152 | |
1153 (setq meta-buf (or meta-buf ediff-meta-buffer)) | |
1154 (cond ((not (bufferp meta-buf)) | |
1155 (error "This Ediff session is not part of a session group")) | |
1156 ((not (ediff-buffer-live-p meta-buf)) | |
1157 (error | |
1158 "Can't find this session's group panel -- session itself is ok"))) | |
1159 | |
1160 (ediff-cleanup-meta-buffer meta-buf) | |
1161 (ediff-eval-in-buffer meta-buf | |
1162 (save-excursion | |
1163 (cond ((setq wind (ediff-get-visible-buffer-window meta-buf)) | |
1164 (or silent | |
1165 (message | |
1166 "Already showing the group panel for this session")) | |
1167 (set-window-buffer wind meta-buf) | |
1168 (select-window wind)) | |
1169 ((window-live-p (setq wind ediff-window-C)) ;in merge--merge buf | |
1170 (set-window-buffer ediff-window-C meta-buf) | |
1171 (select-window wind)) | |
1172 ((window-live-p (setq wind ediff-window-A)) | |
1173 (set-window-buffer ediff-window-A meta-buf) | |
1174 (select-window wind)) | |
1175 ((window-live-p (setq wind ediff-window-B)) | |
1176 (set-window-buffer ediff-window-B meta-buf) | |
1177 (select-window wind)) | |
1178 ((and | |
1179 (setq wind | |
1180 (ediff-get-visible-buffer-window ediff-registry-buffer)) | |
1181 (ediff-window-display-p)) | |
1182 (select-window wind) | |
1183 (other-window 1) | |
1184 (set-window-buffer (selected-window) meta-buf)) | |
1185 (t (ediff-skip-unsuitable-frames 'ok-unsplittable) | |
1186 (set-window-buffer (selected-window) meta-buf))) | |
1187 )) | |
1188 (if (ediff-window-display-p) | |
1189 (progn | |
1190 (setq frame | |
1191 (window-frame (ediff-get-visible-buffer-window meta-buf))) | |
1192 (raise-frame frame) | |
1193 (ediff-reset-mouse frame))) | |
1194 (run-hooks 'ediff-show-session-group-hook) | |
1195 )) | |
1196 | |
1197 (defun ediff-show-meta-buff-from-registry () | |
1198 "Display the session group buffer for a selected session group." | |
1199 (interactive) | |
1200 (let* ((pos (ediff-event-point last-command-event)) | |
1201 (meta-buf (ediff-event-buffer last-command-event)) | |
1202 (info (ediff-get-meta-info meta-buf pos)) | |
1203 (meta-or-session-buf info)) | |
1204 (ediff-eval-in-buffer meta-or-session-buf | |
1205 (ediff-show-meta-buffer)))) | |
1206 | |
1207 ;;;###autoload | |
1208 (defun ediff-show-registry () | |
1209 "Display Ediff's registry." | |
1210 (interactive) | |
1211 (ediff-update-registry) | |
1212 (if (not (ediff-buffer-live-p ediff-registry-buffer)) | |
1213 (error "No active Ediff sessions or corrupted session registry")) | |
1214 (let (wind frame) | |
1215 ;; for some reason, point moves in ediff-registry-buffer, so we preserve it | |
14040 | 1216 ;; explictly |
13130 | 1217 (ediff-eval-in-buffer ediff-registry-buffer |
1218 (save-excursion | |
1219 (cond ((setq wind | |
1220 (ediff-get-visible-buffer-window ediff-registry-buffer)) | |
1221 (message "Already showing the registry") | |
1222 (set-window-buffer wind ediff-registry-buffer) | |
1223 (select-window wind)) | |
1224 ((window-live-p ediff-window-C) | |
1225 (set-window-buffer ediff-window-C ediff-registry-buffer) | |
1226 (select-window ediff-window-C)) | |
1227 ((window-live-p ediff-window-A) | |
1228 (set-window-buffer ediff-window-A ediff-registry-buffer) | |
1229 (select-window ediff-window-A)) | |
1230 ((window-live-p ediff-window-B) | |
1231 (set-window-buffer ediff-window-B ediff-registry-buffer) | |
1232 (select-window ediff-window-B)) | |
1233 ((and (setq wind | |
1234 (ediff-get-visible-buffer-window ediff-meta-buffer)) | |
1235 (ediff-window-display-p)) | |
1236 (select-window wind) | |
1237 (other-window 1) | |
1238 (set-window-buffer (selected-window) ediff-registry-buffer)) | |
1239 (t (ediff-skip-unsuitable-frames 'ok-unsplittable) | |
1240 (set-window-buffer (selected-window) ediff-registry-buffer))) | |
1241 )) | |
1242 (if (ediff-window-display-p) | |
1243 (progn | |
1244 (setq frame | |
1245 (window-frame | |
1246 (ediff-get-visible-buffer-window ediff-registry-buffer))) | |
1247 (raise-frame frame) | |
1248 (ediff-reset-mouse frame))) | |
1249 (run-hooks 'ediff-show-registry-hook) | |
1250 )) | |
1251 | |
1252 ;;;###autoload | |
1253 (defalias 'eregistry 'ediff-show-registry) | |
1254 | |
1255 ;; If meta-buf doesn't exist, it is created. In that case, id doesn't have a | |
1256 ;; parent meta-buf | |
1257 ;; Check if META-BUF exists before calling this function | |
1258 (defun ediff-update-meta-buffer (meta-buf) | |
1259 (ediff-eval-in-buffer (current-buffer) | |
1260 (if (ediff-buffer-live-p meta-buf) | |
1261 (ediff-eval-in-buffer meta-buf | |
1262 (funcall ediff-meta-redraw-function ediff-meta-list)) | |
1263 ))) | |
1264 | |
1265 (defun ediff-update-registry () | |
1266 (ediff-eval-in-buffer (current-buffer) | |
1267 (if (ediff-buffer-live-p ediff-registry-buffer) | |
1268 (ediff-redraw-registry-buffer) | |
1269 (ediff-prepare-meta-buffer | |
1270 'ediff-registry-action | |
1271 ediff-session-registry | |
1272 "*Ediff Registry" | |
1273 'ediff-redraw-registry-buffer | |
1274 'ediff-registry)) | |
1275 )) | |
1276 | |
1277 ;; if meta-buf exists, it is redrawn along with parent. Otherwise, nothing | |
1278 ;; happens | |
1279 (defun ediff-cleanup-meta-buffer (meta-buffer) | |
1280 (if (ediff-buffer-live-p meta-buffer) | |
1281 (ediff-eval-in-buffer meta-buffer | |
1282 (ediff-update-meta-buffer meta-buffer) | |
1283 (if (ediff-buffer-live-p ediff-parent-meta-buffer) | |
1284 (ediff-update-meta-buffer ediff-parent-meta-buffer))))) | |
1285 | |
1286 ;; t if no session in progress | |
1287 (defun ediff-safe-to-quit (meta-buffer) | |
1288 (if (ediff-buffer-live-p meta-buffer) | |
1289 (let ((lis ediff-meta-list) | |
1290 (cont t) | |
1291 buffer-read-only) | |
1292 (ediff-update-meta-buffer meta-buffer) | |
1293 (ediff-eval-in-buffer meta-buffer | |
1294 (setq lis (cdr lis)) ; discard the description part of meta-list | |
1295 (while (and cont lis) | |
1296 (if (ediff-buffer-live-p | |
1297 (ediff-get-group-buffer lis)) ; in progress | |
1298 (setq cont nil)) | |
1299 (setq lis (cdr lis))) | |
1300 cont)))) | |
1301 | |
1302 (defun ediff-quit-meta-buffer () | |
1303 "If no unprocessed sessions in the group, delete the meta buffer. | |
1304 If no session is in progress, ask to confirm before deleting meta buffer. | |
1305 Otherwise, bury the meta buffer. | |
1306 If this is a session registry buffer then just bury it." | |
1307 (interactive) | |
1308 (let* ((buf (current-buffer)) | |
1309 (dir-diffs-buffer ediff-dir-diffs-buffer) | |
1310 (meta-diff-buffer ediff-meta-diff-buffer) | |
1311 (parent-buf ediff-parent-meta-buffer) | |
1312 (dont-show-registry (eq buf ediff-registry-buffer))) | |
1313 (if dont-show-registry | |
1314 (bury-buffer) | |
1315 (ediff-cleanup-meta-buffer buf) | |
1316 (cond ((and (ediff-safe-to-quit buf) | |
1317 (y-or-n-p "Quit this session group? ")) | |
1318 (ediff-dispose-of-meta-buffer buf)) | |
1319 ((ediff-safe-to-quit buf) | |
1320 (bury-buffer)) | |
1321 (t | |
1322 (bury-buffer) | |
1323 (beep) | |
1324 (message | |
1325 "Group has active sessions, panel not deleted"))) | |
1326 (ediff-cleanup-meta-buffer parent-buf) | |
1327 (ediff-kill-buffer-carefully dir-diffs-buffer) | |
1328 (ediff-kill-buffer-carefully meta-diff-buffer) | |
1329 (if (ediff-buffer-live-p parent-buf) | |
1330 (progn | |
1331 (setq dont-show-registry t) | |
1332 (ediff-show-meta-buffer parent-buf))) | |
1333 ) | |
1334 (or dont-show-registry | |
1335 (ediff-show-registry)))) | |
1336 | |
1337 (defun ediff-dispose-of-meta-buffer (buf) | |
1338 (setq ediff-session-registry (delq buf ediff-session-registry)) | |
1339 (ediff-eval-in-buffer buf | |
1340 (if (ediff-buffer-live-p ediff-dir-diffs-buffer) | |
1341 (kill-buffer ediff-dir-diffs-buffer))) | |
1342 (kill-buffer buf)) | |
1343 | |
1344 | |
1345 ;; obtain information on a meta record where the user clicked or typed | |
1346 ;; BUF is the buffer where this happened and POINT is the position | |
1347 ;; If optional NOERROR arg is given, don't report error and return nil if no | |
1348 ;; meta info is found on line. | |
1349 (defun ediff-get-meta-info (buf point &optional noerror) | |
1350 (let (result olist tmp) | |
1351 (if (and point (ediff-buffer-live-p buf)) | |
1352 (ediff-eval-in-buffer buf | |
1353 (if ediff-xemacs-p | |
1354 (setq result | |
1355 (if (setq tmp (extent-at point buf 'ediff-meta-info)) | |
1356 (ediff-overlay-get tmp 'ediff-meta-info))) | |
1357 (setq olist (overlays-at point)) | |
1358 (setq olist | |
1359 (mapcar (function (lambda (elt) | |
1360 (overlay-get elt 'ediff-meta-info))) | |
1361 olist)) | |
1362 (while (and olist (null (car olist)) | |
1363 (overlay-get (car olist) 'invisible)) | |
1364 (setq olist (cdr olist))) | |
1365 (setq result (car olist))))) | |
1366 (if result | |
1367 result | |
1368 (if noerror | |
1369 nil | |
1370 (ediff-update-registry) | |
1371 (error "No session info in this line"))))) | |
1372 | |
1373 ;; return location of the next meta overlay after point | |
1374 (defun ediff-next-meta-overlay-start (point) | |
1375 (let (overl) | |
1376 (if ediff-xemacs-p | |
1377 (progn | |
1378 (setq overl (extent-at point (current-buffer) 'ediff-meta-info)) | |
1379 (if overl | |
1380 (setq overl (next-extent overl)) | |
1381 (setq overl (next-extent (current-buffer)))) | |
1382 (if overl | |
1383 (extent-start-position overl) | |
1384 (point-max))) | |
1385 (if (= point (point-max)) (setq point (point-min))) | |
1386 (setq overl (car (overlays-at point))) | |
1387 (if (and overl (overlay-get overl 'ediff-meta-info)) | |
1388 (overlay-end overl) | |
1389 (next-overlay-change point))))) | |
1390 | |
1391 (defun ediff-previous-meta-overlay-start (point) | |
1392 (let (overl) | |
1393 (if ediff-xemacs-p | |
1394 (progn | |
1395 (setq overl (extent-at point (current-buffer) 'ediff-meta-info)) | |
1396 (if overl | |
1397 (setq overl (previous-extent overl)) | |
1398 (setq overl (previous-extent (current-buffer)))) | |
1399 (if overl | |
1400 (extent-start-position overl) | |
1401 (point-max))) | |
1402 ;;(if (bobp) (setq point (point-max))) | |
1403 (setq overl (car (overlays-at point))) | |
1404 (setq point (if (and overl (overlay-get overl 'ediff-meta-info)) | |
1405 (previous-overlay-change (overlay-start overl)) | |
1406 (previous-overlay-change point))) | |
1407 (if (= point (point-min)) (point-max) point) | |
1408 ))) | |
1409 | |
1410 | |
1411 ;;; Local Variables: | |
1412 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun) | |
1413 ;;; eval: (put 'ediff-eval-in-buffer 'lisp-indent-hook 1) | |
1414 ;;; End: | |
1415 | |
13607
71a4a349d998
Renamed from ediff-meta.el. Changed provide.
Richard M. Stallman <rms@gnu.org>
parents:
13216
diff
changeset
|
1416 (provide 'ediff-mult) |
13130 | 1417 (require 'ediff-util) |
1418 | |
13607
71a4a349d998
Renamed from ediff-meta.el. Changed provide.
Richard M. Stallman <rms@gnu.org>
parents:
13216
diff
changeset
|
1419 ;;; ediff-mult.el ends here |