comparison lisp/packages/diff.el @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children 4103f0995bd7
comparison
equal deleted inserted replaced
1:c0c6a60d29db 2:ac2d302a0011
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details. 17 ;; General Public License for more details.
18 18
19 ;; You should have received a copy of the GNU General Public License 19 ;; You should have received a copy of the GNU General Public License
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free 20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
21 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 22 ;; 02111-1307, USA.
23 ;;; Synched up with: FSF 19.30. 23
24 ;;; Synched up with: FSF 19.34.
24 25
25 ;;; Commentary: 26 ;;; Commentary:
26 27
27 ;; This package helps you explore differences between files, using the 28 ;; This package helps you explore differences between files, using the
28 ;; UNIX command diff(1). The commands are `diff' and `diff-backup'. 29 ;; UNIX command diff(1). The commands are `diff' and `diff-backup'.
33 (require 'compile) 34 (require 'compile)
34 35
35 ;;; This is duplicated in vc.el. 36 ;;; This is duplicated in vc.el.
36 ;;;###autoload 37 ;;;###autoload
37 (defvar diff-switches (purecopy "-c") 38 (defvar diff-switches (purecopy "-c")
38 "*A string or list of strings specifying switches to be be passed to diff.") 39 "*A string or list of strings specifying switches to be passed to diff.")
39 40
40 (defvar diff-command "diff" 41 (defvar diff-command "diff"
41 "*The command to use to run diff.") 42 "*The command to use to run diff.")
42 43
43 (defvar diff-regexp-alist 44 (defvar diff-regexp-alist
44 '( 45 '(
45 ;; -u format: @@ -OLDSTART,OLDEND +NEWSTART,NEWEND @@ 46 ;; -u format: @@ -OLDSTART,OLDEND +NEWSTART,NEWEND @@
46 ("^@@ -\\([0-9]+\\),[0-9]+ \\+\\([0-9]+\\),[0-9]+ @@$" 1 2) 47 ("^@@ -\\([0-9]+\\),[0-9]+ \\+\\([0-9]+\\),[0-9]+ @@$" 1 2)
47 48
48 ;; -c format: *** OLDSTART,OLDEND **** 49 ;; -c format: *** OLDSTART,OLDEND ****
49 ("^\\*\\*\\* \\([0-9]+\\),[0-9]+ \\*\\*\\*\\*$" 1 nil) 50 ("^\\*\\*\\* \\([0-9]+\\),[0-9]+ \\*\\*\\*\\*$" 1 nil)
50 ;; --- NEWSTART,NEWEND ---- 51 ;; --- NEWSTART,NEWEND ----
51 ("^--- \\([0-9]+\\),[0-9]+ ----$" nil 1) 52 ("^--- \\([0-9]+\\),[0-9]+ ----$" nil 1)
52 53
58 59
59 ;; -f format: {a,d,c}OLDSTART[ OLDEND] 60 ;; -f format: {a,d,c}OLDSTART[ OLDEND]
60 ;; -n format: {a,d,c}OLDSTART LINES-CHANGED 61 ;; -n format: {a,d,c}OLDSTART LINES-CHANGED
61 ("^[adc]\\([0-9]+\\)\\( [0-9]+\\)?$" 1) 62 ("^[adc]\\([0-9]+\\)\\( [0-9]+\\)?$" 1)
62 ) 63 )
63 "Alist (REGEXP OLD-IDX NEW-IDX) of regular expressions to match difference 64 "Alist (REGEXP OLD-IDX NEW-IDX) of regular expressions to match difference
64 sections in \\[diff] output. If REGEXP matches, the OLD-IDX'th 65 sections in \\[diff] output. If REGEXP matches, the OLD-IDX'th
65 subexpression gives the line number in the old file, and NEW-IDX'th 66 subexpression gives the line number in the old file, and NEW-IDX'th
66 subexpression gives the line number in the new file. If OLD-IDX or NEW-IDX 67 subexpression gives the line number in the new file. If OLD-IDX or NEW-IDX
67 is nil, REGEXP matches only half a section.") 68 is nil, REGEXP matches only half a section.")
68 69
119 (buffer-substring 120 (buffer-substring
120 (match-beginning subexpr) 121 (match-beginning subexpr)
121 (match-end subexpr))))) 122 (match-end subexpr)))))
122 (save-excursion 123 (save-excursion
123 (save-match-data 124 (save-match-data
124 (set-buffer (find-file-noselect file))) 125 (set-buffer (find-file-noselect file)))
125 (save-excursion 126 (save-excursion
126 (goto-line line) 127 (goto-line line)
127 (point-marker))))) 128 (point-marker)))))
128 compilation-error-list))))) 129 compilation-error-list)))))
129 130
230 (setq buf 231 (setq buf
231 (compile-internal command 232 (compile-internal command
232 "No more differences" "Diff" 233 "No more differences" "Diff"
233 'diff-parse-differences)) 234 'diff-parse-differences))
234 (pop-to-buffer buf) 235 (pop-to-buffer buf)
236 ;; Avoid frightening people with "abnormally terminated"
237 ;; if diff finds differences.
238 (set (make-local-variable 'compilation-exit-message-function)
239 (lambda (status code msg)
240 (cond ((not (eq status 'exit))
241 (cons msg code))
242 ((zerop code)
243 '("finished (no differences)\n" . "no differences"))
244 ((= code 1)
245 '("finished\n" . "differences found"))
246 (t
247 (cons msg code)))))
235 (set (make-local-variable 'diff-old-file) old) 248 (set (make-local-variable 'diff-old-file) old)
236 (set (make-local-variable 'diff-new-file) new) 249 (set (make-local-variable 'diff-new-file) new)
237 (set (make-local-variable 'diff-old-temp-file) old-alt) 250 (set (make-local-variable 'diff-old-temp-file) old-alt)
238 (set (make-local-variable 'diff-new-temp-file) new-alt) 251 (set (make-local-variable 'diff-new-temp-file) new-alt)
239 (set (make-local-variable 'compilation-finish-function) 252 (set (make-local-variable 'compilation-finish-function)