annotate lisp/emerge.el @ 2354:dcc756fba34f

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