annotate lisp/vc/diff.el @ 112453:06719a229a46 default tip

* calc/calc.el (calc-default-power-reference-level) (calc-default-field-reference-level): New variables. * calc/calc-units.el (math-standard-units): Add dB and Np. (math-logunits): New variable. (math-extract-logunits, math-logcombine, calcFunc-luplus) (calcFunc-luminus, calc-luplus, calc-luminus, math-logunit-level) (calcFunc-fieldlevel, calcFunc-powerlevel, calc-level): New functions. (math-find-base-units-rec): Add entry for ln(10). * calc/calc-help.el (calc-u-prefix-help): Add logarithmic help. (calc-ul-prefix-help): New function. * calc/calc-ext.el (calc-init-extensions): Autoload new units functions. Add keybindings for new units functions.
author Jay Belanger <jay.p.belanger@gmail.com>
date Sun, 23 Jan 2011 23:08:04 -0600
parents 5653bdbb0b32
children
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
101092
d7a34bb56274 Comment (add Author:, based on authors.el).
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
3 ;; Copyright (C) 1992, 1994, 1996, 2001, 2002, 2003, 2004, 2005, 2006,
112228
417b1e4d63cd Merge from emacs-23
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111999
diff changeset
4 ;; 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
894
41507a5a8fd7 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 881
diff changeset
5
101092
d7a34bb56274 Comment (add Author:, based on authors.el).
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
6 ;; Author: Frank Bresz
d7a34bb56274 Comment (add Author:, based on authors.el).
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
7 ;; (according to authors.el)
38697
a19197c6442f Keyword added and FSF specified as Maintainer.
Pavel Janík <Pavel@Janik.cz>
parents: 38414
diff changeset
8 ;; Maintainer: FSF
108971
d928a6a7c3f2 * lisp/finder.el (finder-known-keywords): Add keyword "vc"
Juri Linkov <juri@jurta.org>
parents: 108970
diff changeset
9 ;; Keywords: unix, vc, tools
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 669
diff changeset
10
349
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
349
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
15 ;; the Free Software Foundation, either version 3 of the License, or
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
16 ;; (at your option) any later version.
349
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 ;; GNU General Public License for more details.
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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
111676
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
34 (eval-when-compile (require 'cl))
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
35
18143
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
36 (defgroup diff nil
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
37 "Comparing files with `diff'."
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
38 :group 'tools)
894
41507a5a8fd7 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 881
diff changeset
39
18143
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
40 ;;;###autoload
105939
a0f778f4a995 * term/x-win.el (x-gtk-stock-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 101092
diff changeset
41 (defcustom diff-switches (purecopy "-c")
100171
d42aff5ca541 * align.el:
Lute Kamstra <lute@gnu.org>
parents: 99893
diff changeset
42 "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
43 :type '(choice string (repeat string))
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
44 :group 'diff)
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
45
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
46 ;;;###autoload
105939
a0f778f4a995 * term/x-win.el (x-gtk-stock-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 101092
diff changeset
47 (defcustom diff-command (purecopy "diff")
100171
d42aff5ca541 * align.el:
Lute Kamstra <lute@gnu.org>
parents: 99893
diff changeset
48 "The command to use to run diff."
18150
960597385f1c (diff-command): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 18143
diff changeset
49 :type 'string
18143
3584a8182767 Customize.
Richard M. Stallman <rms@gnu.org>
parents: 17732
diff changeset
50 :group 'diff)
9736
093d80b4ae17 (diff-command): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8195
diff changeset
51
53914
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
52 ;; prompt if prefix arg present
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
53 (defun diff-switches ()
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
54 (if current-prefix-arg
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
55 (read-string "Diff switches: "
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
56 (if (stringp diff-switches)
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
57 diff-switches
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
58 (mapconcat 'identity diff-switches " ")))))
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
59
111797
b2c5606310f5 diff-sentinel trivia.
Glenn Morris <rgm@gnu.org>
parents: 111714
diff changeset
60 (defun diff-sentinel (code &optional old-temp-file new-temp-file)
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
61 "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
62 CODE is the exit code of the process. It should be 0 only if no diffs
112428
5653bdbb0b32 * vc/diff.el (diff-sentinel): Doc fix (Bug#7682).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
63 were found.
5653bdbb0b32 * vc/diff.el (diff-sentinel): Doc fix (Bug#7682).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
64 If optional args OLD-TEMP-FILE and/or NEW-TEMP-FILE are non-nil,
5653bdbb0b32 * vc/diff.el (diff-sentinel): Doc fix (Bug#7682).
Chong Yidong <cyd@stupidchicken.com>
parents: 112228
diff changeset
65 delete the temporary files so named."
111676
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
66 (if old-temp-file (delete-file old-temp-file))
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
67 (if new-temp-file (delete-file new-temp-file))
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
68 (save-excursion
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
69 (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
70 (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
71 (insert (format "\nDiff finished%s. %s\n"
99893
34f4c0ab1342 (diff-sentinel): Take note of diff error return value.
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
72 (cond ((equal 0 code) " (no differences)")
34f4c0ab1342 (diff-sentinel): Take note of diff error return value.
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
73 ((equal 2 code) " (diff error)")
34f4c0ab1342 (diff-sentinel): Take note of diff error return value.
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
74 (t ""))
71248
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
75 (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
76
349
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 ;;;###autoload
47301
bac8aaf18835 (diff): Add optional argument no-async, and use the above argument.
Colin Walters <walters@gnu.org>
parents: 45472
diff changeset
78 (defun diff (old new &optional switches no-async)
349
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 "Find and display the differences between OLD and NEW files.
100729
e60cb7984ff1 (diff): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 100171
diff changeset
80 When called interactively, read OLD and NEW using the minibuffer;
e60cb7984ff1 (diff): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 100171
diff changeset
81 the default for NEW is the current buffer's file name, and the
e60cb7984ff1 (diff): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 100171
diff changeset
82 default for OLD is a backup file for NEW, if one exists.
53914
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
83 If NO-ASYNC is non-nil, call diff synchronously.
100729
e60cb7984ff1 (diff): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 100171
diff changeset
84
e60cb7984ff1 (diff): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 100171
diff changeset
85 When called interactively with a prefix argument, prompt
e60cb7984ff1 (diff): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 100171
diff changeset
86 interactively for diff switches. Otherwise, the switches
e60cb7984ff1 (diff): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 100171
diff changeset
87 specified in `diff-switches' are passed to the diff command."
349
feacf757c5b2 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 (interactive
111714
157b25217077 * diff.el (diff): Fix it for good, hopefully, this time.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111707
diff changeset
89 (let* ((newf (if (and buffer-file-name (file-exists-p buffer-file-name))
53914
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
90 (read-file-name
65680
ed770a0a7846 2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents: 64762
diff changeset
91 (concat "Diff new file (default "
111714
157b25217077 * diff.el (diff): Fix it for good, hopefully, this time.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111707
diff changeset
92 (file-name-nondirectory buffer-file-name) "): ")
157b25217077 * diff.el (diff): Fix it for good, hopefully, this time.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111707
diff changeset
93 nil buffer-file-name t)
53914
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
94 (read-file-name "Diff new file: " nil nil t)))
111714
157b25217077 * diff.el (diff): Fix it for good, hopefully, this time.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111707
diff changeset
95 (oldf (file-newest-backup newf)))
111676
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
96 (setq oldf (if (and oldf (file-exists-p oldf))
53914
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
97 (read-file-name
65680
ed770a0a7846 2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents: 64762
diff changeset
98 (concat "Diff original file (default "
ed770a0a7846 2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents: 64762
diff changeset
99 (file-name-nondirectory oldf) "): ")
53914
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
100 (file-name-directory oldf) oldf t)
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
101 (read-file-name "Diff original file: "
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
102 (file-name-directory newf) nil t)))
0ceb9e9ae2b0 (diff-switches): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52894
diff changeset
103 (list oldf newf (diff-switches))))
111676
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
104 (display-buffer
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
105 (diff-no-select old new switches no-async)))
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
106
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
107 (defun diff-file-local-copy (file-or-buf)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
108 (if (bufferp file-or-buf)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
109 (with-current-buffer file-or-buf
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
110 (let ((tempfile (make-temp-file "buffer-content-")))
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
111 (write-region nil nil tempfile nil 'nomessage)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
112 tempfile))
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
113 (file-local-copy file-or-buf)))
111673
a8aaa73f87fa * lisp/files.el: Make revert work with diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 108971
diff changeset
114
111676
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
115 (defun diff-no-select (old new &optional switches no-async buf)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
116 ;; Noninteractive helper for creating and reverting diff buffers
111999
1c6bd016193a Fix 2010-11-22 change to diff.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 111797
diff changeset
117 (unless (bufferp new) (setq new (expand-file-name new)))
1c6bd016193a Fix 2010-11-22 change to diff.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 111797
diff changeset
118 (unless (bufferp old) (setq old (expand-file-name old)))
53917
04ab10f25d5c (diff): Simplify code handling `switch'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53916
diff changeset
119 (or switches (setq switches diff-switches)) ; If not specified, use default.
111676
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
120 (unless (listp switches) (setq switches (list switches)))
111673
a8aaa73f87fa * lisp/files.el: Make revert work with diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 108971
diff changeset
121 (or buf (setq buf (get-buffer-create "*Diff*")))
111676
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
122 (let* ((old-alt (diff-file-local-copy old))
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
123 (new-alt (diff-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
124 (command
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
125 (mapconcat 'identity
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
126 `(,diff-command
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
127 ;; Use explicitly specified switches
111676
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
128 ,@switches
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
129 ,@(mapcar #'shell-quote-argument
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
130 (nconc
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
131 (when (or old-alt new-alt)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
132 (list "-L" (if (stringp old)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
133 old (prin1-to-string old))
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
134 "-L" (if (stringp new)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
135 new (prin1-to-string new))))
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
136 (list (or old-alt old)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
137 (or new-alt new)))))
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
138 " "))
111676
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
139 (thisdir default-directory))
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
140 (with-current-buffer buf
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
141 (setq buffer-read-only t)
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
142 (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
143 (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
144 (erase-buffer))
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
145 (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
146 (diff-mode)
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
147 (set (make-local-variable 'revert-buffer-function)
111676
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
148 (lexical-let ((old old) (new new)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
149 (switches switches)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
150 (no-async no-async))
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
151 (lambda (ignore-auto noconfirm)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
152 (diff-no-select old new switches no-async (current-buffer)))))
55117
9ef081d74155 (diff): Set default-directory in diff buffer.
Andreas Schwab <schwab@suse.de>
parents: 53918
diff changeset
153 (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
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 (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
156 (if (and (not no-async) (fboundp 'start-process))
111676
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
157 (let ((proc (start-process "Diff" buf shell-file-name
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
158 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
159 (set-process-filter proc 'diff-process-filter)
111676
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
160 (lexical-let ((old-alt old-alt) (new-alt new-alt))
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
161 (set-process-sentinel
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
162 proc (lambda (proc msg)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
163 (with-current-buffer (process-buffer proc)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
164 (diff-sentinel (process-exit-status proc)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
165 old-alt new-alt))))))
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
166 ;; 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
167 (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
168 (diff-sentinel
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
169 (call-process shell-file-name nil buf nil
111676
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
170 shell-command-switch command)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
171 old-alt new-alt))))
53918
3619e67b00f4 Don't use compile any more, use diff-mode instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53917
diff changeset
172 buf))
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 349
diff changeset
173
71248
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
174 (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
175 (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
176 (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
177 (save-excursion
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
178 ;; 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
179 (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
180 (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
181 (insert string))
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
182 (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
183 (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
184
894
41507a5a8fd7 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 881
diff changeset
185 ;;;###autoload
41507a5a8fd7 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 881
diff changeset
186 (defun diff-backup (file &optional switches)
881
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
187 "Diff this file with its backup file or vice versa.
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
188 Uses the latest backup, if there are several numerical backups.
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
189 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
190 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
191 With prefix arg, prompt for diff switches."
894
41507a5a8fd7 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 881
diff changeset
192 (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
193 (diff-switches)))
881
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
194 (let (bak ori)
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
195 (if (backup-file-name-p file)
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
196 (setq bak file
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
197 ori (file-name-sans-versions file))
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
198 (setq bak (or (diff-latest-backup-file file)
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
199 (error "No backup found for %s" file))
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
200 ori file))
894
41507a5a8fd7 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 881
diff changeset
201 (diff bak ori switches)))
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 349
diff changeset
202
881
945558e05127 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
203 (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
204 "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
205 (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
206 (if handler
6321
8c667dc4566e (diff-latest-backup-file): Call file name handler properly.
Richard M. Stallman <rms@gnu.org>
parents: 6147
diff changeset
207 (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
208 (file-newest-backup fn))))
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 349
diff changeset
209
111676
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
210 ;;;###autoload
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
211 (defun diff-buffer-with-file (&optional buffer)
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
212 "View the differences between BUFFER and its associated file.
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
213 This requires the external program `diff' to be in your `exec-path'."
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
214 (interactive "bBuffer: ")
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
215 (with-current-buffer (get-buffer (or buffer (current-buffer)))
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
216 (diff buffer-file-name (current-buffer) nil 'noasync)))
7b1a21c5033e Cleanup diff-buffer-with-file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 111673
diff changeset
217
2541
09e58f572f19 (diff-parse-differences): Small robustification --- don't lose if we
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2307
diff changeset
218 (provide 'diff)
09e58f572f19 (diff-parse-differences): Small robustification --- don't lose if we
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2307
diff changeset
219
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 474
diff changeset
220 ;;; diff.el ends here