annotate lisp/packages/emerge.el @ 110:fe104dbd9147 r20-1b7

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