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