diff options
| author | Stefan Monnier | 2000-06-05 07:30:09 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-06-05 07:30:09 +0000 |
| commit | c0078a045cd752c619a9d7739b5a56a4ada10590 (patch) | |
| tree | e17a7b46a7886ea42424e6b77f479d8859775975 /lisp/diff-mode.el | |
| parent | d92474ed9d40721e26933db4e7e1240fcd2ec0f3 (diff) | |
| download | emacs-c0078a045cd752c619a9d7739b5a56a4ada10590.tar.gz emacs-c0078a045cd752c619a9d7739b5a56a4ada10590.zip | |
(diff-font-lock-keywords, diff-hunk-header-re)
(diff-goto-source, diff-unified->context, diff-context->unified)
(diff-reverse-direction, diff-fixup-modifs): Fix the regexps to
understand the format output by the `-p' argument to diff.
Diffstat (limited to 'lisp/diff-mode.el')
| -rw-r--r-- | lisp/diff-mode.el | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/lisp/diff-mode.el b/lisp/diff-mode.el index 960eb8a36b5..8db4887beb8 100644 --- a/lisp/diff-mode.el +++ b/lisp/diff-mode.el | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | ;; Author: Stefan Monnier <monnier@cs.yale.edu> | 5 | ;; Author: Stefan Monnier <monnier@cs.yale.edu> |
| 6 | ;; Keywords: patch diff | 6 | ;; Keywords: patch diff |
| 7 | ;; Revision: $Id: diff-mode.el,v 1.6 2000/03/21 16:59:17 monnier Exp $ | 7 | ;; Revision: $Id: diff-mode.el,v 1.7 2000/05/10 22:12:46 monnier Exp $ |
| 8 | 8 | ||
| 9 | ;; This file is part of GNU Emacs. | 9 | ;; This file is part of GNU Emacs. |
| 10 | 10 | ||
| @@ -199,9 +199,9 @@ when editing big diffs)." | |||
| 199 | (defvar diff-changed-face 'diff-changed-face) | 199 | (defvar diff-changed-face 'diff-changed-face) |
| 200 | 200 | ||
| 201 | (defvar diff-font-lock-keywords | 201 | (defvar diff-font-lock-keywords |
| 202 | '(("^@@ .+ @@$" . diff-hunk-header-face) ;unified | 202 | '(("^@@ -[0-9,]+ \\+[0-9,]+ @@.*$" . diff-hunk-header-face) ;unified |
| 203 | ("^--- .+ ----$" . diff-hunk-header-face) ;context | 203 | ("^--- .+ ----$" . diff-hunk-header-face) ;context |
| 204 | ("^\\*\\*\\*.+\\*\\*\\*\n" . diff-hunk-header-face) ;context | 204 | ("^\\*\\*\\*\\(.+\\*\\*\\*\\|\\*\\{12\\}.*\\)\n" . diff-hunk-header-face) ;context |
| 205 | ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) .*\n" . diff-file-header-face) | 205 | ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) .*\n" . diff-file-header-face) |
| 206 | ("^[0-9,]+[acd][0-9,]+$" . diff-hunk-header-face) | 206 | ("^[0-9,]+[acd][0-9,]+$" . diff-hunk-header-face) |
| 207 | ("^!.*\n" . diff-changed-face) ;context | 207 | ("^!.*\n" . diff-changed-face) ;context |
| @@ -230,7 +230,7 @@ when editing big diffs)." | |||
| 230 | ;;;; Movement | 230 | ;;;; Movement |
| 231 | ;;;; | 231 | ;;;; |
| 232 | 232 | ||
| 233 | (defconst diff-hunk-header-re "^\\(@@ .+ @@\\|\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\n\\*\\*\\* .+ \\*\\*\\*\\*\\|[0-9]+\\(,[0-9]+\\)?[acd][0-9]+\\(,[0-9]+\\)?\\)$") | 233 | (defconst diff-hunk-header-re "^\\(@@ -[0-9,]+ \\+[0-9,]+ @@.*\\|\\*\\{15\\}.*\n\\*\\*\\* .+ \\*\\*\\*\\*\\|[0-9]+\\(,[0-9]+\\)?[acd][0-9]+\\(,[0-9]+\\)?\\)$") |
| 234 | (defconst diff-file-header-re (concat "^\\(--- .+\n\\+\\+\\+\\|\\*\\*\\* .+\n---\\|[^-+!<>0-9@* ]\\).+\n" (substring diff-hunk-header-re 1))) | 234 | (defconst diff-file-header-re (concat "^\\(--- .+\n\\+\\+\\+\\|\\*\\*\\* .+\n---\\|[^-+!<>0-9@* ]\\).+\n" (substring diff-hunk-header-re 1))) |
| 235 | (defvar diff-narrowed-to nil) | 235 | (defvar diff-narrowed-to nil) |
| 236 | 236 | ||
| @@ -433,7 +433,7 @@ If the prefix arg is bigger than 8 (for example with \\[universal-argument] \\[u | |||
| 433 | (when (> (prefix-numeric-value other-file) 8) | 433 | (when (> (prefix-numeric-value other-file) 8) |
| 434 | (setq diff-jump-to-old-file-flag old)) | 434 | (setq diff-jump-to-old-file-flag old)) |
| 435 | (diff-beginning-of-hunk) | 435 | (diff-beginning-of-hunk) |
| 436 | (let* ((loc (if (not (looking-at "[-@*\n ]*\\([0-9,]+\\)\\([ acd+]+\\([0-9,]+\\)\\)?")) | 436 | (let* ((loc (if (not (looking-at "\\(?:\\*\\{15\\}.*\n\\)?[-@* ]*\\([0-9,]+\\)\\([ acd+]+\\([0-9,]+\\)\\)?")) |
| 437 | (error "Can't find the hunk header") | 437 | (error "Can't find the hunk header") |
| 438 | (if old (match-string 1) | 438 | (if old (match-string 1) |
| 439 | (if (match-end 3) (match-string 3) | 439 | (if (match-end 3) (match-string 3) |
| @@ -484,7 +484,7 @@ else cover the whole bufer." | |||
| 484 | (inhibit-read-only t)) | 484 | (inhibit-read-only t)) |
| 485 | (save-excursion | 485 | (save-excursion |
| 486 | (goto-char start) | 486 | (goto-char start) |
| 487 | (while (and (re-search-forward "^\\(\\(---\\) .+\n\\(\\+\\+\\+\\) .+\\|@@ -\\([0-9]+\\),\\([0-9]+\\) \\+\\([0-9]+\\),\\([0-9]+\\) @@\\)$" nil t) | 487 | (while (and (re-search-forward "^\\(\\(---\\) .+\n\\(\\+\\+\\+\\) .+\\|@@ -\\([0-9]+\\),\\([0-9]+\\) \\+\\([0-9]+\\),\\([0-9]+\\) @@.*\\)$" nil t) |
| 488 | (< (point) end)) | 488 | (< (point) end)) |
| 489 | (combine-after-change-calls | 489 | (combine-after-change-calls |
| 490 | (if (match-beginning 2) | 490 | (if (match-beginning 2) |
| @@ -571,7 +571,7 @@ else cover the whole bufer." | |||
| 571 | (inhibit-read-only t)) | 571 | (inhibit-read-only t)) |
| 572 | (save-excursion | 572 | (save-excursion |
| 573 | (goto-char start) | 573 | (goto-char start) |
| 574 | (while (and (re-search-forward "^\\(\\(\\*\\*\\*\\) .+\n\\(---\\) .+\\|\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\n\\*\\*\\* \\([0-9]+\\),\\(-?[0-9]+\\) \\*\\*\\*\\*\\)$" nil t) | 574 | (while (and (re-search-forward "^\\(\\(\\*\\*\\*\\) .+\n\\(---\\) .+\\|\\*\\{15\\}.*\n\\*\\*\\* \\([0-9]+\\),\\(-?[0-9]+\\) \\*\\*\\*\\*\\)$" nil t) |
| 575 | (< (point) end)) | 575 | (< (point) end)) |
| 576 | (combine-after-change-calls | 576 | (combine-after-change-calls |
| 577 | (if (match-beginning 2) | 577 | (if (match-beginning 2) |
| @@ -643,7 +643,7 @@ else cover the whole bufer." | |||
| 643 | (inhibit-read-only t)) | 643 | (inhibit-read-only t)) |
| 644 | (save-excursion | 644 | (save-excursion |
| 645 | (goto-char start) | 645 | (goto-char start) |
| 646 | (while (and (re-search-forward "^\\(\\([-*][-*][-*] \\)\\(.+\\)\n\\([-+][-+][-+] \\)\\(.+\\)\\|\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\n\\*\\*\\* \\(.+\\) \\*\\*\\*\\*\\|@@ -\\(.+\\) \\+\\(.+\\) @@\\)$" nil t) | 646 | (while (and (re-search-forward "^\\(\\([-*][-*][-*] \\)\\(.+\\)\n\\([-+][-+][-+] \\)\\(.+\\)\\|\\*\\{15\\}.*\n\\*\\*\\* \\(.+\\) \\*\\*\\*\\*\\|@@ -\\([0-9,]+\\) \\+\\([0-9,]+\\) @@.*\\)$" nil t) |
| 647 | (< (point) end)) | 647 | (< (point) end)) |
| 648 | (combine-after-change-calls | 648 | (combine-after-change-calls |
| 649 | (cond | 649 | (cond |
| @@ -708,7 +708,7 @@ else cover the whole bufer." | |||
| 708 | (goto-char end) (diff-end-of-hunk) | 708 | (goto-char end) (diff-end-of-hunk) |
| 709 | (let ((plus 0) (minus 0) (space 0) (bang 0)) | 709 | (let ((plus 0) (minus 0) (space 0) (bang 0)) |
| 710 | (while (and (= (forward-line -1) 0) (<= start (point))) | 710 | (while (and (= (forward-line -1) 0) (<= start (point))) |
| 711 | (if (not (looking-at "\\(@@ .+ @@\\|[-*][-*][-*] .+ [-*][-*][-*][-*]\\)$")) | 711 | (if (not (looking-at "\\(@@ -[0-9,]+ \\+[0-9,]+ @@.*\\|[-*][-*][-*] .+ [-*][-*][-*][-*]\\)$")) |
| 712 | (case (char-after) | 712 | (case (char-after) |
| 713 | (?\ (incf space)) | 713 | (?\ (incf space)) |
| 714 | (?+ (incf plus)) | 714 | (?+ (incf plus)) |
| @@ -717,7 +717,7 @@ else cover the whole bufer." | |||
| 717 | ((?\\ ?#) nil) | 717 | ((?\\ ?#) nil) |
| 718 | (t (setq space 0 plus 0 minus 0 bang 0))) | 718 | (t (setq space 0 plus 0 minus 0 bang 0))) |
| 719 | (cond | 719 | (cond |
| 720 | ((looking-at "@@ -[0-9]+,\\([0-9]*\\) \\+[0-9]+,\\([0-9]*\\) @@$") | 720 | ((looking-at "@@ -[0-9]+,\\([0-9]*\\) \\+[0-9]+,\\([0-9]*\\) @@.*$") |
| 721 | (let* ((old1 (match-string 1)) | 721 | (let* ((old1 (match-string 1)) |
| 722 | (old2 (match-string 2)) | 722 | (old2 (match-string 2)) |
| 723 | (new1 (number-to-string (+ space minus))) | 723 | (new1 (number-to-string (+ space minus))) |
| @@ -756,6 +756,11 @@ else cover the whole bufer." | |||
| 756 | (defun diff-after-change-function (beg end len) | 756 | (defun diff-after-change-function (beg end len) |
| 757 | "Remember to fixup the hunk header. | 757 | "Remember to fixup the hunk header. |
| 758 | See `after-change-functions' for the meaning of BEG, END and LEN." | 758 | See `after-change-functions' for the meaning of BEG, END and LEN." |
| 759 | ;; Ignoring changes when inhibit-read-only is set is strictly speaking | ||
| 760 | ;; incorrect, but it turns out that inhibit-read-only is normally not set | ||
| 761 | ;; inside editing commands, while it tends to be set when the buffer gets | ||
| 762 | ;; updated by an async process or by a conversion function, both of which | ||
| 763 | ;; would rather not be uselessly slowed down by this hook. | ||
| 759 | (when (and (not undo-in-progress) (not inhibit-read-only)) | 764 | (when (and (not undo-in-progress) (not inhibit-read-only)) |
| 760 | (if diff-unhandled-changes | 765 | (if diff-unhandled-changes |
| 761 | (setq diff-unhandled-changes | 766 | (setq diff-unhandled-changes |
| @@ -836,6 +841,14 @@ This mode runs `diff-mode-hook'. | |||
| 836 | 841 | ||
| 837 | ;;; Change Log: | 842 | ;;; Change Log: |
| 838 | ;; $Log: diff-mode.el,v $ | 843 | ;; $Log: diff-mode.el,v $ |
| 844 | ;; Revision 1.7 2000/05/10 22:12:46 monnier | ||
| 845 | ;; (diff-font-lock-keywords): Recognize comments. | ||
| 846 | ;; (diff-font-lock-defaults): Explicitly turn off multiline. | ||
| 847 | ;; (diff-end-of-hunk): Handle comments and fix end-of-buffer bug. | ||
| 848 | ;; (diff-ediff-patch): Fix call to ediff-patch-file. | ||
| 849 | ;; (diff-end-of-file, diff-reverse-direction, diff-fixup-modifs): | ||
| 850 | ;; Handle comments. | ||
| 851 | ;; | ||
| 839 | ;; Revision 1.6 2000/03/21 16:59:17 monnier | 852 | ;; Revision 1.6 2000/03/21 16:59:17 monnier |
| 840 | ;; (diff-mode-*-map): use `easy-mmode-defmap'. | 853 | ;; (diff-mode-*-map): use `easy-mmode-defmap'. |
| 841 | ;; (diff-end-of-hunk): Return the end position for use in | 854 | ;; (diff-end-of-hunk): Return the end position for use in |