annotate lisp/emerge.el @ 1436:e7c5faab6571

* xterm.c (compose_status): New variable. (XTread_socket): Pass it by reference to XLookupString. * xterm.c: Clean up some of the caps lock handling: (x_shift_lock_mask): New variable. (x_find_modifier_mappings): Set it, based on the modifier mappings. (x_convert_modifiers): Use x_shift_lock_mask, instead of assuming that the lock bit always means to shift the character. (XTread_socket): When handling KeyPress events, don't pass an XComposeStatus structure along to XLookupString. When handling MappingNotify events, call XRefreshKeyboardMapping for both MappingModifier and MappingKeyboard events, not just the latter.
author Jim Blandy <jimb@redhat.com>
date Mon, 19 Oct 1992 18:31:34 +0000
parents 14a2a89cb634
children fc2b0405bd87
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.
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
567 Differs from `save-excursion' in that it doesn't save the point and mark."
583
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)
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
576 "Defines SYMBOL as an advertised variable.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
577 Performs a defvar, then executes `make-variable-buffer-local' on
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
578 the variable. Also sets the 'preserved' property, so that
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
579 `kill-all-local-variables' (called by major-mode setting commands)
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
580 won't destroy Emerge control variables."
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
581 (` (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
582 (defvar (, var) (, value) (, doc))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
583 (make-variable-buffer-local '(, var))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
584 (put '(, var) 'preserved t))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
585
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
586 ;; Add entries to minor-mode-alist so that emerge modes show correctly
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587 (setq emerge-minor-modes-list '((emerge-mode " Emerge")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
588 (emerge-fast-mode " F")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
589 (emerge-edit-mode " E")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590 (emerge-auto-advance " A")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
591 (emerge-skip-prefers " S")))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
592 (if (not (assq 'emerge-mode minor-mode-alist))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
593 (setq minor-mode-alist (append emerge-minor-modes-list
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
594 minor-mode-alist)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
595
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
596 ;; We need to define this function so describe-mode can describe Emerge mode.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
597 (defun emerge-mode ()
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
598 "Emerge mode is used by the Emerge file-merging package.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
599 It is entered only through one of the functions:
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
600 `emerge-files'
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
601 `emerge-files-with-ancestor'
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
602 `emerge-buffers'
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
603 `emerge-buffers-with-ancestor'
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
604 `emerge-files-command'
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
605 `emerge-files-with-ancestor-command'
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
606 `emerge-files-remote'
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
607 `emerge-files-with-ancestor-remote'
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
608
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
609 Commands:
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
610 \\{emerge-basic-keymap}
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
611 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
612 in 'fast' mode.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
613
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
614 (defvar emerge-version "4"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
615 "The version of Emerge.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
616
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
617 (defun emerge-version ()
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
618 "Return string describing the version of Emerge.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
619 When called interactively, displays the version."
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
620 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
621 (if (interactive-p)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
622 (message "Emerge version %s" (emerge-version))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
623 emerge-version))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
624
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
625 ;;; Emerge configuration variables
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
626
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
627 ;; Commands that produce difference files
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
628 ;; All that can be configured is the name of the programs to execute
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
629 ;; (emerge-diff-program and emerge-diff3-program) and the options
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
630 ;; to be provided (emerge-diff-options). The order in which the file names
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
631 ;; are given is fixed.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
632 ;; The file names are always expanded (see expand-file-name) before being
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
633 ;; passed to diff, thus they need not be invoked under a shell that
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
634 ;; understands '~'.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
635 ;; The code which processes the diff/diff3 output depends on all the
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
636 ;; finicky details of their output, including the somewhat strange
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
637 ;; way they number lines of a file.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
638 (defvar emerge-diff-program "diff"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
639 "*Name of the program which compares two files.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
640 (defvar emerge-diff3-program "diff3"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
641 "*Name of the program which compares an ancestor file (first argument)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
642 and two variant files (second and third arguments).")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
643 (defvar emerge-diff-options ""
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
644 "*Options to be passed to emerge-diff/diff3-program.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
645 (defvar emerge-match-diff-line (let ((x "\\([0-9]+\\)\\(\\|,\\([0-9]+\\)\\)"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
646 (concat "^" x "\\([acd]\\)" x "$"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
647 "*Pattern to match lines produced by diff that describe differences (as
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
648 opposed to lines from the source files).")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
649 (defvar emerge-diff-ok-lines
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
650 "^\\([0-9,]+[acd][0-9,]+$\\|[<>] \\|---\\)"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
651 "*Regexp that matches normal output lines from emerge-diff-program .
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
652 Lines that do not match are assumed to be error output.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
653 (defvar emerge-diff3-ok-lines
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
654 "^\\([1-3]:\\|====\\| \\)"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
655 "*Regexp that matches normal output lines from emerge-diff3-program .
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
656 Lines that do not match are assumed to be error output.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
657
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
658 ;; The flags used to mark differences in the buffers.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
659
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
660 ;; These function definitions need to be up here, because they are used
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
661 ;; during loading.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
662 (defun emerge-new-flags ()
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
663 "Function to be called after `emerge-{before,after}-flag'.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
664 This is called after these functions are changed to compute values that
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
665 depend on the flags."
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
666 (setq emerge-before-flag-length (length emerge-before-flag))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
667 (setq emerge-before-flag-lines
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
668 (count-matches-string emerge-before-flag "\n"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
669 (setq emerge-before-flag-match (regexp-quote emerge-before-flag))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
670 (setq emerge-after-flag-length (length emerge-after-flag))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
671 (setq emerge-after-flag-lines
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
672 (count-matches-string emerge-after-flag "\n"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
673 (setq emerge-after-flag-match (regexp-quote emerge-after-flag)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
674 (defun count-matches-string (string regexp)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
675 "Return the number of matches in STRING for REGEXP."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
676 (let ((i 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
677 (count 0))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
678 (while (string-match regexp string i)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
679 (setq count (1+ count))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
680 (setq i (match-end 0)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
681 count))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
682
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
683 (defvar emerge-before-flag "vvvvvvvvvvvvvvvvvvvv\n"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
684 "*Flag placed above the highlighted block of code. Must end with newline.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
685 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
686 after setting.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
687 (defvar emerge-after-flag "^^^^^^^^^^^^^^^^^^^^\n"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
688 "*Flag placed below the highlighted block of code. Must end with newline.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
689 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
690 after setting.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
691
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
692 ;; Calculate dependent variables
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
693 (emerge-new-flags)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
694
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
695 (defvar emerge-min-visible-lines 3
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
696 "*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
697 displaying a difference.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
698
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
699 (defvar emerge-temp-file-prefix
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
700 (let ((env (getenv "TMPDIR"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
701 d)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
702 (setq d (if (and env (> (length env) 0))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
703 env
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
704 "/tmp"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
705 (if (= (aref d (1- (length d))) ?/)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
706 (setq d (substring d 0 -1)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
707 (concat d "/emerge"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
708 "*Prefix to put on Emerge temporary file names.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
709 Do not start with '~/' or '~user-name/'.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
710
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
711 (defvar emerge-temp-file-mode 384 ; u=rw only
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
712 "*Mode for Emerge temporary files.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
713
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
714 (defvar emerge-combine-versions-template
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
715 "#ifdef NEW\n%b#else /* NEW */\n%a#endif /* NEW */\n"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
716 "*Template for emerge-combine-versions to combine the two versions.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
717 The template is inserted as a string, with the following interpolations:
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
718 %a the A version of the difference
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
719 %b the B version of the difference
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
720 %% the character '%'
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
721 Don't forget to end the template with a newline.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
722 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
723 giving a prefix argument to emerge-set-combine-versions-template .")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
724
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
725 ;; Build keymaps
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
726
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
727 (defvar emerge-basic-keymap nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
728 "Keymap of Emerge commands.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
729 Directly available in 'fast' mode;
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
730 must be prefixed by \\<emerge-fast-keymap>\\[emerge-basic-keymap] in 'edit' mode.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
731
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
732 (defvar emerge-fast-keymap nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
733 "Local keymap used in Emerge 'fast' mode.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
734 Makes Emerge commands directly available.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
735
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
736 (defvar emerge-command-prefix "\C-c"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
737 "*Command prefix for Emerge commands in 'edit' mode.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
738 Must be set before Emerge is loaded.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
739
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
740 ;; This function sets up the fixed keymaps. It is executed when the first
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
741 ;; 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
742 (defun emerge-setup-fixed-keymaps ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
743 ;; Set up the basic keymap
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
744 (setq emerge-basic-keymap (make-keymap))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
745 (suppress-keymap emerge-basic-keymap) ; this sets 0..9 to digit-argument and
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
746 ; - to negative-argument
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
747 (define-key emerge-basic-keymap "p" 'emerge-previous-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
748 (define-key emerge-basic-keymap "n" 'emerge-next-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
749 (define-key emerge-basic-keymap "a" 'emerge-select-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
750 (define-key emerge-basic-keymap "b" 'emerge-select-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
751 (define-key emerge-basic-keymap "j" 'emerge-jump-to-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
752 (define-key emerge-basic-keymap "q" 'emerge-quit)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
753 (define-key emerge-basic-keymap "f" 'emerge-fast-mode)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
754 (define-key emerge-basic-keymap "e" 'emerge-edit-mode)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
755 (define-key emerge-basic-keymap "s" nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
756 (define-key emerge-basic-keymap "sa" 'emerge-auto-advance)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
757 (define-key emerge-basic-keymap "ss" 'emerge-skip-prefers)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
758 (define-key emerge-basic-keymap "l" 'emerge-recenter)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
759 (define-key emerge-basic-keymap "d" nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
760 (define-key emerge-basic-keymap "da" 'emerge-default-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
761 (define-key emerge-basic-keymap "db" 'emerge-default-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
762 (define-key emerge-basic-keymap "c" nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
763 (define-key emerge-basic-keymap "ca" 'emerge-copy-as-kill-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
764 (define-key emerge-basic-keymap "cb" 'emerge-copy-as-kill-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
765 (define-key emerge-basic-keymap "i" nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
766 (define-key emerge-basic-keymap "ia" 'emerge-insert-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
767 (define-key emerge-basic-keymap "ib" 'emerge-insert-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
768 (define-key emerge-basic-keymap "m" 'emerge-mark-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
769 (define-key emerge-basic-keymap "v" 'emerge-scroll-up)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
770 (define-key emerge-basic-keymap "^" 'emerge-scroll-down)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
771 (define-key emerge-basic-keymap "<" 'emerge-scroll-left)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
772 (define-key emerge-basic-keymap ">" 'emerge-scroll-right)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
773 (define-key emerge-basic-keymap "|" 'emerge-scroll-reset)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
774 (define-key emerge-basic-keymap "x" nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
775 (define-key emerge-basic-keymap "x1" 'emerge-one-line-window)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
776 (define-key emerge-basic-keymap "xa" 'emerge-find-difference-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
777 (define-key emerge-basic-keymap "xb" 'emerge-find-difference-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
778 (define-key emerge-basic-keymap "xc" 'emerge-combine-versions)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
779 (define-key emerge-basic-keymap "xC" 'emerge-combine-versions-register)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
780 (define-key emerge-basic-keymap "xd" 'emerge-find-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
781 (define-key emerge-basic-keymap "xf" 'emerge-file-names)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
782 (define-key emerge-basic-keymap "xj" 'emerge-join-differences)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
783 (define-key emerge-basic-keymap "xl" 'emerge-line-numbers)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
784 (define-key emerge-basic-keymap "xm" 'emerge-set-merge-mode)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
785 (define-key emerge-basic-keymap "xs" 'emerge-split-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
786 (define-key emerge-basic-keymap "xt" 'emerge-trim-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
787 (define-key emerge-basic-keymap "xx" 'emerge-set-combine-versions-template)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
788 ;; Allow emerge-basic-keymap to be referenced indirectly
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
789 (fset 'emerge-basic-keymap emerge-basic-keymap)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
790 ;; Set up the fast mode keymap
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
791 (setq emerge-fast-keymap (copy-keymap emerge-basic-keymap))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
792 ;; Allow prefixed commands to work in fast mode
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
793 (define-key emerge-fast-keymap emerge-command-prefix 'emerge-basic-keymap)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
794 ;; Allow emerge-fast-keymap to be referenced indirectly
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
795 (fset 'emerge-fast-keymap emerge-fast-keymap)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
796 ;; Suppress write-file and save-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
797 (emerge-shadow-key-definition 'write-file 'emerge-query-write-file
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 (emerge-shadow-key-definition 'save-buffer 'emerge-query-save-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
800 (current-global-map) emerge-fast-keymap))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
801
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
802 ;; Variables which control each merge. They are local to the merge buffer.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
803
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
804 ;; Mode variables
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
805 (emerge-defvar-local emerge-mode nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
806 "Indicator for emerge-mode.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
807 (emerge-defvar-local emerge-fast-mode nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
808 "Indicator for emerge-mode fast submode.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
809 (emerge-defvar-local emerge-edit-mode nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
810 "Indicator for emerge-mode edit submode.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
811 (emerge-defvar-local emerge-A-buffer nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
812 "The buffer in which the A variant is stored.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
813 (emerge-defvar-local emerge-B-buffer nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
814 "The buffer in which the B variant is stored.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
815 (emerge-defvar-local emerge-merge-buffer nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
816 "The buffer in which the merged file is manipulated.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
817 (emerge-defvar-local emerge-ancestor-buffer nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
818 "The buffer in which the ancestor variant is stored,
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
819 or nil if there is none.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
820
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
821 (defconst emerge-saved-variables
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
822 '((buffer-modified-p set-buffer-modified-p)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
823 buffer-read-only
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
824 buffer-auto-save-file-name)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
825 "Variables and properties of a buffer which are saved, modified and restored
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
826 during a merge.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
827 (defconst emerge-merging-values '(nil t nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
828 "Values to be assigned to emerge-saved-variables during a merge.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
829
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
830 (emerge-defvar-local emerge-A-buffer-values nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
831 "Remembers emerge-saved-variables for emerge-A-buffer.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
832 (emerge-defvar-local emerge-B-buffer-values nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
833 "Remembers emerge-saved-variables for emerge-B-buffer.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
834
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
835 (emerge-defvar-local emerge-difference-list nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
836 "Vector of differences between the variants, and markers in the buffers to
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
837 show where they are. Each difference is represented by a vector of seven
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
838 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
839 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
840 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
841 that difference in the merge buffer.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
842 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
843 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
844 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
845 point.) If the section is part of the selected difference, then the markers
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
846 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
847 the markers.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
848 The \"states\" are:
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
849 A the merge buffer currently contains the A variant
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
850 B the merge buffer currently contains the B variant
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
851 default-A the merge buffer contains the A variant by default,
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
852 but this difference hasn't been selected yet, so
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
853 change-default commands can alter it
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
854 default-B the merge buffer contains the B variant by default,
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
855 but this difference hasn't been selected yet, so
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
856 change-default commands can alter it
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
857 prefer-A in a three-file merge, the A 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 prefer-B in a three-file merge, the B variant is the prefered
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
860 choice")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
861 (emerge-defvar-local emerge-current-difference -1
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
862 "The difference that is currently selected.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
863 (emerge-defvar-local emerge-number-of-differences nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
864 "Number of differences found.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
865 (emerge-defvar-local emerge-edit-keymap nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
866 "The local keymap for the merge buffer, with the emerge commands defined in
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
867 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
868 replaced by emerge-fast-keymap.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
869 (emerge-defvar-local emerge-old-keymap nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
870 "The original local keymap for the merge buffer.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
871 (emerge-defvar-local emerge-auto-advance nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
872 "*If non-nil, emerge-select-A and emerge-select-B automatically advance to
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
873 the next difference.")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
874 (emerge-defvar-local emerge-skip-prefers nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
875 "*If non-nil, differences for which there is a preference are automatically
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
876 skipped.")
854
0b4f3a91f207 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 778
diff changeset
877 (emerge-defvar-local emerge-startup-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 set up.")
854
0b4f3a91f207 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 778
diff changeset
879 (emerge-defvar-local emerge-quit-hook nil
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
880 "Hooks to run in the merge buffer after the merge has been finished.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
881 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
882 command.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
883 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
884 (emerge-defvar-local emerge-output-description nil
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
885 "Describes output destination merge, for the use of `emerge-file-names'.")
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
886
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
887 ;;; Setup functions for two-file mode.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
888
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
889 (defun emerge-files-internal (file-A file-B &optional startup-hooks quit-hooks
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
890 output-file)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
891 (let ((buffer-A (find-file-noselect file-A))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
892 (buffer-B (find-file-noselect file-B)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
893 ;; 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
894 (emerge-eval-in-buffer buffer-A
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
895 (widen)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
896 (emerge-verify-file-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
897 (emerge-eval-in-buffer buffer-B
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
898 (widen)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
899 (emerge-verify-file-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
900 (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
901 output-file)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
902
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
903 ;; Start up Emerge on two files
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
904 (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
905 output-file)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
906 (setq file-A (expand-file-name file-A))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
907 (setq file-B (expand-file-name file-B))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
908 (setq output-file (and output-file (expand-file-name output-file)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
909 (let* ((merge-buffer-name (emerge-unique-buffer-name "*merge" "*"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
910 ;; create the merge buffer from buffer A, so it inherits buffer A's
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
911 ;; default directory, etc.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
912 (merge-buffer (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
913 buffer-A
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
914 (get-buffer-create merge-buffer-name))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
915 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
916 merge-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
917 (emerge-copy-modes buffer-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
918 (setq buffer-read-only nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
919 (auto-save-mode 1)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
920 (setq emerge-mode t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
921 (setq emerge-A-buffer buffer-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
922 (setq emerge-B-buffer buffer-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
923 (setq emerge-ancestor-buffer nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
924 (setq emerge-merge-buffer merge-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
925 (setq emerge-output-description
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
926 (if output-file
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
927 (concat "Output to file: " output-file)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
928 (concat "Output to buffer: " (buffer-name merge-buffer))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
929 (insert-buffer emerge-A-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
930 (emerge-set-keys)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
931 (setq emerge-difference-list (emerge-make-diff-list file-A file-B))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
932 (setq emerge-number-of-differences (length emerge-difference-list))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
933 (setq emerge-current-difference -1)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
934 (setq emerge-quit-hooks quit-hooks)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
935 (emerge-remember-buffer-characteristics))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
936 (emerge-setup-windows buffer-A buffer-B merge-buffer t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
937 (emerge-eval-in-buffer merge-buffer
854
0b4f3a91f207 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 778
diff changeset
938 (run-hooks 'startup-hooks 'emerge-startup-hook)
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
939 (setq buffer-read-only t))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
940
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
941 ;; Generate the Emerge difference list between two files
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
942 (defun emerge-make-diff-list (file-A file-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
943 (setq emerge-diff-buffer (get-buffer-create "*emerge-diff*"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
944 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
945 emerge-diff-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
946 (erase-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
947 (shell-command
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
948 (format "%s %s %s %s"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
949 emerge-diff-program emerge-diff-options file-A file-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
950 t))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
951 (emerge-prepare-error-list emerge-diff-ok-lines)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
952 (emerge-convert-diffs-to-markers
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
953 emerge-A-buffer emerge-B-buffer emerge-merge-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
954 (emerge-extract-diffs emerge-diff-buffer)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
955
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
956 (defun emerge-extract-diffs (diff-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
957 (let (list)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
958 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
959 diff-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
960 (goto-char (point-min))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
961 (while (re-search-forward emerge-match-diff-line nil t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
962 (let* ((a-begin (string-to-int (buffer-substring (match-beginning 1)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
963 (match-end 1))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
964 (a-end (let ((b (match-beginning 3))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
965 (e (match-end 3)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
966 (if b
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
967 (string-to-int (buffer-substring b e))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
968 a-begin)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
969 (diff-type (buffer-substring (match-beginning 4) (match-end 4)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
970 (b-begin (string-to-int (buffer-substring (match-beginning 5)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
971 (match-end 5))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
972 (b-end (let ((b (match-beginning 7))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
973 (e (match-end 7)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
974 (if b
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
975 (string-to-int (buffer-substring b e))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
976 b-begin))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
977 ;; fix the beginning and end numbers, because diff is somewhat
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
978 ;; strange about how it numbers lines
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
979 (if (string-equal diff-type "a")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
980 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
981 (setq b-end (1+ b-end))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
982 (setq a-begin (1+ a-begin))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
983 (setq a-end a-begin))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
984 (if (string-equal diff-type "d")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
985 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
986 (setq a-end (1+ a-end))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
987 (setq b-begin (1+ b-begin))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
988 (setq b-end b-begin))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
989 ;; (string-equal diff-type "c")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
990 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
991 (setq a-end (1+ a-end))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
992 (setq b-end (1+ b-end)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
993 (setq list (cons (vector a-begin a-end
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
994 b-begin b-end
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
995 'default-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
996 list)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
997 (nreverse list)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
998
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
999 ;; Set up buffer of diff/diff3 error messages.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1000 (defun emerge-prepare-error-list (ok-regexp)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1001 (setq emerge-diff-error-buffer (get-buffer-create "*emerge-diff-errors*"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1002 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1003 emerge-diff-error-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1004 (erase-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1005 (insert-buffer emerge-diff-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1006 (delete-matching-lines ok-regexp)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1007
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1008 ;;; Top-level and setup functions for three-file mode.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1009
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1010 (defun emerge-files-with-ancestor-internal (file-A file-B file-ancestor
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1011 &optional startup-hooks quit-hooks
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1012 output-file)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1013 (let ((buffer-A (find-file-noselect file-A))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1014 (buffer-B (find-file-noselect file-B))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1015 (buffer-ancestor (find-file-noselect file-ancestor)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1016 ;; 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
1017 (emerge-eval-in-buffer buffer-A
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1018 (widen)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1019 (emerge-verify-file-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1020 (emerge-eval-in-buffer buffer-B
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1021 (widen)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1022 (emerge-verify-file-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1023 (emerge-eval-in-buffer buffer-ancestor
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1024 (widen)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1025 (emerge-verify-file-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1026 (emerge-setup-with-ancestor buffer-A file-A buffer-B file-B
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1027 buffer-ancestor file-ancestor
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1028 startup-hooks quit-hooks output-file)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1029
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1030 ;; Start up Emerge on two files with an ancestor
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1031 (defun emerge-setup-with-ancestor (buffer-A file-A buffer-B file-B
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1032 buffer-ancestor file-ancestor
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1033 &optional startup-hooks quit-hooks
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1034 output-file)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1035 (setq file-A (expand-file-name file-A))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1036 (setq file-B (expand-file-name file-B))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1037 (setq file-ancestor (expand-file-name file-ancestor))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1038 (setq output-file (and output-file (expand-file-name output-file)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1039 (let* ((merge-buffer-name (emerge-unique-buffer-name "*merge" "*"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1040 ;; create the merge buffer from buffer A, so it inherits buffer A's
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1041 ;; default directory, etc.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1042 (merge-buffer (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1043 buffer-A
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1044 (get-buffer-create merge-buffer-name))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1045 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1046 merge-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1047 (emerge-copy-modes buffer-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1048 (setq buffer-read-only nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1049 (auto-save-mode 1)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1050 (setq emerge-mode t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1051 (setq emerge-A-buffer buffer-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1052 (setq emerge-B-buffer buffer-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1053 (setq emerge-ancestor-buffer buffer-ancestor)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1054 (setq emerge-merge-buffer merge-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1055 (setq emerge-output-description
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1056 (if output-file
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1057 (concat "Output to file: " output-file)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1058 (concat "Output to buffer: " (buffer-name merge-buffer))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1059 (insert-buffer emerge-A-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1060 (emerge-set-keys)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1061 (setq emerge-difference-list
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1062 (emerge-make-diff3-list file-A file-B file-ancestor))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1063 (setq emerge-number-of-differences (length emerge-difference-list))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1064 (setq emerge-current-difference -1)
854
0b4f3a91f207 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 778
diff changeset
1065 (setq emerge-quit-hook quit-hooks)
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1066 (emerge-remember-buffer-characteristics)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1067 (emerge-select-prefer-Bs))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1068 (emerge-setup-windows buffer-A buffer-B merge-buffer t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1069 (emerge-eval-in-buffer merge-buffer
854
0b4f3a91f207 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 778
diff changeset
1070 (run-hooks 'startup-hooks 'emerge-startup-hook)
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1071 (setq buffer-read-only t))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1072
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1073 ;; Generate the Emerge difference list between two files with an ancestor
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1074 (defun emerge-make-diff3-list (file-A file-B file-ancestor)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1075 (setq emerge-diff-buffer (get-buffer-create "*emerge-diff*"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1076 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1077 emerge-diff-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1078 (erase-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1079 (shell-command
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1080 (format "%s %s %s %s %s"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1081 emerge-diff3-program emerge-diff-options
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1082 file-ancestor file-A file-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1083 t))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1084 (emerge-prepare-error-list emerge-diff3-ok-lines)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1085 (emerge-convert-diffs-to-markers
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1086 emerge-A-buffer emerge-B-buffer emerge-merge-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1087 (emerge-extract-diffs3 emerge-diff-buffer)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1088
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1089 (defun emerge-extract-diffs3 (diff-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1090 (let (list)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1091 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1092 diff-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1093 (while (re-search-forward "^====\\(.?\\)$" nil t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1094 ;; leave point after matched line
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1095 (beginning-of-line 2)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1096 (let ((agreement (buffer-substring (match-beginning 1) (match-end 1))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1097 ;; if the A and B files are the same, ignore the difference
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1098 (if (not (string-equal agreement "1"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1099 (setq list
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1100 (cons
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1101 (let ((group-2 (emerge-get-diff3-group "2"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1102 (group-3 (emerge-get-diff3-group "3")))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1103 (vector (car group-2) (car (cdr group-2))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1104 (car group-3) (car (cdr group-3))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1105 (cond ((string-equal agreement "2") 'prefer-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1106 ((string-equal agreement "3") 'prefer-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1107 (t 'default-A))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1108 list))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1109 (nreverse list)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1110
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1111 (defun emerge-get-diff3-group (file)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1112 ;; This save-excursion allows emerge-get-diff3-group to be called for the
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1113 ;; 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
1114 ;; appear in any order. The reason this is necessary is that Gnu diff3
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1115 ;; 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
1116 (save-excursion
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1117 (re-search-forward
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1118 (concat "^" file ":\\([0-9]+\\)\\(,\\([0-9]+\\)\\)?\\([ac]\\)$"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1119 (beginning-of-line 2)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1120 ;; treatment depends on whether it is an "a" group or a "c" group
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1121 (if (string-equal (buffer-substring (match-beginning 4) (match-end 4)) "c")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1122 ;; it is a "c" group
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1123 (if (match-beginning 2)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1124 ;; it has two numbers
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1125 (list (string-to-int
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1126 (buffer-substring (match-beginning 1) (match-end 1)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1127 (1+ (string-to-int
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1128 (buffer-substring (match-beginning 3) (match-end 3)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1129 ;; it has one number
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1130 (let ((x (string-to-int
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1131 (buffer-substring (match-beginning 1) (match-end 1)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1132 (list x (1+ x))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1133 ;; it is an "a" group
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1134 (let ((x (1+ (string-to-int
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1135 (buffer-substring (match-beginning 1) (match-end 1))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1136 (list x x)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1137
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1138 ;;; Functions to start Emerge on files
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1139
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 583
diff changeset
1140 ;;;###autoload
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1141 (defun emerge-files (arg file-A file-B file-out &optional startup-hooks
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1142 quit-hooks)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1143 "Run Emerge on two files."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1144 (interactive
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1145 (let (f)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1146 (list current-prefix-arg
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1147 (setq f (read-file-name "File A to merge: " nil nil 'confirm))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1148 (read-file-name "File B to merge: " nil nil 'confirm)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1149 (and current-prefix-arg
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1150 (read-file-name
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1151 (format "Output file: (default %s) " f)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1152 nil f nil)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1153 (emerge-files-internal
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1154 file-A file-B startup-hooks
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1155 (if arg
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1156 (cons (` (lambda () (emerge-files-exit (, file-out))))
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 quit-hooks)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1159 file-out))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1160
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 583
diff changeset
1161 ;;;###autoload
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1162 (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
1163 &optional startup-hooks quit-hooks)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1164 "Run Emerge on two files, giving another file as the ancestor."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1165 (interactive
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1166 (let (f)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1167 (list current-prefix-arg
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1168 (setq f (read-file-name "File A to merge: " nil nil 'confirm))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1169 (read-file-name "File B to merge: " nil nil 'confirm)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1170 (read-file-name "Ancestor file: " nil nil 'confirm)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1171 (and current-prefix-arg
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1172 (read-file-name
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1173 (format "Output file: (default %s) " f)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1174 nil f nil)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1175 (emerge-files-with-ancestor-internal
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1176 file-A file-B file-ancestor startup-hooks
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1177 (if arg
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1178 (cons (` (lambda () (emerge-files-exit (, file-out))))
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 quit-hooks)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1181 file-out))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1182
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1183 ;; 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
1184 (defun emerge-files-exit (file-out)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1185 ;; if merge was successful was given, save to disk
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1186 (if (not emerge-prefix-argument)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1187 (emerge-write-and-delete file-out)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1188
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1189 ;;; Functions to start Emerge on buffers
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1190
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 583
diff changeset
1191 ;;;###autoload
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1192 (defun emerge-buffers (buffer-A buffer-B &optional startup-hooks quit-hooks)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1193 "Run Emerge on two buffers."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1194 (interactive "bBuffer A to merge: \nbBuffer B to merge: ")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1195 (let ((emerge-file-A (emerge-make-temp-file "A"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1196 (emerge-file-B (emerge-make-temp-file "B")))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1197 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1198 buffer-A
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1199 (write-region (point-min) (point-max) emerge-file-A nil 'no-message))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1200 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1201 buffer-B
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1202 (write-region (point-min) (point-max) emerge-file-B nil 'no-message))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1203 (emerge-setup (get-buffer buffer-A) emerge-file-A
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1204 (get-buffer buffer-B) emerge-file-B
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1205 (cons (function (lambda ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1206 (delete-file emerge-file-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1207 (delete-file emerge-file-B)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1208 startup-hooks)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1209 quit-hooks
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1210 nil)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1211
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 583
diff changeset
1212 ;;;###autoload
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1213 (defun emerge-buffers-with-ancestor (buffer-A buffer-B buffer-ancestor
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1214 &optional startup-hooks
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1215 quit-hooks)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1216 "Run Emerge on two buffers, giving another buffer as the ancestor."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1217 (interactive
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1218 "bBuffer A to merge: \nbBuffer B to merge: \nbAncestor buffer: ")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1219 (let ((emerge-file-A (emerge-make-temp-file "A"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1220 (emerge-file-B (emerge-make-temp-file "B"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1221 (emerge-file-ancestor (emerge-make-temp-file "anc")))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1222 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1223 buffer-A
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1224 (write-region (point-min) (point-max) emerge-file-A nil 'no-message))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1225 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1226 buffer-B
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1227 (write-region (point-min) (point-max) emerge-file-B nil 'no-message))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1228 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1229 buffer-ancestor
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1230 (write-region (point-min) (point-max) emerge-file-ancestor nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1231 'no-message))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1232 (emerge-setup-with-ancestor (get-buffer buffer-A) emerge-file-A
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1233 (get-buffer buffer-B) emerge-file-B
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1234 (get-buffer buffer-ancestor)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1235 emerge-file-ancestor
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1236 (cons (function (lambda ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1237 (delete-file emerge-file-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1238 (delete-file emerge-file-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1239 (delete-file
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1240 emerge-file-ancestor)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1241 startup-hooks)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1242 quit-hooks
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1243 nil)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1244
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1245 ;;; Functions to start Emerge from the command line
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1246
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 583
diff changeset
1247 ;;;###autoload
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1248 (defun emerge-files-command ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1249 (let ((file-a (nth 0 command-line-args-left))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1250 (file-b (nth 1 command-line-args-left))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1251 (file-out (nth 2 command-line-args-left)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1252 (setq command-line-args-left (nthcdr 3 command-line-args-left))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1253 (emerge-files-internal
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1254 file-a file-b nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1255 (list (` (lambda () (emerge-command-exit (, file-out))))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1256
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 583
diff changeset
1257 ;;;###autoload
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1258 (defun emerge-files-with-ancestor-command ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1259 (let (file-a file-b file-anc file-out)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1260 ;; check for a -a flag, for filemerge compatibility
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1261 (if (string= (car command-line-args-left) "-a")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1262 ;; arguments are "-a ancestor file-a file-b file-out"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1263 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1264 (setq file-a (nth 2 command-line-args-left))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1265 (setq file-b (nth 3 command-line-args-left))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1266 (setq file-anc (nth 1 command-line-args-left))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1267 (setq file-out (nth 4 command-line-args-left))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1268 (setq command-line-args-left (nthcdr 5 command-line-args-left)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1269 ;; arguments are "file-a file-b ancestor file-out"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1270 (setq file-a (nth 0 command-line-args-left))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1271 (setq file-b (nth 1 command-line-args-left))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1272 (setq file-anc (nth 2 command-line-args-left))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1273 (setq file-out (nth 3 command-line-args-left))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1274 (setq command-line-args-left (nthcdr 4 command-line-args-left)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1275 (emerge-files-with-ancestor-internal
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1276 file-a file-b file-anc nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1277 (list (` (lambda () (emerge-command-exit (, file-out))))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1278
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1279 (defun emerge-command-exit (file-out)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1280 (emerge-write-and-delete file-out)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1281 (kill-emacs (if emerge-prefix-argument 1 0)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1282
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1283 ;;; Functions to start Emerge via remote request
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1284
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 583
diff changeset
1285 ;;;###autoload
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1286 (defun emerge-files-remote (file-a file-b file-out)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1287 (setq emerge-file-out file-out)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1288 (emerge-files-internal
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1289 file-a file-b nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1290 (list (` (lambda () (emerge-remote-exit (, file-out) '(, exit-func)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1291 file-out)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1292 (throw 'client-wait nil))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1293
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 583
diff changeset
1294 ;;;###autoload
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1295 (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
1296 (setq emerge-file-out file-out)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1297 (emerge-files-with-ancestor-internal
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1298 file-a file-b file-anc nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1299 (list (` (lambda () (emerge-remote-exit (, file-out) '(, exit-func)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1300 file-out)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1301 (throw 'client-wait nil))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1302
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1303 (defun emerge-remote-exit (file-out exit-func)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1304 (emerge-write-and-delete file-out)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1305 (kill-buffer emerge-merge-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1306 (funcall exit-func (if emerge-prefix-argument 1 0)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1307
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1308 ;;; Common setup routines
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1309
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1310 ;; Set up the window configuration. If POS is given, set the points to
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1311 ;; the beginnings of the buffers.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1312 (defun emerge-setup-windows (buffer-A buffer-B merge-buffer &optional pos)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1313 ;; 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
1314 ;; all other windows.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1315 (if (eq (selected-window) (minibuffer-window))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1316 (other-window 1))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1317 (delete-other-windows)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1318 (switch-to-buffer merge-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1319 (emerge-refresh-mode-line)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1320 (split-window-vertically)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1321 (split-window-horizontally)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1322 (switch-to-buffer buffer-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1323 (if pos
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1324 (goto-char (point-min)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1325 (other-window 1)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1326 (switch-to-buffer buffer-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1327 (if pos
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1328 (goto-char (point-min)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1329 (other-window 1)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1330 (if pos
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1331 (goto-char (point-min)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1332 ;; If diff/diff3 reports errors, display them rather than the merge buffer.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1333 (if (/= 0 (emerge-eval-in-buffer emerge-diff-error-buffer (buffer-size)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1334 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1335 (ding)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1336 (message "Errors found in diff/diff3 output. Merge buffer is %s."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1337 (buffer-name emerge-merge-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1338 (switch-to-buffer emerge-diff-error-buffer))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1339
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1340 ;; Set up the keymap in the merge buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1341 (defun emerge-set-keys ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1342 ;; Set up fixed keymaps if necessary
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1343 (if (not emerge-basic-keymap)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1344 (emerge-setup-fixed-keymaps))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1345 ;; Save the old local map
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1346 (setq emerge-old-keymap (current-local-map))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1347 ;; Construct the edit keymap
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1348 (setq emerge-edit-keymap (if emerge-old-keymap
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1349 (copy-keymap emerge-old-keymap)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1350 (make-sparse-keymap)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1351 ;; Install the Emerge commands
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1352 (emerge-force-define-key emerge-edit-keymap emerge-command-prefix
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1353 'emerge-basic-keymap)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1354 ;; Suppress write-file and save-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1355 (emerge-recursively-substitute-key-definition 'write-file
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1356 'emerge-query-write-file
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1357 emerge-edit-keymap)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1358 (emerge-recursively-substitute-key-definition 'save-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1359 'emerge-query-save-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1360 emerge-edit-keymap)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1361 (emerge-shadow-key-definition 'write-file 'emerge-query-write-file
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1362 (current-global-map) emerge-edit-keymap)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1363 (emerge-shadow-key-definition 'save-buffer 'emerge-query-save-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1364 (current-global-map) emerge-edit-keymap)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1365 (use-local-map emerge-fast-keymap)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1366 (setq emerge-edit-mode nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1367 (setq emerge-fast-mode t))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1368
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1369 (defun emerge-remember-buffer-characteristics ()
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1370 "Remembers certain properties of the buffers being merged.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1371 Must be called in the merge buffer. Remembers read-only, modified,
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1372 auto-save, and saves them in buffer local variables. Sets the buffers
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1373 read-only and turns off `auto-save-mode'.
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1374 These characteristics are restored by emerge-restore-buffer-characteristics."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1375 ;; 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
1376 ;; duration
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1377 (do-auto-save)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1378 ;; remember and alter buffer characteristics
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1379 (setq emerge-A-buffer-values
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1380 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1381 emerge-A-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1382 (prog1
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1383 (emerge-save-variables emerge-saved-variables)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1384 (emerge-restore-variables emerge-saved-variables
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1385 emerge-merging-values))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1386 (setq emerge-B-buffer-values
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1387 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1388 emerge-B-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1389 (prog1
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1390 (emerge-save-variables emerge-saved-variables)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1391 (emerge-restore-variables emerge-saved-variables
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1392 emerge-merging-values)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1393
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1394 (defun emerge-restore-buffer-characteristics ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1395 "Restores the characteristics remembered by
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1396 emerge-remember-buffer-characteristics."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1397 (let ((A-values emerge-A-buffer-values)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1398 (B-values emerge-B-buffer-values))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1399 (emerge-eval-in-buffer emerge-A-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1400 (emerge-restore-variables emerge-saved-variables
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1401 A-values))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1402 (emerge-eval-in-buffer emerge-B-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1403 (emerge-restore-variables emerge-saved-variables
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1404 B-values))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1405
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1406 (defun emerge-convert-diffs-to-markers (A-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1407 B-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1408 merge-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1409 lineno-list)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1410 (let* (marker-list
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1411 (A-point-min (emerge-eval-in-buffer A-buffer (point-min)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1412 (offset (1- A-point-min))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1413 (A-hidden-lines (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1414 A-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1415 (save-restriction
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1416 (widen)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1417 (count-lines 1 A-point-min))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1418 (B-point-min (emerge-eval-in-buffer B-buffer (point-min)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1419 (B-hidden-lines (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1420 B-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1421 (save-restriction
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1422 (widen)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1423 (count-lines 1 B-point-min)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1424 (while lineno-list
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1425 (let* ((list-element (car lineno-list))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1426 a-begin-marker
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1427 a-end-marker
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1428 b-begin-marker
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1429 b-end-marker
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1430 (a-begin (aref list-element 0))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1431 (a-end (aref list-element 1))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1432 (b-begin (aref list-element 2))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1433 (b-end (aref list-element 3))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1434 (state (aref list-element 4)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1435 ;; place markers at the appropriate places in the buffers
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1436 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1437 A-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1438 (goto-line (+ a-begin A-hidden-lines))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1439 (setq a-begin-marker (point-marker))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1440 (goto-line (+ a-end A-hidden-lines))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1441 (setq a-end-marker (point-marker)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1442 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1443 B-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1444 (goto-line (+ b-begin B-hidden-lines))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1445 (setq b-begin-marker (point-marker))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1446 (goto-line (+ b-end B-hidden-lines))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1447 (setq b-end-marker (point-marker)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1448 (setq merge-begin-marker (set-marker
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1449 (make-marker)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1450 (- (marker-position a-begin-marker)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1451 offset)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1452 merge-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1453 (setq merge-end-marker (set-marker
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1454 (make-marker)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1455 (- (marker-position a-end-marker)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1456 offset)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1457 merge-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1458 ;; record all the markers for this difference
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1459 (setq marker-list (cons (vector a-begin-marker a-end-marker
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1460 b-begin-marker b-end-marker
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1461 merge-begin-marker merge-end-marker
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1462 state)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1463 marker-list)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1464 (setq lineno-list (cdr lineno-list)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1465 ;; convert the list of difference information into a vector for
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1466 ;; fast access
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1467 (setq emerge-difference-list (apply 'vector (nreverse marker-list)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1468
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1469 ;; If we have an ancestor, select all B variants that we prefer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1470 (defun emerge-select-prefer-Bs ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1471 (let ((n 0))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1472 (while (< n emerge-number-of-differences)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1473 (if (eq (aref (aref emerge-difference-list n) 6) 'prefer-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1474 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1475 (emerge-unselect-and-select-difference n t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1476 (emerge-select-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1477 (aset (aref emerge-difference-list n) 6 'prefer-B)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1478 (setq n (1+ n))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1479 (emerge-unselect-and-select-difference -1))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1480
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1481 ;;; Common exit routines
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1482
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1483 (defun emerge-write-and-delete (file-out)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1484 ;; clear screen format
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1485 (delete-other-windows)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1486 ;; delete A, B, and ancestor buffers, if they haven't been changed
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1487 (if (not (buffer-modified-p emerge-A-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1488 (kill-buffer emerge-A-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1489 (if (not (buffer-modified-p emerge-B-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1490 (kill-buffer emerge-B-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1491 (if (and emerge-ancestor-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1492 (not (buffer-modified-p emerge-ancestor-buffer)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1493 (kill-buffer emerge-ancestor-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1494 ;; Write merge buffer to file
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1495 (write-file file-out))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1496
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1497 ;;; Commands
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1498
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1499 (defun emerge-recenter (&optional arg)
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1500 "Bring the highlighted region of all three merge buffers into view.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1501 This brings the buffers into view if they are in windows.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1502 If an ARGUMENT is given, the default three-window display is reestablished."
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1503 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1504 ;; If there is an argument, rebuild the window structure
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1505 (if arg
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1506 (emerge-setup-windows emerge-A-buffer emerge-B-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1507 emerge-merge-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1508 ;; Redisplay whatever buffers are showing, if there is a selected difference
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1509 (if (and (>= emerge-current-difference 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1510 (< emerge-current-difference emerge-number-of-differences))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1511 (let* ((merge-buffer emerge-merge-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1512 (buffer-A emerge-A-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1513 (buffer-B emerge-B-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1514 (window-A (get-buffer-window buffer-A))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1515 (window-B (get-buffer-window buffer-B))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1516 (merge-window (get-buffer-window merge-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1517 (diff-vector
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1518 (aref emerge-difference-list emerge-current-difference)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1519 (if window-A (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1520 (select-window window-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1521 (emerge-position-region
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1522 (- (aref diff-vector 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1523 (1- emerge-before-flag-length))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1524 (+ (aref diff-vector 1)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1525 (1- emerge-after-flag-length))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1526 (1+ (aref diff-vector 0)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1527 (if window-B (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1528 (select-window window-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1529 (emerge-position-region
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1530 (- (aref diff-vector 2)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1531 (1- emerge-before-flag-length))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1532 (+ (aref diff-vector 3)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1533 (1- emerge-after-flag-length))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1534 (1+ (aref diff-vector 2)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1535 (if merge-window (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1536 (select-window merge-window)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1537 (emerge-position-region
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1538 (- (aref diff-vector 4)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1539 (1- emerge-before-flag-length))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1540 (+ (aref diff-vector 5)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1541 (1- emerge-after-flag-length))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1542 (1+ (aref diff-vector 4))))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1543
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1544 ;;; Window scrolling operations
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1545 ;; These operations are designed to scroll all three windows the same amount,
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1546 ;; so as to keep the text in them aligned.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1547
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1548 ;; Perform some operation on all three windows (if they are showing).
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1549 ;; 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
1550 ;; in the merge window. Usually, errors come from scrolling off the
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1551 ;; beginning or end of the buffer, and this gives a nice error message:
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1552 ;; 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
1553 ;; 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
1554 ;; is reported.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1555 (defun emerge-operate-on-windows (operation arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1556 (let* ((merge-buffer emerge-merge-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1557 (buffer-A emerge-A-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1558 (buffer-B emerge-B-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1559 (window-A (get-buffer-window buffer-A))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1560 (window-B (get-buffer-window buffer-B))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1561 (merge-window (get-buffer-window merge-buffer)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1562 (if window-A (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1563 (select-window window-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1564 (condition-case nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1565 (funcall operation arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1566 (error))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1567 (if window-B (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1568 (select-window window-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1569 (condition-case nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1570 (funcall operation arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1571 (error))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1572 (if merge-window (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1573 (select-window merge-window)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1574 (funcall operation arg)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1575
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1576 (defun emerge-scroll-up (&optional arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1577 "Scroll up all three merge buffers, if they are in windows.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1578 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
1579 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
1580 size of the merge window."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1581 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1582 (emerge-operate-on-windows
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1583 'scroll-up
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1584 ;; calculate argument to scroll-up
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1585 ;; if there is an explicit argument
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1586 (if (and arg (not (equal arg '-)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1587 ;; use it
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1588 (prefix-numeric-value arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1589 ;; if not, see if we can determine a default amount (the window height)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1590 (let ((merge-window (get-buffer-window emerge-merge-buffer)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1591 (if (null merge-window)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1592 ;; no window, use nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1593 nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1594 (let ((default-amount
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1595 (- (window-height merge-window) 1 next-screen-context-lines)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1596 ;; the window was found
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1597 (if arg
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1598 ;; C-u as argument means half of default amount
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1599 (/ default-amount 2)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1600 ;; no argument means default amount
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1601 default-amount)))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1602
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1603 (defun emerge-scroll-down (&optional arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1604 "Scroll down all three merge buffers, if they are in windows.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1605 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
1606 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
1607 size of the merge window."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1608 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1609 (emerge-operate-on-windows
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1610 'scroll-down
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1611 ;; calculate argument to scroll-down
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1612 ;; if there is an explicit argument
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1613 (if (and arg (not (equal arg '-)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1614 ;; use it
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1615 (prefix-numeric-value arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1616 ;; if not, see if we can determine a default amount (the window height)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1617 (let ((merge-window (get-buffer-window emerge-merge-buffer)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1618 (if (null merge-window)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1619 ;; no window, use nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1620 nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1621 (let ((default-amount
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1622 (- (window-height merge-window) 1 next-screen-context-lines)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1623 ;; the window was found
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1624 (if arg
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1625 ;; C-u as argument means half of default amount
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1626 (/ default-amount 2)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1627 ;; no argument means default amount
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1628 default-amount)))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1629
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1630 (defun emerge-scroll-left (&optional arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1631 "Scroll left all three merge buffers, if they are in windows.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1632 If an ARGUMENT is given, that is how many columns are scrolled, else nearly
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1633 the width of the A and B windows. C-u - alone as argument scrolls half the
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1634 width of the A and B windows."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1635 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1636 (emerge-operate-on-windows
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1637 'scroll-left
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1638 ;; calculate argument to scroll-left
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1639 ;; if there is an explicit argument
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1640 (if (and arg (not (equal arg '-)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1641 ;; use it
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1642 (prefix-numeric-value arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1643 ;; if not, see if we can determine a default amount
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1644 ;; (half the window width)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1645 (let ((merge-window (get-buffer-window emerge-merge-buffer)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1646 (if (null merge-window)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1647 ;; no window, use nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1648 nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1649 (let ((default-amount
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1650 (- (/ (window-width merge-window) 2) 3)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1651 ;; the window was found
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1652 (if arg
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1653 ;; C-u as argument means half of default amount
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1654 (/ default-amount 2)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1655 ;; no argument means default amount
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1656 default-amount)))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1657
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1658 (defun emerge-scroll-right (&optional arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1659 "Scroll right all three merge buffers, if they are in windows.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1660 If an ARGUMENT is given, that is how many columns are scrolled, else nearly
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1661 the width of the A and B windows. C-u - alone as argument scrolls half the
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1662 width of the A and B windows."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1663 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1664 (emerge-operate-on-windows
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1665 'scroll-right
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1666 ;; calculate argument to scroll-right
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1667 ;; if there is an explicit argument
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1668 (if (and arg (not (equal arg '-)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1669 ;; use it
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1670 (prefix-numeric-value arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1671 ;; if not, see if we can determine a default amount
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1672 ;; (half the window width)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1673 (let ((merge-window (get-buffer-window emerge-merge-buffer)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1674 (if (null merge-window)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1675 ;; no window, use nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1676 nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1677 (let ((default-amount
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1678 (- (/ (window-width merge-window) 2) 3)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1679 ;; the window was found
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1680 (if arg
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1681 ;; C-u as argument means half of default amount
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1682 (/ default-amount 2)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1683 ;; no argument means default amount
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1684 default-amount)))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1685
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1686 (defun emerge-scroll-reset ()
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1687 "Reset horizontal scrolling.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1688 This resets the horizontal scrolling of all three merge buffers
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1689 to the left margin, if they are in windows."
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1690 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1691 (emerge-operate-on-windows
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1692 (function (lambda (x) (set-window-hscroll (selected-window) 0)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1693 nil))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1694
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1695 ;; Attempt to show the region nicely.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1696 ;; 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
1697 ;; anything.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1698 ;; If not, recenter the region to make it so.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1699 ;; If that isn't possible, remove context lines balancedly from top and botton
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1700 ;; so the entire region shows.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1701 ;; If that isn't possible, show the top of the region.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1702 ;; BEG must be at the beginning of a line.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1703 (defun emerge-position-region (beg end pos)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1704 ;; First test whether the entire region is visible with
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1705 ;; emerge-min-visible-lines above and below it
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1706 (if (not (and (<= (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1707 (move-to-window-line emerge-min-visible-lines)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1708 (point))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1709 beg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1710 (<= end (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1711 (move-to-window-line
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1712 (- (1+ emerge-min-visible-lines)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1713 (point)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1714 ;; We failed that test, see if it fits at all
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1715 ;; Meanwhile positioning it correctly in case it doesn't fit
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1716 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1717 (set-window-start (selected-window) beg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1718 (setq fits (pos-visible-in-window-p end))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1719 (if fits
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1720 ;; Determine the number of lines that the region occupies
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1721 (let ((lines 0))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1722 (while (> end (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1723 (move-to-window-line lines)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1724 (point)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1725 (setq lines (1+ lines)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1726 ;; And position the beginning on the right line
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1727 (goto-char beg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1728 (recenter (/ (1+ (- (1- (window-height (selected-window)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1729 lines))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1730 2))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1731 (goto-char pos))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1732
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1733 (defun emerge-next-difference ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1734 "Advance to the next difference."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1735 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1736 (if (< emerge-current-difference emerge-number-of-differences)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1737 (let ((n (1+ emerge-current-difference)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1738 (while (and emerge-skip-prefers
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1739 (< n emerge-number-of-differences)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1740 (memq (aref (aref emerge-difference-list n) 6)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1741 '(prefer-A prefer-B)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1742 (setq n (1+ n)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1743 (let ((buffer-read-only nil))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1744 (emerge-unselect-and-select-difference n)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1745 (error "At end")))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1746
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1747 (defun emerge-previous-difference ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1748 "Go to the previous difference."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1749 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1750 (if (> emerge-current-difference -1)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1751 (let ((n (1- emerge-current-difference)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1752 (while (and emerge-skip-prefers
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1753 (> n -1)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1754 (memq (aref (aref emerge-difference-list n) 6)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1755 '(prefer-A prefer-B)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1756 (setq n (1- n)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1757 (let ((buffer-read-only nil))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1758 (emerge-unselect-and-select-difference n)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1759 (error "At beginning")))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1760
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1761 (defun emerge-jump-to-difference (difference-number)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1762 "Go to the N-th difference."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1763 (interactive "p")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1764 (let ((buffer-read-only nil))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1765 (setq difference-number (1- difference-number))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1766 (if (and (>= difference-number -1)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1767 (< difference-number (1+ emerge-number-of-differences)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1768 (emerge-unselect-and-select-difference difference-number)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1769 (error "Bad difference number"))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1770
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1771 (defun emerge-quit (arg)
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1772 "Finish an Emerge session.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1773 Prefix argument means to abort rather than successfully finish.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1774 The difference depends on how the merge was started,
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1775 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
1776 to some process which invoked Emerge a failure code.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1777
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1778 Unselects the selected difference, if any, restores the read-only and modified
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1779 flags of the merged file buffers, restores the local keymap of the merge
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1780 buffer, and sets off various emerge flags. Using Emerge commands in this
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1781 buffer after this will cause serious problems."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1782 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1783 (if (prog1
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1784 (y-or-n-p
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1785 (if (not arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1786 "Do you really want to successfully finish this merge? "
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1787 "Do you really want to abort this merge? "))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1788 (message ""))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1789 (emerge-really-quit arg)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1790
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1791 ;; Perform the quit operations.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1792 (defun emerge-really-quit (arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1793 (setq buffer-read-only nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1794 (emerge-unselect-and-select-difference -1)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1795 (emerge-restore-buffer-characteristics)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1796 ;; null out the difference markers so they don't slow down future editing
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1797 ;; operations
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1798 (mapcar (function (lambda (d)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1799 (set-marker (aref d 0) nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1800 (set-marker (aref d 1) nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1801 (set-marker (aref d 2) nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1802 (set-marker (aref d 3) nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1803 (set-marker (aref d 4) nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1804 (set-marker (aref d 5) nil)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1805 emerge-difference-list)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1806 ;; allow them to be garbage collected
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1807 (setq emerge-difference-list nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1808 ;; restore the local map
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1809 (use-local-map emerge-old-keymap)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1810 ;; turn off all the emerge modes
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1811 (setq emerge-mode nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1812 (setq emerge-fast-mode nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1813 (setq emerge-edit-mode nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1814 (setq emerge-auto-advance nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1815 (setq emerge-skip-prefers nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1816 ;; restore mode line
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1817 (kill-local-variable 'mode-line-buffer-identification)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1818 (let ((emerge-prefix-argument arg))
854
0b4f3a91f207 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 778
diff changeset
1819 (run-hooks 'emerge-quit-hook)))
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1820
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1821 (defun emerge-select-A (&optional force)
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1822 "Select the A variant of this difference.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1823 Refuses to function if this difference has been edited, i.e., if it
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1824 is neither the A nor the B variant.
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1825 An ARGUMENT forces the variant to be selected even if the difference has
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1826 been edited."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1827 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1828 (let ((operate
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 (emerge-select-A-edit merge-begin merge-end A-begin A-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1831 (if emerge-auto-advance
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1832 (emerge-next-difference)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1833 (operate-no-change
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1834 (function (lambda ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1835 (if emerge-auto-advance
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1836 (emerge-next-difference))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1837 (emerge-select-version force operate-no-change operate operate)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1838
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1839 ;; Actually select the A variant
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1840 (defun emerge-select-A-edit (merge-begin merge-end A-begin A-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1841 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1842 emerge-merge-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1843 (delete-region merge-begin merge-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1844 (goto-char merge-begin)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1845 (insert-buffer-substring emerge-A-buffer A-begin A-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1846 (goto-char merge-begin)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1847 (aset diff-vector 6 'A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1848 (emerge-refresh-mode-line)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1849
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1850 (defun emerge-select-B (&optional force)
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1851 "Select the B variant of this difference.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1852 Refuses to function if this difference has been edited, i.e., if it
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1853 is neither the A nor the B variant. An ARGUMENT forces the variant to be selected even if the difference has
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1854 been edited."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1855 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1856 (let ((operate
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 (emerge-select-B-edit merge-begin merge-end B-begin B-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1859 (if emerge-auto-advance
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1860 (emerge-next-difference)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1861 (operate-no-change
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1862 (function (lambda ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1863 (if emerge-auto-advance
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1864 (emerge-next-difference))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1865 (emerge-select-version force operate operate-no-change operate)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1866
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1867 ;; Actually select the B variant
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1868 (defun emerge-select-B-edit (merge-begin merge-end B-begin B-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1869 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1870 emerge-merge-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1871 (delete-region merge-begin merge-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1872 (goto-char merge-begin)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1873 (insert-buffer-substring emerge-B-buffer B-begin B-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1874 (goto-char merge-begin)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1875 (aset diff-vector 6 'B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1876 (emerge-refresh-mode-line)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1877
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1878 (defun emerge-default-A ()
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1879 "Selects the A variant.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1880 This selects the A variant for all differences from here down in the buffer
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1881 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
1882 which there is no preference."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1883 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1884 (let ((buffer-read-only nil))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1885 (let ((selected-difference emerge-current-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1886 (n (max emerge-current-difference 0)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1887 (while (< n emerge-number-of-differences)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1888 (let ((diff-vector (aref emerge-difference-list n)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1889 (if (eq (aref diff-vector 6) 'default-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1890 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1891 (emerge-unselect-and-select-difference n t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1892 (emerge-select-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1893 (aset diff-vector 6 'default-A))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1894 (setq n (1+ n))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1895 (if (= (* (/ n 10) 10) n)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1896 (message "Setting default to A...%d" n)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1897 (emerge-unselect-and-select-difference selected-difference)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1898 (message "Default A set"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1899
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1900 (defun emerge-default-B ()
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1901 "Selects the B variant.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1902 This selects the B variant for all differences from here down in the buffer
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1903 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
1904 which there is no preference."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1905 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1906 (let ((buffer-read-only nil))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1907 (let ((selected-difference emerge-current-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1908 (n (max emerge-current-difference 0)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1909 (while (< n emerge-number-of-differences)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1910 (let ((diff-vector (aref emerge-difference-list n)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1911 (if (eq (aref diff-vector 6) 'default-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1912 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1913 (emerge-unselect-and-select-difference n t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1914 (emerge-select-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1915 (aset diff-vector 6 'default-B))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1916 (setq n (1+ n))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1917 (if (= (* (/ n 10) 10) n)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1918 (message "Setting default to B...%d" n)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1919 (emerge-unselect-and-select-difference selected-difference)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1920 (message "Default B set"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1921
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1922 (defun emerge-fast-mode ()
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1923 "Set fast mode.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1924 In this mode ordinary Emacs commands are disabled, and Emerge commands
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1925 are need not be prefixed with \\<emerge-fast-keymap>\\[emerge-basic-keymap]."
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1926 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1927 (setq buffer-read-only t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1928 (use-local-map emerge-fast-keymap)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1929 (setq emerge-mode t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1930 (setq emerge-fast-mode t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1931 (setq emerge-edit-mode nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1932 (message "Fast mode set")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1933 ;; force mode line redisplay
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1934 (set-buffer-modified-p (buffer-modified-p)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1935
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1936 (defun emerge-edit-mode ()
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1937 "Set edit mode.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1938 In this mode ordinary Emacs commands are available, and Emerge commands
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1939 must be prefixed with \\<emerge-fast-keymap>\\[emerge-basic-keymap]."
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1940 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1941 (setq buffer-read-only nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1942 (use-local-map emerge-edit-keymap)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1943 (setq emerge-mode t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1944 (setq emerge-fast-mode nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1945 (setq emerge-edit-mode t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1946 (message "Edit mode set")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1947 ;; force mode line redisplay
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1948 (set-buffer-modified-p (buffer-modified-p)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1949
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1950 (defun emerge-auto-advance (arg)
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1951 "Toggle auto-advance mode.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1952 This mode causes `emerge-select-A' and `emerge-select-B' to automatically
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1953 advance to the next difference. (See `emerge-auto-advance'.)
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1954 If a positive ARGUMENT is given, it turns on `auto-advance-mode'.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1955 If a negative ARGUMENT is given, it turns off `auto-advance-mode'."
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1956 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1957 (setq emerge-auto-advance (if (null arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1958 (not emerge-auto-advance)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1959 (> (prefix-numeric-value arg) 0)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1960 (message (if emerge-skip-prefers
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1961 "Auto-advance set"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1962 "Auto-advance cleared"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1963 ;; force mode line redisplay
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1964 (set-buffer-modified-p (buffer-modified-p)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1965
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1966 (defun emerge-skip-prefers (arg)
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1967 "Toggle skip-prefers mode.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1968 This mode causes `emerge-next-difference' and `emerge-previous-difference'
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1969 to automatically skip over differences for which there is a preference.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1970 (See `emerge-skip-prefers'.) If a positive ARG is given, it turns on
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1971 `skip-prefers' mode.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
1972 If a negative ARG is given, it turns off `skip-prefers' mode."
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1973 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1974 (setq emerge-skip-prefers (if (null arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1975 (not emerge-skip-prefers)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1976 (> (prefix-numeric-value arg) 0)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1977 (message (if emerge-skip-prefers
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1978 "Skip-prefers set"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1979 "Skip-prefers cleared"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1980 ;; force mode line redisplay
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1981 (set-buffer-modified-p (buffer-modified-p)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1982
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1983 (defun emerge-copy-as-kill-A ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1984 "Put the A variant of this difference in the kill ring."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1985 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1986 (emerge-validate-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1987 (let* ((diff-vector
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1988 (aref emerge-difference-list emerge-current-difference))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1989 (A-begin (1+ (aref diff-vector 0)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1990 (A-end (1- (aref diff-vector 1)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1991 ;; so further kills don't append
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1992 this-command)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1993 (save-excursion
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1994 (set-buffer emerge-A-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1995 (copy-region-as-kill A-begin A-end))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1996
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1997 (defun emerge-copy-as-kill-B ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1998 "Put the B variant of this difference in the kill ring."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1999 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2000 (emerge-validate-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2001 (let* ((diff-vector
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2002 (aref emerge-difference-list emerge-current-difference))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2003 (B-begin (1+ (aref diff-vector 2)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2004 (B-end (1- (aref diff-vector 3)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2005 ;; so further kills don't append
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2006 this-command)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2007 (save-excursion
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2008 (set-buffer emerge-B-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2009 (copy-region-as-kill B-begin B-end))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2010
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2011 (defun emerge-insert-A (arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2012 "Insert the A variant of this difference at the point.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2013 Leaves point after text, mark before.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2014 With prefix argument, puts point before, mark after."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2015 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2016 (emerge-validate-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2017 (let* ((diff-vector
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2018 (aref emerge-difference-list emerge-current-difference))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2019 (A-begin (1+ (aref diff-vector 0)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2020 (A-end (1- (aref diff-vector 1)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2021 (opoint (point))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2022 (buffer-read-only nil))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2023 (insert-buffer-substring emerge-A-buffer A-begin A-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2024 (if (not arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2025 (set-mark opoint)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2026 (set-mark (point))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2027 (goto-char opoint))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2028
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2029 (defun emerge-insert-B (arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2030 "Insert the B variant of this difference at the point.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2031 Leaves point after text, mark before.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2032 With prefix argument, puts point before, mark after."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2033 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2034 (emerge-validate-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2035 (let* ((diff-vector
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2036 (aref emerge-difference-list emerge-current-difference))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2037 (B-begin (1+ (aref diff-vector 2)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2038 (B-end (1- (aref diff-vector 3)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2039 (opoint (point))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2040 (buffer-read-only nil))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2041 (insert-buffer-substring emerge-B-buffer B-begin B-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2042 (if (not arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2043 (set-mark opoint)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2044 (set-mark (point))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2045 (goto-char opoint))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2046
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2047 (defun emerge-mark-difference (arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2048 "Leaves the point before this difference and the mark after it.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2049 With prefix argument, puts mark before, point after."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2050 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2051 (emerge-validate-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2052 (let* ((diff-vector
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2053 (aref emerge-difference-list emerge-current-difference))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2054 (merge-begin (1+ (aref diff-vector 4)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2055 (merge-end (1- (aref diff-vector 5))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2056 (if (not arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2057 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2058 (goto-char merge-begin)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2059 (set-mark merge-end))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2060 (goto-char merge-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2061 (set-mark merge-begin))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2062
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2063 (defun emerge-file-names ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2064 "Show the names of the buffers or files being operated on by Emerge.
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2065 Use C-u l to reset the windows afterward."
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2066 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2067 (delete-other-windows)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2068 (let ((temp-buffer-show-hook
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2069 (function (lambda (buf)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2070 (split-window-vertically)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2071 (switch-to-buffer buf)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2072 (other-window 1)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2073 (with-output-to-temp-buffer "*Help*"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2074 (emerge-eval-in-buffer emerge-A-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2075 (if buffer-file-name
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2076 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2077 (princ "File A is: ")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2078 (princ buffer-file-name))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2079 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2080 (princ "Buffer A is: ")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2081 (princ (buffer-name))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2082 (princ "\n"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2083 (emerge-eval-in-buffer emerge-B-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 "File B 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 "Buffer B 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 (if emerge-ancestor-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2093 (emerge-eval-in-buffer emerge-ancestor-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2094 (if buffer-file-name
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2095 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2096 (princ "Ancestor file is: ")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2097 (princ buffer-file-name))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2098 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2099 (princ "Ancestor buffer is: ")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2100 (princ (buffer-name))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2101 (princ "\n")))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2102 (princ emerge-output-description))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2103
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2104 (defun emerge-join-differences (arg)
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2105 "Join the selected difference with the following one.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2106 With a prefix argument, join with the preceeding one."
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2107 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2108 (let ((n emerge-current-difference))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2109 ;; adjust n to be first difference to join
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2110 (if arg
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2111 (setq n (1- n)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2112 ;; n and n+1 are the differences to join
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2113 ;; check that they are both differences
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2114 (if (or (< n 0) (>= n (1- emerge-number-of-differences)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2115 (error "Incorrect differences to join"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2116 ;; remove the flags
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2117 (emerge-unselect-difference emerge-current-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2118 ;; decrement total number of differences
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2119 (setq emerge-number-of-differences (1- emerge-number-of-differences))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2120 ;; build new differences vector
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2121 (let ((i 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2122 (new-differences (make-vector emerge-number-of-differences nil)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2123 (while (< i emerge-number-of-differences)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2124 (aset new-differences i
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2125 (cond
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2126 ((< i n) (aref emerge-difference-list i))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2127 ((> i n) (aref emerge-difference-list (1+ i)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2128 (t (let ((prev (aref emerge-difference-list i))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2129 (next (aref emerge-difference-list (1+ i))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2130 (vector (aref prev 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2131 (aref next 1)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2132 (aref prev 2)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2133 (aref next 3)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2134 (aref prev 4)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2135 (aref next 5)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2136 (let ((ps (aref prev 6))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2137 (ns (aref next 6)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2138 (cond
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2139 ((eq ps ns)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2140 ps)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2141 ((and (or (eq ps 'B) (eq ps 'prefer-B))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2142 (or (eq ns 'B) (eq ns 'prefer-B)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2143 'B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2144 (t 'A))))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2145 (setq i (1+ i)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2146 (setq emerge-difference-list new-differences))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2147 ;; set the current difference correctly
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2148 (setq emerge-current-difference n)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2149 ;; fix the mode line
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2150 (emerge-refresh-mode-line)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2151 ;; reinsert the flags
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2152 (emerge-select-difference emerge-current-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2153 (emerge-recenter)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2154
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2155 (defun emerge-split-difference ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2156 "Split the current difference where the points are in the three windows."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2157 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2158 (let ((n emerge-current-difference))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2159 ;; check that this is a valid difference
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2160 (emerge-validate-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2161 ;; get the point values and old difference
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2162 (let ((A-point (emerge-eval-in-buffer emerge-A-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2163 (point-marker)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2164 (B-point (emerge-eval-in-buffer emerge-B-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2165 (point-marker)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2166 (merge-point (point-marker))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2167 (old-diff (aref emerge-difference-list n)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2168 ;; check location of the points, give error if they aren't in the
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2169 ;; differences
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2170 (if (or (< A-point (aref old-diff 0))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2171 (> A-point (aref old-diff 1)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2172 (error "Point outside of difference in A buffer"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2173 (if (or (< B-point (aref old-diff 2))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2174 (> B-point (aref old-diff 3)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2175 (error "Point outside of difference in B buffer"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2176 (if (or (< merge-point (aref old-diff 4))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2177 (> merge-point (aref old-diff 5)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2178 (error "Point outside of difference in merge buffer"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2179 ;; remove the flags
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2180 (emerge-unselect-difference emerge-current-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2181 ;; increment total number of differences
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2182 (setq emerge-number-of-differences (1+ emerge-number-of-differences))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2183 ;; build new differences vector
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2184 (let ((i 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2185 (new-differences (make-vector emerge-number-of-differences nil)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2186 (while (< i emerge-number-of-differences)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2187 (aset new-differences i
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2188 (cond
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2189 ((< i n)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2190 (aref emerge-difference-list i))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2191 ((> i (1+ n))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2192 (aref emerge-difference-list (1- i)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2193 ((= i n)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2194 (vector (aref old-diff 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2195 A-point
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2196 (aref old-diff 2)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2197 B-point
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2198 (aref old-diff 4)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2199 merge-point
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2200 (aref old-diff 6)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2201 (t
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2202 (vector (copy-marker A-point)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2203 (aref old-diff 1)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2204 (copy-marker B-point)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2205 (aref old-diff 3)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2206 (copy-marker merge-point)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2207 (aref old-diff 5)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2208 (aref old-diff 6)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2209 (setq i (1+ i)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2210 (setq emerge-difference-list new-differences))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2211 ;; set the current difference correctly
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2212 (setq emerge-current-difference n)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2213 ;; fix the mode line
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2214 (emerge-refresh-mode-line)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2215 ;; reinsert the flags
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2216 (emerge-select-difference emerge-current-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2217 (emerge-recenter))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2218
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2219 (defun emerge-trim-difference ()
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2220 "Trim lines off top and bottom of difference that are the same.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2221 If lines are the same in both the A and the B versions, strip them off.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2222 (This can happen when the A and B versions have common lines that the
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2223 ancestor version does not share.)"
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2224 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2225 ;; make sure we are in a real difference
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2226 (emerge-validate-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2227 ;; remove the flags
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2228 (emerge-unselect-difference emerge-current-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2229 (let* ((diff (aref emerge-difference-list emerge-current-difference))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2230 (top-a (marker-position (aref diff 0)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2231 (bottom-a (marker-position (aref diff 1)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2232 (top-b (marker-position (aref diff 2)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2233 (bottom-b (marker-position (aref diff 3)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2234 (top-m (marker-position (aref diff 4)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2235 (bottom-m (marker-position (aref diff 5)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2236 size success sa sb sm)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2237 ;; move down the tops of the difference regions as much as possible
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2238 ;; Try advancing comparing 1000 chars at a time.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2239 ;; When that fails, go 500 chars at a time, and so on.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2240 (setq size 1000)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2241 (while (> size 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2242 (setq success t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2243 (while success
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2244 (setq size (min size (- bottom-a top-a) (- bottom-b top-b)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2245 (- bottom-m top-m)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2246 (setq sa (emerge-eval-in-buffer emerge-A-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2247 (buffer-substring top-a
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2248 (+ size top-a))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2249 (setq sb (emerge-eval-in-buffer emerge-B-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2250 (buffer-substring top-b
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2251 (+ size top-b))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2252 (setq sm (buffer-substring top-m (+ size top-m)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2253 (setq success (and (> size 0) (equal sa sb) (equal sb sm)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2254 (if success
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2255 (setq top-a (+ top-a size)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2256 top-b (+ top-b size)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2257 top-m (+ top-m size))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2258 (setq size (/ size 2)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2259 ;; move up the bottoms of the difference regions as much as possible
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2260 ;; Try advancing comparing 1000 chars at a time.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2261 ;; When that fails, go 500 chars at a time, and so on.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2262 (setq size 1000)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2263 (while (> size 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2264 (setq success t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2265 (while success
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2266 (setq size (min size (- bottom-a top-a) (- bottom-b top-b)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2267 (- bottom-m top-m)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2268 (setq sa (emerge-eval-in-buffer emerge-A-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2269 (buffer-substring (- bottom-a size)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2270 bottom-a)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2271 (setq sb (emerge-eval-in-buffer emerge-B-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2272 (buffer-substring (- bottom-b size)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2273 bottom-b)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2274 (setq sm (buffer-substring (- bottom-m size) bottom-m))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2275 (setq success (and (> size 0) (equal sa sb) (equal sb sm)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2276 (if success
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2277 (setq bottom-a (- bottom-a size)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2278 bottom-b (- bottom-b size)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2279 bottom-m (- bottom-m size))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2280 (setq size (/ size 2)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2281 ;; {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
2282 ;; of the difference regions. Move them to the beginning of lines, as
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2283 ;; appropriate.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2284 (emerge-eval-in-buffer emerge-A-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2285 (goto-char top-a)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2286 (beginning-of-line)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2287 (aset diff 0 (point-marker))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2288 (goto-char bottom-a)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2289 (beginning-of-line 2)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2290 (aset diff 1 (point-marker)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2291 (emerge-eval-in-buffer emerge-B-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2292 (goto-char top-b)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2293 (beginning-of-line)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2294 (aset diff 2 (point-marker))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2295 (goto-char bottom-b)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2296 (beginning-of-line 2)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2297 (aset diff 3 (point-marker)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2298 (goto-char top-m)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2299 (beginning-of-line)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2300 (aset diff 4 (point-marker))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2301 (goto-char bottom-m)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2302 (beginning-of-line 2)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2303 (aset diff 5 (point-marker))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2304 ;; put the flags back in, recenter the display
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2305 (emerge-select-difference emerge-current-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2306 (emerge-recenter)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2307
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2308 (defun emerge-find-difference (arg)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2309 "Find the difference containing the current position of the point.
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 merge 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 merge buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2316 (emerge-find-difference1 arg (point) 4 5))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2317
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2318 (defun emerge-find-difference-A (arg)
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2319 "Find the difference containing the position of the point in the A buffer.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2320 This command must be executed in the merge buffer.
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2321 If there is no containing difference and the prefix argument is positive,
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2322 it finds the nearest following difference. A negative prefix argument finds
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2323 the nearest previous difference."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2324 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2325 ;; search for the point in the A buffer, using the markers
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2326 ;; for the beginning and end of the differences in the A buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2327 (emerge-find-difference1 arg
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2328 (emerge-eval-in-buffer emerge-A-buffer (point))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2329 0 1))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2330
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2331 (defun emerge-find-difference-B (arg)
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2332 "Find the difference containing the position of the point in the B buffer.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2333 This command must be executed in the merge buffer.
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2334 If there is no containing difference and the prefix argument is positive,
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2335 it finds the nearest following difference. A negative prefix argument finds
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2336 the nearest previous difference."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2337 (interactive "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2338 ;; search for the point in the B buffer, using the markers
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2339 ;; for the beginning and end of the differences in the B buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2340 (emerge-find-difference1 arg
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2341 (emerge-eval-in-buffer emerge-B-buffer (point))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2342 2 3))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2343
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2344 (defun emerge-find-difference1 (arg location begin end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2345 (let* ((index
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2346 ;; find first difference containing or after the current position
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2347 (catch 'search
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2348 (let ((n 0))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2349 (while (< n emerge-number-of-differences)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2350 (let ((diff-vector (aref emerge-difference-list n)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2351 (if (<= location (marker-position (aref diff-vector end)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2352 (throw 'search n)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2353 (setq n (1+ n))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2354 emerge-number-of-differences))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2355 (contains
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2356 ;; whether the found difference contains the current position
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2357 (and (< index emerge-number-of-differences)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2358 (<= (marker-position (aref (aref emerge-difference-list index)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2359 begin))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2360 location)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2361 (arg-value
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2362 ;; numeric value of prefix argument
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2363 (prefix-numeric-value arg)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2364 (emerge-unselect-and-select-difference
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2365 (cond
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2366 ;; if the point is in a difference, select it
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2367 (contains index)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2368 ;; 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
2369 ((null arg) (error "No difference contains point"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2370 ;; if the arg is positive, select the following difference
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2371 ((> arg-value 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2372 (if (< index emerge-number-of-differences)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2373 index
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2374 (error "No difference contains or follows point")))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2375 ;; if the arg is negative, select the preceeding difference
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2376 (t
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2377 (if (> index 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2378 (1- index)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2379 (error "No difference contains or preceeds point")))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2380
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2381 (defun emerge-line-numbers ()
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2382 "Display the current line numbers.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2383 This function displays the line numbers of the points in the A, B, and
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2384 merge buffers."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2385 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2386 (let* ((valid-diff
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2387 (and (>= emerge-current-difference 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2388 (< emerge-current-difference emerge-number-of-differences)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2389 (diff (and valid-diff
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2390 (aref emerge-difference-list emerge-current-difference)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2391 (merge-line (emerge-line-number-in-buf 4 5))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2392 (A-line (emerge-eval-in-buffer emerge-A-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2393 (emerge-line-number-in-buf 0 1)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2394 (B-line (emerge-eval-in-buffer emerge-B-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2395 (emerge-line-number-in-buf 2 3))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2396 (message "At lines: merge = %d, A = %d, B = %d"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2397 merge-line A-line B-line)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2398
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2399 (defun emerge-line-number-in-buf (begin-marker end-marker)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2400 (let (temp)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2401 (setq temp (save-excursion
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2402 (beginning-of-line)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2403 (1+ (count-lines 1 (point)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2404 (if valid-diff
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2405 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2406 (if (> (point) (aref diff begin-marker))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2407 (setq temp (- temp emerge-before-flag-lines)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2408 (if (> (point) (aref diff end-marker))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2409 (setq temp (- temp emerge-after-flag-lines)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2410 temp))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2411
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2412 (defun emerge-set-combine-versions-template (start end &optional localize)
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2413 "Copy region into `emerge-combine-versions-template'.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2414 This controls how `emerge-combine-versions' will combine the two versions.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2415 With prefix argument, `emerge-combine-versions' is made local to this
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2416 merge buffer. Localization is permanent for any particular merge buffer."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2417 (interactive "r\nP")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2418 (if localize
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2419 (make-local-variable 'emerge-combine-versions-template))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2420 (setq emerge-combine-versions-template (buffer-substring start end))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2421 (message
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2422 (if (assq 'emerge-combine-versions-template (buffer-local-variables))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2423 "emerge-set-combine-versions-template set locally."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2424 "emerge-set-combine-versions-template set.")))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2425
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2426 (defun emerge-combine-versions (&optional force)
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2427 "Combine versions using the template in `emerge-combine-versions-template'.
583
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.
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2430 An argument forces the variant to be selected even if the difference has
583
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 "P")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2433 (emerge-combine-versions-internal emerge-combine-versions-template force))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2434
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2435 (defun emerge-combine-versions-register (char &optional force)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2436 "Combine the two versions using the template in register REG.
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2437 See documentation of the variable `emerge-combine-versions-template'
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2438 for how the template is interpreted.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2439 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
2440 neither the A nor the B variant.
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2441 An argument forces the variant to be selected even if the difference has
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2442 been edited."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2443 (interactive "cRegister containing template: \nP")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2444 (let ((template (get-register char)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2445 (if (not (stringp template))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2446 (error "Register does not contain text"))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2447 (emerge-combine-versions-internal template force)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2448
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2449 (defun emerge-combine-versions-internal (template force)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2450 (let ((operate
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2451 (function (lambda ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2452 (emerge-combine-versions-edit merge-begin merge-end
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2453 A-begin A-end B-begin B-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2454 (if emerge-auto-advance
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2455 (emerge-next-difference))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2456 (emerge-select-version force operate operate operate)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2457
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2458 (defun emerge-combine-versions-edit (merge-begin merge-end
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2459 A-begin A-end B-begin B-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2460 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2461 emerge-merge-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2462 (delete-region merge-begin merge-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2463 (goto-char merge-begin)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2464 (let ((i 0))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2465 (while (< i (length template))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2466 (let ((c (aref template i)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2467 (if (= c ?%)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2468 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2469 (setq i (1+ i))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2470 (setq c
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2471 (condition-case nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2472 (aref template i)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2473 (error ?%)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2474 (cond ((= c ?a)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2475 (insert-buffer-substring emerge-A-buffer A-begin A-end))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2476 ((= c ?b)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2477 (insert-buffer-substring emerge-B-buffer B-begin B-end))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2478 ((= c ?%)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2479 (insert ?%)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2480 (t
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2481 (insert c)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2482 (insert c)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2483 (setq i (1+ i))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2484 (goto-char merge-begin)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2485 (aset diff-vector 6 'combined)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2486 (emerge-refresh-mode-line)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2487
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2488 (defun emerge-set-merge-mode (mode)
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2489 "Set the major mode in a merge buffer.
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2490 Overrides any change that the mode might make to the mode line or local
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2491 keymap. Leaves merge in fast mode."
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2492 (interactive
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2493 (list (intern (completing-read "New major mode for merge buffer: "
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2494 obarray 'commandp t nil))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2495 (funcall mode)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2496 (emerge-refresh-mode-line)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2497 (if emerge-fast-mode
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2498 (emerge-fast-mode)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2499 (emerge-edit-mode)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2500
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2501 (defun emerge-one-line-window ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2502 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2503 (let ((window-min-height 1))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2504 (shrink-window (- (window-height) 2))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2505
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2506 ;;; Support routines
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2507
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2508 ;; Select a difference by placing the visual flags around the appropriate
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2509 ;; group of lines in the A, B, and merge buffers
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2510 (defun emerge-select-difference (n)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2511 (let ((diff-vector (aref emerge-difference-list n)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2512 (emerge-place-flags-in-buffer emerge-A-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2513 (aref diff-vector 0) (aref diff-vector 1))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2514 (emerge-place-flags-in-buffer emerge-B-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2515 (aref diff-vector 2) (aref diff-vector 3))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2516 (emerge-place-flags-in-buffer emerge-merge-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2517 (aref diff-vector 4) (aref diff-vector 5))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2518
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2519 (defun emerge-place-flags-in-buffer (buffer before after)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2520 (if (eq buffer emerge-merge-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2521 (emerge-place-flags-in-buffer1 buffer before after)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2522 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2523 buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2524 (emerge-place-flags-in-buffer1 buffer before after))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2525
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2526 (defun emerge-place-flags-in-buffer1 (buffer before after)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2527 (let ((buffer-read-only nil))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2528 ;; insert the flags
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2529 (goto-char before)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2530 (insert-before-markers emerge-before-flag)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2531 (goto-char after)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2532 (insert emerge-after-flag)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2533 ;; 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
2534 ;; them
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2535 ;; before marker is one char before the end of the before flag
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2536 ;; after marker is one char after the beginning of the after flag
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2537 (set-marker before (1- before))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2538 (set-marker after (1+ after))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2539
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2540 ;; Unselect a difference by removing the visual flags in the buffers.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2541 (defun emerge-unselect-difference (n)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2542 (let ((diff-vector (aref emerge-difference-list n)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2543 (emerge-remove-flags-in-buffer emerge-A-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2544 (aref diff-vector 0) (aref diff-vector 1))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2545 (emerge-remove-flags-in-buffer emerge-B-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2546 (aref diff-vector 2) (aref diff-vector 3))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2547 (emerge-remove-flags-in-buffer emerge-merge-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2548 (aref diff-vector 4) (aref diff-vector 5))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2549
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2550 (defun emerge-remove-flags-in-buffer (buffer before after)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2551 (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2552 buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2553 (let ((buffer-read-only nil))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2554 ;; put the markers at the beginning of the flags
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2555 (set-marker before (- before (1- emerge-before-flag-length)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2556 (set-marker after (1- after))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2557 ;; remove the flags
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2558 (goto-char before)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2559 (if (looking-at emerge-before-flag-match)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2560 (delete-char emerge-before-flag-length)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2561 ;; the flag isn't there
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2562 (ding)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2563 (message "Trouble removing flag."))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2564 (goto-char after)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2565 (if (looking-at emerge-after-flag-match)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2566 (delete-char emerge-after-flag-length)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2567 ;; the flag isn't there
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2568 (ding)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2569 (message "Trouble removing flag.")))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2570
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2571 ;; Select a difference, removing an flags that exist now.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2572 (defun emerge-unselect-and-select-difference (n &optional suppress-display)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2573 (if (and (>= emerge-current-difference 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2574 (< emerge-current-difference emerge-number-of-differences))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2575 (emerge-unselect-difference emerge-current-difference))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2576 (if (and (>= n 0) (< n emerge-number-of-differences))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2577 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2578 (emerge-select-difference n)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2579 (let* ((diff-vector (aref emerge-difference-list n))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2580 (selection-type (aref diff-vector 6)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2581 (if (eq selection-type 'default-A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2582 (aset diff-vector 6 'A)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2583 (if (eq selection-type 'default-B)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2584 (aset diff-vector 6 'B))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2585 (setq emerge-current-difference n)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2586 (if (not suppress-display)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2587 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2588 (emerge-recenter)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2589 (emerge-refresh-mode-line))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2590
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2591 ;; Perform tests to see whether user should be allowed to select a version
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2592 ;; of this difference:
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2593 ;; a valid difference has been selected; and
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2594 ;; the difference text in the merge buffer is:
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2595 ;; the A version (execute a-version), or
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2596 ;; the B version (execute b-version), or
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2597 ;; empty (execute neither-version), or
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2598 ;; argument FORCE is true (execute neither-version)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2599 ;; Otherwise, signal an error.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2600 (defun emerge-select-version (force a-version b-version neither-version)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2601 (emerge-validate-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2602 (let ((buffer-read-only nil))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2603 (let* ((diff-vector
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2604 (aref emerge-difference-list emerge-current-difference))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2605 (A-begin (1+ (aref diff-vector 0)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2606 (A-end (1- (aref diff-vector 1)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2607 (B-begin (1+ (aref diff-vector 2)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2608 (B-end (1- (aref diff-vector 3)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2609 (merge-begin (1+ (aref diff-vector 4)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2610 (merge-end (1- (aref diff-vector 5))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2611 (if (emerge-compare-buffers emerge-A-buffer A-begin A-end
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2612 emerge-merge-buffer merge-begin
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2613 merge-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2614 (funcall a-version)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2615 (if (emerge-compare-buffers emerge-B-buffer B-begin B-end
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2616 emerge-merge-buffer merge-begin
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2617 merge-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2618 (funcall b-version)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2619 (if (or force (= merge-begin merge-end))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2620 (funcall neither-version)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2621 (error "This difference region has been edited.")))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2622
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2623 ;; Revise the mode line to display which difference we have selected
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2624
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2625 (defun emerge-refresh-mode-line ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2626 (setq mode-line-buffer-identification
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2627 (list (format "Emerge: %%b diff %d of %d%s"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2628 (1+ emerge-current-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2629 emerge-number-of-differences
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2630 (if (and (>= emerge-current-difference 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2631 (< emerge-current-difference
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2632 emerge-number-of-differences))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2633 (cdr (assq (aref (aref emerge-difference-list
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2634 emerge-current-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2635 6)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2636 '((A . " - A")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2637 (B . " - B")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2638 (prefer-A . " - A*")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2639 (prefer-B . " - B*")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2640 (combined . " - comb"))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2641 ""))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2642 ;; Force mode-line redisplay
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2643 (set-buffer-modified-p (buffer-modified-p)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2644
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2645 ;; compare two regions in two buffers for containing the same text
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2646 (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
2647 ;; first check that the two regions are the same length
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2648 (if (not (and (= (- x-end x-begin) (- y-end y-begin))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2649 nil
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2650 (catch 'exit
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2651 (while (< x-begin x-end)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2652 ;; bite off and compare no more than 1000 characters at a time
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2653 (let* ((compare-length (min (- x-end x-begin) 1000))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2654 (x-string (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2655 buffer-x
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2656 (buffer-substring x-begin
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2657 (+ x-begin compare-length))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2658 (y-string (emerge-eval-in-buffer
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2659 buffer-y
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2660 (buffer-substring y-begin
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2661 (+ y-begin compare-length)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2662 (if (not (string-equal x-string y-string))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2663 (throw 'exit nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2664 (setq x-begin (+ x-begin compare-length))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2665 (setq y-begin (+ y-begin compare-length)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2666 t)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2667
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2668 ;; Construct a unique buffer name.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2669 ;; The first one tried is prefixsuffix, then prefix<2>suffix,
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2670 ;; prefix<3>suffix, etc.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2671 (defun emerge-unique-buffer-name (prefix suffix)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2672 (if (null (get-buffer (concat prefix suffix)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2673 (concat prefix suffix)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2674 (let ((n 2))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2675 (while (get-buffer (format "%s<%d>%s" prefix n suffix))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2676 (setq n (1+ n)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2677 (format "%s<%d>%s" prefix n suffix))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2678
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2679 ;; Verify that we have a difference selected.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2680 (defun emerge-validate-difference ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2681 (if (not (and (>= emerge-current-difference 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2682 (< emerge-current-difference emerge-number-of-differences)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2683 (error "No difference selected")))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2684
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2685 ;;; Functions for saving and restoring a batch of variables
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2686
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2687 ;; These functions save (get the values of) and restore (set the values of)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2688 ;; 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
2689 ;; the variables). A list element can also be a list of two functions,
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2690 ;; the first of which (when called with no arguments) gets the value, and
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2691 ;; the second (when called with a value as an argment) sets the value.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2692 ;; A "function" is anything that funcall can handle as an argument.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2693
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2694 (defun emerge-save-variables (vars)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2695 (mapcar (function (lambda (v) (if (symbolp v)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2696 (symbol-value v)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2697 (funcall (car v)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2698 vars))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2699
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2700 (defun emerge-restore-variables (vars values)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2701 (while vars
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2702 (let ((var (car vars))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2703 (value (car values)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2704 (if (symbolp var)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2705 (set var value)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2706 (funcall (car (cdr var)) value)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2707 (setq vars (cdr vars))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2708 (setq values (cdr values))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2709
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2710 ;; Make a temporary file that only we have access to.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2711 ;; PREFIX is appended to emerge-temp-file-prefix to make the filename prefix.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2712 (defun emerge-make-temp-file (prefix)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2713 (let ((f (make-temp-name (concat emerge-temp-file-prefix prefix))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2714 ;; create the file
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2715 (write-region (point-min) (point-min) f nil 'no-message)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2716 (set-file-modes f emerge-temp-file-mode)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2717 f))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2718
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2719 ;;; Functions that query the user before he can write out the current buffer.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2720
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2721 (defun emerge-query-write-file ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2722 "Query the user if he really wants to write out the incomplete merge.
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2723 If he says yes, call `write-file' to do so. See `emerge-query-and-call'
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2724 for details of the querying process."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2725 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2726 (emerge-query-and-call 'write-file))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2727
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2728 (defun emerge-query-save-buffer ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2729 "Query the user if he really wants to write out the incomplete merge.
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2730 If he says yes, call `save-buffer' to do so. See `emerge-query-and-call'
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2731 for details of the querying process."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2732 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2733 (emerge-query-and-call 'save-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2734
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2735 (defun emerge-query-and-call (command)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2736 "Query the user if he really wants to write out the incomplete merge.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2737 If he says yes, call COMMAND interactively. During the call, the flags
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2738 around the current difference are removed."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2739 (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
2740 ;; He really wants to do it -- unselect the difference for the duration
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2741 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2742 (if (and (>= emerge-current-difference 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2743 (< emerge-current-difference emerge-number-of-differences))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2744 (emerge-unselect-difference emerge-current-difference))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2745 ;; call-interactively takes the value of current-prefix-arg as the
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2746 ;; prefix argument value to be passed to the command. Thus, we have
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2747 ;; to do nothing special to make sure the prefix argument is
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2748 ;; transmitted to the command.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2749 (call-interactively command)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2750 (if (and (>= emerge-current-difference 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2751 (< emerge-current-difference emerge-number-of-differences))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2752 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2753 (emerge-select-difference emerge-current-difference)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2754 (emerge-recenter))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2755 ;; He's being smart and not doing it
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2756 (message "Not written")))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2757
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2758 ;; 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
2759 ;; file on disk, and attempt to remedy the situation if not.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2760 ;; 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
2761 ;; to do what is necessary to make them the same.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2762 (defun emerge-verify-file-buffer ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2763 ;; First check if the file has been modified since the buffer visited it.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2764 (if (verify-visited-file-modtime (current-buffer))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2765 (if (buffer-modified-p)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2766 ;; If buffer is not obsolete and is modified, offer to save
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2767 (if (yes-or-no-p (format "Save file %s? " buffer-file-name))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2768 (save-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2769 (error "Buffer out of sync for file %s" buffer-file-name))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2770 ;; If buffer is not obsolete and is not modified, do nothing
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2771 nil)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2772 (if (buffer-modified-p)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2773 ;; If buffer is obsolete and is modified, give error
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2774 (error "Buffer out of sync for file %s" buffer-file-name)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2775 ;; If buffer is obsolete and is not modified, offer to revert
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2776 (if (yes-or-no-p (format "Revert file %s? " buffer-file-name))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2777 (revert-buffer t t)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2778 (error "Buffer out of sync for file %s" buffer-file-name)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2779
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2780 ;; Utilities that might have value outside of Emerge.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2781
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2782 ;; 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
2783 ;; buffer.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2784 (defun emerge-copy-modes (buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2785 ;; Set the major mode
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2786 (funcall (emerge-eval-in-buffer buffer major-mode)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2787
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2788 ;; Define a key, even if a prefix of it is defined
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2789 (defun emerge-force-define-key (keymap key definition)
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2790 "Like `define-key', but isn't stopped if a prefix of KEY is a defined
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2791 command."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2792 ;; Find out if a prefix of key is defined
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2793 (let ((v (lookup-key keymap key)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2794 ;; If so, undefine it
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2795 (if (integerp v)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2796 (define-key keymap (substring key 0 v) nil)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2797 ;; Now define the key
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2798 (define-key keymap key definition))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2799
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2800 ;;; Improvements to describe-mode, so that it describes minor modes as well
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2801 ;;; as the major mode
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2802 (defun describe-mode (&optional minor)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2803 "Display documentation of current major mode.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2804 If optional MINOR is non-nil (or prefix argument is given if interactive),
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2805 display documentation of acive minor modes as well.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2806 For this to work correctly for a minor mode, the mode's indicator variable
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2807 (listed in `minor-mode-alist') must also be a function whose documentation
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2808 describes the minor mode."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2809 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2810 (with-output-to-temp-buffer "*Help*"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2811 (princ mode-name)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2812 (princ " Mode:\n")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2813 (princ (documentation major-mode))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2814 (let ((minor-modes minor-mode-alist)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2815 (locals (buffer-local-variables)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2816 (while minor-modes
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2817 (let* ((minor-mode (car (car minor-modes)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2818 (indicator (car (cdr (car minor-modes))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2819 (local-binding (assq minor-mode locals)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2820 ;; Document a minor mode if it is listed in minor-mode-alist,
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2821 ;; bound locally in this buffer, non-nil, and has a function
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2822 ;; definition.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2823 (if (and local-binding
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2824 (cdr local-binding)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2825 (fboundp minor-mode))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2826 (progn
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2827 (princ (format "\n\n\n%s minor mode (indicator%s):\n"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2828 minor-mode indicator))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2829 (princ (documentation minor-mode)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2830 (setq minor-modes (cdr minor-modes))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2831 (print-help-return-message)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2832
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2833 ;; Adjust things so that keyboard macro definitions are documented correctly.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2834 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2835
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2836 ;; Function to shadow a definition in a keymap with definitions in another.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2837 (defun emerge-shadow-key-definition (olddef newdef keymap shadowmap)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2838 "Shadow OLDDEF with NEWDEF for any keys in KEYMAP with entries in SHADOWMAP.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2839 In other words, SHADOWMAP will now shadow all definitions of OLDDEF in KEYMAP
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2840 with NEWDEF. Does not affect keys that are already defined in SHADOWMAP,
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2841 including those whose definition is OLDDEF."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2842 ;; loop through all keymaps accessible from keymap
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2843 (let ((maps (accessible-keymaps keymap)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2844 (while maps
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2845 (let ((prefix (car (car maps)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2846 (map (cdr (car maps))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2847 ;; examine a keymap
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2848 (if (arrayp map)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2849 ;; array keymap
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2850 (let ((len (length map))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2851 (i 0))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2852 (while (< i len)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2853 (if (eq (aref map i) olddef)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2854 ;; set the shadowing definition
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2855 (let ((key (concat prefix (char-to-string i))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2856 (emerge-define-key-if-possible shadowmap key newdef)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2857 (setq i (1+ i))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2858 ;; sparse keymap
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2859 (while map
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2860 (if (eq (cdr-safe (car-safe map)) olddef)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2861 ;; set the shadowing definition
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2862 (let ((key
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2863 (concat prefix (char-to-string (car (car map))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2864 (emerge-define-key-if-possible shadowmap key newdef)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2865 (setq map (cdr map)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2866 (setq maps (cdr maps)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2867
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2868 ;; 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
2869 (defun emerge-define-key-if-possible (keymap key definition)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2870 ;; look up the present definition of the key
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2871 (let ((present (lookup-key keymap key)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2872 (if (integerp present)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2873 ;; if it is "too long", look up the valid prefix
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2874 (if (not (lookup-key keymap (substring key 0 present)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2875 ;; if the prefix isn't defined, define it
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2876 (define-key keymap key definition))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2877 ;; if there is no present definition, define it
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2878 (if (not present)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2879 (define-key keymap key definition)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2880
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2881 (defun emerge-recursively-substitute-key-definition (olddef newdef keymap)
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2882 "Like `substitute-key-definition', but examines and substitutes in all
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2883 keymaps accessible from KEYMAP. Make sure that subordinate keymaps aren't
1429
14a2a89cb634 Dox fixes.
Christopher Zaborsky <rogue@erratum.com>
parents: 896
diff changeset
2884 shared with other keymaps! (`copy-keymap' will suffice.)"
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2885 ;; Loop through all keymaps accessible from keymap
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2886 (let ((maps (accessible-keymaps keymap)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2887 (while maps
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2888 ;; Substitute in this keymap
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2889 (substitute-key-definition olddef newdef (cdr (car maps)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2890 (setq maps (cdr maps)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2891
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2892 ;; Show the name of the file in the buffer.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2893 (defun emerge-show-file-name ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2894 "Displays the name of the file loaded into the current buffer.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2895 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
2896 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
2897 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
2898 (interactive)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2899 (let ((name (buffer-file-name)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2900 (or name
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2901 (setq name "Buffer has no file name."))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2902 (save-window-excursion
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2903 (select-window (minibuffer-window))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2904 (erase-buffer)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2905 (insert name)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2906 (if (not (pos-visible-in-window-p))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2907 (let ((echo-keystrokes 0))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2908 (while (and (not (pos-visible-in-window-p))
778
cd00bdacc17b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 662
diff changeset
2909 (> (1- (frame-height)) (window-height)))
583
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2910 (enlarge-window 1))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2911 (let ((c (read-char)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2912 (if (/= c 32)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2913 (setq unread-command-char c))))))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2914
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2915 ;; Improved auto-save file names.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2916 ;; This function fixes many problems with the standard auto-save file names:
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2917 ;; Auto-save files for non-file buffers get put in the default directory
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2918 ;; for the buffer, whether that makes sense or not.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2919 ;; 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
2920 ;; regardless of whether we can write into it or not.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2921 ;; 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
2922 ;; 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
2923 ;; each other.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2924 ;; To use this function, do:
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2925 ;; (fset 'make-auto-save-file-name
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2926 ;; (symbol-function 'emerge-make-auto-save-file-name))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2927 (defun emerge-make-auto-save-file-name ()
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2928 "Return file name to use for auto-saves of current buffer.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2929 Does not consider auto-save-visited-file-name; that is checked
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2930 before calling this function.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2931 You can redefine this for customization.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2932 See also auto-save-file-name-p."
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2933 (if buffer-file-name
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2934 ;; if buffer has a file, try the format <file directory>/#<file name>#
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2935 (let ((f (concat (file-name-directory buffer-file-name)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2936 "#"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2937 (file-name-nondirectory 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 (file-writable-p f)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2940 ;; the file is writable, so use it
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2941 f
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2942 ;; the file isn't writable, so use the format
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2943 ;; ~/#&<file name>&<hash of directory>#
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2944 (concat (getenv "HOME")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2945 "/#&"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2946 (file-name-nondirectory buffer-file-name)
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-string-into-string
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2949 (file-name-directory buffer-file-name))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2950 "#")))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2951 ;; if buffer has no file, use the format ~/#%<buffer name>%<process id>#
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2952 (expand-file-name (concat (getenv "HOME")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2953 "/#%"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2954 ;; quote / into \! and \ into \\
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2955 (unslashify-name (buffer-name))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2956 "%"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2957 (make-temp-name "")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2958 "#"))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2959
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2960 ;; 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
2961 ;; name. (Allowed characters are ! through ~, except /.)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2962 (defun hash-string-into-string (s)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2963 (let ((bins (vector 0 0 0 0 0))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2964 (i 0))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2965 (while (< i (length s))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2966 (aset bins (% i 5) (% (+ (* (aref bins (% i 5)) 35)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2967 (aref s i))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2968 65536))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2969 (setq i (1+ i)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2970 (mapconcat (function (lambda (b)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2971 (setq b (+ (% b 93) ?!))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2972 (if (>= b ?/)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2973 (setq b (1+ b)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2974 (char-to-string b)))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2975 bins "")))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2976
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2977 ;; Quote any /s in a string by replacing them with \!.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2978 ;; Also, replace any \s by \\, to make it one-to-one.
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2979 (defun unslashify-name (s)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2980 (let ((limit 0))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2981 (while (string-match "[/\\]" s limit)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2982 (setq s (concat (substring s 0 (match-beginning 0))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2983 (if (string= (substring s (match-beginning 0)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2984 (match-end 0))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2985 "/")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2986 "\\!"
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2987 "\\\\")
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2988 (substring s (match-end 0))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2989 (setq limit (1+ (match-end 0)))))
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2990 s)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2991
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2992 (provide 'emerge)
3c0c1cd8428a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2993
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 583
diff changeset
2994 ;;; emerge.el ends here