(diff-file-header-face): Reset to its previous value.
[bpt/emacs.git] / lisp / diff-mode.el
1 ;;; diff-mode.el --- A mode for viewing/editing context diffs
2
3 ;; Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
4
5 ;; Author: Stefan Monnier <monnier@cs.yale.edu>
6 ;; Keywords: patch diff
7 ;; Revision: $Id: diff-mode.el,v 1.20 2000/09/20 22:36:23 monnier Exp $
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; Provides support for font-lock patterns, outline-regexps, navigation
29 ;; commands, editing and various conversions as well as jumping
30 ;; to the corresponding source file.
31
32 ;; inspired by Pavel Machek's patch-mode.el (<pavel@atrey.karlin.mff.cuni.cz>)
33 ;; some efforts were spent to have it somewhat compatible with XEmacs'
34 ;; diff-mode as well as with compilation-minor-mode
35
36 ;; to use it, simply add to your .emacs the following lines:
37 ;;
38 ;; (autoload 'diff-mode "diff-mode" "Diff major mode" t)
39 ;; (add-to-list 'auto-mode-alist '("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode))
40
41 ;; Bugs:
42
43 ;; - Reverse doesn't work with normal diffs.
44 ;; - (nitpick) The mark is not always quite right in diff-goto-source.
45
46 ;; Todo:
47
48 ;; - Spice up the minor-mode with font-lock support.
49 ;; - Improve narrowed-view support.
50 ;; - Improve the `compile' support (?).
51 ;; - Recognize pcl-cvs' special string for `cvs-execute-single'.
52 ;; - Support for # comments in context->unified.
53 ;; - Do a fuzzy search in diff-goto-source.
54 ;; - Allow diff.el to use diff-mode.
55 ;; This mostly means ability to jump from half-hunk to half-hunk
56 ;; in context (and normal) diffs and to jump to the corresponding
57 ;; (i.e. new or old) file.
58 ;; - Handle `diff -b' output in context->unified.
59
60 ;;; Code:
61
62 (eval-when-compile (require 'cl))
63
64
65 (defgroup diff-mode ()
66 "Major-mode for viewing/editing diffs"
67 :version "21.1"
68 :group 'tools
69 :group 'diff)
70
71 (defcustom diff-jump-to-old-file-flag nil
72 "*Non-nil means `diff-goto-source' jumps to the old file.
73 Else, it jumps to the new file."
74 :group 'diff-mode
75 :type '(boolean))
76
77 (defcustom diff-update-on-the-fly-flag t
78 "*Non-nil means hunk headers are kept up-to-date on-the-fly.
79 When editing a diff file, the line numbers in the hunk headers
80 need to be kept consistent with the actual diff. This can
81 either be done on the fly (but this sometimes interacts poorly with the
82 undo mechanism) or whenever the file is written (can be slow
83 when editing big diffs)."
84 :group 'diff-mode
85 :type '(boolean))
86
87 (defvar diff-mode-hook nil
88 "Run after setting up the `diff-mode' major mode.")
89
90 (defvar diff-outline-regexp
91 "\\([*+][*+][*+] [^0-9]\\|@@ ...\\|\\*\\*\\* [0-9].\\|--- [0-9]..\\)")
92
93 ;;;;
94 ;;;; keymap, menu, ...
95 ;;;;
96
97 (easy-mmode-defmap diff-mode-shared-map
98 '(;; From Pavel Machek's patch-mode.
99 ("n" . diff-hunk-next)
100 ("N" . diff-file-next)
101 ("p" . diff-hunk-prev)
102 ("P" . diff-file-prev)
103 ("k" . diff-hunk-kill)
104 ("K" . diff-file-kill)
105 ;; From compilation-minor-mode.
106 ("}" . diff-file-next)
107 ("{" . diff-file-prev)
108 ("\C-m" . diff-goto-source)
109 ([mouse-2] . diff-mouse-goto-source)
110 ;; From XEmacs' diff-mode.
111 ("W" . widen)
112 ;;("." . diff-goto-source) ;display-buffer
113 ;;("f" . diff-goto-source) ;find-file
114 ("o" . diff-goto-source) ;other-window
115 ;;("w" . diff-goto-source) ;other-frame
116 ;;("N" . diff-narrow)
117 ;;("h" . diff-show-header)
118 ;;("j" . diff-show-difference) ;jump to Nth diff
119 ;;("q" . diff-quit)
120 (" " . scroll-up)
121 ("\177" . scroll-down)
122 ;; Our very own bindings.
123 ("A" . diff-ediff-patch)
124 ("r" . diff-restrict-view)
125 ("R" . diff-reverse-direction)
126 ("U" . diff-context->unified)
127 ("C" . diff-unified->context))
128 "Basic keymap for `diff-mode', bound to various prefix keys.")
129
130 (easy-mmode-defmap diff-mode-map
131 `(("\e" . ,diff-mode-shared-map)
132 ;; From compilation-minor-mode.
133 ("\C-c\C-c" . diff-goto-source)
134 ;; Misc operations.
135 ("\C-cda" . diff-apply-hunk)
136 ("\C-cdt" . diff-test-hunk))
137 "Keymap for `diff-mode'. See also `diff-mode-shared-map'.")
138
139 (easy-menu-define diff-mode-menu diff-mode-map
140 "Menu for `diff-mode'."
141 '("Diff"
142 ["Jump to Source" diff-goto-source t]
143 ["Apply with Ediff" diff-ediff-patch t]
144 ["-----" nil nil]
145 ["Reverse direction" diff-reverse-direction t]
146 ["Context -> Unified" diff-context->unified t]
147 ["Unified -> Context" diff-unified->context t]
148 ;;["Fixup Headers" diff-fixup-modifs (not buffer-read-only)]
149 ))
150
151 (defcustom diff-minor-mode-prefix "\C-cd"
152 "Prefix key for `diff-minor-mode' commands."
153 :group 'diff-mode
154 :type '(choice (string "\e") (string "C-cd") string))
155
156 (easy-mmode-defmap diff-minor-mode-map
157 `((,diff-minor-mode-prefix . ,diff-mode-shared-map))
158 "Keymap for `diff-minor-mode'. See also `diff-mode-shared-map'.")
159
160
161 ;;;;
162 ;;;; font-lock support
163 ;;;;
164
165 (defface diff-header-face
166 '((t (:inherit highlight)))
167 "`diff-mode' face inherited by hunk, file and index header faces."
168 :group 'diff-mode)
169 (defvar diff-header-face 'diff-header-face)
170
171 (defface diff-file-header-face
172 '((((class color) (background light))
173 (:background "grey70" :bold t))
174 (t (:bold t))) ; :height 1.3
175 "`diff-mode' face used to highlight file header lines."
176 :group 'diff-mode)
177 (defvar diff-file-header-face 'diff-file-header-face)
178
179 (defface diff-index-face
180 '((t (:inherit diff-file-header-face)))
181 "`diff-mode' face used to highlight index header lines."
182 :group 'diff-mode)
183 (defvar diff-index-face 'diff-index-face)
184
185 (defface diff-hunk-header-face
186 '((t (:inherit diff-header-face)))
187 "`diff-mode' face used to highlight hunk header lines."
188 :group 'diff-mode)
189 (defvar diff-hunk-header-face 'diff-hunk-header-face)
190
191 (defface diff-removed-face
192 '((t (:inherit diff-changed-face)))
193 "`diff-mode' face used to highlight removed lines."
194 :group 'diff-mode)
195 (defvar diff-removed-face 'diff-removed-face)
196
197 (defface diff-added-face
198 '((t (:inherit diff-changed-face)))
199 "`diff-mode' face used to highlight added lines."
200 :group 'diff-mode)
201 (defvar diff-added-face 'diff-added-face)
202
203 (defface diff-changed-face
204 '((t ()))
205 "`diff-mode' face used to highlight changed lines."
206 :group 'diff-mode)
207 (defvar diff-changed-face 'diff-changed-face)
208
209 (defface diff-comment-face
210 '((t (:inherit font-lock-comment-face)))
211 "`diff-mode' face used to highlight context and other side-information."
212 :group 'diff-mode)
213 (defvar diff-comment-face 'diff-comment-face)
214
215 (defvar diff-font-lock-keywords
216 '(("^\\(@@ -[0-9,]+ \\+[0-9,]+ @@\\)\\(.*\\)$" ;unified
217 (1 diff-hunk-header-face)
218 (2 diff-comment-face))
219 ("^--- .+ ----$" ;context
220 . diff-hunk-header-face)
221 ("\\(\\*\\{15\\}\\)\\(.*\\)$" ;context
222 (1 diff-hunk-header-face)
223 (2 diff-comment-face))
224 ("^\\*\\*\\* .+ \\*\\*\\*\\*". diff-hunk-header-face) ;context
225 ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) \\(\\S-+\\).*[^*-]\n"
226 (0 diff-header-face) (2 diff-file-header-face prepend))
227 ("^[0-9,]+[acd][0-9,]+$" . diff-hunk-header-face)
228 ("^!.*\n" . diff-changed-face) ;context
229 ("^[+>].*\n" . diff-added-face)
230 ("^[-<].*\n" . diff-removed-face)
231 ("^Index: \\(.+\\).*\n" (0 diff-header-face) (1 diff-index-face prepend))
232 ("^#.*" . font-lock-string-face)
233 ("^[^-=+*!<>].*\n" . diff-comment-face)))
234
235 (defconst diff-font-lock-defaults
236 '(diff-font-lock-keywords t nil nil nil (font-lock-multiline . nil)))
237
238 (defvar diff-imenu-generic-expression
239 ;; Prefer second name as first is most likely to be a backup or
240 ;; version-control name.
241 '((nil "\\+\\+\\+\\ \\([^\t\n]+\\)\t" 1) ; unidiffs
242 (nil "^--- \\([^\t\n]+\\)\t.*\n\\*" 1))) ; context diffs
243
244 ;;;;
245 ;;;; Compile support
246 ;;;;
247
248 (defvar diff-file-regexp-alist
249 '(("Index: \\(.+\\)" 1)))
250
251 (defvar diff-error-regexp-alist
252 '(("@@ -\\([0-9]+\\),[0-9]+ \\+\\([0-9]+\\),[0-9]+ @@" nil 2)
253 ("--- \\([0-9]+\\),[0-9]+ ----" nil 1)
254 ("\\([0-9]+\\)\\(,[0-9]+\\)?[adc]\\([0-9]+\\)" nil 3)))
255
256 ;;;;
257 ;;;; Movement
258 ;;;;
259
260 (defconst diff-hunk-header-re "^\\(@@ -[0-9,]+ \\+[0-9,]+ @@.*\\|\\*\\{15\\}.*\n\\*\\*\\* .+ \\*\\*\\*\\*\\|[0-9]+\\(,[0-9]+\\)?[acd][0-9]+\\(,[0-9]+\\)?\\)$")
261 (defconst diff-file-header-re (concat "^\\(--- .+\n\\+\\+\\+\\|\\*\\*\\* .+\n---\\|[^-+!<>0-9@* ]\\).+\n" (substring diff-hunk-header-re 1)))
262 (defvar diff-narrowed-to nil)
263
264 (defun diff-end-of-hunk (&optional style)
265 (if (looking-at diff-hunk-header-re) (goto-char (match-end 0)))
266 (let ((end (and (re-search-forward (case style
267 (unified "^[^-+# \\]")
268 (context "^[^-+#! \\]")
269 (normal "^[^<>#\\]")
270 (t "^[^-+#!<> \\]"))
271 nil t)
272 (match-beginning 0))))
273 ;; The return value is used by easy-mmode-define-navigation.
274 (goto-char (or end (point-max)))))
275
276 (defun diff-beginning-of-hunk ()
277 (beginning-of-line)
278 (unless (looking-at diff-hunk-header-re)
279 (forward-line 1)
280 (condition-case ()
281 (re-search-backward diff-hunk-header-re)
282 (error (error "Can't find the beginning of the hunk")))))
283
284 (defun diff-beginning-of-file ()
285 (beginning-of-line)
286 (unless (looking-at diff-file-header-re)
287 (forward-line 2)
288 (condition-case ()
289 (re-search-backward diff-file-header-re)
290 (error (error "Can't find the beginning of the file")))))
291
292 (defun diff-end-of-file ()
293 (re-search-forward "^[-+#!<>0-9@* \\]" nil t)
294 (re-search-forward "^[^-+#!<>0-9@* \\]" nil 'move)
295 (beginning-of-line))
296
297 ;; Define diff-{hunk,file}-{prev,next}
298 (easy-mmode-define-navigation
299 diff-hunk diff-hunk-header-re "hunk" diff-end-of-hunk)
300 (easy-mmode-define-navigation
301 diff-file diff-file-header-re "file" diff-end-of-hunk)
302
303 (defun diff-restrict-view (&optional arg)
304 "Restrict the view to the current hunk.
305 If the prefix ARG is given, restrict the view to the current file instead."
306 (interactive "P")
307 (save-excursion
308 (if arg (diff-beginning-of-file) (diff-beginning-of-hunk))
309 (narrow-to-region (point)
310 (progn (if arg (diff-end-of-file) (diff-end-of-hunk))
311 (point)))
312 (set (make-local-variable 'diff-narrowed-to) (if arg 'file 'hunk))))
313
314
315 (defun diff-hunk-kill ()
316 "Kill current hunk."
317 (interactive)
318 (diff-beginning-of-hunk)
319 (let ((start (point))
320 (firsthunk (save-excursion
321 (ignore-errors
322 (diff-beginning-of-file) (diff-hunk-next) (point))))
323 (nexthunk (save-excursion
324 (ignore-errors
325 (diff-hunk-next) (point))))
326 (nextfile (save-excursion
327 (ignore-errors
328 (diff-file-next) (point)))))
329 (if (and firsthunk (= firsthunk start)
330 (or (null nexthunk)
331 (and nextfile (> nexthunk nextfile))))
332 ;; we're the only hunk for this file, so kill the file
333 (diff-file-kill)
334 (diff-end-of-hunk)
335 (kill-region start (point)))))
336
337 (defun diff-file-kill ()
338 "Kill current file's hunks."
339 (interactive)
340 (diff-beginning-of-file)
341 (let* ((start (point))
342 (prevhunk (save-excursion
343 (ignore-errors
344 (diff-hunk-prev) (point))))
345 (index (save-excursion
346 (re-search-backward "^Index: " prevhunk t))))
347 (when index (setq start index))
348 (diff-end-of-file)
349 (kill-region start (point))))
350
351 (defun diff-kill-junk ()
352 "Kill spurious empty diffs."
353 (interactive)
354 (save-excursion
355 (let ((inhibit-read-only t))
356 (goto-char (point-min))
357 (while (re-search-forward (concat "^\\(Index: .*\n\\)"
358 "\\([^-+!* <>].*\n\\)*?"
359 "\\(\\(Index:\\) \\|"
360 diff-file-header-re "\\)")
361 nil t)
362 (delete-region (if (match-end 4) (match-beginning 0) (match-end 1))
363 (match-beginning 3))
364 (beginning-of-line)))))
365
366 ;;;;
367 ;;;; jump to other buffers
368 ;;;;
369
370 (defvar diff-remembered-files-alist nil)
371
372 (defun diff-filename-drop-dir (file)
373 (when (string-match "/" file) (substring file (match-end 0))))
374
375 (defun diff-merge-strings (ancestor from to)
376 "Merge the diff between ANCESTOR and FROM into TO.
377 Returns the merged string if successful or nil otherwise.
378 The strings are assumed not to contain any \"\\n\" (i.e. end of line).
379 If ANCESTOR = FROM, returns TO.
380 If ANCESTOR = TO, returns FROM.
381 The heuristic is simplistic and only really works for cases
382 like \(diff-merge-strings \"b/foo\" \"b/bar\" \"/a/c/foo\")."
383 ;; Ideally, we want:
384 ;; AMB ANB CMD -> CND
385 ;; but that's ambiguous if `foo' or `bar' is empty:
386 ;; a/foo a/foo1 b/foo.c -> b/foo1.c but not 1b/foo.c or b/foo.c1
387 (let ((str (concat ancestor "\n" from "\n" to)))
388 (when (and (string-match (concat
389 "\\`\\(.*?\\)\\(.*\\)\\(.*\\)\n"
390 "\\1\\(.*\\)\\3\n"
391 "\\(.*\\(\\2\\).*\\)\\'") str)
392 (equal to (match-string 5 str)))
393 (concat (substring str (match-beginning 5) (match-beginning 6))
394 (match-string 4 str)
395 (substring str (match-end 6) (match-end 5))))))
396
397 (defun diff-find-file-name (&optional old)
398 "Return the file corresponding to the current patch.
399 Non-nil OLD means that we want the old file."
400 (save-excursion
401 (unless (looking-at diff-file-header-re)
402 (or (ignore-errors (diff-beginning-of-file))
403 (re-search-forward diff-file-header-re nil t)))
404 (let* ((limit (save-excursion
405 (condition-case ()
406 (progn (diff-hunk-prev) (point))
407 (error (point-min)))))
408 (header-files
409 (if (looking-at "[-*][-*][-*] \\(\\S-+\\)\\s-.*\n[-+][-+][-+] \\(\\S-+\\)\\s-.*$")
410 (list (if old (match-string 1) (match-string 2))
411 (if old (match-string 2) (match-string 1)))
412 (forward-line 1) nil))
413 (fs (append
414 (when (save-excursion
415 (re-search-backward "^Index: \\(.+\\)" limit t))
416 (list (match-string 1)))
417 header-files
418 (when (re-search-backward "^diff \\(-\\S-+ +\\)*\\(\\S-+\\)\\( +\\(\\S-+\\)\\)?" nil t)
419 (list (if old (match-string 2) (match-string 4))
420 (if old (match-string 4) (match-string 2))))))
421 (fs (delq nil fs)))
422 (or
423 ;; use any previously used preference
424 (cdr (assoc fs diff-remembered-files-alist))
425 ;; try to be clever and use previous choices as an inspiration
426 (dolist (rf diff-remembered-files-alist)
427 (let ((newfile (diff-merge-strings (caar rf) (car fs) (cdr rf))))
428 (if (and newfile (file-exists-p newfile)) (return newfile))))
429 ;; look for each file in turn. If none found, try again but
430 ;; ignoring the first level of directory, ...
431 (do* ((files fs (delq nil (mapcar 'diff-filename-drop-dir files)))
432 (file nil nil))
433 ((or (null files)
434 (setq file (do* ((files files (cdr files))
435 (file (car files) (car files)))
436 ((or (null file) (file-exists-p file))
437 file))))
438 file))
439 ;; <foo>.rej patches implicitly apply to <foo>
440 (and (string-match "\\.rej\\'" (or buffer-file-name ""))
441 (let ((file (substring buffer-file-name 0 (match-beginning 0))))
442 (when (file-exists-p file) file)))
443 ;; if all else fails, ask the user
444 (let ((file (read-file-name (format "Use file %s: " (or (first fs) ""))
445 nil (first fs) t (first fs))))
446 (set (make-local-variable 'diff-remembered-files-alist)
447 (cons (cons fs file) diff-remembered-files-alist))
448 file)))))
449
450 (defun diff-mouse-goto-source (event)
451 "Run `diff-goto-source' for the diff at a mouse click."
452 (interactive "e")
453 (save-excursion
454 (mouse-set-point event)
455 (diff-goto-source)))
456
457 (defun diff-add-log-file-name (log-file)
458 "File name to use in add-log for the hunk at point.
459 For use in `add-log-file-name-function'.
460 LOG-FILE should be the path to the ChangeLog file."
461 (add-log-file-name (expand-file-name (diff-find-file-name)) log-file))
462
463
464 (defun diff-ediff-patch ()
465 "Call `ediff-patch-file' on the current buffer."
466 (interactive)
467 (condition-case err
468 (ediff-patch-file nil (current-buffer))
469 (wrong-number-of-arguments (ediff-patch-file))))
470
471 ;;;;
472 ;;;; Conversion functions
473 ;;;;
474
475 ;;(defvar diff-inhibit-after-change nil
476 ;; "Non-nil means inhibit `diff-mode's after-change functions.")
477
478 (defun diff-unified->context (start end)
479 "Convert unified diffs to context diffs.
480 START and END are either taken from the region (if a prefix arg is given) or
481 else cover the whole bufer."
482 (interactive (if current-prefix-arg
483 (list (mark) (point))
484 (list (point-min) (point-max))))
485 (unless (markerp end) (setq end (copy-marker end)))
486 (let (;;(diff-inhibit-after-change t)
487 (inhibit-read-only t))
488 (save-excursion
489 (goto-char start)
490 (while (and (re-search-forward "^\\(\\(---\\) .+\n\\(\\+\\+\\+\\) .+\\|@@ -\\([0-9]+\\),\\([0-9]+\\) \\+\\([0-9]+\\),\\([0-9]+\\) @@.*\\)$" nil t)
491 (< (point) end))
492 (combine-after-change-calls
493 (if (match-beginning 2)
494 ;; we matched a file header
495 (progn
496 ;; use reverse order to make sure the indices are kept valid
497 (replace-match "---" t t nil 3)
498 (replace-match "***" t t nil 2))
499 ;; we matched a hunk header
500 (let ((line1 (match-string 4))
501 (lines1 (match-string 5))
502 (line2 (match-string 6))
503 (lines2 (match-string 7)))
504 (replace-match
505 (concat "***************\n*** " line1 ","
506 (number-to-string (+ (string-to-number line1)
507 (string-to-number lines1)
508 -1)) " ****"))
509 (forward-line 1)
510 (save-restriction
511 (narrow-to-region (point)
512 (progn (diff-end-of-hunk 'unified) (point)))
513 (let ((hunk (buffer-string)))
514 (goto-char (point-min))
515 (if (not (save-excursion (re-search-forward "^-" nil t)))
516 (delete-region (point) (point-max))
517 (goto-char (point-max))
518 (let ((modif nil) last-pt)
519 (while (progn (setq last-pt (point))
520 (= (forward-line -1) 0))
521 (case (char-after)
522 (? (insert " ") (setq modif nil) (backward-char 1))
523 (?+ (delete-region (point) last-pt) (setq modif t))
524 (?- (if (not modif)
525 (progn (forward-char 1)
526 (insert " "))
527 (delete-char 1)
528 (insert "! "))
529 (backward-char 2))
530 (?\\ (when (save-excursion (forward-line -1)
531 (= (char-after) ?+))
532 (delete-region (point) last-pt) (setq modif t)))
533 (t (setq modif nil))))))
534 (goto-char (point-max))
535 (save-excursion
536 (insert "--- " line2 ","
537 (number-to-string (+ (string-to-number line2)
538 (string-to-number lines2)
539 -1)) " ----\n" hunk))
540 ;;(goto-char (point-min))
541 (forward-line 1)
542 (if (not (save-excursion (re-search-forward "^+" nil t)))
543 (delete-region (point) (point-max))
544 (let ((modif nil) (delete nil))
545 (while (not (eobp))
546 (case (char-after)
547 (? (insert " ") (setq modif nil) (backward-char 1))
548 (?- (setq delete t) (setq modif t))
549 (?+ (if (not modif)
550 (progn (forward-char 1)
551 (insert " "))
552 (delete-char 1)
553 (insert "! "))
554 (backward-char 2))
555 (?\\ (when (save-excursion (forward-line 1)
556 (not (eobp)))
557 (setq delete t) (setq modif t)))
558 (t (setq modif nil)))
559 (let ((last-pt (point)))
560 (forward-line 1)
561 (when delete
562 (delete-region last-pt (point))
563 (setq delete nil)))))))))))))))
564
565 (defun diff-context->unified (start end)
566 "Convert context diffs to unified diffs.
567 START and END are either taken from the region (if a prefix arg is given) or
568 else cover the whole bufer."
569 (interactive (if current-prefix-arg
570 (list (mark) (point))
571 (list (point-min) (point-max))))
572 (unless (markerp end) (setq end (copy-marker end)))
573 (let (;;(diff-inhibit-after-change t)
574 (inhibit-read-only t))
575 (save-excursion
576 (goto-char start)
577 (while (and (re-search-forward "^\\(\\(\\*\\*\\*\\) .+\n\\(---\\) .+\\|\\*\\{15\\}.*\n\\*\\*\\* \\([0-9]+\\),\\(-?[0-9]+\\) \\*\\*\\*\\*\\)$" nil t)
578 (< (point) end))
579 (combine-after-change-calls
580 (if (match-beginning 2)
581 ;; we matched a file header
582 (progn
583 ;; use reverse order to make sure the indices are kept valid
584 (replace-match "+++" t t nil 3)
585 (replace-match "---" t t nil 2))
586 ;; we matched a hunk header
587 (let ((line1s (match-string 4))
588 (line1e (match-string 5))
589 (pt1 (match-beginning 0)))
590 (replace-match "")
591 (unless (re-search-forward
592 "^--- \\([0-9]+\\),\\(-?[0-9]+\\) ----$" nil t)
593 (error "Can't find matching `--- n1,n2 ----' line"))
594 (let ((line2s (match-string 1))
595 (line2e (match-string 2))
596 (pt2 (progn
597 (delete-region (progn (beginning-of-line) (point))
598 (progn (forward-line 1) (point)))
599 (point-marker))))
600 (goto-char pt1)
601 (forward-line 1)
602 (while (< (point) pt2)
603 (case (char-after)
604 ((?! ?-) (delete-char 2) (insert "-") (forward-line 1))
605 (?\ ;merge with the other half of the chunk
606 (let* ((endline2
607 (save-excursion
608 (goto-char pt2) (forward-line 1) (point)))
609 (c (char-after pt2)))
610 (case c
611 ((?! ?+)
612 (insert "+"
613 (prog1 (buffer-substring (+ pt2 2) endline2)
614 (delete-region pt2 endline2))))
615 (?\ ;FIXME: check consistency
616 (delete-region pt2 endline2)
617 (delete-char 1)
618 (forward-line 1))
619 (?\\ (forward-line 1))
620 (t (delete-char 1) (forward-line 1)))))
621 (t (forward-line 1))))
622 (while (looking-at "[+! ] ")
623 (if (/= (char-after) ?!) (forward-char 1)
624 (delete-char 1) (insert "+"))
625 (delete-char 1) (forward-line 1))
626 (save-excursion
627 (goto-char pt1)
628 (insert "@@ -" line1s ","
629 (number-to-string (- (string-to-number line1e)
630 (string-to-number line1s)
631 -1))
632 " +" line2s ","
633 (number-to-string (- (string-to-number line2e)
634 (string-to-number line2s)
635 -1)) " @@"))))))))))
636
637 (defun diff-reverse-direction (start end)
638 "Reverse the direction of the diffs.
639 START and END are either taken from the region (if a prefix arg is given) or
640 else cover the whole bufer."
641 (interactive (if current-prefix-arg
642 (list (mark) (point))
643 (list (point-min) (point-max))))
644 (unless (markerp end) (setq end (copy-marker end)))
645 (let (;;(diff-inhibit-after-change t)
646 (inhibit-read-only t))
647 (save-excursion
648 (goto-char start)
649 (while (and (re-search-forward "^\\(\\([-*][-*][-*] \\)\\(.+\\)\n\\([-+][-+][-+] \\)\\(.+\\)\\|\\*\\{15\\}.*\n\\*\\*\\* \\(.+\\) \\*\\*\\*\\*\\|@@ -\\([0-9,]+\\) \\+\\([0-9,]+\\) @@.*\\)$" nil t)
650 (< (point) end))
651 (combine-after-change-calls
652 (cond
653 ;; a file header
654 ((match-beginning 2) (replace-match "\\2\\5\n\\4\\3" nil))
655 ;; a context-diff hunk header
656 ((match-beginning 6)
657 (let ((pt-lines1 (match-beginning 6))
658 (lines1 (match-string 6)))
659 (replace-match "" nil nil nil 6)
660 (forward-line 1)
661 (let ((half1s (point)))
662 (while (looking-at "[-! \\][ \t]\\|#")
663 (when (= (char-after) ?-) (delete-char 1) (insert "+"))
664 (forward-line 1))
665 (let ((half1 (delete-and-extract-region half1s (point))))
666 (unless (looking-at "^--- \\([0-9]+,-?[0-9]+\\) ----$")
667 (insert half1)
668 (error "Can't find matching `--- n1,n2 ----' line"))
669 (let ((str1 (match-string 1)))
670 (replace-match lines1 nil nil nil 1)
671 (forward-line 1)
672 (let ((half2s (point)))
673 (while (looking-at "[!+ \\][ \t]\\|#")
674 (when (= (char-after) ?+) (delete-char 1) (insert "-"))
675 (forward-line 1))
676 (let ((half2 (delete-and-extract-region half2s (point))))
677 (insert (or half1 ""))
678 (goto-char half1s)
679 (insert (or half2 ""))))
680 (goto-char pt-lines1)
681 (insert str1))))))
682 ;; a unified-diff hunk header
683 ((match-beginning 7)
684 (replace-match "@@ -\\8 +\\7 @@" nil)
685 (forward-line 1)
686 (let ((c (char-after)) first last)
687 (while (case (setq c (char-after))
688 (?- (setq first (or first (point)))
689 (delete-char 1) (insert "+") t)
690 (?+ (setq last (or last (point)))
691 (delete-char 1) (insert "-") t)
692 ((?\\ ?#) t)
693 (t (when (and first last (< first last))
694 (let ((str
695 (save-excursion
696 (delete-and-extract-region first last))))
697 (insert str)))
698 (setq first nil last nil)
699 (equal ?\ c)))
700 (forward-line 1))))))))))
701
702 (defun diff-fixup-modifs (start end)
703 "Fixup the hunk headers (in case the buffer was modified).
704 START and END are either taken from the region (if a prefix arg is given) or
705 else cover the whole bufer."
706 (interactive (if current-prefix-arg
707 (list (mark) (point))
708 (list (point-min) (point-max))))
709 (let ((inhibit-read-only t))
710 (save-excursion
711 (goto-char end) (diff-end-of-hunk)
712 (let ((plus 0) (minus 0) (space 0) (bang 0))
713 (while (and (= (forward-line -1) 0) (<= start (point)))
714 (if (not (looking-at "\\(@@ -[0-9,]+ \\+[0-9,]+ @@.*\\|[-*][-*][-*] .+ [-*][-*][-*][-*]\\)$"))
715 (case (char-after)
716 (?\ (incf space))
717 (?+ (incf plus))
718 (?- (incf minus))
719 (?! (incf bang))
720 ((?\\ ?#) nil)
721 (t (setq space 0 plus 0 minus 0 bang 0)))
722 (cond
723 ((looking-at "@@ -[0-9]+,\\([0-9]*\\) \\+[0-9]+,\\([0-9]*\\) @@.*$")
724 (let* ((old1 (match-string 1))
725 (old2 (match-string 2))
726 (new1 (number-to-string (+ space minus)))
727 (new2 (number-to-string (+ space plus))))
728 (unless (string= new2 old2) (replace-match new2 t t nil 2))
729 (unless (string= new1 old1) (replace-match new1 t t nil 1))))
730 ((looking-at "--- \\([0-9]+\\),\\([0-9]*\\) ----$")
731 (when (> (+ space bang plus) 0)
732 (let* ((old1 (match-string 1))
733 (old2 (match-string 2))
734 (new (number-to-string
735 (+ space bang plus -1 (string-to-number old1)))))
736 (unless (string= new old2) (replace-match new t t nil 2)))))
737 ((looking-at "\\*\\*\\* \\([0-9]+\\),\\(-?[0-9]*\\) \\*\\*\\*\\*$")
738 (when (> (+ space bang minus) 0)
739 (let* ((old (match-string 1))
740 (new (format
741 (concat "%0" (number-to-string (length old)) "d")
742 (+ space bang minus -1 (string-to-number old)))))
743 (unless (string= new old) (replace-match new t t nil 2))))))
744 (setq space 0 plus 0 minus 0 bang 0)))))))
745
746 ;;;;
747 ;;;; Hooks
748 ;;;;
749
750 (defun diff-write-contents-hooks ()
751 "Fixup hunk headers if necessary."
752 (if (buffer-modified-p) (diff-fixup-modifs (point-min) (point-max)))
753 nil)
754
755 ;; It turns out that making changes in the buffer from within an
756 ;; *-change-function is asking for trouble, whereas making them
757 ;; from a post-command-hook doesn't pose much problems
758 (defvar diff-unhandled-changes nil)
759 (defun diff-after-change-function (beg end len)
760 "Remember to fixup the hunk header.
761 See `after-change-functions' for the meaning of BEG, END and LEN."
762 ;; Ignoring changes when inhibit-read-only is set is strictly speaking
763 ;; incorrect, but it turns out that inhibit-read-only is normally not set
764 ;; inside editing commands, while it tends to be set when the buffer gets
765 ;; updated by an async process or by a conversion function, both of which
766 ;; would rather not be uselessly slowed down by this hook.
767 (when (and (not undo-in-progress) (not inhibit-read-only))
768 (if diff-unhandled-changes
769 (setq diff-unhandled-changes
770 (cons (min beg (car diff-unhandled-changes))
771 (max beg (cdr diff-unhandled-changes))))
772 (setq diff-unhandled-changes (cons beg end)))))
773
774 (defun diff-post-command-hook ()
775 "Fixup hunk headers if necessary."
776 (when (consp diff-unhandled-changes)
777 (ignore-errors
778 (save-excursion
779 (goto-char (car diff-unhandled-changes))
780 (unless (ignore-errors
781 (diff-beginning-of-hunk)
782 (save-excursion
783 (diff-end-of-hunk)
784 (> (point) (car diff-unhandled-changes))))
785 (goto-char (car diff-unhandled-changes))
786 (re-search-forward diff-hunk-header-re (cdr diff-unhandled-changes))
787 (diff-beginning-of-hunk))
788 (diff-fixup-modifs (point) (cdr diff-unhandled-changes))))
789 (setq diff-unhandled-changes nil)))
790
791 ;;;;
792 ;;;; The main function
793 ;;;;
794
795 ;;;###autoload
796 (define-derived-mode diff-mode fundamental-mode "Diff"
797 "Major mode for viewing/editing context diffs.
798 Supports unified and context diffs as well as (to a lesser extent) normal diffs.
799 When the buffer is read-only, the ESC prefix is not necessary.
800 This mode runs `diff-mode-hook'.
801 \\{diff-mode-map}"
802 (set (make-local-variable 'font-lock-defaults) diff-font-lock-defaults)
803 (set (make-local-variable 'outline-regexp) diff-outline-regexp)
804 (set (make-local-variable 'imenu-generic-expression)
805 diff-imenu-generic-expression)
806 ;; These are not perfect. They would be better done separately for
807 ;; context diffs and unidiffs.
808 ;; (set (make-local-variable 'paragraph-start)
809 ;; (concat "@@ " ; unidiff hunk
810 ;; "\\|\\*\\*\\* " ; context diff hunk or file start
811 ;; "\\|--- [^\t]+\t")) ; context or unidiff file
812 ;; ; start (first or second line)
813 ;; (set (make-local-variable 'paragraph-separate) paragraph-start)
814 ;; (set (make-local-variable 'page-delimiter) "--- [^\t]+\t")
815 ;; compile support
816 (set (make-local-variable 'compilation-file-regexp-alist)
817 diff-file-regexp-alist)
818 (set (make-local-variable 'compilation-error-regexp-alist)
819 diff-error-regexp-alist)
820 (when (string-match "\\.rej\\'" (or buffer-file-name ""))
821 (set (make-local-variable 'compilation-current-file)
822 (substring buffer-file-name 0 (match-beginning 0))))
823 (compilation-shell-minor-mode 1)
824 ;; setup change hooks
825 (toggle-read-only t)
826 (if (not diff-update-on-the-fly-flag)
827 (add-hook 'write-contents-hooks 'diff-write-contents-hooks)
828 (make-local-variable 'diff-unhandled-changes)
829 (add-hook (make-local-hook 'after-change-functions)
830 'diff-after-change-function nil t)
831 (add-hook (make-local-hook 'post-command-hook)
832 'diff-post-command-hook nil t))
833 ;; Neat trick from Dave Love to add more bindings in read-only mode:
834 (add-to-list (make-local-variable 'minor-mode-overriding-map-alist)
835 (cons 'buffer-read-only diff-mode-shared-map))
836 ;; add-log support
837 (set (make-local-variable 'add-log-current-defun-function)
838 'diff-current-defun)
839 (set (make-local-variable 'add-log-file-name-function)
840 'diff-add-log-file-name))
841
842 ;;;###autoload
843 (define-minor-mode diff-minor-mode
844 "Minor mode for viewing/editing context diffs.
845 \\{diff-minor-mode-map}"
846 nil " Diff" nil
847 ;; FIXME: setup font-lock
848 ;; setup change hooks
849 (if (not diff-update-on-the-fly-flag)
850 (add-hook 'write-contents-hooks 'diff-write-contents-hooks)
851 (make-local-variable 'diff-unhandled-changes)
852 (add-hook (make-local-hook 'after-change-functions)
853 'diff-after-change-function nil t)
854 (add-hook (make-local-hook 'post-command-hook)
855 'diff-post-command-hook nil t)))
856
857
858 ;;;
859 ;;; Misc operations that have proved useful at some point.
860 ;;;
861
862 (defun diff-next-complex-hunk ()
863 "Jump to the next \"complex\" hunk.
864 \"Complex\" is approximated by \"the hunk changes the number of lines\".
865 Only works for unified diffs."
866 (interactive)
867 (while
868 (and (re-search-forward "^@@ [-0-9]+,\\([0-9]+\\) [+0-9]+,\\([0-9]+\\) @@"
869 nil t)
870 (equal (match-string 1) (match-string 2)))))
871
872 (defun diff-hunk-text (hunk destp &optional char-offset)
873 "Return the literal source text from HUNK.
874 if DESTP is nil return the source, otherwise the destination text.
875 If CHAR-OFFSET is non-nil, it should be a char-offset in
876 HUNK, and instead of a string, a cons cell is returned whose car is the
877 appropriate text, and whose cdr is the corresponding char-offset in that text."
878 (with-temp-buffer
879 (insert hunk)
880 (goto-char (point-min))
881 (let ((src-pos nil)
882 (dst-pos nil)
883 (divider-pos nil)
884 (num-pfx-chars 2))
885 ;; Set the following variables:
886 ;; SRC-POS buffer pos of the source part of the hunk or nil if none
887 ;; DST-POS buffer pos of the destination part of the hunk or nil
888 ;; DIVIDER-POS buffer pos of any divider line separating the src & dst
889 ;; NUM-PFX-CHARS number of line-prefix characters used by this format"
890 (cond ((looking-at "^@@")
891 ;; unified diff
892 (setq num-pfx-chars 1)
893 (forward-line 1)
894 (setq src-pos (point) dst-pos (point)))
895 ((looking-at "^\\*\\*")
896 ;; context diff
897 (forward-line 2)
898 (setq src-pos (point))
899 (re-search-forward "^--- " nil t)
900 (forward-line 0)
901 (setq divider-pos (point))
902 (forward-line 1)
903 (setq dst-pos (point)))
904 ((looking-at "^[0-9]+a[0-9,]+$")
905 ;; normal diff, insert
906 (forward-line 1)
907 (setq dst-pos (point)))
908 ((looking-at "^[0-9,]+d[0-9]+$")
909 ;; normal diff, delete
910 (forward-line 1)
911 (setq src-pos (point)))
912 ((looking-at "^[0-9,]+c[0-9,]+$")
913 ;; normal diff, change
914 (forward-line 1)
915 (setq src-pos (point))
916 (re-search-forward "^---$" nil t)
917 (forward-line 0)
918 (setq divider-pos (point))
919 (forward-line 1)
920 (setq dst-pos (point)))
921 (t
922 (error "Unknown diff hunk type")))
923 (if (if destp (null dst-pos) (null src-pos))
924 ;; Implied empty text
925 (if char-offset '("" . 0) "")
926
927 (when char-offset (goto-char (+ (point-min) char-offset)))
928
929 ;; Get rid of anything except the desired text.
930 (save-excursion
931 ;; Delete unused text region
932 (let ((keep (if destp dst-pos src-pos))
933 (kill (or divider-pos (if destp src-pos dst-pos))))
934 (when (and kill (> kill keep))
935 (delete-region kill (point-max)))
936 (delete-region (point-min) keep))
937 ;; Remove line-prefix characters, and unneeded lines (unified diffs).
938 (let ((kill-char (if destp ?- ?+)))
939 (goto-char (point-min))
940 (while (not (eobp))
941 (if (eq (char-after) kill-char)
942 (delete-region (point) (progn (forward-line 1) (point)))
943 (delete-char num-pfx-chars)
944 (forward-line 1)))))
945
946 (let ((text (buffer-substring-no-properties (point-min) (point-max))))
947 (if char-offset (cons text (- (point) (point-min))) text))))))
948
949
950 (defun diff-find-text (text)
951 "Return the buffer position of the nearest occurrence of TEXT.
952 If TEXT isn't found, nil is returned."
953 (let* ((orig (point))
954 (forw (and (search-forward text nil t)
955 (match-beginning 0)))
956 (back (and (goto-char (+ orig (length text)))
957 (search-backward text nil t)
958 (match-beginning 0))))
959 ;; Choose the closest match.
960 (if (and forw back)
961 (if (> (- forw orig) (- orig back)) back forw)
962 (or back forw))))
963
964 (defsubst diff-xor (a b) (if a (not b) b))
965
966 (defun diff-find-source-location (&optional other-file reverse)
967 "Find out (BUF LINE-OFFSET POS SRC DST SWITCHED)."
968 (save-excursion
969 (let* ((other (diff-xor other-file diff-jump-to-old-file-flag))
970 (char-offset (- (point) (progn (diff-beginning-of-hunk) (point))))
971 (hunk (buffer-substring (point)
972 (save-excursion (diff-end-of-hunk) (point))))
973 (old (diff-hunk-text hunk reverse char-offset))
974 (new (diff-hunk-text hunk (not reverse) char-offset))
975 ;; Find the location specification.
976 (line (if (not (looking-at "\\(?:\\*\\{15\\}.*\n\\)?[-@* ]*\\([0-9,]+\\)\\([ acd+]+\\([0-9,]+\\)\\)?"))
977 (error "Can't find the hunk header")
978 (if other (match-string 1)
979 (if (match-end 3) (match-string 3)
980 (unless (re-search-forward "^--- \\([0-9,]+\\)" nil t)
981 (error "Can't find the hunk separator"))
982 (match-string 1)))))
983 (file (or (diff-find-file-name other) (error "Can't find the file")))
984 (buf (find-file-noselect file)))
985 ;; Update the user preference if he so wished.
986 (when (> (prefix-numeric-value other-file) 8)
987 (setq diff-jump-to-old-file-flag other))
988 (with-current-buffer buf
989 (goto-line (string-to-number line))
990 (let* ((orig-pos (point))
991 (pos (diff-find-text (car old)))
992 (switched nil))
993 (when (null pos)
994 (setq pos (diff-find-text (car new)) switched t))
995 (nconc
996 (list buf)
997 (if pos (list (count-lines orig-pos pos) pos) (list nil orig-pos))
998 (if switched (list new old t) (list old new))))))))
999
1000
1001 (defun diff-hunk-status-msg (line-offset reversed dry-run)
1002 (let ((msg (if dry-run
1003 (if reversed "already applied" "not yet applied")
1004 (if reversed "undone" "applied"))))
1005 (message (cond ((null line-offset) "Hunk text not found")
1006 ((= line-offset 0) "Hunk %s")
1007 ((= line-offset 1) "Hunk %s at offset %d line")
1008 (t "Hunk %s at offset %d lines"))
1009 msg line-offset)))
1010
1011
1012 (defun diff-apply-hunk (&optional reverse)
1013 "Apply the current hunk to the source file.
1014 By default, the new source file is patched, but if the variable
1015 `diff-jump-to-old-file-flag' is non-nil, then the old source file is
1016 patched instead (some commands, such as `diff-goto-source' can change
1017 the value of this variable when given an appropriate prefix argument).
1018
1019 With a prefix argument, REVERSE the hunk.
1020
1021 Return value is t if the hunk was sucessfully applied, `reversed' if the
1022 hunk was applied backwards and nil if the hunk wasn't applied."
1023 (interactive "P")
1024 (destructuring-bind (buf line-offset pos old new &optional switched)
1025 (diff-find-source-location nil reverse)
1026 (cond
1027 ((null line-offset) (error "Can't find the text to patch"))
1028 ((and switched
1029 ;; A reversed patch was detected, perhaps apply it in reverse
1030 (not (save-window-excursion
1031 (pop-to-buffer buf)
1032 (goto-char (+ pos (cdr old)))
1033 (y-or-n-p
1034 (if reverse
1035 "Hunk hasn't been applied yet; apply it now? "
1036 "Hunk has already been applied; undo it? ")))))
1037 (message "(Nothing done)"))
1038 (t
1039 (let ((reversed (diff-xor switched reverse)))
1040 ;; Apply the hunk
1041 (with-current-buffer buf
1042 (goto-char pos)
1043 (delete-char (length (car old)))
1044 (insert (car new)))
1045 ;; Display BUF in a window
1046 (let ((win (display-buffer buf)))
1047 (set-window-point win (+ pos (cdr new))))
1048 (diff-hunk-status-msg line-offset reversed nil)
1049 (if reversed 'reversed t))))))
1050
1051
1052 (defun diff-test-hunk (&optional reverse)
1053 ;; FIXME: is `reverse' ever useful ???
1054 "See whether it's possible to apply the current hunk.
1055 With a prefix argument, try to REVERSE the hunk.
1056 Returns t if the hunk can be applied, `reversed' if it's already
1057 applied and nil if it can't be found."
1058 (interactive "P")
1059 (destructuring-bind (buf line-offset pos src dst &optional switched)
1060 (diff-find-source-location nil reverse)
1061 (let ((win (display-buffer buf)))
1062 (set-window-point win (+ pos (cdr src))))
1063 (diff-hunk-status-msg line-offset (diff-xor reverse switched) t)))
1064
1065
1066 (defun diff-goto-source (&optional other-file)
1067 "Jump to the corresponding source line.
1068 `diff-jump-to-old-file-flag' (or its opposite if the OTHER-FILE prefix arg
1069 is given) determines whether to jump to the old or the new file.
1070 If the prefix arg is bigger than 8 (for example with \\[universal-argument] \\[universal-argument])
1071 then `diff-jump-to-old-file-flag' is also set, for the next invocations."
1072 (interactive "P")
1073 (destructuring-bind (buf line-offset pos src dst &optional switched)
1074 ;; We normally jump to the NEW file, where the hunk should already
1075 ;; be applied, so favor the `reverse'.
1076 (diff-find-source-location other-file t)
1077 (pop-to-buffer buf)
1078 (goto-char (+ pos (cdr src)))
1079 (unless line-offset (message "Hunk text not found"))))
1080
1081
1082 (defun diff-current-defun ()
1083 "Find the name of function at point.
1084 For use in `add-log-current-defun-function'."
1085 (destructuring-bind (buf line-offset pos src dst &optional switched)
1086 (diff-find-source-location)
1087 (save-excursion
1088 (beginning-of-line)
1089 (or (when (memq (char-after) '(?< ?-))
1090 ;; Cursor is pointing at removed text. This could be a removed
1091 ;; function, in which case, going to the source buffer will
1092 ;; not help since the function is now removed. Instead,
1093 ;; try to figure out the function name just from the code-fragment.
1094 (let ((old (if switched dst src)))
1095 (with-temp-buffer
1096 (insert (car old))
1097 (goto-char (cdr old))
1098 (funcall (with-current-buffer buf major-mode))
1099 (add-log-current-defun))))
1100 (with-current-buffer buf
1101 (goto-char (+ pos (cdr src)))
1102 (add-log-current-defun))))))
1103
1104 ;; provide the package
1105 (provide 'diff-mode)
1106
1107 ;;; Old Change Log from when diff-mode wasn't part of Emacs:
1108 ;; Revision 1.11 1999/10/09 23:38:29 monnier
1109 ;; (diff-mode-load-hook): dropped.
1110 ;; (auto-mode-alist): also catch *.diffs.
1111 ;; (diff-find-file-name, diff-mode): add smarts to find the right file
1112 ;; for *.rej files (that lack any file name indication).
1113 ;;
1114 ;; Revision 1.10 1999/09/30 15:32:11 monnier
1115 ;; added support for "\ No newline at end of file".
1116 ;;
1117 ;; Revision 1.9 1999/09/15 00:01:13 monnier
1118 ;; - added basic `compile' support.
1119 ;; - have diff-kill-hunk call diff-kill-file if it's the only hunk.
1120 ;; - diff-kill-file now tries to kill the leading garbage as well.
1121 ;;
1122 ;; Revision 1.8 1999/09/13 21:10:09 monnier
1123 ;; - don't use CL in the autoloaded code
1124 ;; - accept diffs using -T
1125 ;;
1126 ;; Revision 1.7 1999/09/05 20:53:03 monnier
1127 ;; interface to ediff-patch
1128 ;;
1129 ;; Revision 1.6 1999/09/01 20:55:13 monnier
1130 ;; (ediff=patch-file): add bindings to call ediff-patch.
1131 ;; (diff-find-file-name): taken out of diff-goto-source.
1132 ;; (diff-unified->context, diff-context->unified, diff-reverse-direction,
1133 ;; diff-fixup-modifs): only use the region if a prefix arg is given.
1134 ;;
1135 ;; Revision 1.5 1999/08/31 19:18:52 monnier
1136 ;; (diff-beginning-of-file, diff-prev-file): fixed wrong parenthesis.
1137 ;;
1138 ;; Revision 1.4 1999/08/31 13:01:44 monnier
1139 ;; use `combine-after-change-calls' to minimize the slowdown of font-lock.
1140 ;;
1141
1142 ;;; diff-mode.el ends here