]> code.delx.au - gnu-emacs/blob - lisp/diff-mode.el
Merge from emacs--devo--0
[gnu-emacs] / lisp / diff-mode.el
1 ;;; diff-mode.el --- a mode for viewing/editing context diffs
2
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
5
6 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
7 ;; Keywords: convenience patch diff
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 3, 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., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;; Provides support for font-lock, outline, 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 ;; Bugs:
37
38 ;; - Reverse doesn't work with normal diffs.
39
40 ;; Todo:
41
42 ;; - Add a `delete-after-apply' so C-c C-a automatically deletes hunks.
43 ;; Also allow C-c C-a to delete already-applied hunks.
44 ;;
45 ;; - Try `diff <file> <hunk>' to try and fuzzily discover the source location
46 ;; of a hunk. Show then the changes between <file> and <hunk> and make it
47 ;; possible to apply them to <file>, <hunk-src>, or <hunk-dst>.
48 ;; Or maybe just make it into a ".rej to diff3-markers converter".
49 ;; Maybe just use `wiggle' (by Neil Brown) to do it for us.
50 ;;
51 ;; - Refine hunk on a word-by-word basis.
52 ;;
53 ;; - in diff-apply-hunk, strip context in replace-match to better
54 ;; preserve markers and spacing.
55 ;; - Handle `diff -b' output in context->unified.
56
57 ;;; Code:
58 (eval-when-compile (require 'cl))
59
60 (defvar add-log-buffer-file-name-function)
61
62
63 (defgroup diff-mode ()
64 "Major mode for viewing/editing diffs."
65 :version "21.1"
66 :group 'tools
67 :group 'diff)
68
69 (defcustom diff-default-read-only nil
70 "If non-nil, `diff-mode' buffers default to being read-only."
71 :type 'boolean
72 :group 'diff-mode)
73
74 (defcustom diff-jump-to-old-file nil
75 "Non-nil means `diff-goto-source' jumps to the old file.
76 Else, it jumps to the new file."
77 :type 'boolean
78 :group 'diff-mode)
79
80 (defcustom diff-update-on-the-fly t
81 "*Non-nil means hunk headers are kept up-to-date on-the-fly.
82 When editing a diff file, the line numbers in the hunk headers
83 need to be kept consistent with the actual diff. This can
84 either be done on the fly (but this sometimes interacts poorly with the
85 undo mechanism) or whenever the file is written (can be slow
86 when editing big diffs)."
87 :type 'boolean
88 :group 'diff-mode)
89
90 (defcustom diff-advance-after-apply-hunk t
91 "*Non-nil means `diff-apply-hunk' will move to the next hunk after applying."
92 :type 'boolean
93 :group 'diff-mode)
94
95
96 (defcustom diff-mode-hook nil
97 "Run after setting up the `diff-mode' major mode."
98 :type 'hook
99 :options '(diff-delete-empty-files diff-make-unified)
100 :group 'diff-mode)
101
102 (defvar diff-outline-regexp
103 "\\([*+][*+][*+] [^0-9]\\|@@ ...\\|\\*\\*\\* [0-9].\\|--- [0-9]..\\)")
104
105 ;;;;
106 ;;;; keymap, menu, ...
107 ;;;;
108
109 (easy-mmode-defmap diff-mode-shared-map
110 '(;; From Pavel Machek's patch-mode.
111 ("n" . diff-hunk-next)
112 ("N" . diff-file-next)
113 ("p" . diff-hunk-prev)
114 ("P" . diff-file-prev)
115 ("k" . diff-hunk-kill)
116 ("K" . diff-file-kill)
117 ;; From compilation-minor-mode.
118 ("}" . diff-file-next)
119 ("{" . diff-file-prev)
120 ("\C-m" . diff-goto-source)
121 ([mouse-2] . diff-goto-source)
122 ;; From XEmacs' diff-mode.
123 ;; Standard M-w is useful, so don't change M-W.
124 ;;("W" . widen)
125 ;;("." . diff-goto-source) ;display-buffer
126 ;;("f" . diff-goto-source) ;find-file
127 ("o" . diff-goto-source) ;other-window
128 ;;("w" . diff-goto-source) ;other-frame
129 ;;("N" . diff-narrow)
130 ;;("h" . diff-show-header)
131 ;;("j" . diff-show-difference) ;jump to Nth diff
132 ;;("q" . diff-quit)
133 ;; Not useful if you have to metafy them.
134 ;;(" " . scroll-up)
135 ;;("\177" . scroll-down)
136 ;; Standard M-a is useful, so don't change M-A.
137 ;;("A" . diff-ediff-patch)
138 ;; Standard M-r is useful, so don't change M-r or M-R.
139 ;;("r" . diff-restrict-view)
140 ;;("R" . diff-reverse-direction)
141 ("q" . quit-window))
142 "Basic keymap for `diff-mode', bound to various prefix keys.")
143
144 (easy-mmode-defmap diff-mode-map
145 `(("\e" . ,diff-mode-shared-map)
146 ;; From compilation-minor-mode.
147 ("\C-c\C-c" . diff-goto-source)
148 ;; Misc operations.
149 ("\C-c\C-a" . diff-apply-hunk)
150 ("\C-c\C-e" . diff-ediff-patch)
151 ("\C-c\C-n" . diff-restrict-view)
152 ("\C-c\C-r" . diff-reverse-direction)
153 ("\C-c\C-s" . diff-split-hunk)
154 ("\C-c\C-t" . diff-test-hunk)
155 ("\C-c\C-u" . diff-context->unified)
156 ;; `d' because it duplicates the context :-( --Stef
157 ("\C-c\C-d" . diff-unified->context)
158 ("\C-c\C-w" . diff-refine-ignore-spaces-hunk)
159 ("\C-c\C-f" . next-error-follow-minor-mode))
160 "Keymap for `diff-mode'. See also `diff-mode-shared-map'.")
161
162 (easy-menu-define diff-mode-menu diff-mode-map
163 "Menu for `diff-mode'."
164 '("Diff"
165 ["Jump to Source" diff-goto-source t]
166 ["Apply hunk" diff-apply-hunk t]
167 ["Test applying hunk" diff-test-hunk t]
168 ["Apply diff with Ediff" diff-ediff-patch t]
169 "-----"
170 ["Reverse direction" diff-reverse-direction t]
171 ["Context -> Unified" diff-context->unified t]
172 ["Unified -> Context" diff-unified->context t]
173 ;;["Fixup Headers" diff-fixup-modifs (not buffer-read-only)]
174 "-----"
175 ["Split hunk" diff-split-hunk (diff-splittable-p)]
176 ["Refine hunk" diff-refine-ignore-spaces-hunk t]
177 ["Kill current hunk" diff-hunk-kill t]
178 ["Kill current file's hunks" diff-file-kill t]
179 "-----"
180 ["Previous Hunk" diff-hunk-prev t]
181 ["Next Hunk" diff-hunk-next t]
182 ["Previous File" diff-file-prev t]
183 ["Next File" diff-file-next t]
184 ))
185
186 (defcustom diff-minor-mode-prefix "\C-c="
187 "Prefix key for `diff-minor-mode' commands."
188 :type '(choice (string "\e") (string "C-c=") string)
189 :group 'diff-mode)
190
191 (easy-mmode-defmap diff-minor-mode-map
192 `((,diff-minor-mode-prefix . ,diff-mode-shared-map))
193 "Keymap for `diff-minor-mode'. See also `diff-mode-shared-map'.")
194
195
196 ;;;;
197 ;;;; font-lock support
198 ;;;;
199
200 (defface diff-header
201 '((((class color) (min-colors 88) (background light))
202 :background "grey85")
203 (((class color) (min-colors 88) (background dark))
204 :background "grey45")
205 (((class color) (background light))
206 :foreground "blue1" :weight bold)
207 (((class color) (background dark))
208 :foreground "green" :weight bold)
209 (t :weight bold))
210 "`diff-mode' face inherited by hunk and index header faces."
211 :group 'diff-mode)
212 ;; backward-compatibility alias
213 (put 'diff-header-face 'face-alias 'diff-header)
214 (defvar diff-header-face 'diff-header)
215
216 (defface diff-file-header
217 '((((class color) (min-colors 88) (background light))
218 :background "grey70" :weight bold)
219 (((class color) (min-colors 88) (background dark))
220 :background "grey60" :weight bold)
221 (((class color) (background light))
222 :foreground "green" :weight bold)
223 (((class color) (background dark))
224 :foreground "cyan" :weight bold)
225 (t :weight bold)) ; :height 1.3
226 "`diff-mode' face used to highlight file header lines."
227 :group 'diff-mode)
228 ;; backward-compatibility alias
229 (put 'diff-file-header-face 'face-alias 'diff-file-header)
230 (defvar diff-file-header-face 'diff-file-header)
231
232 (defface diff-index
233 '((t :inherit diff-file-header))
234 "`diff-mode' face used to highlight index header lines."
235 :group 'diff-mode)
236 ;; backward-compatibility alias
237 (put 'diff-index-face 'face-alias 'diff-index)
238 (defvar diff-index-face 'diff-index)
239
240 (defface diff-hunk-header
241 '((t :inherit diff-header))
242 "`diff-mode' face used to highlight hunk header lines."
243 :group 'diff-mode)
244 ;; backward-compatibility alias
245 (put 'diff-hunk-header-face 'face-alias 'diff-hunk-header)
246 (defvar diff-hunk-header-face 'diff-hunk-header)
247
248 (defface diff-removed
249 '((t :inherit diff-changed))
250 "`diff-mode' face used to highlight removed lines."
251 :group 'diff-mode)
252 ;; backward-compatibility alias
253 (put 'diff-removed-face 'face-alias 'diff-removed)
254 (defvar diff-removed-face 'diff-removed)
255
256 (defface diff-added
257 '((t :inherit diff-changed))
258 "`diff-mode' face used to highlight added lines."
259 :group 'diff-mode)
260 ;; backward-compatibility alias
261 (put 'diff-added-face 'face-alias 'diff-added)
262 (defvar diff-added-face 'diff-added)
263
264 (defface diff-changed
265 '((((type tty pc) (class color) (background light))
266 :foreground "magenta" :weight bold :slant italic)
267 (((type tty pc) (class color) (background dark))
268 :foreground "yellow" :weight bold :slant italic))
269 "`diff-mode' face used to highlight changed lines."
270 :group 'diff-mode)
271 ;; backward-compatibility alias
272 (put 'diff-changed-face 'face-alias 'diff-changed)
273 (defvar diff-changed-face 'diff-changed)
274
275 (defface diff-indicator-removed
276 '((t :inherit diff-removed))
277 "`diff-mode' face used to highlight indicator of removed lines (-, <)."
278 :group 'diff-mode
279 :version "22.1")
280 (defvar diff-indicator-removed-face 'diff-indicator-removed)
281
282 (defface diff-indicator-added
283 '((t :inherit diff-added))
284 "`diff-mode' face used to highlight indicator of added lines (+, >)."
285 :group 'diff-mode
286 :version "22.1")
287 (defvar diff-indicator-added-face 'diff-indicator-added)
288
289 (defface diff-indicator-changed
290 '((t :inherit diff-changed))
291 "`diff-mode' face used to highlight indicator of changed lines."
292 :group 'diff-mode
293 :version "22.1")
294 (defvar diff-indicator-changed-face 'diff-indicator-changed)
295
296 (defface diff-function
297 '((t :inherit diff-header))
298 "`diff-mode' face used to highlight function names produced by \"diff -p\"."
299 :group 'diff-mode)
300 ;; backward-compatibility alias
301 (put 'diff-function-face 'face-alias 'diff-function)
302 (defvar diff-function-face 'diff-function)
303
304 (defface diff-context
305 '((((class color grayscale) (min-colors 88)) :inherit shadow))
306 "`diff-mode' face used to highlight context and other side-information."
307 :group 'diff-mode)
308 ;; backward-compatibility alias
309 (put 'diff-context-face 'face-alias 'diff-context)
310 (defvar diff-context-face 'diff-context)
311
312 (defface diff-nonexistent
313 '((t :inherit diff-file-header))
314 "`diff-mode' face used to highlight nonexistent files in recursive diffs."
315 :group 'diff-mode)
316 ;; backward-compatibility alias
317 (put 'diff-nonexistent-face 'face-alias 'diff-nonexistent)
318 (defvar diff-nonexistent-face 'diff-nonexistent)
319
320 (defconst diff-yank-handler '(diff-yank-function))
321 (defun diff-yank-function (text)
322 ;; FIXME: the yank-handler is now called separately on each piece of text
323 ;; with a yank-handler property, so the next-single-property-change call
324 ;; below will always return nil :-( --stef
325 (let ((mixed (next-single-property-change 0 'yank-handler text))
326 (start (point)))
327 ;; First insert the text.
328 (insert text)
329 ;; If the text does not include any diff markers and if we're not
330 ;; yanking back into a diff-mode buffer, get rid of the prefixes.
331 (unless (or mixed (derived-mode-p 'diff-mode))
332 (undo-boundary) ; Just in case the user wanted the prefixes.
333 (let ((re (save-excursion
334 (if (re-search-backward "^[><!][ \t]" start t)
335 (if (eq (char-after) ?!)
336 "^[!+- ][ \t]" "^[<>][ \t]")
337 "^[ <>!+-]"))))
338 (save-excursion
339 (while (re-search-backward re start t)
340 (replace-match "" t t)))))))
341
342
343 (defvar diff-font-lock-keywords
344 `(("^\\(@@ -[0-9,]+ \\+[0-9,]+ @@\\)\\(.*\\)$" ;unified
345 (1 diff-hunk-header-face) (2 diff-function-face))
346 ("^\\(\\*\\{15\\}\\)\\(.*\\)$" ;context
347 (1 diff-hunk-header-face) (2 diff-function-face))
348 ("^\\*\\*\\* .+ \\*\\*\\*\\*". diff-hunk-header-face) ;context
349 ("^--- .+ ----$" . diff-hunk-header-face) ;context
350 ("^[0-9,]+[acd][0-9,]+$" . diff-hunk-header-face) ;normal
351 ("^---$" . diff-hunk-header-face) ;normal
352 ;; For file headers, accept files with spaces, but be careful to rule
353 ;; out false-positives when matching hunk headers.
354 ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) \\([^\t\n]+?\\)\\(?:\t.*\\| \\(\\*\\*\\*\\*\\|----\\)\\)?\n"
355 (0 diff-header-face)
356 (2 (if (not (match-end 3)) diff-file-header-face) prepend))
357 ("^\\([-<]\\)\\(.*\n\\)"
358 (1 diff-indicator-removed-face) (2 diff-removed-face))
359 ("^\\([+>]\\)\\(.*\n\\)"
360 (1 diff-indicator-added-face) (2 diff-added-face))
361 ("^\\(!\\)\\(.*\n\\)"
362 (1 diff-indicator-changed-face) (2 diff-changed-face))
363 ("^Index: \\(.+\\).*\n"
364 (0 diff-header-face) (1 diff-index-face prepend))
365 ("^Only in .*\n" . diff-nonexistent-face)
366 ("^\\(#\\)\\(.*\\)"
367 (1 font-lock-comment-delimiter-face)
368 (2 font-lock-comment-face))
369 ("^[^-=+*!<>#].*\n" (0 diff-context-face))))
370
371 (defconst diff-font-lock-defaults
372 '(diff-font-lock-keywords t nil nil nil (font-lock-multiline . nil)))
373
374 (defvar diff-imenu-generic-expression
375 ;; Prefer second name as first is most likely to be a backup or
376 ;; version-control name. The [\t\n] at the end of the unidiff pattern
377 ;; catches Debian source diff files (which lack the trailing date).
378 '((nil "\\+\\+\\+\\ \\([^\t\n]+\\)[\t\n]" 1) ; unidiffs
379 (nil "^--- \\([^\t\n]+\\)\t.*\n\\*" 1))) ; context diffs
380
381 ;;;;
382 ;;;; Movement
383 ;;;;
384
385 (defconst diff-hunk-header-re "^\\(@@ -[0-9,]+ \\+[0-9,]+ @@.*\\|\\*\\{15\\}.*\n\\*\\*\\* .+ \\*\\*\\*\\*\\|[0-9]+\\(,[0-9]+\\)?[acd][0-9]+\\(,[0-9]+\\)?\\)$")
386 (defconst diff-file-header-re (concat "^\\(--- .+\n\\+\\+\\+ \\|\\*\\*\\* .+\n--- \\|[^-+!<>0-9@* ]\\).+\n" (substring diff-hunk-header-re 1)))
387 (defvar diff-narrowed-to nil)
388
389 (defun diff-end-of-hunk (&optional style)
390 (when (looking-at diff-hunk-header-re)
391 (unless style
392 ;; Especially important for unified (because headers are ambiguous).
393 (setq style (cdr (assq (char-after) '((?@ . unified) (?* . context))))))
394 (goto-char (match-end 0)))
395 (let ((end (and (re-search-forward (case style
396 ;; A `unified' header is ambiguous.
397 (unified (concat "^[^-+# \\]\\|"
398 diff-file-header-re))
399 (context "^[^-+#! \\]")
400 (normal "^[^<>#\\]")
401 (t "^[^-+#!<> \\]"))
402 nil t)
403 (match-beginning 0))))
404 ;; The return value is used by easy-mmode-define-navigation.
405 (goto-char (or end (point-max)))))
406
407 (defun diff-beginning-of-hunk (&optional try-harder)
408 "Move back to beginning of hunk.
409 If TRY-HARDER is non-nil, try to cater to the case where we're not in a hunk
410 but in the file header instead, in which case move forward to the first hunk."
411 (beginning-of-line)
412 (unless (looking-at diff-hunk-header-re)
413 (forward-line 1)
414 (condition-case ()
415 (re-search-backward diff-hunk-header-re)
416 (error
417 (if (not try-harder)
418 (error "Can't find the beginning of the hunk")
419 (diff-beginning-of-file-and-junk)
420 (diff-hunk-next))))))
421
422 (defun diff-unified-hunk-p ()
423 (save-excursion
424 (ignore-errors
425 (diff-beginning-of-hunk)
426 (looking-at "^@@"))))
427
428 (defun diff-beginning-of-file ()
429 (beginning-of-line)
430 (unless (looking-at diff-file-header-re)
431 (let ((start (point))
432 res)
433 ;; diff-file-header-re may need to match up to 4 lines, so in case
434 ;; we're inside the header, we need to move up to 3 lines forward.
435 (forward-line 3)
436 (if (and (setq res (re-search-backward diff-file-header-re nil t))
437 ;; Maybe the 3 lines forward were too much and we matched
438 ;; a file header after our starting point :-(
439 (or (<= (point) start)
440 (setq res (re-search-backward diff-file-header-re nil t))))
441 res
442 (goto-char start)
443 (error "Can't find the beginning of the file")))))
444
445
446 (defun diff-end-of-file ()
447 (re-search-forward "^[-+#!<>0-9@* \\]" nil t)
448 (re-search-forward (concat "^[^-+#!<>0-9@* \\]\\|" diff-file-header-re)
449 nil 'move)
450 (if (match-beginning 1)
451 (goto-char (match-beginning 1))
452 (beginning-of-line)))
453
454 ;; Define diff-{hunk,file}-{prev,next}
455 (easy-mmode-define-navigation
456 diff-hunk diff-hunk-header-re "hunk" diff-end-of-hunk diff-restrict-view)
457 (easy-mmode-define-navigation
458 diff-file diff-file-header-re "file" diff-end-of-hunk)
459
460 (defun diff-restrict-view (&optional arg)
461 "Restrict the view to the current hunk.
462 If the prefix ARG is given, restrict the view to the current file instead."
463 (interactive "P")
464 (save-excursion
465 (if arg (diff-beginning-of-file) (diff-beginning-of-hunk 'try-harder))
466 (narrow-to-region (point)
467 (progn (if arg (diff-end-of-file) (diff-end-of-hunk))
468 (point)))
469 (set (make-local-variable 'diff-narrowed-to) (if arg 'file 'hunk))))
470
471
472 (defun diff-hunk-kill ()
473 "Kill current hunk."
474 (interactive)
475 (diff-beginning-of-hunk)
476 (let* ((start (point))
477 (nexthunk (when (re-search-forward diff-hunk-header-re nil t)
478 (match-beginning 0)))
479 (firsthunk (ignore-errors
480 (goto-char start)
481 (diff-beginning-of-file) (diff-hunk-next) (point)))
482 (nextfile (ignore-errors (diff-file-next) (point)))
483 (inhibit-read-only t))
484 (goto-char start)
485 (if (and firsthunk (= firsthunk start)
486 (or (null nexthunk)
487 (and nextfile (> nexthunk nextfile))))
488 ;; It's the only hunk for this file, so kill the file.
489 (diff-file-kill)
490 (diff-end-of-hunk)
491 (kill-region start (point)))))
492
493 (defun diff-beginning-of-file-and-junk ()
494 "Go to the beginning of file-related diff-info.
495 This is like `diff-beginning-of-file' except it tries to skip back over leading
496 data such as \"Index: ...\" and such."
497 (let* ((start (point))
498 (prevfile (condition-case err
499 (save-excursion (diff-beginning-of-file) (point))
500 (error err)))
501 (err (if (consp prevfile) prevfile))
502 (nextfile (ignore-errors
503 (save-excursion
504 (goto-char start) (diff-file-next) (point))))
505 ;; prevhunk is one of the limits.
506 (prevhunk (save-excursion
507 (ignore-errors
508 (if (numberp prevfile) (goto-char prevfile))
509 (diff-hunk-prev) (point))))
510 (previndex (save-excursion
511 (re-search-backward "^Index: " prevhunk t))))
512 ;; If we're in the junk, we should use nextfile instead of prevfile.
513 (if (and (numberp nextfile)
514 (or (not (numberp prevfile))
515 (and previndex (> previndex prevfile))))
516 (setq prevfile nextfile))
517 (if (and previndex (numberp prevfile) (< previndex prevfile))
518 (setq prevfile previndex))
519 (if (and (numberp prevfile) (<= prevfile start))
520 (goto-char prevfile)
521 ;; File starts *after* the starting point: we really weren't in
522 ;; a file diff but elsewhere.
523 (goto-char start)
524 (signal (car err) (cdr err)))))
525
526 (defun diff-file-kill ()
527 "Kill current file's hunks."
528 (interactive)
529 (diff-beginning-of-file-and-junk)
530 (let* ((start (point))
531 (inhibit-read-only t))
532 (diff-end-of-file)
533 (if (looking-at "^\n") (forward-char 1)) ;`tla' generates such diffs.
534 (kill-region start (point))))
535
536 (defun diff-kill-junk ()
537 "Kill spurious empty diffs."
538 (interactive)
539 (save-excursion
540 (let ((inhibit-read-only t))
541 (goto-char (point-min))
542 (while (re-search-forward (concat "^\\(Index: .*\n\\)"
543 "\\([^-+!* <>].*\n\\)*?"
544 "\\(\\(Index:\\) \\|"
545 diff-file-header-re "\\)")
546 nil t)
547 (delete-region (if (match-end 4) (match-beginning 0) (match-end 1))
548 (match-beginning 3))
549 (beginning-of-line)))))
550
551 (defun diff-count-matches (re start end)
552 (save-excursion
553 (let ((n 0))
554 (goto-char start)
555 (while (re-search-forward re end t) (incf n))
556 n)))
557
558 (defun diff-splittable-p ()
559 (save-excursion
560 (beginning-of-line)
561 (and (looking-at "^[-+ ]")
562 (progn (forward-line -1) (looking-at "^[-+ ]"))
563 (diff-unified-hunk-p))))
564
565 (defun diff-split-hunk ()
566 "Split the current (unified diff) hunk at point into two hunks."
567 (interactive)
568 (beginning-of-line)
569 (let ((pos (point))
570 (start (progn (diff-beginning-of-hunk) (point))))
571 (unless (looking-at "@@ -\\([0-9]+\\),[0-9]+ \\+\\([0-9]+\\),[0-9]+ @@")
572 (error "diff-split-hunk only works on unified context diffs"))
573 (forward-line 1)
574 (let* ((start1 (string-to-number (match-string 1)))
575 (start2 (string-to-number (match-string 2)))
576 (newstart1 (+ start1 (diff-count-matches "^[- \t]" (point) pos)))
577 (newstart2 (+ start2 (diff-count-matches "^[+ \t]" (point) pos)))
578 (inhibit-read-only t))
579 (goto-char pos)
580 ;; Hopefully the after-change-function will not screw us over.
581 (insert "@@ -" (number-to-string newstart1) ",1 +"
582 (number-to-string newstart2) ",1 @@\n")
583 ;; Fix the original hunk-header.
584 (diff-fixup-modifs start pos))))
585
586
587 ;;;;
588 ;;;; jump to other buffers
589 ;;;;
590
591 (defvar diff-remembered-files-alist nil)
592
593 (defun diff-filename-drop-dir (file)
594 (when (string-match "/" file) (substring file (match-end 0))))
595
596 (defun diff-merge-strings (ancestor from to)
597 "Merge the diff between ANCESTOR and FROM into TO.
598 Returns the merged string if successful or nil otherwise.
599 The strings are assumed not to contain any \"\\n\" (i.e. end of line).
600 If ANCESTOR = FROM, returns TO.
601 If ANCESTOR = TO, returns FROM.
602 The heuristic is simplistic and only really works for cases
603 like \(diff-merge-strings \"b/foo\" \"b/bar\" \"/a/c/foo\")."
604 ;; Ideally, we want:
605 ;; AMB ANB CMD -> CND
606 ;; but that's ambiguous if `foo' or `bar' is empty:
607 ;; a/foo a/foo1 b/foo.c -> b/foo1.c but not 1b/foo.c or b/foo.c1
608 (let ((str (concat ancestor "\n" from "\n" to)))
609 (when (and (string-match (concat
610 "\\`\\(.*?\\)\\(.*\\)\\(.*\\)\n"
611 "\\1\\(.*\\)\\3\n"
612 "\\(.*\\(\\2\\).*\\)\\'") str)
613 (equal to (match-string 5 str)))
614 (concat (substring str (match-beginning 5) (match-beginning 6))
615 (match-string 4 str)
616 (substring str (match-end 6) (match-end 5))))))
617
618 (defun diff-tell-file-name (old name)
619 "Tell Emacs where the find the source file of the current hunk.
620 If the OLD prefix arg is passed, tell the file NAME of the old file."
621 (interactive
622 (let* ((old current-prefix-arg)
623 (fs (diff-hunk-file-names current-prefix-arg)))
624 (unless fs (error "No file name to look for"))
625 (list old (read-file-name (format "File for %s: " (car fs))
626 nil (diff-find-file-name old) t))))
627 (let ((fs (diff-hunk-file-names old)))
628 (unless fs (error "No file name to look for"))
629 (push (cons fs name) diff-remembered-files-alist)))
630
631 (defun diff-hunk-file-names (&optional old)
632 "Give the list of file names textually mentioned for the current hunk."
633 (save-excursion
634 (unless (looking-at diff-file-header-re)
635 (or (ignore-errors (diff-beginning-of-file))
636 (re-search-forward diff-file-header-re nil t)))
637 (let ((limit (save-excursion
638 (condition-case ()
639 (progn (diff-hunk-prev) (point))
640 (error (point-min)))))
641 (header-files
642 (if (looking-at "[-*][-*][-*] \\(\\S-+\\)\\(\\s-.*\\)?\n[-+][-+][-+] \\(\\S-+\\)")
643 (list (if old (match-string 1) (match-string 3))
644 (if old (match-string 3) (match-string 1)))
645 (forward-line 1) nil)))
646 (delq nil
647 (append
648 (when (and (not old)
649 (save-excursion
650 (re-search-backward "^Index: \\(.+\\)" limit t)))
651 (list (match-string 1)))
652 header-files
653 (when (re-search-backward
654 "^diff \\(-\\S-+ +\\)*\\(\\S-+\\)\\( +\\(\\S-+\\)\\)?"
655 nil t)
656 (list (if old (match-string 2) (match-string 4))
657 (if old (match-string 4) (match-string 2)))))))))
658
659 (defun diff-find-file-name (&optional old batch prefix)
660 "Return the file corresponding to the current patch.
661 Non-nil OLD means that we want the old file.
662 Non-nil BATCH means to prefer returning an incorrect answer than to prompt
663 the user.
664 PREFIX is only used internally: don't use it."
665 (save-excursion
666 (unless (looking-at diff-file-header-re)
667 (or (ignore-errors (diff-beginning-of-file))
668 (re-search-forward diff-file-header-re nil t)))
669 (let ((fs (diff-hunk-file-names old)))
670 (if prefix (setq fs (mapcar (lambda (f) (concat prefix f)) fs)))
671 (or
672 ;; use any previously used preference
673 (cdr (assoc fs diff-remembered-files-alist))
674 ;; try to be clever and use previous choices as an inspiration
675 (dolist (rf diff-remembered-files-alist)
676 (let ((newfile (diff-merge-strings (caar rf) (car fs) (cdr rf))))
677 (if (and newfile (file-exists-p newfile)) (return newfile))))
678 ;; look for each file in turn. If none found, try again but
679 ;; ignoring the first level of directory, ...
680 (do* ((files fs (delq nil (mapcar 'diff-filename-drop-dir files)))
681 (file nil nil))
682 ((or (null files)
683 (setq file (do* ((files files (cdr files))
684 (file (car files) (car files)))
685 ;; Use file-regular-p to avoid
686 ;; /dev/null, directories, etc.
687 ((or (null file) (file-regular-p file))
688 file))))
689 file))
690 ;; <foo>.rej patches implicitly apply to <foo>
691 (and (string-match "\\.rej\\'" (or buffer-file-name ""))
692 (let ((file (substring buffer-file-name 0 (match-beginning 0))))
693 (when (file-exists-p file) file)))
694 ;; If we haven't found the file, maybe it's because we haven't paid
695 ;; attention to the PCL-CVS hint.
696 (and (not prefix)
697 (boundp 'cvs-pcl-cvs-dirchange-re)
698 (save-excursion
699 (re-search-backward cvs-pcl-cvs-dirchange-re nil t))
700 (diff-find-file-name old batch (match-string 1)))
701 ;; Invent something, if necessary.
702 (when batch
703 (or (car fs) default-directory))
704 ;; if all else fails, ask the user
705 (let ((file (read-file-name (format "Use file %s: " (or (first fs) ""))
706 nil (first fs) t (first fs))))
707 (set (make-local-variable 'diff-remembered-files-alist)
708 (cons (cons fs file) diff-remembered-files-alist))
709 file)))))
710
711
712 (defun diff-ediff-patch ()
713 "Call `ediff-patch-file' on the current buffer."
714 (interactive)
715 (condition-case err
716 (ediff-patch-file nil (current-buffer))
717 (wrong-number-of-arguments (ediff-patch-file))))
718
719 ;;;;
720 ;;;; Conversion functions
721 ;;;;
722
723 ;;(defvar diff-inhibit-after-change nil
724 ;; "Non-nil means inhibit `diff-mode's after-change functions.")
725
726 (defun diff-unified->context (start end)
727 "Convert unified diffs to context diffs.
728 START and END are either taken from the region (if a prefix arg is given) or
729 else cover the whole buffer."
730 (interactive (if (or current-prefix-arg (and transient-mark-mode mark-active))
731 (list (region-beginning) (region-end))
732 (list (point-min) (point-max))))
733 (unless (markerp end) (setq end (copy-marker end t)))
734 (let (;;(diff-inhibit-after-change t)
735 (inhibit-read-only t))
736 (save-excursion
737 (goto-char start)
738 (while (and (re-search-forward "^\\(\\(---\\) .+\n\\(\\+\\+\\+\\) .+\\|@@ -\\([0-9]+\\),\\([0-9]+\\) \\+\\([0-9]+\\),\\([0-9]+\\) @@.*\\)$" nil t)
739 (< (point) end))
740 (combine-after-change-calls
741 (if (match-beginning 2)
742 ;; we matched a file header
743 (progn
744 ;; use reverse order to make sure the indices are kept valid
745 (replace-match "---" t t nil 3)
746 (replace-match "***" t t nil 2))
747 ;; we matched a hunk header
748 (let ((line1 (match-string 4))
749 (lines1 (match-string 5))
750 (line2 (match-string 6))
751 (lines2 (match-string 7))
752 ;; Variables to use the special undo function.
753 (old-undo buffer-undo-list)
754 (old-end (marker-position end))
755 (start (match-beginning 0))
756 (reversible t))
757 (replace-match
758 (concat "***************\n*** " line1 ","
759 (number-to-string (+ (string-to-number line1)
760 (string-to-number lines1)
761 -1)) " ****"))
762 (forward-line 1)
763 (save-restriction
764 (narrow-to-region (point)
765 (progn (diff-end-of-hunk 'unified) (point)))
766 (let ((hunk (buffer-string)))
767 (goto-char (point-min))
768 (if (not (save-excursion (re-search-forward "^-" nil t)))
769 (delete-region (point) (point-max))
770 (goto-char (point-max))
771 (let ((modif nil) last-pt)
772 (while (progn (setq last-pt (point))
773 (= (forward-line -1) 0))
774 (case (char-after)
775 (?\s (insert " ") (setq modif nil) (backward-char 1))
776 (?+ (delete-region (point) last-pt) (setq modif t))
777 (?- (if (not modif)
778 (progn (forward-char 1)
779 (insert " "))
780 (delete-char 1)
781 (insert "! "))
782 (backward-char 2))
783 (?\\ (when (save-excursion (forward-line -1)
784 (= (char-after) ?+))
785 (delete-region (point) last-pt) (setq modif t)))
786 (t (setq modif nil))))))
787 (goto-char (point-max))
788 (save-excursion
789 (insert "--- " line2 ","
790 (number-to-string (+ (string-to-number line2)
791 (string-to-number lines2)
792 -1)) " ----\n" hunk))
793 ;;(goto-char (point-min))
794 (forward-line 1)
795 (if (not (save-excursion (re-search-forward "^+" nil t)))
796 (delete-region (point) (point-max))
797 (let ((modif nil) (delete nil))
798 (if (save-excursion (re-search-forward "^\\+.*\n-" nil t))
799 ;; Normally, lines in a substitution come with
800 ;; first the removals and then the additions, and
801 ;; the context->unified function follows this
802 ;; convention, of course. Yet, other alternatives
803 ;; are valid as well, but they preclude the use of
804 ;; context->unified as an undo command.
805 (setq reversible nil))
806 (while (not (eobp))
807 (case (char-after)
808 (?\s (insert " ") (setq modif nil) (backward-char 1))
809 (?- (setq delete t) (setq modif t))
810 (?+ (if (not modif)
811 (progn (forward-char 1)
812 (insert " "))
813 (delete-char 1)
814 (insert "! "))
815 (backward-char 2))
816 (?\\ (when (save-excursion (forward-line 1)
817 (not (eobp)))
818 (setq delete t) (setq modif t)))
819 (t (setq modif nil)))
820 (let ((last-pt (point)))
821 (forward-line 1)
822 (when delete
823 (delete-region last-pt (point))
824 (setq delete nil)))))))
825 (unless (or (not reversible) (eq buffer-undo-list t))
826 ;; Drop the many undo entries and replace them with
827 ;; a single entry that uses diff-context->unified to do
828 ;; the work.
829 (setq buffer-undo-list
830 (cons (list 'apply (- old-end end) start (point-max)
831 'diff-context->unified start (point-max))
832 old-undo)))))))))))
833
834 (defun diff-context->unified (start end &optional to-context)
835 "Convert context diffs to unified diffs.
836 START and END are either taken from the region
837 \(when it is highlighted) or else cover the whole buffer.
838 With a prefix argument, convert unified format to context format."
839 (interactive (if (and transient-mark-mode mark-active)
840 (list (region-beginning) (region-end) current-prefix-arg)
841 (list (point-min) (point-max) current-prefix-arg)))
842 (if to-context
843 (diff-unified->context start end)
844 (unless (markerp end) (setq end (copy-marker end t)))
845 (let ( ;;(diff-inhibit-after-change t)
846 (inhibit-read-only t))
847 (save-excursion
848 (goto-char start)
849 (while (and (re-search-forward "^\\(\\(\\*\\*\\*\\) .+\n\\(---\\) .+\\|\\*\\{15\\}.*\n\\*\\*\\* \\([0-9]+\\),\\(-?[0-9]+\\) \\*\\*\\*\\*\\)$" nil t)
850 (< (point) end))
851 (combine-after-change-calls
852 (if (match-beginning 2)
853 ;; we matched a file header
854 (progn
855 ;; use reverse order to make sure the indices are kept valid
856 (replace-match "+++" t t nil 3)
857 (replace-match "---" t t nil 2))
858 ;; we matched a hunk header
859 (let ((line1s (match-string 4))
860 (line1e (match-string 5))
861 (pt1 (match-beginning 0)))
862 (replace-match "")
863 (unless (re-search-forward
864 "^--- \\([0-9]+\\),\\(-?[0-9]+\\) ----$" nil t)
865 (error "Can't find matching `--- n1,n2 ----' line"))
866 (let ((line2s (match-string 1))
867 (line2e (match-string 2))
868 (pt2 (progn
869 (delete-region (progn (beginning-of-line) (point))
870 (progn (forward-line 1) (point)))
871 (point-marker))))
872 (goto-char pt1)
873 (forward-line 1)
874 (while (< (point) pt2)
875 (case (char-after)
876 ((?! ?-) (delete-char 2) (insert "-") (forward-line 1))
877 (?\s ;merge with the other half of the chunk
878 (let* ((endline2
879 (save-excursion
880 (goto-char pt2) (forward-line 1) (point)))
881 (c (char-after pt2)))
882 (case c
883 ((?! ?+)
884 (insert "+"
885 (prog1 (buffer-substring (+ pt2 2) endline2)
886 (delete-region pt2 endline2))))
887 (?\s ;FIXME: check consistency
888 (delete-region pt2 endline2)
889 (delete-char 1)
890 (forward-line 1))
891 (?\\ (forward-line 1))
892 (t (delete-char 1) (forward-line 1)))))
893 (t (forward-line 1))))
894 (while (looking-at "[+! ] ")
895 (if (/= (char-after) ?!) (forward-char 1)
896 (delete-char 1) (insert "+"))
897 (delete-char 1) (forward-line 1))
898 (save-excursion
899 (goto-char pt1)
900 (insert "@@ -" line1s ","
901 (number-to-string (- (string-to-number line1e)
902 (string-to-number line1s)
903 -1))
904 " +" line2s ","
905 (number-to-string (- (string-to-number line2e)
906 (string-to-number line2s)
907 -1)) " @@")))))))))))
908
909 (defun diff-reverse-direction (start end)
910 "Reverse the direction of the diffs.
911 START and END are either taken from the region (if a prefix arg is given) or
912 else cover the whole buffer."
913 (interactive (if (or current-prefix-arg (and transient-mark-mode mark-active))
914 (list (region-beginning) (region-end))
915 (list (point-min) (point-max))))
916 (unless (markerp end) (setq end (copy-marker end t)))
917 (let (;;(diff-inhibit-after-change t)
918 (inhibit-read-only t))
919 (save-excursion
920 (goto-char start)
921 (while (and (re-search-forward "^\\(\\([-*][-*][-*] \\)\\(.+\\)\n\\([-+][-+][-+] \\)\\(.+\\)\\|\\*\\{15\\}.*\n\\*\\*\\* \\(.+\\) \\*\\*\\*\\*\\|@@ -\\([0-9,]+\\) \\+\\([0-9,]+\\) @@.*\\)$" nil t)
922 (< (point) end))
923 (combine-after-change-calls
924 (cond
925 ;; a file header
926 ((match-beginning 2) (replace-match "\\2\\5\n\\4\\3" nil))
927 ;; a context-diff hunk header
928 ((match-beginning 6)
929 (let ((pt-lines1 (match-beginning 6))
930 (lines1 (match-string 6)))
931 (replace-match "" nil nil nil 6)
932 (forward-line 1)
933 (let ((half1s (point)))
934 (while (looking-at "[-! \\][ \t]\\|#")
935 (when (= (char-after) ?-) (delete-char 1) (insert "+"))
936 (forward-line 1))
937 (let ((half1 (delete-and-extract-region half1s (point))))
938 (unless (looking-at "^--- \\([0-9]+,-?[0-9]+\\) ----$")
939 (insert half1)
940 (error "Can't find matching `--- n1,n2 ----' line"))
941 (let ((str1 (match-string 1)))
942 (replace-match lines1 nil nil nil 1)
943 (forward-line 1)
944 (let ((half2s (point)))
945 (while (looking-at "[!+ \\][ \t]\\|#")
946 (when (= (char-after) ?+) (delete-char 1) (insert "-"))
947 (forward-line 1))
948 (let ((half2 (delete-and-extract-region half2s (point))))
949 (insert (or half1 ""))
950 (goto-char half1s)
951 (insert (or half2 ""))))
952 (goto-char pt-lines1)
953 (insert str1))))))
954 ;; a unified-diff hunk header
955 ((match-beginning 7)
956 (replace-match "@@ -\\8 +\\7 @@" nil)
957 (forward-line 1)
958 (let ((c (char-after)) first last)
959 (while (case (setq c (char-after))
960 (?- (setq first (or first (point)))
961 (delete-char 1) (insert "+") t)
962 (?+ (setq last (or last (point)))
963 (delete-char 1) (insert "-") t)
964 ((?\\ ?#) t)
965 (t (when (and first last (< first last))
966 (insert (delete-and-extract-region first last)))
967 (setq first nil last nil)
968 (equal ?\s c)))
969 (forward-line 1))))))))))
970
971 (defun diff-fixup-modifs (start end)
972 "Fixup the hunk headers (in case the buffer was modified).
973 START and END are either taken from the region (if a prefix arg is given) or
974 else cover the whole buffer."
975 (interactive (if (or current-prefix-arg (and transient-mark-mode mark-active))
976 (list (region-beginning) (region-end))
977 (list (point-min) (point-max))))
978 (let ((inhibit-read-only t))
979 (save-excursion
980 (goto-char end) (diff-end-of-hunk)
981 (let ((plus 0) (minus 0) (space 0) (bang 0))
982 (while (and (= (forward-line -1) 0) (<= start (point)))
983 (if (not (looking-at
984 (concat "@@ -[0-9,]+ \\+[0-9,]+ @@"
985 "\\|[-*][-*][-*] [0-9,]+ [-*][-*][-*][-*]$"
986 "\\|--- .+\n\\+\\+\\+ ")))
987 (case (char-after)
988 (?\s (incf space))
989 (?+ (incf plus))
990 (?- (incf minus))
991 (?! (incf bang))
992 ((?\\ ?#) nil)
993 (t (setq space 0 plus 0 minus 0 bang 0)))
994 (cond
995 ((looking-at "@@ -[0-9]+,\\([0-9]*\\) \\+[0-9]+,\\([0-9]*\\) @@.*$")
996 (let* ((old1 (match-string 1))
997 (old2 (match-string 2))
998 (new1 (number-to-string (+ space minus)))
999 (new2 (number-to-string (+ space plus))))
1000 (unless (string= new2 old2) (replace-match new2 t t nil 2))
1001 (unless (string= new1 old1) (replace-match new1 t t nil 1))))
1002 ((looking-at "--- \\([0-9]+\\),\\([0-9]*\\) ----$")
1003 (when (> (+ space bang plus) 0)
1004 (let* ((old1 (match-string 1))
1005 (old2 (match-string 2))
1006 (new (number-to-string
1007 (+ space bang plus -1 (string-to-number old1)))))
1008 (unless (string= new old2) (replace-match new t t nil 2)))))
1009 ((looking-at "\\*\\*\\* \\([0-9]+\\),\\(-?[0-9]*\\) \\*\\*\\*\\*$")
1010 (when (> (+ space bang minus) 0)
1011 (let* ((old (match-string 1))
1012 (new (format
1013 (concat "%0" (number-to-string (length old)) "d")
1014 (+ space bang minus -1 (string-to-number old)))))
1015 (unless (string= new old) (replace-match new t t nil 2))))))
1016 (setq space 0 plus 0 minus 0 bang 0)))))))
1017
1018 ;;;;
1019 ;;;; Hooks
1020 ;;;;
1021
1022 (defun diff-write-contents-hooks ()
1023 "Fixup hunk headers if necessary."
1024 (if (buffer-modified-p) (diff-fixup-modifs (point-min) (point-max)))
1025 nil)
1026
1027 ;; It turns out that making changes in the buffer from within an
1028 ;; *-change-function is asking for trouble, whereas making them
1029 ;; from a post-command-hook doesn't pose much problems
1030 (defvar diff-unhandled-changes nil)
1031 (defun diff-after-change-function (beg end len)
1032 "Remember to fixup the hunk header.
1033 See `after-change-functions' for the meaning of BEG, END and LEN."
1034 ;; Ignoring changes when inhibit-read-only is set is strictly speaking
1035 ;; incorrect, but it turns out that inhibit-read-only is normally not set
1036 ;; inside editing commands, while it tends to be set when the buffer gets
1037 ;; updated by an async process or by a conversion function, both of which
1038 ;; would rather not be uselessly slowed down by this hook.
1039 (when (and (not undo-in-progress) (not inhibit-read-only))
1040 (if diff-unhandled-changes
1041 (setq diff-unhandled-changes
1042 (cons (min beg (car diff-unhandled-changes))
1043 (max end (cdr diff-unhandled-changes))))
1044 (setq diff-unhandled-changes (cons beg end)))))
1045
1046 (defun diff-post-command-hook ()
1047 "Fixup hunk headers if necessary."
1048 (when (consp diff-unhandled-changes)
1049 (ignore-errors
1050 (save-excursion
1051 (goto-char (car diff-unhandled-changes))
1052 ;; Maybe we've cut the end of the hunk before point.
1053 (if (and (bolp) (not (bobp))) (backward-char 1))
1054 ;; We used to fixup modifs on all the changes, but it turns out
1055 ;; that it's safer not to do it on big changes, for example
1056 ;; when yanking a big diff, since we might then screw up perfectly
1057 ;; correct values. -stef
1058 ;; (unless (ignore-errors
1059 ;; (diff-beginning-of-hunk)
1060 ;; (save-excursion
1061 ;; (diff-end-of-hunk)
1062 ;; (> (point) (car diff-unhandled-changes))))
1063 ;; (goto-char (car diff-unhandled-changes))
1064 ;; (re-search-forward diff-hunk-header-re (cdr diff-unhandled-changes))
1065 ;; (diff-beginning-of-hunk))
1066 ;; (diff-fixup-modifs (point) (cdr diff-unhandled-changes))
1067 (diff-beginning-of-hunk)
1068 (when (save-excursion
1069 (diff-end-of-hunk)
1070 (>= (point) (cdr diff-unhandled-changes)))
1071 (diff-fixup-modifs (point) (cdr diff-unhandled-changes)))))
1072 (setq diff-unhandled-changes nil)))
1073
1074 (defun diff-next-error (arg reset)
1075 ;; Select a window that displays the current buffer so that point
1076 ;; movements are reflected in that window. Otherwise, the user might
1077 ;; never see the hunk corresponding to the source she's jumping to.
1078 (pop-to-buffer (current-buffer))
1079 (if reset (goto-char (point-min)))
1080 (diff-hunk-next arg)
1081 (diff-goto-source))
1082
1083 ;;;###autoload
1084 (define-derived-mode diff-mode fundamental-mode "Diff"
1085 "Major mode for viewing/editing context diffs.
1086 Supports unified and context diffs as well as (to a lesser extent)
1087 normal diffs.
1088
1089 When the buffer is read-only, the ESC prefix is not necessary.
1090 If you edit the buffer manually, diff-mode will try to update the hunk
1091 headers for you on-the-fly.
1092
1093 You can also switch between context diff and unified diff with \\[diff-context->unified],
1094 or vice versa with \\[diff-unified->context] and you can also reverse the direction of
1095 a diff with \\[diff-reverse-direction].
1096
1097 \\{diff-mode-map}"
1098
1099 (set (make-local-variable 'font-lock-defaults) diff-font-lock-defaults)
1100 (set (make-local-variable 'outline-regexp) diff-outline-regexp)
1101 (set (make-local-variable 'imenu-generic-expression)
1102 diff-imenu-generic-expression)
1103 ;; These are not perfect. They would be better done separately for
1104 ;; context diffs and unidiffs.
1105 ;; (set (make-local-variable 'paragraph-start)
1106 ;; (concat "@@ " ; unidiff hunk
1107 ;; "\\|\\*\\*\\* " ; context diff hunk or file start
1108 ;; "\\|--- [^\t]+\t")) ; context or unidiff file
1109 ;; ; start (first or second line)
1110 ;; (set (make-local-variable 'paragraph-separate) paragraph-start)
1111 ;; (set (make-local-variable 'page-delimiter) "--- [^\t]+\t")
1112 ;; compile support
1113 (set (make-local-variable 'next-error-function) 'diff-next-error)
1114
1115 (setq buffer-read-only diff-default-read-only)
1116 ;; setup change hooks
1117 (if (not diff-update-on-the-fly)
1118 (add-hook 'write-contents-functions 'diff-write-contents-hooks nil t)
1119 (make-local-variable 'diff-unhandled-changes)
1120 (add-hook 'after-change-functions 'diff-after-change-function nil t)
1121 (add-hook 'post-command-hook 'diff-post-command-hook nil t))
1122 ;; Neat trick from Dave Love to add more bindings in read-only mode:
1123 (lexical-let ((ro-bind (cons 'buffer-read-only diff-mode-shared-map)))
1124 (add-to-list 'minor-mode-overriding-map-alist ro-bind)
1125 ;; Turn off this little trick in case the buffer is put in view-mode.
1126 (add-hook 'view-mode-hook
1127 (lambda ()
1128 (setq minor-mode-overriding-map-alist
1129 (delq ro-bind minor-mode-overriding-map-alist)))
1130 nil t))
1131 ;; add-log support
1132 (set (make-local-variable 'add-log-current-defun-function)
1133 'diff-current-defun)
1134 (set (make-local-variable 'add-log-buffer-file-name-function)
1135 'diff-find-file-name))
1136
1137 ;;;###autoload
1138 (define-minor-mode diff-minor-mode
1139 "Minor mode for viewing/editing context diffs.
1140 \\{diff-minor-mode-map}"
1141 :group 'diff-mode :lighter " Diff"
1142 ;; FIXME: setup font-lock
1143 ;; setup change hooks
1144 (if (not diff-update-on-the-fly)
1145 (add-hook 'write-contents-functions 'diff-write-contents-hooks nil t)
1146 (make-local-variable 'diff-unhandled-changes)
1147 (add-hook 'after-change-functions 'diff-after-change-function nil t)
1148 (add-hook 'post-command-hook 'diff-post-command-hook nil t)))
1149
1150 ;;; Handy hook functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1151
1152 (defun diff-delete-if-empty ()
1153 ;; An empty diff file means there's no more diffs to integrate, so we
1154 ;; can just remove the file altogether. Very handy for .rej files if we
1155 ;; remove hunks as we apply them.
1156 (when (and buffer-file-name
1157 (eq 0 (nth 7 (file-attributes buffer-file-name))))
1158 (delete-file buffer-file-name)))
1159
1160 (defun diff-delete-empty-files ()
1161 "Arrange for empty diff files to be removed."
1162 (add-hook 'after-save-hook 'diff-delete-if-empty nil t))
1163
1164 (defun diff-make-unified ()
1165 "Turn context diffs into unified diffs if applicable."
1166 (if (save-excursion
1167 (goto-char (point-min))
1168 (and (looking-at diff-hunk-header-re) (eq (char-after) ?*)))
1169 (let ((mod (buffer-modified-p)))
1170 (unwind-protect
1171 (diff-context->unified (point-min) (point-max))
1172 (restore-buffer-modified-p mod)))))
1173
1174 ;;;
1175 ;;; Misc operations that have proved useful at some point.
1176 ;;;
1177
1178 (defun diff-next-complex-hunk ()
1179 "Jump to the next \"complex\" hunk.
1180 \"Complex\" is approximated by \"the hunk changes the number of lines\".
1181 Only works for unified diffs."
1182 (interactive)
1183 (while
1184 (and (re-search-forward "^@@ [-0-9]+,\\([0-9]+\\) [+0-9]+,\\([0-9]+\\) @@"
1185 nil t)
1186 (equal (match-string 1) (match-string 2)))))
1187
1188 (defun diff-sanity-check-context-hunk-half (lines)
1189 (let ((count lines))
1190 (while
1191 (cond
1192 ((and (memq (char-after) '(?\s ?! ?+ ?-))
1193 (memq (char-after (1+ (point))) '(?\s ?\t)))
1194 (decf count) t)
1195 ((or (zerop count) (= count lines)) nil)
1196 ((memq (char-after) '(?! ?+ ?-))
1197 (if (not (and (eq (char-after (1+ (point))) ?\n)
1198 (y-or-n-p "Try to auto-fix whitespace loss damage? ")))
1199 (error "End of hunk ambiguously marked")
1200 (forward-char 1) (insert " ") (forward-line -1) t))
1201 ((< lines 0)
1202 (error "End of hunk ambiguously marked"))
1203 ((not (y-or-n-p "Try to auto-fix whitespace loss and word-wrap damage? "))
1204 (error "Abort!"))
1205 ((eolp) (insert " ") (forward-line -1) t)
1206 (t (insert " ") (delete-region (- (point) 2) (- (point) 1)) t))
1207 (forward-line))))
1208
1209 (defun diff-sanity-check-hunk ()
1210 (let (;; Every modification is protected by a y-or-n-p, so it's probably
1211 ;; OK to override a read-only setting.
1212 (inhibit-read-only t))
1213 (save-excursion
1214 (cond
1215 ((not (looking-at diff-hunk-header-re))
1216 (error "Not recognizable hunk header"))
1217
1218 ;; A context diff.
1219 ((eq (char-after) ?*)
1220 (if (not (looking-at "\\*\\{15\\}\\(?: .*\\)?\n\\*\\*\\* \\([0-9]+\\),\\([0-9]+\\) \\*\\*\\*\\*"))
1221 (error "Unrecognized context diff first hunk header format")
1222 (forward-line 2)
1223 (diff-sanity-check-context-hunk-half
1224 (1+ (- (string-to-number (match-string 2))
1225 (string-to-number (match-string 1)))))
1226 (if (not (looking-at "--- \\([0-9]+\\),\\([0-9]+\\) ----$"))
1227 (error "Unrecognized context diff second hunk header format")
1228 (forward-line)
1229 (diff-sanity-check-context-hunk-half
1230 (1+ (- (string-to-number (match-string 2))
1231 (string-to-number (match-string 1))))))))
1232
1233 ;; A unified diff.
1234 ((eq (char-after) ?@)
1235 (if (not (looking-at
1236 "@@ -[0-9]+,\\([0-9]+\\) \\+[0-9]+,\\([0-9]+\\) @@"))
1237 (error "Unrecognized unified diff hunk header format")
1238 (let ((before (string-to-number (match-string 1)))
1239 (after (string-to-number (match-string 2))))
1240 (forward-line)
1241 (while
1242 (case (char-after)
1243 (?\s (decf before) (decf after) t)
1244 (?- (decf before) t)
1245 (?+ (decf after) t)
1246 (t
1247 (cond
1248 ((and (zerop before) (zerop after)) nil)
1249 ((or (< before 0) (< after 0))
1250 (error (if (or (zerop before) (zerop after))
1251 "End of hunk ambiguously marked"
1252 "Hunk seriously messed up")))
1253 ((not (y-or-n-p "Try to auto-fix whitespace loss and word-wrap damage? "))
1254 (error "Abort!"))
1255 ((eolp) (insert " ") (forward-line -1) t)
1256 (t (insert " ")
1257 (delete-region (- (point) 2) (- (point) 1)) t))))
1258 (forward-line)))))
1259
1260 ;; A plain diff.
1261 (t
1262 ;; TODO.
1263 )))))
1264
1265 (defun diff-hunk-text (hunk destp char-offset)
1266 "Return the literal source text from HUNK as (TEXT . OFFSET).
1267 If DESTP is nil, TEXT is the source, otherwise the destination text.
1268 CHAR-OFFSET is a char-offset in HUNK, and OFFSET is the corresponding
1269 char-offset in TEXT."
1270 (with-temp-buffer
1271 (insert hunk)
1272 (goto-char (point-min))
1273 (let ((src-pos nil)
1274 (dst-pos nil)
1275 (divider-pos nil)
1276 (num-pfx-chars 2))
1277 ;; Set the following variables:
1278 ;; SRC-POS buffer pos of the source part of the hunk or nil if none
1279 ;; DST-POS buffer pos of the destination part of the hunk or nil
1280 ;; DIVIDER-POS buffer pos of any divider line separating the src & dst
1281 ;; NUM-PFX-CHARS number of line-prefix characters used by this format"
1282 (cond ((looking-at "^@@")
1283 ;; unified diff
1284 (setq num-pfx-chars 1)
1285 (forward-line 1)
1286 (setq src-pos (point) dst-pos (point)))
1287 ((looking-at "^\\*\\*")
1288 ;; context diff
1289 (forward-line 2)
1290 (setq src-pos (point))
1291 (re-search-forward "^--- " nil t)
1292 (forward-line 0)
1293 (setq divider-pos (point))
1294 (forward-line 1)
1295 (setq dst-pos (point)))
1296 ((looking-at "^[0-9]+a[0-9,]+$")
1297 ;; normal diff, insert
1298 (forward-line 1)
1299 (setq dst-pos (point)))
1300 ((looking-at "^[0-9,]+d[0-9]+$")
1301 ;; normal diff, delete
1302 (forward-line 1)
1303 (setq src-pos (point)))
1304 ((looking-at "^[0-9,]+c[0-9,]+$")
1305 ;; normal diff, change
1306 (forward-line 1)
1307 (setq src-pos (point))
1308 (re-search-forward "^---$" nil t)
1309 (forward-line 0)
1310 (setq divider-pos (point))
1311 (forward-line 1)
1312 (setq dst-pos (point)))
1313 (t
1314 (error "Unknown diff hunk type")))
1315
1316 (if (if destp (null dst-pos) (null src-pos))
1317 ;; Implied empty text
1318 (if char-offset '("" . 0) "")
1319
1320 ;; For context diffs, either side can be empty, (if there's only
1321 ;; added or only removed text). We should then use the other side.
1322 (cond ((equal src-pos divider-pos) (setq src-pos dst-pos))
1323 ((equal dst-pos (point-max)) (setq dst-pos src-pos)))
1324
1325 (when char-offset (goto-char (+ (point-min) char-offset)))
1326
1327 ;; Get rid of anything except the desired text.
1328 (save-excursion
1329 ;; Delete unused text region
1330 (let ((keep (if destp dst-pos src-pos)))
1331 (when (and divider-pos (> divider-pos keep))
1332 (delete-region divider-pos (point-max)))
1333 (delete-region (point-min) keep))
1334 ;; Remove line-prefix characters, and unneeded lines (unified diffs).
1335 (let ((kill-char (if destp ?- ?+)))
1336 (goto-char (point-min))
1337 (while (not (eobp))
1338 (if (eq (char-after) kill-char)
1339 (delete-region (point) (progn (forward-line 1) (point)))
1340 (delete-char num-pfx-chars)
1341 (forward-line 1)))))
1342
1343 (let ((text (buffer-substring-no-properties (point-min) (point-max))))
1344 (if char-offset (cons text (- (point) (point-min))) text))))))
1345
1346
1347 (defun diff-find-text (text)
1348 "Return the buffer position (BEG . END) of the nearest occurrence of TEXT.
1349 If TEXT isn't found, nil is returned."
1350 (let* ((orig (point))
1351 (forw (and (search-forward text nil t)
1352 (cons (match-beginning 0) (match-end 0))))
1353 (back (and (goto-char (+ orig (length text)))
1354 (search-backward text nil t)
1355 (cons (match-beginning 0) (match-end 0)))))
1356 ;; Choose the closest match.
1357 (if (and forw back)
1358 (if (> (- (car forw) orig) (- orig (car back))) back forw)
1359 (or back forw))))
1360
1361 (defun diff-find-approx-text (text)
1362 "Return the buffer position (BEG . END) of the nearest occurrence of TEXT.
1363 Whitespace differences are ignored."
1364 (let* ((orig (point))
1365 (re (concat "^[ \t\n\f]*"
1366 (mapconcat 'regexp-quote (split-string text) "[ \t\n\f]+")
1367 "[ \t\n\f]*\n"))
1368 (forw (and (re-search-forward re nil t)
1369 (cons (match-beginning 0) (match-end 0))))
1370 (back (and (goto-char (+ orig (length text)))
1371 (re-search-backward re nil t)
1372 (cons (match-beginning 0) (match-end 0)))))
1373 ;; Choose the closest match.
1374 (if (and forw back)
1375 (if (> (- (car forw) orig) (- orig (car back))) back forw)
1376 (or back forw))))
1377
1378 (defsubst diff-xor (a b) (if a (if (not b) a) b))
1379
1380 (defun diff-find-source-location (&optional other-file reverse)
1381 "Find out (BUF LINE-OFFSET POS SRC DST SWITCHED).
1382 BUF is the buffer corresponding to the source file.
1383 LINE-OFFSET is the offset between the expected and actual positions
1384 of the text of the hunk or nil if the text was not found.
1385 POS is a pair (BEG . END) indicating the position of the text in the buffer.
1386 SRC and DST are the two variants of text as returned by `diff-hunk-text'.
1387 SRC is the variant that was found in the buffer.
1388 SWITCHED is non-nil if the patch is already applied."
1389 (save-excursion
1390 (let* ((other (diff-xor other-file diff-jump-to-old-file))
1391 (char-offset (- (point) (progn (diff-beginning-of-hunk 'try-harder)
1392 (point))))
1393 ;; Check that the hunk is well-formed. Otherwise diff-mode and
1394 ;; the user may disagree on what constitutes the hunk
1395 ;; (e.g. because an empty line truncates the hunk mid-course),
1396 ;; leading to potentially nasty surprises for the user.
1397 (_ (diff-sanity-check-hunk))
1398 (hunk (buffer-substring (point)
1399 (save-excursion (diff-end-of-hunk) (point))))
1400 (old (diff-hunk-text hunk reverse char-offset))
1401 (new (diff-hunk-text hunk (not reverse) char-offset))
1402 ;; Find the location specification.
1403 (line (if (not (looking-at "\\(?:\\*\\{15\\}.*\n\\)?[-@* ]*\\([0-9,]+\\)\\([ acd+]+\\([0-9,]+\\)\\)?"))
1404 (error "Can't find the hunk header")
1405 (if other (match-string 1)
1406 (if (match-end 3) (match-string 3)
1407 (unless (re-search-forward "^--- \\([0-9,]+\\)" nil t)
1408 (error "Can't find the hunk separator"))
1409 (match-string 1)))))
1410 (file (or (diff-find-file-name other) (error "Can't find the file")))
1411 (buf (find-file-noselect file)))
1412 ;; Update the user preference if he so wished.
1413 (when (> (prefix-numeric-value other-file) 8)
1414 (setq diff-jump-to-old-file other))
1415 (with-current-buffer buf
1416 (goto-line (string-to-number line))
1417 (let* ((orig-pos (point))
1418 (switched nil)
1419 ;; FIXME: Check for case where both OLD and NEW are found.
1420 (pos (or (diff-find-text (car old))
1421 (progn (setq switched t) (diff-find-text (car new)))
1422 (progn (setq switched nil)
1423 (condition-case nil
1424 (diff-find-approx-text (car old))
1425 (invalid-regexp nil))) ;Regex too big.
1426 (progn (setq switched t)
1427 (condition-case nil
1428 (diff-find-approx-text (car new))
1429 (invalid-regexp nil))) ;Regex too big.
1430 (progn (setq switched nil) nil))))
1431 (nconc
1432 (list buf)
1433 (if pos
1434 (list (count-lines orig-pos (car pos)) pos)
1435 (list nil (cons orig-pos (+ orig-pos (length (car old))))))
1436 (if switched (list new old t) (list old new))))))))
1437
1438
1439 (defun diff-hunk-status-msg (line-offset reversed dry-run)
1440 (let ((msg (if dry-run
1441 (if reversed "already applied" "not yet applied")
1442 (if reversed "undone" "applied"))))
1443 (message (cond ((null line-offset) "Hunk text not found")
1444 ((= line-offset 0) "Hunk %s")
1445 ((= line-offset 1) "Hunk %s at offset %d line")
1446 (t "Hunk %s at offset %d lines"))
1447 msg line-offset)))
1448
1449 (defvar diff-apply-hunk-to-backup-file nil)
1450
1451 (defun diff-apply-hunk (&optional reverse)
1452 "Apply the current hunk to the source file and go to the next.
1453 By default, the new source file is patched, but if the variable
1454 `diff-jump-to-old-file' is non-nil, then the old source file is
1455 patched instead (some commands, such as `diff-goto-source' can change
1456 the value of this variable when given an appropriate prefix argument).
1457
1458 With a prefix argument, REVERSE the hunk."
1459 (interactive "P")
1460 (destructuring-bind (buf line-offset pos old new &optional switched)
1461 ;; Sometimes we'd like to have the following behavior: if REVERSE go
1462 ;; to the new file, otherwise go to the old. But that means that by
1463 ;; default we use the old file, which is the opposite of the default
1464 ;; for diff-goto-source, and is thus confusing. Also when you don't
1465 ;; know about it it's pretty surprising.
1466 ;; TODO: make it possible to ask explicitly for this behavior.
1467 ;;
1468 ;; This is duplicated in diff-test-hunk.
1469 (diff-find-source-location nil reverse)
1470 (cond
1471 ((null line-offset)
1472 (error "Can't find the text to patch"))
1473 ((with-current-buffer buf
1474 (and buffer-file-name
1475 (backup-file-name-p buffer-file-name)
1476 (not diff-apply-hunk-to-backup-file)
1477 (not (set (make-local-variable 'diff-apply-hunk-to-backup-file)
1478 (yes-or-no-p (format "Really apply this hunk to %s? "
1479 (file-name-nondirectory
1480 buffer-file-name)))))))
1481 (error "%s"
1482 (substitute-command-keys
1483 (format "Use %s\\[diff-apply-hunk] to apply it to the other file"
1484 (if (not reverse) "\\[universal-argument] ")))))
1485 ((and switched
1486 ;; A reversed patch was detected, perhaps apply it in reverse.
1487 (not (save-window-excursion
1488 (pop-to-buffer buf)
1489 (goto-char (+ (car pos) (cdr old)))
1490 (y-or-n-p
1491 (if reverse
1492 "Hunk hasn't been applied yet; apply it now? "
1493 "Hunk has already been applied; undo it? ")))))
1494 (message "(Nothing done)"))
1495 (t
1496 ;; Apply the hunk
1497 (with-current-buffer buf
1498 (goto-char (car pos))
1499 (delete-region (car pos) (cdr pos))
1500 (insert (car new)))
1501 ;; Display BUF in a window
1502 (set-window-point (display-buffer buf) (+ (car pos) (cdr new)))
1503 (diff-hunk-status-msg line-offset (diff-xor switched reverse) nil)
1504 (when diff-advance-after-apply-hunk
1505 (diff-hunk-next))))))
1506
1507
1508 (defun diff-test-hunk (&optional reverse)
1509 "See whether it's possible to apply the current hunk.
1510 With a prefix argument, try to REVERSE the hunk."
1511 (interactive "P")
1512 (destructuring-bind (buf line-offset pos src dst &optional switched)
1513 (diff-find-source-location nil reverse)
1514 (set-window-point (display-buffer buf) (+ (car pos) (cdr src)))
1515 (diff-hunk-status-msg line-offset (diff-xor reverse switched) t)))
1516
1517
1518 (defalias 'diff-mouse-goto-source 'diff-goto-source)
1519
1520 (defun diff-goto-source (&optional other-file event)
1521 "Jump to the corresponding source line.
1522 `diff-jump-to-old-file' (or its opposite if the OTHER-FILE prefix arg
1523 is given) determines whether to jump to the old or the new file.
1524 If the prefix arg is bigger than 8 (for example with \\[universal-argument] \\[universal-argument])
1525 then `diff-jump-to-old-file' is also set, for the next invocations."
1526 (interactive (list current-prefix-arg last-input-event))
1527 ;; When pointing at a removal line, we probably want to jump to
1528 ;; the old location, and else to the new (i.e. as if reverting).
1529 ;; This is a convenient detail when using smerge-diff.
1530 (if event (posn-set-point (event-end event)))
1531 (let ((rev (not (save-excursion (beginning-of-line) (looking-at "[-<]")))))
1532 (destructuring-bind (buf line-offset pos src dst &optional switched)
1533 (diff-find-source-location other-file rev)
1534 (pop-to-buffer buf)
1535 (goto-char (+ (car pos) (cdr src)))
1536 (diff-hunk-status-msg line-offset (diff-xor rev switched) t))))
1537
1538
1539 (defun diff-current-defun ()
1540 "Find the name of function at point.
1541 For use in `add-log-current-defun-function'."
1542 (save-excursion
1543 (when (looking-at diff-hunk-header-re)
1544 (forward-line 1)
1545 (re-search-forward "^[^ ]" nil t))
1546 (destructuring-bind (buf line-offset pos src dst &optional switched)
1547 (diff-find-source-location)
1548 (beginning-of-line)
1549 (or (when (memq (char-after) '(?< ?-))
1550 ;; Cursor is pointing at removed text. This could be a removed
1551 ;; function, in which case, going to the source buffer will
1552 ;; not help since the function is now removed. Instead,
1553 ;; try to figure out the function name just from the code-fragment.
1554 (let ((old (if switched dst src)))
1555 (with-temp-buffer
1556 (insert (car old))
1557 (funcall (with-current-buffer buf major-mode))
1558 (goto-char (+ (point-min) (cdr old)))
1559 (add-log-current-defun))))
1560 (with-current-buffer buf
1561 (goto-char (+ (car pos) (cdr src)))
1562 (add-log-current-defun))))))
1563
1564 (defun diff-refine-ignore-spaces-hunk ()
1565 "Refine the current hunk by ignoring space differences."
1566 (interactive)
1567 (let* ((char-offset (- (point) (progn (diff-beginning-of-hunk 'try-harder)
1568 (point))))
1569 (opts (case (char-after) (?@ "-bu") (?* "-bc") (t "-b")))
1570 (line-nb (and (or (looking-at "[^0-9]+\\([0-9]+\\)")
1571 (error "Can't find line number"))
1572 (string-to-number (match-string 1))))
1573 (hunk (delete-and-extract-region
1574 (point) (save-excursion (diff-end-of-hunk) (point))))
1575 (lead (make-string (1- line-nb) ?\n)) ;Line nums start at 1.
1576 (file1 (make-temp-file "diff1"))
1577 (file2 (make-temp-file "diff2"))
1578 (coding-system-for-read buffer-file-coding-system)
1579 (inhibit-read-only t)
1580 old new)
1581 (unwind-protect
1582 (save-excursion
1583 (setq old (diff-hunk-text hunk nil char-offset))
1584 (setq new (diff-hunk-text hunk t char-offset))
1585 (write-region (concat lead (car old)) nil file1 nil 'nomessage)
1586 (write-region (concat lead (car new)) nil file2 nil 'nomessage)
1587 (with-temp-buffer
1588 (let ((status
1589 (call-process diff-command nil t nil
1590 opts file1 file2)))
1591 (case status
1592 (0 nil) ;Nothing to reformat.
1593 (1 (goto-char (point-min))
1594 ;; Remove the file-header.
1595 (when (re-search-forward diff-hunk-header-re nil t)
1596 (delete-region (point-min) (match-beginning 0))))
1597 (t (goto-char (point-max))
1598 (unless (bolp) (insert "\n"))
1599 (insert hunk)))
1600 (setq hunk (buffer-string))
1601 (unless (memq status '(0 1))
1602 (error "Diff returned: %s" status)))))
1603 ;; Whatever happens, put back some equivalent text: either the new
1604 ;; one or the original one in case some error happened.
1605 (insert hunk)
1606 (delete-file file1)
1607 (delete-file file2))))
1608
1609 ;; provide the package
1610 (provide 'diff-mode)
1611
1612 ;;; Old Change Log from when diff-mode wasn't part of Emacs:
1613 ;; Revision 1.11 1999/10/09 23:38:29 monnier
1614 ;; (diff-mode-load-hook): dropped.
1615 ;; (auto-mode-alist): also catch *.diffs.
1616 ;; (diff-find-file-name, diff-mode): add smarts to find the right file
1617 ;; for *.rej files (that lack any file name indication).
1618 ;;
1619 ;; Revision 1.10 1999/09/30 15:32:11 monnier
1620 ;; added support for "\ No newline at end of file".
1621 ;;
1622 ;; Revision 1.9 1999/09/15 00:01:13 monnier
1623 ;; - added basic `compile' support.
1624 ;; - have diff-kill-hunk call diff-kill-file if it's the only hunk.
1625 ;; - diff-kill-file now tries to kill the leading garbage as well.
1626 ;;
1627 ;; Revision 1.8 1999/09/13 21:10:09 monnier
1628 ;; - don't use CL in the autoloaded code
1629 ;; - accept diffs using -T
1630 ;;
1631 ;; Revision 1.7 1999/09/05 20:53:03 monnier
1632 ;; interface to ediff-patch
1633 ;;
1634 ;; Revision 1.6 1999/09/01 20:55:13 monnier
1635 ;; (ediff=patch-file): add bindings to call ediff-patch.
1636 ;; (diff-find-file-name): taken out of diff-goto-source.
1637 ;; (diff-unified->context, diff-context->unified, diff-reverse-direction,
1638 ;; diff-fixup-modifs): only use the region if a prefix arg is given.
1639 ;;
1640 ;; Revision 1.5 1999/08/31 19:18:52 monnier
1641 ;; (diff-beginning-of-file, diff-prev-file): fixed wrong parenthesis.
1642 ;;
1643 ;; Revision 1.4 1999/08/31 13:01:44 monnier
1644 ;; use `combine-after-change-calls' to minimize the slowdown of font-lock.
1645 ;;
1646
1647 ;; arch-tag: 2571d7ff-bc28-4cf9-8585-42e21890be66
1648 ;;; diff-mode.el ends here