0
|
1 ;;; emerge.el --- merge diffs under Emacs control
|
|
2
|
|
3 ;;; The author has placed this file in the public domain.
|
|
4
|
|
5 ;; Author: Dale R. Worley <drw@math.mit.edu>
|
|
6 ;; Version: 5xemacs
|
|
7 ;; Keywords: unix, tools
|
|
8
|
|
9 ;; This software was created by Dale R. Worley and is
|
|
10 ;; distributed free of charge. It is placed in the public domain and
|
|
11 ;; permission is granted to anyone to use, duplicate, modify and redistribute
|
|
12 ;; it provided that this notice is attached.
|
|
13
|
|
14 ;; Dale R. Worley provides absolutely NO WARRANTY OF ANY KIND
|
|
15 ;; with respect to this software. The entire risk as to the quality and
|
|
16 ;; performance of this software is with the user. IN NO EVENT WILL DALE
|
|
17 ;; R. WORLEY BE LIABLE TO ANYONE FOR ANY DAMAGES ARISING OUT THE
|
|
18 ;; USE OF THIS SOFTWARE, INCLUDING, WITHOUT LIMITATION, DAMAGES RESULTING FROM
|
|
19 ;; LOST DATA OR LOST PROFITS, OR FOR ANY SPECIAL, INCIDENTAL OR CONSEQUENTIAL
|
|
20 ;; DAMAGES.
|
|
21
|
|
22 ;;; Synched up with: FSF 19.30.
|
|
23
|
|
24 ;; LCD Archive Entry:
|
|
25 ;; emerge|Dale R. Worley|drw@math.mit.edu
|
|
26 ;; |File merge
|
|
27 ;; |92-12-11|version 5 gamma|~/packages/emerge.el.Z
|
|
28
|
|
29 ;;; Code
|
|
30
|
|
31 (defconst emerge-xemacs-p (not (not (string-match "XEmacs" emacs-version)))
|
|
32 "Non-nil if this is XEmacs. Don't alter manually, because it also
|
|
33 turns on work-arounds for bugs.")
|
|
34
|
|
35 (defmacro emerge-defvar-local (var value doc)
|
|
36 "Defines SYMBOL as an advertised variable.
|
|
37 Performs a defvar, then executes `make-variable-buffer-local' on
|
|
38 the variable. Also sets the `preserved' property, so that
|
|
39 `kill-all-local-variables' (called by major-mode setting commands)
|
|
40 won't destroy Emerge control variables."
|
|
41 (` (progn
|
|
42 (defvar (, var) (, value) (, doc))
|
|
43 (make-variable-buffer-local '(, var))
|
|
44 (put '(, var)
|
|
45 ;; This "if" can't be optimized by having "(, )" wrapped arount it,
|
|
46 ;; because byte-compilation will then try to evaluate it while
|
|
47 ;; macro-expanding the uses of emerge-defvar-local, and
|
|
48 ;; emerge-xemacs-p is not defined at that time.
|
|
49 (if emerge-xemacs-p 'permanent-local 'preserved)
|
|
50 t))))
|
|
51
|
|
52 ;; Add entries to minor-mode-alist so that emerge modes show correctly
|
|
53 (defvar emerge-minor-modes-list '((emerge-mode " Emerge")
|
|
54 (emerge-fast-mode " F")
|
|
55 (emerge-edit-mode " E")
|
|
56 (emerge-auto-advance " A")
|
|
57 (emerge-skip-prefers " S")))
|
|
58 (if (not (assq 'emerge-mode minor-mode-alist))
|
|
59 (setq minor-mode-alist (append emerge-minor-modes-list
|
|
60 minor-mode-alist)))
|
|
61
|
|
62 ;; We need to define this function so describe-mode can describe Emerge mode.
|
|
63 (defun emerge-mode ()
|
|
64 "Emerge mode is used by the Emerge file-merging package.
|
|
65 It is entered only through one of the functions:
|
|
66 `emerge-files'
|
|
67 `emerge-files-with-ancestor'
|
|
68 `emerge-buffers'
|
|
69 `emerge-buffers-with-ancestor'
|
|
70 `emerge-files-command'
|
|
71 `emerge-files-with-ancestor-command'
|
|
72 `emerge-files-remote'
|
|
73 `emerge-files-with-ancestor-remote'
|
|
74
|
|
75 Commands:
|
|
76 \\{emerge-basic-keymap}
|
|
77 Commands must be prefixed by \\<emerge-fast-keymap>\\[emerge-basic-keymap] in `edit' mode,
|
|
78 but can be invoked directly in `fast' mode.")
|
|
79
|
|
80 (defvar emerge-version "5xemacs"
|
|
81 "The version of Emerge.")
|
|
82
|
|
83 (defun emerge-version ()
|
|
84 "Return string describing the version of Emerge.
|
|
85 When called interactively, displays the version."
|
|
86 (interactive)
|
|
87 (if (interactive-p)
|
|
88 (message "Emerge version %s" (emerge-version))
|
|
89 emerge-version))
|
|
90
|
|
91 ;;; Emerge configuration variables
|
|
92
|
|
93 ;; Commands that produce difference files
|
|
94 ;; All that can be configured is the name of the programs to execute
|
|
95 ;; (emerge-diff-program and emerge-diff3-program) and the options
|
|
96 ;; to be provided (emerge-diff-options). The order in which the file names
|
|
97 ;; are given is fixed.
|
|
98 ;; The file names are always expanded (see expand-file-name) before being
|
|
99 ;; passed to diff, thus they need not be invoked under a shell that
|
|
100 ;; understands `~'.
|
|
101 ;; The code which processes the diff/diff3 output depends on all the
|
|
102 ;; finicky details of their output, including the somewhat strange
|
|
103 ;; way they number lines of a file.
|
|
104 (defvar emerge-diff-program "diff"
|
|
105 "*Name of the program which compares two files.")
|
|
106 (defvar emerge-diff3-program "diff3"
|
|
107 "*Name of the program which compares three files.
|
|
108 Its arguments are the ancestor file and the two variant files.")
|
|
109 (defvar emerge-diff-options ""
|
|
110 "*Options to pass to `emerge-diff-program' and `emerge-diff3-program'.")
|
|
111 (defvar emerge-match-diff-line (let ((x "\\([0-9]+\\)\\(\\|,\\([0-9]+\\)\\)"))
|
|
112 (concat "^" x "\\([acd]\\)" x "$"))
|
|
113 "*Pattern to match lines produced by diff that describe differences.
|
|
114 This is as opposed to lines from the source files.")
|
|
115 (defvar emerge-diff-ok-lines-regexp
|
|
116 "^\\([0-9,]+[acd][0-9,]+$\\|[<>] \\|---\\)"
|
|
117 "*Regexp that matches normal output lines from `emerge-diff-program'.
|
|
118 Lines that do not match are assumed to be error messages.")
|
|
119 (defvar emerge-diff3-ok-lines-regexp
|
|
120 "^\\([1-3]:\\|====\\| \\)"
|
|
121 "*Regexp that matches normal output lines from `emerge-diff3-program'.
|
|
122 Lines that do not match are assumed to be error messages.")
|
|
123
|
|
124 (defvar emerge-rcs-ci-program "ci"
|
|
125 "*Name of the program that checks in RCS revisions.")
|
|
126 (defvar emerge-rcs-co-program "co"
|
|
127 "*Name of the program that checks out RCS revisions.")
|
|
128
|
|
129 (defvar emerge-process-local-variables nil
|
|
130 "*Non-nil if Emerge should process local-variables lists in merge buffers.
|
|
131 \(You can explicitly request processing the local-variables
|
|
132 by executing `(hack-local-variables)'.)")
|
|
133 (defvar emerge-execute-line-deletions nil
|
|
134 "*If non-nil: `emerge-execute-line' makes no output if an input was deleted.
|
|
135 It concludes that an input version has been deleted when an ancestor entry
|
|
136 is present, only one A or B entry is present, and an output entry is present.
|
|
137 If nil: In such circumstances, the A or B file that is present will be
|
|
138 copied to the designated output file.")
|
|
139
|
|
140 (defvar emerge-before-flag "vvvvvvvvvvvvvvvvvvvv\n"
|
|
141 "*Flag placed above the highlighted block of code. Must end with newline.
|
|
142 Must be set before Emerge is loaded, or emerge-new-flags must be run
|
|
143 after setting.")
|
|
144 (defvar emerge-after-flag "^^^^^^^^^^^^^^^^^^^^\n"
|
|
145 "*Flag placed below the highlighted block of code. Must end with newline.
|
|
146 Must be set before Emerge is loaded, or emerge-new-flags must be run
|
|
147 after setting.")
|
|
148
|
|
149 (defvar emerge-split-horizontally t
|
|
150 ;; XEmacs - even when this works, jwz hates it.
|
|
151 "*Flag to control whether emerge will split windows horizontally or not.
|
|
152 Nil means that windows will be split vertically.")
|
|
153
|
|
154 ;; Hook variables
|
|
155
|
|
156 (defvar emerge-startup-hook nil
|
|
157 "*Hook to run in the merge buffer after the merge has been set up.")
|
|
158 (defvar emerge-select-hook nil
|
|
159 "*Hook to run after a difference has been selected.
|
|
160 The variable `n' holds the (internal) number of the difference.")
|
|
161 (defvar emerge-unselect-hook nil
|
|
162 "*Hook to run after a difference has been unselected.
|
|
163 The variable `n' holds the (internal) number of the difference.")
|
|
164
|
|
165 ;; Variables to control the default directories of the arguments to
|
|
166 ;; Emerge commands.
|
|
167
|
|
168 (defvar emerge-default-last-directories nil
|
|
169 "*If nil, default dir for filenames in emerge is `default-directory'.
|
|
170 If non-nil, filenames complete in the directory of the last argument of the
|
|
171 same type to an `emerge-files...' command.")
|
|
172
|
|
173 (defvar emerge-last-dir-A nil
|
|
174 "Last directory for the first file of an `emerge-files...' command.")
|
|
175 (defvar emerge-last-dir-B nil
|
|
176 "Last directory for the second file of an `emerge-files...' command.")
|
|
177 (defvar emerge-last-dir-ancestor nil
|
|
178 "Last directory for the ancestor file of an `emerge-files...' command.")
|
|
179 (defvar emerge-last-dir-output nil
|
|
180 "Last directory for the output file of an `emerge-files...' command.")
|
|
181 (defvar emerge-last-revision-A nil
|
|
182 "Last RCS revision used for first file of an `emerge-revisions...' command.")
|
|
183 (defvar emerge-last-revision-B nil
|
|
184 "Last RCS revision used for second file of an `emerge-revisions...' command.")
|
|
185 (defvar emerge-last-revision-ancestor nil
|
|
186 "Last RCS revision used for ancestor file of an `emerge-revisions...' command.")
|
|
187
|
|
188 (defvar emerge-before-flag-length)
|
|
189 (defvar emerge-before-flag-lines)
|
|
190 (defvar emerge-before-flag-match)
|
|
191 (defvar emerge-after-flag-length)
|
|
192 (defvar emerge-after-flag-lines)
|
|
193 (defvar emerge-after-flag-match)
|
|
194 ;;(defvar emerge-diff-buffer)
|
|
195 ;;(defvar emerge-diff-error-buffer)
|
|
196 (defvar emerge-prefix-argument)
|
|
197 (defvar emerge-exit-func) ; was just exit-func, but fsf
|
|
198 ; renamed it and it's not used anywhere
|
|
199 (defvar emerge-globalized-difference-list)
|
|
200 (defvar emerge-globalized-number-of-differences)
|
|
201
|
|
202 (defvar A-begin)
|
|
203 (defvar A-end)
|
|
204 (defvar B-begin)
|
|
205 (defvar B-end)
|
|
206 (defvar merge-begin)
|
|
207 (defvar merge-end)
|
|
208 ;;(defvar diff)
|
|
209 (defvar diff-vector)
|
|
210 (defvar valid-diff)
|
|
211
|
|
212 ;; Set up the face to highlight the current difference
|
|
213 (if emerge-xemacs-p
|
|
214 (or (and (find-face 'emerge-highlight-face)
|
|
215 (face-differs-from-default-p 'emerge-highlight-face))
|
|
216 (copy-face 'bold-italic 'emerge-highlight-face)))
|
|
217
|
|
218 ;;(defvar emerge-mark-with-text (not emerge-xemacs-p))
|
|
219 ;; this doesn't work yet -jwz
|
|
220 ;; and probably never will now that there's ediff --stig
|
|
221 (defvar emerge-mark-with-text t)
|
|
222
|
|
223 ;; These function definitions need to be up here, because they are used
|
|
224 ;; during loading.
|
|
225 (defun emerge-new-flags ()
|
|
226 "Function to be called after `emerge-{before,after}-flag'.
|
|
227 This is called after these functions are changed to compute values that
|
|
228 depend on the flags."
|
|
229 (setq emerge-before-flag-length (length emerge-before-flag))
|
|
230 (setq emerge-before-flag-lines
|
|
231 (emerge-count-matches-string emerge-before-flag "\n"))
|
|
232 (setq emerge-before-flag-match (regexp-quote emerge-before-flag))
|
|
233 (setq emerge-after-flag-length (length emerge-after-flag))
|
|
234 (setq emerge-after-flag-lines
|
|
235 (emerge-count-matches-string emerge-after-flag "\n"))
|
|
236 (setq emerge-after-flag-match (regexp-quote emerge-after-flag)))
|
|
237
|
|
238 (defun emerge-count-matches-string (string regexp)
|
|
239 "Return the number of matches in STRING for REGEXP."
|
|
240 (let ((i 0)
|
|
241 (count 0))
|
|
242 (while (string-match regexp string i)
|
|
243 (setq count (1+ count))
|
|
244 (setq i (match-end 0)))
|
|
245 count))
|
|
246
|
|
247 ;; Calculate dependent variables
|
|
248 (emerge-new-flags)
|
|
249
|
|
250 (defvar emerge-min-visible-lines 3
|
|
251 "*Number of lines that we want to show above and below the flags when we are
|
|
252 displaying a difference.")
|
|
253
|
|
254 (defvar emerge-temp-file-prefix
|
|
255 (let ((env (or (getenv "TMPDIR")
|
|
256 (getenv "TMP")
|
|
257 (getenv "TEMP")))
|
|
258 d)
|
|
259 (setq d (if (and env (> (length env) 0))
|
|
260 env
|
|
261 "/tmp"))
|
|
262 (if (= (aref d (1- (length d))) ?/)
|
|
263 (setq d (substring d 0 -1)))
|
|
264 (concat d "/emerge"))
|
|
265 "*Prefix to put on Emerge temporary file names.
|
|
266 Do not start with `~/' or `~user-name/'.")
|
|
267
|
|
268 (defvar emerge-temp-file-mode 384 ; u=rw only
|
|
269 "*Mode for Emerge temporary files.")
|
|
270
|
|
271 (defvar emerge-combine-versions-template
|
|
272 "#ifdef NEW\n%b#else /* NEW */\n%a#endif /* NEW */\n"
|
|
273 "*Template for `emerge-combine-versions' to combine the two versions.
|
|
274 The template is inserted as a string, with the following interpolations:
|
|
275 %a the A version of the difference
|
|
276 %b the B version of the difference
|
|
277 %% the character `%'
|
|
278 Don't forget to end the template with a newline.
|
|
279 Note that this variable can be made local to a particular merge buffer by
|
|
280 giving a prefix argument to `emerge-set-combine-versions-template'.")
|
|
281
|
|
282 ;; Build keymaps
|
|
283
|
|
284 (defvar emerge-basic-keymap nil
|
|
285 "Keymap of Emerge commands.
|
|
286 Directly available in `fast' mode;
|
|
287 must be prefixed by \\<emerge-fast-keymap>\\[emerge-basic-keymap] in `edit' mode.")
|
|
288
|
|
289 (defvar emerge-fast-keymap nil
|
|
290 "Local keymap used in Emerge `fast' mode.
|
|
291 Makes Emerge commands directly available.")
|
|
292
|
|
293 (defvar emerge-command-prefix "\C-c"
|
|
294 "*Command prefix for Emerge commands in 'edit' mode.
|
|
295 Must be set before Emerge is loaded.")
|
|
296
|
|
297 ;; This function sets up the fixed keymaps. It is executed when the first
|
|
298 ;; Emerge is done to allow the user maximum time to set up the global keymap.
|
|
299 (defun emerge-setup-fixed-keymaps ()
|
|
300 ;; Set up the basic keymap
|
|
301 (setq emerge-basic-keymap (make-keymap))
|
|
302 (set-keymap-name emerge-basic-keymap 'emerge-basic-keymap)
|
|
303 (suppress-keymap emerge-basic-keymap) ; this sets 0..9 to digit-argument and
|
|
304 ; - to negative-argument
|
|
305 (define-key emerge-basic-keymap "p" 'emerge-previous-difference)
|
|
306 (define-key emerge-basic-keymap "n" 'emerge-next-difference)
|
|
307 (define-key emerge-basic-keymap "a" 'emerge-select-A)
|
|
308 (define-key emerge-basic-keymap "b" 'emerge-select-B)
|
|
309 (define-key emerge-basic-keymap "j" 'emerge-jump-to-difference)
|
|
310 (define-key emerge-basic-keymap "." 'emerge-find-difference)
|
|
311 (define-key emerge-basic-keymap "q" 'emerge-quit)
|
|
312 (define-key emerge-basic-keymap "\C-]" 'emerge-abort)
|
|
313 (define-key emerge-basic-keymap "f" 'emerge-fast-mode)
|
|
314 (define-key emerge-basic-keymap "e" 'emerge-edit-mode)
|
|
315 (define-key emerge-basic-keymap "s" nil)
|
|
316 (define-key emerge-basic-keymap "sa" 'emerge-auto-advance)
|
|
317 (define-key emerge-basic-keymap "ss" 'emerge-skip-prefers)
|
|
318 (define-key emerge-basic-keymap "l" 'emerge-recenter)
|
|
319 (define-key emerge-basic-keymap "d" nil)
|
|
320 (define-key emerge-basic-keymap "da" 'emerge-default-A)
|
|
321 (define-key emerge-basic-keymap "db" 'emerge-default-B)
|
|
322 (define-key emerge-basic-keymap "c" nil)
|
|
323 (define-key emerge-basic-keymap "ca" 'emerge-copy-as-kill-A)
|
|
324 (define-key emerge-basic-keymap "cb" 'emerge-copy-as-kill-B)
|
|
325 (define-key emerge-basic-keymap "i" nil)
|
|
326 (define-key emerge-basic-keymap "ia" 'emerge-insert-A)
|
|
327 (define-key emerge-basic-keymap "ib" 'emerge-insert-B)
|
|
328 (define-key emerge-basic-keymap "m" 'emerge-mark-difference)
|
|
329 (define-key emerge-basic-keymap "v" 'emerge-scroll-up)
|
|
330 (define-key emerge-basic-keymap "^" 'emerge-scroll-down)
|
|
331 (define-key emerge-basic-keymap "<" 'emerge-scroll-left)
|
|
332 (define-key emerge-basic-keymap ">" 'emerge-scroll-right)
|
|
333 (define-key emerge-basic-keymap "|" 'emerge-scroll-reset)
|
|
334 (define-key emerge-basic-keymap "x" nil)
|
|
335 (define-key emerge-basic-keymap "x1" 'emerge-one-line-window)
|
|
336 (define-key emerge-basic-keymap "xa" 'emerge-find-difference-A)
|
|
337 (define-key emerge-basic-keymap "xb" 'emerge-find-difference-B)
|
|
338 (define-key emerge-basic-keymap "xc" 'emerge-combine-versions)
|
|
339 (define-key emerge-basic-keymap "xC" 'emerge-combine-versions-register)
|
|
340 (define-key emerge-basic-keymap "xd" 'emerge-find-difference)
|
|
341 (define-key emerge-basic-keymap "xf" 'emerge-file-names)
|
|
342 (define-key emerge-basic-keymap "xj" 'emerge-join-differences)
|
|
343 (define-key emerge-basic-keymap "xl" 'emerge-line-numbers)
|
|
344 (define-key emerge-basic-keymap "xm" 'emerge-set-merge-mode)
|
|
345 (define-key emerge-basic-keymap "xs" 'emerge-split-difference)
|
|
346 (define-key emerge-basic-keymap "xt" 'emerge-trim-difference)
|
|
347 (define-key emerge-basic-keymap "xx" 'emerge-set-combine-versions-template)
|
|
348 ;; Allow emerge-basic-keymap to be referenced indirectly
|
|
349 (fset 'emerge-basic-keymap emerge-basic-keymap)
|
|
350 ;; Set up the fast mode keymap
|
|
351 (setq emerge-fast-keymap (make-sparse-keymap))
|
|
352 (set-keymap-parent emerge-fast-keymap emerge-basic-keymap)
|
|
353 (set-keymap-name emerge-fast-keymap 'emerge-fast-keymap)
|
|
354 ;; Allow prefixed commands to work in fast mode
|
|
355 (define-key emerge-fast-keymap emerge-command-prefix 'emerge-basic-keymap)
|
|
356 ;; Allow emerge-fast-keymap to be referenced indirectly
|
|
357 (fset 'emerge-fast-keymap emerge-fast-keymap)
|
|
358 ;; Suppress write-file and save-buffer
|
|
359 (substitute-key-definition 'write-file 'emerge-query-write-file
|
|
360 emerge-fast-keymap (current-global-map))
|
|
361 (substitute-key-definition 'save-buffer 'emerge-query-save-buffer
|
|
362 emerge-fast-keymap (current-global-map)))
|
|
363
|
|
364 ;;fsf (define-key emerge-basic-keymap [menu-bar] (make-sparse-keymap))
|
|
365 ;;fsf
|
|
366 ;;fsf (define-key emerge-fast-keymap [menu-bar options]
|
|
367 ;;fsf (cons "Options" emerge-options-menu))
|
|
368 ;;fsf (define-key emerge-fast-keymap [menu-bar merge]
|
|
369 ;;fsf (cons "Merge" emerge-merge-menu))
|
|
370 ;;fsf (define-key emerge-fast-keymap [menu-bar move]
|
|
371 ;;fsf (cons "Move" emerge-move-menu))
|
|
372 ;;fsf
|
|
373 ;;fsf (define-key emerge-move-menu [emerge-scroll-reset]
|
|
374 ;;fsf '("Scroll Reset" . emerge-scroll-reset))
|
|
375 ;;fsf (define-key emerge-move-menu [emerge-scroll-right]
|
|
376 ;;fsf '("Scroll Right" . emerge-scroll-right))
|
|
377 ;;fsf (define-key emerge-move-menu [emerge-scroll-left]
|
|
378 ;;fsf '("Scroll Left" . emerge-scroll-left))
|
|
379 ;;fsf (define-key emerge-move-menu [emerge-scroll-down]
|
|
380 ;;fsf '("Scroll Down" . emerge-scroll-down))
|
|
381 ;;fsf (define-key emerge-move-menu [emerge-scroll-up]
|
|
382 ;;fsf '("Scroll Up" . emerge-scroll-up))
|
|
383 ;;fsf (define-key emerge-move-menu [emerge-recenter]
|
|
384 ;;fsf '("Recenter" . emerge-recenter))
|
|
385 ;;fsf (define-key emerge-move-menu [emerge-mark-difference]
|
|
386 ;;fsf '("Mark Difference" . emerge-mark-difference))
|
|
387 ;;fsf (define-key emerge-move-menu [emerge-jump-to-difference]
|
|
388 ;;fsf '("Jump To Difference" . emerge-jump-to-difference))
|
|
389 ;;fsf (define-key emerge-move-menu [emerge-find-difference]
|
|
390 ;;fsf '("Find Difference" . emerge-find-difference))
|
|
391 ;;fsf (define-key emerge-move-menu [emerge-previous-difference]
|
|
392 ;;fsf '("Previous Difference" . emerge-previous-difference))
|
|
393 ;;fsf (define-key emerge-move-menu [emerge-next-difference]
|
|
394 ;;fsf '("Next Difference" . emerge-next-difference))
|
|
395 ;;fsf
|
|
396 ;;fsf
|
|
397 ;;fsf (define-key emerge-options-menu [emerge-one-line-window]
|
|
398 ;;fsf '("One Line Window" . emerge-one-line-window))
|
|
399 ;;fsf (define-key emerge-options-menu [emerge-set-merge-mode]
|
|
400 ;;fsf '("Set Merge Mode" . emerge-set-merge-mode))
|
|
401 ;;fsf (define-key emerge-options-menu [emerge-set-combine-template]
|
|
402 ;;fsf '("Set Combine Template..." . emerge-set-combine-template))
|
|
403 ;;fsf (define-key emerge-options-menu [emerge-default-B]
|
|
404 ;;fsf '("Default B" . emerge-default-B))
|
|
405 ;;fsf (define-key emerge-options-menu [emerge-default-A]
|
|
406 ;;fsf '("Default A" . emerge-default-A))
|
|
407 ;;fsf (define-key emerge-options-menu [emerge-skip-prefers]
|
|
408 ;;fsf '("Skip Prefers" . emerge-skip-prefers))
|
|
409 ;;fsf (define-key emerge-options-menu [emerge-auto-advance]
|
|
410 ;;fsf '("Auto Advance" . emerge-auto-advance))
|
|
411 ;;fsf (define-key emerge-options-menu [emerge-edit-mode]
|
|
412 ;;fsf '("Edit Mode" . emerge-edit-mode))
|
|
413 ;;fsf (define-key emerge-options-menu [emerge-fast-mode]
|
|
414 ;;fsf '("Fast Mode" . emerge-fast-mode))
|
|
415 ;;fsf
|
|
416 ;;fsf (define-key emerge-merge-menu [emerge-abort] '("Abort" . emerge-abort))
|
|
417 ;;fsf (define-key emerge-merge-menu [emerge-quit] '("Quit" . emerge-quit))
|
|
418 ;;fsf (define-key emerge-merge-menu [emerge-split-difference]
|
|
419 ;;fsf '("Split Difference" . emerge-split-difference))
|
|
420 ;;fsf (define-key emerge-merge-menu [emerge-join-differences]
|
|
421 ;;fsf '("Join Differences" . emerge-join-differences))
|
|
422 ;;fsf (define-key emerge-merge-menu [emerge-trim-difference]
|
|
423 ;;fsf '("Trim Difference" . emerge-trim-difference))
|
|
424 ;;fsf (define-key emerge-merge-menu [emerge-combine-versions]
|
|
425 ;;fsf '("Combine Versions" . emerge-combine-versions))
|
|
426 ;;fsf (define-key emerge-merge-menu [emerge-copy-as-kill-B]
|
|
427 ;;fsf '("Copy B as Kill" . emerge-copy-as-kill-B))
|
|
428 ;;fsf (define-key emerge-merge-menu [emerge-copy-as-kill-A]
|
|
429 ;;fsf '("Copy A as Kill" . emerge-copy-as-kill-A))
|
|
430 ;;fsf (define-key emerge-merge-menu [emerge-insert-B]
|
|
431 ;;fsf '("Insert B" . emerge-insert-B))
|
|
432 ;;fsf (define-key emerge-merge-menu [emerge-insert-A]
|
|
433 ;;fsf '("Insert A" . emerge-insert-A))
|
|
434 ;;fsf (define-key emerge-merge-menu [emerge-select-B]
|
|
435 ;;fsf '("Select B" . emerge-select-B))
|
|
436 ;;fsf (define-key emerge-merge-menu [emerge-select-A]
|
|
437 ;;fsf '("Select A" . emerge-select-A)))
|
|
438
|
|
439 (defvar emerge-menu
|
|
440 '(["Buffers ..." emerge-buffers t]
|
|
441 ["Buffers With Ancestor ..." emerge-buffers-with-ancestor t]
|
|
442 ["Files ..." emerge-files t]
|
|
443 ["Files with Ancestor ..." emerge-files-with-ancestor t]
|
|
444 ["Revisions ..." emerge-revisions t]
|
|
445 ["Revisions with Ancestor ..." emerge-revisions-with-ancestor t]
|
|
446 ["Merge Directories ..." emerge-merge-directories t])
|
|
447 "Menubar entry for using Emerge.")
|
|
448
|
|
449 (defvar emerge-mode-menu
|
|
450 '(
|
|
451 ["Next Difference" emerge-next-difference t]
|
|
452 ["Previous Difference" emerge-previous-difference t]
|
|
453 ("Other Motion"
|
|
454 ["Find Difference" emerge-find-difference t]
|
|
455 ["Jump To Difference" emerge-jump-to-difference t]
|
|
456 ["Mark Difference" emerge-mark-difference t]
|
|
457 ["Recenter" emerge-recenter t]
|
|
458 ["Scroll Up" emerge-scroll-up t]
|
|
459 ["Scroll Down" emerge-scroll-down t]
|
|
460 ["Scroll Left" emerge-scroll-left t]
|
|
461 ["Scroll Right" emerge-scroll-right t]
|
|
462 ["Scroll Reset" emerge-scroll-reset t])
|
|
463 "---"
|
|
464 ["Select A" emerge-select-A t]
|
|
465 ["Select B" emerge-select-B t]
|
|
466 ["Insert A" emerge-insert-A t]
|
|
467 ["Insert B" emerge-insert-B t]
|
|
468 ["Copy A as Kill" emerge-copy-as-kill-A t]
|
|
469 ["Copy B as Kill" emerge-copy-as-kill-B t]
|
|
470 ("Other Merge"
|
|
471 ["Combine Versions" emerge-combine-versions t]
|
|
472 ["Trim Difference" emerge-trim-difference t]
|
|
473 ["Join Differences" emerge-join-differences t]
|
|
474 ["Split Difference" emerge-split-difference t])
|
|
475 "---"
|
|
476 ("Options"
|
|
477 ["Fast Mode" emerge-fast-mode t]
|
|
478 ["Edit Mode" emerge-edit-mode t]
|
|
479 ["Auto Advance" emerge-auto-advance t]
|
|
480 ["Skip Prefers" emerge-skip-prefers t]
|
|
481 ["Default A" emerge-default-A t]
|
|
482 ["Default B" emerge-default-B t]
|
|
483 ["Set Combine Template..." emerge-set-combine-template t]
|
|
484 ["Set Merge Mode" emerge-set-merge-mode t]
|
|
485 ["One Line Window" emerge-one-line-window t])
|
|
486 ["Abort" emerge-abort t]
|
|
487 ["Quit" emerge-quit t])
|
|
488 "Menubar entry while in Emerge minor mode.")
|
|
489
|
|
490 ;; Variables which control each merge. They are local to the merge buffer.
|
|
491
|
|
492 ;; Mode variables
|
|
493 (emerge-defvar-local emerge-mode nil
|
|
494 "Indicator for emerge-mode.")
|
|
495 (emerge-defvar-local emerge-fast-mode nil
|
|
496 "Indicator for emerge-mode fast submode.")
|
|
497 (emerge-defvar-local emerge-edit-mode nil
|
|
498 "Indicator for emerge-mode edit submode.")
|
|
499 (emerge-defvar-local emerge-A-buffer nil
|
|
500 "The buffer in which the A variant is stored.")
|
|
501 (emerge-defvar-local emerge-B-buffer nil
|
|
502 "The buffer in which the B variant is stored.")
|
|
503 (emerge-defvar-local emerge-merge-buffer nil
|
|
504 "The buffer in which the merged file is manipulated.")
|
|
505 (emerge-defvar-local emerge-ancestor-buffer nil
|
|
506 "The buffer in which the ancestor variant is stored,
|
|
507 or nil if there is none.")
|
|
508
|
|
509 (defconst emerge-saved-variables
|
|
510 '((buffer-modified-p set-buffer-modified-p)
|
|
511 buffer-read-only
|
|
512 buffer-auto-save-file-name)
|
|
513 "Variables and properties of a buffer which are saved, modified and restored
|
|
514 during a merge.")
|
|
515 (defconst emerge-merging-values '(nil t nil)
|
|
516 "Values to be assigned to emerge-saved-variables during a merge.")
|
|
517
|
|
518 (emerge-defvar-local emerge-A-buffer-values nil
|
|
519 "Remembers emerge-saved-variables for emerge-A-buffer.")
|
|
520 (emerge-defvar-local emerge-B-buffer-values nil
|
|
521 "Remembers emerge-saved-variables for emerge-B-buffer.")
|
|
522
|
|
523 (emerge-defvar-local emerge-difference-list nil
|
|
524 "Vector of differences between the variants, and markers in the buffers to
|
|
525 show where they are. Each difference is represented by a vector of seven
|
|
526 elements. The first two are markers to the beginning and end of the difference
|
|
527 section in the A buffer, the second two are markers for the B buffer, the third
|
|
528 two are markers for the merge buffer, and the last element is the \"state\" of
|
|
529 that difference in the merge buffer.
|
|
530 A section of a buffer is described by two markers, one to the beginning of
|
|
531 the first line of the section, and one to the beginning of the first line
|
|
532 after the section. (If the section is empty, both markers point to the same
|
|
533 point.) If the section is part of the selected difference, then the markers
|
|
534 are moved into the flags, so the user can edit the section without disturbing
|
|
535 the markers.
|
|
536 The \"states\" are:
|
|
537 A the merge buffer currently contains the A variant
|
|
538 B the merge buffer currently contains the B variant
|
|
539 default-A the merge buffer contains the A variant by default,
|
|
540 but this difference hasn't been selected yet, so
|
|
541 change-default commands can alter it
|
|
542 default-B the merge buffer contains the B variant by default,
|
|
543 but this difference hasn't been selected yet, so
|
|
544 change-default commands can alter it
|
|
545 prefer-A in a three-file merge, the A variant is the preferred
|
|
546 choice
|
|
547 prefer-B in a three-file merge, the B variant is the preferred
|
|
548 choice")
|
|
549 (emerge-defvar-local emerge-current-difference -1
|
|
550 "The difference that is currently selected.")
|
|
551 (emerge-defvar-local emerge-number-of-differences nil
|
|
552 "Number of differences found.")
|
|
553 (emerge-defvar-local emerge-edit-keymap nil
|
|
554 "The local keymap for the merge buffer, with the emerge commands defined in
|
|
555 it. Used to save the local keymap during fast mode, when the local keymap is
|
|
556 replaced by emerge-fast-keymap.")
|
|
557 (emerge-defvar-local emerge-old-keymap nil
|
|
558 "The original local keymap for the merge buffer.")
|
|
559 (emerge-defvar-local emerge-auto-advance nil
|
|
560 "*If non-nil, emerge-select-A and emerge-select-B automatically advance to
|
|
561 the next difference.")
|
|
562 (emerge-defvar-local emerge-skip-prefers nil
|
|
563 "*If non-nil, differences for which there is a preference are automatically
|
|
564 skipped.")
|
|
565 (emerge-defvar-local emerge-quit-hook nil
|
|
566 "Hooks to run in the merge buffer after the merge has been finished.
|
|
567 `emerge-prefix-argument' will hold the prefix argument of the `emerge-quit'
|
|
568 command.
|
|
569 This is *not* a user option, since Emerge uses it for its own processing.")
|
|
570 (emerge-defvar-local emerge-output-description nil
|
|
571 "Describes output destination of emerge, for `emerge-file-names'.")
|
|
572
|
|
573 ;;; Setup functions for two-file mode.
|
|
574
|
|
575 (defun emerge-files-internal (file-A file-B &optional startup-hooks quit-hooks
|
|
576 output-file)
|
|
577 (if (not (file-readable-p file-A))
|
|
578 (error "File \"%s\" does not exist or is not readable" file-A))
|
|
579 (if (not (file-readable-p file-B))
|
|
580 (error "File \"%s\" does not exist or is not readable" file-B))
|
|
581 (let ((buffer-A (find-file-noselect file-A))
|
|
582 (buffer-B (find-file-noselect file-B)))
|
|
583 ;; Record the directories of the files
|
|
584 (setq emerge-last-dir-A (file-name-directory file-A))
|
|
585 (setq emerge-last-dir-B (file-name-directory file-B))
|
|
586 (if output-file
|
|
587 (setq emerge-last-dir-output (file-name-directory output-file)))
|
|
588 ;; Make sure the entire files are seen, and they reflect what is on disk
|
189
|
589 (with-current-buffer buffer-A
|
|
590 (widen)
|
|
591 (if (emerge-remote-file-p)
|
|
592 (progn
|
|
593 ;; Store in a local file
|
|
594 (setq file-A (emerge-make-temp-file "A"))
|
|
595 (write-region (point-min) (point-max) file-A nil 'no-message)
|
|
596 (setq startup-hooks
|
|
597 (cons (` (lambda () (delete-file (, file-A))))
|
|
598 startup-hooks)))
|
|
599 ;; Verify that the file matches the buffer
|
|
600 (emerge-verify-file-buffer)))
|
|
601 (with-current-buffer
|
|
602 buffer-B
|
|
603 (widen)
|
|
604 (if (emerge-remote-file-p)
|
|
605 (progn
|
|
606 ;; Store in a local file
|
|
607 (setq file-B (emerge-make-temp-file "B"))
|
|
608 (write-region (point-min) (point-max) file-B nil 'no-message)
|
|
609 (setq startup-hooks
|
|
610 (cons (` (lambda () (delete-file (, file-B))))
|
|
611 startup-hooks)))
|
|
612 ;; Verify that the file matches the buffer
|
|
613 (emerge-verify-file-buffer)))
|
0
|
614 (emerge-setup buffer-A file-A buffer-B file-B startup-hooks quit-hooks
|
|
615 output-file)))
|
|
616
|
|
617 ;; Start up Emerge on two files
|
|
618 (defun emerge-setup (buffer-A file-A buffer-B file-B startup-hooks quit-hooks
|
|
619 output-file)
|
|
620 (setq file-A (expand-file-name file-A))
|
|
621 (setq file-B (expand-file-name file-B))
|
|
622 (setq output-file (and output-file (expand-file-name output-file)))
|
|
623 (let* ((merge-buffer-name (emerge-unique-buffer-name "*merge" "*"))
|
|
624 ;; create the merge buffer from buffer A, so it inherits buffer A's
|
|
625 ;; default directory, etc.
|
189
|
626 (merge-buffer (with-current-buffer
|
|
627 buffer-A
|
|
628 (get-buffer-create merge-buffer-name))))
|
|
629 (with-current-buffer
|
|
630 merge-buffer
|
|
631 (emerge-copy-modes buffer-A)
|
|
632 (setq buffer-read-only nil)
|
|
633 (auto-save-mode 1)
|
|
634 (setq emerge-mode t)
|
|
635 (setq emerge-A-buffer buffer-A)
|
|
636 (setq emerge-B-buffer buffer-B)
|
|
637 (setq emerge-ancestor-buffer nil)
|
|
638 (setq emerge-merge-buffer merge-buffer)
|
|
639 (setq emerge-output-description
|
|
640 (if output-file
|
|
641 (concat "Output to file: " output-file)
|
|
642 (concat "Output to buffer: " (buffer-name merge-buffer))))
|
|
643 (insert-buffer emerge-A-buffer)
|
|
644 (emerge-set-keys)
|
|
645 (setq emerge-difference-list (emerge-make-diff-list file-A file-B))
|
|
646 (setq emerge-number-of-differences (length emerge-difference-list))
|
|
647 (setq emerge-current-difference -1)
|
|
648 (setq emerge-quit-hook quit-hooks)
|
|
649 (emerge-remember-buffer-characteristics)
|
|
650 (emerge-handle-local-variables))
|
0
|
651 (emerge-setup-windows buffer-A buffer-B merge-buffer t)
|
189
|
652 (with-current-buffer merge-buffer
|
|
653 (run-hooks 'startup-hooks 'emerge-startup-hook)
|
|
654 (setq buffer-read-only t))))
|
0
|
655
|
|
656 ;; Generate the Emerge difference list between two files
|
|
657 (defun emerge-make-diff-list (file-A file-B)
|
|
658 (let ((diff-buffer (get-buffer-create "*emerge-diff*")))
|
189
|
659 (with-current-buffer
|
|
660 diff-buffer
|
|
661 (erase-buffer)
|
|
662 (shell-command
|
|
663 (format "%s %s %s %s"
|
|
664 emerge-diff-program emerge-diff-options
|
|
665 (emerge-protect-metachars file-A)
|
|
666 (emerge-protect-metachars file-B))
|
|
667 t))
|
0
|
668 (emerge-prepare-error-list emerge-diff-ok-lines-regexp diff-buffer)
|
|
669 (emerge-convert-diffs-to-markers
|
|
670 emerge-A-buffer emerge-B-buffer emerge-merge-buffer
|
|
671 (emerge-extract-diffs diff-buffer))))
|
|
672
|
|
673 (defun emerge-extract-diffs (diff-buffer)
|
|
674 (let (list)
|
189
|
675 (with-current-buffer
|
|
676 diff-buffer
|
|
677 (goto-char (point-min))
|
|
678 (while (re-search-forward emerge-match-diff-line nil t)
|
|
679 (let* ((a-begin (string-to-int (buffer-substring (match-beginning 1)
|
|
680 (match-end 1))))
|
|
681 (a-end (let ((b (match-beginning 3))
|
|
682 (e (match-end 3)))
|
|
683 (if b
|
|
684 (string-to-int (buffer-substring b e))
|
|
685 a-begin)))
|
|
686 (diff-type (buffer-substring (match-beginning 4) (match-end 4)))
|
|
687 (b-begin (string-to-int (buffer-substring (match-beginning 5)
|
|
688 (match-end 5))))
|
|
689 (b-end (let ((b (match-beginning 7))
|
|
690 (e (match-end 7)))
|
0
|
691 (if b
|
|
692 (string-to-int (buffer-substring b e))
|
189
|
693 b-begin))))
|
|
694 ;; fix the beginning and end numbers, because diff is somewhat
|
|
695 ;; strange about how it numbers lines
|
|
696 (if (string-equal diff-type "a")
|
|
697 (progn
|
|
698 (setq b-end (1+ b-end))
|
|
699 (setq a-begin (1+ a-begin))
|
|
700 (setq a-end a-begin))
|
|
701 (if (string-equal diff-type "d")
|
|
702 (progn
|
|
703 (setq a-end (1+ a-end))
|
|
704 (setq b-begin (1+ b-begin))
|
|
705 (setq b-end b-begin))
|
|
706 ;; (string-equal diff-type "c")
|
|
707 (progn
|
|
708 (setq a-end (1+ a-end))
|
|
709 (setq b-end (1+ b-end)))))
|
|
710 (setq list (cons (vector a-begin a-end
|
|
711 b-begin b-end
|
|
712 'default-A)
|
|
713 list)))))
|
0
|
714 (nreverse list)))
|
|
715
|
|
716 ;; Set up buffer of diff/diff3 error messages.
|
|
717 (defun emerge-prepare-error-list (ok-regexp diff-buffer)
|
|
718 (setq emerge-diff-error-buffer (get-buffer-create "*emerge-diff-errors*"))
|
189
|
719 (with-current-buffer
|
|
720 emerge-diff-error-buffer
|
|
721 (erase-buffer)
|
|
722 (insert-buffer diff-buffer)
|
|
723 (delete-matching-lines ok-regexp)))
|
0
|
724
|
|
725 ;;; Top-level and setup functions for three-file mode.
|
|
726
|
|
727 (defun emerge-files-with-ancestor-internal (file-A file-B file-ancestor
|
|
728 &optional startup-hooks quit-hooks
|
|
729 output-file)
|
|
730 (if (not (file-readable-p file-A))
|
|
731 (error "File \"%s\" does not exist or is not readable" file-A))
|
|
732 (if (not (file-readable-p file-B))
|
|
733 (error "File \"%s\" does not exist or is not readable" file-B))
|
|
734 (if (not (file-readable-p file-ancestor))
|
|
735 (error "File \"%s\" does not exist or is not readable" file-ancestor))
|
|
736 (let ((buffer-A (find-file-noselect file-A))
|
|
737 (buffer-B (find-file-noselect file-B))
|
|
738 (buffer-ancestor (find-file-noselect file-ancestor)))
|
|
739 ;; Record the directories of the files
|
|
740 (setq emerge-last-dir-A (file-name-directory file-A))
|
|
741 (setq emerge-last-dir-B (file-name-directory file-B))
|
|
742 (setq emerge-last-dir-ancestor (file-name-directory file-ancestor))
|
|
743 (if output-file
|
|
744 (setq emerge-last-dir-output (file-name-directory output-file)))
|
|
745 ;; Make sure the entire files are seen, and they reflect what is on disk
|
189
|
746 (with-current-buffer
|
|
747 buffer-A
|
|
748 (widen)
|
|
749 (if (emerge-remote-file-p)
|
|
750 (progn
|
|
751 ;; Store in a local file
|
|
752 (setq file-A (emerge-make-temp-file "A"))
|
|
753 (write-region (point-min) (point-max) file-A nil 'no-message)
|
|
754 (setq startup-hooks
|
|
755 (cons (` (lambda () (delete-file (, file-A))))
|
|
756 startup-hooks)))
|
|
757 ;; Verify that the file matches the buffer
|
|
758 (emerge-verify-file-buffer)))
|
|
759 (with-current-buffer
|
|
760 buffer-B
|
|
761 (widen)
|
|
762 (if (emerge-remote-file-p)
|
|
763 (progn
|
|
764 ;; Store in a local file
|
|
765 (setq file-B (emerge-make-temp-file "B"))
|
|
766 (write-region (point-min) (point-max) file-B nil 'no-message)
|
|
767 (setq startup-hooks
|
|
768 (cons (` (lambda () (delete-file (, file-B))))
|
|
769 startup-hooks)))
|
|
770 ;; Verify that the file matches the buffer
|
|
771 (emerge-verify-file-buffer)))
|
|
772 (with-current-buffer
|
|
773 buffer-ancestor
|
|
774 (widen)
|
|
775 (if (emerge-remote-file-p)
|
|
776 (progn
|
|
777 ;; Store in a local file
|
|
778 (setq file-ancestor (emerge-make-temp-file "anc"))
|
|
779 (write-region (point-min) (point-max) file-ancestor nil 'no-message)
|
|
780 (setq startup-hooks
|
|
781 (cons (` (lambda () (delete-file (, file-ancestor))))
|
|
782 startup-hooks)))
|
|
783 ;; Verify that the file matches the buffer
|
|
784 (emerge-verify-file-buffer)))
|
0
|
785 (emerge-setup-with-ancestor buffer-A file-A buffer-B file-B
|
|
786 buffer-ancestor file-ancestor
|
|
787 startup-hooks quit-hooks output-file)))
|
|
788
|
|
789 ;; Start up Emerge on two files with an ancestor
|
|
790 (defun emerge-setup-with-ancestor (buffer-A file-A buffer-B file-B
|
|
791 buffer-ancestor file-ancestor
|
|
792 &optional startup-hooks quit-hooks
|
|
793 output-file)
|
|
794 (setq file-A (expand-file-name file-A))
|
|
795 (setq file-B (expand-file-name file-B))
|
|
796 (setq file-ancestor (expand-file-name file-ancestor))
|
|
797 (setq output-file (and output-file (expand-file-name output-file)))
|
|
798 (let* ((merge-buffer-name (emerge-unique-buffer-name "*merge" "*"))
|
|
799 ;; create the merge buffer from buffer A, so it inherits buffer A's
|
|
800 ;; default directory, etc.
|
189
|
801 (merge-buffer (with-current-buffer
|
|
802 buffer-A
|
|
803 (get-buffer-create merge-buffer-name))))
|
|
804 (with-current-buffer
|
|
805 merge-buffer
|
|
806 (emerge-copy-modes buffer-A)
|
|
807 (setq buffer-read-only nil)
|
|
808 (auto-save-mode 1)
|
|
809 (setq emerge-mode t)
|
|
810 (setq emerge-A-buffer buffer-A)
|
|
811 (setq emerge-B-buffer buffer-B)
|
|
812 (setq emerge-ancestor-buffer buffer-ancestor)
|
|
813 (setq emerge-merge-buffer merge-buffer)
|
|
814 (setq emerge-output-description
|
|
815 (if output-file
|
|
816 (concat "Output to file: " output-file)
|
|
817 (concat "Output to buffer: " (buffer-name merge-buffer))))
|
|
818 (insert-buffer emerge-A-buffer)
|
|
819 (emerge-set-keys)
|
|
820 (setq emerge-difference-list
|
|
821 (emerge-make-diff3-list file-A file-B file-ancestor))
|
|
822 (setq emerge-number-of-differences (length emerge-difference-list))
|
|
823 (setq emerge-current-difference -1)
|
|
824 (setq emerge-quit-hook quit-hooks)
|
|
825 (emerge-remember-buffer-characteristics)
|
|
826 (emerge-select-prefer-Bs)
|
|
827 (emerge-handle-local-variables))
|
0
|
828 (emerge-setup-windows buffer-A buffer-B merge-buffer t)
|
189
|
829 (with-current-buffer merge-buffer
|
|
830 (run-hooks 'startup-hooks 'emerge-startup-hook)
|
|
831 (setq buffer-read-only t))))
|
0
|
832
|
|
833 ;; Generate the Emerge difference list between two files with an ancestor
|
|
834 (defun emerge-make-diff3-list (file-A file-B file-ancestor)
|
|
835 (let ((diff-buffer (get-buffer-create "*emerge-diff*")))
|
189
|
836 (with-current-buffer
|
|
837 diff-buffer
|
|
838 (erase-buffer)
|
|
839 (shell-command
|
|
840 (format "%s %s %s %s %s"
|
|
841 emerge-diff3-program emerge-diff-options
|
|
842 ;; #### - fsf reverses file-ancestor and file-A, why?
|
|
843 (emerge-protect-metachars file-ancestor)
|
|
844 (emerge-protect-metachars file-A)
|
|
845 (emerge-protect-metachars file-B))
|
|
846 t))
|
0
|
847 (emerge-prepare-error-list emerge-diff3-ok-lines-regexp diff-buffer)
|
|
848 (emerge-convert-diffs-to-markers
|
|
849 emerge-A-buffer emerge-B-buffer emerge-merge-buffer
|
|
850 (emerge-extract-diffs3 diff-buffer))))
|
|
851
|
|
852 (defun emerge-extract-diffs3 (diff-buffer)
|
|
853 (let (list)
|
189
|
854 (with-current-buffer
|
|
855 diff-buffer
|
|
856 (while (re-search-forward "^====\\(.?\\)$" nil t)
|
|
857 ;; leave point after matched line
|
|
858 (beginning-of-line 2)
|
|
859 (let ((agreement (buffer-substring (match-beginning 1) (match-end 1))))
|
|
860 ;; if the A and B files are the same, ignore the difference
|
|
861 (if (not (string-equal agreement "1")) ; this goes with the file-A/ancestor reversal
|
|
862 (setq list
|
|
863 (cons
|
|
864 (let* ((pos (point))
|
|
865 (group-2 (emerge-get-diff3-group "2"))
|
|
866 (group-3 (progn (goto-char pos)
|
|
867 (emerge-get-diff3-group "3"))))
|
|
868 (vector (car group-2) (car (cdr group-2))
|
|
869 (car group-3) (car (cdr group-3))
|
|
870 (cond ((string-equal agreement "2") 'prefer-A)
|
|
871 ((string-equal agreement "3") 'prefer-B)
|
|
872 (t 'default-A))))
|
|
873 list))))))
|
0
|
874 (nreverse list)))
|
|
875
|
|
876 (defun emerge-get-diff3-group (file)
|
|
877 ;; This save-excursion allows emerge-get-diff3-group to be called for the
|
|
878 ;; various groups of lines (1, 2, 3) in any order, and for the lines to
|
|
879 ;; appear in any order. The reason this is necessary is that Gnu diff3
|
|
880 ;; can produce the groups in the order 1, 2, 3 or 1, 3, 2.
|
|
881 (save-excursion
|
|
882 (re-search-forward
|
|
883 (concat "^" file ":\\([0-9]+\\)\\(,\\([0-9]+\\)\\)?\\([ac]\\)$"))
|
|
884 (beginning-of-line 2)
|
|
885 ;; treatment depends on whether it is an "a" group or a "c" group
|
|
886 (if (string-equal (buffer-substring (match-beginning 4) (match-end 4)) "c")
|
|
887 ;; it is a "c" group
|
|
888 (if (match-beginning 2)
|
|
889 ;; it has two numbers
|
|
890 (list (string-to-int
|
|
891 (buffer-substring (match-beginning 1) (match-end 1)))
|
|
892 (1+ (string-to-int
|
|
893 (buffer-substring (match-beginning 3) (match-end 3)))))
|
|
894 ;; it has one number
|
|
895 (let ((x (string-to-int
|
|
896 (buffer-substring (match-beginning 1) (match-end 1)))))
|
|
897 (list x (1+ x))))
|
|
898 ;; it is an "a" group
|
|
899 (let ((x (1+ (string-to-int
|
|
900 (buffer-substring (match-beginning 1) (match-end 1))))))
|
|
901 (list x x)))))
|
|
902
|
|
903 ;;; Functions to start Emerge on files
|
|
904
|
|
905 ;;;###autoload
|
|
906 (defun emerge-files (arg file-A file-B file-out &optional startup-hooks
|
|
907 quit-hooks)
|
|
908 "Run Emerge on two files."
|
|
909 (interactive
|
|
910 (let (f)
|
|
911 (list current-prefix-arg
|
|
912 (setq f (emerge-read-file-name "File A to merge" emerge-last-dir-A
|
|
913 nil nil t))
|
|
914 (emerge-read-file-name "File B to merge" emerge-last-dir-B nil f t)
|
|
915 (and current-prefix-arg
|
|
916 (emerge-read-file-name "Output file" emerge-last-dir-output
|
|
917 f f nil)))))
|
|
918 (emerge-files-internal
|
|
919 file-A file-B startup-hooks
|
|
920 (if file-out
|
|
921 (cons (` (lambda () (emerge-files-exit (, file-out))))
|
|
922 quit-hooks)
|
|
923 quit-hooks)
|
|
924 file-out))
|
|
925
|
|
926 ;;;###autoload
|
|
927 (fset 'emerge 'emerge-files)
|
|
928
|
|
929 ;;;###autoload
|
|
930 (defun emerge-files-with-ancestor (arg file-A file-B file-ancestor file-out
|
|
931 &optional startup-hooks quit-hooks)
|
|
932 "Run Emerge on two files, giving another file as the ancestor."
|
|
933 (interactive
|
|
934 (let (f)
|
|
935 (list current-prefix-arg
|
|
936 (setq f (emerge-read-file-name "File A to merge" emerge-last-dir-A
|
|
937 nil nil t))
|
|
938 (emerge-read-file-name "File B to merge" emerge-last-dir-B nil f t)
|
|
939 (emerge-read-file-name "Ancestor file" emerge-last-dir-ancestor
|
|
940 nil f t)
|
|
941 (and current-prefix-arg
|
|
942 (emerge-read-file-name "Output file" emerge-last-dir-output
|
|
943 f f nil)))))
|
|
944 (emerge-files-with-ancestor-internal
|
|
945 file-A file-B file-ancestor startup-hooks
|
|
946 (if file-out
|
|
947 (cons (` (lambda () (emerge-files-exit (, file-out))))
|
|
948 quit-hooks)
|
|
949 quit-hooks)
|
|
950 file-out))
|
|
951
|
|
952 ;; Write the merge buffer out in place of the file the A buffer is visiting.
|
|
953 (defun emerge-files-exit (file-out)
|
|
954 ;; if merge was successful was given, save to disk
|
|
955 (if (not emerge-prefix-argument)
|
|
956 (emerge-write-and-delete file-out)))
|
|
957
|
|
958 ;;; Functions to start Emerge on buffers
|
|
959
|
|
960 ;;;###autoload
|
|
961 (defun emerge-buffers (buffer-A buffer-B &optional startup-hooks quit-hooks)
|
|
962 "Run Emerge on two buffers."
|
|
963 (interactive "bBuffer A to merge: \nbBuffer B to merge: ")
|
|
964 (let ((emerge-file-A (emerge-make-temp-file "A"))
|
|
965 (emerge-file-B (emerge-make-temp-file "B")))
|
189
|
966 (with-current-buffer
|
|
967 buffer-A
|
|
968 (write-region (point-min) (point-max) emerge-file-A nil 'no-message))
|
|
969 (with-current-buffer
|
|
970 buffer-B
|
|
971 (write-region (point-min) (point-max) emerge-file-B nil 'no-message))
|
0
|
972 (emerge-setup (get-buffer buffer-A) emerge-file-A
|
|
973 (get-buffer buffer-B) emerge-file-B
|
|
974 (cons (` (lambda ()
|
|
975 (delete-file (, emerge-file-A))
|
|
976 (delete-file (, emerge-file-B))))
|
|
977 startup-hooks)
|
|
978 quit-hooks
|
|
979 nil)))
|
|
980
|
|
981 ;;;###autoload
|
|
982 (defun emerge-buffers-with-ancestor (buffer-A buffer-B buffer-ancestor
|
|
983 &optional startup-hooks
|
|
984 quit-hooks)
|
|
985 "Run Emerge on two buffers, giving another buffer as the ancestor."
|
|
986 (interactive
|
|
987 "bBuffer A to merge: \nbBuffer B to merge: \nbAncestor buffer: ")
|
|
988 (let ((emerge-file-A (emerge-make-temp-file "A"))
|
|
989 (emerge-file-B (emerge-make-temp-file "B"))
|
|
990 (emerge-file-ancestor (emerge-make-temp-file "anc")))
|
189
|
991 (with-current-buffer
|
|
992 buffer-A
|
|
993 (write-region (point-min) (point-max) emerge-file-A nil 'no-message))
|
|
994 (with-current-buffer
|
|
995 buffer-B
|
|
996 (write-region (point-min) (point-max) emerge-file-B nil 'no-message))
|
|
997 (with-current-buffer
|
|
998 buffer-ancestor
|
|
999 (write-region (point-min) (point-max) emerge-file-ancestor nil
|
|
1000 'no-message))
|
0
|
1001 (emerge-setup-with-ancestor (get-buffer buffer-A) emerge-file-A
|
|
1002 (get-buffer buffer-B) emerge-file-B
|
|
1003 (get-buffer buffer-ancestor)
|
|
1004 emerge-file-ancestor
|
|
1005 (cons (` (lambda ()
|
|
1006 (delete-file (, emerge-file-A))
|
|
1007 (delete-file (, emerge-file-B))
|
|
1008 (delete-file
|
|
1009 (, emerge-file-ancestor))))
|
|
1010 startup-hooks)
|
|
1011 quit-hooks
|
|
1012 nil)))
|
|
1013
|
|
1014 ;;; Functions to start Emerge from the command line
|
|
1015
|
|
1016 ;;;###autoload
|
|
1017 (defun emerge-files-command ()
|
|
1018 (let ((file-a (nth 0 command-line-args-left))
|
|
1019 (file-b (nth 1 command-line-args-left))
|
|
1020 (file-out (nth 2 command-line-args-left)))
|
|
1021 (setq command-line-args-left (nthcdr 3 command-line-args-left))
|
|
1022 (emerge-files-internal
|
|
1023 file-a file-b nil
|
|
1024 (list (` (lambda () (emerge-command-exit (, file-out))))))))
|
|
1025
|
|
1026 ;;;###autoload
|
|
1027 (defun emerge-files-with-ancestor-command ()
|
|
1028 (let (file-a file-b file-anc file-out)
|
|
1029 ;; check for a -a flag, for filemerge compatibility
|
|
1030 (if (string= (car command-line-args-left) "-a")
|
|
1031 ;; arguments are "-a ancestor file-a file-b file-out"
|
|
1032 (progn
|
|
1033 (setq file-a (nth 2 command-line-args-left))
|
|
1034 (setq file-b (nth 3 command-line-args-left))
|
|
1035 (setq file-anc (nth 1 command-line-args-left))
|
|
1036 (setq file-out (nth 4 command-line-args-left))
|
|
1037 (setq command-line-args-left (nthcdr 5 command-line-args-left)))
|
|
1038 ;; arguments are "file-a file-b ancestor file-out"
|
|
1039 (setq file-a (nth 0 command-line-args-left))
|
|
1040 (setq file-b (nth 1 command-line-args-left))
|
|
1041 (setq file-anc (nth 2 command-line-args-left))
|
|
1042 (setq file-out (nth 3 command-line-args-left))
|
|
1043 (setq command-line-args-left (nthcdr 4 command-line-args-left)))
|
|
1044 (emerge-files-with-ancestor-internal
|
|
1045 file-a file-b file-anc nil
|
|
1046 (list (` (lambda () (emerge-command-exit (, file-out))))))))
|
|
1047
|
|
1048 (defun emerge-command-exit (file-out)
|
|
1049 (emerge-write-and-delete file-out)
|
|
1050 (kill-emacs (if emerge-prefix-argument 1 0)))
|
|
1051
|
|
1052 ;;; Functions to start Emerge via remote request
|
|
1053
|
|
1054 ;;;###autoload
|
|
1055 (defun emerge-files-remote (file-a file-b file-out)
|
|
1056 (emerge-files-internal
|
|
1057 file-a file-b nil
|
|
1058 (list (` (lambda () (emerge-remote-exit (, file-out) '(, emerge-exit-func)))))
|
|
1059 file-out)
|
|
1060 (throw 'client-wait nil))
|
|
1061
|
|
1062 ;;;###autoload
|
|
1063 (defun emerge-files-with-ancestor-remote (file-a file-b file-anc file-out)
|
|
1064 (emerge-files-with-ancestor-internal
|
|
1065 file-a file-b file-anc nil
|
|
1066 (list (` (lambda () (emerge-remote-exit (, file-out) '(, emerge-exit-func)))))
|
|
1067 file-out)
|
|
1068 (throw 'client-wait nil))
|
|
1069
|
|
1070 (defun emerge-remote-exit (file-out emerge-exit-func)
|
|
1071 (emerge-write-and-delete file-out)
|
|
1072 (kill-buffer emerge-merge-buffer)
|
|
1073 (funcall emerge-exit-func (if emerge-prefix-argument 1 0)))
|
|
1074
|
|
1075 ;;; Functions to start Emerge on RCS versions
|
|
1076
|
|
1077 ;;;###autoload
|
|
1078 (defun emerge-revisions (arg file revision-A revision-B
|
|
1079 &optional startup-hooks quit-hooks)
|
|
1080 "Emerge two RCS revisions of a file."
|
|
1081 (interactive
|
|
1082 (list current-prefix-arg
|
|
1083 (read-file-name "File to merge: " nil nil 'confirm)
|
|
1084 (read-string "Revision A to merge: " emerge-last-revision-A)
|
|
1085 (read-string "Revision B to merge: " emerge-last-revision-B)))
|
|
1086 (setq emerge-last-revision-A revision-A
|
|
1087 emerge-last-revision-B revision-B)
|
|
1088 (emerge-revisions-internal
|
|
1089 file revision-A revision-B startup-hooks
|
|
1090 (if arg
|
|
1091 (cons (` (lambda ()
|
|
1092 (shell-command
|
|
1093 (, (format "%s %s" emerge-rcs-ci-program file)))))
|
|
1094 quit-hooks)
|
|
1095 quit-hooks)))
|
|
1096
|
|
1097 ;;;###autoload
|
|
1098 (defun emerge-revisions-with-ancestor (arg file revision-A
|
|
1099 revision-B ancestor
|
|
1100 &optional
|
|
1101 startup-hooks quit-hooks)
|
|
1102 "Emerge two RCS revisions of a file, with another revision as ancestor."
|
|
1103 (interactive
|
|
1104 (list current-prefix-arg
|
|
1105 (read-file-name "File to merge: " nil nil 'confirm)
|
|
1106 (read-string "Revision A to merge: " emerge-last-revision-A)
|
|
1107 (read-string "Revision B to merge: " emerge-last-revision-B)
|
|
1108 (read-string "Ancestor: " emerge-last-revision-ancestor)))
|
|
1109 (setq emerge-last-revision-A revision-A
|
|
1110 emerge-last-revision-B revision-B
|
|
1111 emerge-last-revision-ancestor ancestor)
|
|
1112 (emerge-revision-with-ancestor-internal
|
|
1113 file revision-A revision-B ancestor startup-hooks
|
|
1114 (if arg
|
|
1115 (let ((cmd ))
|
|
1116 (cons (` (lambda ()
|
|
1117 (shell-command
|
|
1118 (, (format "%s %s" emerge-rcs-ci-program file)))))
|
|
1119 quit-hooks))
|
|
1120 quit-hooks)))
|
|
1121
|
|
1122 (defun emerge-revisions-internal (file revision-A revision-B &optional
|
|
1123 startup-hooks quit-hooks output-file)
|
|
1124 (let ((buffer-A (get-buffer-create (format "%s,%s" file revision-A)))
|
|
1125 (buffer-B (get-buffer-create (format "%s,%s" file revision-B)))
|
|
1126 (emerge-file-A (emerge-make-temp-file "A"))
|
|
1127 (emerge-file-B (emerge-make-temp-file "B")))
|
|
1128 ;; Get the revisions into buffers
|
189
|
1129 (with-current-buffer
|
|
1130 buffer-A
|
|
1131 (erase-buffer)
|
|
1132 (shell-command
|
|
1133 (format "%s -q -p%s %s" emerge-rcs-co-program revision-A file)
|
|
1134 t)
|
|
1135 (write-region (point-min) (point-max) emerge-file-A nil 'no-message)
|
|
1136 (set-buffer-modified-p nil))
|
|
1137 (with-current-buffer
|
|
1138 buffer-B
|
|
1139 (erase-buffer)
|
|
1140 (shell-command
|
|
1141 (format "%s -q -p%s %s" emerge-rcs-co-program revision-B file)
|
|
1142 t)
|
|
1143 (write-region (point-min) (point-max) emerge-file-B nil 'no-message)
|
|
1144 (set-buffer-modified-p nil))
|
0
|
1145 ;; Do the merge
|
|
1146 (emerge-setup buffer-A emerge-file-A
|
|
1147 buffer-B emerge-file-B
|
|
1148 (cons (` (lambda ()
|
|
1149 (delete-file (, emerge-file-A))
|
|
1150 (delete-file (, emerge-file-B))))
|
|
1151 startup-hooks)
|
|
1152 (cons (` (lambda () (emerge-files-exit (, file))))
|
|
1153 quit-hooks)
|
|
1154 nil)))
|
|
1155
|
|
1156 (defun emerge-revision-with-ancestor-internal (file revision-A revision-B
|
|
1157 ancestor
|
|
1158 &optional startup-hooks
|
|
1159 quit-hooks output-file)
|
|
1160 (let ((buffer-A (get-buffer-create (format "%s,%s" file revision-A)))
|
|
1161 (buffer-B (get-buffer-create (format "%s,%s" file revision-B)))
|
|
1162 (buffer-ancestor (get-buffer-create (format "%s,%s" file ancestor)))
|
|
1163 (emerge-file-A (emerge-make-temp-file "A"))
|
|
1164 (emerge-file-B (emerge-make-temp-file "B"))
|
|
1165 (emerge-ancestor (emerge-make-temp-file "ancestor")))
|
|
1166 ;; Get the revisions into buffers
|
189
|
1167 (with-current-buffer
|
|
1168 buffer-A
|
|
1169 (erase-buffer)
|
|
1170 (shell-command
|
|
1171 (format "%s -q -p%s %s" emerge-rcs-co-program
|
|
1172 revision-A file)
|
|
1173 t)
|
|
1174 (write-region (point-min) (point-max) emerge-file-A nil 'no-message)
|
|
1175 (set-buffer-modified-p nil))
|
|
1176 (with-current-buffer
|
|
1177 buffer-B
|
|
1178 (erase-buffer)
|
|
1179 (shell-command
|
|
1180 (format "%s -q -p%s %s" emerge-rcs-co-program revision-B file)
|
|
1181 t)
|
|
1182 (write-region (point-min) (point-max) emerge-file-B nil 'no-message)
|
|
1183 (set-buffer-modified-p nil))
|
|
1184 (with-current-buffer
|
|
1185 buffer-ancestor
|
|
1186 (erase-buffer)
|
|
1187 (shell-command
|
|
1188 (format "%s -q -p%s %s" emerge-rcs-co-program ancestor file)
|
|
1189 t)
|
|
1190 (write-region (point-min) (point-max) emerge-ancestor nil 'no-message)
|
|
1191 (set-buffer-modified-p nil))
|
0
|
1192 ;; Do the merge
|
|
1193 (emerge-setup-with-ancestor
|
|
1194 buffer-A emerge-file-A buffer-B emerge-file-B
|
|
1195 buffer-ancestor emerge-ancestor
|
|
1196 (cons (` (lambda ()
|
|
1197 (delete-file (, emerge-file-A))
|
|
1198 (delete-file (, emerge-file-B))
|
|
1199 (delete-file (, emerge-ancestor))))
|
|
1200 startup-hooks)
|
|
1201 (cons (` (lambda () (emerge-files-exit (, file))))
|
|
1202 quit-hooks)
|
|
1203 output-file)))
|
|
1204
|
|
1205 ;;; Function to start Emerge based on a line in a file
|
|
1206
|
|
1207 (defun emerge-execute-line ()
|
|
1208 "Run Emerge using files named in current text line.
|
|
1209 Looks in that line for whitespace-separated entries of these forms:
|
|
1210 a=file1
|
|
1211 b=file2
|
|
1212 ancestor=file3
|
|
1213 output=file4
|
|
1214 to specify the files to use in Emerge.
|
|
1215
|
|
1216 In addition, if only one of `a=file' or `b=file' is present,
|
|
1217 and `output=file' is present:
|
|
1218 If `emerge-execute-line-deletions' is non-nil and `ancestor=file'
|
|
1219 is present, it is assumed that the file in question has been deleted,
|
|
1220 and it is not copied to the output file.
|
|
1221 Otherwise, the A or B file present is copied to the output file."
|
|
1222 (interactive)
|
|
1223 (let (file-A file-B file-ancestor file-out
|
|
1224 (case-fold-search t))
|
|
1225 ;; Stop if at end of buffer (even though we might be in a line, if
|
|
1226 ;; the line does not end with newline)
|
|
1227 (if (eobp)
|
|
1228 (error "At end of buffer"))
|
|
1229 ;; Go to the beginning of the line
|
|
1230 (beginning-of-line)
|
|
1231 ;; Skip any initial whitespace
|
|
1232 (if (looking-at "[ \t]*")
|
|
1233 (goto-char (match-end 0)))
|
|
1234 ;; Process the entire line
|
|
1235 (while (not (eolp))
|
|
1236 ;; Get the next entry
|
|
1237 (if (looking-at "\\([a-z]+\\)=\\([^ \t\n]+\\)[ \t]*")
|
|
1238 ;; Break apart the tab (before =) and the filename (after =)
|
|
1239 (let ((tag (downcase
|
|
1240 (buffer-substring (match-beginning 1) (match-end 1))))
|
|
1241 (file (buffer-substring (match-beginning 2) (match-end 2))))
|
|
1242 ;; Move point after the entry
|
|
1243 (goto-char (match-end 0))
|
|
1244 ;; Store the filename in the right variable
|
|
1245 (cond
|
|
1246 ((string-equal tag "a")
|
|
1247 (if file-A
|
|
1248 (error "This line has two `A' entries"))
|
|
1249 (setq file-A file))
|
|
1250 ((string-equal tag "b")
|
|
1251 (if file-B
|
|
1252 (error "This line has two `B' entries"))
|
|
1253 (setq file-B file))
|
|
1254 ((or (string-equal tag "anc") (string-equal tag "ancestor"))
|
|
1255 (if file-ancestor
|
|
1256 (error "This line has two `ancestor' entries"))
|
|
1257 (setq file-ancestor file))
|
|
1258 ((or (string-equal tag "out") (string-equal tag "output"))
|
|
1259 (if file-out
|
|
1260 (error "This line has two `output' entries"))
|
|
1261 (setq file-out file))
|
|
1262 (t
|
|
1263 (error "Unrecognized entry"))))
|
|
1264 ;; If the match on the entry pattern failed
|
|
1265 (error "Unparsable entry")))
|
|
1266 ;; Make sure that file-A and file-B are present
|
|
1267 (if (not (or (and file-A file-B) file-out))
|
|
1268 (error "Must have both `A' and `B' entries"))
|
|
1269 (if (not (or file-A file-B))
|
|
1270 (error "Must have `A' or `B' entry"))
|
|
1271 ;; Go to the beginning of the next line, so next execution will use
|
|
1272 ;; next line in buffer.
|
|
1273 (beginning-of-line 2)
|
|
1274 ;; Execute the correct command
|
|
1275 (cond
|
|
1276 ;; Merge of two files with ancestor
|
|
1277 ((and file-A file-B file-ancestor)
|
|
1278 (message "Merging %s and %s..." file-A file-B)
|
|
1279 (emerge-files-with-ancestor (not (not file-out)) file-A file-B
|
|
1280 file-ancestor file-out
|
|
1281 nil
|
|
1282 ;; When done, return to this buffer.
|
|
1283 (list
|
|
1284 (` (lambda ()
|
|
1285 (switch-to-buffer (, (current-buffer)))
|
|
1286 (message "Merge done."))))))
|
|
1287 ;; Merge of two files without ancestor
|
|
1288 ((and file-A file-B)
|
|
1289 (message "Merging %s and %s..." file-A file-B)
|
|
1290 (emerge-files (not (not file-out)) file-A file-B file-out
|
|
1291 nil
|
|
1292 ;; When done, return to this buffer.
|
|
1293 (list
|
|
1294 (` (lambda ()
|
|
1295 (switch-to-buffer (, (current-buffer)))
|
|
1296 (message "Merge done."))))))
|
|
1297 ;; There is an output file (or there would have been an error above),
|
|
1298 ;; but only one input file.
|
|
1299 ;; The file appears to have been deleted in one version; do nothing.
|
|
1300 ((and file-ancestor emerge-execute-line-deletions)
|
|
1301 (message "No action."))
|
|
1302 ;; The file should be copied from the version that contains it
|
|
1303 (t (let ((input-file (or file-A file-B)))
|
|
1304 (message "Copying...")
|
|
1305 (copy-file input-file file-out)
|
|
1306 (message "%s copied to %s." input-file file-out))))))
|
|
1307
|
|
1308 ;;; Sample function for creating information for emerge-execute-line
|
|
1309
|
|
1310 (defvar emerge-merge-directories-filename-regexp "[^.]"
|
|
1311 "Regexp describing files to be processed by `emerge-merge-directories'.")
|
|
1312
|
|
1313 ;;;###autoload
|
|
1314 (defun emerge-merge-directories (a-dir b-dir ancestor-dir output-dir)
|
|
1315 (interactive
|
|
1316 (list
|
|
1317 (read-file-name "A directory: " nil nil 'confirm)
|
|
1318 (read-file-name "B directory: " nil nil 'confirm)
|
|
1319 (read-file-name "Ancestor directory (null for none): " nil nil 'confirm)
|
|
1320 (read-file-name "Output directory (null for none): " nil nil 'confirm)))
|
|
1321 ;; Check that we're not on a line
|
|
1322 (if (not (and (bolp) (eolp)))
|
|
1323 (error "There is text on this line"))
|
|
1324 ;; Turn null strings into nil to indicate directories not used.
|
|
1325 (if (and ancestor-dir (string-equal ancestor-dir ""))
|
|
1326 (setq ancestor-dir nil))
|
|
1327 (if (and output-dir (string-equal output-dir ""))
|
|
1328 (setq output-dir nil))
|
|
1329 ;; Canonicalize the directory names
|
|
1330 (setq a-dir (expand-file-name a-dir))
|
|
1331 (if (not (string-equal (substring a-dir -1) "/"))
|
|
1332 (setq a-dir (concat a-dir "/")))
|
|
1333 (setq b-dir (expand-file-name b-dir))
|
|
1334 (if (not (string-equal (substring b-dir -1) "/"))
|
|
1335 (setq b-dir (concat b-dir "/")))
|
|
1336 (if ancestor-dir
|
|
1337 (progn
|
|
1338 (setq ancestor-dir (expand-file-name ancestor-dir))
|
|
1339 (if (not (string-equal (substring ancestor-dir -1) "/"))
|
|
1340 (setq ancestor-dir (concat ancestor-dir "/")))))
|
|
1341 (if output-dir
|
|
1342 (progn
|
|
1343 (setq output-dir (expand-file-name output-dir))
|
|
1344 (if (not (string-equal (substring output-dir -1) "/"))
|
|
1345 (setq output-dir (concat output-dir "/")))))
|
|
1346 ;; Set the mark to where we start
|
|
1347 (push-mark)
|
|
1348 ;; Find out what files are in the directories.
|
|
1349 (let* ((a-dir-files
|
|
1350 (directory-files a-dir nil emerge-merge-directories-filename-regexp))
|
|
1351 (b-dir-files
|
|
1352 (directory-files b-dir nil emerge-merge-directories-filename-regexp))
|
|
1353 (ancestor-dir-files
|
|
1354 (and ancestor-dir
|
|
1355 (directory-files ancestor-dir nil
|
|
1356 emerge-merge-directories-filename-regexp)))
|
|
1357 (all-files (sort (nconc (copy-sequence a-dir-files)
|
|
1358 (copy-sequence b-dir-files)
|
|
1359 (copy-sequence ancestor-dir-files))
|
|
1360 (function string-lessp))))
|
|
1361 ;; Remove duplicates from all-files.
|
|
1362 (let ((p all-files))
|
|
1363 (while p
|
|
1364 (if (and (cdr p) (string-equal (car p) (car (cdr p))))
|
|
1365 (setcdr p (cdr (cdr p)))
|
|
1366 (setq p (cdr p)))))
|
|
1367 ;; Generate the control lines for the various files.
|
|
1368 (while all-files
|
|
1369 (let ((f (car all-files)))
|
|
1370 (setq all-files (cdr all-files))
|
|
1371 (if (and a-dir-files (string-equal (car a-dir-files) f))
|
|
1372 (progn
|
|
1373 (insert "A=" a-dir f "\t")
|
|
1374 (setq a-dir-files (cdr a-dir-files))))
|
|
1375 (if (and b-dir-files (string-equal (car b-dir-files) f))
|
|
1376 (progn
|
|
1377 (insert "B=" b-dir f "\t")
|
|
1378 (setq b-dir-files (cdr b-dir-files))))
|
|
1379 (if (and ancestor-dir-files (string-equal (car ancestor-dir-files) f))
|
|
1380 (progn
|
|
1381 (insert "ancestor=" ancestor-dir f "\t")
|
|
1382 (setq ancestor-dir-files (cdr ancestor-dir-files))))
|
|
1383 (if output-dir
|
|
1384 (insert "output=" output-dir f "\t"))
|
|
1385 (backward-delete-char 1)
|
|
1386 (insert "\n")))))
|
|
1387
|
|
1388 ;;; Common setup routines
|
|
1389
|
|
1390 ;; Set up the window configuration. If POS is given, set the points to
|
|
1391 ;; the beginnings of the buffers.
|
|
1392 (defun emerge-setup-windows (buffer-A buffer-B merge-buffer &optional pos)
|
|
1393 ;; Make sure we are not in the minibuffer window when we try to delete
|
|
1394 ;; all other windows.
|
|
1395 (if (eq (selected-window) (minibuffer-window))
|
|
1396 (other-window 1))
|
|
1397 (delete-other-windows)
|
|
1398 (switch-to-buffer merge-buffer)
|
|
1399 (emerge-refresh-mode-line)
|
|
1400 ;; in v18, split-window and split-window-vertically were the same,
|
|
1401 ;; but in v19, split-window-vertically might select the other window.
|
|
1402 ;; (split-window-vertically)
|
|
1403 (split-window)
|
|
1404 (if emerge-split-horizontally
|
|
1405 (split-window-horizontally)
|
|
1406 (split-window))
|
|
1407 (switch-to-buffer buffer-A)
|
|
1408 (if pos
|
|
1409 (goto-char (point-min)))
|
|
1410 (other-window 1)
|
|
1411 (switch-to-buffer buffer-B)
|
|
1412 (if pos
|
|
1413 (goto-char (point-min)))
|
|
1414 (other-window 1)
|
|
1415 (if pos
|
|
1416 (goto-char (point-min)))
|
|
1417 ;; If diff/diff3 reports errors, display them rather than the merge buffer.
|
189
|
1418 (if (/= 0 (with-current-buffer emerge-diff-error-buffer (buffer-size)))
|
0
|
1419 (progn
|
|
1420 (ding)
|
|
1421 (message "Errors found in diff/diff3 output. Merge buffer is %s."
|
|
1422 (buffer-name emerge-merge-buffer))
|
|
1423 (switch-to-buffer emerge-diff-error-buffer))))
|
|
1424
|
|
1425 ;; Set up the keymap in the merge buffer
|
|
1426 (defun emerge-set-keys ()
|
|
1427 ;; Set up fixed keymaps if necessary
|
|
1428 (if (not emerge-basic-keymap)
|
|
1429 (emerge-setup-fixed-keymaps))
|
|
1430 ;; Save the old local map
|
|
1431 (setq emerge-old-keymap (current-local-map))
|
|
1432 ;; Construct the edit keymap
|
|
1433 (setq emerge-edit-keymap (if emerge-old-keymap
|
|
1434 (copy-keymap emerge-old-keymap)
|
|
1435 (make-sparse-keymap)))
|
|
1436 ;; Install the Emerge commands
|
|
1437 (emerge-force-define-key emerge-edit-keymap emerge-command-prefix
|
|
1438 'emerge-basic-keymap)
|
|
1439 ;;fsf (define-key emerge-edit-keymap [menu-bar] (make-sparse-keymap))
|
|
1440 ;;fsf
|
|
1441 ;;fsf ;; Create the additional menu bar items.
|
|
1442 ;;fsf (define-key emerge-edit-keymap [menu-bar options]
|
|
1443 ;;fsf (cons "Options" emerge-options-menu))
|
|
1444 ;;fsf (define-key emerge-edit-keymap [menu-bar merge]
|
|
1445 ;;fsf (cons "Merge" emerge-merge-menu))
|
|
1446 ;;fsf (define-key emerge-edit-keymap [menu-bar move]
|
|
1447 ;;fsf (cons "Move" emerge-move-menu))
|
|
1448
|
|
1449 ;; Suppress write-file and save-buffer
|
|
1450 (substitute-key-definition 'write-file 'emerge-query-write-file
|
|
1451 emerge-edit-keymap (current-global-map))
|
|
1452 (substitute-key-definition 'save-buffer 'emerge-query-save-buffer
|
|
1453 emerge-edit-keymap (current-global-map))
|
|
1454 (substitute-key-definition 'write-file 'emerge-query-write-file
|
|
1455 emerge-edit-keymap (current-global-map))
|
|
1456 (substitute-key-definition 'save-buffer 'emerge-query-save-buffer
|
|
1457 emerge-edit-keymap (current-global-map))
|
|
1458 (use-local-map emerge-fast-keymap)
|
|
1459 (make-local-variable 'current-menubar)
|
|
1460 (add-menu nil "Emerge" emerge-mode-menu)
|
|
1461 (setq emerge-edit-mode nil)
|
|
1462 (setq emerge-fast-mode t))
|
|
1463
|
|
1464 (defun emerge-remember-buffer-characteristics ()
|
|
1465 "Record certain properties of the buffers being merged.
|
|
1466 Must be called in the merge buffer. Remembers read-only, modified,
|
|
1467 auto-save, and saves them in buffer local variables. Sets the buffers
|
|
1468 read-only and turns off `auto-save-mode'.
|
|
1469 These characteristics are restored by `emerge-restore-buffer-characteristics'."
|
|
1470 ;; force auto-save, because we will turn off auto-saving in buffers for the
|
|
1471 ;; duration
|
|
1472 (do-auto-save)
|
|
1473 ;; remember and alter buffer characteristics
|
|
1474 (setq emerge-A-buffer-values
|
189
|
1475 (with-current-buffer
|
|
1476 emerge-A-buffer
|
|
1477 (prog1
|
|
1478 (emerge-save-variables emerge-saved-variables)
|
|
1479 (emerge-restore-variables emerge-saved-variables
|
|
1480 emerge-merging-values))))
|
0
|
1481 (setq emerge-B-buffer-values
|
189
|
1482 (with-current-buffer
|
|
1483 emerge-B-buffer
|
|
1484 (prog1
|
|
1485 (emerge-save-variables emerge-saved-variables)
|
|
1486 (emerge-restore-variables emerge-saved-variables
|
|
1487 emerge-merging-values)))))
|
0
|
1488
|
|
1489 (defun emerge-restore-buffer-characteristics ()
|
|
1490 "Restores characteristics saved by `emerge-remember-buffer-characteristics'."
|
|
1491 (let ((A-values emerge-A-buffer-values)
|
|
1492 (B-values emerge-B-buffer-values))
|
189
|
1493 (with-current-buffer emerge-A-buffer
|
|
1494 (emerge-restore-variables emerge-saved-variables
|
|
1495 A-values))
|
|
1496 (with-current-buffer emerge-B-buffer
|
|
1497 (emerge-restore-variables emerge-saved-variables
|
|
1498 B-values))))
|
0
|
1499 ;; Move to line DESIRED-LINE assuming we are at line CURRENT-LINE.
|
|
1500 ;; Return DESIRED-LINE.
|
|
1501 (defun emerge-goto-line (desired-line current-line)
|
|
1502 (forward-line (- desired-line current-line))
|
|
1503 desired-line)
|
|
1504
|
|
1505 (defun emerge-convert-diffs-to-markers (A-buffer
|
|
1506 B-buffer
|
|
1507 merge-buffer
|
|
1508 lineno-list)
|
|
1509 (let* (marker-list
|
189
|
1510 (A-point-min (with-current-buffer A-buffer (point-min)))
|
0
|
1511 (offset (1- A-point-min))
|
189
|
1512 (B-point-min (with-current-buffer B-buffer (point-min)))
|
0
|
1513 ;; Record current line number in each buffer
|
|
1514 ;; so we don't have to count from the beginning.
|
|
1515 (a-line 1)
|
|
1516 (b-line 1))
|
189
|
1517 (with-current-buffer A-buffer (goto-char (point-min)))
|
|
1518 (with-current-buffer B-buffer (goto-char (point-min)))
|
0
|
1519 (while lineno-list
|
|
1520 (let* ((list-element (car lineno-list))
|
|
1521 a-begin-marker
|
|
1522 a-end-marker
|
|
1523 b-begin-marker
|
|
1524 b-end-marker
|
|
1525 merge-begin-marker
|
|
1526 merge-end-marker
|
|
1527 (a-begin (aref list-element 0))
|
|
1528 (a-end (aref list-element 1))
|
|
1529 (b-begin (aref list-element 2))
|
|
1530 (b-end (aref list-element 3))
|
|
1531 (state (aref list-element 4)))
|
|
1532 ;; place markers at the appropriate places in the buffers
|
189
|
1533 (with-current-buffer
|
|
1534 A-buffer
|
|
1535 (setq a-line (emerge-goto-line a-begin a-line))
|
|
1536 (setq a-begin-marker (point-marker))
|
|
1537 (setq a-line (emerge-goto-line a-end a-line))
|
|
1538 (setq a-end-marker (point-marker)))
|
|
1539 (with-current-buffer
|
|
1540 B-buffer
|
|
1541 (setq b-line (emerge-goto-line b-begin b-line))
|
|
1542 (setq b-begin-marker (point-marker))
|
|
1543 (setq b-line (emerge-goto-line b-end b-line))
|
|
1544 (setq b-end-marker (point-marker)))
|
0
|
1545 (setq merge-begin-marker (set-marker
|
|
1546 (make-marker)
|
|
1547 (- (marker-position a-begin-marker)
|
|
1548 offset)
|
|
1549 merge-buffer))
|
|
1550 (setq merge-end-marker (set-marker
|
|
1551 (make-marker)
|
|
1552 (- (marker-position a-end-marker)
|
|
1553 offset)
|
|
1554 merge-buffer))
|
|
1555 ;; record all the markers for this difference
|
|
1556 (setq marker-list (cons (vector a-begin-marker a-end-marker
|
|
1557 b-begin-marker b-end-marker
|
|
1558 merge-begin-marker merge-end-marker
|
|
1559 state)
|
|
1560 marker-list)))
|
|
1561 (setq lineno-list (cdr lineno-list)))
|
|
1562 ;; convert the list of difference information into a vector for
|
|
1563 ;; fast access
|
|
1564 (setq emerge-difference-list (apply 'vector (nreverse marker-list)))))
|
|
1565
|
|
1566 ;; If we have an ancestor, select all B variants that we prefer
|
|
1567 (defun emerge-select-prefer-Bs ()
|
|
1568 (let ((n 0))
|
|
1569 (while (< n emerge-number-of-differences)
|
|
1570 (if (eq (aref (aref emerge-difference-list n) 6) 'prefer-B)
|
|
1571 (progn
|
|
1572 (emerge-unselect-and-select-difference n t)
|
|
1573 (emerge-select-B)
|
|
1574 (aset (aref emerge-difference-list n) 6 'prefer-B)))
|
|
1575 (setq n (1+ n))))
|
|
1576 (emerge-unselect-and-select-difference -1))
|
|
1577
|
|
1578 ;; Process the local-variables list at the end of the merged file, if
|
|
1579 ;; requested.
|
|
1580 (defun emerge-handle-local-variables ()
|
|
1581 (if emerge-process-local-variables
|
|
1582 (condition-case err
|
|
1583 (hack-local-variables t)
|
|
1584 (error (message "Local-variables error in merge buffer: %s"
|
|
1585 (prin1-to-string err))))))
|
|
1586
|
|
1587 ;;; Common exit routines
|
|
1588
|
|
1589 (defun emerge-write-and-delete (file-out)
|
|
1590 ;; clear screen format
|
|
1591 (delete-other-windows)
|
|
1592 ;; delete A, B, and ancestor buffers, if they haven't been changed
|
|
1593 (if (not (buffer-modified-p emerge-A-buffer))
|
|
1594 (kill-buffer emerge-A-buffer))
|
|
1595 (if (not (buffer-modified-p emerge-B-buffer))
|
|
1596 (kill-buffer emerge-B-buffer))
|
|
1597 (if (and emerge-ancestor-buffer
|
|
1598 (not (buffer-modified-p emerge-ancestor-buffer)))
|
|
1599 (kill-buffer emerge-ancestor-buffer))
|
|
1600 ;; Write merge buffer to file
|
|
1601 (and file-out
|
|
1602 (write-file file-out)))
|
|
1603
|
|
1604 ;;; Commands
|
|
1605
|
|
1606 (defun emerge-recenter (&optional arg)
|
|
1607 "Bring the highlighted region of all three merge buffers into view.
|
|
1608 This brings the buffers into view if they are in windows.
|
|
1609 With an argument, reestablish the default three-window display."
|
|
1610 (interactive "P")
|
|
1611 ;; If there is an argument, rebuild the window structure
|
|
1612 (if arg
|
|
1613 (emerge-setup-windows emerge-A-buffer emerge-B-buffer
|
|
1614 emerge-merge-buffer))
|
|
1615 ;; Redisplay whatever buffers are showing, if there is a selected difference
|
|
1616 (if (and (>= emerge-current-difference 0)
|
|
1617 (< emerge-current-difference emerge-number-of-differences))
|
|
1618 (let* ((merge-buffer emerge-merge-buffer)
|
|
1619 (buffer-A emerge-A-buffer)
|
|
1620 (buffer-B emerge-B-buffer)
|
|
1621 (window-A (get-buffer-window buffer-A 'visible))
|
|
1622 (window-B (get-buffer-window buffer-B 'visible))
|
|
1623 (merge-window (get-buffer-window merge-buffer))
|
|
1624 (diff-vector
|
|
1625 (aref emerge-difference-list emerge-current-difference)))
|
|
1626 ;; note that emerge-{before,after}-flag-length are meaningless
|
|
1627 ;; when (not emerge-mark-with-text). -jwz.
|
|
1628 (if window-A (progn
|
|
1629 (select-window window-A)
|
|
1630 (emerge-position-region
|
|
1631 (- (aref diff-vector 0)
|
|
1632 (if emerge-mark-with-text
|
|
1633 (1- emerge-before-flag-length)
|
|
1634 0))
|
|
1635 (+ (aref diff-vector 1)
|
|
1636 (if emerge-mark-with-text
|
|
1637 (1- emerge-after-flag-length)
|
|
1638 0))
|
|
1639 (1+ (aref diff-vector 0)))))
|
|
1640 (if window-B (progn
|
|
1641 (select-window window-B)
|
|
1642 (emerge-position-region
|
|
1643 (- (aref diff-vector 2)
|
|
1644 (if emerge-mark-with-text
|
|
1645 (1- emerge-before-flag-length)
|
|
1646 0))
|
|
1647 (+ (aref diff-vector 3)
|
|
1648 (if emerge-mark-with-text
|
|
1649 (1- emerge-after-flag-length)
|
|
1650 0))
|
|
1651 (1+ (aref diff-vector 2)))))
|
|
1652 (if merge-window (progn
|
|
1653 (select-window merge-window)
|
|
1654 (emerge-position-region
|
|
1655 (- (aref diff-vector 4)
|
|
1656 (if emerge-mark-with-text
|
|
1657 (1- emerge-before-flag-length)
|
|
1658 0))
|
|
1659 (+ (aref diff-vector 5)
|
|
1660 (if emerge-mark-with-text
|
|
1661 (1- emerge-after-flag-length)
|
|
1662 0))
|
|
1663 (1+ (aref diff-vector 4))))))))
|
|
1664
|
|
1665 ;;; Window scrolling operations
|
|
1666 ;; These operations are designed to scroll all three windows the same amount,
|
|
1667 ;; so as to keep the text in them aligned.
|
|
1668
|
|
1669 ;; Perform some operation on all three windows (if they are showing).
|
|
1670 ;; Catches all errors on the operation in the A and B windows, but not
|
|
1671 ;; in the merge window. Usually, errors come from scrolling off the
|
|
1672 ;; beginning or end of the buffer, and this gives a nice error message:
|
|
1673 ;; End of buffer is reported in the merge buffer, but if the scroll was
|
|
1674 ;; possible in the A or B windows, it is performed there before the error
|
|
1675 ;; is reported.
|
|
1676 (defun emerge-operate-on-windows (operation arg)
|
|
1677 (let* ((merge-buffer emerge-merge-buffer)
|
|
1678 (buffer-A emerge-A-buffer)
|
|
1679 (buffer-B emerge-B-buffer)
|
|
1680 (window-A (get-buffer-window buffer-A 'visible))
|
|
1681 (window-B (get-buffer-window buffer-B 'visible))
|
|
1682 (merge-window (get-buffer-window merge-buffer)))
|
|
1683 (if window-A (progn
|
|
1684 (select-window window-A)
|
|
1685 (condition-case nil
|
|
1686 (funcall operation arg)
|
|
1687 (error))))
|
|
1688 (if window-B (progn
|
|
1689 (select-window window-B)
|
|
1690 (condition-case nil
|
|
1691 (funcall operation arg)
|
|
1692 (error))))
|
|
1693 (if merge-window (progn
|
|
1694 (select-window merge-window)
|
|
1695 (funcall operation arg)))))
|
|
1696
|
|
1697 (defun emerge-scroll-up (&optional arg)
|
|
1698 "Scroll up all three merge buffers, if they are in windows.
|
|
1699 With argument N, scroll N lines; otherwise scroll by nearly
|
|
1700 the height of the merge window.
|
|
1701 `C-u -' alone as argument scrolls half the height of the merge window."
|
|
1702 (interactive "P")
|
|
1703 (emerge-operate-on-windows
|
|
1704 'scroll-up
|
|
1705 ;; calculate argument to scroll-up
|
|
1706 ;; if there is an explicit argument
|
|
1707 (if (and arg (not (equal arg '-)))
|
|
1708 ;; use it
|
|
1709 (prefix-numeric-value arg)
|
|
1710 ;; if not, see if we can determine a default amount (the window height)
|
|
1711 (let ((merge-window (get-buffer-window emerge-merge-buffer)))
|
|
1712 (if (null merge-window)
|
|
1713 ;; no window, use nil
|
|
1714 nil
|
|
1715 (let ((default-amount
|
|
1716 (- (window-height merge-window) 1 next-screen-context-lines)))
|
|
1717 ;; the window was found
|
|
1718 (if arg
|
|
1719 ;; C-u as argument means half of default amount
|
|
1720 (/ default-amount 2)
|
|
1721 ;; no argument means default amount
|
|
1722 default-amount)))))))
|
|
1723
|
|
1724 (defun emerge-scroll-down (&optional arg)
|
|
1725 "Scroll down all three merge buffers, if they are in windows.
|
|
1726 With argument N, scroll N lines; otherwise scroll by nearly
|
|
1727 the height of the merge window.
|
|
1728 `C-u -' alone as argument scrolls half the height of the merge window."
|
|
1729 (interactive "P")
|
|
1730 (emerge-operate-on-windows
|
|
1731 'scroll-down
|
|
1732 ;; calculate argument to scroll-down
|
|
1733 ;; if there is an explicit argument
|
|
1734 (if (and arg (not (equal arg '-)))
|
|
1735 ;; use it
|
|
1736 (prefix-numeric-value arg)
|
|
1737 ;; if not, see if we can determine a default amount (the window height)
|
|
1738 (let ((merge-window (get-buffer-window emerge-merge-buffer)))
|
|
1739 (if (null merge-window)
|
|
1740 ;; no window, use nil
|
|
1741 nil
|
|
1742 (let ((default-amount
|
|
1743 (- (window-height merge-window) 1 next-screen-context-lines)))
|
|
1744 ;; the window was found
|
|
1745 (if arg
|
|
1746 ;; C-u as argument means half of default amount
|
|
1747 (/ default-amount 2)
|
|
1748 ;; no argument means default amount
|
|
1749 default-amount)))))))
|
|
1750
|
|
1751 (defun emerge-scroll-left (&optional arg)
|
|
1752 "Scroll left all three merge buffers, if they are in windows.
|
|
1753 If an argument is given, that is how many columns are scrolled, else nearly
|
|
1754 the width of the A and B windows. `C-u -' alone as argument scrolls half the
|
|
1755 width of the A and B windows."
|
|
1756 (interactive "P")
|
|
1757 (emerge-operate-on-windows
|
|
1758 'scroll-left
|
|
1759 ;; calculate argument to scroll-left
|
|
1760 ;; if there is an explicit argument
|
|
1761 (if (and arg (not (equal arg '-)))
|
|
1762 ;; use it
|
|
1763 (prefix-numeric-value arg)
|
|
1764 ;; if not, see if we can determine a default amount
|
|
1765 ;; (half the window width)
|
|
1766 (let ((merge-window (get-buffer-window emerge-merge-buffer)))
|
|
1767 (if (null merge-window)
|
|
1768 ;; no window, use nil
|
|
1769 nil
|
|
1770 (let ((default-amount
|
|
1771 (- (/ (window-width merge-window) 2) 3)))
|
|
1772 ;; the window was found
|
|
1773 (if arg
|
|
1774 ;; C-u as argument means half of default amount
|
|
1775 (/ default-amount 2)
|
|
1776 ;; no argument means default amount
|
|
1777 default-amount)))))))
|
|
1778
|
|
1779 (defun emerge-scroll-right (&optional arg)
|
|
1780 "Scroll right all three merge buffers, if they are in windows.
|
|
1781 If an argument is given, that is how many columns are scrolled, else nearly
|
|
1782 the width of the A and B windows. `C-u -' alone as argument scrolls half the
|
|
1783 width of the A and B windows."
|
|
1784 (interactive "P")
|
|
1785 (emerge-operate-on-windows
|
|
1786 'scroll-right
|
|
1787 ;; calculate argument to scroll-right
|
|
1788 ;; if there is an explicit argument
|
|
1789 (if (and arg (not (equal arg '-)))
|
|
1790 ;; use it
|
|
1791 (prefix-numeric-value arg)
|
|
1792 ;; if not, see if we can determine a default amount
|
|
1793 ;; (half the window width)
|
|
1794 (let ((merge-window (get-buffer-window emerge-merge-buffer)))
|
|
1795 (if (null merge-window)
|
|
1796 ;; no window, use nil
|
|
1797 nil
|
|
1798 (let ((default-amount
|
|
1799 (- (/ (window-width merge-window) 2) 3)))
|
|
1800 ;; the window was found
|
|
1801 (if arg
|
|
1802 ;; C-u as argument means half of default amount
|
|
1803 (/ default-amount 2)
|
|
1804 ;; no argument means default amount
|
|
1805 default-amount)))))))
|
|
1806
|
|
1807 (defun emerge-scroll-reset ()
|
|
1808 "Reset horizontal scrolling in Emerge.
|
|
1809 This resets the horizontal scrolling of all three merge buffers
|
|
1810 to the left margin, if they are in windows."
|
|
1811 (interactive)
|
|
1812 (emerge-operate-on-windows
|
|
1813 (function (lambda (x) (set-window-hscroll (selected-window) 0)))
|
|
1814 nil))
|
|
1815
|
|
1816 ;; Attempt to show the region nicely.
|
|
1817 ;; If there are min-lines lines above and below the region, then don't do
|
|
1818 ;; anything.
|
|
1819 ;; If not, recenter the region to make it so.
|
|
1820 ;; If that isn't possible, remove context lines balancedly from top and botton
|
|
1821 ;; so the entire region shows.
|
|
1822 ;; If that isn't possible, show the top of the region.
|
|
1823 ;; BEG must be at the beginning of a line.
|
|
1824 (defun emerge-position-region (beg end pos)
|
|
1825 ;; First test whether the entire region is visible with
|
|
1826 ;; emerge-min-visible-lines above and below it
|
|
1827 (if (not (and (<= (progn
|
|
1828 (move-to-window-line emerge-min-visible-lines)
|
|
1829 (point))
|
|
1830 beg)
|
|
1831 (<= end (progn
|
|
1832 (move-to-window-line
|
|
1833 (- (1+ emerge-min-visible-lines)))
|
|
1834 (point)))))
|
|
1835 ;; We failed that test, see if it fits at all
|
|
1836 ;; Meanwhile positioning it correctly in case it doesn't fit
|
|
1837 (progn
|
|
1838 (set-window-start (selected-window) beg)
|
|
1839 (if (pos-visible-in-window-p end)
|
|
1840 ;; Determine the number of lines that the region occupies
|
|
1841 (let ((lines 0))
|
|
1842 (while (> end (progn
|
|
1843 (move-to-window-line lines)
|
|
1844 (point)))
|
|
1845 (setq lines (1+ lines)))
|
|
1846 ;; And position the beginning on the right line
|
|
1847 (goto-char beg)
|
|
1848 (recenter (/ (1+ (- (1- (window-height (selected-window)))
|
|
1849 lines))
|
|
1850 2))))))
|
|
1851 (goto-char pos))
|
|
1852
|
|
1853 (defun emerge-next-difference ()
|
|
1854 "Advance to the next difference."
|
|
1855 (interactive)
|
|
1856 (if (< emerge-current-difference emerge-number-of-differences)
|
|
1857 (let ((n (1+ emerge-current-difference)))
|
|
1858 (while (and emerge-skip-prefers
|
|
1859 (< n emerge-number-of-differences)
|
|
1860 (memq (aref (aref emerge-difference-list n) 6)
|
|
1861 '(prefer-A prefer-B)))
|
|
1862 (setq n (1+ n)))
|
|
1863 (let ((buffer-read-only nil))
|
|
1864 (emerge-unselect-and-select-difference n)))
|
|
1865 (error "At end")))
|
|
1866
|
|
1867 (defun emerge-previous-difference ()
|
|
1868 "Go to the previous difference."
|
|
1869 (interactive)
|
|
1870 (if (> emerge-current-difference -1)
|
|
1871 (let ((n (1- emerge-current-difference)))
|
|
1872 (while (and emerge-skip-prefers
|
|
1873 (> n -1)
|
|
1874 (memq (aref (aref emerge-difference-list n) 6)
|
|
1875 '(prefer-A prefer-B)))
|
|
1876 (setq n (1- n)))
|
|
1877 (let ((buffer-read-only nil))
|
|
1878 (emerge-unselect-and-select-difference n)))
|
|
1879 (error "At beginning")))
|
|
1880
|
|
1881 (defun emerge-jump-to-difference (difference-number)
|
|
1882 "Go to the N-th difference."
|
|
1883 (interactive "p")
|
|
1884 (let ((buffer-read-only nil))
|
|
1885 (setq difference-number (1- difference-number))
|
|
1886 (if (and (>= difference-number -1)
|
|
1887 (< difference-number (1+ emerge-number-of-differences)))
|
|
1888 (emerge-unselect-and-select-difference difference-number)
|
|
1889 (error "Bad difference number"))))
|
|
1890
|
|
1891 (defun emerge-abort ()
|
|
1892 "Abort the Emerge session."
|
|
1893 (interactive)
|
|
1894 (emerge-quit t))
|
|
1895
|
|
1896 (defun emerge-quit (arg)
|
|
1897 "Finish the Emerge session and exit Emerge.
|
|
1898 Prefix argument means to abort rather than successfully finish.
|
|
1899 The difference depends on how the merge was started,
|
|
1900 but usually means to not write over one of the original files, or to signal
|
|
1901 to some process which invoked Emerge a failure code.
|
|
1902
|
|
1903 Unselects the selected difference, if any, restores the read-only and modified
|
|
1904 flags of the merged file buffers, restores the local keymap of the merge
|
|
1905 buffer, and sets off various emerge flags. Using Emerge commands in this
|
|
1906 buffer after this will cause serious problems."
|
|
1907 (interactive "P")
|
|
1908 (if (prog1
|
|
1909 (y-or-n-p
|
|
1910 (if (not arg)
|
|
1911 "Do you really want to successfully finish this merge? "
|
|
1912 "Do you really want to abort this merge? "))
|
|
1913 (message ""))
|
|
1914 (emerge-really-quit arg)))
|
|
1915
|
|
1916 ;; Perform the quit operations.
|
|
1917 (defun emerge-really-quit (arg)
|
|
1918 (setq buffer-read-only nil)
|
|
1919 (emerge-unselect-and-select-difference -1)
|
|
1920 (emerge-restore-buffer-characteristics)
|
|
1921 ;; null out the difference markers so they don't slow down future editing
|
|
1922 ;; operations
|
|
1923 (mapcar (function (lambda (d)
|
|
1924 (set-marker (aref d 0) nil)
|
|
1925 (set-marker (aref d 1) nil)
|
|
1926 (set-marker (aref d 2) nil)
|
|
1927 (set-marker (aref d 3) nil)
|
|
1928 (set-marker (aref d 4) nil)
|
|
1929 (set-marker (aref d 5) nil)))
|
|
1930 emerge-difference-list)
|
|
1931 ;; allow them to be garbage collected
|
|
1932 (setq emerge-difference-list nil)
|
|
1933 ;; restore the menubar
|
|
1934 ;; don't make the menubar become un-local because the major mode might
|
|
1935 ;; have already made it local and added an item.
|
|
1936 (delete-menu-item '("Emerge"))
|
|
1937 ;; restore the local map
|
|
1938 (use-local-map emerge-old-keymap)
|
|
1939 ;; turn off all the emerge modes
|
|
1940 (setq emerge-mode nil)
|
|
1941 (setq emerge-fast-mode nil)
|
|
1942 (setq emerge-edit-mode nil)
|
|
1943 (setq emerge-auto-advance nil)
|
|
1944 (setq emerge-skip-prefers nil)
|
|
1945 ;; restore mode line
|
|
1946 (kill-local-variable 'mode-line-buffer-identification)
|
|
1947 (let ((emerge-prefix-argument arg))
|
|
1948 (run-hooks 'emerge-quit-hook)))
|
|
1949
|
|
1950 (defun emerge-select-A (&optional force)
|
|
1951 "Select the A variant of this difference.
|
|
1952 Refuses to function if this difference has been edited, i.e., if it
|
|
1953 is neither the A nor the B variant.
|
|
1954 A prefix argument forces the variant to be selected
|
|
1955 even if the difference has been edited."
|
|
1956 (interactive "P")
|
|
1957 (let ((operate
|
|
1958 (function (lambda ()
|
|
1959 (emerge-select-A-edit merge-begin merge-end A-begin A-end)
|
|
1960 (if emerge-auto-advance
|
|
1961 (emerge-next-difference)))))
|
|
1962 (operate-no-change
|
|
1963 (function (lambda ()
|
|
1964 (if emerge-auto-advance
|
|
1965 (emerge-next-difference))))))
|
|
1966 (emerge-select-version force operate-no-change operate operate)))
|
|
1967
|
|
1968 ;; Actually select the A variant
|
|
1969 (defun emerge-select-A-edit (merge-begin merge-end A-begin A-end)
|
189
|
1970 (with-current-buffer
|
|
1971 emerge-merge-buffer
|
|
1972 (delete-region merge-begin merge-end)
|
|
1973 (goto-char merge-begin)
|
|
1974 (insert-buffer-substring emerge-A-buffer A-begin A-end)
|
|
1975 (goto-char merge-begin)
|
|
1976 (aset diff-vector 6 'A)
|
|
1977 (emerge-refresh-mode-line)))
|
0
|
1978
|
|
1979 (defun emerge-select-B (&optional force)
|
|
1980 "Select the B variant of this difference.
|
|
1981 Refuses to function if this difference has been edited, i.e., if it
|
|
1982 is neither the A nor the B variant.
|
|
1983 A prefix argument forces the variant to be selected
|
|
1984 even if the difference has been edited."
|
|
1985 (interactive "P")
|
|
1986 (let ((operate
|
|
1987 (function (lambda ()
|
|
1988 (emerge-select-B-edit merge-begin merge-end B-begin B-end)
|
|
1989 (if emerge-auto-advance
|
|
1990 (emerge-next-difference)))))
|
|
1991 (operate-no-change
|
|
1992 (function (lambda ()
|
|
1993 (if emerge-auto-advance
|
|
1994 (emerge-next-difference))))))
|
|
1995 (emerge-select-version force operate operate-no-change operate)))
|
|
1996
|
|
1997 ;; Actually select the B variant
|
|
1998 (defun emerge-select-B-edit (merge-begin merge-end B-begin B-end)
|
189
|
1999 (with-current-buffer
|
|
2000 emerge-merge-buffer
|
|
2001 (delete-region merge-begin merge-end)
|
|
2002 (goto-char merge-begin)
|
|
2003 (insert-buffer-substring emerge-B-buffer B-begin B-end)
|
|
2004 (goto-char merge-begin)
|
|
2005 (aset diff-vector 6 'B)
|
|
2006 (emerge-refresh-mode-line)))
|
0
|
2007
|
|
2008 (defun emerge-default-A (force)
|
|
2009 "Make the A variant the default from here down.
|
|
2010 This selects the A variant for all differences from here down in the buffer
|
|
2011 which are still defaulted, i.e., which the user has not selected and for
|
|
2012 which there is no preference.
|
|
2013 A prefix argument forces all differences from here down that have
|
|
2014 selected the B version to become default-A as well."
|
|
2015 (interactive "P")
|
|
2016 (let ((buffer-read-only nil))
|
|
2017 (let ((selected-difference emerge-current-difference)
|
|
2018 (n (max emerge-current-difference 0)))
|
|
2019 (while (< n emerge-number-of-differences)
|
|
2020 (let ((diff-vector (aref emerge-difference-list n)))
|
|
2021 (if (or (eq (aref diff-vector 6) 'default-B)
|
|
2022 (and force
|
|
2023 (eq (aref diff-vector 6) 'B)))
|
|
2024 (progn
|
|
2025 (emerge-unselect-and-select-difference n t)
|
|
2026 (emerge-select-A force)
|
|
2027 (aset diff-vector 6 'default-A))))
|
|
2028 (setq n (1+ n))
|
|
2029 (if (zerop (% n 10))
|
|
2030 (message "Setting default to A...%d" n)))
|
|
2031 (emerge-unselect-and-select-difference selected-difference)))
|
|
2032 (message "Default choice is now A"))
|
|
2033
|
|
2034 (defun emerge-default-B (force)
|
|
2035 "Make the B variant the default from here down.
|
|
2036 This selects the B variant for all differences from here down in the buffer
|
|
2037 which are still defaulted, i.e., which the user has not selected and for
|
|
2038 which there is no preference.
|
|
2039 A prefix argument forces all differences from here down that have
|
|
2040 selected the A version to become default-B as well."
|
|
2041 (interactive "P")
|
|
2042 (let ((buffer-read-only nil))
|
|
2043 (let ((selected-difference emerge-current-difference)
|
|
2044 (n (max emerge-current-difference 0)))
|
|
2045 (while (< n emerge-number-of-differences)
|
|
2046 (let ((diff-vector (aref emerge-difference-list n)))
|
|
2047 (if (or (eq (aref diff-vector 6) 'default-A)
|
|
2048 (and force
|
|
2049 (eq (aref diff-vector 6) 'A)))
|
|
2050 (progn
|
|
2051 (emerge-unselect-and-select-difference n t)
|
|
2052 (emerge-select-B force)
|
|
2053 (aset diff-vector 6 'default-B))))
|
|
2054 (setq n (1+ n))
|
|
2055 (if (zerop (% n 10))
|
|
2056 (message "Setting default to B...%d" n)))
|
|
2057 (emerge-unselect-and-select-difference selected-difference)))
|
|
2058 (message "Default choice is now B"))
|
|
2059
|
|
2060 (defun emerge-fast-mode ()
|
|
2061 "Set fast mode, for Emerge.
|
|
2062 In this mode ordinary Emacs commands are disabled, and Emerge commands
|
|
2063 need not be prefixed with \\<emerge-fast-keymap>\\[emerge-basic-keymap]."
|
|
2064 (interactive)
|
|
2065 (setq buffer-read-only t)
|
|
2066 (use-local-map emerge-fast-keymap)
|
|
2067 (setq emerge-mode t)
|
|
2068 (setq emerge-fast-mode t)
|
|
2069 (setq emerge-edit-mode nil)
|
|
2070 (message "Fast mode set")
|
|
2071 (force-mode-line-update))
|
|
2072
|
|
2073 (defun emerge-edit-mode ()
|
|
2074 "Set edit mode, for Emerge.
|
|
2075 In this mode ordinary Emacs commands are available, and Emerge commands
|
|
2076 must be prefixed with \\<emerge-fast-keymap>\\[emerge-basic-keymap]."
|
|
2077 (interactive)
|
|
2078 (setq buffer-read-only nil)
|
|
2079 (use-local-map emerge-edit-keymap)
|
|
2080 (setq emerge-mode t)
|
|
2081 (setq emerge-fast-mode nil)
|
|
2082 (setq emerge-edit-mode t)
|
|
2083 (message "Edit mode set")
|
|
2084 (force-mode-line-update))
|
|
2085
|
|
2086 (defun emerge-auto-advance (arg)
|
|
2087 "Toggle Auto-Advance mode, for Emerge.
|
|
2088 This mode causes `emerge-select-A' and `emerge-select-B' to automatically
|
|
2089 advance to the next difference.
|
|
2090 With a positive argument, turn on Auto-Advance mode.
|
|
2091 With a negative argument, turn off Auto-Advance mode."
|
|
2092 (interactive "P")
|
|
2093 (setq emerge-auto-advance (if (null arg)
|
|
2094 (not emerge-auto-advance)
|
|
2095 (> (prefix-numeric-value arg) 0)))
|
|
2096 (message (if emerge-auto-advance
|
|
2097 "Auto-advance set"
|
|
2098 "Auto-advance cleared"))
|
|
2099 (force-mode-line-update))
|
|
2100
|
|
2101 (defun emerge-skip-prefers (arg)
|
|
2102 "Toggle Skip-Prefers mode, for Emerge.
|
|
2103 This mode causes `emerge-next-difference' and `emerge-previous-difference'
|
|
2104 to automatically skip over differences for which there is a preference.
|
|
2105 With a positive argument, turn on Skip-Prefers mode.
|
|
2106 With a negative argument, turn off Skip-Prefers mode."
|
|
2107 (interactive "P")
|
|
2108 (setq emerge-skip-prefers (if (null arg)
|
|
2109 (not emerge-skip-prefers)
|
|
2110 (> (prefix-numeric-value arg) 0)))
|
|
2111 (message (if emerge-skip-prefers
|
|
2112 "Skip-prefers set"
|
|
2113 "Skip-prefers cleared"))
|
|
2114 (force-mode-line-update))
|
|
2115
|
|
2116 (defun emerge-copy-as-kill-A ()
|
|
2117 "Put the A variant of this difference in the kill ring."
|
|
2118 (interactive)
|
|
2119 (emerge-validate-difference)
|
|
2120 (let* ((diff-vector
|
|
2121 (aref emerge-difference-list emerge-current-difference))
|
|
2122 (A-begin (1+ (aref diff-vector 0)))
|
|
2123 (A-end (1- (aref diff-vector 1)))
|
|
2124 ;; so further kills don't append
|
|
2125 this-command)
|
|
2126 (save-excursion
|
|
2127 (set-buffer emerge-A-buffer)
|
|
2128 (copy-region-as-kill A-begin A-end))))
|
|
2129
|
|
2130 (defun emerge-copy-as-kill-B ()
|
|
2131 "Put the B variant of this difference in the kill ring."
|
|
2132 (interactive)
|
|
2133 (emerge-validate-difference)
|
|
2134 (let* ((diff-vector
|
|
2135 (aref emerge-difference-list emerge-current-difference))
|
|
2136 (B-begin (1+ (aref diff-vector 2)))
|
|
2137 (B-end (1- (aref diff-vector 3)))
|
|
2138 ;; so further kills don't append
|
|
2139 this-command)
|
|
2140 (save-excursion
|
|
2141 (set-buffer emerge-B-buffer)
|
|
2142 (copy-region-as-kill B-begin B-end))))
|
|
2143
|
|
2144 (defun emerge-insert-A (arg)
|
|
2145 "Insert the A variant of this difference at the point.
|
|
2146 Leaves point after text, mark before.
|
|
2147 With prefix argument, puts point before, mark after."
|
|
2148 (interactive "P")
|
|
2149 (emerge-validate-difference)
|
|
2150 (let* ((diff-vector
|
|
2151 (aref emerge-difference-list emerge-current-difference))
|
|
2152 (A-begin (1+ (aref diff-vector 0)))
|
|
2153 (A-end (1- (aref diff-vector 1)))
|
|
2154 (opoint (point))
|
|
2155 (buffer-read-only nil))
|
|
2156 (insert-buffer-substring emerge-A-buffer A-begin A-end)
|
|
2157 (if (not arg)
|
|
2158 (set-mark opoint)
|
|
2159 (set-mark (point))
|
|
2160 (goto-char opoint))))
|
|
2161
|
|
2162 (defun emerge-insert-B (arg)
|
|
2163 "Insert the B variant of this difference at the point.
|
|
2164 Leaves point after text, mark before.
|
|
2165 With prefix argument, puts point before, mark after."
|
|
2166 (interactive "P")
|
|
2167 (emerge-validate-difference)
|
|
2168 (let* ((diff-vector
|
|
2169 (aref emerge-difference-list emerge-current-difference))
|
|
2170 (B-begin (1+ (aref diff-vector 2)))
|
|
2171 (B-end (1- (aref diff-vector 3)))
|
|
2172 (opoint (point))
|
|
2173 (buffer-read-only nil))
|
|
2174 (insert-buffer-substring emerge-B-buffer B-begin B-end)
|
|
2175 (if (not arg)
|
|
2176 (set-mark opoint)
|
|
2177 (set-mark (point))
|
|
2178 (goto-char opoint))))
|
|
2179
|
|
2180 (defun emerge-mark-difference (arg)
|
|
2181 "Leaves the point before this difference and the mark after it.
|
|
2182 With prefix argument, puts mark before, point after."
|
|
2183 (interactive "P")
|
|
2184 (emerge-validate-difference)
|
|
2185 (let* ((diff-vector
|
|
2186 (aref emerge-difference-list emerge-current-difference))
|
|
2187 (merge-begin (1+ (aref diff-vector 4)))
|
|
2188 (merge-end (1- (aref diff-vector 5))))
|
|
2189 (if (not arg)
|
|
2190 (progn
|
|
2191 (goto-char merge-begin)
|
|
2192 (set-mark merge-end))
|
|
2193 (goto-char merge-end)
|
|
2194 (set-mark merge-begin))))
|
|
2195
|
|
2196 (defun emerge-file-names ()
|
|
2197 "Show the names of the buffers or files being operated on by Emerge.
|
|
2198 Use C-u l to reset the windows afterward."
|
|
2199 (interactive)
|
|
2200 (delete-other-windows)
|
|
2201 (let ((temp-buffer-show-function
|
|
2202 (function
|
|
2203 (lambda (buf)
|
|
2204 ;; in v18, split-window and split-window-vertically were the same,
|
|
2205 ;; but in v19, split-window-vertically might select the other
|
|
2206 ;; window.
|
|
2207 ;; (split-window-vertically)
|
|
2208 (switch-to-buffer buf)
|
|
2209 (other-window 1)))))
|
|
2210 (with-output-to-temp-buffer "*Help*"
|
189
|
2211 (with-current-buffer emerge-A-buffer
|
|
2212 (if buffer-file-name
|
|
2213 (progn
|
|
2214 (princ "File A is: ")
|
|
2215 (princ buffer-file-name))
|
|
2216 (progn
|
|
2217 (princ "Buffer A is: ")
|
|
2218 (princ (buffer-name))))
|
|
2219 (princ "\n"))
|
|
2220 (with-current-buffer emerge-B-buffer
|
|
2221 (if buffer-file-name
|
|
2222 (progn
|
|
2223 (princ "File B is: ")
|
|
2224 (princ buffer-file-name))
|
|
2225 (progn
|
|
2226 (princ "Buffer B is: ")
|
|
2227 (princ (buffer-name))))
|
|
2228 (princ "\n"))
|
0
|
2229 (if emerge-ancestor-buffer
|
189
|
2230 (with-current-buffer emerge-ancestor-buffer
|
|
2231 (if buffer-file-name
|
|
2232 (progn
|
|
2233 (princ "Ancestor file is: ")
|
|
2234 (princ buffer-file-name))
|
|
2235 (progn
|
|
2236 (princ "Ancestor buffer is: ")
|
|
2237 (princ (buffer-name))))
|
|
2238 (princ "\n")))
|
0
|
2239 (princ emerge-output-description)
|
|
2240 (save-excursion
|
|
2241 (set-buffer standard-output)
|
|
2242 (help-mode)))))
|
|
2243
|
|
2244 (defun emerge-join-differences (arg)
|
|
2245 "Join the selected difference with the following one.
|
|
2246 With a prefix argument, join with the preceding one."
|
|
2247 (interactive "P")
|
|
2248 (let ((n emerge-current-difference))
|
|
2249 ;; adjust n to be first difference to join
|
|
2250 (if arg
|
|
2251 (setq n (1- n)))
|
|
2252 ;; n and n+1 are the differences to join
|
|
2253 ;; check that they are both differences
|
|
2254 (if (or (< n 0) (>= n (1- emerge-number-of-differences)))
|
|
2255 (error "Incorrect differences to join"))
|
|
2256 ;; remove the flags
|
|
2257 (emerge-unselect-difference emerge-current-difference)
|
|
2258 ;; decrement total number of differences
|
|
2259 (setq emerge-number-of-differences (1- emerge-number-of-differences))
|
|
2260 ;; build new differences vector
|
|
2261 (let ((i 0)
|
|
2262 (new-differences (make-vector emerge-number-of-differences nil)))
|
|
2263 (while (< i emerge-number-of-differences)
|
|
2264 (aset new-differences i
|
|
2265 (cond
|
|
2266 ((< i n) (aref emerge-difference-list i))
|
|
2267 ((> i n) (aref emerge-difference-list (1+ i)))
|
|
2268 (t (let ((prev (aref emerge-difference-list i))
|
|
2269 (next (aref emerge-difference-list (1+ i))))
|
|
2270 (vector (aref prev 0)
|
|
2271 (aref next 1)
|
|
2272 (aref prev 2)
|
|
2273 (aref next 3)
|
|
2274 (aref prev 4)
|
|
2275 (aref next 5)
|
|
2276 (let ((ps (aref prev 6))
|
|
2277 (ns (aref next 6)))
|
|
2278 (cond
|
|
2279 ((eq ps ns)
|
|
2280 ps)
|
|
2281 ((and (or (eq ps 'B) (eq ps 'prefer-B))
|
|
2282 (or (eq ns 'B) (eq ns 'prefer-B)))
|
|
2283 'B)
|
|
2284 (t 'A))))))))
|
|
2285 (setq i (1+ i)))
|
|
2286 (setq emerge-difference-list new-differences))
|
|
2287 ;; set the current difference correctly
|
|
2288 (setq emerge-current-difference n)
|
|
2289 ;; fix the mode line
|
|
2290 (emerge-refresh-mode-line)
|
|
2291 ;; reinsert the flags
|
|
2292 (emerge-select-difference emerge-current-difference)
|
|
2293 (emerge-recenter)))
|
|
2294
|
|
2295 (defun emerge-split-difference ()
|
|
2296 "Split the current difference where the points are in the three windows."
|
|
2297 (interactive)
|
|
2298 (let ((n emerge-current-difference))
|
|
2299 ;; check that this is a valid difference
|
|
2300 (emerge-validate-difference)
|
|
2301 ;; get the point values and old difference
|
189
|
2302 (let ((A-point (with-current-buffer emerge-A-buffer
|
|
2303 (point-marker)))
|
|
2304 (B-point (with-current-buffer emerge-B-buffer
|
|
2305 (point-marker)))
|
0
|
2306 (merge-point (point-marker))
|
|
2307 (old-diff (aref emerge-difference-list n)))
|
|
2308 ;; check location of the points, give error if they aren't in the
|
|
2309 ;; differences
|
|
2310 (if (or (< A-point (aref old-diff 0))
|
|
2311 (> A-point (aref old-diff 1)))
|
|
2312 (error "Point outside of difference in A buffer"))
|
|
2313 (if (or (< B-point (aref old-diff 2))
|
|
2314 (> B-point (aref old-diff 3)))
|
|
2315 (error "Point outside of difference in B buffer"))
|
|
2316 (if (or (< merge-point (aref old-diff 4))
|
|
2317 (> merge-point (aref old-diff 5)))
|
|
2318 (error "Point outside of difference in merge buffer"))
|
|
2319 ;; remove the flags
|
|
2320 (emerge-unselect-difference emerge-current-difference)
|
|
2321 ;; increment total number of differences
|
|
2322 (setq emerge-number-of-differences (1+ emerge-number-of-differences))
|
|
2323 ;; build new differences vector
|
|
2324 (let ((i 0)
|
|
2325 (new-differences (make-vector emerge-number-of-differences nil)))
|
|
2326 (while (< i emerge-number-of-differences)
|
|
2327 (aset new-differences i
|
|
2328 (cond
|
|
2329 ((< i n)
|
|
2330 (aref emerge-difference-list i))
|
|
2331 ((> i (1+ n))
|
|
2332 (aref emerge-difference-list (1- i)))
|
|
2333 ((= i n)
|
|
2334 (vector (aref old-diff 0)
|
|
2335 A-point
|
|
2336 (aref old-diff 2)
|
|
2337 B-point
|
|
2338 (aref old-diff 4)
|
|
2339 merge-point
|
|
2340 (aref old-diff 6)))
|
|
2341 (t
|
|
2342 (vector (copy-marker A-point)
|
|
2343 (aref old-diff 1)
|
|
2344 (copy-marker B-point)
|
|
2345 (aref old-diff 3)
|
|
2346 (copy-marker merge-point)
|
|
2347 (aref old-diff 5)
|
|
2348 (aref old-diff 6)))))
|
|
2349 (setq i (1+ i)))
|
|
2350 (setq emerge-difference-list new-differences))
|
|
2351 ;; set the current difference correctly
|
|
2352 (setq emerge-current-difference n)
|
|
2353 ;; fix the mode line
|
|
2354 (emerge-refresh-mode-line)
|
|
2355 ;; reinsert the flags
|
|
2356 (emerge-select-difference emerge-current-difference)
|
|
2357 (emerge-recenter))))
|
|
2358
|
|
2359 (defun emerge-trim-difference ()
|
|
2360 "Trim lines off top and bottom of difference that are the same.
|
|
2361 If lines are the same in both the A and the B versions, strip them off.
|
|
2362 \(This can happen when the A and B versions have common lines that the
|
|
2363 ancestor version does not share.)"
|
|
2364 (interactive)
|
|
2365 ;; make sure we are in a real difference
|
|
2366 (emerge-validate-difference)
|
|
2367 ;; remove the flags
|
|
2368 (emerge-unselect-difference emerge-current-difference)
|
|
2369 (let* ((diff (aref emerge-difference-list emerge-current-difference))
|
|
2370 (top-a (marker-position (aref diff 0)))
|
|
2371 (bottom-a (marker-position (aref diff 1)))
|
|
2372 (top-b (marker-position (aref diff 2)))
|
|
2373 (bottom-b (marker-position (aref diff 3)))
|
|
2374 (top-m (marker-position (aref diff 4)))
|
|
2375 (bottom-m (marker-position (aref diff 5)))
|
|
2376 size success sa sb sm)
|
|
2377 ;; move down the tops of the difference regions as much as possible
|
|
2378 ;; Try advancing comparing 1000 chars at a time.
|
|
2379 ;; When that fails, go 500 chars at a time, and so on.
|
|
2380 (setq size 1000)
|
|
2381 (while (> size 0)
|
|
2382 (setq success t)
|
|
2383 (while success
|
|
2384 (setq size (min size (- bottom-a top-a) (- bottom-b top-b)
|
|
2385 (- bottom-m top-m)))
|
189
|
2386 (setq sa (with-current-buffer emerge-A-buffer
|
|
2387 (buffer-substring top-a
|
|
2388 (+ size top-a))))
|
|
2389 (setq sb (with-current-buffer emerge-B-buffer
|
|
2390 (buffer-substring top-b
|
|
2391 (+ size top-b))))
|
0
|
2392 (setq sm (buffer-substring top-m (+ size top-m)))
|
|
2393 (setq success (and (> size 0) (equal sa sb) (equal sb sm)))
|
|
2394 (if success
|
|
2395 (setq top-a (+ top-a size)
|
|
2396 top-b (+ top-b size)
|
|
2397 top-m (+ top-m size))))
|
|
2398 (setq size (/ size 2)))
|
|
2399 ;; move up the bottoms of the difference regions as much as possible
|
|
2400 ;; Try advancing comparing 1000 chars at a time.
|
|
2401 ;; When that fails, go 500 chars at a time, and so on.
|
|
2402 (setq size 1000)
|
|
2403 (while (> size 0)
|
|
2404 (setq success t)
|
|
2405 (while success
|
|
2406 (setq size (min size (- bottom-a top-a) (- bottom-b top-b)
|
|
2407 (- bottom-m top-m)))
|
189
|
2408 (setq sa (with-current-buffer emerge-A-buffer
|
|
2409 (buffer-substring (- bottom-a size)
|
|
2410 bottom-a)))
|
|
2411 (setq sb (with-current-buffer emerge-B-buffer
|
|
2412 (buffer-substring (- bottom-b size)
|
|
2413 bottom-b)))
|
0
|
2414 (setq sm (buffer-substring (- bottom-m size) bottom-m))
|
|
2415 (setq success (and (> size 0) (equal sa sb) (equal sb sm)))
|
|
2416 (if success
|
|
2417 (setq bottom-a (- bottom-a size)
|
|
2418 bottom-b (- bottom-b size)
|
|
2419 bottom-m (- bottom-m size))))
|
|
2420 (setq size (/ size 2)))
|
|
2421 ;; {top,bottom}-{a,b,m} are now set at the new beginnings and ends
|
|
2422 ;; of the difference regions. Move them to the beginning of lines, as
|
|
2423 ;; appropriate.
|
189
|
2424 (with-current-buffer emerge-A-buffer
|
|
2425 (goto-char top-a)
|
|
2426 (beginning-of-line)
|
|
2427 (aset diff 0 (point-marker))
|
|
2428 (goto-char bottom-a)
|
|
2429 (beginning-of-line 2)
|
|
2430 (aset diff 1 (point-marker)))
|
|
2431 (with-current-buffer emerge-B-buffer
|
|
2432 (goto-char top-b)
|
|
2433 (beginning-of-line)
|
|
2434 (aset diff 2 (point-marker))
|
|
2435 (goto-char bottom-b)
|
|
2436 (beginning-of-line 2)
|
|
2437 (aset diff 3 (point-marker)))
|
0
|
2438 (goto-char top-m)
|
|
2439 (beginning-of-line)
|
|
2440 (aset diff 4 (point-marker))
|
|
2441 (goto-char bottom-m)
|
|
2442 (beginning-of-line 2)
|
|
2443 (aset diff 5 (point-marker))
|
|
2444 ;; put the flags back in, recenter the display
|
|
2445 (emerge-select-difference emerge-current-difference)
|
|
2446 (emerge-recenter)))
|
|
2447
|
|
2448 (defun emerge-find-difference (arg)
|
|
2449 "Find the difference containing the current position of the point.
|
|
2450 If there is no containing difference and the prefix argument is positive,
|
|
2451 it finds the nearest following difference. A negative prefix argument finds
|
|
2452 the nearest previous difference."
|
|
2453 (interactive "P")
|
|
2454 ;; search for the point in the merge buffer, using the markers
|
|
2455 ;; for the beginning and end of the differences in the merge buffer
|
|
2456 (cond ((eq (current-buffer) emerge-A-buffer)
|
|
2457 (emerge-find-difference-A arg))
|
|
2458 ((eq (current-buffer) emerge-B-buffer)
|
|
2459 (emerge-find-difference-B arg))
|
|
2460 (t (emerge-find-difference-merge arg))))
|
|
2461
|
|
2462 (defun emerge-find-difference-merge (arg)
|
|
2463 "Find the difference containing point, in the merge buffer.
|
|
2464 If there is no containing difference and the prefix argument is positive,
|
|
2465 it finds the nearest following difference. A negative prefix argument finds
|
|
2466 the nearest previous difference."
|
|
2467 (interactive "P")
|
|
2468 ;; search for the point in the merge buffer, using the markers
|
|
2469 ;; for the beginning and end of the differences in the merge buffer
|
|
2470 (emerge-find-difference1 arg (point) 4 5))
|
|
2471
|
|
2472 (defun emerge-find-difference-A (arg)
|
|
2473 "Find the difference containing point, in the A buffer.
|
|
2474 This command must be executed in the merge buffer.
|
|
2475 If there is no containing difference and the prefix argument is positive,
|
|
2476 it finds the nearest following difference. A negative prefix argument finds
|
|
2477 the nearest previous difference."
|
|
2478 (interactive "P")
|
|
2479 ;; search for the point in the A buffer, using the markers
|
|
2480 ;; for the beginning and end of the differences in the A buffer
|
|
2481 (emerge-find-difference1 arg
|
189
|
2482 (with-current-buffer emerge-A-buffer (point))
|
0
|
2483 0 1))
|
|
2484
|
|
2485 (defun emerge-find-difference-B (arg)
|
|
2486 "Find the difference containing point, in the B buffer.
|
|
2487 This command must be executed in the merge buffer.
|
|
2488 If there is no containing difference and the prefix argument is positive,
|
|
2489 it finds the nearest following difference. A negative prefix argument finds
|
|
2490 the nearest previous difference."
|
|
2491 (interactive "P")
|
|
2492 ;; search for the point in the B buffer, using the markers
|
|
2493 ;; for the beginning and end of the differences in the B buffer
|
|
2494 (emerge-find-difference1 arg
|
189
|
2495 (with-current-buffer emerge-B-buffer (point))
|
0
|
2496 2 3))
|
|
2497
|
|
2498 (defun emerge-find-difference1 (arg location begin end)
|
|
2499 (let* ((index
|
|
2500 ;; find first difference containing or after the current position
|
|
2501 (catch 'search
|
|
2502 (let ((n 0))
|
|
2503 (while (< n emerge-number-of-differences)
|
|
2504 (let ((diff-vector (aref emerge-difference-list n)))
|
|
2505 (if (<= location (marker-position (aref diff-vector end)))
|
|
2506 (throw 'search n)))
|
|
2507 (setq n (1+ n))))
|
|
2508 emerge-number-of-differences))
|
|
2509 (contains
|
|
2510 ;; whether the found difference contains the current position
|
|
2511 (and (< index emerge-number-of-differences)
|
|
2512 (<= (marker-position (aref (aref emerge-difference-list index)
|
|
2513 begin))
|
|
2514 location)))
|
|
2515 (arg-value
|
|
2516 ;; numeric value of prefix argument
|
|
2517 (prefix-numeric-value arg)))
|
|
2518 (emerge-unselect-and-select-difference
|
|
2519 (cond
|
|
2520 ;; if the point is in a difference, select it
|
|
2521 (contains index)
|
|
2522 ;; if the arg is nil and the point is not in a difference, error
|
|
2523 ((null arg) (error "No difference contains point"))
|
|
2524 ;; if the arg is positive, select the following difference
|
|
2525 ((> arg-value 0)
|
|
2526 (if (< index emerge-number-of-differences)
|
|
2527 index
|
|
2528 (error "No difference contains or follows point")))
|
|
2529 ;; if the arg is negative, select the preceding difference
|
|
2530 (t
|
|
2531 (if (> index 0)
|
|
2532 (1- index)
|
|
2533 (error "No difference contains or precedes point")))))))
|
|
2534
|
|
2535 (defun emerge-line-numbers ()
|
|
2536 "Display the current line numbers.
|
|
2537 This function displays the line numbers of the points in the A, B, and
|
|
2538 merge buffers."
|
|
2539 (interactive)
|
|
2540 (let* ((valid-diff
|
|
2541 (and (>= emerge-current-difference 0)
|
|
2542 (< emerge-current-difference emerge-number-of-differences)))
|
|
2543 (diff (and valid-diff
|
|
2544 (aref emerge-difference-list emerge-current-difference)))
|
|
2545 (merge-line (emerge-line-number-in-buf 4 5))
|
189
|
2546 (A-line (with-current-buffer emerge-A-buffer
|
|
2547 (emerge-line-number-in-buf 0 1)))
|
|
2548 (B-line (with-current-buffer emerge-B-buffer
|
|
2549 (emerge-line-number-in-buf 2 3))))
|
0
|
2550 (message "At lines: merge = %d, A = %d, B = %d"
|
|
2551 merge-line A-line B-line)))
|
|
2552
|
|
2553 (defun emerge-line-number-in-buf (begin-marker end-marker)
|
|
2554 (let (temp)
|
|
2555 (setq temp (save-excursion
|
|
2556 (beginning-of-line)
|
|
2557 (1+ (count-lines 1 (point)))))
|
|
2558 (if valid-diff
|
|
2559 (progn
|
|
2560 (if (> (point) (aref diff begin-marker))
|
|
2561 (setq temp (- temp emerge-before-flag-lines)))
|
|
2562 (if (> (point) (aref diff end-marker))
|
|
2563 (setq temp (- temp emerge-after-flag-lines)))))
|
|
2564 temp))
|
|
2565
|
|
2566 (defun emerge-set-combine-template (string &optional localize)
|
|
2567 "Set `emerge-combine-versions-template' to STRING.
|
|
2568 This value controls how `emerge-combine-versions' combines the two versions.
|
|
2569 With prefix argument, `emerge-combine-versions-template' is made local to this
|
|
2570 merge buffer. Localization is permanent for any particular merge buffer."
|
|
2571 (interactive "s\nP")
|
|
2572 (if localize
|
|
2573 (make-local-variable 'emerge-combine-versions-template))
|
|
2574 (setq emerge-combine-versions-template string)
|
|
2575 (message
|
|
2576 (if (assq 'emerge-combine-versions-template (buffer-local-variables))
|
|
2577 "emerge-set-combine-versions-template set locally"
|
|
2578 "emerge-set-combine-versions-template set")))
|
|
2579
|
|
2580 (defun emerge-set-combine-versions-template (start end &optional localize)
|
|
2581 "Copy region into `emerge-combine-versions-template'.
|
|
2582 This controls how `emerge-combine-versions' will combine the two versions.
|
|
2583 With prefix argument, `emerge-combine-versions-template' is made local to this
|
|
2584 merge buffer. Localization is permanent for any particular merge buffer."
|
|
2585 (interactive "r\nP")
|
|
2586 (if localize
|
|
2587 (make-local-variable 'emerge-combine-versions-template))
|
|
2588 (setq emerge-combine-versions-template (buffer-substring start end))
|
|
2589 (message
|
|
2590 (if (assq 'emerge-combine-versions-template (buffer-local-variables))
|
|
2591 "emerge-set-combine-versions-template set locally."
|
|
2592 "emerge-set-combine-versions-template set.")))
|
|
2593
|
|
2594 (defun emerge-combine-versions (&optional force)
|
|
2595 "Combine versions using the template in `emerge-combine-versions-template'.
|
|
2596 Refuses to function if this difference has been edited, i.e., if it is
|
|
2597 neither the A nor the B variant.
|
|
2598 An argument forces the variant to be selected even if the difference has
|
|
2599 been edited."
|
|
2600 (interactive "P")
|
|
2601 (emerge-combine-versions-internal emerge-combine-versions-template force))
|
|
2602
|
|
2603 (defun emerge-combine-versions-register (char &optional force)
|
|
2604 "Combine the two versions using the template in register REG.
|
|
2605 See documentation of the variable `emerge-combine-versions-template'
|
|
2606 for how the template is interpreted.
|
|
2607 Refuses to function if this difference has been edited, i.e., if it is
|
|
2608 neither the A nor the B variant.
|
|
2609 An argument forces the variant to be selected even if the difference has
|
|
2610 been edited."
|
|
2611 (interactive "cRegister containing template: \nP")
|
|
2612 (let ((template (get-register char)))
|
|
2613 (if (not (stringp template))
|
|
2614 (error "Register does not contain text"))
|
|
2615 (emerge-combine-versions-internal template force)))
|
|
2616
|
|
2617 (defun emerge-combine-versions-internal (template force)
|
|
2618 (let ((operate
|
|
2619 (function (lambda ()
|
|
2620 (emerge-combine-versions-edit merge-begin merge-end
|
|
2621 A-begin A-end B-begin B-end
|
|
2622 template)
|
|
2623 (if emerge-auto-advance
|
|
2624 (emerge-next-difference))))))
|
|
2625 (emerge-select-version force operate operate operate)))
|
|
2626
|
|
2627 (defun emerge-combine-versions-edit (merge-begin merge-end
|
|
2628 A-begin A-end B-begin B-end
|
|
2629 template)
|
189
|
2630 (with-current-buffer
|
|
2631 emerge-merge-buffer
|
|
2632 (delete-region merge-begin merge-end)
|
|
2633 (goto-char merge-begin)
|
|
2634 (let ((i 0))
|
|
2635 (while (< i (length template))
|
|
2636 (let ((c (aref template i)))
|
|
2637 (if (= c ?%)
|
|
2638 (progn
|
|
2639 (setq i (1+ i))
|
|
2640 (setq c
|
|
2641 (condition-case nil
|
|
2642 (aref template i)
|
|
2643 (error ?%)))
|
|
2644 (cond ((= c ?a)
|
|
2645 (insert-buffer-substring emerge-A-buffer A-begin A-end))
|
|
2646 ((= c ?b)
|
|
2647 (insert-buffer-substring emerge-B-buffer B-begin B-end))
|
|
2648 ((= c ?%)
|
|
2649 (insert ?%))
|
|
2650 (t
|
|
2651 (insert c))))
|
|
2652 (insert c)))
|
|
2653 (setq i (1+ i))))
|
|
2654 (goto-char merge-begin)
|
|
2655 (aset diff-vector 6 'combined)
|
|
2656 (emerge-refresh-mode-line)))
|
0
|
2657
|
|
2658 (defun emerge-set-merge-mode (mode)
|
|
2659 "Set the major mode in a merge buffer.
|
|
2660 Overrides any change that the mode might make to the mode line or local
|
|
2661 keymap. Leaves merge in fast mode."
|
|
2662 (interactive
|
|
2663 (list (intern (completing-read "New major mode for merge buffer: "
|
|
2664 obarray 'commandp t nil))))
|
|
2665 (funcall mode)
|
|
2666 (emerge-refresh-mode-line)
|
|
2667 (if emerge-fast-mode
|
|
2668 (emerge-fast-mode)
|
|
2669 (emerge-edit-mode)))
|
|
2670
|
|
2671 (defun emerge-one-line-window ()
|
|
2672 (interactive)
|
|
2673 (let ((window-min-height 1))
|
|
2674 (shrink-window (- (window-height) 2))))
|
|
2675
|
|
2676 ;;; Support routines
|
|
2677
|
|
2678 ;; Select a difference by placing the visual flags around the appropriate
|
|
2679 ;; group of lines in the A, B, and merge buffers
|
|
2680 (defun emerge-select-difference (n)
|
|
2681 (let ((emerge-globalized-difference-list emerge-difference-list)
|
|
2682 (emerge-globalized-number-of-differences emerge-number-of-differences))
|
|
2683 (emerge-place-flags-in-buffer emerge-A-buffer n 0 1)
|
|
2684 (emerge-place-flags-in-buffer emerge-B-buffer n 2 3)
|
|
2685 (emerge-place-flags-in-buffer nil n 4 5))
|
|
2686 (run-hooks 'emerge-select-hook))
|
|
2687
|
|
2688 (defun emerge-place-flags-in-buffer (buffer difference before-index
|
|
2689 after-index)
|
|
2690 (if buffer
|
189
|
2691 (with-current-buffer
|
|
2692 buffer
|
|
2693 (emerge-place-flags-in-buffer1 difference before-index after-index))
|
0
|
2694 (emerge-place-flags-in-buffer1 difference before-index after-index)))
|
|
2695
|
|
2696 (defun emerge-place-flags-in-buffer1 (difference before-index after-index)
|
|
2697 (if (and emerge-xemacs-p (not emerge-mark-with-text))
|
|
2698 ;; XEmacs highlights the difference
|
|
2699 (emerge-place-flags-in-buffer1-xemacs difference before-index after-index)
|
|
2700 ;; Else insert character flags
|
|
2701 (let ((buffer-read-only nil))
|
|
2702 ;; insert the flag before the difference
|
|
2703 (let ((before (aref (aref emerge-globalized-difference-list difference)
|
|
2704 before-index))
|
|
2705 here)
|
|
2706 (goto-char before)
|
|
2707 ;; insert the flag itself
|
|
2708 (insert-before-markers emerge-before-flag)
|
|
2709 (setq here (point))
|
|
2710 ;; Put the marker(s) referring to this position 1 character before the
|
|
2711 ;; end of the flag, so it won't be damaged by the user.
|
|
2712 ;; This gets a bit tricky, as there could be a number of markers
|
|
2713 ;; that have to be moved.
|
|
2714 (set-marker before (1- before))
|
|
2715 (let ((n (1- difference)) after-marker before-marker diff-list)
|
|
2716 (while (and
|
|
2717 (>= n 0)
|
|
2718 (progn
|
|
2719 (setq diff-list (aref emerge-globalized-difference-list n)
|
|
2720 after-marker (aref diff-list after-index))
|
|
2721 (= after-marker here)))
|
|
2722 (set-marker after-marker (1- after-marker))
|
|
2723 (setq before-marker (aref diff-list before-index))
|
|
2724 (if (= before-marker here)
|
|
2725 (setq before-marker (1- before-marker)))
|
|
2726 (setq n (1- n)))))
|
|
2727 ;; insert the flag after the difference
|
|
2728 (let* ((after (aref (aref emerge-globalized-difference-list difference)
|
|
2729 after-index))
|
|
2730 (here (marker-position after)))
|
|
2731 (goto-char here)
|
|
2732 ;; insert the flag itself
|
|
2733 (insert emerge-after-flag)
|
|
2734 ;; Put the marker(s) referring to this position 1 character after the
|
|
2735 ;; beginning of the flag, so it won't be damaged by the user.
|
|
2736 ;; This gets a bit tricky, as there could be a number of markers
|
|
2737 ;; that have to be moved.
|
|
2738 (set-marker after (1+ after))
|
|
2739 (let ((n (1+ difference)) before-marker after-marker diff-list)
|
|
2740 (while (and
|
|
2741 (< n emerge-globalized-number-of-differences)
|
|
2742 (progn
|
|
2743 (setq diff-list (aref emerge-globalized-difference-list n)
|
|
2744 before-marker (aref diff-list before-index))
|
|
2745 (= before-marker here)))
|
|
2746 (set-marker before-marker (1+ before-marker))
|
|
2747 (setq after-marker (aref diff-list after-index))
|
|
2748 (if (= after-marker here)
|
|
2749 (setq after-marker (1+ after-marker)))
|
|
2750 (setq n (1+ n))))))))
|
|
2751
|
|
2752 (defun emerge-place-flags-in-buffer1-xemacs (difference before-index
|
|
2753 after-index)
|
|
2754 (let* ((before (aref (aref emerge-globalized-difference-list difference)
|
|
2755 before-index))
|
|
2756 (after (aref (aref emerge-globalized-difference-list difference)
|
|
2757 after-index))
|
|
2758 (extent (make-extent (marker-position before) (marker-position after)
|
|
2759 (current-buffer))))
|
|
2760 (set-extent-face extent 'emerge-highlight-face)
|
|
2761 ;; Assert that this extent is slightly more important than random other
|
|
2762 ;; extents that may have been inserted by things like font-lock-mode.
|
|
2763 ;; This way, any conflict between the display of a highlighting face
|
|
2764 ;; and the emerge face will be resolved in emerge's favor.
|
|
2765 (set-extent-priority extent 1)
|
|
2766 (set-extent-property extent 'emerge t)))
|
|
2767
|
|
2768 ;; Unselect a difference by removing the visual flags in the buffers.
|
|
2769 (defun emerge-unselect-difference (n)
|
|
2770 (let ((diff-vector (aref emerge-difference-list n)))
|
|
2771 (emerge-remove-flags-in-buffer emerge-A-buffer
|
|
2772 (aref diff-vector 0) (aref diff-vector 1))
|
|
2773 (emerge-remove-flags-in-buffer emerge-B-buffer
|
|
2774 (aref diff-vector 2) (aref diff-vector 3))
|
|
2775 (emerge-remove-flags-in-buffer emerge-merge-buffer
|
|
2776 (aref diff-vector 4) (aref diff-vector 5)))
|
|
2777 (run-hooks 'emerge-unselect-hook))
|
|
2778
|
|
2779 (defun emerge-remove-flags-in-buffer (buffer before after)
|
|
2780 (if (and emerge-xemacs-p (not emerge-mark-with-text))
|
|
2781 ;; XEmacs -- remove highlighting
|
|
2782 (emerge-remove-flags-in-buffer-xemacs buffer before after)
|
|
2783 ;; Else remove character flags
|
189
|
2784 (with-current-buffer
|
|
2785 buffer
|
|
2786 (let ((buffer-read-only nil))
|
|
2787 ;; remove the flags, if they're there
|
|
2788 (goto-char (- before (1- emerge-before-flag-length)))
|
|
2789 (if (looking-at emerge-before-flag-match)
|
|
2790 (delete-char emerge-before-flag-length)
|
|
2791 ;; the flag isn't there
|
|
2792 (ding)
|
|
2793 (message "Trouble removing flag"))
|
|
2794 (goto-char (1- after))
|
|
2795 (if (looking-at emerge-after-flag-match)
|
|
2796 (delete-char emerge-after-flag-length)
|
|
2797 ;; the flag isn't there
|
|
2798 (ding)
|
|
2799 (message "Trouble removing flag"))))))
|
0
|
2800
|
|
2801 (defun emerge-remove-flags-in-buffer-xemacs (buffer before after)
|
|
2802 (map-extents (function (lambda (x y)
|
|
2803 (if (extent-property x 'emerge)
|
|
2804 (delete-extent x))))
|
|
2805 buffer (marker-position before) (marker-position after) nil))
|
|
2806
|
|
2807 ;; Select a difference, removing any flags that exist now.
|
|
2808 (defun emerge-unselect-and-select-difference (n &optional suppress-display)
|
|
2809 (if (and (>= emerge-current-difference 0)
|
|
2810 (< emerge-current-difference emerge-number-of-differences))
|
|
2811 (emerge-unselect-difference emerge-current-difference))
|
|
2812 (if (and (>= n 0) (< n emerge-number-of-differences))
|
|
2813 (progn
|
|
2814 (emerge-select-difference n)
|
|
2815 (let* ((diff-vector (aref emerge-difference-list n))
|
|
2816 (selection-type (aref diff-vector 6)))
|
|
2817 (if (eq selection-type 'default-A)
|
|
2818 (aset diff-vector 6 'A)
|
|
2819 (if (eq selection-type 'default-B)
|
|
2820 (aset diff-vector 6 'B))))))
|
|
2821 (setq emerge-current-difference n)
|
|
2822 (if (not suppress-display)
|
|
2823 (progn
|
|
2824 (emerge-recenter)
|
|
2825 (emerge-refresh-mode-line))))
|
|
2826
|
|
2827 ;; Perform tests to see whether user should be allowed to select a version
|
|
2828 ;; of this difference:
|
|
2829 ;; a valid difference has been selected; and
|
|
2830 ;; the difference text in the merge buffer is:
|
|
2831 ;; the A version (execute a-version), or
|
|
2832 ;; the B version (execute b-version), or
|
|
2833 ;; empty (execute neither-version), or
|
|
2834 ;; argument FORCE is true (execute neither-version)
|
|
2835 ;; Otherwise, signal an error.
|
|
2836 (defun emerge-select-version (force a-version b-version neither-version)
|
|
2837 (emerge-validate-difference)
|
|
2838 (let ((buffer-read-only nil))
|
|
2839 (let* ((diff-vector
|
|
2840 (aref emerge-difference-list emerge-current-difference))
|
|
2841 (A-begin (1+ (aref diff-vector 0)))
|
|
2842 (A-end (1- (aref diff-vector 1)))
|
|
2843 (B-begin (1+ (aref diff-vector 2)))
|
|
2844 (B-end (1- (aref diff-vector 3)))
|
|
2845 (merge-begin (1+ (aref diff-vector 4)))
|
|
2846 (merge-end (1- (aref diff-vector 5))))
|
|
2847 (if (emerge-compare-buffers emerge-A-buffer A-begin A-end
|
|
2848 emerge-merge-buffer merge-begin
|
|
2849 merge-end)
|
|
2850 (funcall a-version)
|
|
2851 (if (emerge-compare-buffers emerge-B-buffer B-begin B-end
|
|
2852 emerge-merge-buffer merge-begin
|
|
2853 merge-end)
|
|
2854 (funcall b-version)
|
|
2855 (if (or force (= merge-begin merge-end))
|
|
2856 (funcall neither-version)
|
|
2857 (error "This difference region has been edited")))))))
|
|
2858
|
|
2859 ;; Read a file name, handling all of the various defaulting rules.
|
|
2860
|
|
2861 (defun emerge-read-file-name (prompt alternative-default-dir default-file
|
|
2862 A-file must-match)
|
|
2863 ;; `prompt' should not have trailing ": ", so that it can be modified
|
|
2864 ;; according to context.
|
|
2865 ;; If alternative-default-dir is non-nil, it should be used as the default
|
|
2866 ;; directory instead if default-directory, if emerge-default-last-directories
|
|
2867 ;; is set.
|
|
2868 ;; If default-file is set, it should be used as the default value.
|
|
2869 ;; If A-file is set, and its directory is different from
|
|
2870 ;; alternative-default-dir, and if emerge-default-last-directories is set,
|
|
2871 ;; the default file should be the last part of A-file in the default
|
|
2872 ;; directory. (Overriding default-file.)
|
|
2873 ;; 'must-match' controlls whether non-existent file names are allowed;
|
|
2874 ;; see the fourth argument of read-file-name for interpretations of values.
|
|
2875 (cond
|
|
2876 ;; If this is not the A-file argument (shown by non-nil A-file), and
|
|
2877 ;; if emerge-default-last-directories is set, and
|
|
2878 ;; the default directory exists but is not the same as the directory of the
|
|
2879 ;; A-file,
|
|
2880 ;; then make the default file have the same name as the A-file, but in
|
|
2881 ;; the default directory.
|
|
2882 ((and emerge-default-last-directories
|
|
2883 A-file
|
|
2884 alternative-default-dir
|
|
2885 (not (string-equal alternative-default-dir
|
|
2886 (file-name-directory A-file))))
|
|
2887 (read-file-name (format "%s (default %s): "
|
|
2888 prompt (file-name-nondirectory A-file))
|
|
2889 alternative-default-dir
|
|
2890 (concat alternative-default-dir
|
|
2891 (file-name-nondirectory A-file))
|
|
2892 (and must-match 'confirm)))
|
|
2893 ;; If there is a default file, use it.
|
|
2894 (default-file
|
|
2895 (read-file-name (format "%s (default %s): " prompt default-file)
|
|
2896 ;; If emerge-default-last-directories is set, use the
|
|
2897 ;; directory from the same argument of the last call of
|
|
2898 ;; Emerge as the default for this argument.
|
|
2899 (and emerge-default-last-directories
|
|
2900 alternative-default-dir)
|
|
2901 default-file (and must-match 'confirm)))
|
|
2902 (t
|
|
2903 (read-file-name (concat prompt ": ")
|
|
2904 ;; If emerge-default-last-directories is set, use the
|
|
2905 ;; directory from the same argument of the last call of
|
|
2906 ;; Emerge as the default for this argument.
|
|
2907 (and emerge-default-last-directories
|
|
2908 alternative-default-dir)
|
|
2909 nil (and must-match 'confirm)))))
|
|
2910
|
|
2911 ;; Revise the mode line to display which difference we have selected
|
|
2912
|
|
2913 (defun emerge-refresh-mode-line ()
|
|
2914 (setq mode-line-buffer-identification
|
|
2915 (list (format "Emerge: %%b diff %d of %d%s"
|
|
2916 (1+ emerge-current-difference)
|
|
2917 emerge-number-of-differences
|
|
2918 (if (and (>= emerge-current-difference 0)
|
|
2919 (< emerge-current-difference
|
|
2920 emerge-number-of-differences))
|
|
2921 (cdr (assq (aref (aref emerge-difference-list
|
|
2922 emerge-current-difference)
|
|
2923 6)
|
|
2924 '((A . " - A")
|
|
2925 (B . " - B")
|
|
2926 (prefer-A . " - A*")
|
|
2927 (prefer-B . " - B*")
|
|
2928 (combined . " - comb"))))
|
|
2929 ""))))
|
|
2930 (force-mode-line-update))
|
|
2931
|
|
2932 ;; compare two regions in two buffers for containing the same text
|
|
2933 (defun emerge-compare-buffers (buffer-x x-begin x-end buffer-y y-begin y-end)
|
|
2934 ;; first check that the two regions are the same length
|
|
2935 (if (not (and (= (- x-end x-begin) (- y-end y-begin))))
|
|
2936 nil
|
|
2937 (catch 'exit
|
|
2938 (while (< x-begin x-end)
|
|
2939 ;; bite off and compare no more than 1000 characters at a time
|
|
2940 (let* ((compare-length (min (- x-end x-begin) 1000))
|
189
|
2941 (x-string (with-current-buffer
|
|
2942 buffer-x
|
|
2943 (buffer-substring x-begin
|
|
2944 (+ x-begin compare-length))))
|
|
2945 (y-string (with-current-buffer
|
|
2946 buffer-y
|
|
2947 (buffer-substring y-begin
|
|
2948 (+ y-begin compare-length)))))
|
0
|
2949 (if (not (string-equal x-string y-string))
|
|
2950 (throw 'exit nil)
|
|
2951 (setq x-begin (+ x-begin compare-length))
|
|
2952 (setq y-begin (+ y-begin compare-length)))))
|
|
2953 t)))
|
|
2954
|
|
2955 ;; Construct a unique buffer name.
|
|
2956 ;; The first one tried is prefixsuffix, then prefix<2>suffix,
|
|
2957 ;; prefix<3>suffix, etc.
|
|
2958 (defun emerge-unique-buffer-name (prefix suffix)
|
|
2959 (if (null (get-buffer (concat prefix suffix)))
|
|
2960 (concat prefix suffix)
|
|
2961 (let ((n 2))
|
|
2962 (while (get-buffer (format "%s<%d>%s" prefix n suffix))
|
|
2963 (setq n (1+ n)))
|
|
2964 (format "%s<%d>%s" prefix n suffix))))
|
|
2965
|
|
2966 ;; Verify that we have a difference selected.
|
|
2967 (defun emerge-validate-difference ()
|
|
2968 (if (not (and (>= emerge-current-difference 0)
|
|
2969 (< emerge-current-difference emerge-number-of-differences)))
|
|
2970 (error "No difference selected")))
|
|
2971
|
|
2972 ;;; Functions for saving and restoring a batch of variables
|
|
2973
|
|
2974 ;; These functions save (get the values of) and restore (set the values of)
|
|
2975 ;; a list of variables. The argument is a list of symbols (the names of
|
|
2976 ;; the variables). A list element can also be a list of two functions,
|
|
2977 ;; the first of which (when called with no arguments) gets the value, and
|
108
|
2978 ;; the second (when called with a value as an argument) sets the value.
|
0
|
2979 ;; A "function" is anything that funcall can handle as an argument.
|
|
2980
|
|
2981 (defun emerge-save-variables (vars)
|
|
2982 (mapcar (function (lambda (v) (if (symbolp v)
|
|
2983 (symbol-value v)
|
|
2984 (funcall (car v)))))
|
|
2985 vars))
|
|
2986
|
|
2987 (defun emerge-restore-variables (vars values)
|
|
2988 (while vars
|
|
2989 (let ((var (car vars))
|
|
2990 (value (car values)))
|
|
2991 (if (symbolp var)
|
|
2992 (set var value)
|
|
2993 (funcall (car (cdr var)) value)))
|
|
2994 (setq vars (cdr vars))
|
|
2995 (setq values (cdr values))))
|
|
2996
|
|
2997 ;; Make a temporary file that only we have access to.
|
|
2998 ;; PREFIX is appended to emerge-temp-file-prefix to make the filename prefix.
|
|
2999 (defun emerge-make-temp-file (prefix)
|
|
3000 (let ((f (make-temp-name (concat emerge-temp-file-prefix prefix))))
|
|
3001 ;; create the file
|
|
3002 (write-region (point-min) (point-min) f nil 'no-message)
|
|
3003 (set-file-modes f emerge-temp-file-mode)
|
|
3004 f))
|
|
3005
|
|
3006 ;;; Functions that query the user before he can write out the current buffer.
|
|
3007
|
|
3008 (defun emerge-query-write-file ()
|
|
3009 "Ask the user whether to write out an incomplete merge.
|
|
3010 If answer is yes, call `write-file' to do so. See `emerge-query-and-call'
|
|
3011 for details of the querying process."
|
|
3012 (interactive)
|
|
3013 (emerge-query-and-call 'write-file))
|
|
3014
|
|
3015 (defun emerge-query-save-buffer ()
|
|
3016 "Ask the user whether to save an incomplete merge.
|
|
3017 If answer is yes, call `save-buffer' to do so. See `emerge-query-and-call'
|
|
3018 for details of the querying process."
|
|
3019 (interactive)
|
|
3020 (emerge-query-and-call 'save-buffer))
|
|
3021
|
|
3022 (defun emerge-query-and-call (command)
|
|
3023 "Ask the user whether to save or write out the incomplete merge.
|
|
3024 If answer is yes, call COMMAND interactively. During the call, the flags
|
|
3025 around the current difference are removed."
|
|
3026 (if (yes-or-no-p "Do you really write to write out this unfinished merge? ")
|
|
3027 ;; He really wants to do it -- unselect the difference for the duration
|
|
3028 (progn
|
|
3029 (if (and (>= emerge-current-difference 0)
|
|
3030 (< emerge-current-difference emerge-number-of-differences))
|
|
3031 (emerge-unselect-difference emerge-current-difference))
|
|
3032 ;; call-interactively takes the value of current-prefix-arg as the
|
|
3033 ;; prefix argument value to be passed to the command. Thus, we have
|
|
3034 ;; to do nothing special to make sure the prefix argument is
|
|
3035 ;; transmitted to the command.
|
|
3036 (call-interactively command)
|
|
3037 (if (and (>= emerge-current-difference 0)
|
|
3038 (< emerge-current-difference emerge-number-of-differences))
|
|
3039 (progn
|
|
3040 (emerge-select-difference emerge-current-difference)
|
|
3041 (emerge-recenter))))
|
|
3042 ;; He's being smart and not doing it
|
|
3043 (message "Not written")))
|
|
3044
|
|
3045 ;; Make sure the current buffer (for a file) has the same contents as the
|
|
3046 ;; file on disk, and attempt to remedy the situation if not.
|
|
3047 ;; Signal an error if we can't make them the same, or the user doesn't want
|
|
3048 ;; to do what is necessary to make them the same.
|
|
3049 (defun emerge-verify-file-buffer ()
|
|
3050 ;; First check if the file has been modified since the buffer visited it.
|
|
3051 (if (verify-visited-file-modtime (current-buffer))
|
|
3052 (if (buffer-modified-p)
|
|
3053 ;; If buffer is not obsolete and is modified, offer to save
|
|
3054 (if (yes-or-no-p (format "Save file %s? " buffer-file-name))
|
|
3055 (save-buffer)
|
|
3056 (error "Buffer out of sync for file %s" buffer-file-name))
|
|
3057 ;; If buffer is not obsolete and is not modified, do nothing
|
|
3058 nil)
|
|
3059 (if (buffer-modified-p)
|
|
3060 ;; If buffer is obsolete and is modified, give error
|
|
3061 (error "Buffer out of sync for file %s" buffer-file-name)
|
|
3062 ;; If buffer is obsolete and is not modified, offer to revert
|
|
3063 (if (yes-or-no-p (format "Revert file %s? " buffer-file-name))
|
|
3064 (revert-buffer t t)
|
|
3065 (error "Buffer out of sync for file %s" buffer-file-name)))))
|
|
3066
|
|
3067 ;; Returns true if the file visited in the current buffer is not accessible
|
|
3068 ;; through its filename, or for some other reason should be stored in a
|
|
3069 ;; temporary file for input to diff.
|
|
3070 ;; As written, checks whether this is an ange-ftp file. It may be modified
|
|
3071 ;; for customization.
|
|
3072 (defun emerge-remote-file-p ()
|
|
3073 (and (boundp 'ange-ftp-path-format)
|
|
3074 ange-ftp-path-format
|
|
3075 (string-match (car ange-ftp-path-format) buffer-file-name)))
|
|
3076
|
|
3077 ;; Utilities that might have value outside of Emerge.
|
|
3078
|
|
3079 ;; Set up the mode in the current buffer to duplicate the mode in another
|
|
3080 ;; buffer.
|
|
3081 (defun emerge-copy-modes (buffer)
|
|
3082 ;; Set the major mode
|
189
|
3083 (funcall (with-current-buffer buffer major-mode)))
|
0
|
3084
|
|
3085 ;; Define a key, even if a prefix of it is defined
|
|
3086 (defun emerge-force-define-key (keymap key definition)
|
|
3087 "Like `define-key', but forcibly creates prefix characters as needed.
|
|
3088 If some prefix of KEY has a non-prefix definition, it is redefined."
|
|
3089 ;; Find out if a prefix of key is defined
|
|
3090 (let ((v (lookup-key keymap key)))
|
|
3091 ;; If so, undefine it
|
|
3092 (if (integerp v)
|
|
3093 (define-key keymap (substring key 0 v) nil)))
|
|
3094 ;; Now define the key
|
|
3095 (define-key keymap key definition))
|
|
3096
|
|
3097 ;; XEmacs -- nuked a bunch of junk here that provides a newer version
|
|
3098 ;; of `describe-mode' that describes minor modes as well as the major
|
|
3099 ;; mode. We have this code standardly.
|
|
3100
|
|
3101 ;; Show the name of the file in the buffer.
|
|
3102 (defun emerge-show-file-name ()
|
|
3103 "Displays the name of the file loaded into the current buffer.
|
|
3104 If the name won't fit on one line, the minibuffer is expanded to hold it,
|
|
3105 and the command waits for a keystroke from the user. If the keystroke is
|
|
3106 SPC, it is ignored\; if it is anything else, it is processed as a command."
|
|
3107 (interactive)
|
|
3108 (let ((name (buffer-file-name)))
|
|
3109 (or name
|
|
3110 (setq name "Buffer has no file name."))
|
|
3111 (save-window-excursion
|
|
3112 (select-window (minibuffer-window))
|
|
3113 (erase-buffer)
|
|
3114 (insert name)
|
|
3115 (if (not (pos-visible-in-window-p))
|
|
3116 (let ((echo-keystrokes 0))
|
|
3117 (while (and (not (pos-visible-in-window-p))
|
|
3118 (> (1- (screen-height)) (window-height)))
|
|
3119 (enlarge-window 1))
|
|
3120 (if emerge-xemacs-p
|
|
3121 (let ((e (next-command-event)))
|
|
3122 (if (not (eq 32 (event-to-character e)))
|
|
3123 (setq unread-command-event e)))
|
|
3124 (let ((c (read-event)))
|
|
3125 (if (not (eq c 32))
|
|
3126 (setq unread-command-events (list c))))))))))
|
|
3127
|
|
3128 ;; Improved auto-save file names.
|
|
3129 ;; This function fixes many problems with the standard auto-save file names:
|
|
3130 ;; Auto-save files for non-file buffers get put in the default directory
|
|
3131 ;; for the buffer, whether that makes sense or not.
|
|
3132 ;; Auto-save files for file buffers get put in the directory of the file,
|
|
3133 ;; regardless of whether we can write into it or not.
|
|
3134 ;; Auto-save files for non-file buffers don't use the process id, so if a
|
|
3135 ;; user runs more than on Emacs, they can make auto-save files that overwrite
|
|
3136 ;; each other.
|
|
3137 ;; To use this function, do:
|
|
3138 ;; (fset 'make-auto-save-file-name
|
|
3139 ;; (symbol-function 'emerge-make-auto-save-file-name))
|
|
3140 (defun emerge-make-auto-save-file-name ()
|
|
3141 "Return file name to use for auto-saves of current buffer.
|
|
3142 Does not consider `auto-save-visited-file-name';
|
|
3143 that is checked before calling this function.
|
|
3144 You can redefine this for customization.
|
|
3145 See also `auto-save-file-name-p'."
|
|
3146 (if buffer-file-name
|
|
3147 ;; if buffer has a file, try the format <file directory>/#<file name>#
|
|
3148 (let ((f (concat (file-name-directory buffer-file-name)
|
|
3149 "#"
|
|
3150 (file-name-nondirectory buffer-file-name)
|
|
3151 "#")))
|
|
3152 (if (file-writable-p f)
|
|
3153 ;; the file is writable, so use it
|
|
3154 f
|
|
3155 ;; the file isn't writable, so use the format
|
|
3156 ;; ~/#&<file name>&<hash of directory>#
|
|
3157 (concat (getenv "HOME")
|
|
3158 "/#&"
|
|
3159 (file-name-nondirectory buffer-file-name)
|
|
3160 "&"
|
|
3161 (emerge-hash-string-into-string
|
|
3162 (file-name-directory buffer-file-name))
|
|
3163 "#")))
|
|
3164 ;; if buffer has no file, use the format ~/#%<buffer name>%<process id>#
|
|
3165 (expand-file-name (concat (getenv "HOME")
|
|
3166 "/#%"
|
|
3167 ;; quote / into \! and \ into \\
|
|
3168 (emerge-unslashify-name (buffer-name))
|
|
3169 "%"
|
|
3170 (make-temp-name "")
|
|
3171 "#"))))
|
|
3172
|
|
3173 ;; Hash a string into five characters more-or-less suitable for use in a file
|
|
3174 ;; name. (Allowed characters are ! through ~, except /.)
|
|
3175 (defun emerge-hash-string-into-string (s)
|
|
3176 (let ((bins (vector 0 0 0 0 0))
|
|
3177 (i 0))
|
|
3178 (while (< i (length s))
|
|
3179 (aset bins (% i 5) (% (+ (* (aref bins (% i 5)) 35)
|
|
3180 (aref s i))
|
|
3181 65536))
|
|
3182 (setq i (1+ i)))
|
|
3183 (mapconcat (function (lambda (b)
|
|
3184 (setq b (+ (% b 93) ?!))
|
|
3185 (if (>= b ?/)
|
|
3186 (setq b (1+ b)))
|
|
3187 (char-to-string b)))
|
|
3188 bins "")))
|
|
3189
|
|
3190 ;; Quote any /s in a string by replacing them with \!.
|
|
3191 ;; Also, replace any \s by \\, to make it one-to-one.
|
|
3192 (defun emerge-unslashify-name (s)
|
|
3193 (let ((limit 0))
|
|
3194 (while (string-match "[/\\]" s limit)
|
|
3195 (setq s (concat (substring s 0 (match-beginning 0))
|
|
3196 (if (string= (substring s (match-beginning 0)
|
|
3197 (match-end 0))
|
|
3198 "/")
|
|
3199 "\\!"
|
|
3200 "\\\\")
|
|
3201 (substring s (match-end 0))))
|
|
3202 (setq limit (1+ (match-end 0)))))
|
|
3203 s)
|
|
3204
|
|
3205 ;; Metacharacters that have to be protected from the shell when executing
|
|
3206 ;; a diff/diff3 command.
|
|
3207 (defvar emerge-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
|
|
3208 "Characters that must be quoted with \\ when used in a shell command line.
|
|
3209 More precisely, a [...] regexp to match any one such character.")
|
|
3210
|
|
3211 ;; Quote metacharacters (using \) when executing a diff/diff3 command.
|
|
3212 (defun emerge-protect-metachars (s)
|
|
3213 (let ((limit 0))
|
|
3214 (while (string-match emerge-metachars s limit)
|
|
3215 (setq s (concat (substring s 0 (match-beginning 0))
|
|
3216 "\\"
|
|
3217 (substring s (match-beginning 0))))
|
|
3218 (setq limit (1+ (match-end 0)))))
|
|
3219 s)
|
|
3220
|
|
3221 (provide 'emerge)
|
|
3222
|
|
3223 ;;; emerge.el ends here
|