annotate lisp/emerge.el @ 966:eb74884fc95a

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