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