annotate lisp/diff.el @ 92833:272f566348a7

(generated-autoload-file): Don't set, instead use different values of generate-autoload-cookie plus Makefile rules to allow for a mixture of internal calendar autoloads and normal autoloads.
author Glenn Morris <rgm@gnu.org>
date Thu, 13 Mar 2008 05:44:04 +0000
parents 107ccd98fa12
children 606f2d163a64 ee5932bf781d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
64762
41bb365f41c4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64091
diff changeset
3 ;; Copyright (C) 1992, 1994, 1996, 2001, 2002, 2003, 2004,
79721
73661ddc7ac7 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 78492
diff changeset
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
894
41507a5a8fd7 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 881
diff changeset
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
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
78236
9355f9b7bbff Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
13 ;; the Free Software Foundation; either version 3, or (at your option)
349
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 ;; any later version.
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; GNU General Public License for more details.
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14140
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 55255
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 55255
diff changeset
24 ;; Boston, MA 02110-1301, USA.
349
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
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
41507a5a8fd7 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 881
diff changeset
32 ;;; Code:
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 669
diff changeset
33
18143
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
34 (defgroup diff nil
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
35 "Comparing files with `diff'."
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
36 :group 'tools)
894
41507a5a8fd7 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 881
diff changeset
37
18143
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
38 ;;;###autoload
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
39 (defcustom diff-switches "-c"
55255
3654c6b288e0 (diff-switches): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 55117
diff changeset
40 "*A string or list of strings specifying switches to be passed to diff."
18143
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
41 :type '(choice string (repeat string))
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
42 :group 'diff)
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
43
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
44 ;;;###autoload
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
45 (defcustom diff-command "diff"
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
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
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
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
53914
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
55 ;; prompt if prefix arg present
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
56 (defun diff-switches ()
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
57 (if current-prefix-arg
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
58 (read-string "Diff switches: "
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
59 (if (stringp diff-switches)
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
60 diff-switches
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
61 (mapconcat 'identity diff-switches " ")))))
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
62
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
63 (defun diff-sentinel (code)
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
64 "Code run when the diff process exits.
78492
7c8949dbfa0d Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78236
diff changeset
65 CODE is the exit code of the process. It should be 0 only if no diffs
7c8949dbfa0d Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78236
diff changeset
66 were found."
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
67 (if diff-old-temp-file (delete-file diff-old-temp-file))
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
68 (if diff-new-temp-file (delete-file diff-new-temp-file))
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
69 (save-excursion
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
70 (goto-char (point-max))
71248
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
71 (let ((inhibit-read-only t))
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
72 (insert (format "\nDiff finished%s. %s\n"
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
73 (if (equal 0 code) " (no differences)" "")
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
74 (current-time-string))))))
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
75
85686
a55a536ce0db * emulation/pc-select.el (next-line-mark, next-line-nomark)
Dan Nicolaescu <dann@ics.uci.edu>
parents: 82365
diff changeset
76 (defvar diff-old-file nil)
a55a536ce0db * emulation/pc-select.el (next-line-mark, next-line-nomark)
Dan Nicolaescu <dann@ics.uci.edu>
parents: 82365
diff changeset
77 (defvar diff-new-file nil)
a55a536ce0db * emulation/pc-select.el (next-line-mark, next-line-nomark)
Dan Nicolaescu <dann@ics.uci.edu>
parents: 82365
diff changeset
78 (defvar diff-extra-args nil)
a55a536ce0db * emulation/pc-select.el (next-line-mark, next-line-nomark)
Dan Nicolaescu <dann@ics.uci.edu>
parents: 82365
diff changeset
79
349
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 ;;;###autoload
47301
bac8aaf18835 (diff): Add optional argument no-async, and use the above argument.
Colin Walters <walters@gnu.org>
parents: 45472
diff changeset
81 (defun diff (old new &optional switches no-async)
349
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 "Find and display the differences between OLD and NEW files.
4759
5ca1f3073ffc (diff): Doc fix.
Brian Fox <bfox@gnu.org>
parents: 3874
diff changeset
83 Interactively the current buffer's file name is the default for NEW
894
41507a5a8fd7 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 881
diff changeset
84 and a backup file for NEW is the default for OLD.
53914
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
85 If NO-ASYNC is non-nil, call diff synchronously.
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
86 With prefix arg, prompt for diff switches."
349
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 (interactive
53914
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
88 (let (oldf newf)
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
89 (setq newf (buffer-file-name)
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
90 newf (if (and newf (file-exists-p newf))
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
91 (read-file-name
65680
ed770a0a7846 2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents: 64762
diff changeset
92 (concat "Diff new file (default "
ed770a0a7846 2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents: 64762
diff changeset
93 (file-name-nondirectory newf) "): ")
53914
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
94 nil newf t)
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
95 (read-file-name "Diff new file: " nil nil t)))
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
96 (setq oldf (file-newest-backup newf)
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
97 oldf (if (and oldf (file-exists-p oldf))
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
98 (read-file-name
65680
ed770a0a7846 2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents: 64762
diff changeset
99 (concat "Diff original file (default "
ed770a0a7846 2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents: 64762
diff changeset
100 (file-name-nondirectory oldf) "): ")
53914
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
101 (file-name-directory oldf) oldf t)
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
102 (read-file-name "Diff original file: "
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
103 (file-name-directory newf) nil t)))
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
104 (list oldf newf (diff-switches))))
349
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 (setq new (expand-file-name new)
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 old (expand-file-name old))
53917
04ab10f25d5c (diff): Simplify code handling `switch'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53916
diff changeset
107 (or switches (setq switches diff-switches)) ; If not specified, use default.
04ab10f25d5c (diff): Simplify code handling `switch'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53916
diff changeset
108 (let* ((old-alt (file-local-copy old))
1134
05c961416bb5 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 1112
diff changeset
109 (new-alt (file-local-copy new))
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
110 (command
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
111 (mapconcat 'identity
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
112 `(,diff-command
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
113 ;; Use explicitly specified switches
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
114 ,@(if (listp switches) switches (list switches))
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
115 ,@(if (or old-alt new-alt)
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
116 (list "-L" old "-L" new))
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
117 ,(shell-quote-argument (or old-alt old))
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
118 ,(shell-quote-argument (or new-alt new)))
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
119 " "))
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
120 (buf (get-buffer-create "*Diff*"))
55117
9ef081d74155 (diff): Set default-directory in diff buffer.
Andreas Schwab <schwab@suse.de>
parents: 53918
diff changeset
121 (thisdir default-directory)
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
122 proc)
15932
e4d0cf418b2b (diff): Don't pop to *diff* buffer. Change bogus
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
123 (save-excursion
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
124 (display-buffer buf)
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
125 (set-buffer buf)
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
126 (setq buffer-read-only nil)
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
127 (buffer-disable-undo (current-buffer))
71248
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
128 (let ((inhibit-read-only t))
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
129 (erase-buffer))
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
130 (buffer-enable-undo (current-buffer))
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
131 (diff-mode)
80857
b8d11546ac61 (diff): Use buffer-local vars diff-old-file and diff-new-file
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 75347
diff changeset
132 ;; Use below 2 vars for backward-compatibility.
b8d11546ac61 (diff): Use buffer-local vars diff-old-file and diff-new-file
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 75347
diff changeset
133 (set (make-local-variable 'diff-old-file) old)
b8d11546ac61 (diff): Use buffer-local vars diff-old-file and diff-new-file
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 75347
diff changeset
134 (set (make-local-variable 'diff-new-file) new)
b8d11546ac61 (diff): Use buffer-local vars diff-old-file and diff-new-file
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 75347
diff changeset
135 (set (make-local-variable 'diff-extra-args) (list switches no-async))
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
136 (set (make-local-variable 'revert-buffer-function)
80857
b8d11546ac61 (diff): Use buffer-local vars diff-old-file and diff-new-file
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 75347
diff changeset
137 (lambda (ignore-auto noconfirm)
b8d11546ac61 (diff): Use buffer-local vars diff-old-file and diff-new-file
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 75347
diff changeset
138 (apply 'diff diff-old-file diff-new-file diff-extra-args)))
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
139 (set (make-local-variable 'diff-old-temp-file) old-alt)
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
140 (set (make-local-variable 'diff-new-temp-file) new-alt)
55117
9ef081d74155 (diff): Set default-directory in diff buffer.
Andreas Schwab <schwab@suse.de>
parents: 53918
diff changeset
141 (setq default-directory thisdir)
71248
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
142 (let ((inhibit-read-only t))
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
143 (insert command "\n"))
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
144 (if (and (not no-async) (fboundp 'start-process))
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
145 (progn
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
146 (setq proc (start-process "Diff" buf shell-file-name
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
147 shell-command-switch command))
71248
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
148 (set-process-filter proc 'diff-process-filter)
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
149 (set-process-sentinel
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
150 proc (lambda (proc msg)
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
151 (with-current-buffer (process-buffer proc)
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
152 (diff-sentinel (process-exit-status proc))))))
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
153 ;; Async processes aren't available.
71248
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
154 (let ((inhibit-read-only t))
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
155 (diff-sentinel
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
156 (call-process shell-file-name nil buf nil
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
157 shell-command-switch command)))))
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
158 buf))
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 349
diff changeset
159
71248
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
160 (defun diff-process-filter (proc string)
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
161 (with-current-buffer (process-buffer proc)
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
162 (let ((moving (= (point) (process-mark proc))))
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
163 (save-excursion
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
164 ;; Insert the text, advancing the process marker.
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
165 (goto-char (process-mark proc))
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
166 (let ((inhibit-read-only t))
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
167 (insert string))
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
168 (set-marker (process-mark proc) (point)))
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
169 (if moving (goto-char (process-mark proc))))))
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
170
894
41507a5a8fd7 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 881
diff changeset
171 ;;;###autoload
41507a5a8fd7 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 881
diff changeset
172 (defun diff-backup (file &optional switches)
881
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
173 "Diff this file with its backup file or vice versa.
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
174 Uses the latest backup, if there are several numerical backups.
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
175 If this file is a backup, diff it with its original.
53914
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
176 The backup file is the first file given to `diff'.
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
177 With prefix arg, prompt for diff switches."
894
41507a5a8fd7 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 881
diff changeset
178 (interactive (list (read-file-name "Diff (file with backup): ")
53914
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
179 (diff-switches)))
881
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
180 (let (bak ori)
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
181 (if (backup-file-name-p file)
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
182 (setq bak file
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
183 ori (file-name-sans-versions file))
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
184 (setq bak (or (diff-latest-backup-file file)
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
185 (error "No backup found for %s" file))
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
186 ori file))
894
41507a5a8fd7 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 881
diff changeset
187 (diff bak ori switches)))
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 349
diff changeset
188
881
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
189 (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
190 "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
191 (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
192 (if handler
6321
8c667dc4566e (diff-latest-backup-file): Call file name handler properly.
Richard M. Stallman <rms@gnu.org>
parents: 6147
diff changeset
193 (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
194 (file-newest-backup fn))))
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 349
diff changeset
195
2541
09e58f572f19 (diff-parse-differences): Small robustification --- don't lose if we
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2307
diff changeset
196 (provide 'diff)
09e58f572f19 (diff-parse-differences): Small robustification --- don't lose if we
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2307
diff changeset
197
80857
b8d11546ac61 (diff): Use buffer-local vars diff-old-file and diff-new-file
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 75347
diff changeset
198 ;; arch-tag: 7de2c29b-7ea5-4b85-9b9d-72dd860de2bd
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 474
diff changeset
199 ;;; diff.el ends here