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