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