diff options
| author | Stefan Monnier | 2004-02-10 21:37:35 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2004-02-10 21:37:35 +0000 |
| commit | 4c11f6a8f2031270f07e1beef0ebd7cf0fe306db (patch) | |
| tree | cf303502c00f93734fd7474de9a6e7534f4cdafd /lisp/diff.el | |
| parent | b9aafad504b1d74b069788a088f7ee4b152f5628 (diff) | |
| download | emacs-4c11f6a8f2031270f07e1beef0ebd7cf0fe306db.tar.gz emacs-4c11f6a8f2031270f07e1beef0ebd7cf0fe306db.zip | |
(diff-switches): New fun.
(diff, diff-backup): Use it.
(diff): Clean up the args construction. Use backquote.
Use listp instead of consp to avoid putting a nil arg.
Diffstat (limited to 'lisp/diff.el')
| -rw-r--r-- | lisp/diff.el | 95 |
1 files changed, 44 insertions, 51 deletions
diff --git a/lisp/diff.el b/lisp/diff.el index 5981e1888e1..c776e36dfdc 100644 --- a/lisp/diff.el +++ b/lisp/diff.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; diff.el --- run `diff' in compilation-mode | 1 | ;;; diff.el --- run `diff' in compilation-mode |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1992, 1994, 1996, 2001 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1992, 1994, 1996, 2001, 2004 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Maintainer: FSF | 5 | ;; Maintainer: FSF |
| 6 | ;; Keywords: unix, tools | 6 | ;; Keywords: unix, tools |
| @@ -185,39 +185,39 @@ is nil, REGEXP matches only half a hunk.") | |||
| 185 | (t | 185 | (t |
| 186 | (cons msg code)))))) | 186 | (cons msg code)))))) |
| 187 | 187 | ||
| 188 | ;; prompt if prefix arg present | ||
| 189 | (defun diff-switches () | ||
| 190 | (if current-prefix-arg | ||
| 191 | (read-string "Diff switches: " | ||
| 192 | (if (stringp diff-switches) | ||
| 193 | diff-switches | ||
| 194 | (mapconcat 'identity diff-switches " "))))) | ||
| 195 | |||
| 188 | ;;;###autoload | 196 | ;;;###autoload |
| 189 | (defun diff (old new &optional switches no-async) | 197 | (defun diff (old new &optional switches no-async) |
| 190 | "Find and display the differences between OLD and NEW files. | 198 | "Find and display the differences between OLD and NEW files. |
| 191 | Interactively the current buffer's file name is the default for NEW | 199 | Interactively the current buffer's file name is the default for NEW |
| 192 | and a backup file for NEW is the default for OLD. | 200 | and a backup file for NEW is the default for OLD. |
| 193 | With prefix arg, prompt for diff switches. | 201 | If NO-ASYNC is non-nil, call diff synchronously. |
| 194 | If NO-ASYNC is non-nil, call diff synchronously." | 202 | With prefix arg, prompt for diff switches." |
| 195 | (interactive | 203 | (interactive |
| 196 | (nconc | 204 | (let (oldf newf) |
| 197 | (let (oldf newf) | 205 | (setq newf (buffer-file-name) |
| 198 | (nreverse | 206 | newf (if (and newf (file-exists-p newf)) |
| 199 | (list | 207 | (read-file-name |
| 200 | (setq newf (buffer-file-name) | 208 | (concat "Diff new file: (default " |
| 201 | newf (if (and newf (file-exists-p newf)) | 209 | (file-name-nondirectory newf) ") ") |
| 202 | (read-file-name | 210 | nil newf t) |
| 203 | (concat "Diff new file: (default " | 211 | (read-file-name "Diff new file: " nil nil t))) |
| 204 | (file-name-nondirectory newf) ") ") | 212 | (setq oldf (file-newest-backup newf) |
| 205 | nil newf t) | 213 | oldf (if (and oldf (file-exists-p oldf)) |
| 206 | (read-file-name "Diff new file: " nil nil t))) | 214 | (read-file-name |
| 207 | (setq oldf (file-newest-backup newf) | 215 | (concat "Diff original file: (default " |
| 208 | oldf (if (and oldf (file-exists-p oldf)) | 216 | (file-name-nondirectory oldf) ") ") |
| 209 | (read-file-name | 217 | (file-name-directory oldf) oldf t) |
| 210 | (concat "Diff original file: (default " | 218 | (read-file-name "Diff original file: " |
| 211 | (file-name-nondirectory oldf) ") ") | 219 | (file-name-directory newf) nil t))) |
| 212 | (file-name-directory oldf) oldf t) | 220 | (list oldf newf (diff-switches)))) |
| 213 | (read-file-name "Diff original file: " | ||
| 214 | (file-name-directory newf) nil t)))))) | ||
| 215 | (if current-prefix-arg | ||
| 216 | (list (read-string "Diff switches: " | ||
| 217 | (if (stringp diff-switches) | ||
| 218 | diff-switches | ||
| 219 | (mapconcat 'identity diff-switches " ")))) | ||
| 220 | nil))) | ||
| 221 | (setq new (expand-file-name new) | 221 | (setq new (expand-file-name new) |
| 222 | old (expand-file-name old)) | 222 | old (expand-file-name old)) |
| 223 | (let ((old-alt (file-local-copy old)) | 223 | (let ((old-alt (file-local-copy old)) |
| @@ -227,21 +227,19 @@ If NO-ASYNC is non-nil, call diff synchronously." | |||
| 227 | (let ((compilation-process-setup-function 'diff-process-setup) | 227 | (let ((compilation-process-setup-function 'diff-process-setup) |
| 228 | (command | 228 | (command |
| 229 | (mapconcat 'identity | 229 | (mapconcat 'identity |
| 230 | (append (list diff-command) | 230 | `(,diff-command |
| 231 | ;; Use explicitly specified switches | 231 | ;; Use explicitly specified switches |
| 232 | (if switches | 232 | ,@(if switches |
| 233 | (if (consp switches) | 233 | (if (listp switches) |
| 234 | switches (list switches)) | 234 | switches (list switches)) |
| 235 | ;; If not specified, use default. | 235 | ;; If not specified, use default. |
| 236 | (if (consp diff-switches) | 236 | (if (listp diff-switches) |
| 237 | diff-switches | 237 | diff-switches |
| 238 | (list diff-switches))) | 238 | (list diff-switches))) |
| 239 | (if (or old-alt new-alt) | 239 | ,@(if (or old-alt new-alt) |
| 240 | (list "-L" old "-L" new)) | 240 | (list "-L" old "-L" new)) |
| 241 | (list | 241 | ,(shell-quote-argument (or old-alt old)) |
| 242 | (shell-quote-argument (or old-alt old))) | 242 | ,(shell-quote-argument (or new-alt new))) |
| 243 | (list | ||
| 244 | (shell-quote-argument (or new-alt new)))) | ||
| 245 | " "))) | 243 | " "))) |
| 246 | (setq buf | 244 | (setq buf |
| 247 | (compile-internal command | 245 | (compile-internal command |
| @@ -270,15 +268,10 @@ If NO-ASYNC is non-nil, call diff synchronously." | |||
| 270 | "Diff this file with its backup file or vice versa. | 268 | "Diff this file with its backup file or vice versa. |
| 271 | Uses the latest backup, if there are several numerical backups. | 269 | Uses the latest backup, if there are several numerical backups. |
| 272 | If this file is a backup, diff it with its original. | 270 | If this file is a backup, diff it with its original. |
| 273 | The backup file is the first file given to `diff'." | 271 | The backup file is the first file given to `diff'. |
| 272 | With prefix arg, prompt for diff switches." | ||
| 274 | (interactive (list (read-file-name "Diff (file with backup): ") | 273 | (interactive (list (read-file-name "Diff (file with backup): ") |
| 275 | (if current-prefix-arg | 274 | (diff-switches))) |
| 276 | (read-string "Diff switches: " | ||
| 277 | (if (stringp diff-switches) | ||
| 278 | diff-switches | ||
| 279 | (mapconcat 'identity | ||
| 280 | diff-switches " "))) | ||
| 281 | nil))) | ||
| 282 | (let (bak ori) | 275 | (let (bak ori) |
| 283 | (if (backup-file-name-p file) | 276 | (if (backup-file-name-p file) |
| 284 | (setq bak file | 277 | (setq bak file |