diff options
| author | Jim Blandy | 1991-12-21 09:14:03 +0000 |
|---|---|---|
| committer | Jim Blandy | 1991-12-21 09:14:03 +0000 |
| commit | aa228418e97d3b6aada0da50ee0419c5c23f726c (patch) | |
| tree | 54f5de32b8b44b028fc96ebda21b9d11f96916fe /lisp/diff.el | |
| parent | 0231f2dce81e3f5118c5c2eecec6081ba888e03a (diff) | |
| download | emacs-aa228418e97d3b6aada0da50ee0419c5c23f726c.tar.gz emacs-aa228418e97d3b6aada0da50ee0419c5c23f726c.zip | |
*** empty log message ***
Diffstat (limited to 'lisp/diff.el')
| -rw-r--r-- | lisp/diff.el | 88 |
1 files changed, 77 insertions, 11 deletions
diff --git a/lisp/diff.el b/lisp/diff.el index 4dd8b2e57ff..7b92c6a4314 100644 --- a/lisp/diff.el +++ b/lisp/diff.el | |||
| @@ -29,12 +29,22 @@ | |||
| 29 | ;; containing 0 or more arguments which are passed on to `diff'. | 29 | ;; containing 0 or more arguments which are passed on to `diff'. |
| 30 | ;; NOTE: This is not an ordinary hook; it may not be a list of functions.") | 30 | ;; NOTE: This is not an ordinary hook; it may not be a list of functions.") |
| 31 | 31 | ||
| 32 | ;; - fpb@ittc.wec.com - Sep 25, 1990 | ||
| 33 | ;; Added code to support sccs diffing. | ||
| 34 | ;; also fixed one minor glitch in the | ||
| 35 | ;; search for the pattern. If you only 1 addition you won't find the end | ||
| 36 | ;; of the pattern (minor) | ||
| 37 | |||
| 38 | ;; | ||
| 32 | (defvar diff-switches nil | 39 | (defvar diff-switches nil |
| 33 | "*A list of switches to pass to the diff program.") | 40 | "*A list of switches to pass to the diff program.") |
| 34 | 41 | ||
| 35 | (defvar diff-search-pattern "^\\([0-9]\\|\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\)" | 42 | (defvar diff-search-pattern "^\\([0-9]\\|\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\)" |
| 36 | "Regular expression that delineates difference regions in diffs.") | 43 | "Regular expression that delineates difference regions in diffs.") |
| 37 | 44 | ||
| 45 | (defvar diff-rcs-extension ",v" | ||
| 46 | "*Extension to find RCS file, some systems do not use ,v") | ||
| 47 | |||
| 38 | ;; Initialize the keymap if it isn't already | 48 | ;; Initialize the keymap if it isn't already |
| 39 | (if (boundp 'diff-mode-map) | 49 | (if (boundp 'diff-mode-map) |
| 40 | nil | 50 | nil |
| @@ -75,22 +85,78 @@ and what appears to be it's backup for OLD." | |||
| 75 | (message "Comparing files %s %s..." new old) | 85 | (message "Comparing files %s %s..." new old) |
| 76 | (setq new (expand-file-name new) | 86 | (setq new (expand-file-name new) |
| 77 | old (expand-file-name old)) | 87 | old (expand-file-name old)) |
| 78 | (let ((buffer-read-only nil) | 88 | (diff-internal-diff "diff" (append diff-switches (list new old)) nil)) |
| 79 | (sw diff-switches)) | 89 | |
| 90 | (defun diff-sccs (new) | ||
| 91 | "Find and display the differences between OLD and SCCS files." | ||
| 92 | (interactive | ||
| 93 | (let (newf) | ||
| 94 | (list | ||
| 95 | (setq newf (buffer-file-name) | ||
| 96 | newf (if (and newf (file-exists-p newf)) | ||
| 97 | (read-file-name | ||
| 98 | (concat "Diff new file: (" | ||
| 99 | (file-name-nondirectory newf) ") ") | ||
| 100 | nil newf t) | ||
| 101 | (read-file-name "Diff new file: " nil nil t)))))) | ||
| 102 | |||
| 103 | (message "Comparing SCCS file %s..." new) | ||
| 104 | (setq new (expand-file-name new)) | ||
| 105 | (if (file-exists-p (concat | ||
| 106 | (file-name-directory new) | ||
| 107 | "SCCS/s." | ||
| 108 | (file-name-nondirectory new))) | ||
| 109 | (diff-internal-diff "sccs" | ||
| 110 | (append '("diffs") diff-switches (list new)) | ||
| 111 | 2) | ||
| 112 | (error "%s does not exist" | ||
| 113 | (concat (file-name-directory new) "SCCS/s." | ||
| 114 | (file-name-nondirectory new))))) | ||
| 115 | |||
| 116 | (defun diff-rcs (new) | ||
| 117 | "Find and display the differences between OLD and RCS files." | ||
| 118 | (interactive | ||
| 119 | (let (newf) | ||
| 120 | (list | ||
| 121 | (setq newf (buffer-file-name) | ||
| 122 | newf (if (and newf (file-exists-p newf)) | ||
| 123 | (read-file-name | ||
| 124 | (concat "Diff new file: (" | ||
| 125 | (file-name-nondirectory newf) ") ") | ||
| 126 | nil newf t) | ||
| 127 | (read-file-name "Diff new file: " nil nil t)))))) | ||
| 128 | |||
| 129 | (message "Comparing RCS file %s..." new) | ||
| 130 | (let* ((fullname (expand-file-name new)) | ||
| 131 | (rcsfile (concat (file-name-directory fullname) | ||
| 132 | "RCS/" | ||
| 133 | (file-name-nondirectory fullname) | ||
| 134 | diff-rcs-extension))) | ||
| 135 | (if (file-exists-p rcsfile) | ||
| 136 | (diff-internal-diff "rcsdiff" (append diff-switches (list fullname)) 4) | ||
| 137 | (error "%s does not exist" rcsfile)))) | ||
| 138 | |||
| 139 | (defun diff-internal-diff (diff-command sw strip) | ||
| 140 | (let ((buffer-read-only nil)) | ||
| 80 | (with-output-to-temp-buffer "*Diff Output*" | 141 | (with-output-to-temp-buffer "*Diff Output*" |
| 81 | (buffer-disable-undo standard-output) | 142 | (buffer-disable-undo standard-output) |
| 82 | (save-excursion | 143 | (save-excursion |
| 83 | (set-buffer standard-output) | 144 | (set-buffer standard-output) |
| 84 | (erase-buffer) | 145 | (erase-buffer) |
| 85 | (apply 'call-process "diff" nil t nil | 146 | (apply 'call-process diff-command nil t nil sw))) |
| 86 | (append diff-switches (list old new))))) | ||
| 87 | (set-buffer "*Diff Output*") | 147 | (set-buffer "*Diff Output*") |
| 88 | (goto-char (point-min)) | 148 | (goto-char (point-min)) |
| 89 | (while sw | 149 | (while sw |
| 90 | (if (string= (car sw) "-c") | 150 | (if (string= (car sw) "-c") |
| 91 | ;; strip leading filenames from context diffs | 151 | ;; strip leading filenames from context diffs |
| 92 | (progn (forward-line 2) (delete-region (point-min) (point)))) | 152 | (progn (forward-line 2) (delete-region (point-min) (point)))) |
| 93 | (setq sw (cdr sw)))) | 153 | (if (and (string= (car sw) "-C") (string= "sccs" diff-command)) |
| 154 | ;; strip stuff from SCCS context diffs | ||
| 155 | (progn (forward-line 2) (delete-region (point-min) (point)))) | ||
| 156 | (setq sw (cdr sw))) | ||
| 157 | (if strip | ||
| 158 | ;; strip stuff from SCCS context diffs | ||
| 159 | (progn (forward-line strip) (delete-region (point-min) (point))))) | ||
| 94 | (diff-mode) | 160 | (diff-mode) |
| 95 | (if (string= "0" diff-total-differences) | 161 | (if (string= "0" diff-total-differences) |
| 96 | (let ((buffer-read-only nil)) | 162 | (let ((buffer-read-only nil)) |
| @@ -103,7 +169,7 @@ and what appears to be it's backup for OLD." | |||
| 103 | (goto-char (point-max))))) | 169 | (goto-char (point-max))))) |
| 104 | (setq diff-current-difference "1"))) | 170 | (setq diff-current-difference "1"))) |
| 105 | 171 | ||
| 106 | ;; Take a buffer full of Unix diff output and go into a mode to easily | 172 | ;; Take a buffer full of Unix diff output and go into a mode to easily |
| 107 | ;; see the next and previous difference | 173 | ;; see the next and previous difference |
| 108 | (defun diff-mode () | 174 | (defun diff-mode () |
| 109 | "Diff Mode is used by \\[diff] for perusing the output from the diff program. | 175 | "Diff Mode is used by \\[diff] for perusing the output from the diff program. |
| @@ -129,8 +195,8 @@ All normal editing commands are turned off. Instead, these are available: | |||
| 129 | (int-to-string (diff-count-differences)))) | 195 | (int-to-string (diff-count-differences)))) |
| 130 | 196 | ||
| 131 | (defun diff-next-difference (n) | 197 | (defun diff-next-difference (n) |
| 132 | "In diff mode, go to the beginning of the next difference as delimited | 198 | "Go to the beginning of the next difference. |
| 133 | by `diff-search-pattern'." | 199 | Differences are delimited by `diff-search-pattern'." |
| 134 | (interactive "p") | 200 | (interactive "p") |
| 135 | (if (< n 0) (diff-previous-difference (- n)) | 201 | (if (< n 0) (diff-previous-difference (- n)) |
| 136 | (if (zerop n) () | 202 | (if (zerop n) () |
| @@ -153,8 +219,8 @@ by `diff-search-pattern'." | |||
| 153 | (goto-char (point-min))))) | 219 | (goto-char (point-min))))) |
| 154 | 220 | ||
| 155 | (defun diff-previous-difference (n) | 221 | (defun diff-previous-difference (n) |
| 156 | "In diff mode, go the the beginning of the previous difference as delimited | 222 | "Go the the beginning of the previous difference. |
| 157 | by `diff-search-pattern'." | 223 | Differences are delimited by `diff-search-pattern'." |
| 158 | (interactive "p") | 224 | (interactive "p") |
| 159 | (if (< n 0) (diff-next-difference (- n)) | 225 | (if (< n 0) (diff-next-difference (- n)) |
| 160 | (if (zerop n) () | 226 | (if (zerop n) () |
| @@ -172,7 +238,7 @@ by `diff-search-pattern'." | |||
| 172 | (goto-char (point-min))))) | 238 | (goto-char (point-min))))) |
| 173 | 239 | ||
| 174 | (defun diff-show-difference (n) | 240 | (defun diff-show-difference (n) |
| 175 | "Show difference number N (prefix arg)." | 241 | "Show difference number N (prefix argument)." |
| 176 | (interactive "p") | 242 | (interactive "p") |
| 177 | (let ((cur (string-to-int diff-current-difference))) | 243 | (let ((cur (string-to-int diff-current-difference))) |
| 178 | (cond ((or (= n cur) | 244 | (cond ((or (= n cur) |