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