annotate lisp/packages/diff.el @ 191:ecf6ba7b0a10 r20-3b22

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