annotate lisp/packages/diff.el @ 104:cf808b4c4290 r20-1b4

Import from CVS: tag r20-1b4
author cvs
date Mon, 13 Aug 2007 09:16:51 +0200
parents 4be1180a9e89
children fe104dbd9147
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
1 ;; -*-Emacs-Lisp-*-
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
3 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
4 ;; File: diff.el
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 100
diff changeset
5 ;; Version: $Revision: 1.3 $
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
6 ;; Author: This file is based on diff.el by
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
7 ;; sunpitt!wpmstr!fbresz@Sun.COM 1/27/89.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
8 ;; It has been completely rewritten in July 1994 by
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
9 ;; Sandy Rutherford <sandy@ibm550.sissa.it>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
10 ;; RCS:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
11 ;; Description: diff-mode for handling output from unix diff utility.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
12 ;; Modified: Wed Jul 17 10:26:57 1996 (Andy Norman) ange@hplb.hpl.hp.com
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
13 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
14 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
16 ;;; Copyright (C) 1990 Free Software Foundation, Inc.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
17 ;;; Copyright (C) 1994 Sandy Rutherford
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
19 ;;; This file is based on diff.el by sunpitt!wpmstr!fbresz@Sun.COM 1/27/89.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
20 ;;; It has been completely rewritten in July 1994 by
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
21 ;;; Sandy Rutherford <sandy@ibm550.sissa.it>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
23 ;;; This program is free software; you can redistribute it and/or modify
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
24 ;;; it under the terms of the GNU General Public License as published by
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
25 ;;; the Free Software Foundation; either version 1, or (at your option)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
26 ;;; any later version.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
27 ;;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
28 ;;; This program is distributed in the hope that it will be useful,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
29 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
30 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
31 ;;; GNU General Public License for more details.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
32 ;;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
33 ;;; A copy of the GNU General Public License can be obtained from this
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
34 ;;; program's author (send electronic mail to sandy@ibm550.sissa.it) or
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
35 ;;; from the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
36 ;;; MA 02139, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
38 (provide 'diff)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
40 ;;; User Variables
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 32
diff changeset
41
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
42 ;; should be in to loaddefs.el now.
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 100
diff changeset
43 ;;;###autoload
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
44 (defvar diff-switches nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
45 "*A list of switches (strings) to pass to the diff program.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
47 (defvar diff-do-narrow nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
48 "*If non-nil diff buffers are initialized narrowed to each difference.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
50 (defvar diff-load-hooks nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
51 "Hooks to run after loading diff.el")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
52
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
53 ;;; Internal variables
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
54
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
55 (defconst diff-emacs-19-p
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
56 (let ((ver (string-to-int (substring emacs-version 0 2))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
57 (>= ver 19)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
59 (or diff-emacs-19-p (require 'emacs-19))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
61 (defvar diff-old-file nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
62 ;; A list whose car is the name of the old file, and whose cdr indicates
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
63 ;; whether we should delete the buffer on quit.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
64 (defvar diff-new-file nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
65 ;; Same as diff-old-file, except for the new file.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
66 (defvar diff-total-differences "0")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
67 ;; Total number of difference hunks as a string.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
68 (defvar diff-current-difference "0")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
69 ;; Current difference hunk as a string.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
70 (defvar diff-current-hunk 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
71 ;; Current difference hunk as an integer.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
72 (defvar diff-total-hunks 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
73 ;; Total number of difference hunks as an integer.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
74 (defvar diff-hunk-vector (vector 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
75 ;; Vector storing the starting positions of the difference hunks.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
76 (defvar diff-old-file-pattern nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
77 (defvar diff-new-file-pattern nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
78 (defvar diff-hunk-pattern nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
79 ;; Regexps to use when parsing file lines in difference hunks.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
81
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
82 (defvar diff-search-pattern-alist
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
83 (list
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
84 (list ?e "^[0-9]\\(,[0-9]+\\)?[acd]$" "^\\([0-9]+\\)" nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
85 (list ?c "^\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\n"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
86 "^\\*+ \\([0-9]+\\)" "^-+ \\([0-9]+\\)")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
87 (list ?u "^@@ " "^@@ -\\([0-9]+\\)" "^@@ -[0-9,]+ \\+\\([0-9]+\\)")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
88 (list nil "^[0-9]+" "^\\([0-9]+\\)" "^[0-9,]+[acd]\\([0-9]+\\)")))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
90 (defvar diff-keymap-grokked nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
91
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
92 (defvar diff-temp-template "/tmp/diff")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
94 ;; Initialize the keymap if it isn't already
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
95
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
96 (defvar diff-mode-map nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
97 "Keymap used in diff mode.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
99 (if diff-mode-map
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
100 nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
101 (setq diff-mode-map (make-keymap))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
102 (suppress-keymap diff-mode-map)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
103 (define-key diff-mode-map "?" 'describe-mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
104 (define-key diff-mode-map "." 'diff-display-file)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
105 (define-key diff-mode-map "N" 'diff-narrow)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
106 (define-key diff-mode-map "W" 'widen)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
107 (define-key diff-mode-map "f" 'diff-find-file)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
108 (define-key diff-mode-map "h" 'diff-show-header)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
109 (define-key diff-mode-map "j" 'diff-show-difference)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
110 (define-key diff-mode-map "n" 'diff-next-difference)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
111 (define-key diff-mode-map "o" 'diff-find-file-other-window)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
112 (define-key diff-mode-map "p" 'diff-previous-difference)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
113 (define-key diff-mode-map "q" 'diff-quit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
114 (define-key diff-mode-map "w" 'diff-find-file-other-frame)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
115 (define-key diff-mode-map "\C-c\C-c" 'diff-find-file-other-window)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
116 (define-key diff-mode-map " " 'diff-advertised-scroll-up)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
117 (define-key diff-mode-map "\177" 'diff-advertised-scroll-down)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
118 (define-key diff-mode-map "\C-n" 'diff-next-line)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
119 (define-key diff-mode-map "\C-p" 'diff-previous-line)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
120 (define-key diff-mode-map "\M->" 'diff-end-of-buffer)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
121 (define-key diff-mode-map "\M-<" 'diff-beginning-of-buffer))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
122
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
123 ;;; Internal functions
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
125 (defun diff-grok-keys (to-command from-command)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
126 ;; Assigns to TO-COMMAND the keys for the global binding of FROM-COMMAND.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
127 ;; Does not clobber anything in the local keymap.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
128 (let ((keys (where-is-internal from-command)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
129 (while keys
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
130 (condition-case nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
131 (if (eq (global-key-binding (car keys)) (key-binding (car keys)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
132 (local-set-key (car keys) to-command))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
133 (error nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
134 (setq keys (cdr keys)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
135
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
136 (defun diff-grok-keymap ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
137 (if diff-keymap-grokked
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
138 ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
139 (if (and term-setup-hook (boundp 'command-line-args-left))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
140 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
141 (if diff-emacs-19-p
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
142 (run-hooks term-setup-hook)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
143 (funcall term-setup-hook))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
144 (setq term-setup-hook nil)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
145 (setq diff-keymap-grokked t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
146 (diff-grok-keys 'diff-next-line 'next-line)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
147 (diff-grok-keys 'diff-previous-line 'previous-line)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
148 (diff-grok-keys 'diff-forward-char 'forward-char)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
149 (diff-grok-keys 'diff-backward-char 'backward-char)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
150 (diff-grok-keys 'diff-scroll-up 'scroll-up)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
151 (diff-grok-keys 'diff-scroll-down 'scroll-down)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
152 (diff-grok-keys 'diff-beginning-of-buffer 'beginning-of-buffer)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
153 (diff-grok-keys 'diff-end-of-buffer 'end-of-buffer)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
155 (defun diff-buffer-narrowed-p ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
156 ;; Returns t if the current buffer is narrowed
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
157 (save-restriction
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
158 (let ((min (point-min))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
159 (max (point-max)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
160 (widen)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
161 (not (and (= min (point-min)) (= max (point-max)))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
163 (defun diff-current-hunk ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
164 ;; Returns the current diff hunk.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
165 (let ((pt (point))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
166 (start 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
167 (end (1+ diff-total-hunks))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
168 m)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
169 (while (> (- end start) 1)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
170 (setq m (/ (+ start end) 2))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
171 (if (>= pt (aref diff-hunk-vector m))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
172 (setq start m)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
173 (setq end m)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
174 (if (>= pt (aref diff-hunk-vector end))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
175 (setq m end)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
176 (setq m start))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
177 ;; Don't treat end of buffer as start of next hunk
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
178 (if (eobp) (1- m) m)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
180 (defun diff-hunk-min (n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
181 ;; Returns the start of the current diff hunk.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
182 (aref diff-hunk-vector n))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
183
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
184 (defun diff-hunk-max (n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
185 ;; Returns the end of the current diff hunk.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
186 (aref diff-hunk-vector (1+ n)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
188 (defun diff-parse-hunks ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
189 ;; Parses a buffer of diff output.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
190 (save-excursion
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
191 (save-restriction
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
192 (message "Parsing differences...")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
193 (widen)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
194 (goto-char (point-min))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
195 (let ((hunks (list 1)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
196 (while (re-search-forward diff-hunk-pattern nil t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
197 (setq hunks (cons (match-beginning 0) hunks)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
198 (setq diff-total-hunks (1- (length hunks))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
199 diff-hunk-vector (apply 'vector
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
200 (nreverse (cons (point-max) hunks)))))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
201 (message "Parsing differences...done"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
203 (defun diff-update-modeline ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
204 ;; Updates the mode line to show current diff hunk.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
205 (if (or (< (point) (diff-hunk-min diff-current-hunk))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
206 (>= (point) (diff-hunk-max diff-current-hunk)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
207 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
208 (setq diff-current-hunk (diff-current-hunk)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
209 diff-current-difference (int-to-string diff-current-hunk))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
210 (set-buffer-modified-p (buffer-modified-p)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
211
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
212 (defun diff-read-args (oldprompt newprompt switchprompt
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
213 &optional file-for-backup)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
214 ;; Grab the args for diff. OLDPROMPT and NEWPROMPT are the prompts
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
215 ;; for the old & new filenames, SWITCHPROMPT for the list of
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
216 ;; switches. If FILE_FOR_BACKUP is provided (it must be a string if
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
217 ;; so), then it will be used to try & work out a file & backup to
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
218 ;; diff, & in this case the prompting order is backwards. %s in a
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
219 ;; prompt has a guess substituted into it. This is nasty.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
220 (let (oldf newf)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
221 (if file-for-backup
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
222 (setq newf file-for-backup
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 newf (if (and newf (file-exists-p newf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (read-file-name
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
225 (format newprompt (file-name-nondirectory newf))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 nil newf t)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
227 (read-file-name (format newprompt "") nil nil t))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
228 oldf (file-newest-backup newf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 oldf (if (and oldf (file-exists-p oldf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (read-file-name
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
231 (format oldprompt (file-name-nondirectory oldf))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
232 nil oldf t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
233 (read-file-name (format oldprompt "")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
234 (file-name-directory newf) nil t)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
235 ;; Else we aren't trying to be bright...
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
236 (setq oldf (read-file-name (format oldprompt "") nil nil t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
237 newf (read-file-name
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
238 (format newprompt (file-name-nondirectory oldf))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
239 nil (file-name-directory oldf) t)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
240 (list oldf newf (diff-read-switches switchprompt))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
241
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
242 (defun diff-read-switches (switchprompt)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
243 ;; Read and return a list of switches
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
244 (if current-prefix-arg
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
245 (let ((default (if (listp diff-switches)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
246 (mapconcat 'identity diff-switches " ")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
247 diff-switches)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
248 (diff-fix-switches
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
249 (read-string (format switchprompt default) default)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
250
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
251 (defun diff-fix-switches (switch-spec)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
252 ;; Parse a string into a list of switches or leave it be if it's
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
253 ;; not a string
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
254 (if (stringp switch-spec)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
255 (let (result (start 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
256 (while (string-match "\\(\\S-+\\)" switch-spec start)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
257 (setq result (cons (substring switch-spec (match-beginning 1)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
258 (match-end 1))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
259 result)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
260 start (match-end 0)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
261 (nreverse result))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
262 switch-spec))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
264 (defun diff-get-file-buffer (file)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
265 ;; Returns \(BUFFER . DEL-P\), where DEL-P is t if diff is expected
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
266 ;; to delete the buffer, and nil otherwise.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
267 (let* ((buff (get-file-buffer file))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
268 (del-p (null buff)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
269 (if (and buff (buffer-modified-p buff))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
270 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
271 (message
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
272 "Buffer %s is modified. Diffing against buffer contents."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
273 (buffer-name buff))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
274 (sit-for 1)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
275 ;; Call find-file-noselect even if we already have the buffer,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
276 ;; as it will run verify-buffer-file-modtime.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
277 (cons (find-file-noselect file) del-p)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
279 (defun diff-cleanup-buffers ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
280 ;; Cleans up diff buffers by deleting buffers that we don't expect
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
281 ;; the user to care about.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
282 (let ((files (list diff-old-file diff-new-file)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
283 (while files
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
284 (let ((ent (car files))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
285 buff)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
286 (and (cdr ent)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
287 (setq buff (get-file-buffer (car ent)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
288 (not (buffer-modified-p buff))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
289 (kill-buffer buff)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
290 (setq files (cdr files)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
291 (if (get-buffer "*Diff Header*")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
292 (kill-buffer "*Diff Header*"))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
293
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
294 (defun diff-latest-backup-file (file)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 "Return the latest existing backup of FILE, or nil."
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
296 ;; First try simple backup, then the highest numbered of the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
297 ;; numbered backups.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
298 ;; Ignore the value of version-control because we look for existing
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
299 ;; backups, which maybe were made earlier or by another user with
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
300 ;; a different value of version-control.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
301 (let* ((file (expand-file-name file))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
302 (handler (find-file-name-handler file 'diff-latest-backup-file)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (if handler
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
304 (funcall handler 'diff-latest-backup-file file)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (or
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
306 (let ((bak (make-backup-file-name file)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (if (file-exists-p bak) bak))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
308 (let* ((dir (file-name-directory file))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
309 (base-versions (concat (file-name-nondirectory file) ".~"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (bv-length (length base-versions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (concat dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (car (sort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (file-name-all-completions base-versions dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 ;; bv-length is a fluid var for backup-extract-version:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (lambda (fn1 fn2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (> (backup-extract-version fn1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (backup-extract-version fn2))))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
320 (defun diff-file-line (&optional old-file-p)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
321 "Return line number of current hunk in `diff-new-file'.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
322 With optional argument OLD-FILE-P, use `diff-old-file' instead."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
323 (save-excursion
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
324 (let ((min (diff-hunk-min diff-current-hunk))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
325 (max (diff-hunk-max diff-current-hunk))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
326 (regexp (if old-file-p diff-old-file-pattern diff-new-file-pattern)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
327 (goto-char min)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
328 (or (and regexp (re-search-forward regexp max t))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
329 (error "Unable to locate a file line for %s file."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
330 (if old-file-p "old" "new")))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
331 (string-to-int (buffer-substring (match-beginning 1) (match-end 1))))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
332
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
333 (defun diff-run-diff (switches old old-temp new new-temp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
334 ;; Actually run the diff process with SWITCHES on OLD and NEW.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
335 ;; OLD-TEMP and NEW-TEMP are names of temp files that can be used
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
336 ;; to dump the data out to.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
337 (insert "diff " (mapconcat 'identity switches " ") " " old
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
338 " " new "\n")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
339 (apply 'call-process "diff" nil t nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
340 (append switches (list old-temp new-temp))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
341
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
342
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
343 (defun diff-fix-file-names (old old-temp new new-temp pattern)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
344 ;; Replaces any temp file names with the real names of files.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
345 (save-excursion
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
346 (save-restriction
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
347 (let ((files (list old new))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
348 (temps (list old-temp new-temp))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
349 buffer-read-only case-fold-search)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
350 (goto-char (point-min))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
351 (if (re-search-forward pattern nil t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
352 (narrow-to-region (point-min) (match-beginning 0)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
353 (while files
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
354 (let ((regexp (concat "[ \t\n]\\("
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
355 (regexp-quote (car temps))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
356 "\\)[ \t\n]")))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
357 (goto-char (point-min))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
358 (forward-line 1)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
359 (while (re-search-forward regexp nil t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
360 (goto-char (match-beginning 1))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
361 (delete-region (point) (match-end 1))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
362 (insert (car files))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
363 (setq files (cdr files)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
364 temps (cdr temps)))))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
365
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
366 ;;;; User commands
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
367
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
368 (defun diff-mode ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
369 "Diff Mode is used by \\[diff] for perusing the output from the diff program.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
370 All normal editing commands are turned off. Instead, these are available:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
371 \\<diff-mode-map>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
372 \\[diff-advertised-scroll-up] Scroll to next screen of this difference.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
373 \\[diff-advertised-scroll-down] Scroll to previous screen of this difference.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
374 \\[diff-next-difference] Move to Next Difference.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
375 \\[diff-previous-difference] Move to Previous Difference.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
376 \\[diff-show-difference] Jump to difference specified by numeric position.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
377 \\[diff-find-file] Find current diff in file
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
378 \\[diff-find-file-other-window] Find current diff in file in other window
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
379 \\[diff-display-file] Display file in other window
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
380 \\[diff-narrow] Narrow diff buffer to current difference
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
381 \\[widen] Widen diff buffer
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
382 \\[diff-show-header] Show diff header describing file name etc.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
383 \\[diff-quit] Quit diff
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
384 "
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
385 (interactive)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
386 (use-local-map diff-mode-map)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
387 (diff-grok-keymap)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
388 (setq buffer-read-only t
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
389 major-mode 'diff-mode
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
390 mode-name "Diff"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
391 mode-line-modified "--- "
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
392 mode-line-process
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
393 '(" " diff-current-difference "/" diff-total-differences))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
394 (diff-parse-hunks)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
395 (setq diff-total-differences (int-to-string diff-total-hunks)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
396
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
397 ;;; Motion commands
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
398
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
399 (defun diff-next-difference (n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
400 "In diff-mode go the the beginning of the next difference hunk."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
401 (interactive "p")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
402 (if (zerop n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
403 (goto-char (diff-hunk-min diff-current-hunk))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
404 (let ((narrow (diff-buffer-narrowed-p))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
405 (max (point-max))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
406 (min (point-min)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
407 (unwind-protect
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
408 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
409 (widen)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
410 (setq diff-current-hunk (+ n diff-current-hunk))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
411 (cond ((> diff-current-hunk diff-total-hunks)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
412 (setq diff-current-hunk diff-total-hunks)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
413 (message "No following difference hunks."))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
414 ((< diff-current-hunk 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
415 (setq diff-current-hunk 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
416 (message "No preceding difference hunks.")))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
417 (setq diff-current-difference (int-to-string diff-current-hunk)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
418 min (goto-char (diff-hunk-min diff-current-hunk))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
419 max (diff-hunk-max diff-current-hunk)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
420 (if narrow (narrow-to-region min max))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
421 (set-buffer-modified-p (buffer-modified-p))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
422
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
423 (defun diff-previous-difference (n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
424 "In diff-mode go the the beginning of the previous difference hunk."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
425 (interactive "p")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
426 (diff-next-difference (- n)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
427
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
428 (defun diff-next-line (n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
429 "In diff-mode go to the next line."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
430 (interactive "p")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
431 (condition-case nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
432 (next-line n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
433 (error (if (> n 0) (message "End of difference hunk"))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
434 (diff-update-modeline))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
435
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
436 (defun diff-previous-line (n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
437 "In diff-mode go to the previous line."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
438 (interactive "p")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
439 (diff-next-line (- n)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
440
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
441 (defun diff-forward-char (n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
442 "In diff-mode move the point forward."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
443 (interactive "p")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
444 (forward-char n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
445 (diff-update-modeline))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
446
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
447 (defun diff-backward-char (n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
448 "In diff-mode move the point backward."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
449 (interactive "p")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
450 (backward-char n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
451 (diff-update-modeline))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
452
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
453 (defun diff-scroll-up (n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
454 "In diff-mode scroll the buffer up."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
455 (interactive "P")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
456 (scroll-up n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
457 (diff-update-modeline))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
458
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
459 (fset 'diff-advertised-scroll-up 'diff-scroll-up)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
460
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
461 (defun diff-scroll-down (n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
462 "In diff-mode scroll the buffer down."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
463 (interactive "P")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
464 (scroll-down n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
465 (diff-update-modeline))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
466
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
467 (fset 'diff-advertised-scroll-down 'diff-scroll-down)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
468
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
469 (defun diff-beginning-of-buffer (n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
470 "In diff-mode go to the beginning of the buffer."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
471 (interactive "P")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
472 (beginning-of-buffer n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
473 (diff-update-modeline))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
474
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
475 (defun diff-end-of-buffer (n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
476 "In diff-mode go to the end of the buffer."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
477 (interactive "P")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
478 (end-of-buffer n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
479 (diff-update-modeline))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
480
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
481 ;;; The main command.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 100
diff changeset
483 ;;;###autoload
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
484 (defun diff (old new &optional switches)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
485 "Find and display the differences between OLD and NEW files.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
486 Interactively you are prompted with the current buffer's file name for NEW
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
487 and what appears to be its backup for OLD."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
488 ;; Support for diffing directories is rather limited. It needs work.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
489 (interactive (diff-read-args "Diff original file (%s) "
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
490 "Diff new file (%s) "
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
491 "Switches for diff (%s) "
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
492 (buffer-file-name)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
493 (setq switches (diff-fix-switches (or switches diff-switches))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
494 old (expand-file-name old)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
495 new (expand-file-name new))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
496 (let ((curr-buff (current-buffer))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
497 doing-dirs old-temp new-temp old-buffer new-buffer flag)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
498 (let ((fdp-old (file-directory-p old))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
499 (fdp-new (file-directory-p new)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
500 (cond
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
501 ((null (or fdp-new fdp-old)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
502 ((null fdp-new)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
503 (setq old (expand-file-name (file-name-nondirectory new) old)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
504 ((null fdp-old)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
505 (setq new (expand-file-name (file-name-nondirectory old) new)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
506 (t (setq doing-dirs t))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
507 ;; (message "diff %s %s %s..."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
508 ;; (mapconcat (function identity) switches " ") new old)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
509 (message "diff %s %s %s..."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
510 (mapconcat (function identity) switches " ") old new)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
511 (if doing-dirs
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
512 (setq diff-old-file nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
513 diff-new-file nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
514 (setq old-temp (make-temp-name (concat diff-temp-template "1"))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
515 new-temp (make-temp-name (concat diff-temp-template "2"))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
516 old-buffer (diff-get-file-buffer old)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
517 new-buffer (diff-get-file-buffer new)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
518 diff-old-file (cons old (cdr old-buffer))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
519 diff-new-file (cons new (cdr new-buffer))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
520 (let (case-fold-search)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
521 (mapcar (function
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
522 (lambda (x)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
523 (if (string-match "[ecu]" x)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
524 (setq flag (aref x (match-beginning 0))))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
525 switches))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
526 (unwind-protect
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
527 (let ((patterns (assq flag diff-search-pattern-alist)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
528 (set-buffer (get-buffer-create "*Diff Output*"))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
529 (setq default-directory (file-name-directory new)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
530 diff-old-file-pattern (nth 2 patterns)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
531 diff-new-file-pattern (nth 3 patterns)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
532 diff-hunk-pattern (nth 1 patterns))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
533 (let (buffer-read-only)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
534 (if (fboundp 'buffer-disable-undo)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
535 (buffer-disable-undo (current-buffer))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
536 ;; old style (Emacs 18.55 and earlier)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
537 (buffer-disable-undo (current-buffer)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
538 (widen)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
539 (erase-buffer)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
540 (if doing-dirs
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
541 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
542 (diff-run-diff switches old old new new)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
543 (setq diff-hunk-pattern (concat diff-hunk-pattern
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
544 "\\|^Only in ")))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
545 (save-excursion
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
546 (set-buffer (car old-buffer))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
547 (write-region (point-min) (point-max) old-temp nil 'quiet)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
548 (set-buffer (car new-buffer))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
549 (write-region (point-min) (point-max) new-temp nil 'quiet))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
550 (diff-run-diff switches old old-temp new new-temp))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
551 ;; Need to replace file names
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
552 (if (and (not doing-dirs) (memq flag '(?c ?u)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
553 (diff-fix-file-names old old-temp new new-temp
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
554 diff-hunk-pattern))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
555 (diff-mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
556 (goto-char (point-min))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
557 (setq diff-current-difference "0"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
558 diff-current-hunk 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
559 (if (zerop diff-total-hunks)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
560 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
561 (diff-cleanup-buffers)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
562 (message "No differences"))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
563 (if diff-do-narrow (narrow-to-region (point) (diff-hunk-max 0)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
564 (display-buffer (current-buffer))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
565 (message "%s difference hunk%s" diff-total-differences
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
566 (if (= diff-total-hunks 1) "" "s")))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
567 (condition-case nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
568 (delete-file old-temp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
569 (error nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
570 (condition-case nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
571 (delete-file new-temp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
572 (error nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
573 (set-buffer curr-buff))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
574
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 100
diff changeset
575 ;;;###autoload
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
576 (defun diff-backup (file &optional switches)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
577 "Diff this file with its backup file or vice versa.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
578 Uses the latest backup, if there are several numerical backups.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
579 If this file is a backup, diff it with its original.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
580 The backup file is the first file given to `diff'."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
581 (interactive (list (read-file-name "Diff (file with backup): ")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
582 (and current-prefix-arg
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
583 (diff-read-switches "Diff switches: "))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
584 (let (bak ori)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
585 (if (backup-file-name-p file)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
586 (setq bak file
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
587 ori (file-name-sans-versions file))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
588 (setq bak (or (diff-latest-backup-file file)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
589 (error "No backup found for %s" file))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
590 ori file))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
591 (diff bak ori switches)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
592
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
593 (defun diff-show-difference (n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
594 "Show difference number N (prefix argument)."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
595 (interactive "p")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
596 (let ((narrowedp (diff-buffer-narrowed-p))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
597 (min (diff-hunk-min diff-current-hunk))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
598 (max (diff-hunk-max diff-current-hunk)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
599 (unwind-protect
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
600 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
601 (widen)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
602 (cond
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
603 ((< n 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
604 (message "No negative hunks.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
605 (setq n 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
606 ((> n diff-total-hunks)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
607 (message "No hunk %d." n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
608 (setq n diff-total-hunks)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
609 (setq diff-current-hunk n
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
610 diff-current-difference (int-to-string diff-current-hunk)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
611 min (diff-hunk-min n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
612 max (diff-hunk-max n))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
613 (goto-char min))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
614 (if narrowedp (narrow-to-region min max))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
615 (set-buffer-modified-p (buffer-modified-p)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
616
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
617 (defun diff-show-header ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
618 "Show `diff-header'."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
619 (interactive)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
620 (with-output-to-temp-buffer "*Diff Header*"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
621 (princ (save-restriction
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
622 (widen)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
623 (buffer-substring (diff-hunk-min 0) (diff-hunk-max 0))))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
624
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
625
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
626 (defun diff-find-file (old-file-p)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
627 "Visit diffed file, at the point corresponding to the current hunk.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
628 Default is to visit the new file; prefix means visit old file instead."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
629 (interactive "P")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
630 (let ((line (diff-file-line old-file-p)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
631 (find-file
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
632 (if old-file-p
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
633 (car diff-old-file)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
634 (car diff-new-file)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
635 (goto-line line)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
636 (recenter 0)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
637
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
638 (defun diff-find-file-other-window (old-file-p)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
639 "Visit the diffed file in other window, with the point at the current hunk.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
640 Default is to visit the new file; prefix means visit the old file instead."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
641 (interactive "P")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
642 (let ((line (diff-file-line old-file-p)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
643 (find-file-other-window
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
644 (if old-file-p
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
645 (car diff-old-file)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
646 (car diff-new-file)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
647 (goto-line line)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
648 (recenter 0)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
649
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
650 (defun diff-find-file-other-frame (old-file-p)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
651 "Visit the diffed file in other frame, with point at the current hunk.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
652 Default is to visit the new file; prefix means visit the old file instead."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
653 (interactive "P")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
654 (let ((line (diff-file-line old-file-p)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
655 (find-file-other-frame
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
656 (if old-file-p
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
657 (car diff-old-file)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
658 (car diff-new-file)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
659 (goto-line line)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
660 (recenter 0)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
661
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
662 (defun diff-display-file (old-file-p)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
663 "Display the diffed file in other window, with point at the current hunk.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
664 Default is to visit the new file; prefix means visit the old file instead."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
665 (interactive "P")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
666 (let ((line (diff-file-line old-file-p))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
667 (wind (display-buffer (find-file-noselect (if old-file-p
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
668 (car diff-old-file)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
669 (car diff-new-file)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
670 (curr-wind (selected-window)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
671 (unwind-protect
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
672 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
673 (select-window wind)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
674 (goto-line line)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
675 (recenter 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
676 (select-window curr-wind))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
677
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
678 (defun diff-quit ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
679 "Quit diff by killing the diff buffer."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
680 (interactive)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
681 (kill-buffer "*Diff Output*")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
682 (diff-cleanup-buffers))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
683
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
684 (defun diff-narrow ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
685 "Narrow diff buffer to current difference hunk."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
686 (interactive)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
687 (narrow-to-region (diff-hunk-min diff-current-hunk)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
688 (diff-hunk-max diff-current-hunk)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
689
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
690 ;;; Run any load hooks
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
691 (run-hooks 'diff-load-hook)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
692
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
693 ;;; end of diff.el