annotate lisp/emerge.el @ 866:ae5c412a32ec

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