Mercurial > emacs
comparison lisp/diff.el @ 16984:100ef50c2c01
* (diff-process-setup): New function, sets up the
compilation-exit-message-function so that it works with both
asynchronous and synchronous sub-processes.
(diff): Bind compilation-exit-message-function. Run
compilation-finish-function when compile-internal returns if async
processes aren't supported.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sun, 09 Feb 1997 15:57:11 +0000 |
parents | e4d0cf418b2b |
children | 442b07348a34 |
comparison
equal
deleted
inserted
replaced
16983:8c94c682773a | 16984:100ef50c2c01 |
---|---|
157 ;; Set to point-max, not point, so we don't perpetually | 157 ;; Set to point-max, not point, so we don't perpetually |
158 ;; parse the last bit of text when it isn't a diff header. | 158 ;; parse the last bit of text when it isn't a diff header. |
159 (setq compilation-parsing-end (point-max))) | 159 (setq compilation-parsing-end (point-max))) |
160 (message "Parsing differences...done")) | 160 (message "Parsing differences...done")) |
161 (setq compilation-error-list (nreverse compilation-error-list))) | 161 (setq compilation-error-list (nreverse compilation-error-list))) |
162 | |
163 (defun diff-process-setup () | |
164 "Set up \`compilation-exit-message-function' for \`diff'." | |
165 ;; Avoid frightening people with "abnormally terminated" | |
166 ;; if diff finds differences. | |
167 (set (make-local-variable 'compilation-exit-message-function) | |
168 (lambda (status code msg) | |
169 (cond ((not (eq status 'exit)) | |
170 (cons msg code)) | |
171 ((zerop code) | |
172 '("finished (no differences)\n" . "no differences")) | |
173 ((= code 1) | |
174 '("finished\n" . "differences found")) | |
175 (t | |
176 (cons msg code)))))) | |
162 | 177 |
163 ;;;###autoload | 178 ;;;###autoload |
164 (defun diff (old new &optional switches) | 179 (defun diff (old new &optional switches) |
165 "Find and display the differences between OLD and NEW files. | 180 "Find and display the differences between OLD and NEW files. |
166 Interactively the current buffer's file name is the default for NEW | 181 Interactively the current buffer's file name is the default for NEW |
196 old (expand-file-name old)) | 211 old (expand-file-name old)) |
197 (let ((old-alt (file-local-copy old)) | 212 (let ((old-alt (file-local-copy old)) |
198 (new-alt (file-local-copy new)) | 213 (new-alt (file-local-copy new)) |
199 buf) | 214 buf) |
200 (save-excursion | 215 (save-excursion |
201 (let ((command | 216 (let ((compilation-process-setup-function 'diff-process-setup) |
217 (command | |
202 (mapconcat 'identity | 218 (mapconcat 'identity |
203 (append (list diff-command) | 219 (append (list diff-command) |
204 ;; Use explicitly specified switches | 220 ;; Use explicitly specified switches |
205 (if switches | 221 (if switches |
206 (if (consp switches) | 222 (if (consp switches) |
219 (setq buf | 235 (setq buf |
220 (compile-internal command | 236 (compile-internal command |
221 "No more differences" "Diff" | 237 "No more differences" "Diff" |
222 'diff-parse-differences)) | 238 'diff-parse-differences)) |
223 (set-buffer buf) | 239 (set-buffer buf) |
224 ;; Avoid frightening people with "abnormally terminated" | |
225 ;; if diff finds differences. | |
226 (set (make-local-variable 'compilation-exit-message-function) | |
227 (lambda (status code msg) | |
228 (cond ((not (eq status 'exit)) | |
229 (cons msg code)) | |
230 ((zerop code) | |
231 '("finished (no differences)\n" . "no differences")) | |
232 ((= code 1) | |
233 '("finished\n" . "differences found")) | |
234 (t | |
235 (cons msg code))))) | |
236 (set (make-local-variable 'diff-old-file) old) | 240 (set (make-local-variable 'diff-old-file) old) |
237 (set (make-local-variable 'diff-new-file) new) | 241 (set (make-local-variable 'diff-new-file) new) |
238 (set (make-local-variable 'diff-old-temp-file) old-alt) | 242 (set (make-local-variable 'diff-old-temp-file) old-alt) |
239 (set (make-local-variable 'diff-new-temp-file) new-alt) | 243 (set (make-local-variable 'diff-new-temp-file) new-alt) |
240 (set (make-local-variable 'compilation-finish-function) | 244 (set (make-local-variable 'compilation-finish-function) |
241 (function (lambda (buff msg) | 245 (function (lambda (buff msg) |
242 (if diff-old-temp-file | 246 (if diff-old-temp-file |
243 (delete-file diff-old-temp-file)) | 247 (delete-file diff-old-temp-file)) |
244 (if diff-new-temp-file | 248 (if diff-new-temp-file |
245 (delete-file diff-new-temp-file))))) | 249 (delete-file diff-new-temp-file))))) |
250 ;; When async processes aren't available, the compilation finish | |
251 ;; function doesn't get chance to run. Invoke it by hand. | |
252 (or (fboundp 'start-process) | |
253 (funcall compilation-finish-function nil nil)) | |
246 buf)))) | 254 buf)))) |
247 | 255 |
248 ;;;###autoload | 256 ;;;###autoload |
249 (defun diff-backup (file &optional switches) | 257 (defun diff-backup (file &optional switches) |
250 "Diff this file with its backup file or vice versa. | 258 "Diff this file with its backup file or vice versa. |