Mercurial > emacs
annotate lisp/diff.el @ 88335:7f7748896b97
(rmail-summary-kill-label): Call rmail-kill-label
with only one argument.
author | Alex Schroeder <alex@gnu.org> |
---|---|
date | Tue, 11 Apr 2006 13:28:56 +0000 |
parents | d7ddb3e565de |
children |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
25413
diff
changeset
|
1 ;;; diff.el --- run `diff' in compilation-mode |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
2 |
88155 | 3 ;; Copyright (C) 1992, 1994, 1996, 2001, 2002, 2003, 2004, |
4 ;; 2005 Free Software Foundation, Inc. | |
894 | 5 |
38697
a19197c6442f
Keyword added and FSF specified as Maintainer.
Pavel Janík <Pavel@Janik.cz>
parents:
38414
diff
changeset
|
6 ;; Maintainer: FSF |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1215
diff
changeset
|
7 ;; Keywords: unix, tools |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
669
diff
changeset
|
8 |
349 | 9 ;; This file is part of GNU Emacs. |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
669
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
349 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
88155 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
349 | 25 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
26 ;;; Commentary: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
27 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
28 ;; This package helps you explore differences between files, using the |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
29 ;; UNIX command diff(1). The commands are `diff' and `diff-backup'. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
30 ;; You can specify options with `diff-switches'. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
31 |
894 | 32 ;;; Code: |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
669
diff
changeset
|
33 |
18143 | 34 (defgroup diff nil |
35 "Comparing files with `diff'." | |
36 :group 'tools) | |
894 | 37 |
18143 | 38 ;;;###autoload |
39 (defcustom diff-switches "-c" | |
88155 | 40 "*A string or list of strings specifying switches to be passed to diff." |
18143 | 41 :type '(choice string (repeat string)) |
42 :group 'diff) | |
43 | |
44 ;;;###autoload | |
45 (defcustom diff-command "diff" | |
46 "*The command to use to run diff." | |
18150
960597385f1c
(diff-command): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
18143
diff
changeset
|
47 :type 'string |
18143 | 48 :group 'diff) |
9736
093d80b4ae17
(diff-command): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8195
diff
changeset
|
49 |
1134
05c961416bb5
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
50 (defvar diff-old-temp-file nil |
05c961416bb5
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
51 "This is the name of a temp file to be deleted after diff finishes.") |
05c961416bb5
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
52 (defvar diff-new-temp-file nil |
05c961416bb5
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
53 "This is the name of a temp file to be deleted after diff finishes.") |
05c961416bb5
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
54 |
88155 | 55 ;; prompt if prefix arg present |
56 (defun diff-switches () | |
57 (if current-prefix-arg | |
58 (read-string "Diff switches: " | |
59 (if (stringp diff-switches) | |
60 diff-switches | |
61 (mapconcat 'identity diff-switches " "))))) | |
894 | 62 |
88155 | 63 (defun diff-sentinel (code) |
64 "Code run when the diff process exits. | |
65 CODE is the exit code of the process. It should be 0 iff no diffs were found." | |
66 (if diff-old-temp-file (delete-file diff-old-temp-file)) | |
67 (if diff-new-temp-file (delete-file diff-new-temp-file)) | |
68 (save-excursion | |
69 (goto-char (point-max)) | |
70 (insert (format "\nDiff finished%s. %s\n" | |
71 (if (equal 0 code) " (no differences)" "") | |
72 (current-time-string))))) | |
16984
100ef50c2c01
* (diff-process-setup): New function, sets up the
Eli Zaretskii <eliz@gnu.org>
parents:
15932
diff
changeset
|
73 |
349 | 74 ;;;###autoload |
47301
bac8aaf18835
(diff): Add optional argument no-async, and use the above argument.
Colin Walters <walters@gnu.org>
parents:
45472
diff
changeset
|
75 (defun diff (old new &optional switches no-async) |
349 | 76 "Find and display the differences between OLD and NEW files. |
4759 | 77 Interactively the current buffer's file name is the default for NEW |
894 | 78 and a backup file for NEW is the default for OLD. |
88155 | 79 If NO-ASYNC is non-nil, call diff synchronously. |
80 With prefix arg, prompt for diff switches." | |
349 | 81 (interactive |
88155 | 82 (let (oldf newf) |
83 (setq newf (buffer-file-name) | |
84 newf (if (and newf (file-exists-p newf)) | |
85 (read-file-name | |
86 (concat "Diff new file (default " | |
87 (file-name-nondirectory newf) "): ") | |
88 nil newf t) | |
89 (read-file-name "Diff new file: " nil nil t))) | |
90 (setq oldf (file-newest-backup newf) | |
91 oldf (if (and oldf (file-exists-p oldf)) | |
92 (read-file-name | |
93 (concat "Diff original file (default " | |
94 (file-name-nondirectory oldf) "): ") | |
95 (file-name-directory oldf) oldf t) | |
96 (read-file-name "Diff original file: " | |
97 (file-name-directory newf) nil t))) | |
98 (list oldf newf (diff-switches)))) | |
349 | 99 (setq new (expand-file-name new) |
100 old (expand-file-name old)) | |
88155 | 101 (or switches (setq switches diff-switches)) ; If not specified, use default. |
102 (let* ((old-alt (file-local-copy old)) | |
1134
05c961416bb5
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1112
diff
changeset
|
103 (new-alt (file-local-copy new)) |
88155 | 104 (command |
105 (mapconcat 'identity | |
106 `(,diff-command | |
107 ;; Use explicitly specified switches | |
108 ,@(if (listp switches) switches (list switches)) | |
109 ,@(if (or old-alt new-alt) | |
110 (list "-L" old "-L" new)) | |
111 ,(shell-quote-argument (or old-alt old)) | |
112 ,(shell-quote-argument (or new-alt new))) | |
113 " ")) | |
114 (buf (get-buffer-create "*Diff*")) | |
115 (thisdir default-directory) | |
116 proc) | |
15932
e4d0cf418b2b
(diff): Don't pop to *diff* buffer. Change bogus
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
117 (save-excursion |
88155 | 118 (display-buffer buf) |
119 (set-buffer buf) | |
120 (setq buffer-read-only nil) | |
121 (buffer-disable-undo (current-buffer)) | |
122 (erase-buffer) | |
123 (buffer-enable-undo (current-buffer)) | |
124 (diff-mode) | |
125 (set (make-local-variable 'revert-buffer-function) | |
126 `(lambda (ignore-auto noconfirm) | |
127 (diff ',old ',new ',switches ',no-async))) | |
128 (set (make-local-variable 'diff-old-temp-file) old-alt) | |
129 (set (make-local-variable 'diff-new-temp-file) new-alt) | |
130 (setq default-directory thisdir) | |
131 (insert command "\n") | |
132 (if (and (not no-async) (fboundp 'start-process)) | |
133 (progn | |
134 (setq proc (start-process "Diff" buf shell-file-name | |
135 shell-command-switch command)) | |
136 (set-process-sentinel | |
137 proc (lambda (proc msg) | |
138 (with-current-buffer (process-buffer proc) | |
139 (diff-sentinel (process-exit-status proc)))))) | |
140 ;; Async processes aren't available. | |
141 (diff-sentinel | |
142 (call-process shell-file-name nil buf nil | |
143 shell-command-switch command)))) | |
144 buf)) | |
474 | 145 |
894 | 146 ;;;###autoload |
147 (defun diff-backup (file &optional switches) | |
881
945558e05127
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
148 "Diff this file with its backup file or vice versa. |
945558e05127
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
149 Uses the latest backup, if there are several numerical backups. |
945558e05127
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
150 If this file is a backup, diff it with its original. |
88155 | 151 The backup file is the first file given to `diff'. |
152 With prefix arg, prompt for diff switches." | |
894 | 153 (interactive (list (read-file-name "Diff (file with backup): ") |
88155 | 154 (diff-switches))) |
881
945558e05127
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
155 (let (bak ori) |
945558e05127
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
156 (if (backup-file-name-p file) |
945558e05127
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
157 (setq bak file |
945558e05127
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
158 ori (file-name-sans-versions file)) |
945558e05127
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
159 (setq bak (or (diff-latest-backup-file file) |
945558e05127
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
160 (error "No backup found for %s" file)) |
945558e05127
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
161 ori file)) |
894 | 162 (diff bak ori switches))) |
474 | 163 |
881
945558e05127
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
164 (defun diff-latest-backup-file (fn) ; actually belongs into files.el |
945558e05127
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
165 "Return the latest existing backup of FILE, or nil." |
7028
6915bf781a38
Pass operation to Ffind_file_name_handler.
Karl Heuer <kwzh@gnu.org>
parents:
6321
diff
changeset
|
166 (let ((handler (find-file-name-handler fn 'diff-latest-backup-file))) |
6147
f89879182407
(diff-latest-backup-file): Check for a file-name-handler and run it.
Roland McGrath <roland@gnu.org>
parents:
5542
diff
changeset
|
167 (if handler |
6321
8c667dc4566e
(diff-latest-backup-file): Call file name handler properly.
Richard M. Stallman <rms@gnu.org>
parents:
6147
diff
changeset
|
168 (funcall handler 'diff-latest-backup-file fn) |
45472
6b7dcaa53b5c
(diff-latest-backup-file): Replace the main code by a call of
Markus Rost <rost@math.uni-bielefeld.de>
parents:
45198
diff
changeset
|
169 (file-newest-backup fn)))) |
474 | 170 |
2541
09e58f572f19
(diff-parse-differences): Small robustification --- don't lose if we
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
171 (provide 'diff) |
09e58f572f19
(diff-parse-differences): Small robustification --- don't lose if we
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
172 |
88155 | 173 ;;; arch-tag: 7de2c29b-7ea5-4b85-9b9d-72dd860de2bd |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
474
diff
changeset
|
174 ;;; diff.el ends here |